[app] Preload webview htmls (#1078)

* [app] Preload webview htmls

* [app] Remove "v" from version name
This commit is contained in:
tehcneko 2021-09-08 10:03:02 +08:00 committed by GitHub
parent 3cc4e4eeaf
commit 4464210e69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 61 additions and 73 deletions

View File

@ -119,7 +119,7 @@ androidComponents.onVariants { v ->
if (v is ApplicationVariantImpl) v
else (v as AnalyticsEnabledApplicationVariant).delegate as ApplicationVariantImpl
variant.outputs.forEach {
it.outputFileName.set("LSPosedManager-${verName}-${verCode}-${variant.name}.apk")
it.outputFileName.set("LSPosedManager-v${verName}-${verCode}-${variant.name}.apk")
}
}
@ -162,7 +162,7 @@ tasks.whenTaskAdded {
dependencies {
val glideVersion = "4.12.0"
val okhttpVersion = "4.9.1"
val navVersion = "2.4.0-alpha07"
val navVersion = "2.4.0-alpha08"
annotationProcessor("com.github.bumptech.glide:compiler:$glideVersion")
implementation("androidx.activity:activity:1.3.1")
implementation("androidx.browser:browser:1.3.0")
@ -172,10 +172,10 @@ dependencies {
implementation("androidx.navigation:navigation-fragment:$navVersion")
implementation("androidx.navigation:navigation-ui:$navVersion")
implementation("androidx.recyclerview:recyclerview:1.2.1")
implementation("androidx.slidingpanelayout:slidingpanelayout:1.2.0-alpha04")
implementation("androidx.slidingpanelayout:slidingpanelayout:1.2.0-beta01")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation("com.github.bumptech.glide:glide:$glideVersion")
implementation("com.google.android.material:material:1.5.0-alpha02")
implementation("com.google.android.material:material:1.5.0-alpha03")
implementation("com.google.code.gson:gson:2.8.8")
implementation("com.takisoft.preferencex:preferencex:1.1.0")
implementation("com.takisoft.preferencex:preferencex-colorpicker:1.1.0")

View File

@ -29,7 +29,6 @@ import android.system.Os;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.preference.PreferenceManager;
import com.google.gson.JsonParser;

View File

@ -85,7 +85,7 @@ import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.ConcurrentLinkedQueue;
import rikka.core.res.ResourcesKt;
import rikka.core.util.ResourceUtils;
import rikka.widget.switchbar.SwitchBar;
@SuppressLint("NotifyDataSetChanged")
@ -385,7 +385,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
if (!android) sb.append("\n");
String recommended = activity.getString(R.string.requested_by_module);
sb.append(recommended);
final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ResourcesKt.resolveColor(activity.getTheme(), androidx.appcompat.R.attr.colorAccent));
final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ResourceUtils.resolveColor(activity.getTheme(), androidx.appcompat.R.attr.colorAccent));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
final TypefaceSpan typefaceSpan = new TypefaceSpan(Typeface.create("sans-serif-medium", Typeface.NORMAL));
sb.setSpan(typefaceSpan, sb.length() - recommended.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);

View File

@ -38,7 +38,7 @@ import org.lsposed.manager.R;
import org.lsposed.manager.util.NavUtil;
import org.lsposed.manager.util.theme.ThemeUtil;
import rikka.core.res.ResourcesKt;
import rikka.core.util.ResourceUtils;
import rikka.material.app.MaterialActivity;
public class BaseActivity extends MaterialActivity {
@ -87,7 +87,7 @@ public class BaseActivity extends MaterialActivity {
window.getDecorView().post(() -> {
if (window.getDecorView().getRootWindowInsets().getSystemWindowInsetBottom() >= Resources.getSystem().getDisplayMetrics().density * 40) {
window.setNavigationBarColor(ResourcesKt.resolveColor(getTheme(), android.R.attr.navigationBarColor) & 0x00ffffff | -0x20000000);
window.setNavigationBarColor(ResourceUtils.resolveColor(getTheme(), android.R.attr.navigationBarColor) & 0x00ffffff | -0x20000000);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.setNavigationBarContrastEnforced(false);
}

View File

@ -19,8 +19,6 @@
package org.lsposed.manager.ui.fragment;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
@ -31,7 +29,6 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.core.text.HtmlCompat;
import com.bumptech.glide.Glide;
import com.google.android.material.snackbar.Snackbar;
import org.lsposed.manager.App;
@ -40,7 +37,6 @@ import org.lsposed.manager.ConfigManager;
import org.lsposed.manager.R;
import org.lsposed.manager.databinding.DialogAboutBinding;
import org.lsposed.manager.databinding.FragmentHomeBinding;
import org.lsposed.manager.databinding.FragmentMainBinding;
import org.lsposed.manager.ui.activity.base.BaseActivity;
import org.lsposed.manager.ui.dialog.BlurBehindDialogBuilder;
import org.lsposed.manager.ui.dialog.InfoDialogBuilder;
@ -50,23 +46,11 @@ import org.lsposed.manager.util.chrome.LinkTransformationMethod;
import java.util.Locale;
import rikka.core.res.ResourcesKt;
import rikka.widget.borderview.BorderView;
import rikka.core.util.ResourceUtils;
public class HomeFragment extends BaseFragment {
private FragmentHomeBinding binding;
private View snackbar;
private static PackageInfo wrap(ApplicationInfo applicationInfo, int longVersionCode) {
PackageInfo packageInfo = new PackageInfo();
packageInfo.applicationInfo = applicationInfo;
packageInfo.versionCode = longVersionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
packageInfo.setLongVersionCode(longVersionCode);
}
return packageInfo;
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -116,33 +100,33 @@ public class HomeFragment extends BaseFragment {
if (isBinderAlive) {
if (!ConfigManager.isSepolicyLoaded()) {
binding.statusTitle.setText(R.string.partial_activated);
cardBackgroundColor = ResourcesKt.resolveColor(activity.getTheme(), rikka.material.R.attr.colorWarning);
cardBackgroundColor = ResourceUtils.resolveColor(activity.getTheme(), rikka.material.R.attr.colorWarning);
binding.statusIcon.setImageResource(R.drawable.ic_warning);
binding.statusSummary.setText(R.string.selinux_policy_not_loaded_summary);
} else if (!ConfigManager.systemServerRequested()) {
binding.statusTitle.setText(R.string.partial_activated);
cardBackgroundColor = ResourcesKt.resolveColor(activity.getTheme(), rikka.material.R.attr.colorWarning);
cardBackgroundColor = ResourceUtils.resolveColor(activity.getTheme(), rikka.material.R.attr.colorWarning);
binding.statusIcon.setImageResource(R.drawable.ic_warning);
binding.statusSummary.setText(R.string.system_inject_fail_summary);
} else if (!ConfigManager.dex2oatFlagsLoaded()) {
binding.statusTitle.setText(R.string.partial_activated);
cardBackgroundColor = ResourcesKt.resolveColor(activity.getTheme(), rikka.material.R.attr.colorWarning);
cardBackgroundColor = ResourceUtils.resolveColor(activity.getTheme(), rikka.material.R.attr.colorWarning);
binding.statusIcon.setImageResource(R.drawable.ic_warning);
binding.statusSummary.setText(R.string.system_prop_incorrect_summary);
} else if (needUpdate) {
binding.statusTitle.setText(R.string.need_update);
cardBackgroundColor = ResourcesKt.resolveColor(activity.getTheme(), rikka.material.R.attr.colorWarning);
cardBackgroundColor = ResourceUtils.resolveColor(activity.getTheme(), rikka.material.R.attr.colorWarning);
binding.statusIcon.setImageResource(R.drawable.ic_warning);
binding.statusSummary.setText(R.string.please_update_summary);
} else {
binding.statusTitle.setText(R.string.activated);
cardBackgroundColor = ResourcesKt.resolveColor(activity.getTheme(), R.attr.colorNormal);
cardBackgroundColor = ResourceUtils.resolveColor(activity.getTheme(), R.attr.colorNormal);
binding.statusIcon.setImageResource(R.drawable.ic_check_circle);
binding.statusSummary.setText(String.format(Locale.ROOT, "%s (%d)",
ConfigManager.getXposedVersionName(), ConfigManager.getXposedVersionCode()));
}
} else {
cardBackgroundColor = ResourcesKt.resolveColor(activity.getTheme(), R.attr.colorInstall);
cardBackgroundColor = ResourceUtils.resolveColor(activity.getTheme(), R.attr.colorInstall);
boolean isMagiskInstalled = ConfigManager.isMagiskInstalled();
binding.statusTitle.setText(isMagiskInstalled ? R.string.install : R.string.not_installed);
binding.statusSummary.setText(isMagiskInstalled ? R.string.install_summary : R.string.not_install_summary);

View File

@ -89,7 +89,7 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import rikka.core.res.ResourcesKt;
import rikka.core.util.ResourceUtils;
import rikka.insets.WindowInsetsHelperKt;
import rikka.recyclerview.RecyclerViewKt;
import rikka.widget.borderview.BorderRecyclerView;
@ -346,7 +346,7 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
int position = arguments.getInt("position");
ItemRepoRecyclerviewBinding binding = ItemRepoRecyclerviewBinding.inflate(getLayoutInflater(), container, false);
if (fragment.adapters.size() == 1) {
WindowInsetsHelperKt.setInitialPadding(binding.recyclerView, 0, ResourcesKt.resolveDimensionPixelOffset(requireActivity().getTheme(), androidx.appcompat.R.attr.actionBarSize, 0), 0, 0);
WindowInsetsHelperKt.setInitialPadding(binding.recyclerView, 0, ResourceUtils.resolveDimensionPixelOffset(requireActivity().getTheme(), androidx.appcompat.R.attr.actionBarSize, 0), 0, 0);
}
binding.recyclerView.setTag(position);
binding.recyclerView.setAdapter(fragment.adapters.get(position));
@ -487,7 +487,7 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
sb.append("\n");
String recommended = getString(R.string.update_available, ver.second);
sb.append(recommended);
final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ResourcesKt.resolveColor(requireActivity().getTheme(), androidx.appcompat.R.attr.colorAccent));
final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ResourceUtils.resolveColor(requireActivity().getTheme(), androidx.appcompat.R.attr.colorAccent));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
final TypefaceSpan typefaceSpan = new TypefaceSpan(Typeface.create("sans-serif-medium", Typeface.NORMAL));
sb.setSpan(typefaceSpan, sb.length() - recommended.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);

View File

@ -30,6 +30,7 @@ import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.text.style.TypefaceSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@ -58,19 +59,25 @@ import org.lsposed.manager.repo.RepoLoader;
import org.lsposed.manager.repo.model.OnlineModule;
import org.lsposed.manager.util.ModuleUtil;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.FutureTask;
import java.util.stream.Collectors;
import rikka.core.res.ResourcesKt;
import rikka.core.util.LabelComparator;
import rikka.core.util.ResourceUtils;
import rikka.recyclerview.RecyclerViewKt;
public class RepoFragment extends BaseFragment implements RepoLoader.Listener {
public static final FutureTask<String> HTML_TEMPLATE = new FutureTask<>(() -> readWebviewHTML("template.html"));
public static final FutureTask<String> HTML_TEMPLATE_DARK = new FutureTask<>(() -> readWebviewHTML("template_dark.html"));
protected FragmentRepoBinding binding;
protected SearchView searchView;
private SearchView.OnQueryTextListener mSearchListener;
@ -80,6 +87,21 @@ public class RepoFragment extends BaseFragment implements RepoLoader.Listener {
private final RepoLoader repoLoader = RepoLoader.getInstance();
private RepoAdapter adapter;
private static String readWebviewHTML(String name) {
try {
var input = App.getInstance().getAssets().open("webview/" + name);
var result = new ByteArrayOutputStream(1024);
var buffer = new byte[1024];
for (int length; (length = input.read(buffer)) != -1; ) {
result.write(buffer, 0, length);
}
return result.toString(StandardCharsets.UTF_8.name());
} catch (IOException e) {
Log.e(App.TAG, "read webview HTML", e);
return "<html><body>@body@</body></html>";
}
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
mSearchListener = new SearchView.OnQueryTextListener() {
@ -144,6 +166,11 @@ public class RepoFragment extends BaseFragment implements RepoLoader.Listener {
if (preLoadWebview) {
mHandler.postDelayed(() -> {
new WebView(requireContext());
if (ResourceUtils.isNightMode(getResources().getConfiguration())) {
HTML_TEMPLATE_DARK.run();
} else {
HTML_TEMPLATE.run();
}
}, 500);
preLoadWebview = false;
}
@ -213,7 +240,7 @@ public class RepoFragment extends BaseFragment implements RepoLoader.Listener {
sb.append("\n");
String recommended = getString(R.string.update_available, ver.second);
sb.append(recommended);
final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ResourcesKt.resolveColor(requireActivity().getTheme(), androidx.appcompat.R.attr.colorAccent));
final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ResourceUtils.resolveColor(requireActivity().getTheme(), androidx.appcompat.R.attr.colorAccent));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
final TypefaceSpan typefaceSpan = new TypefaceSpan(Typeface.create("sans-serif-medium", Typeface.NORMAL));
sb.setSpan(typefaceSpan, sb.length() - recommended.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);

View File

@ -19,7 +19,6 @@
package org.lsposed.manager.ui.fragment;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Spannable;
@ -67,42 +66,23 @@ import org.lsposed.manager.ui.widget.LinkifyTextView;
import org.lsposed.manager.util.NavUtil;
import org.lsposed.manager.util.chrome.CustomTabsURLSpan;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.stream.IntStream;
import rikka.core.util.ResourceUtils;
import rikka.recyclerview.RecyclerViewKt;
import rikka.widget.borderview.BorderNestedScrollView;
import rikka.widget.borderview.BorderRecyclerView;
import rikka.widget.borderview.BorderView;
public class RepoItemFragment extends BaseFragment implements RepoLoader.Listener {
private static final String HTML_TEMPLATE = readWebviewHTML("template.html");
private static final String HTML_TEMPLATE_DARK = readWebviewHTML("template_dark.html");
FragmentPagerBinding binding;
private OnlineModule module;
private ReleaseAdapter releaseAdapter;
private static String readWebviewHTML(String name) {
try {
var input = App.getInstance().getAssets().open("webview/" + name);
var result = new ByteArrayOutputStream(1024);
var buffer = new byte[1024];
for (int length; (length = input.read(buffer)) != -1; ) {
result.write(buffer, 0, length);
}
return result.toString(StandardCharsets.UTF_8.name());
} catch (IOException e) {
Log.e(App.TAG, "read webview HTML", e);
return "<html><body>@body@</body></html>";
}
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -170,11 +150,10 @@ public class RepoItemFragment extends BaseFragment implements RepoLoader.Listene
setting.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
setting.setTextZoom(80);
String body;
int nightModeFlags = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
if (nightModeFlags == Configuration.UI_MODE_NIGHT_YES) {
body = HTML_TEMPLATE_DARK.replace("@body@", text);
if (ResourceUtils.isNightMode(getResources().getConfiguration())) {
body = RepoFragment.HTML_TEMPLATE_DARK.get().replace("@body@", text);
} else {
body = HTML_TEMPLATE.replace("@body@", text);
body = RepoFragment.HTML_TEMPLATE.get().replace("@body@", text);
}
view.setWebViewClient(new WebViewClient() {
@Override

View File

@ -32,7 +32,7 @@ import androidx.annotation.Nullable;
import org.lsposed.manager.R;
import rikka.core.res.ResourcesKt;
import rikka.core.util.ResourceUtils;
import rikka.widget.borderview.BorderRecyclerView;
public class EmptyStateRecyclerView extends BorderRecyclerView {
@ -68,7 +68,7 @@ public class EmptyStateRecyclerView extends BorderRecyclerView {
super(context, attrs, defStyle);
DisplayMetrics dm = context.getResources().getDisplayMetrics();
paint.setColor(ResourcesKt.resolveColor(context.getTheme(), android.R.attr.textColorSecondary));
paint.setColor(ResourceUtils.resolveColor(context.getTheme(), android.R.attr.textColorSecondary));
paint.setTextSize(16f * dm.scaledDensity);
emptyText = context.getString(R.string.list_empty);

View File

@ -26,7 +26,6 @@ import android.net.Uri;
import androidx.browser.customtabs.CustomTabColorSchemeParams;
import androidx.browser.customtabs.CustomTabsIntent;
import rikka.core.res.ResourcesKt;
import rikka.core.util.ResourceUtils;
public final class NavUtil {
@ -35,8 +34,8 @@ public final class NavUtil {
CustomTabsIntent.Builder customTabsIntent = new CustomTabsIntent.Builder();
customTabsIntent.setShowTitle(true);
CustomTabColorSchemeParams params = new CustomTabColorSchemeParams.Builder()
.setToolbarColor(ResourcesKt.resolveColor(activity.getTheme(), android.R.attr.colorBackground))
.setNavigationBarColor(ResourcesKt.resolveColor(activity.getTheme(), android.R.attr.navigationBarColor))
.setToolbarColor(ResourceUtils.resolveColor(activity.getTheme(), android.R.attr.colorBackground))
.setNavigationBarColor(ResourceUtils.resolveColor(activity.getTheme(), android.R.attr.navigationBarColor))
.setNavigationBarDividerColor(0)
.build();
customTabsIntent.setDefaultColorSchemeParams(params);

View File

@ -130,7 +130,7 @@
<style name="HomeItem">
<item name="android:layout_marginHorizontal">16dp</item>
<item name="android:layout_marginTop">8dp</item>
<item name="android:layout_marginBottom">8dp</item>
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
<item name="cardCornerRadius">8dp</item>

View File

@ -27,7 +27,7 @@ buildscript {
dependencies {
classpath("com.android.tools.build:gradle:7.1.0-alpha11")
classpath("org.eclipse.jgit:org.eclipse.jgit:5.12.0.202106070339-r")
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0-alpha07")
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.0-alpha08")
}
}
@ -37,7 +37,7 @@ val commitCount = Git(repo).log().add(refId).call().count()
val defaultManagerPackageName by extra("org.lsposed.manager")
val verCode by extra(commitCount + 4200)
val verName by extra("v1.5.3")
val verName by extra("1.5.3")
val androidTargetSdkVersion by extra(31)
val androidMinSdkVersion by extra(27)
val androidBuildToolsVersion by extra("31.0.0")

View File

@ -126,7 +126,7 @@ androidComponents.onVariants { v ->
else (v as AnalyticsEnabledApplicationVariant).delegate as ApplicationVariantImpl
val variantCapped = variant.name.capitalize()
val variantLowered = variant.name.toLowerCase()
val zipFileName = "$moduleName-$verName-$verCode-$variantLowered.zip"
val zipFileName = "$moduleName-v$verName-$verCode-$variantLowered.zip"
val magiskDir = "$buildDir/magisk/$variantLowered"
afterEvaluate {
@ -172,7 +172,7 @@ androidComponents.onVariants { v ->
include("module.prop")
expand(
"moduleId" to moduleId,
"versionName" to verName,
"versionName" to "v$verName",
"versionCode" to verCode,
"authorList" to authors,
"minRiruVersionName" to moduleMinRiruVersionName

View File

@ -36,7 +36,7 @@ namespace lspd {
void onModuleLoaded() {
LOGI("onModuleLoaded: welcome to LSPosed!");
LOGI("onModuleLoaded: version %s (%d)", versionName, versionCode);
LOGI("onModuleLoaded: version v%s (%d)", versionName, versionCode);
if constexpr (isDebug) {
Context::GetInstance()->PreLoadDex("/system/" + kDexPath);
} else {