aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-03-20 09:52:50 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-03-20 09:52:50 +0000
commitc827d6f1cd03505083ed6baf914f77682c2861a6 (patch)
tree1fc6d75a43c612193a9b8504e246c34bdb580d3a /app/src/main/java
parent587dfccd32fadcf402f128da08bd9859b1dac06e (diff)
downloadinfinity-for-reddit-c827d6f1cd03505083ed6baf914f77682c2861a6.tar
infinity-for-reddit-c827d6f1cd03505083ed6baf914f77682c2861a6.tar.gz
infinity-for-reddit-c827d6f1cd03505083ed6baf914f77682c2861a6.tar.bz2
infinity-for-reddit-c827d6f1cd03505083ed6baf914f77682c2861a6.tar.lz
infinity-for-reddit-c827d6f1cd03505083ed6baf914f77682c2861a6.tar.xz
infinity-for-reddit-c827d6f1cd03505083ed6baf914f77682c2861a6.tar.zst
infinity-for-reddit-c827d6f1cd03505083ed6baf914f77682c2861a6.zip
Customizing light, dark and amoled themes is now available.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java73
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java35
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java78
3 files changed, 178 insertions, 8 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java
index e345cc8f..b496502f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java
@@ -3,7 +3,9 @@ package ml.docilealligator.infinityforreddit.Activity;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
+import android.view.Menu;
import android.view.MenuItem;
+import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
@@ -23,6 +25,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Adapter.CustomizeThemeRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCustomThemeAsyncTask;
+import ml.docilealligator.infinityforreddit.AsyncTask.InsertCustomThemeAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeSettingsItem;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeViewModel;
@@ -30,6 +33,7 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils;
public class CustomizeThemeActivity extends BaseActivity {
@@ -54,6 +58,10 @@ public class CustomizeThemeActivity extends BaseActivity {
CustomThemeWrapper customThemeWrapper;
public CustomThemeViewModel customThemeViewModel;
+
+ private int themeType;
+ private String themeName;
+ private ArrayList<CustomThemeSettingsItem> customThemeSettingsItems;
private CustomizeThemeRecyclerViewAdapter adapter;
@Override
@@ -67,7 +75,6 @@ public class CustomizeThemeActivity extends BaseActivity {
applyCustomTheme();
- setTitle(getIntent().getStringExtra(EXTRA_THEME_NAME));
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@@ -75,13 +82,14 @@ public class CustomizeThemeActivity extends BaseActivity {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
- customThemeViewModel = new ViewModelProvider(this, new CustomThemeViewModel.Factory(redditDataRoomDatabase))
- .get(CustomThemeViewModel.class);
+ customThemeSettingsItems = new ArrayList<>();
int androidVersion = Build.VERSION.SDK_INT;
if (getIntent().hasExtra(EXTRA_THEME_TYPE)) {
+ customThemeViewModel = new ViewModelProvider(this, new CustomThemeViewModel.Factory(redditDataRoomDatabase))
+ .get(CustomThemeViewModel.class);
LiveData<CustomTheme> customThemeLiveData;
- int themeType = getIntent().getIntExtra(EXTRA_THEME_TYPE, EXTRA_LIGHT_THEME);
+ themeType = getIntent().getIntExtra(EXTRA_THEME_TYPE, EXTRA_LIGHT_THEME);
switch (themeType) {
case EXTRA_DARK_THEME:
setTitle(getString(R.string.customize_dark_theme_fragment_title));
@@ -98,7 +106,6 @@ public class CustomizeThemeActivity extends BaseActivity {
}
customThemeLiveData.observe(this, customTheme -> {
- ArrayList<CustomThemeSettingsItem> customThemeSettingsItems;
if (customTheme == null) {
switch (themeType) {
case EXTRA_DARK_THEME:
@@ -130,18 +137,68 @@ public class CustomizeThemeActivity extends BaseActivity {
adapter.setCustomThemeSettingsItem(customThemeSettingsItems);
});
} else {
- new GetCustomThemeAsyncTask(redditDataRoomDatabase, getIntent().getStringExtra(EXTRA_THEME_NAME),
- customTheme -> adapter.setCustomThemeSettingsItem(
- CustomThemeSettingsItem.convertCustomThemeToSettingsItem(CustomizeThemeActivity.this, customTheme))).execute();
+ themeName = getIntent().getStringExtra(EXTRA_THEME_NAME);
+ setTitle(themeName);
+ new GetCustomThemeAsyncTask(redditDataRoomDatabase, themeName,
+ customTheme -> {
+ customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem(CustomizeThemeActivity.this, customTheme);
+ adapter.setCustomThemeSettingsItem(customThemeSettingsItems);
+ }).execute();
}
}
@Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.customize_theme_activity, menu);
+ applyMenuItemTheme(menu);
+ return true;
+ }
+
+ @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
+ case R.id.action_save_customize_theme_activity:
+ if (themeName == null) {
+ switch (themeType) {
+ case CustomThemeSharedPreferencesUtils.DARK:
+ themeName = "Indigo Dark";
+ break;
+ case CustomThemeSharedPreferencesUtils.AMOLED:
+ themeName = "Indigo Amoled";
+ break;
+ default:
+ themeName = "Indigo";
+ }
+ }
+
+ CustomTheme customTheme = CustomTheme.convertSettingsItemsToCustomTheme(customThemeSettingsItems, themeName);
+
+ switch (themeType) {
+ case CustomThemeSharedPreferencesUtils.DARK:
+ customTheme.isLightTheme = false;
+ customTheme.isDarkTheme = true;
+ customTheme.isAmoledTheme = false;
+ break;
+ case CustomThemeSharedPreferencesUtils.AMOLED:
+ customTheme.isLightTheme = false;
+ customTheme.isDarkTheme = false;
+ customTheme.isAmoledTheme = true;
+ break;
+ default:
+ customTheme.isLightTheme = true;
+ customTheme.isDarkTheme = false;
+ customTheme.isAmoledTheme = false;
+ }
+
+ new InsertCustomThemeAsyncTask(redditDataRoomDatabase, customTheme, () -> {
+ Toast.makeText(CustomizeThemeActivity.this, R.string.saved, Toast.LENGTH_SHORT).show();
+ finish();
+ }).execute();
+
+ return true;
}
return false;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java
new file mode 100644
index 00000000..2bdb149d
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java
@@ -0,0 +1,35 @@
+package ml.docilealligator.infinityforreddit.AsyncTask;
+
+import android.os.AsyncTask;
+
+import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme;
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+
+public class InsertCustomThemeAsyncTask extends AsyncTask<Void, Void, Void> {
+ private RedditDataRoomDatabase redditDataRoomDatabase;
+ private InsertCustomThemeAsyncTaskListener insertCustomThemeAsyncTaskListener;
+ private CustomTheme customTheme;
+
+ public interface InsertCustomThemeAsyncTaskListener {
+ void success();
+ }
+
+ public InsertCustomThemeAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, CustomTheme customTheme,
+ InsertCustomThemeAsyncTaskListener insertCustomThemeAsyncTaskListener) {
+ this.redditDataRoomDatabase = redditDataRoomDatabase;
+ this.customTheme = customTheme;
+ this.insertCustomThemeAsyncTaskListener = insertCustomThemeAsyncTaskListener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ redditDataRoomDatabase.customThemeDao().insert(customTheme);
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ insertCustomThemeAsyncTaskListener.success();
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java
index bb7da9db..374030ac 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java
@@ -5,6 +5,8 @@ import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
+import java.util.ArrayList;
+
@Entity(tableName = "custom_themes")
public class CustomTheme {
@PrimaryKey
@@ -151,4 +153,80 @@ public class CustomTheme {
public CustomTheme(@NonNull String name) {
this.name = name;
}
+
+ public static CustomTheme convertSettingsItemsToCustomTheme(ArrayList<CustomThemeSettingsItem> customThemeSettingsItems, String themeName) {
+ CustomTheme customTheme = new CustomTheme(themeName);
+
+ if (customThemeSettingsItems.isEmpty()) {
+ return customTheme;
+ }
+
+ customTheme.colorPrimary = customThemeSettingsItems.get(0).colorValue;
+ customTheme.colorPrimaryDark = customThemeSettingsItems.get(1).colorValue;
+ customTheme.colorAccent = customThemeSettingsItems.get(2).colorValue;
+ customTheme.colorPrimaryLightTheme = customThemeSettingsItems.get(3).colorValue;
+ customTheme.primaryTextColor = customThemeSettingsItems.get(4).colorValue;
+ customTheme.secondaryTextColor = customThemeSettingsItems.get(5).colorValue;
+ customTheme.postTitleColor = customThemeSettingsItems.get(6).colorValue;
+ customTheme.postContentColor = customThemeSettingsItems.get(7).colorValue;
+ customTheme.commentColor = customThemeSettingsItems.get(8).colorValue;
+ customTheme.buttonTextColor = customThemeSettingsItems.get(9).colorValue;
+ customTheme.chipTextColor = customThemeSettingsItems.get(10).colorValue;
+ customTheme.backgroundColor = customThemeSettingsItems.get(11).colorValue;
+ customTheme.cardViewBackgroundColor = customThemeSettingsItems.get(12).colorValue;
+ customTheme.commentBackgroundColor = customThemeSettingsItems.get(13).colorValue;
+ customTheme.bottomAppBarBackgroundColor = customThemeSettingsItems.get(14).colorValue;
+ customTheme.primaryIconColor = customThemeSettingsItems.get(15).colorValue;
+ customTheme.postIconAndInfoColor = customThemeSettingsItems.get(16).colorValue;
+ customTheme.commentIconAndInfoColor = customThemeSettingsItems.get(17).colorValue;
+ customTheme.fabIconColor = customThemeSettingsItems.get(18).colorValue;
+ customTheme.toolbarPrimaryTextAndIconColor = customThemeSettingsItems.get(19).colorValue;
+ customTheme.toolbarSecondaryTextColor = customThemeSettingsItems.get(20).colorValue;
+ customTheme.circularProgressBarBackground = customThemeSettingsItems.get(21).colorValue;
+ customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = customThemeSettingsItems.get(22).colorValue;
+ customTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = customThemeSettingsItems.get(23).colorValue;
+ customTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(24).colorValue;
+ customTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = customThemeSettingsItems.get(25).colorValue;
+ customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = customThemeSettingsItems.get(26).colorValue;
+ customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(27).colorValue;
+ customTheme.upvoted = customThemeSettingsItems.get(28).colorValue;
+ customTheme.downvoted = customThemeSettingsItems.get(29).colorValue;
+ customTheme.postTypeBackgroundColor = customThemeSettingsItems.get(30).colorValue;
+ customTheme.postTypeTextColor = customThemeSettingsItems.get(31).colorValue;
+ customTheme.spoilerBackgroundColor = customThemeSettingsItems.get(32).colorValue;
+ customTheme.spoilerTextColor = customThemeSettingsItems.get(33).colorValue;
+ customTheme.nsfwBackgroundColor = customThemeSettingsItems.get(34).colorValue;
+ customTheme.nsfwTextColor = customThemeSettingsItems.get(35).colorValue;
+ customTheme.flairBackgroundColor = customThemeSettingsItems.get(36).colorValue;
+ customTheme.flairTextColor = customThemeSettingsItems.get(37).colorValue;
+ customTheme.archivedTint = customThemeSettingsItems.get(38).colorValue;
+ customTheme.lockedIconTint = customThemeSettingsItems.get(39).colorValue;
+ customTheme.crosspostIconTint = customThemeSettingsItems.get(40).colorValue;
+ customTheme.stickiedPostIconTint = customThemeSettingsItems.get(41).colorValue;
+ customTheme.subscribed = customThemeSettingsItems.get(42).colorValue;
+ customTheme.unsubscribed = customThemeSettingsItems.get(43).colorValue;
+ customTheme.username = customThemeSettingsItems.get(44).colorValue;
+ customTheme.subreddit = customThemeSettingsItems.get(45).colorValue;
+ customTheme.authorFlairTextColor = customThemeSettingsItems.get(46).colorValue;
+ customTheme.submitter = customThemeSettingsItems.get(47).colorValue;
+ customTheme.moderator = customThemeSettingsItems.get(48).colorValue;
+ customTheme.singleCommentThreadBackgroundColor = customThemeSettingsItems.get(49).colorValue;
+ customTheme.unreadMessageBackgroundColor = customThemeSettingsItems.get(50).colorValue;
+ customTheme.dividerColor = customThemeSettingsItems.get(51).colorValue;
+ customTheme.noPreviewLinkBackgroundColor = customThemeSettingsItems.get(52).colorValue;
+ customTheme.voteAndReplyUnavailableButtonColor = customThemeSettingsItems.get(53).colorValue;
+ customTheme.commentVerticalBarColor1 = customThemeSettingsItems.get(54).colorValue;
+ customTheme.commentVerticalBarColor2 = customThemeSettingsItems.get(55).colorValue;
+ customTheme.commentVerticalBarColor3 = customThemeSettingsItems.get(56).colorValue;
+ customTheme.commentVerticalBarColor4 = customThemeSettingsItems.get(57).colorValue;
+ customTheme.commentVerticalBarColor5 = customThemeSettingsItems.get(58).colorValue;
+ customTheme.commentVerticalBarColor6 = customThemeSettingsItems.get(59).colorValue;
+ customTheme.commentVerticalBarColor7 = customThemeSettingsItems.get(60).colorValue;
+ customTheme.navBarColor = customThemeSettingsItems.get(61).colorValue;
+ customTheme.isLightStatusBar = customThemeSettingsItems.get(62).isEnabled;
+ customTheme.isLightNavBar = customThemeSettingsItems.get(63).isEnabled;
+ customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = customThemeSettingsItems.get(64).isEnabled;
+
+ return customTheme;
+ }
}