diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-02-02 15:16:15 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-02-02 15:16:15 +0000 |
commit | 802a70e9c9d63c799e86e1d889801d74a517212f (patch) | |
tree | fae88e1ec46f0aaecde9a324f9bd61ecd43a08a1 /app | |
parent | 7ae7827d491473b326dcf3f3c297803816f798c0 (diff) | |
download | infinity-for-reddit-802a70e9c9d63c799e86e1d889801d74a517212f.tar infinity-for-reddit-802a70e9c9d63c799e86e1d889801d74a517212f.tar.gz infinity-for-reddit-802a70e9c9d63c799e86e1d889801d74a517212f.tar.bz2 infinity-for-reddit-802a70e9c9d63c799e86e1d889801d74a517212f.tar.lz infinity-for-reddit-802a70e9c9d63c799e86e1d889801d74a517212f.tar.xz infinity-for-reddit-802a70e9c9d63c799e86e1d889801d74a517212f.tar.zst infinity-for-reddit-802a70e9c9d63c799e86e1d889801d74a517212f.zip |
Add a dark theme toggle in the navigation drawer.
Diffstat (limited to 'app')
5 files changed, 98 insertions, 30 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index ab645240..865525d2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -23,6 +23,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBarDrawerToggle; +import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.view.GravityCompat; @@ -99,6 +100,9 @@ import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + public class MainActivity extends BaseActivity implements SortTypeSelectionCallback, PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback { @@ -140,29 +144,31 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @BindView(R.id.account_label_main_activity) TextView accountLabelTextView; @BindView(R.id.profile_text_view_main_activity) - TextView profileLinearLayout; + TextView profileTextView; @BindView(R.id.subscriptions_text_view_main_activity) - TextView subscriptionLinearLayout; + TextView subscriptionTextView; @BindView(R.id.multi_reddits_text_view_main_activity) - TextView multiRedditsLinearLayout; + TextView multiRedditsTextView; @BindView(R.id.inbox_text_view_main_activity) - TextView inboxLinearLayout; + TextView inboxTextView; @BindView(R.id.post_label_main_activity) TextView postLabelTextView; @BindView(R.id.upvoted_text_view_main_activity) - TextView upvotedLinearLayout; + TextView upvotedTextView; @BindView(R.id.downvoted_text_view_main_activity) - TextView downvotedLinearLayout; + TextView downvotedTextView; @BindView(R.id.hidden_text_view_main_activity) - TextView hiddenLinearLayout; + TextView hiddenTextView; @BindView(R.id.saved_text_view_main_activity) - TextView savedLinearLayout; + TextView savedTextView; @BindView(R.id.gilded_text_view_main_activity) - TextView gildedLinearLayout; + TextView gildedTextView; @BindView(R.id.divider_main_activity) View divider; + @BindView(R.id.night_mode_toggle_text_view_main_activity) + TextView nightModeToggleTextView; @BindView(R.id.settings_text_view_main_activity) - TextView settingsLinearLayout; + TextView settingsTextView; @BindView(R.id.account_recycler_view_main_activity) RecyclerView accountRecyclerView; @BindView(R.id.tab_layout_main_activity) @@ -640,16 +646,16 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb mKarmaTextView.setText(R.string.press_here_to_login); mAccountNameTextView.setText(R.string.anonymous_account); accountLabelTextView.setVisibility(View.GONE); - profileLinearLayout.setVisibility(View.GONE); - subscriptionLinearLayout.setVisibility(View.GONE); - multiRedditsLinearLayout.setVisibility(View.GONE); - inboxLinearLayout.setVisibility(View.GONE); + profileTextView.setVisibility(View.GONE); + subscriptionTextView.setVisibility(View.GONE); + multiRedditsTextView.setVisibility(View.GONE); + inboxTextView.setVisibility(View.GONE); postLabelTextView.setVisibility(View.GONE); - upvotedLinearLayout.setVisibility(View.GONE); - downvotedLinearLayout.setVisibility(View.GONE); - hiddenLinearLayout.setVisibility(View.GONE); - savedLinearLayout.setVisibility(View.GONE); - gildedLinearLayout.setVisibility(View.GONE); + upvotedTextView.setVisibility(View.GONE); + downvotedTextView.setVisibility(View.GONE); + hiddenTextView.setVisibility(View.GONE); + savedTextView.setVisibility(View.GONE); + gildedTextView.setVisibility(View.GONE); divider.setVisibility(View.GONE); } @@ -669,66 +675,94 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb glide.load(mBannerImageUrl).into(mBannerImageView); } - profileLinearLayout.setOnClickListener(view -> { + profileTextView.setOnClickListener(view -> { Intent intent = new Intent(this, ViewUserDetailActivity.class); intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName); startActivity(intent); drawer.closeDrawers(); }); - subscriptionLinearLayout.setOnClickListener(view -> { + subscriptionTextView.setOnClickListener(view -> { Intent intent = new Intent(this, SubscribedThingListingActivity.class); startActivity(intent); drawer.closeDrawers(); }); - multiRedditsLinearLayout.setOnClickListener(view -> { + multiRedditsTextView.setOnClickListener(view -> { Intent intent = new Intent(this, MultiRedditListingActivity.class); startActivity(intent); drawer.closeDrawers(); }); - inboxLinearLayout.setOnClickListener(view -> { + inboxTextView.setOnClickListener(view -> { Intent intent = new Intent(this, ViewMessageActivity.class); startActivity(intent); drawer.closeDrawers(); }); - upvotedLinearLayout.setOnClickListener(view -> { + upvotedTextView.setOnClickListener(view -> { Intent intent = new Intent(MainActivity.this, AccountPostsActivity.class); intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_UPVOTED); startActivity(intent); drawer.closeDrawers(); }); - downvotedLinearLayout.setOnClickListener(view -> { + downvotedTextView.setOnClickListener(view -> { Intent intent = new Intent(MainActivity.this, AccountPostsActivity.class); intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_DOWNVOTED); startActivity(intent); drawer.closeDrawers(); }); - hiddenLinearLayout.setOnClickListener(view -> { + hiddenTextView.setOnClickListener(view -> { Intent intent = new Intent(MainActivity.this, AccountPostsActivity.class); intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_HIDDEN); startActivity(intent); drawer.closeDrawers(); }); - savedLinearLayout.setOnClickListener(view -> { + savedTextView.setOnClickListener(view -> { Intent intent = new Intent(MainActivity.this, AccountSavedThingActivity.class); startActivity(intent); drawer.closeDrawers(); }); - gildedLinearLayout.setOnClickListener(view -> { + gildedTextView.setOnClickListener(view -> { Intent intent = new Intent(MainActivity.this, AccountPostsActivity.class); intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_GILDED); startActivity(intent); drawer.closeDrawers(); }); - settingsLinearLayout.setOnClickListener(view -> { + if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + nightModeToggleTextView.setText(R.string.dark_theme); + nightModeToggleTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_dark_theme_24dp, 0, 0, 0); + } else { + nightModeToggleTextView.setText(R.string.light_theme); + nightModeToggleTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_light_theme_24dp, 0, 0, 0); + } + + nightModeToggleTextView.setOnClickListener(view -> { + if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + mSharedPreferences.edit().putString(SharedPreferencesUtils.THEME_KEY, "1").apply(); + nightModeToggleTextView.setText(R.string.dark_theme); + nightModeToggleTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_dark_theme_24dp, 0, 0, 0); + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { + getTheme().applyStyle(R.style.Theme_Default_AmoledDark, true); + } else { + getTheme().applyStyle(R.style.Theme_Default_NormalDark, true); + } + } else { + mSharedPreferences.edit().putString(SharedPreferencesUtils.THEME_KEY, "0").apply(); + nightModeToggleTextView.setText(R.string.light_theme); + nightModeToggleTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_light_theme_24dp, 0, 0, 0); + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + getTheme().applyStyle(R.style.Theme_Default, true); + } + }); + + settingsTextView.setOnClickListener(view -> { drawer.closeDrawers(); Intent intent = new Intent(MainActivity.this, SettingsActivity.class); startActivity(intent); diff --git a/app/src/main/res/drawable/ic_dark_theme_24dp.xml b/app/src/main/res/drawable/ic_dark_theme_24dp.xml new file mode 100644 index 00000000..24ef45dd --- /dev/null +++ b/app/src/main/res/drawable/ic_dark_theme_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#FF000000" + android:pathData="M12.7,4.91C15.25,6.24 17,8.92 17,12s-1.75,5.76 -4.3,7.09c1.46,-2 2.3,-4.46 2.3,-7.09s-0.84,-5.09 -2.3,-7.09M9,2c-1.05,0 -2.05,0.16 -3,0.46 4.06,1.27 7,5.06 7,9.54s-2.94,8.27 -7,9.54c0.95,0.3 1.95,0.46 3,0.46 5.52,0 10,-4.48 10,-10S14.52,2 9,2z"/> +</vector> diff --git a/app/src/main/res/drawable/ic_light_theme_24dp.xml b/app/src/main/res/drawable/ic_light_theme_24dp.xml new file mode 100644 index 00000000..8a7d0fe8 --- /dev/null +++ b/app/src/main/res/drawable/ic_light_theme_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#FFFFFFFF" + android:pathData="M20,8.69L20,4h-4.69L12,0.69 8.69,4L4,4v4.69L0.69,12 4,15.31L4,20h4.69L12,23.31 15.31,20L20,20v-4.69L23.31,12 20,8.69zM18,14.48L18,18h-3.52L12,20.48 9.52,18L6,18v-3.52L3.52,12 6,9.52L6,6h3.52L12,3.52 14.48,6L18,6v3.52L20.48,12 18,14.48zM12,6.5c-3.03,0 -5.5,2.47 -5.5,5.5s2.47,5.5 5.5,5.5 5.5,-2.47 5.5,-5.5 -2.47,-5.5 -5.5,-5.5zM12,15.5c-1.93,0 -3.5,-1.57 -3.5,-3.5s1.57,-3.5 3.5,-3.5 3.5,1.57 3.5,3.5 -1.57,3.5 -3.5,3.5z"/> +</vector> diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ca33eadf..798dd9c3 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -200,6 +200,19 @@ android:background="@color/dividerColor" /> <TextView + android:id="@+id/night_mode_toggle_text_view_main_activity" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:padding="16dp" + android:drawablePadding="32dp" + android:textColor="@color/primaryTextColor" + android:textSize="?attr/font_default" + android:background="?attr/selectableItemBackground" + android:clickable="true" + android:focusable="true" /> + + <TextView android:id="@+id/settings_text_view_main_activity" android:layout_width="match_parent" android:layout_height="wrap_content" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 686029d1..6d0667a7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -289,7 +289,7 @@ <string name="settings_notification_enable_notification_title">Enable Notifications</string> <string name="settings_notification_interval_title">Check Notifications Interval</string> <string name="settings_theme_title">Theme</string> - <string name="settings_theme_light__theme_summary">Light Theme</string> + <string name="settings_theme_light_theme_summary">Light Theme</string> <string name="settings_theme_dark_theme_summary">Dark Theme</string> <string name="settings_theme_system_default_summary">Device default</string> <string name="settings_amoled_dark_title">Amoled Dark</string> @@ -424,4 +424,7 @@ <string name="unsave_comment">Unsave comment</string> <string name="exit_app">Exit?</string> + + <string name="light_theme">Light Theme</string> + <string name="dark_theme">Dark Theme</string> </resources> |