From df9c40c035998fdd8a7b0c85a4980cd44447c320 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 20 Feb 2018 05:07:18 +0800 Subject: [PATCH] Move to raw resources --- .gitignore | 2 +- src/main/java/com/topjohnwu/magisk/AboutActivity.java | 10 ++-------- src/main/java/com/topjohnwu/magisk/MainActivity.java | 11 ++--------- .../com/topjohnwu/magisk/asyncs/MarkDownWindow.java | 4 +++- src/main/{assets => res/raw}/changelog.md | 0 src/main/{assets => res/raw}/dark.css | 0 src/main/{assets => res/raw}/light.css | 0 7 files changed, 8 insertions(+), 19 deletions(-) rename src/main/{assets => res/raw}/changelog.md (100%) rename src/main/{assets => res/raw}/dark.css (100%) rename src/main/{assets => res/raw}/light.css (100%) diff --git a/.gitignore b/.gitignore index 3f0eb250d..6e4d8b049 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ app/release *.hprof .externalNativeBuild/ -src/main/assets/*.sh +src/main/assets public.certificate.x509.pem private.key.pk8 *.apk diff --git a/src/main/java/com/topjohnwu/magisk/AboutActivity.java b/src/main/java/com/topjohnwu/magisk/AboutActivity.java index fb185f76b..e1b732ff9 100644 --- a/src/main/java/com/topjohnwu/magisk/AboutActivity.java +++ b/src/main/java/com/topjohnwu/magisk/AboutActivity.java @@ -14,8 +14,6 @@ import com.topjohnwu.magisk.components.AboutCardRow; import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.utils.Const; -import java.io.IOException; -import java.io.InputStream; import java.util.Locale; import butterknife.BindView; @@ -56,12 +54,8 @@ public class AboutActivity extends Activity { appChangelog.removeSummary(); appChangelog.setOnClickListener(v -> { - try { - InputStream is = getAssets().open("changelog.md"); - new MarkDownWindow(this, getString(R.string.app_changelog), is).exec(); - } catch (IOException e) { - e.printStackTrace(); - } + new MarkDownWindow(this, getString(R.string.app_changelog), + getResources().openRawResource(R.raw.changelog)).exec(); }); String translators = getString(R.string.translators); diff --git a/src/main/java/com/topjohnwu/magisk/MainActivity.java b/src/main/java/com/topjohnwu/magisk/MainActivity.java index 769b51c89..94886eda2 100644 --- a/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -23,9 +23,6 @@ import com.topjohnwu.magisk.utils.Topic; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; -import java.io.IOException; -import java.io.InputStream; - import butterknife.BindView; import butterknife.ButterKnife; @@ -99,12 +96,8 @@ public class MainActivity extends Activity if (mm.prefs.getInt(Const.Key.APP_VER, -1) < BuildConfig.VERSION_CODE) { prefs.edit().putInt(Const.Key.APP_VER, BuildConfig.VERSION_CODE).apply(); - try { - InputStream is = getAssets().open("changelog.md"); - new MarkDownWindow(this, getString(R.string.app_changelog), is).exec(); - } catch (IOException e) { - e.printStackTrace(); - } + new MarkDownWindow(this, getString(R.string.app_changelog), + getResources().openRawResource(R.raw.changelog)).exec(); } } diff --git a/src/main/java/com/topjohnwu/magisk/asyncs/MarkDownWindow.java b/src/main/java/com/topjohnwu/magisk/asyncs/MarkDownWindow.java index ece1dbc05..06a31ef92 100644 --- a/src/main/java/com/topjohnwu/magisk/asyncs/MarkDownWindow.java +++ b/src/main/java/com/topjohnwu/magisk/asyncs/MarkDownWindow.java @@ -54,11 +54,13 @@ public class MarkDownWindow extends ParallelTask { } String css; try ( - InputStream in = mm.getAssets().open(mm.isDarkTheme ? "dark.css" : "light.css"); + InputStream in = mm.getResources().openRawResource( + mm.isDarkTheme ? R.raw.dark : R.raw.light); ByteArrayOutputStream out = new ByteArrayOutputStream() ) { ShellUtils.pump(in, out); css = out.toString(); + in.close(); } catch (IOException e) { e.printStackTrace(); return ""; diff --git a/src/main/assets/changelog.md b/src/main/res/raw/changelog.md similarity index 100% rename from src/main/assets/changelog.md rename to src/main/res/raw/changelog.md diff --git a/src/main/assets/dark.css b/src/main/res/raw/dark.css similarity index 100% rename from src/main/assets/dark.css rename to src/main/res/raw/dark.css diff --git a/src/main/assets/light.css b/src/main/res/raw/light.css similarity index 100% rename from src/main/assets/light.css rename to src/main/res/raw/light.css