Add chip with information to the description

pull/27/head
DerGoogler 4 years ago
parent 19182a28a8
commit 44ab584ae3

@ -23,6 +23,8 @@ public class Constants {
public static final String EXTRA_MARKDOWN_URL = "extra_markdown_url"; public static final String EXTRA_MARKDOWN_URL = "extra_markdown_url";
public static final String EXTRA_MARKDOWN_TITLE = "extra_markdown_title"; public static final String EXTRA_MARKDOWN_TITLE = "extra_markdown_title";
public static final String EXTRA_MARKDOWN_CONFIG = "extra_markdown_config"; public static final String EXTRA_MARKDOWN_CONFIG = "extra_markdown_config";
public static final String EXTRA_MARKDOWN_CHANGE_BOOT = "extra_markdown_change_boot";
public static final String EXTRA_MARKDOWN_NEEDS_RAMDISK = "extra_markdown_needs_ramdisk";
public static final String EXTRA_FADE_OUT = "extra_fade_out"; public static final String EXTRA_FADE_OUT = "extra_fade_out";
public static final String EXTRA_FROM_MANAGER = "extra_from_manager"; public static final String EXTRA_FROM_MANAGER = "extra_from_manager";
} }

@ -120,6 +120,11 @@ public class MainApplication extends CompatApplication {
getSharedPreferences().getBoolean("pref_enable_blur", false); getSharedPreferences().getBoolean("pref_enable_blur", false);
} }
public static boolean isChipsDisabled() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
getSharedPreferences().getBoolean("pref_disable_chips", false);
}
public static boolean isDeveloper() { public static boolean isDeveloper() {
return BuildConfig.DEBUG || return BuildConfig.DEBUG ||
getSharedPreferences().getBoolean("developer", false); getSharedPreferences().getBoolean("developer", false);

@ -7,6 +7,7 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.HorizontalScrollView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -19,6 +20,7 @@ import com.fox2code.mmm.XHooks;
import com.fox2code.mmm.compat.CompatActivity; import com.fox2code.mmm.compat.CompatActivity;
import com.fox2code.mmm.utils.Http; import com.fox2code.mmm.utils.Http;
import com.fox2code.mmm.utils.IntentHelper; import com.fox2code.mmm.utils.IntentHelper;
import com.google.android.material.chip.Chip;
import com.topjohnwu.superuser.internal.UiThreadHandler; import com.topjohnwu.superuser.internal.UiThreadHandler;
import java.io.IOException; import java.io.IOException;
@ -51,7 +53,8 @@ public class MarkdownActivity extends CompatActivity {
byte[] rawMarkdown = Http.doHttpGet(prefix + suffix, true); byte[] rawMarkdown = Http.doHttpGet(prefix + suffix, true);
redirects.put(url, newUrl); // Avoid retries redirects.put(url, newUrl); // Avoid retries
return rawMarkdown; return rawMarkdown;
} catch (IOException ignored) {} } catch (IOException ignored) {
}
} }
} }
throw e; throw e;
@ -74,6 +77,10 @@ public class MarkdownActivity extends CompatActivity {
.getString(Constants.EXTRA_MARKDOWN_TITLE); .getString(Constants.EXTRA_MARKDOWN_TITLE);
String config = intent.getExtras() String config = intent.getExtras()
.getString(Constants.EXTRA_MARKDOWN_CONFIG); .getString(Constants.EXTRA_MARKDOWN_CONFIG);
boolean change_boot = intent.getExtras()
.getBoolean(Constants.EXTRA_MARKDOWN_CHANGE_BOOT);
boolean needs_ramdisk = intent.getExtras()
.getBoolean(Constants.EXTRA_MARKDOWN_NEEDS_RAMDISK);
if (title != null && !title.isEmpty()) { if (title != null && !title.isEmpty()) {
this.setTitle(title); this.setTitle(title);
} }
@ -98,9 +105,26 @@ public class MarkdownActivity extends CompatActivity {
setContentView(R.layout.markdown_view); setContentView(R.layout.markdown_view);
final ViewGroup markdownBackground = findViewById(R.id.markdownBackground); final ViewGroup markdownBackground = findViewById(R.id.markdownBackground);
final TextView textView = findViewById(R.id.markdownView); final TextView textView = findViewById(R.id.markdownView);
final Chip chip_can_change_boot = findViewById(R.id.chip_change_boot);
final Chip chip_needs_ramdisk = findViewById(R.id.chip_needs_ramdisk);
final HorizontalScrollView chip_holder = findViewById(R.id.chip_holder);
final Chip min_magisk = findViewById(R.id.chip_min_magisk);
final TextView footer = findViewById(R.id.markdownFooter); final TextView footer = findViewById(R.id.markdownFooter);
UiThreadHandler.handler.postDelayed(() -> // Fix footer height UiThreadHandler.handler.postDelayed(() -> // Fix footer height
footer.setMinHeight(this.getNavigationBarHeight()), 1L); footer.setMinHeight(this.getNavigationBarHeight()), 1L);
// Really bad created
if (MainApplication.isChipsDisabled()) {
chip_holder.setVisibility(View.GONE);
} else {
if (change_boot) {
chip_can_change_boot.setVisibility(View.VISIBLE);
}
if (needs_ramdisk) {
chip_needs_ramdisk.setVisibility(View.VISIBLE);
}
}
new Thread(() -> { new Thread(() -> {
try { try {
Log.d(TAG, "Downloading"); Log.d(TAG, "Downloading");

@ -39,7 +39,9 @@ public enum ActionButtonType {
} else { } else {
IntentHelper.openMarkdown(button.getContext(), notesUrl, IntentHelper.openMarkdown(button.getContext(), notesUrl,
moduleHolder.repoModule.moduleInfo.name, moduleHolder.repoModule.moduleInfo.name,
moduleHolder.getMainModuleConfig()); moduleHolder.getMainModuleConfig(),
moduleHolder.repoModule.moduleInfo.changeBoot,
moduleHolder.repoModule.moduleInfo.needRamdisk);
} }
} }

@ -165,12 +165,14 @@ public class IntentHelper {
} }
} }
public static void openMarkdown(Context context, String url, String title, String config) { public static void openMarkdown(Context context, String url, String title, String config, Boolean changeBoot, Boolean needsRamdisk) {
try { try {
Intent intent = new Intent(context, MarkdownActivity.class); Intent intent = new Intent(context, MarkdownActivity.class);
MainApplication.addSecret(intent); MainApplication.addSecret(intent);
intent.putExtra(Constants.EXTRA_MARKDOWN_URL, url); intent.putExtra(Constants.EXTRA_MARKDOWN_URL, url);
intent.putExtra(Constants.EXTRA_MARKDOWN_TITLE, title); intent.putExtra(Constants.EXTRA_MARKDOWN_TITLE, title);
intent.putExtra(Constants.EXTRA_MARKDOWN_CHANGE_BOOT, changeBoot);
intent.putExtra(Constants.EXTRA_MARKDOWN_NEEDS_RAMDISK, needsRamdisk);
if (config != null && !config.isEmpty()) if (config != null && !config.isEmpty())
intent.putExtra(Constants.EXTRA_MARKDOWN_CONFIG, config); intent.putExtra(Constants.EXTRA_MARKDOWN_CONFIG, config);
startActivity(context, intent, true); startActivity(context, intent, true);

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M5,14.5h14v-6L5,8.5v6zM11,0.55L11,3.5h2L13,0.55h-2zM19.04,3.05l-1.79,1.79 1.41,1.41 1.8,-1.79 -1.42,-1.41zM13,22.45L13,19.5h-2v2.95h2zM20.45,18.54l-1.8,-1.79 -1.41,1.41 1.79,1.8 1.42,-1.42zM3.55,4.46l1.79,1.79 1.41,-1.41 -1.79,-1.79 -1.41,1.41zM4.96,19.95l1.79,-1.8 -1.41,-1.41 -1.79,1.79 1.41,1.42z"/>
</vector>

@ -1,23 +1,32 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/markdownBackground" android:id="@+id/markdownBackground"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="vertical"
app:fitsSystemWindowsInsets="top|left|right"> app:fitsSystemWindowsInsets="top|left|right">
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="0dp"
android:layout_weight="1"
tools:ignore="UselessParent">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/markdownView" android:id="@+id/markdownView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/markdown_border_content" android:layout_margin="@dimen/markdown_border_content"
android:text="@string/loading" /> android:text="@string/loading" />
<TextView <TextView
android:id="@+id/markdownFooter" android:id="@+id/markdownFooter"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -25,4 +34,40 @@
android:text="" /> android:text="" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
<HorizontalScrollView
android:id="@+id/chip_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.chip.ChipGroup
android:layout_width="wrap_content"
android:padding="8dp"
android:layout_height="wrap_content"
app:singleLine="true">
<com.google.android.material.chip.Chip
android:visibility="gone"
android:id="@+id/chip_change_boot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/module_can_change_boot"/>
<com.google.android.material.chip.Chip
android:visibility="gone"
android:id="@+id/chip_needs_ramdisk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/module_needs_ramdisk"/>
<!-- Leaving string hard codded -->
<com.google.android.material.chip.Chip
android:visibility="gone"
android:id="@+id/chip_min_magisk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Minimum Magisk 24.3+"/>
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
</LinearLayout> </LinearLayout>

@ -34,6 +34,8 @@
<string name="module_by">by</string> <string name="module_by">by</string>
<string name="module_downloads">Downloads:</string> <string name="module_downloads">Downloads:</string>
<string name="module_stars">Stars:</string> <string name="module_stars">Stars:</string>
<string name="module_needs_ramdisk">Needs ramdisk</string>
<string name="module_can_change_boot">Can change boot</string>
<!-- Preference Titles --> <!-- Preference Titles -->
<!-- Note: Lockdown mode used to be called showcase mode --> <!-- Note: Lockdown mode used to be called showcase mode -->
@ -100,6 +102,7 @@
all text on the same line when installing a module. all text on the same line when installing a module.
</string> </string>
<string name="enable_blur_pref">Blur</string> <string name="enable_blur_pref">Blur</string>
<string name="disable_chips_in_description">Disable chips in description</string>
<string name="repo_enabled">Repo on</string> <string name="repo_enabled">Repo on</string>
<string name="repo_disabled">Repo off</string> <string name="repo_disabled">Repo off</string>
<string name="add_repo">Add Repo</string> <string name="add_repo">Add Repo</string>

@ -64,6 +64,13 @@
app:title="@string/force_dark_terminal_title" app:title="@string/force_dark_terminal_title"
app:singleLineTitle="false" /> app:singleLineTitle="false" />
<SwitchPreferenceCompat
app:defaultValue="false"
app:key="pref_disable_chips"
app:icon="@drawable/ic_baseline_chip_24"
app:title="@string/disable_chips_in_description"
app:singleLineTitle="false" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
app:defaultValue="false" app:defaultValue="false"
app:key="pref_wrap_text" app:key="pref_wrap_text"

@ -3,4 +3,3 @@ distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionSha256Sum=9afb3ca688fc12c761a0e9e4321e4d24e977a4a8916c8a768b1fe05ddb4d6b66

Loading…
Cancel
Save