1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-05 06:27:30 +00:00

Merge pull request #45 from ammargitham/feature/amoled-theme

Add AMOLED dark theme
This commit is contained in:
Austin Huang 2020-08-11 12:26:12 -04:00 committed by GitHub
commit 55d2fbd6fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 119 additions and 57 deletions

1
.idea/.gitignore vendored
View File

@ -1,2 +1,3 @@
# Default ignored files
/shelf/
/dictionaries/

View File

@ -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();
}
}

View File

@ -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,36 +394,36 @@ 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;
@Override
public void onOffsetChanged(final AppBarLayout appBarLayout, final int verticalOffset) {
if (height == 0) {
height = main.mainBinding.profileView.profileInfo.getHeight();
collapsingToolbar.setMinimumHeight(height);
}
main.mainBinding.profileView.profileInfo.setTranslationY(-Math.min(0, verticalOffset));
}
});
// main.mainBinding.profileView.appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
// private int height;
//
// @Override
// public void onOffsetChanged(final AppBarLayout appBarLayout, final int verticalOffset) {
// if (height == 0) {
// height = main.mainBinding.profileView.profileInfo.getHeight();
// collapsingToolbar.setMinimumHeight(height);
// }
// main.mainBinding.profileView.profileInfo.setTranslationY(-Math.min(0, verticalOffset));
// }
// });
main.setSupportActionBar(main.mainBinding.toolbar.toolbar);
if (isBottomToolbar) {

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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<String> queriesStack;
private DataBox.CookieModel cookieModel;
public Main() {
super();
Utils.changeTheme();
}
@Override
protected void onCreate(@Nullable final Bundle bundle) {
super.onCreate(bundle);

View File

@ -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);

View File

@ -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";

View File

@ -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})

View File

@ -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);
}

View File

@ -42,7 +42,9 @@
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:background="@null"
app:elevation="0dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -98,6 +98,31 @@
android:paddingBottom="4dp" />
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:background="?android:selectableItemBackground"
android:orientation="horizontal"
android:padding="5dp">
<androidx.appcompat.widget.AppCompatCheckBox
android:id="@+id/cbAmoledTheme"
android:layout_width="30dp"
android:layout_height="30dp"
android:contentDescription="@string/use_amoled_dark_theme" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="5dp"
android:text="@string/use_amoled_dark_theme"
android:textColor="?android:textColorPrimary"
android:textSize="16sp" />
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -11,7 +11,9 @@
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:background="@null"
app:elevation="0dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -8,6 +8,7 @@
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:background="@null"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -15,7 +16,7 @@
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
app:layout_scrollFlags="scroll|enterAlways">
<RelativeLayout
android:id="@+id/infoContainer"

View File

@ -31,4 +31,7 @@
<color name="feed_text_primary_color">@color/text_color_light</color>
<color name="dm_profile_button_color">#efefef</color>
<!-- Amoled Colors -->
<color name="background_amoled">#000000</color>
</resources>

View File

@ -211,4 +211,5 @@
<string name="updated">Thank you for updating InstaGrabber!</string>
<string name="crash_title">App crashed</string>
<string name="crash_descr">Oops.. the app crashed, but don\'t worry you can send error report to the developer to help him fix the issue. (:</string>
<string name="use_amoled_dark_theme">Use AMOLED mode for Dark theme</string>
</resources>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Amoled" parent="Theme.AppCompat.NoActionBar">
<item name="android:colorBackground">@color/background_amoled</item>
<item name="bottomSheetDialogTheme">@style/AppTheme.BottomSheetDialog.Dark</item>
<item name="android:windowAnimationStyle">@style/AppTheme.WindowAnimationTransition</item>
</style>
<style name="AppTheme.BottomSheetDialog.Dark" parent="Theme.MaterialComponents.BottomSheetDialog"/>
</resources>