From c1b113e275c1e102b79636788159c81a41907696 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Mon, 10 Aug 2020 16:33:19 +0900 Subject: [PATCH] Add AMOLED dark theme --- .idea/.gitignore | 1 + .../java/awais/instagrabber/InstaApp.java | 3 -- .../java/awais/instagrabber/MainHelper.java | 40 ++++++++----------- .../activities/BaseLanguageActivity.java | 10 +++++ .../activities/DirectMessagesUserInbox.java | 2 +- .../awais/instagrabber/activities/Main.java | 6 --- .../instagrabber/dialogs/SettingsDialog.java | 7 +++- .../awais/instagrabber/utils/Constants.java | 1 + .../instagrabber/utils/SettingsHelper.java | 3 +- .../java/awais/instagrabber/utils/Utils.java | 29 +++++++++++--- app/src/main/res/layout/activity_main.xml | 4 +- .../main/res/layout/dialog_main_settings.xml | 25 ++++++++++++ app/src/main/res/layout/layout_feed_view.xml | 4 +- .../main/res/layout/layout_profile_view.xml | 3 +- app/src/main/res/values/color.xml | 3 ++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/themes.xml | 10 +++++ 17 files changed, 107 insertions(+), 45 deletions(-) create mode 100644 app/src/main/res/values/themes.xml diff --git a/.idea/.gitignore b/.idea/.gitignore index 4b922951..530e6742 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -1,2 +1,3 @@ # Default ignored files /shelf/ +/dictionaries/ diff --git a/app/src/main/java/awais/instagrabber/InstaApp.java b/app/src/main/java/awais/instagrabber/InstaApp.java index a0e10ef7..9bc2d396 100755 --- a/app/src/main/java/awais/instagrabber/InstaApp.java +++ b/app/src/main/java/awais/instagrabber/InstaApp.java @@ -18,7 +18,6 @@ import awaisomereport.CrashReporter; import awaisomereport.LogCollector; import static awais.instagrabber.utils.Utils.NET_COOKIE_MANAGER; -import static awais.instagrabber.utils.Utils.changeTheme; import static awais.instagrabber.utils.Utils.clipboardManager; import static awais.instagrabber.utils.Utils.dataBox; import static awais.instagrabber.utils.Utils.datetimeParser; @@ -63,7 +62,5 @@ public final class InstaApp extends MultiDexApplication { settingsHelper.getString(Constants.DATE_TIME_FORMAT), LocaleUtils.getCurrentLocale()); settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString()); - - changeTheme(); } } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/MainHelper.java b/app/src/main/java/awais/instagrabber/MainHelper.java index 01603893..23fb0fe3 100755 --- a/app/src/main/java/awais/instagrabber/MainHelper.java +++ b/app/src/main/java/awais/instagrabber/MainHelper.java @@ -5,13 +5,10 @@ import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.graphics.Canvas; import android.graphics.Typeface; -import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; -import android.os.Handler; import android.text.SpannableStringBuilder; import android.text.method.LinkMovementMethod; import android.text.style.RelativeSizeSpan; @@ -37,7 +34,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.shape.MaterialShapeDrawable; import java.io.DataOutputStream; import java.io.InputStream; @@ -77,10 +73,8 @@ import awais.instagrabber.models.DiscoverItemModel; import awais.instagrabber.models.DiscoverTopicModel; import awais.instagrabber.models.FeedModel; import awais.instagrabber.models.FeedStoryModel; -import awais.instagrabber.models.HashtagModel; import awais.instagrabber.models.IntentModel; import awais.instagrabber.models.PostModel; -import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.enums.IntentModelType; import awais.instagrabber.models.enums.ItemGetType; import awais.instagrabber.utils.Constants; @@ -400,23 +394,23 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { main.mainBinding.profileView.highlightsList.setLayoutManager(new LinearLayoutManager(main, LinearLayoutManager.HORIZONTAL, false)); main.mainBinding.profileView.highlightsList.setAdapter(main.highlightsAdapter); - int color = -1; - final Drawable background = main.mainBinding.profileView.appBarLayout.getBackground(); - if (background instanceof MaterialShapeDrawable) { - final MaterialShapeDrawable drawable = (MaterialShapeDrawable) background; - final ColorStateList fillColor = drawable.getFillColor(); - if (fillColor != null) color = fillColor.getDefaultColor(); - } else { - final Bitmap bitmap = Bitmap.createBitmap(9, 9, Bitmap.Config.ARGB_8888); - final Canvas canvas = new Canvas(); - canvas.setBitmap(bitmap); - background.draw(canvas); - color = bitmap.getPixel(4, 4); - if (!bitmap.isRecycled()) bitmap.recycle(); - } - if (color == -1 || color == 0) color = resources.getBoolean(R.bool.isNight) ? 0xff212121 : 0xfff5f5f5; - main.mainBinding.profileView.profileInfo.setBackgroundColor(color); - if (!isBottomToolbar) main.mainBinding.toolbar.toolbar.setBackgroundColor(color); + // int color = -1; + // final Drawable background = main.mainBinding.profileView.appBarLayout.getBackground(); + // if (background instanceof MaterialShapeDrawable) { + // final MaterialShapeDrawable drawable = (MaterialShapeDrawable) background; + // final ColorStateList fillColor = drawable.getFillColor(); + // if (fillColor != null) color = fillColor.getDefaultColor(); + // } else { + // final Bitmap bitmap = Bitmap.createBitmap(9, 9, Bitmap.Config.ARGB_8888); + // final Canvas canvas = new Canvas(); + // canvas.setBitmap(bitmap); + // background.draw(canvas); + // color = bitmap.getPixel(4, 4); + // if (!bitmap.isRecycled()) bitmap.recycle(); + // } + // if (color == -1 || color == 0) color = resources.getBoolean(R.bool.isNight) ? 0xff212121 : 0xfff5f5f5; + // main.mainBinding.profileView.profileInfo.setBackgroundColor(color); + // if (!isBottomToolbar) main.mainBinding.toolbar.toolbar.setBackgroundColor(color); main.mainBinding.profileView.appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { private int height; diff --git a/app/src/main/java/awais/instagrabber/activities/BaseLanguageActivity.java b/app/src/main/java/awais/instagrabber/activities/BaseLanguageActivity.java index 781aa5ea..20f6289e 100755 --- a/app/src/main/java/awais/instagrabber/activities/BaseLanguageActivity.java +++ b/app/src/main/java/awais/instagrabber/activities/BaseLanguageActivity.java @@ -1,11 +1,21 @@ package awais.instagrabber.activities; +import android.os.Bundle; + +import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import awais.instagrabber.utils.LocaleUtils; +import awais.instagrabber.utils.Utils; public abstract class BaseLanguageActivity extends AppCompatActivity { protected BaseLanguageActivity() { LocaleUtils.updateConfig(this); } + + @Override + protected void onCreate(@Nullable final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Utils.changeTheme(this); + } } diff --git a/app/src/main/java/awais/instagrabber/activities/DirectMessagesUserInbox.java b/app/src/main/java/awais/instagrabber/activities/DirectMessagesUserInbox.java index 23cea34b..698829e3 100755 --- a/app/src/main/java/awais/instagrabber/activities/DirectMessagesUserInbox.java +++ b/app/src/main/java/awais/instagrabber/activities/DirectMessagesUserInbox.java @@ -42,7 +42,7 @@ import awais.instagrabber.utils.Utils; import static awais.instagrabber.utils.Utils.settingsHelper; -public final class DirectMessagesUserInbox extends AppCompatActivity { +public final class DirectMessagesUserInbox extends BaseLanguageActivity { private DirectItemModel directItemModel; private final ProfileModel myProfileHolder = new ProfileModel(false, false, false, null, null, null, null, null, null, null, 0, 0, 0, false, false, false, false); diff --git a/app/src/main/java/awais/instagrabber/activities/Main.java b/app/src/main/java/awais/instagrabber/activities/Main.java index c1f1ca21..ea4bc9e7 100755 --- a/app/src/main/java/awais/instagrabber/activities/Main.java +++ b/app/src/main/java/awais/instagrabber/activities/Main.java @@ -9,7 +9,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.PersistableBundle; import android.provider.BaseColumns; -import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -108,11 +107,6 @@ public final class Main extends BaseLanguageActivity { private Stack queriesStack; private DataBox.CookieModel cookieModel; - public Main() { - super(); - Utils.changeTheme(); - } - @Override protected void onCreate(@Nullable final Bundle bundle) { super.onCreate(bundle); diff --git a/app/src/main/java/awais/instagrabber/dialogs/SettingsDialog.java b/app/src/main/java/awais/instagrabber/dialogs/SettingsDialog.java index 604ff987..81402aaa 100755 --- a/app/src/main/java/awais/instagrabber/dialogs/SettingsDialog.java +++ b/app/src/main/java/awais/instagrabber/dialogs/SettingsDialog.java @@ -33,6 +33,7 @@ import awais.instagrabber.utils.LocaleUtils; import awais.instagrabber.utils.Utils; import awaisomereport.CrashReporter; +import static awais.instagrabber.utils.Constants.AMOLED_THEME; import static awais.instagrabber.utils.Constants.APP_LANGUAGE; import static awais.instagrabber.utils.Constants.APP_THEME; import static awais.instagrabber.utils.Constants.AUTOLOAD_POSTS; @@ -44,7 +45,6 @@ import static awais.instagrabber.utils.Constants.FOLDER_SAVE_TO; import static awais.instagrabber.utils.Constants.INSTADP; import static awais.instagrabber.utils.Constants.MARK_AS_SEEN; import static awais.instagrabber.utils.Constants.MUTED_VIDEOS; -import static awais.instagrabber.utils.Constants.SHOW_FEED; import static awais.instagrabber.utils.Constants.STORIESIG; import static awais.instagrabber.utils.Utils.settingsHelper; @@ -130,6 +130,7 @@ public final class SettingsDialog extends BottomSheetDialogFragment implements V final AppCompatCheckBox cbMarkAsSeen = contentView.findViewById(R.id.cbMarkAsSeen); final AppCompatCheckBox cbInstadp = contentView.findViewById(R.id.cbInstadp); final AppCompatCheckBox cbStoriesig = contentView.findViewById(R.id.cbStoriesig); + final AppCompatCheckBox cbAmoledTheme = contentView.findViewById(R.id.cbAmoledTheme); cbSaveTo.setChecked(settingsHelper.getBoolean(FOLDER_SAVE_TO)); cbMuteVideos.setChecked(settingsHelper.getBoolean(MUTED_VIDEOS)); @@ -138,7 +139,7 @@ public final class SettingsDialog extends BottomSheetDialogFragment implements V cbMarkAsSeen.setChecked(settingsHelper.getBoolean(MARK_AS_SEEN)); cbInstadp.setChecked(settingsHelper.getBoolean(INSTADP)); cbStoriesig.setChecked(settingsHelper.getBoolean(STORIESIG)); - + cbAmoledTheme.setChecked(settingsHelper.getBoolean(AMOLED_THEME)); cbAutoloadPosts.setChecked(settingsHelper.getBoolean(AUTOLOAD_POSTS)); cbDownloadUsername.setChecked(settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER)); @@ -151,6 +152,7 @@ public final class SettingsDialog extends BottomSheetDialogFragment implements V setupListener(cbMarkAsSeen); setupListener(cbInstadp); setupListener(cbStoriesig); + setupListener(cbAmoledTheme); btnSaveTo.setEnabled(cbSaveTo.isChecked()); @@ -221,6 +223,7 @@ public final class SettingsDialog extends BottomSheetDialogFragment implements V else if (id == R.id.cbMarkAsSeen) settingsHelper.putBoolean(MARK_AS_SEEN, checked); else if (id == R.id.cbInstadp) settingsHelper.putBoolean(INSTADP, checked); else if (id == R.id.cbStoriesig) settingsHelper.putBoolean(STORIESIG, checked); + else if (id == R.id.cbAmoledTheme) settingsHelper.putBoolean(AMOLED_THEME, checked); else if (id == R.id.cbSaveTo) { settingsHelper.putBoolean(FOLDER_SAVE_TO, checked); btnSaveTo.setEnabled(checked); diff --git a/app/src/main/java/awais/instagrabber/utils/Constants.java b/app/src/main/java/awais/instagrabber/utils/Constants.java index b51d2500..e8aab8db 100755 --- a/app/src/main/java/awais/instagrabber/utils/Constants.java +++ b/app/src/main/java/awais/instagrabber/utils/Constants.java @@ -22,6 +22,7 @@ public final class Constants { public static final String MARK_AS_SEEN = "mark_as_seen"; public static final String INSTADP = "instadp"; public static final String STORIESIG = "storiesig"; + public static final String AMOLED_THEME = "amoled_theme"; // never Export public static final String COOKIE = "cookie"; public static final String SHOW_QUICK_ACCESS_DIALOG = "show_quick_dlg"; diff --git a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java index 12517f36..53d07f47 100755 --- a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java +++ b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java @@ -8,6 +8,7 @@ import androidx.annotation.NonNull; import androidx.annotation.StringDef; import androidx.appcompat.app.AppCompatDelegate; +import static awais.instagrabber.utils.Constants.AMOLED_THEME; import static awais.instagrabber.utils.Constants.APP_LANGUAGE; import static awais.instagrabber.utils.Constants.APP_THEME; import static awais.instagrabber.utils.Constants.AUTOLOAD_POSTS; @@ -109,7 +110,7 @@ public final class SettingsHelper { public @interface StringSettings {} @StringDef({DOWNLOAD_USER_FOLDER, BOTTOM_TOOLBAR, FOLDER_SAVE_TO, AUTOPLAY_VIDEOS, SHOW_QUICK_ACCESS_DIALOG, MUTED_VIDEOS, - AUTOLOAD_POSTS, CUSTOM_DATE_TIME_FORMAT_ENABLED, MARK_AS_SEEN, INSTADP, STORIESIG}) + AUTOLOAD_POSTS, CUSTOM_DATE_TIME_FORMAT_ENABLED, MARK_AS_SEEN, INSTADP, STORIESIG, AMOLED_THEME}) public @interface BooleanSettings {} @StringDef({APP_THEME, APP_LANGUAGE, PREV_INSTALL_VERSION}) diff --git a/app/src/main/java/awais/instagrabber/utils/Utils.java b/app/src/main/java/awais/instagrabber/utils/Utils.java index 74fbf7db..dce62017 100755 --- a/app/src/main/java/awais/instagrabber/utils/Utils.java +++ b/app/src/main/java/awais/instagrabber/utils/Utils.java @@ -10,6 +10,7 @@ import android.content.ContentResolver; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.res.Configuration; import android.content.res.Resources; import android.net.Uri; import android.os.AsyncTask; @@ -19,7 +20,6 @@ import android.text.Editable; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.Spanned; -import android.text.style.RelativeSizeSpan; import android.text.style.URLSpan; import android.util.DisplayMetrics; import android.util.Log; @@ -71,10 +71,7 @@ import awais.instagrabber.asyncs.PostFetcher; import awais.instagrabber.customviews.CommentMentionClickSpan; import awais.instagrabber.databinding.DialogImportExportBinding; import awais.instagrabber.models.BasePostModel; -import awais.instagrabber.models.FeedStoryModel; -import awais.instagrabber.models.HighlightModel; import awais.instagrabber.models.IntentModel; -import awais.instagrabber.models.stickers.PollModel; import awais.instagrabber.models.ProfileModel; import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.direct_messages.DirectItemModel; @@ -88,7 +85,6 @@ import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.enums.NotificationType; import awais.instagrabber.models.enums.RavenExpiringMediaType; import awais.instagrabber.models.enums.RavenMediaViewType; -import awais.instagrabber.models.stickers.QuestionModel; import awaisomereport.LogCollector; import static awais.instagrabber.models.direct_messages.DirectItemModel.DirectItemActionLogModel; @@ -792,7 +788,7 @@ public final class Utils { return Math.round((dp * displayMetrics.densityDpi) / 160.0f); } - public static void changeTheme() { + public static void changeTheme(final Context context) { int themeCode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; // this is fallback / default if (settingsHelper != null) themeCode = settingsHelper.getThemeCode(false); @@ -800,6 +796,27 @@ public final class Utils { if (themeCode == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM && Build.VERSION.SDK_INT < 29) themeCode = AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; + boolean isAmoledEnabled = false; + if (settingsHelper != null) { + isAmoledEnabled = settingsHelper.getBoolean(Constants.AMOLED_THEME); + } + // use amoled theme only if enabled in settings + if (isAmoledEnabled) { + // check if setting is set to 'Dark' + boolean isNight = themeCode == AppCompatDelegate.MODE_NIGHT_YES; + // if not dark check if themeCode is MODE_NIGHT_FOLLOW_SYSTEM or MODE_NIGHT_AUTO_BATTERY + if (!isNight && (themeCode == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM || themeCode == AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY)) { + // check if resulting theme would be NIGHT + final int uiMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + isNight = uiMode == Configuration.UI_MODE_NIGHT_YES; + } + if (isNight) { + // set amoled theme + Log.d("InstaGrabber", "settings amoled theme"); + context.setTheme(R.style.Theme_Amoled); + return; + } + } AppCompatDelegate.setDefaultNightMode(themeCode); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2ffe1d10..47dd39f0 100755 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -42,7 +42,9 @@ + android:layout_height="wrap_content" + android:background="@null" + app:elevation="0dp"> + + + + + + + + android:layout_height="wrap_content" + android:background="@null" + app:elevation="0dp"> @@ -15,7 +16,7 @@ + app:layout_scrollFlags="noScroll"> @color/text_color_light #efefef + + + #000000 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c8c04d46..c0ab2dea 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -211,4 +211,5 @@ Thank you for updating InstaGrabber! App crashed Oops.. the app crashed, but don\'t worry you can send error report to the developer to help him fix the issue. (: + Use AMOLED mode for Dark theme diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 00000000..5a10e802 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,10 @@ + + + + +