From 9ca494d4b5409b12b8262194f736284036858c01 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 20 Sep 2019 21:27:00 +0800 Subject: Changing font size is available. Delete duplicate Edit menu in comments. --- .../main/java/Settings/MainPreferenceFragment.java | 20 ++++++-- .../infinityforreddit/AccountPostsActivity.java | 8 +++- .../AccountSavedThingActivity.java | 8 +++- .../infinityforreddit/AppComponent.java | 1 + .../infinityforreddit/ChangeFontSizeEvent.java | 8 ++++ .../infinityforreddit/CommentActivity.java | 8 +++- .../infinityforreddit/EditCommentActivity.java | 8 +++- .../infinityforreddit/EditPostActivity.java | 8 +++- .../infinityforreddit/FilteredThingActivity.java | 8 +++- .../infinityforreddit/FontStyle.java | 24 ++++++++++ .../infinityforreddit/MainActivity.java | 12 ++++- .../infinityforreddit/PostDataSource.java | 3 ++ .../infinityforreddit/PostDataSourceFactory.java | 4 ++ .../infinityforreddit/PostFragment.java | 1 + .../infinityforreddit/PostImageActivity.java | 8 +++- .../infinityforreddit/PostLinkActivity.java | 8 +++- .../infinityforreddit/PostTextActivity.java | 8 +++- .../infinityforreddit/PostVideoActivity.java | 8 +++- .../infinityforreddit/PostViewModel.java | 4 ++ .../infinityforreddit/RulesActivity.java | 8 +++- .../infinityforreddit/SearchActivity.java | 8 +++- .../infinityforreddit/SearchResultActivity.java | 8 +++- .../SearchSubredditsResultActivity.java | 8 +++- .../infinityforreddit/SettingsActivity.java | 8 +++- .../infinityforreddit/SharedPreferencesUtils.java | 1 + .../SubredditSelectionActivity.java | 8 +++- .../SubscribedThingListingActivity.java | 8 +++- .../infinityforreddit/ViewImageActivity.java | 13 +++++ .../infinityforreddit/ViewMessageActivity.java | 8 +++- .../infinityforreddit/ViewPostDetailActivity.java | 8 +++- .../ViewSubredditDetailActivity.java | 8 +++- .../infinityforreddit/ViewUserDetailActivity.java | 8 +++- app/src/main/res/layout/activity_comment.xml | 4 +- app/src/main/res/layout/activity_edit_comment.xml | 2 +- app/src/main/res/layout/activity_edit_post.xml | 4 +- app/src/main/res/layout/activity_main.xml | 33 ++++++++----- app/src/main/res/layout/activity_post_image.xml | 12 +++-- app/src/main/res/layout/activity_post_link.xml | 13 +++-- app/src/main/res/layout/activity_post_text.xml | 13 +++-- app/src/main/res/layout/activity_post_video.xml | 12 +++-- app/src/main/res/layout/activity_rules.xml | 1 + app/src/main/res/layout/activity_search.xml | 6 ++- app/src/main/res/layout/activity_view_image.xml | 3 +- app/src/main/res/layout/activity_view_message.xml | 3 +- .../main/res/layout/activity_view_post_detail.xml | 3 +- .../res/layout/activity_view_subreddit_detail.xml | 7 ++- .../main/res/layout/activity_view_user_detail.xml | 3 +- app/src/main/res/layout/dialog_edit_flair.xml | 3 +- .../main/res/layout/fragment_comments_listing.xml | 3 +- .../res/layout/fragment_flair_bottom_sheet.xml | 5 +- .../res/layout/fragment_followed_users_listing.xml | 3 +- .../fragment_modify_comment_bottom_sheet.xml | 16 +------ app/src/main/res/layout/fragment_post.xml | 3 +- .../res/layout/fragment_post_type_bottom_sheet.xml | 12 +++-- ...fragment_search_post_sort_type_bottom_sheet.xml | 5 ++ ...h_user_and_subreddit_sort_type_bottom_sheet.xml | 2 + .../res/layout/fragment_sort_type_bottom_sheet.xml | 7 +++ .../main/res/layout/fragment_subreddit_listing.xml | 3 +- .../fragment_subscribed_subreddits_listing.xml | 3 +- app/src/main/res/layout/fragment_user_listing.xml | 3 +- .../fragment_user_thing_sort_type_bottom_sheet.xml | 4 ++ app/src/main/res/layout/item_account.xml | 3 +- app/src/main/res/layout/item_acknowledgement.xml | 5 +- app/src/main/res/layout/item_comment.xml | 6 ++- .../main/res/layout/item_comment_footer_error.xml | 5 +- app/src/main/res/layout/item_flair.xml | 3 +- app/src/main/res/layout/item_footer_error.xml | 5 +- .../item_load_comments_failed_placeholder.xml | 3 +- .../layout/item_load_more_comments_placeholder.xml | 3 +- app/src/main/res/layout/item_message.xml | 11 +++-- .../res/layout/item_no_comment_placeholder.xml | 3 +- app/src/main/res/layout/item_post.xml | 20 ++++---- app/src/main/res/layout/item_post_detail.xml | 24 ++++++---- app/src/main/res/layout/item_rule.xml | 5 +- app/src/main/res/layout/item_subreddit_listing.xml | 1 + app/src/main/res/layout/item_subscribed_thing.xml | 5 +- app/src/main/res/layout/item_user_listing.xml | 3 +- app/src/main/res/layout/item_view_all_comments.xml | 3 +- app/src/main/res/layout/nav_header_main.xml | 4 +- app/src/main/res/values/arrays.xml | 14 ++++++ app/src/main/res/values/attr.xml | 8 ++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 56 ++++++++++++++++++++++ app/src/main/res/xml/main_preferences.xml | 8 ++++ 84 files changed, 496 insertions(+), 153 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/ChangeFontSizeEvent.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FontStyle.java (limited to 'app') diff --git a/app/src/main/java/Settings/MainPreferenceFragment.java b/app/src/main/java/Settings/MainPreferenceFragment.java index 11093bf6..847112a9 100644 --- a/app/src/main/java/Settings/MainPreferenceFragment.java +++ b/app/src/main/java/Settings/MainPreferenceFragment.java @@ -15,6 +15,7 @@ import org.greenrobot.eventbus.EventBus; import javax.inject.Inject; +import ml.docilealligator.infinityforreddit.ChangeFontSizeEvent; import ml.docilealligator.infinityforreddit.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Infinity; @@ -44,7 +45,8 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY); SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY); - ListPreference listPreference = findPreference(SharedPreferencesUtils.THEME_KEY); + ListPreference themePreference = findPreference(SharedPreferencesUtils.THEME_KEY); + ListPreference fontSizePreference = findPreference(SharedPreferencesUtils.FONT_SIZE_KEY); if(nsfwSwitch != null) { nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> { @@ -73,14 +75,14 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; - if(listPreference != null) { + if(themePreference != null) { if(systemDefault) { - listPreference.setEntries(R.array.settings_theme_q); + themePreference.setEntries(R.array.settings_theme_q); } else { - listPreference.setEntries(R.array.settings_theme); + themePreference.setEntries(R.array.settings_theme); } - listPreference.setOnPreferenceChangeListener((preference, newValue) -> { + themePreference.setOnPreferenceChangeListener((preference, newValue) -> { int option = Integer.parseInt((String) newValue); switch (option) { case 0: @@ -99,6 +101,14 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { return true; }); } + + if(fontSizePreference != null) { + fontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeFontSizeEvent((String) newValue)); + activity.recreate(); + return true; + }); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java index e2e0a5b8..3a99ebf1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java @@ -67,12 +67,16 @@ public class AccountPostsActivity extends AppCompatActivity implements UserThing @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_account_posts); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); Resources resources = getResources(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountSavedThingActivity.java index 2b8206e4..ccd56a77 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountSavedThingActivity.java @@ -75,12 +75,16 @@ public class AccountSavedThingActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_account_saved_thing); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); Resources resources = getResources(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 4cbc8e2f..1c134841 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -44,4 +44,5 @@ public interface AppComponent { void inject(SettingsActivity settingsActivity); void inject(MainPreferenceFragment mainPreferenceFragment); void inject(AccountSavedThingActivity accountSavedThingActivity); + void inject(ViewImageActivity viewImageActivity); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ChangeFontSizeEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ChangeFontSizeEvent.java new file mode 100644 index 00000000..78846c79 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ChangeFontSizeEvent.java @@ -0,0 +1,8 @@ +package ml.docilealligator.infinityforreddit; + +public class ChangeFontSizeEvent { + public String fontSize; + public ChangeFontSizeEvent(String fontSize) { + this.fontSize = fontSize; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java index 17e4061c..5104bef8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentActivity.java @@ -83,12 +83,16 @@ public class CommentActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_comment); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java index c5606ae8..602095ea 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/EditCommentActivity.java @@ -72,12 +72,16 @@ public class EditCommentActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_edit_comment); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java index 882fe11c..d1352cdf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java @@ -71,12 +71,16 @@ public class EditPostActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_edit_post); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java index 27a9ddf0..66ce2fcf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java @@ -78,12 +78,16 @@ public class FilteredThingActivity extends AppCompatActivity implements SortType @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_filtered_thing); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); Resources resources = getResources(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FontStyle.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FontStyle.java new file mode 100644 index 00000000..bb2448ca --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FontStyle.java @@ -0,0 +1,24 @@ +package ml.docilealligator.infinityforreddit; + +public enum FontStyle { + Small(R.style.FontStyle_Small, "Small"), + Normal(R.style.FontStyle_Normal, "Normal"), + Large(R.style.FontStyle_Large, "Large"), + XLarge(R.style.FontStyle_XLarge, "XLarge"); + + private int resId; + private String title; + + public int getResId() { + return resId; + } + + public String getTitle() { + return title; + } + + FontStyle(int resId, String title) { + this.resId = resId; + this.title = title; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java index d4365b0a..38cf5cc0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java @@ -166,11 +166,16 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe setTheme(R.style.AppTheme_NoActionBarWithTransparentStatusBar); super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_main); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); EventBus.getDefault().register(this); @@ -885,6 +890,11 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw); } + @Subscribe + public void onChangeFontSizeEvent(ChangeFontSizeEvent changeFontSizeEvent) { + recreate(); + } + private class SectionsPagerAdapter extends FragmentPagerAdapter { private PostFragment frontPagePostFragment; private PostFragment popularPostFragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java index 4b8deadd..0d13dc2e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java @@ -1,5 +1,7 @@ package ml.docilealligator.infinityforreddit; +import android.util.Log; + import androidx.annotation.NonNull; import androidx.lifecycle.MutableLiveData; import androidx.paging.PageKeyedDataSource; @@ -69,6 +71,7 @@ class PostDataSource extends PageKeyedDataSource { PostDataSource(Retrofit retrofit, String accessToken, Locale locale, String subredditOrUserName, int postType, String sortType, int filter, boolean nsfw) { + Log.i("asfdasdf", "datasource: " + sortType); this.retrofit = retrofit; this.accessToken = accessToken; this.locale = locale; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java index 3942bec3..6e2aaa89 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java @@ -1,5 +1,7 @@ package ml.docilealligator.infinityforreddit; +import android.util.Log; + import androidx.annotation.NonNull; import androidx.lifecycle.MutableLiveData; import androidx.paging.DataSource; @@ -37,6 +39,7 @@ class PostDataSourceFactory extends DataSource.Factory { PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType, String sortType, int filter, boolean nsfw) { + Log.i("asfdasdf", "datasource factory: " + sortType); this.retrofit = retrofit; this.accessToken = accessToken; this.locale = locale; @@ -86,6 +89,7 @@ class PostDataSourceFactory extends DataSource.Factory { postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, query, postType, sortType, filter, nsfw); } else if(postType == PostDataSource.TYPE_SUBREDDIT) { + Log.i("asfdasdf", "datasource create: " + sortType); postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, postType, sortType, filter, nsfw); } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java index 67a0b247..6497f57c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java @@ -255,6 +255,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { int postType = getArguments().getInt(EXTRA_POST_TYPE); String sortType = getArguments().getString(EXTRA_SORT_TYPE); + int filter = getArguments().getInt(EXTRA_FILTER); String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); boolean nsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java index 27c27fd2..1e2dc155 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java @@ -133,14 +133,18 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_post_image); ButterKnife.bind(this); EventBus.getDefault().register(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Window window = getWindow(); if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java index cab3288d..cf384682 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java @@ -110,14 +110,18 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_post_link); ButterKnife.bind(this); EventBus.getDefault().register(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Window window = getWindow(); if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java index b8e967f2..5f1200b3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java @@ -110,14 +110,18 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_post_text); ButterKnife.bind(this); EventBus.getDefault().register(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Window window = getWindow(); if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java index eb3e51ff..f287fd07 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java @@ -143,14 +143,18 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_post_video); ButterKnife.bind(this); EventBus.getDefault().register(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Window window = getWindow(); if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java index 412a0d0e..9340e20b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java @@ -1,5 +1,7 @@ package ml.docilealligator.infinityforreddit; +import android.util.Log; + import androidx.annotation.NonNull; import androidx.core.util.Pair; import androidx.lifecycle.LiveData; @@ -58,6 +60,7 @@ public class PostViewModel extends ViewModel { public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType, String sortType, int filter, boolean nsfw) { + Log.i("asfdasdf", "viewmodel: " + sortType); postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName, postType, sortType, filter, nsfw); @@ -206,6 +209,7 @@ public class PostViewModel extends ViewModel { public Factory(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType, String sortType, int filter, boolean nsfw) { + Log.i("asfdasdf", "viewmodel factory: " + sortType); this.retrofit = retrofit; this.accessToken = accessToken; this.locale = locale; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RulesActivity.java index e519797a..8923e364 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RulesActivity.java @@ -70,12 +70,16 @@ public class RulesActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_rules); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java index b1627f0b..a715014f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java @@ -67,12 +67,16 @@ public class SearchActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_search); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java index 9a6652c5..b0640071 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java @@ -72,12 +72,16 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_search_result); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchSubredditsResultActivity.java index c6bd9685..31118441 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchSubredditsResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchSubredditsResultActivity.java @@ -63,12 +63,16 @@ public class SearchSubredditsResultActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_search_subreddits_result); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SettingsActivity.java index f963b0a4..4e8b0a64 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SettingsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SettingsActivity.java @@ -42,12 +42,16 @@ public class SettingsActivity extends AppCompatActivity implements @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.settings_activity); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Window window = getWindow(); if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java index e0b6672a..6bc34647 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java @@ -23,4 +23,5 @@ public class SharedPreferencesUtils { public static final String EMAIL_KEY = "email"; public static final String REDDIT_ACCOUNT_KEY = "reddit_account"; public static final String SUBREDDIT_KEY = "subreddit"; + public static final String FONT_SIZE_KEY = "font_size"; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java index 4bb67e27..e3d5d82d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditSelectionActivity.java @@ -82,12 +82,16 @@ public class SubredditSelectionActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_subreddit_selection); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java index 35d49eeb..15380d86 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedThingListingActivity.java @@ -75,12 +75,16 @@ public class SubscribedThingListingActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_subscribed_thing_listing); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java index 3f81263f..2db793e5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java @@ -7,6 +7,7 @@ import android.animation.ValueAnimator; import android.app.DownloadManager; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.PorterDuff; import android.graphics.drawable.ColorDrawable; @@ -45,6 +46,8 @@ import com.github.pwittchen.swipe.library.rx2.Swipe; import java.io.File; +import javax.inject.Inject; + import butterknife.BindView; import butterknife.ButterKnife; @@ -76,10 +79,20 @@ public class ViewImageActivity extends AppCompatActivity { private boolean isSwiping = false; + @Inject + SharedPreferences mSharedPreferences; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_view_image); + ButterKnife.bind(this); ActionBar actionBar = getSupportActionBar(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java index 34f1d653..5d748643 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewMessageActivity.java @@ -86,12 +86,16 @@ public class ViewMessageActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_view_message); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); mGlide = Glide.with(this); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 3063e0c0..d6d6c0b7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -139,6 +139,12 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_view_post_detail); Bridge.restoreInstanceState(this, savedInstanceState); @@ -147,8 +153,6 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo EventBus.getDefault().register(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - Resources resources = getResources(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java index cf950b2b..f567349f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java @@ -121,12 +121,16 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_view_subreddit_detail); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java index 91525a3e..d57e57f8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java @@ -127,12 +127,16 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences + .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); + setContentView(R.layout.activity_view_user_detail); ButterKnife.bind(this); - ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; diff --git a/app/src/main/res/layout/activity_comment.xml b/app/src/main/res/layout/activity_comment.xml index 494872ce..f5c5afe1 100644 --- a/app/src/main/res/layout/activity_comment.xml +++ b/app/src/main/res/layout/activity_comment.xml @@ -37,7 +37,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" - android:textSize="16sp" /> + android:textSize="?attr/font_16" /> diff --git a/app/src/main/res/layout/activity_edit_comment.xml b/app/src/main/res/layout/activity_edit_comment.xml index 93504c14..94f9b602 100644 --- a/app/src/main/res/layout/activity_edit_comment.xml +++ b/app/src/main/res/layout/activity_edit_comment.xml @@ -29,7 +29,7 @@ android:padding="16dp" android:hint="@string/post_text_content_hint" android:inputType="textCapSentences|textMultiLine" - android:textSize="18sp" + android:textSize="?attr/font_18" android:background="#00000000" android:textColor="@color/primaryTextColor" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> diff --git a/app/src/main/res/layout/activity_edit_post.xml b/app/src/main/res/layout/activity_edit_post.xml index e95ba34c..e7645c5e 100644 --- a/app/src/main/res/layout/activity_edit_post.xml +++ b/app/src/main/res/layout/activity_edit_post.xml @@ -37,7 +37,7 @@ android:layout_height="wrap_content" android:gravity="top" android:padding="16dp" - android:textSize="18sp" + android:textSize="?attr/font_18" android:textColor="@color/primaryTextColor" /> diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 6d85662b..4cf0b16f 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -45,7 +45,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" - android:text="@string/label_account" /> + android:text="@string/label_account" + android:textSize="?attr/font_default" /> + android:textColor="@color/primaryTextColor" + android:textSize="?attr/font_default" /> @@ -95,7 +97,8 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/subscriptions" - android:textColor="@color/primaryTextColor" /> + android:textColor="@color/primaryTextColor" + android:textSize="?attr/font_default" /> @@ -121,7 +124,8 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/inbox" - android:textColor="@color/primaryTextColor" /> + android:textColor="@color/primaryTextColor" + android:textSize="?attr/font_default" /> @@ -130,7 +134,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" - android:text="@string/label_post" /> + android:text="@string/label_post" + android:textSize="?attr/font_default" /> + android:textColor="@color/primaryTextColor" + android:textSize="?attr/font_default" /> @@ -180,7 +186,8 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/downvoted" - android:textColor="@color/primaryTextColor" /> + android:textColor="@color/primaryTextColor" + android:textSize="?attr/font_default" /> @@ -206,7 +213,8 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/hidden" - android:textColor="@color/primaryTextColor" /> + android:textColor="@color/primaryTextColor" + android:textSize="?attr/font_default" /> @@ -232,7 +240,8 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/saved" - android:textColor="@color/primaryTextColor" /> + android:textColor="@color/primaryTextColor" + android:textSize="?attr/font_default" /> @@ -258,7 +267,8 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/gilded" - android:textColor="@color/primaryTextColor" /> + android:textColor="@color/primaryTextColor" + android:textSize="?attr/font_default" /> @@ -290,7 +300,8 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/settings" - android:textColor="@color/primaryTextColor" /> + android:textColor="@color/primaryTextColor" + android:textSize="?attr/font_default" /> diff --git a/app/src/main/res/layout/activity_post_image.xml b/app/src/main/res/layout/activity_post_image.xml index 795e53cf..1cf36a16 100644 --- a/app/src/main/res/layout/activity_post_image.xml +++ b/app/src/main/res/layout/activity_post_image.xml @@ -55,7 +55,8 @@ android:layout_centerVertical="true" android:layout_marginStart="32dp" android:layout_marginEnd="16dp" - android:text="@string/choose_a_subreddit" /> + android:text="@string/choose_a_subreddit" + android:textSize="?attr/font_default" />