diff options
Diffstat (limited to 'app/src/main/java')
166 files changed, 1865 insertions, 737 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index c33a6deb..54e54567 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -5,7 +5,6 @@ import javax.inject.Singleton; import dagger.Component; import ml.docilealligator.infinityforreddit.activities.AccountPostsActivity; import ml.docilealligator.infinityforreddit.activities.AccountSavedThingActivity; -import ml.docilealligator.infinityforreddit.activities.AnonymousSubscriptionsActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.CreateMultiRedditActivity; import ml.docilealligator.infinityforreddit.activities.CustomThemeListingActivity; @@ -271,8 +270,6 @@ public interface AppComponent { void inject(CrashReportsFragment crashReportsFragment); - void inject(AnonymousSubscriptionsActivity anonymousSubscriptionsActivity); - void inject(LockScreenActivity lockScreenActivity); void inject(MaterialYouService materialYouService); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomFontReceiver.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomFontReceiver.java new file mode 100644 index 00000000..0d3c1e20 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomFontReceiver.java @@ -0,0 +1,7 @@ +package ml.docilealligator.infinityforreddit; + +import android.graphics.Typeface; + +public interface CustomFontReceiver { + void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java index 78939b83..f6b5706d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java @@ -81,8 +81,8 @@ public class Infinity extends Application implements LifecycleObserver { registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { @Override public void onActivityPreCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { - if (activity instanceof BaseActivity) { - ((BaseActivity) activity).setCustomFont(typeface, titleTypeface, contentTypeface); + if (activity instanceof CustomFontReceiver) { + ((CustomFontReceiver) activity).setCustomFont(typeface, titleTypeface, contentTypeface); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java index 6254f97d..32896b06 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java @@ -52,6 +52,7 @@ import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostPagingSource; import ml.docilealligator.infinityforreddit.readpost.InsertReadPost; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; public class AccountSavedThingActivity extends BaseActivity implements ActivityToolbarInterface, @@ -179,10 +180,10 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> { switch (position) { case 0: - tab.setText(R.string.posts); + Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.posts)); break; case 1: - tab.setText(R.string.comments); + Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.comments)); break; } }).attach(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AnonymousSubscriptionsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AnonymousSubscriptionsActivity.java deleted file mode 100644 index 403f3567..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AnonymousSubscriptionsActivity.java +++ /dev/null @@ -1,116 +0,0 @@ -package ml.docilealligator.infinityforreddit.activities; - -import android.content.SharedPreferences; -import android.os.Build; -import android.os.Bundle; -import android.view.MenuItem; -import android.view.View; -import android.view.Window; -import android.view.WindowManager; - -import androidx.annotation.NonNull; -import androidx.appcompat.widget.Toolbar; -import androidx.coordinatorlayout.widget.CoordinatorLayout; - -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.appbar.CollapsingToolbarLayout; -import com.r0adkll.slidr.Slidr; - -import javax.inject.Inject; -import javax.inject.Named; - -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.fragments.SubscribedSubredditsListingFragment; -import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; - -public class AnonymousSubscriptionsActivity extends BaseActivity { - - @BindView(R.id.coordinator_layout_anonymous_subscriptions_activity) - CoordinatorLayout coordinatorLayout; - @BindView(R.id.appbar_layout_anonymous_subscriptions_activity) - AppBarLayout appBarLayout; - @BindView(R.id.collapsing_toolbar_layout_anonymous_subscriptions_activity) - CollapsingToolbarLayout collapsingToolbarLayout; - @BindView(R.id.toolbar_anonymous_subscriptions_activity) - Toolbar toolbar; - @Inject - @Named("default") - SharedPreferences mSharedPreferences; - @Inject - CustomThemeWrapper mCustomThemeWrapper; - - @Override - protected void onCreate(Bundle savedInstanceState) { - ((Infinity) getApplication()).getAppComponent().inject(this); - - setImmersiveModeNotApplicable(); - - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_anonymous_subscriptions); - - ButterKnife.bind(this); - - applyCustomTheme(); - - if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) { - Slidr.attach(this); - } - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - Window window = getWindow(); - - if (isChangeStatusBarIconColor()) { - addOnOffsetChangedListener(appBarLayout); - } - - if (isImmersiveInterface()) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - coordinatorLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); - } else { - window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); - } - adjustToolbar(toolbar); - } - } - - setSupportActionBar(toolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - SubscribedSubredditsListingFragment mFragment = new SubscribedSubredditsListingFragment(); - Bundle bundle = new Bundle(); - bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_NAME, "-"); - mFragment.setArguments(bundle); - getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_anonymous_subscriptions_activity, mFragment).commit(); - } - - @Override - protected SharedPreferences getDefaultSharedPreferences() { - return mSharedPreferences; - } - - @Override - protected CustomThemeWrapper getCustomThemeWrapper() { - return mCustomThemeWrapper; - } - - @Override - protected void applyCustomTheme() { - coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - if (item.getItemId() == android.R.id.home) { - finish(); - return true; - } - return false; - } -}
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java index 9890d538..b0dec874 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java @@ -20,6 +20,7 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.Window; +import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; @@ -40,6 +41,7 @@ import java.util.Locale; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; +import ml.docilealligator.infinityforreddit.CustomFontReceiver; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.font.ContentFontFamily; @@ -50,8 +52,9 @@ import ml.docilealligator.infinityforreddit.font.TitleFontFamily; import ml.docilealligator.infinityforreddit.font.TitleFontStyle; import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; -public abstract class BaseActivity extends AppCompatActivity { +public abstract class BaseActivity extends AppCompatActivity implements CustomFontReceiver { private boolean immersiveInterface; private boolean changeStatusBarIconColor; private boolean transparentStatusBarAfterToolbarCollapsed; @@ -321,13 +324,21 @@ public abstract class BaseActivity extends AppCompatActivity { if (toolbar.getOverflowIcon() != null) { toolbar.getOverflowIcon().setColorFilter(customThemeWrapper.getToolbarPrimaryTextAndIconColor(), android.graphics.PorterDuff.Mode.SRC_IN); } + if (typeface != null) { + toolbar.addOnLayoutChangeListener((view, i, i1, i2, i3, i4, i5, i6, i7) -> { + for (int j = 0; j < toolbar.getChildCount(); j++) { + if (toolbar.getChildAt(j) instanceof TextView) { + ((TextView) toolbar.getChildAt(j)).setTypeface(typeface); + } + } + }); + } } @SuppressLint("RestrictedApi") protected boolean applyMenuItemTheme(Menu menu) { if (customThemeWrapper != null) { - int size = Math.min(menu.size(), 2); - for (int i = 0; i < size; i++) { + for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); if (((MenuItemImpl) item).requestsActionButton()) { Drawable drawable = item.getIcon(); @@ -336,6 +347,7 @@ public abstract class BaseActivity extends AppCompatActivity { item.setIcon(drawable); } } + Utils.setTitleWithCustomFontToMenuItem(typeface, item, null); } } return true; @@ -372,6 +384,7 @@ public abstract class BaseActivity extends AppCompatActivity { } catch (NoSuchFieldException | IllegalAccessException ignore) {} } + @Override public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { this.typeface = typeface; this.titleTypeface = titleTypeface; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java index 5e1db8be..54c07da6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -243,6 +243,9 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { + if (contentTypeface != null) { + textView.setTypeface(contentTypeface); + } textView.setTextColor(markdownColor); textView.setOnLongClickListener(view -> { Utils.hideKeyboard(CommentActivity.this); @@ -357,6 +360,11 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); commentEditText.setHintTextColor(secondaryTextColor); markdownColor = secondaryTextColor; + + if (typeface != null) { + commentParentMarkwonView.setTypeface(typeface); + commentEditText.setTypeface(typeface); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java index 9ae956f9..6be1059a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java @@ -38,6 +38,7 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.multireddit.CreateMultiReddit; import ml.docilealligator.infinityforreddit.multireddit.MultiRedditJSONModel; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; public class CreateMultiRedditActivity extends BaseActivity { @@ -235,5 +236,9 @@ public class CreateMultiRedditActivity extends BaseActivity { descriptionEditText.setHintTextColor(secondaryTextColor); visibilityTextView.setTextColor(primaryTextColor); selectSubredditTextView.setTextColor(primaryTextColor); + + if (typeface != null) { + Utils.setFontToAllTextViews(coordinatorLayout, typeface); + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java index e3d232e6..3c6bf60d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java @@ -9,6 +9,7 @@ import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; +import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; import android.util.TypedValue; @@ -48,6 +49,7 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; +import ml.docilealligator.infinityforreddit.CustomFontReceiver; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; @@ -59,10 +61,14 @@ import ml.docilealligator.infinityforreddit.font.TitleFontStyle; import ml.docilealligator.infinityforreddit.fragments.ThemePreviewCommentsFragment; import ml.docilealligator.infinityforreddit.fragments.ThemePreviewPostsFragment; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; -public class CustomThemePreviewActivity extends AppCompatActivity { +public class CustomThemePreviewActivity extends AppCompatActivity implements CustomFontReceiver { public static final String EXTRA_CUSTOM_THEME_SETTINGS_ITEMS = "ECTSI"; + public Typeface typeface; + public Typeface titleTypeface; + public Typeface contentTypeface; @BindView(R.id.coordinator_layout_theme_preview_activity) CoordinatorLayout coordinatorLayout; @@ -357,6 +363,13 @@ public class CustomThemePreviewActivity extends AppCompatActivity { applyFABTheme(fab); unsubscribedColor = customTheme.unsubscribed; subscribedColor = customTheme.subscribed; + if (typeface != null) { + subredditNameTextView.setTypeface(typeface); + usernameTextView.setTypeface(typeface); + primaryTextView.setTypeface(typeface); + secondaryTextView.setTypeface(typeface); + subscribeSubredditChip.setTypeface(typeface); + } } protected void applyAppBarLayoutAndToolbarTheme(AppBarLayout appBarLayout, Toolbar toolbar) { @@ -369,6 +382,15 @@ public class CustomThemePreviewActivity extends AppCompatActivity { if (toolbar.getOverflowIcon() != null) { toolbar.getOverflowIcon().setColorFilter(customTheme.toolbarPrimaryTextAndIconColor, android.graphics.PorterDuff.Mode.SRC_IN); } + if (typeface != null) { + toolbar.addOnLayoutChangeListener((view, i, i1, i2, i3, i4, i5, i6, i7) -> { + for (int j = 0; j < toolbar.getChildCount(); j++) { + if (toolbar.getChildAt(j) instanceof TextView) { + ((TextView) toolbar.getChildAt(j)).setTypeface(typeface); + } + } + }); + } } private void adjustToolbar(Toolbar toolbar) { @@ -424,6 +446,13 @@ public class CustomThemePreviewActivity extends AppCompatActivity { } } + @Override + public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { + this.typeface = typeface; + this.titleTypeface = titleTypeface; + this.contentTypeface = contentTypeface; + } + private class SectionsPagerAdapter extends FragmentPagerAdapter { private ThemePreviewPostsFragment themePreviewPostsFragment; private ThemePreviewCommentsFragment themePreviewCommentsFragment; @@ -450,9 +479,9 @@ public class CustomThemePreviewActivity extends AppCompatActivity { public CharSequence getPageTitle(int position) { switch (position) { case 0: - return "Posts"; + return Utils.getTabTextWithCustomFont(typeface, "Posts"); case 1: - return "Comments"; + return Utils.getTabTextWithCustomFont(typeface, "Comments"); } return null; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java index 8603c808..5f7bbc6e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java @@ -498,6 +498,10 @@ public class CustomizePostFilterActivity extends BaseActivity { setCursorDrawableColor(minAwardsTextInputEditText, primaryTextColor); setCursorDrawableColor(maxAwardsTextInputEditText, primaryTextColor); } + + if (typeface != null) { + Utils.setFontToAllTextViews(coordinatorLayout, typeface); + } } public static void setCursorDrawableColor(EditText editText, int color) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java index 4f4b81ec..29f2f0f1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java @@ -185,6 +185,10 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); contentEditText.setTextColor(mCustomThemeWrapper.getCommentColor()); + + if (contentTypeface != null) { + contentEditText.setTypeface(contentTypeface); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java index 1ff1b157..20dfe06f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java @@ -41,6 +41,7 @@ import ml.docilealligator.infinityforreddit.multireddit.FetchMultiRedditInfo; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; import ml.docilealligator.infinityforreddit.multireddit.MultiRedditJSONModel; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; public class EditMultiRedditActivity extends BaseActivity { @@ -288,5 +289,9 @@ public class EditMultiRedditActivity extends BaseActivity { descriptionEditText.setHintTextColor(secondaryTextColor); visibilityTextView.setTextColor(primaryTextColor); selectSubredditTextView.setTextColor(primaryTextColor); + + if (typeface != null) { + Utils.setFontToAllTextViews(coordinatorLayout, typeface); + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java index 0d22d9b3..2bdcdd0b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java @@ -196,6 +196,13 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled titleTextView.setTextColor(mCustomThemeWrapper.getPostTitleColor()); divider.setBackgroundColor(mCustomThemeWrapper.getPostTitleColor()); contentEditText.setTextColor(mCustomThemeWrapper.getPostContentColor()); + + if (titleTypeface != null) { + titleTextView.setTypeface(titleTypeface); + } + if (contentTypeface != null) { + contentEditText.setTypeface(contentTypeface); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java index 106b717a..25531633 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java @@ -52,6 +52,7 @@ import ml.docilealligator.infinityforreddit.services.EditProfileService; import ml.docilealligator.infinityforreddit.user.UserViewModel; import ml.docilealligator.infinityforreddit.utils.EditProfileUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; @@ -61,7 +62,7 @@ public class EditProfileActivity extends BaseActivity { private static final int PICK_IMAGE_AVATAR_REQUEST_CODE = 0x402; @BindView(R.id.root_layout_view_edit_profile_activity) - CoordinatorLayout root; + CoordinatorLayout coordinatorLayout; @BindView(R.id.content_view_edit_profile_activity) LinearLayout content; @BindView(R.id.collapsing_toolbar_layout_edit_profile_activity) @@ -344,9 +345,11 @@ public class EditProfileActivity extends BaseActivity { @Override protected void applyCustomTheme() { applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); - root.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - + coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); changeColorTextView(content, mCustomThemeWrapper.getPrimaryTextColor()); + if (typeface != null) { + Utils.setFontToAllTextViews(coordinatorLayout, typeface); + } } private void changeColorTextView(ViewGroup viewGroup, int color) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java index ed6aaeeb..05533044 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -3,14 +3,10 @@ package ml.docilealligator.infinityforreddit.activities; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.Color; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.text.SpannableStringBuilder; import android.text.Spanned; -import android.text.TextPaint; -import android.text.style.ClickableSpan; import android.text.util.Linkify; import android.view.Menu; import android.view.MenuItem; @@ -33,9 +29,6 @@ import org.commonmark.ext.gfm.tables.TableBlock; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import javax.inject.Inject; import javax.inject.Named; @@ -63,9 +56,8 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; -import ml.docilealligator.infinityforreddit.markdown.SpoilerSpan; -import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; public class FullMarkdownActivity extends BaseActivity { @@ -157,6 +149,9 @@ public class FullMarkdownActivity extends BaseActivity { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { + if (typeface != null) { + textView.setTypeface(typeface); + } textView.setTextColor(markdownColor); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java index 50db35d1..e6094cdd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java @@ -19,7 +19,6 @@ import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.RecyclerView; -import com.bumptech.glide.Glide; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.switchmaterial.SwitchMaterial; @@ -113,7 +112,7 @@ public class GiveAwardActivity extends BaseActivity { } private void bindView() { - adapter = new AwardRecyclerViewAdapter(Glide.with(this), mCustomThemeWrapper, award -> { + adapter = new AwardRecyclerViewAdapter(this, mCustomThemeWrapper, award -> { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.dialog_give_award, null); SwitchMaterial switchMaterial = layout.findViewById(R.id.switch_material_give_award_dialog); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java index 203ded9e..7e2fd59f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java @@ -58,6 +58,7 @@ import ml.docilealligator.infinityforreddit.fragments.InboxFragment; import ml.docilealligator.infinityforreddit.message.FetchMessage; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -283,10 +284,10 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> { switch (position) { case 0: - tab.setText(R.string.notifications); + Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.notifications)); break; case 1: - tab.setText(R.string.messages); + Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.messages)); break; } }).attach(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java index 76205df0..12f5f929 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java @@ -98,6 +98,10 @@ public class LockScreenActivity extends BaseActivity { textView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); unlockButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); unlockButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme()); + if (typeface != null) { + textView.setTypeface(typeface); + unlockButton.setTypeface(typeface); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java index cef2a207..8e143136 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java @@ -286,6 +286,9 @@ public class LoginActivity extends BaseActivity { Drawable infoDrawable = Utils.getTintedDrawable(this, R.drawable.ic_info_preference_24dp, mCustomThemeWrapper.getPrimaryIconColor()); twoFAInfoTextView.setCompoundDrawablesWithIntrinsicBounds(infoDrawable, null, null, null); applyFABTheme(fab); + if (typeface != null) { + twoFAInfoTextView.setTypeface(typeface); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 44c284b5..d42ca18d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -25,7 +25,6 @@ import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -355,12 +354,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb applyTabLayoutTheme(tabLayout); bottomAppBar.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); applyFABTheme(fab); - for (int i = 0; i < toolbar.getChildCount(); i++) { - View view = toolbar.getChildAt(i); - if (view instanceof TextView) { - ((TextView) view).setTypeface(typeface); - } - } } private void initializeNotificationAndBindView(boolean doNotInitializeNotificationIfNoNewAccount) { @@ -858,32 +851,32 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> { switch (position) { case 0: - tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home))); + Utils.setTitleWithCustomFontToTab(typeface, tab, mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home))); break; case 1: - tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular))); + Utils.setTitleWithCustomFontToTab(typeface, tab, mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular))); break; case 2: - tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all))); + Utils.setTitleWithCustomFontToTab(typeface, tab, mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all))); break; } if (position >= tabCount && (mShowFavoriteMultiReddits || mShowMultiReddits || mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) && sectionsPagerAdapter != null) { if (position - tabCount < sectionsPagerAdapter.favoriteMultiReddits.size()) { - tab.setText(sectionsPagerAdapter.favoriteMultiReddits.get(position - tabCount).getName()); + Utils.setTitleWithCustomFontToTab(typeface, tab, sectionsPagerAdapter.favoriteMultiReddits.get(position - tabCount).getName()); } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() < sectionsPagerAdapter.multiReddits.size()) { - tab.setText(sectionsPagerAdapter.multiReddits.get(position - tabCount + Utils.setTitleWithCustomFontToTab(typeface, tab, sectionsPagerAdapter.multiReddits.get(position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size()).getName()); } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() - sectionsPagerAdapter.multiReddits.size() < sectionsPagerAdapter.favoriteSubscribedSubreddits.size()) { - tab.setText(sectionsPagerAdapter.favoriteSubscribedSubreddits.get(position - tabCount + Utils.setTitleWithCustomFontToTab(typeface, tab, sectionsPagerAdapter.favoriteSubscribedSubreddits.get(position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() - sectionsPagerAdapter.multiReddits.size()).getName()); } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() - sectionsPagerAdapter.multiReddits.size() - sectionsPagerAdapter.favoriteSubscribedSubreddits.size() < sectionsPagerAdapter.subscribedSubreddits.size()) { - tab.setText(sectionsPagerAdapter.subscribedSubreddits.get(position - tabCount + Utils.setTitleWithCustomFontToTab(typeface, tab, sectionsPagerAdapter.subscribedSubreddits.get(position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() - sectionsPagerAdapter.multiReddits.size() - sectionsPagerAdapter.favoriteSubscribedSubreddits.size()).getName()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java index 44a6f62d..ab96b850 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java @@ -98,7 +98,7 @@ public class PostFilterPreferenceActivity extends BaseActivity { } }); - adapter = new PostFilterRecyclerViewAdapter(postFilter -> { + adapter = new PostFilterRecyclerViewAdapter(this, postFilter -> { if (post != null) { showPostFilterOptions(post, postFilter); } else if (subredditName != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java index 22cb3b69..1782776b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java @@ -425,6 +425,15 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee nsfwTextView.setTextColor(primaryTextColor); titleEditText.setTextColor(primaryTextColor); titleEditText.setHintTextColor(secondaryTextColor); + if (typeface != null) { + subredditNameTextView.setTypeface(typeface); + rulesButton.setTypeface(typeface); + receivePostReplyNotificationsTextView.setTypeface(typeface); + flairTextView.setTypeface(typeface); + spoilerTextView.setTypeface(typeface); + nsfwTextView.setTypeface(typeface); + titleEditText.setTypeface(typeface); + } } public void selectImage() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java index 7125033e..1acc53e7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java @@ -409,6 +409,16 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF applyFABTheme(captureFab); applyFABTheme(selectFromLibraryFab); selectAgainTextView.setTextColor(mCustomThemeWrapper.getColorAccent()); + if (typeface != null) { + subredditNameTextView.setTypeface(typeface); + rulesButton.setTypeface(typeface); + receivePostReplyNotificationsTextView.setTypeface(typeface); + flairTextView.setTypeface(typeface); + spoilerTextView.setTypeface(typeface); + nsfwTextView.setTypeface(typeface); + titleEditText.setTypeface(typeface); + selectAgainTextView.setTypeface(typeface); + } } private void loadImage() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java index 1bdd8d55..43e4040c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java @@ -384,6 +384,19 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr suggestTitleButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); linkEditText.setTextColor(primaryTextColor); linkEditText.setHintTextColor(secondaryTextColor); + if (typeface != null) { + subredditNameTextView.setTypeface(typeface); + rulesButton.setTypeface(typeface); + receivePostReplyNotificationsTextView.setTypeface(typeface); + flairTextView.setTypeface(typeface); + spoilerTextView.setTypeface(typeface); + nsfwTextView.setTypeface(typeface); + titleEditText.setTypeface(typeface); + suggestTitleButton.setTypeface(typeface); + } + if (contentTypeface != null) { + linkEditText.setTypeface(contentTypeface); + } } private void displaySubredditIcon() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java index c0570951..4f197825 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java @@ -406,6 +406,18 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr titleEditText.setHintTextColor(secondaryTextColor); contentEditText.setTextColor(primaryTextColor); contentEditText.setHintTextColor(secondaryTextColor); + if (typeface != null) { + subredditNameTextView.setTypeface(typeface); + rulesButton.setTypeface(typeface); + receivePostReplyNotificationsTextView.setTypeface(typeface); + flairTextView.setTypeface(typeface); + spoilerTextView.setTypeface(typeface); + nsfwTextView.setTypeface(typeface); + titleEditText.setTypeface(typeface); + } + if (contentTypeface != null) { + contentEditText.setTypeface(typeface); + } } private void displaySubredditIcon() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java index db38a1b1..56c2d2e8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java @@ -424,6 +424,16 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF applyFABTheme(captureFab); applyFABTheme(selectFromLibraryFab); selectAgainTextView.setTextColor(mCustomThemeWrapper.getColorAccent()); + if (typeface != null) { + subredditNameTextView.setTypeface(typeface); + rulesButton.setTypeface(typeface); + receivePostReplyNotificationsTextView.setTypeface(typeface); + flairTextView.setTypeface(typeface); + spoilerTextView.setTypeface(typeface); + nsfwTextView.setTypeface(typeface); + titleEditText.setTypeface(typeface); + selectAgainTextView.setTypeface(typeface); + } } private void loadVideo() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java index a027e738..ecc459a4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java @@ -4,6 +4,7 @@ import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; +import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.media.AudioManager; @@ -46,6 +47,7 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.CustomFontReceiver; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RPANBroadcast; @@ -60,13 +62,14 @@ import ml.docilealligator.infinityforreddit.font.TitleFontStyle; import ml.docilealligator.infinityforreddit.fragments.ViewRPANBroadcastFragment; import ml.docilealligator.infinityforreddit.utils.JSONUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; -public class RPANActivity extends AppCompatActivity { +public class RPANActivity extends AppCompatActivity implements CustomFontReceiver { public static final String EXTRA_RPAN_BROADCAST_FULLNAME_OR_ID = "ERBFOI"; @@ -90,6 +93,7 @@ public class RPANActivity extends AppCompatActivity { ArrayList<RPANBroadcast> rpanBroadcasts; @State String nextCursor; + public Typeface typeface; private SectionsPagerAdapter sectionsPagerAdapter; @Override @@ -130,7 +134,7 @@ public class RPANActivity extends AppCompatActivity { Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp); actionBar.setHomeAsUpIndicator(upArrow); actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000"))); - actionBar.setTitle(Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.rpan_activity_label) + "</font>")); + actionBar.setTitle(Utils.getTabTextWithCustomFont(typeface, Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.rpan_activity_label) + "</font>"))); if (rpanBroadcasts == null) { loadRPANVideos(); @@ -337,6 +341,9 @@ public class RPANActivity extends AppCompatActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.rpan_activity, menu); + for (int i = 0; i < menu.size(); i++) { + Utils.setTitleWithCustomFontToMenuItem(typeface, menu.getItem(i), null); + } return true; } @@ -382,6 +389,11 @@ public class RPANActivity extends AppCompatActivity { } } + @Override + public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { + this.typeface = typeface; + } + private class SectionsPagerAdapter extends FragmentStateAdapter { public SectionsPagerAdapter(FragmentActivity fa) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java index f00c9eb3..91ca0686 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java @@ -112,9 +112,9 @@ public class ReportActivity extends BaseActivity { } if (generalReasons != null) { - mAdapter = new ReportReasonRecyclerViewAdapter(mCustomThemeWrapper, generalReasons); + mAdapter = new ReportReasonRecyclerViewAdapter(this, mCustomThemeWrapper, generalReasons); } else { - mAdapter = new ReportReasonRecyclerViewAdapter(mCustomThemeWrapper, ReportReason.getGeneralReasons(this)); + mAdapter = new ReportReasonRecyclerViewAdapter(this, mCustomThemeWrapper, ReportReason.getGeneralReasons(this)); } recyclerView.setAdapter(mAdapter); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java index 75e01121..a2c141b7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java @@ -160,6 +160,9 @@ public class RulesActivity extends BaseActivity { applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); progressBar.setIndeterminateTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorAccent())); errorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + if (typeface != null) { + errorTextView.setTypeface(typeface); + } } private void displayError() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java index b98fb205..533fb345 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -51,6 +51,7 @@ import ml.docilealligator.infinityforreddit.subreddit.ParseSubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -360,6 +361,9 @@ public class SearchActivity extends BaseActivity { searchInTextView.setTextColor(colorAccent); subredditNameTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); divider.setBackgroundColor(mCustomThemeWrapper.getDividerColor()); + if (typeface != null) { + Utils.setFontToAllTextViews(coordinatorLayout, typeface); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index 95a98aa9..2d928ac5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -258,13 +258,13 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> { switch (position) { case 0: - tab.setText(R.string.posts); + Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.posts)); break; case 1: - tab.setText(R.string.subreddits); + Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.subreddits)); break; case 2: - tab.setText(R.string.users); + Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.users)); break; } }).attach(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java index 3b4252dd..244fe14c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java @@ -129,7 +129,7 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo } private void instantiateRecyclerView() { - mAdapter = new UserFlairRecyclerViewAdapter(mCustomThemeWrapper, mUserFlairs, (userFlair, editUserFlair) -> { + mAdapter = new UserFlairRecyclerViewAdapter(this, mCustomThemeWrapper, mUserFlairs, (userFlair, editUserFlair) -> { if (editUserFlair) { View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit_flair, null); EditText flairEditText = dialogView.findViewById(R.id.flair_edit_text_edit_flair_dialog); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java index 9df207b0..7a29e200 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java @@ -90,7 +90,7 @@ public class SelectedSubredditsAndUsersActivity extends BaseActivity implements subreddits = getIntent().getStringArrayListExtra(EXTRA_SELECTED_SUBREDDITS); } - adapter = new SelectedSubredditsRecyclerViewAdapter(mCustomThemeWrapper, subreddits); + adapter = new SelectedSubredditsRecyclerViewAdapter(this, mCustomThemeWrapper, subreddits); linearLayoutManager = new LinearLayoutManagerBugFixed(this); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setAdapter(adapter); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SendPrivateMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SendPrivateMessageActivity.java index abfe7810..eb38ef3c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SendPrivateMessageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SendPrivateMessageActivity.java @@ -186,5 +186,10 @@ public class SendPrivateMessageActivity extends BaseActivity { int dividerColor = mCustomThemeWrapper.getDividerColor(); divider1.setBackgroundColor(dividerColor); divider2.setBackgroundColor(dividerColor); + if (typeface != null) { + usernameEditText.setTypeface(typeface); + subjectEditText.setTypeface(typeface); + messageEditText.setTypeface(typeface); + } } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java index d1514d1a..82e4cf57 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java @@ -418,6 +418,18 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom contentTextView.setHintTextColor(secondaryTextColor); playButton.setColorFilter(mCustomThemeWrapper.getMediaIndicatorIconColor(), PorterDuff.Mode.SRC_IN); playButton.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getMediaIndicatorBackgroundColor())); + if (typeface != null) { + subredditNameTextView.setTypeface(typeface); + rulesButton.setTypeface(typeface); + receivePostReplyNotificationsTextView.setTypeface(typeface); + flairTextView.setTypeface(typeface); + spoilerTextView.setTypeface(typeface); + nsfwTextView.setTypeface(typeface); + titleEditText.setTypeface(typeface); + } + if (contentTypeface != null) { + contentTextView.setTypeface(contentTypeface); + } } private void displaySubredditIcon() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java index 91da0e06..1b2bd602 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java @@ -231,6 +231,9 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(mAppBarLayout, mCollapsingToolbarLayout, mToolbar); mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + if (typeface != null) { + mErrorTextView.setTypeface(typeface); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java index 1aa679ee..957e77ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java @@ -69,6 +69,7 @@ import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; public class SubscribedThingListingActivity extends BaseActivity implements ActivityToolbarInterface { @@ -508,11 +509,11 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti public CharSequence getPageTitle(int position) { switch (position) { case 0: - return getString(R.string.subreddits); + return Utils.getTabTextWithCustomFont(typeface, getString(R.string.subreddits)); case 1: - return getString(R.string.users); + return Utils.getTabTextWithCustomFont(typeface, getString(R.string.users)); case 2: - return getString(R.string.multi_reddits); + return Utils.getTabTextWithCustomFont(typeface, getString(R.string.multi_reddits)); } return null; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SuicidePreventionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SuicidePreventionActivity.java index 08e51b14..81710e98 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SuicidePreventionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SuicidePreventionActivity.java @@ -84,5 +84,10 @@ public class SuicidePreventionActivity extends BaseActivity { doNotShowThisAgainTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); continueButton.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimaryLightTheme())); continueButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); + if (typeface != null) { + quoteTextView.setTypeface(typeface); + doNotShowThisAgainTextView.setTypeface(typeface); + continueButton.setTypeface(typeface); + } } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java index 039688fb..5169e62d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java @@ -332,6 +332,9 @@ public class TrendingActivity extends BaseActivity { swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); errorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + if (typeface != null) { + errorTextView.setTypeface(typeface); + } } @Subscribe diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java index 0c105691..4f5117b6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.Bitmap; +import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; @@ -60,6 +61,7 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.BuildConfig; +import ml.docilealligator.infinityforreddit.CustomFontReceiver; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback; @@ -75,8 +77,9 @@ import ml.docilealligator.infinityforreddit.font.TitleFontFamily; import ml.docilealligator.infinityforreddit.font.TitleFontStyle; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; -public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWallpaperCallback { +public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWallpaperCallback, CustomFontReceiver { public static final String EXTRA_IMAGE_URL_KEY = "EIUK"; public static final String EXTRA_GIF_URL_KEY = "EGUK"; @@ -114,6 +117,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa private String mSubredditName; private boolean isGif = true; private boolean isNsfw; + private Typeface typeface; @Override protected void onCreate(Bundle savedInstanceState) { @@ -175,7 +179,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa if (useBottomAppBar) { titleTextView.setText(title); } else { - setTitle(title); + setTitle(Utils.getTabTextWithCustomFont(typeface, title)); } } else { if (!useBottomAppBar) { @@ -312,8 +316,12 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.view_image_or_gif_activity, menu); - if (!isGif) + for (int i = 0; i < menu.size(); i++) { + Utils.setTitleWithCustomFontToMenuItem(typeface, menu.getItem(i), null); + } + if (!isGif) { menu.findItem(R.id.action_set_wallpaper_view_image_or_gif_activity).setVisible(true); + } return true; } @@ -545,4 +553,9 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa super.onDestroy(); BigImageViewer.imageLoader().cancelAll(); } + + @Override + public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { + this.typeface = typeface; + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java index 43e8cc0d..e439aed1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit.activities; import android.content.SharedPreferences; +import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.AsyncTask; @@ -36,6 +37,7 @@ import app.futured.hauler.DragDirection; import app.futured.hauler.HaulerView; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.CustomFontReceiver; import ml.docilealligator.infinityforreddit.ImgurMedia; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; @@ -54,12 +56,13 @@ import ml.docilealligator.infinityforreddit.fragments.ViewImgurVideoFragment; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.JSONUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; -public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWallpaperCallback { +public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWallpaperCallback, CustomFontReceiver { public static final String EXTRA_IMGUR_TYPE = "EIT"; public static final String EXTRA_IMGUR_ID = "EII"; @@ -76,6 +79,7 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa ViewPagerBugFixed viewPager; @BindView(R.id.load_image_error_linear_layout_view_imgur_media_activity) LinearLayout errorLinearLayout; + public Typeface typeface; private SectionsPagerAdapter sectionsPagerAdapter; private ArrayList<ImgurMedia> images; private boolean useBottomAppBar; @@ -297,9 +301,9 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa private void setToolbarTitle(int position) { if (images != null && position >= 0 && position < images.size()) { if (images.get(position).getType() == ImgurMedia.TYPE_VIDEO) { - setTitle(Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.view_imgur_media_activity_video_label, position + 1, images.size()) + "</font>")); + setTitle(Utils.getTabTextWithCustomFont(typeface, Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.view_imgur_media_activity_video_label, position + 1, images.size()) + "</font>"))); } else { - setTitle(Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.view_imgur_media_activity_image_label, position + 1, images.size()) + "</font>")); + setTitle(Utils.getTabTextWithCustomFont(typeface, Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.view_imgur_media_activity_image_label, position + 1, images.size()) + "</font>"))); } } } @@ -383,6 +387,11 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa return viewPager.getCurrentItem(); } + @Override + public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { + this.typeface = typeface; + } + private class SectionsPagerAdapter extends FragmentStatePagerAdapter { SectionsPagerAdapter(@NonNull FragmentManager fm) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index 494d062c..3954bf2a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -289,6 +289,10 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele previousResultImageView.setColorFilter(searchPanelTextAndIconColor, android.graphics.PorterDuff.Mode.SRC_IN); nextResultImageView.setColorFilter(searchPanelTextAndIconColor, android.graphics.PorterDuff.Mode.SRC_IN); closeSearchPanelImageView.setColorFilter(searchPanelTextAndIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + if (typeface != null) { + searchTextInputLayout.setTypeface(typeface); + searchTextInputEditText.setTypeface(typeface); + } } private void checkNewAccountAndBindView(Bundle savedInstanceState) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java index a9571923..40b858c6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java @@ -298,6 +298,9 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit mEditTextLinearLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); mSendMessageIconColor = mCustomThemeWrapper.getSendMessageIconColor(); mSendImageView.setColorFilter(mSendMessageIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + if (typeface != null) { + mEditText.setTypeface(typeface); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java index 659ff7a8..7731679f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java @@ -7,6 +7,7 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; @@ -37,6 +38,7 @@ import app.futured.hauler.DragDirection; import app.futured.hauler.HaulerView; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.CustomFontReceiver; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback; @@ -52,8 +54,9 @@ import ml.docilealligator.infinityforreddit.fragments.ViewRedditGalleryImageOrGi import ml.docilealligator.infinityforreddit.fragments.ViewRedditGalleryVideoFragment; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; -public class ViewRedditGalleryActivity extends AppCompatActivity implements SetAsWallpaperCallback { +public class ViewRedditGalleryActivity extends AppCompatActivity implements SetAsWallpaperCallback, CustomFontReceiver { public static final String EXTRA_REDDIT_GALLERY = "ERG"; public static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -68,6 +71,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA SharedPreferences sharedPreferences; @Inject Executor executor; + public Typeface typeface; private SectionsPagerAdapter sectionsPagerAdapter; private ArrayList<Post.Gallery> gallery; private String subredditName; @@ -194,11 +198,11 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA private void setToolbarTitle(int position) { if (gallery != null && position >= 0 && position < gallery.size()) { if (gallery.get(position).mediaType == Post.Gallery.TYPE_IMAGE) { - setTitle(Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.view_reddit_gallery_activity_image_label, position + 1, gallery.size()) + "</font>")); + setTitle(Utils.getTabTextWithCustomFont(typeface, Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.view_reddit_gallery_activity_image_label, position + 1, gallery.size()) + "</font>"))); } else if (gallery.get(position).mediaType == Post.Gallery.TYPE_GIF) { - setTitle(Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.view_reddit_gallery_activity_gif_label, position + 1, gallery.size()) + "</font>")); + setTitle(Utils.getTabTextWithCustomFont(typeface, Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.view_reddit_gallery_activity_gif_label, position + 1, gallery.size()) + "</font>"))); } else { - setTitle(Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.view_reddit_gallery_activity_video_label, position + 1, gallery.size()) + "</font>")); + setTitle(Utils.getTabTextWithCustomFont(typeface, Html.fromHtml("<font color=\"#FFFFFF\">" + getString(R.string.view_reddit_gallery_activity_video_label, position + 1, gallery.size()) + "</font>"))); } } } @@ -276,6 +280,11 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA return viewPager.getCurrentItem(); } + @Override + public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { + this.typeface = typeface; + } + private class SectionsPagerAdapter extends FragmentStatePagerAdapter { SectionsPagerAdapter(@NonNull FragmentManager fm) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 05af1b00..b2b82fa6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -558,6 +558,15 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp option4BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); applyTabLayoutTheme(tabLayout); applyFABTheme(fab); + if (typeface != null) { + subredditNameTextView.setTypeface(typeface); + subscribeSubredditChip.setTypeface(typeface); + nSubscribersTextView.setTypeface(typeface); + nOnlineSubscribersTextView.setTypeface(typeface); + sinceTextView.setTypeface(typeface); + creationTimeTextView.setTypeface(typeface); + descriptionTextView.setTypeface(typeface); + } unsubscribedColor = mCustomThemeWrapper.getUnsubscribed(); subscribedColor = mCustomThemeWrapper.getSubscribed(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index 9a1a120a..731c6aa9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -653,6 +653,13 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele descriptionTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); subscribeUserChip.setTextColor(mCustomThemeWrapper.getChipTextColor()); applyTabLayoutTheme(tabLayout); + if (typeface != null) { + userNameTextView.setTypeface(typeface); + karmaTextView.setTypeface(typeface); + cakedayTextView.setTypeface(typeface); + subscribeUserChip.setTypeface(typeface); + descriptionTextView.setTypeface(typeface); + } } private void checkNewAccountAndInitializeViewPager() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index 9431ca29..0586b8ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -14,6 +14,7 @@ import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Matrix; +import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.media.AudioManager; @@ -81,6 +82,7 @@ import app.futured.hauler.HaulerView; import app.futured.hauler.LockableNestedScrollView; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.CustomFontReceiver; import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks; import ml.docilealligator.infinityforreddit.FetchStreamableVideo; import ml.docilealligator.infinityforreddit.Infinity; @@ -106,7 +108,7 @@ import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; -public class ViewVideoActivity extends AppCompatActivity { +public class ViewVideoActivity extends AppCompatActivity implements CustomFontReceiver { public static final int PLAYBACK_SPEED_25 = 25; public static final int PLAYBACK_SPEED_50 = 50; @@ -168,6 +170,8 @@ public class ViewVideoActivity extends AppCompatActivity { @BindView(R.id.lockable_nested_scroll_view_view_video_activity) LockableNestedScrollView nestedScrollView; + public Typeface typeface; + private Uri mVideoUri; private SimpleExoPlayer player; private DefaultTrackSelector trackSelector; @@ -556,7 +560,7 @@ public class ViewVideoActivity extends AppCompatActivity { if (useBottomAppBar) { titleTextView.setText(Html.fromHtml(String.format("<font color=\"#FFFFFF\"><small>%s</small></font>", title))); } else { - setTitle(Html.fromHtml(String.format("<font color=\"#FFFFFF\"><small>%s</small></font>", title))); + setTitle(Utils.getTabTextWithCustomFont(typeface, Html.fromHtml(String.format("<font color=\"#FFFFFF\"><small>%s</small></font>", title)))); } } else { if (!useBottomAppBar) { @@ -808,6 +812,9 @@ public class ViewVideoActivity extends AppCompatActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.view_video_activity, menu); + for (int i = 0; i < menu.size(); i++) { + Utils.setTitleWithCustomFontToMenuItem(typeface, menu.getItem(i), null); + } return true; } @@ -941,4 +948,9 @@ public class ViewVideoActivity extends AppCompatActivity { } outState.putInt(PLAYBACK_SPEED_STATE, playbackSpeed); } + + @Override + public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { + this.typeface = typeface; + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java index 8c18718c..50bc0819 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java @@ -117,6 +117,7 @@ public class WebViewActivity extends BaseActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.web_view_activity, menu); + applyMenuItemTheme(menu); return true; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java index 19c5f5a2..552995b4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -338,6 +338,9 @@ public class WikiActivity extends BaseActivity { swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); mFetchWikiInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + if (typeface != null) { + mFetchWikiInfoTextView.setTypeface(typeface); + } } @Subscribe diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/AcknowledgementRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/AcknowledgementRecyclerViewAdapter.java index 9d9b0843..9e53600f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/AcknowledgementRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/AcknowledgementRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.content.Context; import android.content.Intent; import android.view.LayoutInflater; import android.view.View; @@ -14,16 +13,17 @@ import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.settings.Acknowledgement; public class AcknowledgementRecyclerViewAdapter extends RecyclerView.Adapter<AcknowledgementRecyclerViewAdapter.AcknowledgementViewHolder> { private ArrayList<Acknowledgement> acknowledgements; - private Context context; + private BaseActivity activity; - public AcknowledgementRecyclerViewAdapter(Context context, ArrayList<Acknowledgement> acknowledgements) { - this.context = context; + public AcknowledgementRecyclerViewAdapter(BaseActivity activity, ArrayList<Acknowledgement> acknowledgements) { + this.activity = activity; this.acknowledgements = acknowledgements; } @@ -40,10 +40,10 @@ public class AcknowledgementRecyclerViewAdapter extends RecyclerView.Adapter<Ack holder.nameTextView.setText(acknowledgement.getName()); holder.introductionTextView.setText(acknowledgement.getIntroduction()); holder.itemView.setOnClickListener(view -> { - if (context != null) { - Intent intent = new Intent(context, LinkResolverActivity.class); + if (activity != null) { + Intent intent = new Intent(activity, LinkResolverActivity.class); intent.setData(acknowledgement.getLink()); - context.startActivity(intent); + activity.startActivity(intent); } }); } @@ -65,6 +65,11 @@ public class AcknowledgementRecyclerViewAdapter extends RecyclerView.Adapter<Ack super(itemView); ButterKnife.bind(this, itemView); this.itemView = itemView; + + if (activity.typeface != null) { + nameTextView.setTypeface(activity.typeface); + introductionTextView.setTypeface(activity.typeface); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/AwardRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/AwardRecyclerViewAdapter.java index cfe0d799..8d0e9688 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/AwardRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/AwardRecyclerViewAdapter.java @@ -8,20 +8,23 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; +import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.award.Award; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.R; import pl.droidsonroids.gif.GifImageView; public class AwardRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private ArrayList<Award> awards; + private BaseActivity activity; private RequestManager glide; private ItemOnClickListener itemOnClickListener; private int primaryTextColor; @@ -31,10 +34,11 @@ public class AwardRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView. void onClick(Award award); } - public AwardRecyclerViewAdapter(RequestManager glide, CustomThemeWrapper customThemeWrapper, + public AwardRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, ItemOnClickListener itemOnClickListener) { awards = Award.getAvailableAwards(); - this.glide = glide; + this.activity = activity; + this.glide = Glide.with(activity); primaryTextColor = customThemeWrapper.getPrimaryTextColor(); secondaryTextColor = customThemeWrapper.getSecondaryTextColor(); this.itemOnClickListener = itemOnClickListener; @@ -52,7 +56,7 @@ public class AwardRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView. Award award = awards.get(position); glide.load(award.getIconUrl()).into(((AwardViewHolder) holder).iconImageView); ((AwardViewHolder) holder).nameTextView.setText(award.getName()); - ((AwardViewHolder) holder).desctiptionTextView.setText(award.getDescription()); + ((AwardViewHolder) holder).descriptionTextView.setText(award.getDescription()); ((AwardViewHolder) holder).coinTextView.setText(Integer.toString(award.getCoinPrice())); } } @@ -68,7 +72,7 @@ public class AwardRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView. if (holder instanceof AwardViewHolder) { glide.clear(((AwardViewHolder) holder).iconImageView); ((AwardViewHolder) holder).nameTextView.setText(""); - ((AwardViewHolder) holder).desctiptionTextView.setText(""); + ((AwardViewHolder) holder).descriptionTextView.setText(""); } } @@ -78,7 +82,7 @@ public class AwardRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView. @BindView(R.id.name_text_view_item_award) TextView nameTextView; @BindView(R.id.description_text_view_item_award) - TextView desctiptionTextView; + TextView descriptionTextView; @BindView(R.id.coin_text_view_item_award) TextView coinTextView; @@ -86,8 +90,13 @@ public class AwardRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView. super(itemView); ButterKnife.bind(this, itemView); + if (activity.typeface != null) { + nameTextView.setTypeface(activity.typeface); + descriptionTextView.setTypeface(activity.typeface); + coinTextView.setTypeface(activity.typeface); + } nameTextView.setTextColor(primaryTextColor); - desctiptionTextView.setTextColor(secondaryTextColor); + descriptionTextView.setTextColor(secondaryTextColor); coinTextView.setTextColor(primaryTextColor); itemView.setOnClickListener(view -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index 9665fb85..6ebce53e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -3,14 +3,9 @@ package ml.docilealligator.infinityforreddit.adapters; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; -import android.graphics.Color; import android.graphics.PorterDuff; import android.net.Uri; import android.os.Bundle; -import android.text.SpannableStringBuilder; -import android.text.Spanned; -import android.text.TextPaint; -import android.text.style.ClickableSpan; import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; @@ -32,8 +27,6 @@ import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; import java.util.Locale; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import butterknife.BindView; import butterknife.ButterKnife; @@ -54,6 +47,7 @@ import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity; import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity; @@ -65,10 +59,9 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView; import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; -import ml.docilealligator.infinityforreddit.markdown.SpoilerSpan; +import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; @@ -87,7 +80,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment return comment.getCommentMarkdown().equals(t1.getCommentMarkdown()); } }; - private AppCompatActivity mActivity; + private BaseActivity mActivity; private Retrofit mOauthRetrofit; private Locale mLocale; private Markwon mMarkwon; @@ -114,7 +107,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment private NetworkState networkState; private RetryLoadingMoreCallback mRetryLoadingMoreCallback; - public CommentsListingRecyclerViewAdapter(AppCompatActivity activity, Retrofit oauthRetrofit, + public CommentsListingRecyclerViewAdapter(BaseActivity activity, Retrofit oauthRetrofit, CustomThemeWrapper customThemeWrapper, Locale locale, SharedPreferences sharedPreferences, String accessToken, String accountName, RetryLoadingMoreCallback retryLoadingMoreCallback) { @@ -421,6 +414,16 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment commentDivider.setVisibility(View.VISIBLE); } + if (mActivity.typeface != null) { + authorTextView.setTypeface(mActivity.typeface); + authorFlairTextView.setTypeface(mActivity.typeface); + commentTimeTextView.setTypeface(mActivity.typeface); + awardsTextView.setTypeface(mActivity.typeface); + scoreTextView.setTypeface(mActivity.typeface); + } + if (mActivity.contentTypeface != null) { + commentMarkdownView.setTypeface(mActivity.typeface); + } itemView.setBackgroundColor(mCommentBackgroundColor); authorTextView.setTextColor(mUsernameColor); authorFlairTextView.setTextColor(mAuthorFlairColor); @@ -705,6 +708,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment ErrorViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + errorTextView.setTypeface(mActivity.typeface); + retryButton.setTypeface(mActivity.typeface); + } errorTextView.setText(R.string.load_comments_failed); retryButton.setOnClickListener(view -> mRetryLoadingMoreCallback.retryLoadingMore()); errorTextView.setTextColor(mSecondaryTextColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 64139e8c..512140c1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -22,7 +22,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; import androidx.core.graphics.drawable.DrawableCompat; @@ -45,7 +44,6 @@ import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.html.HtmlPlugin; import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.AutolinkInlineProcessor; -import io.noties.markwon.inlineparser.BackslashInlineProcessor; import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; @@ -55,6 +53,7 @@ import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity; @@ -86,7 +85,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi private static final int VIEW_TYPE_LOAD_MORE_COMMENTS_FAILED = 16; private static final int VIEW_TYPE_VIEW_ALL_COMMENTS = 17; - private AppCompatActivity mActivity; + private BaseActivity mActivity; private ViewPostDetailFragment mFragment; private Executor mExecutor; private Retrofit mRetrofit; @@ -145,7 +144,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi private int mSearchCommentIndex = -1; - public CommentsRecyclerViewAdapter(AppCompatActivity activity, ViewPostDetailFragment fragment, + public CommentsRecyclerViewAdapter(BaseActivity activity, ViewPostDetailFragment fragment, CustomThemeWrapper customThemeWrapper, Executor executor, Retrofit retrofit, Retrofit oauthRetrofit, String accessToken, String accountName, @@ -1119,6 +1118,17 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi commentDivider.setVisibility(View.VISIBLE); } + if (mActivity.typeface != null) { + authorTextView.setTypeface(mActivity.typeface); + commentTimeTextView.setTypeface(mActivity.typeface); + authorFlairTextView.setTypeface(mActivity.typeface); + topScoreTextView.setTypeface(mActivity.typeface); + awardsTextView.setTypeface(mActivity.typeface); + scoreTextView.setTypeface(mActivity.typeface); + } + if (mActivity.contentTypeface != null) { + commentMarkdownView.setTypeface(mActivity.contentTypeface); + } itemView.setBackgroundColor(mCommentBackgroundColor); authorTextView.setTextColor(mUsernameColor); commentTimeTextView.setTextColor(mSecondaryTextColor); @@ -1440,16 +1450,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi } }); - /*commentMarkdownView.setMovementMethod(BetterLinkMovementMethod.newInstance().setOnLinkLongClickListener((textView, url) -> { - if (!mActivity.isDestroyed() && !mActivity.isFinishing()) { - UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url); - urlMenuBottomSheetFragment.setArguments(bundle); - urlMenuBottomSheetFragment.show(mActivity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag()); - } - return true; - }));*/ if (mSwapTapAndLong) { if (mCommentToolbarHideOnClick) { View.OnLongClickListener hideToolbarOnLongClickListener = view -> hideToolbar(); @@ -1547,6 +1547,11 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + usernameTextView.setTypeface(mActivity.typeface); + scoreTextView.setTypeface(mActivity.typeface); + commentTimeTextView.setTypeface(mActivity.typeface); + } itemView.setBackgroundColor(mFullyCollapsedCommentBackgroundColor); usernameTextView.setTextColor(mUsernameColor); scoreTextView.setTextColor(mSecondaryTextColor); @@ -1602,6 +1607,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi commentDivider.setVisibility(View.VISIBLE); } + if (mActivity.typeface != null) { + placeholderTextView.setTypeface(mActivity.typeface); + } itemView.setBackgroundColor(mCommentBackgroundColor); placeholderTextView.setTextColor(mPrimaryTextColor); commentDivider.setBackgroundColor(mDividerColor); @@ -1628,6 +1636,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi super(itemView); ButterKnife.bind(this, itemView); itemView.setOnClickListener(view -> mCommentRecyclerViewAdapterCallback.retryFetchingComments()); + if (mActivity.typeface != null) { + errorTextView.setTypeface(mActivity.typeface); + } errorTextView.setTextColor(mSecondaryTextColor); } } @@ -1639,6 +1650,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi NoCommentViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + errorTextView.setTypeface(mActivity.typeface); + } errorTextView.setTextColor(mSecondaryTextColor); } } @@ -1663,6 +1677,10 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi LoadMoreCommentsFailedViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + errorTextView.setTypeface(mActivity.typeface); + retryButton.setTypeface(mActivity.typeface); + } errorTextView.setText(R.string.load_comments_failed); retryButton.setOnClickListener(view -> mCommentRecyclerViewAdapterCallback.retryFetchingMoreComments()); errorTextView.setTextColor(mSecondaryTextColor); @@ -1685,6 +1703,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi } }); + if (mActivity.typeface != null) { + ((TextView) itemView).setTypeface(mActivity.typeface); + } itemView.setBackgroundTintList(ColorStateList.valueOf(mCommentBackgroundColor)); ((TextView) itemView).setTextColor(mColorAccent); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CrashReportsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CrashReportsRecyclerViewAdapter.java index 641562b9..810f8648 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CrashReportsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CrashReportsRecyclerViewAdapter.java @@ -11,11 +11,14 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.List; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; public class CrashReportsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + private BaseActivity activity; private List<String> crashReports; - public CrashReportsRecyclerViewAdapter(List<String> crashReports) { + public CrashReportsRecyclerViewAdapter(BaseActivity activity, List<String> crashReports) { + this.activity = activity; this.crashReports = crashReports; } @@ -40,6 +43,10 @@ public class CrashReportsRecyclerViewAdapter extends RecyclerView.Adapter<Recycl public CrashReportViewHolder(@NonNull View itemView) { super(itemView); crashReportTextView = (TextView) itemView; + + if (activity.typeface != null) { + crashReportTextView.setTypeface(activity.typeface); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java index 127c6955..e9aa20ec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java @@ -10,7 +10,6 @@ import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; @@ -18,11 +17,12 @@ import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CustomThemeListingActivity; import ml.docilealligator.infinityforreddit.activities.CustomizeThemeActivity; -import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; import ml.docilealligator.infinityforreddit.bottomsheetfragments.CustomThemeOptionsBottomSheetFragment; -import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int VIEW_TYPE_PREDEFINED_THEME = 0; @@ -30,11 +30,11 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< private static final int VIEW_TYPE_PREDEFINED_THEME_DIVIDER = 2; private static final int VIEW_TYPE_USER_THEME_DIVIDER = 3; - private AppCompatActivity activity; + private BaseActivity activity; private ArrayList<CustomTheme> predefinedCustomThemes; private ArrayList<CustomTheme> userCustomThemes; - public CustomThemeListingRecyclerViewAdapter(AppCompatActivity activity, ArrayList<CustomTheme> predefinedCustomThemes) { + public CustomThemeListingRecyclerViewAdapter(BaseActivity activity, ArrayList<CustomTheme> predefinedCustomThemes) { this.activity = activity; this.predefinedCustomThemes = predefinedCustomThemes; userCustomThemes = new ArrayList<>(); @@ -134,6 +134,9 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< PredefinedCustomThemeViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (activity.typeface != null) { + nameTextView.setTypeface(activity.typeface); + } } } @@ -151,6 +154,9 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< UserCustomThemeViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (activity.typeface != null) { + nameTextView.setTypeface(activity.typeface); + } } } @@ -158,6 +164,9 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< PreDefinedThemeDividerViewHolder(@NonNull View itemView) { super(itemView); + if (activity.typeface != null) { + ((TextView) itemView).setTypeface(activity.typeface); + } } } @@ -165,6 +174,9 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< UserThemeDividerViewHolder(@NonNull View itemView) { super(itemView); + if (activity.typeface != null) { + ((TextView) itemView).setTypeface(activity.typeface); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomizeThemeRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomizeThemeRecyclerViewAdapter.java index 37af8c46..1cf3879c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomizeThemeRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomizeThemeRecyclerViewAdapter.java @@ -7,33 +7,33 @@ import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; -import android.widget.Switch; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.switchmaterial.SwitchMaterial; import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeSettingsItem; import ml.docilealligator.infinityforreddit.customviews.ColorPickerDialog; -import ml.docilealligator.infinityforreddit.R; public class CustomizeThemeRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int VIEW_TYPE_COLOR = 1; private static final int VIEW_TYPE_SWITCH = 2; private static final int VIEW_TYPE_THEME_NAME = 3; - private AppCompatActivity activity; + private BaseActivity activity; private ArrayList<CustomThemeSettingsItem> customThemeSettingsItems; private String themeName; private boolean isPredefinedTheme; - public CustomizeThemeRecyclerViewAdapter(AppCompatActivity activity, String themeName, + public CustomizeThemeRecyclerViewAdapter(BaseActivity activity, String themeName, boolean isPredefinedTheme) { this.activity = activity; customThemeSettingsItems = new ArrayList<>(); @@ -148,6 +148,10 @@ public class CustomizeThemeRecyclerViewAdapter extends RecyclerView.Adapter<Recy ThemeColorItemViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (activity.typeface != null) { + themeItemNameTextView.setTypeface(activity.typeface); + themeItemInfoTextView.setTypeface(activity.typeface); + } } } @@ -157,11 +161,15 @@ public class CustomizeThemeRecyclerViewAdapter extends RecyclerView.Adapter<Recy @BindView(R.id.theme_item_info_text_view_item_custom_theme_switch_item) TextView themeItemInfoTextView; @BindView(R.id.theme_item_switch_item_custom_theme_switch_item) - Switch themeItemSwitch; + SwitchMaterial themeItemSwitch; ThemeSwitchItemViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (activity.typeface != null) { + themeItemNameTextView.setTypeface(activity.typeface); + themeItemInfoTextView.setTypeface(activity.typeface); + } } } @@ -173,6 +181,10 @@ public class CustomizeThemeRecyclerViewAdapter extends RecyclerView.Adapter<Recy public ThemeNameItemViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (activity.typeface != null) { + themeNameTextView.setTypeface(activity.typeface); + descriptionTextView.setTypeface(activity.typeface); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FlairBottomSheetRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FlairBottomSheetRecyclerViewAdapter.java index 399726d0..cc36dde5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FlairBottomSheetRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FlairBottomSheetRecyclerViewAdapter.java @@ -19,19 +19,20 @@ import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.Flair; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; public class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter<FlairBottomSheetRecyclerViewAdapter.FlairViewHolder> { - private Context context; + private BaseActivity activity; private ArrayList<Flair> flairs; private int flairTextColor; private ItemClickListener itemClickListener; - public FlairBottomSheetRecyclerViewAdapter(Context context, CustomThemeWrapper customThemeWrapper, + public FlairBottomSheetRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, ItemClickListener itemClickListener) { - this.context = context; + this.activity = activity; flairTextColor = customThemeWrapper.getPrimaryTextColor(); this.itemClickListener = itemClickListener; } @@ -47,14 +48,14 @@ public class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter<Fl if (flairs.get(holder.getBindingAdapterPosition()).isEditable()) { holder.editFlairImageView.setVisibility(View.VISIBLE); holder.editFlairImageView.setOnClickListener(view -> { - View dialogView = ((Activity) context).getLayoutInflater().inflate(R.layout.dialog_edit_flair, null); + View dialogView = ((Activity) activity).getLayoutInflater().inflate(R.layout.dialog_edit_flair, null); EditText flairEditText = dialogView.findViewById(R.id.flair_edit_text_edit_flair_dialog); flairEditText.requestFocus(); - InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); } - new MaterialAlertDialogBuilder(context, R.style.MaterialAlertDialogTheme) + new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme) .setTitle(R.string.edit_flair) .setView(dialogView) .setPositiveButton(R.string.ok, (dialogInterface, i) @@ -109,6 +110,10 @@ public class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter<Fl ButterKnife.bind(this, itemView); this.itemView = itemView; flairTextView.setTextColor(flairTextColor); + + if (activity.typeface != null) { + flairTextView.setTypeface(activity.typeface); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java index 89bae0c9..33be9ea3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.content.Context; import android.content.Intent; import android.os.Handler; import android.view.LayoutInflater; @@ -27,6 +26,7 @@ import me.zhanghai.android.fastscroll.PopupTextProvider; import ml.docilealligator.infinityforreddit.FavoriteThing; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; @@ -41,7 +41,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc private List<SubscribedUserData> mSubscribedUserData; private List<SubscribedUserData> mFavoriteSubscribedUserData; - private Context mContext; + private BaseActivity mActivity; private Executor mExecutor; private Retrofit mOauthRetrofit; private RedditDataRoomDatabase mRedditDataRoomDatabase; @@ -50,16 +50,16 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc private int mPrimaryTextColor; private int mSecondaryTextColor; - public FollowedUsersRecyclerViewAdapter(Context context, Executor executor, Retrofit oauthRetrofit, + public FollowedUsersRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, CustomThemeWrapper customThemeWrapper, String accessToken) { - mContext = context; + mActivity = activity; mExecutor = executor; mOauthRetrofit = oauthRetrofit; mRedditDataRoomDatabase = redditDataRoomDatabase; mAccessToken = accessToken; - glide = Glide.with(context); + glide = Glide.with(activity); mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor(); mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor(); } @@ -202,14 +202,17 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc FavoriteUserViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + userNameTextView.setTypeface(mActivity.typeface); + } userNameTextView.setTextColor(mPrimaryTextColor); itemView.setOnClickListener(view -> { int position = getBindingAdapterPosition() - 1; if(position >= 0 && mFavoriteSubscribedUserData.size() > position) { - Intent intent = new Intent(mContext, ViewUserDetailActivity.class); + Intent intent = new Intent(mActivity, ViewUserDetailActivity.class); intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mFavoriteSubscribedUserData.get(position).getName()); - mContext.startActivity(intent); + mActivity.startActivity(intent); } }); @@ -234,7 +237,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc @Override public void failed() { - Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); int position = getBindingAdapterPosition() - 1; if(position >= 0 && mFavoriteSubscribedUserData.size() > position) { mFavoriteSubscribedUserData.get(position).setFavorite(true); @@ -260,7 +263,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc @Override public void failed() { - Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); int position = getBindingAdapterPosition() - 1; if(position >= 0 && mFavoriteSubscribedUserData.size() > position) { mFavoriteSubscribedUserData.get(position).setFavorite(false); @@ -285,6 +288,9 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc UserViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + userNameTextView.setTypeface(mActivity.typeface); + } userNameTextView.setTextColor(mPrimaryTextColor); itemView.setOnClickListener(view -> { @@ -292,9 +298,9 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc mFavoriteSubscribedUserData.size() + 2 : 0; int position = getBindingAdapterPosition() - offset; if(position >= 0 && mSubscribedUserData.size() > position) { - Intent intent = new Intent(mContext, ViewUserDetailActivity.class); + Intent intent = new Intent(mActivity, ViewUserDetailActivity.class); intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mSubscribedUserData.get(position).getName()); - mContext.startActivity(intent); + mActivity.startActivity(intent); } }); @@ -322,7 +328,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc @Override public void failed() { - Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); int position = getBindingAdapterPosition() - offset; if(position >= 0 && mSubscribedUserData.size() > position) { mSubscribedUserData.get(position).setFavorite(true); @@ -348,7 +354,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc @Override public void failed() { - Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); int position = getBindingAdapterPosition() - offset; if(position >= 0 && mSubscribedUserData.size() > position) { mSubscribedUserData.get(position).setFavorite(false); @@ -368,6 +374,9 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc FavoriteUsersDividerViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + dividerTextView.setTypeface(mActivity.typeface); + } dividerTextView.setText(R.string.favorites); dividerTextView.setTextColor(mSecondaryTextColor); } @@ -379,6 +388,9 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc AllUsersDividerViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + dividerTextView.setTypeface(mActivity.typeface); + } dividerTextView.setText(R.string.all); dividerTextView.setTextColor(mSecondaryTextColor); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java index 38886715..d558d500 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java @@ -1,15 +1,9 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.content.Context; import android.content.Intent; import android.content.res.ColorStateList; -import android.graphics.Color; import android.net.Uri; -import android.text.SpannableStringBuilder; -import android.text.Spanned; -import android.text.TextPaint; import android.text.method.LinkMovementMethod; -import android.text.style.ClickableSpan; import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; @@ -24,8 +18,6 @@ import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import butterknife.BindView; import butterknife.ButterKnife; @@ -43,16 +35,16 @@ import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewPrivateMessagesActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; -import ml.docilealligator.infinityforreddit.markdown.SpoilerSpan; +import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.message.FetchMessage; import ml.docilealligator.infinityforreddit.message.Message; import ml.docilealligator.infinityforreddit.message.ReadMessage; -import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; @@ -71,7 +63,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl return message.getBody().equals(t1.getBody()); } }; - private Context mContext; + private BaseActivity mActivity; private Retrofit mOauthRetrofit; private Markwon mMarkwon; private String mAccessToken; @@ -88,12 +80,12 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl private int mButtonTextColor; private boolean markAllMessagesAsRead = false; - public MessageRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, + public MessageRecyclerViewAdapter(BaseActivity activity, Retrofit oauthRetrofit, CustomThemeWrapper customThemeWrapper, String accessToken, String where, RetryLoadingMoreCallback retryLoadingMoreCallback) { super(DIFF_CALLBACK); - mContext = context; + mActivity = activity; mOauthRetrofit = oauthRetrofit; mRetryLoadingMoreCallback = retryLoadingMoreCallback; @@ -107,7 +99,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); mButtonTextColor = customThemeWrapper.getButtonTextColor(); - mMarkwon = Markwon.builder(mContext) + mMarkwon = Markwon.builder(mActivity) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); plugin.excludeInlineProcessor(HtmlInlineProcessor.class); @@ -127,10 +119,10 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { builder.linkResolver((view, link) -> { - Intent intent = new Intent(mContext, LinkResolverActivity.class); + Intent intent = new Intent(mActivity, LinkResolverActivity.class); Uri uri = Uri.parse(link); intent.setData(uri); - mContext.startActivity(intent); + mActivity.startActivity(intent); }); } @@ -199,14 +191,14 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl if (mMessageType == FetchMessage.MESSAGE_TYPE_INBOX && message.getContext() != null && !message.getContext().equals("")) { Uri uri = Uri.parse(message.getContext()); - Intent intent = new Intent(mContext, LinkResolverActivity.class); + Intent intent = new Intent(mActivity, LinkResolverActivity.class); intent.setData(uri); - mContext.startActivity(intent); + mActivity.startActivity(intent); } else if (mMessageType == FetchMessage.MESSAGE_TYPE_PRIVATE_MESSAGE) { - Intent intent = new Intent(mContext, ViewPrivateMessagesActivity.class); + Intent intent = new Intent(mActivity, ViewPrivateMessagesActivity.class); intent.putExtra(ViewPrivateMessagesActivity.EXTRA_PRIVATE_MESSAGE, message); intent.putExtra(ViewPrivateMessagesActivity.EXTRA_MESSAGE_POSITION, holder.getBindingAdapterPosition()); - mContext.startActivity(intent); + mActivity.startActivity(intent); } if (displayedMessage.isNew()) { @@ -229,9 +221,9 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl }); ((DataViewHolder) holder).authorTextView.setOnClickListener(view -> { - Intent intent = new Intent(mContext, ViewUserDetailActivity.class); + Intent intent = new Intent(mActivity, ViewUserDetailActivity.class); intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getAuthor()); - mContext.startActivity(intent); + mActivity.startActivity(intent); }); ((DataViewHolder) holder).contentCustomMarkwonView.setOnClickListener(view -> { @@ -325,6 +317,12 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl DataViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + authorTextView.setTypeface(mActivity.typeface); + subjectTextView.setTypeface(mActivity.typeface); + titleTextView.setTypeface(mActivity.titleTypeface); + contentCustomMarkwonView.setTypeface(mActivity.contentTypeface); + } itemView.setBackgroundColor(mMessageBackgroundColor); authorTextView.setTextColor(mUsernameColor); subjectTextView.setTextColor(mPrimaryTextColor); @@ -344,6 +342,10 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl ErrorViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + errorTextView.setTypeface(mActivity.typeface); + retryButton.setTypeface(mActivity.typeface); + } errorTextView.setText(R.string.load_comments_failed); errorTextView.setTextColor(mSecondaryTextColor); retryButton.setOnClickListener(view -> mRetryLoadingMoreCallback.retryLoadingMore()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java index bb8f1420..3f75f967 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java @@ -9,7 +9,6 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; @@ -25,6 +24,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import me.zhanghai.android.fastscroll.PopupTextProvider; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.asynctasks.InsertMultireddit; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.multireddit.FavoriteMultiReddit; @@ -39,7 +39,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< private static final int VIEW_TYPE_MULTI_REDDIT_DIVIDER = 2; private static final int VIEW_TYPE_MULTI_REDDIT = 3; - private AppCompatActivity mActivity; + private BaseActivity mActivity; private Executor mExecutor; private Retrofit mOauthRetrofit; private RedditDataRoomDatabase mRedditDataRoomDatabase; @@ -57,7 +57,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< void onLongClick(MultiReddit multiReddit); } - public MultiRedditListingRecyclerViewAdapter(AppCompatActivity activity, Executor executor, Retrofit oauthRetrofit, + public MultiRedditListingRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, CustomThemeWrapper customThemeWrapper, String accessToken, OnItemClickListener onItemClickListener) { @@ -377,6 +377,9 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< MultiRedditViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + multiRedditNameTextView.setTypeface(mActivity.typeface); + } multiRedditNameTextView.setTextColor(mPrimaryTextColor); } } @@ -392,6 +395,9 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< FavoriteMultiRedditViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + multiRedditNameTextView.setTypeface(mActivity.typeface); + } multiRedditNameTextView.setTextColor(mPrimaryTextColor); } } @@ -402,6 +408,9 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< FavoriteMultiRedditsDividerViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + dividerTextView.setTypeface(mActivity.typeface); + } dividerTextView.setText(R.string.favorites); dividerTextView.setTextColor(mSecondaryTextColor); } @@ -413,6 +422,9 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter< AllMultiRedditsDividerViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + dividerTextView.setTypeface(mActivity.typeface); + } dividerTextView.setText(R.string.all); dividerTextView.setTextColor(mSecondaryTextColor); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java index 3fa436b4..d5e0f502 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java @@ -12,7 +12,6 @@ import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.biometric.BiometricManager; import androidx.biometric.BiometricPrompt; import androidx.core.content.ContextCompat; @@ -32,6 +31,7 @@ import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.account.Account; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.InboxActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; @@ -62,7 +62,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re private static final int POST_SECTION_ITEMS = 5; private static final int PREFERENCES_SECTION_ITEMS = 3; - private AppCompatActivity appCompatActivity; + private BaseActivity baseActivity; private Resources resources; private RequestManager glide; private String accountName; @@ -92,15 +92,15 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re private int dividerColor; private int primaryIconColor; - public NavigationDrawerRecyclerViewAdapter(AppCompatActivity appCompatActivity, SharedPreferences sharedPreferences, + public NavigationDrawerRecyclerViewAdapter(BaseActivity baseActivity, SharedPreferences sharedPreferences, SharedPreferences nsfwAndSpoilerSharedPreferences, SharedPreferences navigationDrawerSharedPreferences, CustomThemeWrapper customThemeWrapper, String accountName, ItemClickListener itemClickListener) { - this.appCompatActivity = appCompatActivity; - resources = appCompatActivity.getResources(); - glide = Glide.with(appCompatActivity); + this.baseActivity = baseActivity; + resources = baseActivity.getResources(); + glide = Glide.with(baseActivity); this.accountName = accountName; isNSFWEnabled = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); requireAuthToAccountSection = sharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false); @@ -238,7 +238,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re } ((NavHeaderViewHolder) holder).profileImageView.setLayoutParams(params); if (isLoggedIn) { - ((NavHeaderViewHolder) holder).karmaTextView.setText(appCompatActivity.getString(R.string.karma_info, karma)); + ((NavHeaderViewHolder) holder).karmaTextView.setText(baseActivity.getString(R.string.karma_info, karma)); ((NavHeaderViewHolder) holder).accountNameTextView.setText(accountName); if (profileImageUrl != null && !profileImageUrl.equals("")) { glide.load(profileImageUrl) @@ -272,10 +272,10 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re holder.itemView.setOnClickListener(view -> { if (isInMainPage) { if (requireAuthToAccountSection) { - BiometricManager biometricManager = BiometricManager.from(appCompatActivity); + BiometricManager biometricManager = BiometricManager.from(baseActivity); if (biometricManager.canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) == BiometricManager.BIOMETRIC_SUCCESS) { - Executor executor = ContextCompat.getMainExecutor(appCompatActivity); - BiometricPrompt biometricPrompt = new BiometricPrompt(appCompatActivity, + Executor executor = ContextCompat.getMainExecutor(baseActivity); + BiometricPrompt biometricPrompt = new BiometricPrompt(baseActivity, executor, new BiometricPrompt.AuthenticationCallback() { @Override public void onAuthenticationSucceeded( @@ -286,7 +286,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re }); BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder() - .setTitle(appCompatActivity.getString(R.string.unlock_account_section)) + .setTitle(baseActivity.getString(R.string.unlock_account_section)) .setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) .build(); @@ -473,14 +473,14 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re case 5: setOnClickListener = false; if (inboxCount > 0) { - ((MenuItemViewHolder) holder).menuTextView.setText(appCompatActivity.getString(R.string.inbox_with_count, inboxCount)); + ((MenuItemViewHolder) holder).menuTextView.setText(baseActivity.getString(R.string.inbox_with_count, inboxCount)); } else { ((MenuItemViewHolder) holder).menuTextView.setText(R.string.inbox); } - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_inbox_24dp)); + ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, R.drawable.ic_inbox_24dp)); holder.itemView.setOnClickListener(view -> { - Intent intent = new Intent(appCompatActivity, InboxActivity.class); - appCompatActivity.startActivity(intent); + Intent intent = new Intent(baseActivity, InboxActivity.class); + baseActivity.startActivity(intent); }); break; case 7: @@ -534,12 +534,12 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re if (isNSFWEnabled) { isNSFWEnabled = false; ((MenuItemViewHolder) holder).menuTextView.setText(R.string.enable_nsfw); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_nsfw_on_24dp)); + ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, R.drawable.ic_nsfw_on_24dp)); itemClickListener.onMenuClick(R.string.disable_nsfw); } else { isNSFWEnabled = true; ((MenuItemViewHolder) holder).menuTextView.setText(R.string.disable_nsfw); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_nsfw_off_24dp)); + ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, R.drawable.ic_nsfw_off_24dp)); itemClickListener.onMenuClick(R.string.enable_nsfw); } }); @@ -585,12 +585,12 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re if (isNSFWEnabled) { isNSFWEnabled = false; ((MenuItemViewHolder) holder).menuTextView.setText(R.string.enable_nsfw); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_nsfw_on_24dp)); + ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, R.drawable.ic_nsfw_on_24dp)); itemClickListener.onMenuClick(R.string.disable_nsfw); } else { isNSFWEnabled = true; ((MenuItemViewHolder) holder).menuTextView.setText(R.string.disable_nsfw); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_nsfw_off_24dp)); + ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, R.drawable.ic_nsfw_off_24dp)); itemClickListener.onMenuClick(R.string.enable_nsfw); } }); @@ -621,7 +621,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re if (stringId != 0) { ((MenuItemViewHolder) holder).menuTextView.setText(stringId); - ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, drawableId)); + ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(baseActivity, drawableId)); if (setOnClickListener) { int finalStringId = stringId; holder.itemView.setOnClickListener(view -> itemClickListener.onMenuClick(finalStringId)); @@ -863,6 +863,11 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re NavHeaderViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + + if (baseActivity.typeface != null) { + accountNameTextView.setTypeface(baseActivity.typeface); + karmaTextView.setTypeface(baseActivity.typeface); + } } } @@ -875,6 +880,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re MenuGroupTitleViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (baseActivity.typeface != null) { + titleTextView.setTypeface(baseActivity.typeface); + } titleTextView.setTextColor(secondaryTextColor); collapseIndicatorImageView.setColorFilter(secondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN); } @@ -889,6 +897,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re MenuItemViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (baseActivity.typeface != null) { + menuTextView.setTypeface(baseActivity.typeface); + } menuTextView.setTextColor(primaryTextColor); imageView.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN); } @@ -911,6 +922,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re FavoriteSubscribedThingViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (baseActivity.typeface != null) { + subredditNameTextView.setTypeface(baseActivity.typeface); + } subredditNameTextView.setTextColor(primaryTextColor); } } @@ -924,6 +938,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re SubscribedThingViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (baseActivity.typeface != null) { + subredditNameTextView.setTypeface(baseActivity.typeface); + } subredditNameTextView.setTextColor(primaryTextColor); } } @@ -937,6 +954,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re AccountViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (baseActivity.typeface != null) { + usernameTextView.setTypeface(baseActivity.typeface); + } usernameTextView.setTextColor(primaryTextColor); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/Paging3LoadingStateAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/Paging3LoadingStateAdapter.java index 3f80d65e..4f767703 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/Paging3LoadingStateAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/Paging3LoadingStateAdapter.java @@ -15,14 +15,17 @@ import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.button.MaterialButton; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; public class Paging3LoadingStateAdapter extends LoadStateAdapter<Paging3LoadingStateAdapter.LoadStateViewHolder> { + private BaseActivity activity; private CustomThemeWrapper mCustomThemeWrapper; private int mErrorStringId; private View.OnClickListener mRetryCallback; - public Paging3LoadingStateAdapter(CustomThemeWrapper customThemeWrapper, int errorStringId, View.OnClickListener retryCallback) { + public Paging3LoadingStateAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, int errorStringId, View.OnClickListener retryCallback) { + this.activity = activity; this.mCustomThemeWrapper = customThemeWrapper; this.mErrorStringId = errorStringId; this.mRetryCallback = retryCallback; @@ -59,6 +62,11 @@ public class Paging3LoadingStateAdapter extends LoadStateAdapter<Paging3LoadingS mRetry.setTextColor(mCustomThemeWrapper.getButtonTextColor()); mRetry.setOnClickListener(retryCallback); mErrorView.setOnClickListener(retryCallback); + + if (activity.typeface != null) { + mErrorMsg.setTypeface(activity.typeface); + mRetry.setTypeface(activity.typeface); + } } public void bind(LoadState loadState) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 6b63a0c0..476651e8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -27,7 +27,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; import androidx.core.graphics.drawable.DrawableCompat; @@ -90,6 +89,7 @@ import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStra import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.StreamableVideo; import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; @@ -131,7 +131,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler private static final int VIEW_TYPE_POST_DETAIL_NO_PREVIEW_LINK = 6; private static final int VIEW_TYPE_POST_DETAIL_GALLERY = 7; private static final int VIEW_TYPE_POST_DETAIL_TEXT_TYPE = 8; - private AppCompatActivity mActivity; + private BaseActivity mActivity; private ViewPostDetailFragment mFragment; private Executor mExecutor; private Retrofit mRetrofit; @@ -210,7 +210,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler private boolean canStartActivity = true; private boolean canPlayVideo = true; - public PostDetailRecyclerViewAdapter(AppCompatActivity activity, ViewPostDetailFragment fragment, + public PostDetailRecyclerViewAdapter(BaseActivity activity, ViewPostDetailFragment fragment, Executor executor, CustomThemeWrapper customThemeWrapper, Retrofit retrofit, Retrofit oauthRetrofit, Retrofit gfycatRetrofit, Retrofit redgifsRetrofit, Retrofit streamableRetrofit, @@ -255,6 +255,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { + if (mActivity.contentTypeface != null) { + textView.setTypeface(mActivity.typeface); + } textView.setTextColor(markdownColor); textView.setOnLongClickListener(view -> { if (textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) { @@ -841,14 +844,14 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler ((PostDetailGalleryViewHolder) holder).mCaptionConstraintLayout.setVisibility(View.VISIBLE); } if (!previewCaptionIsEmpty) { - ((PostDetailGalleryViewHolder) holder).mCaption.setTextColor(mCommentColor); - ((PostDetailGalleryViewHolder) holder).mCaption.setText(previewCaption); - ((PostDetailGalleryViewHolder) holder).mCaption.setSelected(true); + ((PostDetailGalleryViewHolder) holder).mCaptionTextView.setTextColor(mCommentColor); + ((PostDetailGalleryViewHolder) holder).mCaptionTextView.setText(previewCaption); + ((PostDetailGalleryViewHolder) holder).mCaptionTextView.setSelected(true); } if (!previewCaptionUrlIsEmpty) { String domain = Uri.parse(previewCaptionUrl).getHost(); domain = domain.startsWith("www.") ? domain.substring(4) : domain; - mPostDetailMarkwon.setMarkdown(((PostDetailGalleryViewHolder) holder).mCaptionUrl, String.format("[%s](%s)", domain, previewCaptionUrl)); + mPostDetailMarkwon.setMarkdown(((PostDetailGalleryViewHolder) holder).mCaptionUrlTextView, String.format("[%s](%s)", domain, previewCaptionUrl)); } } } @@ -1512,6 +1515,23 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler constraintSet.applyTo(mBottomConstraintLayout); } + if (mActivity.typeface != null) { + mSubredditTextView.setTypeface(mActivity.typeface); + mUserTextView.setTypeface(mActivity.typeface); + mAuthorFlairTextView.setTypeface(mActivity.typeface); + mPostTimeTextView.setTypeface(mActivity.typeface); + mTypeTextView.setTypeface(mActivity.typeface); + mSpoilerTextView.setTypeface(mActivity.typeface); + mNSFWTextView.setTypeface(mActivity.typeface); + mFlairTextView.setTypeface(mActivity.typeface); + mAwardsTextView.setTypeface(mActivity.typeface); + mUpvoteRatioTextView.setTypeface(mActivity.typeface); + mScoreTextView.setTypeface(mActivity.typeface); + commentsCountTextView.setTypeface(mActivity.typeface); + } + if (mActivity.titleTypeface != null) { + mTitleTextView.setTypeface(mActivity.typeface); + } itemView.setBackgroundColor(mCardViewColor); mSubredditTextView.setTextColor(mSubredditColor); mUserTextView.setTextColor(mUsernameColor); @@ -2114,6 +2134,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler mSaveButton, mShareButton); + if (mActivity.typeface != null) { + mLinkTextView.setTypeface(mActivity.typeface); + } mLinkTextView.setTextColor(mSecondaryTextColor); mLoadImageProgressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); mLoadImageErrorTextView.setTextColor(mPrimaryTextColor); @@ -2206,6 +2229,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler mSaveButton, mShareButton); + if (mActivity.typeface != null) { + mLinkTextView.setTypeface(mActivity.typeface); + } mLinkTextView.setTextColor(mSecondaryTextColor); mNoPreviewPostTypeImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); mNoPreviewPostTypeImageView.setColorFilter(mNoPreviewPostTypeIconTint, PorterDuff.Mode.SRC_IN); @@ -2311,9 +2337,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler @BindView(R.id.caption_constraint_layout_item_post_detail_gallery) ConstraintLayout mCaptionConstraintLayout; @BindView(R.id.caption_text_view_item_post_detail_gallery) - TextView mCaption; + TextView mCaptionTextView; @BindView(R.id.caption_url_text_view_item_post_detail_gallery) - TextView mCaptionUrl; + TextView mCaptionUrlTextView; @BindView(R.id.image_view_no_preview_link_item_post_detail_gallery) ImageView mNoPreviewPostTypeImageView; @BindView(R.id.bottom_constraint_layout_item_post_detail_gallery) @@ -2357,6 +2383,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler mSaveButton, mShareButton); + if (mActivity.typeface != null) { + mLoadImageErrorTextView.setTypeface(mActivity.typeface); + mCaptionTextView.setTypeface(mActivity.typeface); + mCaptionUrlTextView.setTypeface(mActivity.typeface); + } videoOrGifIndicatorImageView.setColorFilter(mMediaIndicatorIconTint, PorterDuff.Mode.SRC_IN); videoOrGifIndicatorImageView.setBackgroundTintList(ColorStateList.valueOf(mMediaIndicatorBackgroundColor)); mLoadImageProgressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java index 4faab908..9b6b2bd5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterRecyclerViewAdapter.java @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.List; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -18,6 +19,7 @@ public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<Recycler private static final int VIEW_TYPE_HEADER = 1; private static final int VIEW_TYPE_POST_FILTER = 2; + private BaseActivity activity; private final OnItemClickListener onItemClickListener; private List<PostFilter> postFilterList; @@ -25,7 +27,8 @@ public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<Recycler void onItemClick(PostFilter postFilter); } - public PostFilterRecyclerViewAdapter(OnItemClickListener onItemClickListener) { + public PostFilterRecyclerViewAdapter(BaseActivity activity, OnItemClickListener onItemClickListener) { + this.activity = activity; this.onItemClickListener = onItemClickListener; } @@ -70,6 +73,11 @@ public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<Recycler public PostFilterViewHolder(@NonNull View itemView) { super(itemView); textView = (TextView) itemView; + + if (activity.typeface != null) { + textView.setTypeface(activity.typeface); + } + itemView.setOnClickListener(view -> { onItemClickListener.onItemClick(postFilterList.get(getBindingAdapterPosition() - 1)); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterUsageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterUsageRecyclerViewAdapter.java index e8c92df3..fe0c3002 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterUsageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostFilterUsageRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -12,20 +11,21 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.List; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage; public class PostFilterUsageRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<PostFilterUsage> postFilterUsages; private OnItemClickListener onItemClickListener; - private Context context; + private BaseActivity activity; public interface OnItemClickListener { void onClick(PostFilterUsage postFilterUsage); } - public PostFilterUsageRecyclerViewAdapter(Context context, + public PostFilterUsageRecyclerViewAdapter(BaseActivity activity, OnItemClickListener onItemClickListener) { - this.context = context; + this.activity = activity; this.onItemClickListener = onItemClickListener; } @@ -46,21 +46,21 @@ public class PostFilterUsageRecyclerViewAdapter extends RecyclerView.Adapter<Rec if (postFilterUsage.nameOfUsage.equals(PostFilterUsage.NO_USAGE)) { ((PostFilterUsageViewHolder) holder).usageTextView.setText(R.string.post_filter_usage_subreddit_all); } else { - ((PostFilterUsageViewHolder) holder).usageTextView.setText(context.getString(R.string.post_filter_usage_subreddit, postFilterUsage.nameOfUsage)); + ((PostFilterUsageViewHolder) holder).usageTextView.setText(activity.getString(R.string.post_filter_usage_subreddit, postFilterUsage.nameOfUsage)); } break; case PostFilterUsage.USER_TYPE: if (postFilterUsage.nameOfUsage.equals(PostFilterUsage.NO_USAGE)) { ((PostFilterUsageViewHolder) holder).usageTextView.setText(R.string.post_filter_usage_user_all); } else { - ((PostFilterUsageViewHolder) holder).usageTextView.setText(context.getString(R.string.post_filter_usage_user, postFilterUsage.nameOfUsage)); + ((PostFilterUsageViewHolder) holder).usageTextView.setText(activity.getString(R.string.post_filter_usage_user, postFilterUsage.nameOfUsage)); } break; case PostFilterUsage.MULTIREDDIT_TYPE: if (postFilterUsage.nameOfUsage.equals(PostFilterUsage.NO_USAGE)) { ((PostFilterUsageViewHolder) holder).usageTextView.setText(R.string.post_filter_usage_multireddit_all); } else { - ((PostFilterUsageViewHolder) holder).usageTextView.setText(context.getString(R.string.post_filter_usage_multireddit, postFilterUsage.nameOfUsage)); + ((PostFilterUsageViewHolder) holder).usageTextView.setText(activity.getString(R.string.post_filter_usage_multireddit, postFilterUsage.nameOfUsage)); } break; case PostFilterUsage.SEARCH_TYPE: @@ -85,6 +85,10 @@ public class PostFilterUsageRecyclerViewAdapter extends RecyclerView.Adapter<Rec super(itemView); usageTextView = (TextView) itemView; + if (activity.typeface != null) { + usageTextView.setTypeface(activity.typeface); + } + usageTextView.setOnClickListener(view -> { onItemClickListener.onClick(postFilterUsages.get(getBindingAdapterPosition())); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index e326c11d..cec20a29 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -24,7 +24,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.Barrier; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; @@ -126,7 +125,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } }; - private AppCompatActivity mActivity; + private BaseActivity mActivity; private PostFragment mFragment; private SharedPreferences mSharedPreferences; private Executor mExecutor; @@ -212,7 +211,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie private Callback mCallback; private boolean canPlayVideo = true; - public PostRecyclerViewAdapter(AppCompatActivity activity, PostFragment fragment, Executor executor, Retrofit oauthRetrofit, + public PostRecyclerViewAdapter(BaseActivity activity, PostFragment fragment, Executor executor, Retrofit oauthRetrofit, Retrofit gfycatRetrofit, Retrofit redgifsRetrofit, Retrofit streambleRetrofit, CustomThemeWrapper customThemeWrapper, Locale locale, String accessToken, String accountName, int postType, int postLayout, boolean displaySubredditName, @@ -2105,23 +2104,20 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); } - if (((BaseActivity) mActivity).typeface != null) { - subredditTextView.setTypeface(((BaseActivity) mActivity).typeface); - userTextView.setTypeface(((BaseActivity) mActivity).typeface); - postTimeTextView.setTypeface(((BaseActivity) mActivity).typeface); - typeTextView.setTypeface(((BaseActivity) mActivity).typeface); - spoilerTextView.setTypeface(((BaseActivity) mActivity).typeface); - nsfwTextView.setTypeface(((BaseActivity) mActivity).typeface); - flairTextView.setTypeface(((BaseActivity) mActivity).typeface); - awardsTextView.setTypeface(((BaseActivity) mActivity).typeface); - scoreTextView.setTypeface(((BaseActivity) mActivity).typeface); - commentsCountTextView.setTypeface(((BaseActivity) mActivity).typeface); + if (mActivity.typeface != null) { + subredditTextView.setTypeface(mActivity.typeface); + userTextView.setTypeface(mActivity.typeface); + postTimeTextView.setTypeface(mActivity.typeface); + typeTextView.setTypeface(mActivity.typeface); + spoilerTextView.setTypeface(mActivity.typeface); + nsfwTextView.setTypeface(mActivity.typeface); + flairTextView.setTypeface(mActivity.typeface); + awardsTextView.setTypeface(mActivity.typeface); + scoreTextView.setTypeface(mActivity.typeface); + commentsCountTextView.setTypeface(mActivity.typeface); } - if (((BaseActivity) mActivity).titleTypeface != null) { - titleTextView.setTypeface(((BaseActivity) mActivity).titleTypeface); - } - if (((BaseActivity) mActivity).contentTypeface != null) { - + if (mActivity.titleTypeface != null) { + titleTextView.setTypeface(mActivity.titleTypeface); } subredditTextView.setTextColor(mSubredditColor); @@ -2933,6 +2929,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie saveButton, shareButton); + if (mActivity.typeface != null) { + linkTextView.setTypeface(mActivity.typeface); + errorTextView.setTypeface(mActivity.typeface); + } linkTextView.setTextColor(mSecondaryTextColor); noPreviewLinkImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); noPreviewLinkImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); @@ -3053,6 +3053,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie saveButton, shareButton); + if (mActivity.contentTypeface != null) { + contentTextView.setTypeface(mActivity.titleTypeface); + } contentTextView.setTextColor(mPostContentColor); } } @@ -3169,6 +3172,22 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((ViewGroup) itemView).getLayoutTransition().setAnimateParentHierarchy(false); } + if (mActivity.typeface != null) { + nameTextView.setTypeface(mActivity.typeface); + postTimeTextView.setTypeface(mActivity.typeface); + typeTextView.setTypeface(mActivity.typeface); + spoilerTextView.setTypeface(mActivity.typeface); + nsfwTextView.setTypeface(mActivity.typeface); + flairTextView.setTypeface(mActivity.typeface); + awardsTextView.setTypeface(mActivity.typeface); + linkTextView.setTypeface(mActivity.typeface); + scoreTextView.setTypeface(mActivity.typeface); + commentsCountTextView.setTypeface(mActivity.typeface); + } + if (mActivity.titleTypeface != null) { + titleTextView.setTypeface(mActivity.titleTypeface); + } + itemView.setBackgroundColor(mCardViewBackgroundColor); postTimeTextView.setTextColor(mSecondaryTextColor); titleTextView.setTextColor(mPostTitleColor); @@ -3790,6 +3809,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + errorTextView.setTypeface(mActivity.typeface); + } + if (mActivity.titleTypeface != null) { + titleTextView.setTypeface(mActivity.titleTypeface); + } itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); titleTextView.setTextColor(mPostTitleColor); progressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent)); @@ -4221,6 +4246,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie shareButton, true); + if (mActivity.typeface != null) { + linkTextView.setTypeface(mActivity.typeface); + errorTextView.setTypeface(mActivity.typeface); + } linkTextView.setTextColor(mSecondaryTextColor); noPreviewImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor); noPreviewImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN); @@ -4345,6 +4374,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie shareButton, true); + if (mActivity.contentTypeface != null) { + contentTextView.setTypeface(mActivity.contentTypeface); + } contentTextView.setTextColor(mPostContentColor); divider.setBackgroundColor(mDividerColor); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java index 065bab4f..eaf50978 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; import android.net.Uri; +import android.text.Spanned; import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; @@ -40,9 +41,9 @@ import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewPrivateMessagesActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.message.Message; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { @@ -89,6 +90,13 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt } @Override + public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { + if (mViewPrivateMessagesActivity.contentTypeface != null) { + textView.setTypeface(mViewPrivateMessagesActivity.contentTypeface); + } + } + + @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { builder.linkResolver((view, link) -> { Intent intent = new Intent(viewPrivateMessagesActivity, LinkResolverActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RPANCommentStreamRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RPANCommentStreamRecyclerViewAdapter.java index ba7dcd34..d3c029af 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RPANCommentStreamRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RPANCommentStreamRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -19,13 +18,16 @@ import java.util.ArrayList; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RPANComment; +import ml.docilealligator.infinityforreddit.activities.RPANActivity; public class RPANCommentStreamRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + private RPANActivity activity; private RequestManager glide; private ArrayList<RPANComment> rpanComments; - public RPANCommentStreamRecyclerViewAdapter(Context context) { - glide = Glide.with(context); + public RPANCommentStreamRecyclerViewAdapter(RPANActivity activity) { + this.activity = activity; + glide = Glide.with(activity); rpanComments = new ArrayList<>(); } @@ -70,7 +72,6 @@ public class RPANCommentStreamRecyclerViewAdapter extends RecyclerView.Adapter<R class RPANCommentViewHolder extends RecyclerView.ViewHolder { ImageView iconImageView; TextView authorTextView; - TextView timeTextView; TextView contentTextView; public RPANCommentViewHolder(@NonNull View itemView) { @@ -78,6 +79,11 @@ public class RPANCommentStreamRecyclerViewAdapter extends RecyclerView.Adapter<R iconImageView = itemView.findViewById(R.id.icon_image_view_item_rpan_comment); authorTextView = itemView.findViewById(R.id.author_text_view_item_rpan_comment); contentTextView = itemView.findViewById(R.id.content_text_view_item_rpan_comment); + + if (activity.typeface != null) { + authorTextView.setTypeface(activity.typeface); + contentTextView.setTypeface(activity.typeface); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/ReportReasonRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/ReportReasonRecyclerViewAdapter.java index 80e57a5a..e9e62a56 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/ReportReasonRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/ReportReasonRecyclerViewAdapter.java @@ -14,18 +14,21 @@ import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.ReportReason; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; public class ReportReasonRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + private BaseActivity activity; private ArrayList<ReportReason> generalReasons; private ArrayList<ReportReason> rules; private int primaryTextColor; private int colorAccent; - public ReportReasonRecyclerViewAdapter(CustomThemeWrapper customThemeWrapper, ArrayList<ReportReason> generalReasons) { + public ReportReasonRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, ArrayList<ReportReason> generalReasons) { + this.activity = activity; this.generalReasons = generalReasons; primaryTextColor = customThemeWrapper.getPrimaryTextColor(); colorAccent = customThemeWrapper.getColorAccent(); @@ -101,6 +104,10 @@ public class ReportReasonRecyclerViewAdapter extends RecyclerView.Adapter<Recycl reasonTextView.setTextColor(primaryTextColor); checkBox.setButtonTintList(ColorStateList.valueOf(colorAccent)); + if (activity.typeface != null) { + reasonTextView.setTypeface(activity.typeface); + } + checkBox.setOnClickListener(view -> { for (int i = 0; i < generalReasons.size(); i++) { if (generalReasons.get(i).isSelected()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java index 49826453..abbfc00c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.adapters; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.text.Spanned; import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; @@ -10,7 +11,6 @@ import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; @@ -33,6 +33,7 @@ import io.noties.markwon.movement.MovementMethodPlugin; import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Rule; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; @@ -40,12 +41,14 @@ import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecyclerViewAdapter.RuleViewHolder> { + private BaseActivity activity; private Markwon markwon; private ArrayList<Rule> rules; private int mPrimaryTextColor; private int mSecondaryTextColor; - public RulesRecyclerViewAdapter(AppCompatActivity activity, CustomThemeWrapper customThemeWrapper) { + public RulesRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper) { + this.activity = activity; markwon = Markwon.builder(activity) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(AutolinkInlineProcessor.class); @@ -64,6 +67,15 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler } @Override + public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { + if (activity.typeface != null) { + textView.setTypeface(activity.typeface); + } + + textView.setTextColor(mPrimaryTextColor); + } + + @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { builder.linkResolver((view, link) -> { Intent intent = new Intent(activity, LinkResolverActivity.class); @@ -138,6 +150,11 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler ButterKnife.bind(this, itemView); shortNameTextView.setTextColor(mPrimaryTextColor); descriptionMarkwonView.setTextColor(mSecondaryTextColor); + + if (activity.typeface != null) { + shortNameTextView.setTypeface(activity.typeface); + descriptionMarkwonView.setTypeface(activity.typeface); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java index 35cf33e7..51a8fb63 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.app.Activity; import android.graphics.drawable.Drawable; import android.view.LayoutInflater; import android.view.View; @@ -15,12 +14,14 @@ import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.recentsearchquery.RecentSearchQuery; import ml.docilealligator.infinityforreddit.utils.Utils; public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + private BaseActivity activity; private List<RecentSearchQuery> recentSearchQueries; private int primaryTextColor; private Drawable historyIcon; @@ -32,8 +33,9 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy void onDelete(RecentSearchQuery recentSearchQuery); } - public SearchActivityRecyclerViewAdapter(Activity activity, CustomThemeWrapper customThemeWrapper, + public SearchActivityRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, ItemOnClickListener itemOnClickListener) { + this.activity = activity; this.primaryTextColor = customThemeWrapper.getPrimaryTextColor(); this.historyIcon = Utils.getTintedDrawable(activity, R.drawable.ic_history_24dp, customThemeWrapper.getPrimaryIconColor()); this.deleteIcon = Utils.getTintedDrawable(activity, R.drawable.ic_delete_24dp, customThemeWrapper.getPrimaryIconColor()); @@ -80,6 +82,10 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy recentSearchQueryTextView.setCompoundDrawablesWithIntrinsicBounds(historyIcon, null, null, null); deleteImageView.setImageDrawable(deleteIcon); + if (activity.typeface != null) { + recentSearchQueryTextView.setTypeface(activity.typeface); + } + itemView.setOnClickListener(view -> { if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) { itemOnClickListener.onClick(recentSearchQueries.get(getBindingAdapterPosition()).getSearchQuery()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SelectedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SelectedSubredditsRecyclerViewAdapter.java index ad57d3ba..89833ae8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SelectedSubredditsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SelectedSubredditsRecyclerViewAdapter.java @@ -13,14 +13,17 @@ import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; public class SelectedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + private BaseActivity activity; private CustomThemeWrapper customThemeWrapper; private ArrayList<String> subreddits; - public SelectedSubredditsRecyclerViewAdapter(CustomThemeWrapper customThemeWrapper, ArrayList<String> subreddits) { + public SelectedSubredditsRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, ArrayList<String> subreddits) { + this.activity = activity; this.customThemeWrapper = customThemeWrapper; if (subreddits == null) { this.subreddits = new ArrayList<>(); @@ -79,6 +82,10 @@ public class SelectedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter< subredditNameTextView.setTextColor(customThemeWrapper.getPrimaryIconColor()); deleteButton.setColorFilter(customThemeWrapper.getPrimaryIconColor(), android.graphics.PorterDuff.Mode.SRC_IN); + + if (activity.typeface != null) { + subredditNameTextView.setTypeface(activity.typeface); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditAutocompleteRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditAutocompleteRecyclerViewAdapter.java index c657f422..ac46be2b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditAutocompleteRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditAutocompleteRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -19,19 +18,22 @@ import java.util.List; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import pl.droidsonroids.gif.GifImageView; public class SubredditAutocompleteRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + private BaseActivity activity; private List<SubredditData> subreddits; private RequestManager glide; private CustomThemeWrapper customThemeWrapper; private ItemOnClickListener itemOnClickListener; - public SubredditAutocompleteRecyclerViewAdapter(Context context, CustomThemeWrapper customThemeWrapper, + public SubredditAutocompleteRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, ItemOnClickListener itemOnClickListener) { - glide = Glide.with(context); + this.activity = activity; + glide = Glide.with(activity); this.customThemeWrapper = customThemeWrapper; this.itemOnClickListener = itemOnClickListener; } @@ -91,6 +93,10 @@ public class SubredditAutocompleteRecyclerViewAdapter extends RecyclerView.Adapt subredditNameTextView.setTextColor(customThemeWrapper.getPrimaryTextColor()); + if (activity.typeface != null) { + subredditNameTextView.setTypeface(activity.typeface); + } + itemView.setOnClickListener(view -> { itemOnClickListener.onClick(subreddits.get(getBindingAdapterPosition())); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java index 18268b54..e3bbda50 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditListingRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.content.Context; import android.content.res.ColorStateList; import android.os.Handler; import android.view.LayoutInflater; @@ -32,6 +31,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubreddit; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.subreddit.SubredditData; @@ -55,7 +55,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred } }; private RequestManager glide; - private Context context; + private BaseActivity activity; private Executor executor; private Retrofit oauthRetrofit; private Retrofit retrofit; @@ -73,13 +73,13 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred private NetworkState networkState; private Callback callback; - public SubredditListingRecyclerViewAdapter(Context context, Executor executor, Retrofit oauthRetrofit, Retrofit retrofit, + public SubredditListingRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit, Retrofit retrofit, CustomThemeWrapper customThemeWrapper, String accessToken, String accountName, RedditDataRoomDatabase redditDataRoomDatabase, boolean isMultiSelection, Callback callback) { super(DIFF_CALLBACK); - this.context = context; + this.activity = activity; this.executor = executor; this.oauthRetrofit = oauthRetrofit; this.retrofit = retrofit; @@ -88,7 +88,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred this.redditDataRoomDatabase = redditDataRoomDatabase; this.isMultiSelection = isMultiSelection; this.callback = callback; - glide = Glide.with(context); + glide = Glide.with(this.activity); colorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); primaryTextColor = customThemeWrapper.getPrimaryTextColor(); secondaryTextColor = customThemeWrapper.getSecondaryTextColor(); @@ -163,12 +163,12 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred @Override public void onSubredditSubscriptionSuccess() { ((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE); - Toast.makeText(context, R.string.subscribed, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.subscribed, Toast.LENGTH_SHORT).show(); } @Override public void onSubredditSubscriptionFail() { - Toast.makeText(context, R.string.subscribe_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.subscribe_failed, Toast.LENGTH_SHORT).show(); } }); } else { @@ -178,12 +178,12 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred @Override public void onSubredditSubscriptionSuccess() { ((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE); - Toast.makeText(context, R.string.subscribed, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.subscribed, Toast.LENGTH_SHORT).show(); } @Override public void onSubredditSubscriptionFail() { - Toast.makeText(context, R.string.subscribe_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.subscribe_failed, Toast.LENGTH_SHORT).show(); } }); } @@ -273,6 +273,10 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred if (isMultiSelection) { checkBox.setVisibility(View.VISIBLE); } + + if (activity.typeface != null) { + subredditNameTextView.setTypeface(activity.typeface); + } } } @@ -290,6 +294,11 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred errorTextView.setTextColor(secondaryTextColor); retryButton.setBackgroundTintList(ColorStateList.valueOf(colorPrimaryLightTheme)); retryButton.setTextColor(buttonTextColor); + + if (activity.typeface != null) { + retryButton.setTypeface(activity.typeface); + errorTextView.setTypeface(activity.typeface); + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditMultiselectionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditMultiselectionRecyclerViewAdapter.java index cb3a3c40..8ed3739f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditMultiselectionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubredditMultiselectionRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.content.Context; import android.content.res.ColorStateList; import android.view.LayoutInflater; import android.view.View; @@ -21,21 +20,24 @@ import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.subreddit.SubredditWithSelection; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; import pl.droidsonroids.gif.GifImageView; public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + private BaseActivity activity; private ArrayList<SubredditWithSelection> subscribedSubreddits; private RequestManager glide; private int primaryTextColor; private int colorAccent; - public SubredditMultiselectionRecyclerViewAdapter(Context context, CustomThemeWrapper customThemeWrapper) { - glide = Glide.with(context); + public SubredditMultiselectionRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper) { + this.activity = activity; + glide = Glide.with(activity); primaryTextColor = customThemeWrapper.getPrimaryTextColor(); colorAccent = customThemeWrapper.getColorAccent(); } @@ -118,6 +120,10 @@ public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Ada ButterKnife.bind(this, itemView); nameTextView.setTextColor(primaryTextColor); checkBox.setButtonTintList(ColorStateList.valueOf(colorAccent)); + + if (activity.typeface != null) { + nameTextView.setTypeface(activity.typeface); + } } } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java index 9be81b60..ef8e1d36 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.content.Context; import android.content.Intent; import android.os.Handler; import android.view.LayoutInflater; @@ -27,6 +26,7 @@ import me.zhanghai.android.fastscroll.PopupTextProvider; import ml.docilealligator.infinityforreddit.FavoriteThing; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; @@ -39,7 +39,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte private static final int VIEW_TYPE_SUBREDDIT_DIVIDER = 2; private static final int VIEW_TYPE_SUBREDDIT = 3; - private Context mContext; + private BaseActivity mActivity; private Executor mExecutor; private Retrofit mOauthRetrofit; private RedditDataRoomDatabase mRedditDataRoomDatabase; @@ -56,13 +56,13 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte private int primaryTextColor; private int secondaryTextColor; - public SubscribedSubredditsRecyclerViewAdapter(Context context, Executor executor, Retrofit oauthRetrofit, + public SubscribedSubredditsRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, CustomThemeWrapper customThemeWrapper, String accessToken) { - mContext = context; + mActivity = activity; mExecutor = executor; - glide = Glide.with(context); + glide = Glide.with(activity); mOauthRetrofit = oauthRetrofit; mRedditDataRoomDatabase = redditDataRoomDatabase; this.accessToken = accessToken; @@ -70,12 +70,12 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte secondaryTextColor = customThemeWrapper.getSecondaryTextColor(); } - public SubscribedSubredditsRecyclerViewAdapter(Context context, Executor executor, Retrofit oauthRetrofit, + public SubscribedSubredditsRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, CustomThemeWrapper customThemeWrapper, String accessToken, boolean hasClearSelectionRow, ItemClickListener itemClickListener) { - this(context, executor, oauthRetrofit, redditDataRoomDatabase, customThemeWrapper, accessToken); + this(activity, executor, oauthRetrofit, redditDataRoomDatabase, customThemeWrapper, accessToken); this.hasClearSelectionRow = hasClearSelectionRow; this.itemClickListener = itemClickListener; } @@ -208,7 +208,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte @Override public void failed() { - Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); int position = viewHolder.getBindingAdapterPosition() - offset; if(position >= 0 && mSubscribedSubredditData.size() > position) { mSubscribedSubredditData.get(position).setFavorite(true); @@ -234,7 +234,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte @Override public void failed() { - Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); int position = viewHolder.getBindingAdapterPosition() - offset; if(position >= 0 && mSubscribedSubredditData.size() > position) { mSubscribedSubredditData.get(position).setFavorite(false); @@ -252,9 +252,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte if (itemClickListener == null) { viewHolder.itemView.setOnClickListener(view -> { - Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class); + Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class); intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, name); - mContext.startActivity(intent); + mActivity.startActivity(intent); }); } @@ -307,7 +307,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte @Override public void failed() { - Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show(); int position = viewHolder.getBindingAdapterPosition() - 1; if(position >= 0 && mFavoriteSubscribedSubredditData.size() > position) { mFavoriteSubscribedSubredditData.get(position).setFavorite(true); @@ -332,7 +332,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte @Override public void failed() { - Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show(); int position = viewHolder.getBindingAdapterPosition() - 1; if(position >= 0 && mFavoriteSubscribedSubredditData.size() > position) { mFavoriteSubscribedSubredditData.get(position).setFavorite(false); @@ -347,9 +347,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, false)); } else { viewHolder.itemView.setOnClickListener(view -> { - Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class); + Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class); intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, name); - mContext.startActivity(intent); + mActivity.startActivity(intent); }); } @@ -483,6 +483,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte SubredditViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + subredditNameTextView.setTypeface(mActivity.typeface); + } subredditNameTextView.setTextColor(primaryTextColor); } } @@ -498,6 +501,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte FavoriteSubredditViewHolder(View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + subredditNameTextView.setTypeface(mActivity.typeface); + } subredditNameTextView.setTextColor(primaryTextColor); } } @@ -508,6 +514,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte FavoriteSubredditsDividerViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + dividerTextView.setTypeface(mActivity.typeface); + } dividerTextView.setText(R.string.favorites); dividerTextView.setTextColor(secondaryTextColor); } @@ -519,6 +528,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte AllSubredditsDividerViewHolder(@NonNull View itemView) { super(itemView); ButterKnife.bind(this, itemView); + if (mActivity.typeface != null) { + dividerTextView.setTypeface(mActivity.typeface); + } dividerTextView.setText(R.string.all); dividerTextView.setTextColor(secondaryTextColor); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TranslationFragmentRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TranslationFragmentRecyclerViewAdapter.java index 5b17c06b..77232d74 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TranslationFragmentRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TranslationFragmentRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.view.LayoutInflater; @@ -16,18 +15,19 @@ import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.settings.Translation; public class TranslationFragmentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { - private Activity activity; + private BaseActivity activity; private int primaryTextColor; private int secondaryTextColor; private ArrayList<Translation> translationContributors; - public TranslationFragmentRecyclerViewAdapter(Activity activity, CustomThemeWrapper customThemeWrapper) { + public TranslationFragmentRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper) { this.activity = activity; primaryTextColor = customThemeWrapper.getPrimaryTextColor(); secondaryTextColor = customThemeWrapper.getSecondaryTextColor(); @@ -73,6 +73,11 @@ public class TranslationFragmentRecyclerViewAdapter extends RecyclerView.Adapter ButterKnife.bind(this, itemView); + if (activity.typeface != null) { + languageNameTextView.setTypeface(activity.typeface); + contributorNamesTextView.setTypeface(activity.typeface); + } + languageNameTextView.setTextColor(primaryTextColor); contributorNamesTextView.setTextColor(secondaryTextColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java index 8ab40aff..4e2ad94f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.content.Context; import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.view.LayoutInflater; @@ -29,11 +28,13 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.TrendingSearch; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; import ml.docilealligator.infinityforreddit.post.Post; public class TrendingSearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + private BaseActivity activity; private ArrayList<TrendingSearch> trendingSearches; private CustomThemeWrapper customThemeWrapper; private RequestManager glide; @@ -43,15 +44,16 @@ public class TrendingSearchRecyclerViewAdapter extends RecyclerView.Adapter<Recy private float mScale; private ItemClickListener itemClickListener; - public TrendingSearchRecyclerViewAdapter(Context context, CustomThemeWrapper customThemeWrapper, + public TrendingSearchRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, int imageViewWidth, boolean dataSavingMode, boolean disableImagePreview, ItemClickListener itemClickListener) { + this.activity = activity; this.customThemeWrapper = customThemeWrapper; - this.glide = Glide.with(context); + this.glide = Glide.with(activity); this.imageViewWidth = imageViewWidth; this.dataSavingMode = dataSavingMode; this.disableImagePreview = disableImagePreview; - mScale = context.getResources().getDisplayMetrics().density; + mScale = activity.getResources().getDisplayMetrics().density; this.itemClickListener = itemClickListener; } @@ -216,6 +218,11 @@ public class TrendingSearchRecyclerViewAdapter extends RecyclerView.Adapter<Recy progressBar.setIndeterminateTintList(ColorStateList.valueOf(customThemeWrapper.getColorAccent())); errorTextView.setTextColor(customThemeWrapper.getPrimaryTextColor()); + if (activity.typeface != null) { + titleTextView.setTypeface(activity.typeface); + errorTextView.setTypeface(activity.typeface); + } + itemView.setOnClickListener(view -> { itemClickListener.onClick(trendingSearches.get(getBindingAdapterPosition())); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UploadedImagesRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UploadedImagesRecyclerViewAdapter.java index eebd6482..b3c0ec63 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UploadedImagesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UploadedImagesRecyclerViewAdapter.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.adapters; +import android.app.Activity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -12,12 +13,17 @@ import java.util.ArrayList; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; public class UploadedImagesRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + private BaseActivity activity; private ArrayList<UploadedImage> uploadedImages; private ItemClickListener itemClickListener; - public UploadedImagesRecyclerViewAdapter(ArrayList<UploadedImage> uploadedImages, ItemClickListener itemClickListener) { + public UploadedImagesRecyclerViewAdapter(Activity activity, ArrayList<UploadedImage> uploadedImages, ItemClickListener itemClickListener) { + if (activity instanceof BaseActivity) { + this.activity = (BaseActivity) activity; + } this.uploadedImages = uploadedImages; this.itemClickListener = itemClickListener; } @@ -49,6 +55,11 @@ public class UploadedImagesRecyclerViewAdapter extends RecyclerView.Adapter<Recy imageNameTextView = itemView.findViewById(R.id.image_name_item_uploaded_image); imageUrlTextView = itemView.findViewById(R.id.image_url_item_uploaded_image); + if (activity != null && activity.typeface != null) { + imageNameTextView.setTypeface(activity.typeface); + imageUrlTextView.setTypeface(activity.typeface); + } + itemView.setOnClickListener(view -> { itemClickListener.onClick(uploadedImages.get(getBindingAdapterPosition())); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java index d260bb0d..5eec9c24 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java @@ -13,18 +13,21 @@ import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.UserFlair; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.utils.Utils; public class UserFlairRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { + private BaseActivity activity; private CustomThemeWrapper customThemeWrapper; private ArrayList<UserFlair> userFlairs; private ItemClickListener itemClickListener; - public UserFlairRecyclerViewAdapter(CustomThemeWrapper customThemeWrapper, ArrayList<UserFlair> userFlairs, + public UserFlairRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, ArrayList<UserFlair> userFlairs, ItemClickListener itemClickListener) { + this.activity = activity; this.customThemeWrapper = customThemeWrapper; this.userFlairs = userFlairs; this.itemClickListener = itemClickListener; @@ -76,6 +79,10 @@ public class UserFlairRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerV userFlairHtmlTextView.setTextColor(customThemeWrapper.getPrimaryTextColor()); editUserFlairImageView.setColorFilter(customThemeWrapper.getPrimaryTextColor(), android.graphics.PorterDuff.Mode.SRC_IN); + if (activity.typeface != null) { + userFlairHtmlTextView.setTypeface(activity.typeface); + } + itemView.setOnClickListener(view -> { itemClickListener.onClick(userFlairs.get(getBindingAdapterPosition()), false); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserListingRecyclerViewAdapter.java index 5beedeef..1ca779ac 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserListingRecyclerViewAdapter.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.content.Context; import android.content.res.ColorStateList; import android.os.Handler; import android.view.LayoutInflater; @@ -32,6 +31,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.asynctasks.CheckIsFollowingUser; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.user.UserData; @@ -55,7 +55,7 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R } }; private RequestManager glide; - private Context context; + private BaseActivity activity; private Executor executor; private Retrofit oauthRetrofit; private Retrofit retrofit; @@ -73,12 +73,12 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R private NetworkState networkState; private final Callback callback; - public UserListingRecyclerViewAdapter(Context context, Executor executor, Retrofit oauthRetrofit, Retrofit retrofit, + public UserListingRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit, Retrofit retrofit, CustomThemeWrapper customThemeWrapper, String accessToken, String accountName, RedditDataRoomDatabase redditDataRoomDatabase, boolean isMultiSelection, Callback callback) { super(DIFF_CALLBACK); - this.context = context; + this.activity = activity; this.executor = executor; this.oauthRetrofit = oauthRetrofit; this.retrofit = retrofit; @@ -87,7 +87,7 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R this.redditDataRoomDatabase = redditDataRoomDatabase; this.isMultiSelection = isMultiSelection; this.callback = callback; - glide = Glide.with(context); + glide = Glide.with(activity); primaryTextColor = customThemeWrapper.getPrimaryTextColor(); buttonTextColor = customThemeWrapper.getButtonTextColor(); colorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); @@ -155,12 +155,12 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R @Override public void onUserFollowingSuccess() { ((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE); - Toast.makeText(context, R.string.followed, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.followed, Toast.LENGTH_SHORT).show(); } @Override public void onUserFollowingFail() { - Toast.makeText(context, R.string.follow_failed, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, R.string.follow_failed, Toast.LENGTH_SHORT).show(); } }); }); @@ -246,6 +246,11 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R ButterKnife.bind(this, itemView); userNameTextView.setTextColor(primaryTextColor); subscribeButton.setColorFilter(unsubscribedColor, android.graphics.PorterDuff.Mode.SRC_IN); + + if (activity.typeface != null) { + userNameTextView.setTypeface(activity.typeface); + } + if (isMultiSelection) { checkBox.setVisibility(View.VISIBLE); } @@ -266,6 +271,11 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R errorTextView.setTextColor(primaryTextColor); retryButton.setTextColor(buttonTextColor); retryButton.setBackgroundTintList(ColorStateList.valueOf(colorPrimaryLightTheme)); + + if (activity.typeface != null) { + retryButton.setTypeface(activity.typeface); + errorTextView.setTypeface(activity.typeface); + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java index 378a227b..c9a47d40 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java @@ -14,13 +14,13 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.EditCommentActivity; import ml.docilealligator.infinityforreddit.activities.FullMarkdownActivity; @@ -30,6 +30,7 @@ import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.comment.Comment; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; /** @@ -64,7 +65,7 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott TextView reportTextView; @BindView(R.id.see_removed_view_comment_more_bottom_sheet_fragment) TextView seeRemovedTextView; - private AppCompatActivity activity; + private BaseActivity activity; public CommentMoreBottomSheetFragment() { // Required empty public constructor @@ -224,12 +225,16 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott }); } + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (AppCompatActivity) context; + activity = (BaseActivity) context; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java index e30156dc..08ef7769 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java @@ -1,12 +1,10 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.os.Bundle; -import android.text.Html; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -21,7 +19,9 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; /** * A simple {@link Fragment} subclass. @@ -39,7 +39,7 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS @BindView(R.id.copy_all_markdown_text_view_copy_text_bottom_sheet_fragment) TextView copyAllMarkdownTextView; - private Activity activity; + private BaseActivity activity; private String markdownText; public CopyTextBottomSheetFragment() { @@ -88,6 +88,10 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS copyAllMarkdownTextView.setVisibility(View.GONE); } + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } @@ -118,6 +122,6 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (Activity) context; + activity = (BaseActivity) context; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CreateThemeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CreateThemeBottomSheetFragment.java index ffa13115..a025db0b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CreateThemeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CreateThemeBottomSheetFragment.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; @@ -15,8 +14,10 @@ import androidx.fragment.app.Fragment; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CustomizeThemeActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; /** * A simple {@link Fragment} subclass. @@ -31,7 +32,7 @@ public class CreateThemeBottomSheetFragment extends LandscapeExpandedRoundedBott TextView darkThemeTextView; @BindView(R.id.amoled_theme_text_view_create_theme_bottom_sheet_fragment) TextView amoledThemeTextView; - private Activity activity; + private BaseActivity activity; public interface SelectBaseThemeBottomSheetFragmentListener { void importTheme(); @@ -78,12 +79,16 @@ public class CreateThemeBottomSheetFragment extends LandscapeExpandedRoundedBott startActivity(intent); dismiss(); }); + + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } return rootView; } @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (Activity) context; + activity = (BaseActivity) context; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CustomThemeOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CustomThemeOptionsBottomSheetFragment.java index e06fbb12..28d2d388 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CustomThemeOptionsBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CustomThemeOptionsBottomSheetFragment.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; @@ -10,14 +9,15 @@ import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CustomizeThemeActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; /** * A simple {@link Fragment} subclass. @@ -36,7 +36,7 @@ public class CustomThemeOptionsBottomSheetFragment extends LandscapeExpandedRoun @BindView(R.id.delete_theme_text_view_custom_theme_options_bottom_sheet_fragment) TextView deleteTextView; private String themeName; - private Activity activity; + private BaseActivity activity; public CustomThemeOptionsBottomSheetFragment() { // Required empty public constructor @@ -79,12 +79,16 @@ public class CustomThemeOptionsBottomSheetFragment extends LandscapeExpandedRoun dismiss(); }); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (AppCompatActivity) context; + activity = (BaseActivity) context; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FABMoreOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FABMoreOptionsBottomSheetFragment.java index 720b8ce0..39d2b937 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FABMoreOptionsBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FABMoreOptionsBottomSheetFragment.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; +import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; @@ -12,7 +13,9 @@ import androidx.annotation.NonNull; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; public class FABMoreOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { @@ -117,6 +120,13 @@ public class FABMoreOptionsBottomSheetFragment extends LandscapeExpandedRoundedB dismiss(); }); + Activity baseActivity = getActivity(); + if (baseActivity instanceof BaseActivity) { + if (((BaseActivity) baseActivity).typeface != null) { + Utils.setFontToAllTextViews(rootView, ((BaseActivity) baseActivity).typeface); + } + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FilteredThingFABMoreOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FilteredThingFABMoreOptionsBottomSheetFragment.java index e2298a5b..b88249cc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FilteredThingFABMoreOptionsBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FilteredThingFABMoreOptionsBottomSheetFragment.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; +import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; @@ -12,7 +13,9 @@ import androidx.annotation.NonNull; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; public class FilteredThingFABMoreOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { @@ -47,6 +50,13 @@ public class FilteredThingFABMoreOptionsBottomSheetFragment extends LandscapeExp dismiss(); }); + Activity baseActivity = getActivity(); + if (baseActivity instanceof BaseActivity) { + if (((BaseActivity) baseActivity).typeface != null) { + Utils.setFontToAllTextViews(rootView, ((BaseActivity) baseActivity).typeface); + } + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java index 82373398..ed2a6485 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; @@ -30,9 +29,11 @@ import ml.docilealligator.infinityforreddit.FetchFlairs; import ml.docilealligator.infinityforreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.adapters.FlairBottomSheetRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.FlairSelectedEvent; +import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; @@ -60,7 +61,7 @@ public class FlairBottomSheetFragment extends BottomSheetDialogFragment { CustomThemeWrapper mCustomThemeWrapper; private String mAccessToken; private String mSubredditName; - private Activity mActivity; + private BaseActivity mActivity; private FlairBottomSheetRecyclerViewAdapter mAdapter; public FlairBottomSheetFragment() { @@ -76,6 +77,10 @@ public class FlairBottomSheetFragment extends BottomSheetDialogFragment { ((Infinity) mActivity.getApplication()).getAppComponent().inject(this); + if (mActivity.typeface != null) { + Utils.setFontToAllTextViews(rootView, mActivity.typeface); + } + long viewPostFragmentId = getArguments().getLong(EXTRA_VIEW_POST_DETAIL_FRAGMENT_ID, -1); mAdapter = new FlairBottomSheetRecyclerViewAdapter(mActivity, mCustomThemeWrapper, flair -> { if (viewPostFragmentId <= 0) { @@ -133,7 +138,7 @@ public class FlairBottomSheetFragment extends BottomSheetDialogFragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - mActivity = (Activity) context; + mActivity = (BaseActivity) context; } public interface FlairSelectionCallback { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/MultiRedditOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/MultiRedditOptionsBottomSheetFragment.java index 6e9caa87..37cca62a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/MultiRedditOptionsBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/MultiRedditOptionsBottomSheetFragment.java @@ -21,6 +21,7 @@ import ml.docilealligator.infinityforreddit.activities.EditMultiRedditActivity; import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; +import ml.docilealligator.infinityforreddit.utils.Utils; /** * A simple {@link Fragment} subclass. @@ -79,6 +80,10 @@ public class MultiRedditOptionsBottomSheetFragment extends LandscapeExpandedRoun dismiss(); }); + if (subscribedThingListingActivity.typeface != null) { + Utils.setFontToAllTextViews(rootView, subscribedThingListingActivity.typeface); + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/NewPostFilterUsageBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/NewPostFilterUsageBottomSheetFragment.java index 7bb4baf5..9157da44 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/NewPostFilterUsageBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/NewPostFilterUsageBottomSheetFragment.java @@ -15,6 +15,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.PostFilterUsageListingActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage; +import ml.docilealligator.infinityforreddit.utils.Utils; public class NewPostFilterUsageBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { @@ -67,6 +68,10 @@ public class NewPostFilterUsageBottomSheetFragment extends LandscapeExpandedRoun dismiss(); }); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PlaybackSpeedBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PlaybackSpeedBottomSheetFragment.java index 8957b56b..f5fc9279 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PlaybackSpeedBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PlaybackSpeedBottomSheetFragment.java @@ -14,10 +14,13 @@ import androidx.fragment.app.Fragment; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity; +import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity; import ml.docilealligator.infinityforreddit.activities.ViewVideoActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.fragments.ViewImgurVideoFragment; import ml.docilealligator.infinityforreddit.fragments.ViewRedditGalleryVideoFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; public class PlaybackSpeedBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { @@ -119,6 +122,20 @@ public class PlaybackSpeedBottomSheetFragment extends LandscapeExpandedRoundedBo setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_200); dismiss(); }); + + if (activity instanceof ViewVideoActivity) { + if (((ViewVideoActivity) activity).typeface != null) { + Utils.setFontToAllTextViews(rootView, ((ViewVideoActivity) activity).typeface); + } + } else if (activity instanceof ViewImgurMediaActivity) { + if (((ViewImgurMediaActivity) activity).typeface != null) { + Utils.setFontToAllTextViews(rootView, ((ViewImgurMediaActivity) activity).typeface); + } + } else if (activity instanceof ViewRedditGalleryActivity) { + if (((ViewRedditGalleryActivity) activity).typeface != null) { + Utils.setFontToAllTextViews(rootView, ((ViewRedditGalleryActivity) activity).typeface); + } + } return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostCommentSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostCommentSortTypeBottomSheetFragment.java index 47de159e..544b97ca 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostCommentSortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostCommentSortTypeBottomSheetFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.os.Build; @@ -19,7 +18,9 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; /** * A simple {@link Fragment} subclass. @@ -44,7 +45,7 @@ public class PostCommentSortTypeBottomSheetFragment extends LandscapeExpandedRou TextView qaTypeTextView; @BindView(R.id.live_type_text_view_post_comment_sort_type_bottom_sheet_fragment) TextView liveTypeTextView; - private Activity activity; + private BaseActivity activity; public PostCommentSortTypeBottomSheetFragment() { // Required empty public constructor } @@ -107,12 +108,16 @@ public class PostCommentSortTypeBottomSheetFragment extends LandscapeExpandedRou dismiss(); }); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - this.activity = (Activity) context; + this.activity = (BaseActivity) context; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostFilterOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostFilterOptionsBottomSheetFragment.java index ab06f69f..268f82ba 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostFilterOptionsBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostFilterOptionsBottomSheetFragment.java @@ -15,6 +15,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.PostFilterPreferenceActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; +import ml.docilealligator.infinityforreddit.utils.Utils; public class PostFilterOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { @@ -56,6 +57,10 @@ public class PostFilterOptionsBottomSheetFragment extends LandscapeExpandedRound dismiss(); }); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostFilterUsageOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostFilterUsageOptionsBottomSheetFragment.java index c57a6f4d..a3225959 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostFilterUsageOptionsBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostFilterUsageOptionsBottomSheetFragment.java @@ -15,6 +15,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.PostFilterUsageListingActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.postfilter.PostFilterUsage; +import ml.docilealligator.infinityforreddit.utils.Utils; public class PostFilterUsageOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { @@ -54,6 +55,10 @@ public class PostFilterUsageOptionsBottomSheetFragment extends LandscapeExpanded dismiss(); }); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostLayoutBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostLayoutBottomSheetFragment.java index 2172f27d..58fcef0a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostLayoutBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostLayoutBottomSheetFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; @@ -15,8 +14,10 @@ import androidx.fragment.app.Fragment; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; /** * A simple {@link Fragment} subclass. @@ -31,7 +32,7 @@ public class PostLayoutBottomSheetFragment extends LandscapeExpandedRoundedBotto TextView compactLayoutTextView; @BindView(R.id.gallery_layout_text_view_post_layout_bottom_sheet_fragment) TextView galleryLayoutTextView; - private Activity activity; + private BaseActivity activity; public PostLayoutBottomSheetFragment() { // Required empty public constructor } @@ -60,13 +61,17 @@ public class PostLayoutBottomSheetFragment extends LandscapeExpandedRoundedBotto ((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_CARD_2); dismiss(); }); + + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } return rootView; } @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - this.activity = (Activity) context; + this.activity = (BaseActivity) context; } public interface PostLayoutSelectionCallback { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostTypeBottomSheetFragment.java index a8d0ff54..fd6fc650 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostTypeBottomSheetFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.os.Build; @@ -17,7 +16,9 @@ import androidx.fragment.app.Fragment; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; /** @@ -40,7 +41,7 @@ public class PostTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS TextView videoTypeTextView; @BindView(R.id.gallery_type_linear_layout_post_type_bottom_sheet_fragment) TextView galleryTypeTextView; - private Activity activity; + private BaseActivity activity; public PostTypeBottomSheetFragment() { // Required empty public constructor @@ -82,13 +83,17 @@ public class PostTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS dismiss(); }); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - this.activity = (Activity) context; + this.activity = (BaseActivity) context; } public interface PostTypeSelectionCallback { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/RandomBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/RandomBottomSheetFragment.java index 15a1ac62..3cb0360b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/RandomBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/RandomBottomSheetFragment.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; +import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; @@ -12,7 +13,9 @@ import androidx.annotation.NonNull; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; public class RandomBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { @@ -72,6 +75,13 @@ public class RandomBottomSheetFragment extends LandscapeExpandedRoundedBottomShe dismiss(); }); + Activity baseActivity = getActivity(); + if (baseActivity instanceof BaseActivity) { + if (((BaseActivity) activity).typeface != null) { + Utils.setFontToAllTextViews(rootView, ((BaseActivity) activity).typeface); + } + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchPostSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchPostSortTypeBottomSheetFragment.java index 415cf976..90f2a15b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchPostSortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchPostSortTypeBottomSheetFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.os.Build; @@ -19,7 +18,9 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; /** @@ -37,7 +38,7 @@ public class SearchPostSortTypeBottomSheetFragment extends LandscapeExpandedRoun TextView newTypeTextView; @BindView(R.id.comments_type_text_view_search_sort_type_bottom_sheet_fragment) TextView commentsTypeTextView; - private Activity activity; + private BaseActivity activity; public SearchPostSortTypeBottomSheetFragment() { // Required empty public constructor } @@ -78,12 +79,16 @@ public class SearchPostSortTypeBottomSheetFragment extends LandscapeExpandedRoun dismiss(); }); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - this.activity = (Activity) context; + this.activity = (BaseActivity) context; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchUserAndSubredditSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchUserAndSubredditSortTypeBottomSheetFragment.java index 771c7a69..4b7f82b0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchUserAndSubredditSortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchUserAndSubredditSortTypeBottomSheetFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.os.Build; @@ -19,7 +18,9 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; /** @@ -32,7 +33,7 @@ public class SearchUserAndSubredditSortTypeBottomSheetFragment extends Landscape TextView relevanceTypeTextView; @BindView(R.id.activity_type_text_view_search_user_and_subreddit_sort_type_bottom_sheet_fragment) TextView activityTypeTextView; - private Activity activity; + private BaseActivity activity; public SearchUserAndSubredditSortTypeBottomSheetFragment() { // Required empty public constructor } @@ -64,12 +65,16 @@ public class SearchUserAndSubredditSortTypeBottomSheetFragment extends Landscape dismiss(); }); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - this.activity = (Activity) context; + this.activity = (BaseActivity) context; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectOrCaptureImageBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectOrCaptureImageBottomSheetFragment.java index 0497ecbf..8b100566 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectOrCaptureImageBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectOrCaptureImageBottomSheetFragment.java @@ -12,6 +12,7 @@ import androidx.annotation.NonNull; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.PostGalleryActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; public class SelectOrCaptureImageBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { @@ -40,6 +41,10 @@ public class SelectOrCaptureImageBottomSheetFragment extends LandscapeExpandedRo dismiss(); }); + if (mActivity.typeface != null) { + Utils.setFontToAllTextViews(rootView, mActivity.typeface); + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectSubredditsOrUsersOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectSubredditsOrUsersOptionsBottomSheetFragment.java index 6adc6982..7b94b051 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectSubredditsOrUsersOptionsBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectSubredditsOrUsersOptionsBottomSheetFragment.java @@ -14,6 +14,7 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.SelectedSubredditsAndUsersActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; public class SelectSubredditsOrUsersOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { @@ -45,6 +46,10 @@ public class SelectSubredditsOrUsersOptionsBottomSheetFragment extends Landscape dismiss(); }); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SetAsWallpaperBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SetAsWallpaperBottomSheetFragment.java index 4a4762aa..e2ca8536 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SetAsWallpaperBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SetAsWallpaperBottomSheetFragment.java @@ -15,7 +15,11 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback; +import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity; +import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity; +import ml.docilealligator.infinityforreddit.activities.ViewVideoActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; public class SetAsWallpaperBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { @@ -68,6 +72,20 @@ public class SetAsWallpaperBottomSheetFragment extends LandscapeExpandedRoundedB }); } + if (mActivity instanceof ViewVideoActivity) { + if (((ViewVideoActivity) mActivity).typeface != null) { + Utils.setFontToAllTextViews(rootView, ((ViewVideoActivity) mActivity).typeface); + } + } else if (mActivity instanceof ViewImgurMediaActivity) { + if (((ViewImgurMediaActivity) mActivity).typeface != null) { + Utils.setFontToAllTextViews(rootView, ((ViewImgurMediaActivity) mActivity).typeface); + } + } else if (mActivity instanceof ViewRedditGalleryActivity) { + if (((ViewRedditGalleryActivity) mActivity).typeface != null) { + Utils.setFontToAllTextViews(rootView, ((ViewRedditGalleryActivity) mActivity).typeface); + } + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/ShareLinkBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/ShareLinkBottomSheetFragment.java index f35e008a..d6385527 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/ShareLinkBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/ShareLinkBottomSheetFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.ClipData; import android.content.ClipboardManager; @@ -15,14 +14,15 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.post.Post; +import ml.docilealligator.infinityforreddit.utils.Utils; /** * A simple {@link Fragment} subclass. @@ -41,7 +41,7 @@ public class ShareLinkBottomSheetFragment extends LandscapeExpandedRoundedBottom @BindView(R.id.copy_media_link_text_view_share_link_bottom_sheet_fragment) TextView copyMediaLinkTextView; - private Activity activity; + private BaseActivity activity; public ShareLinkBottomSheetFragment() { // Required empty public constructor @@ -108,6 +108,10 @@ public class ShareLinkBottomSheetFragment extends LandscapeExpandedRoundedBottom copyLink(postLink); dismiss(); }); + + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } return rootView; } @@ -136,6 +140,6 @@ public class ShareLinkBottomSheetFragment extends LandscapeExpandedRoundedBottom @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (AppCompatActivity) context; + activity = (BaseActivity) context; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTimeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTimeBottomSheetFragment.java index 5f184ea8..a595ec85 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTimeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTimeBottomSheetFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.os.Build; @@ -19,7 +18,9 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; /** * A simple {@link Fragment} subclass. @@ -40,7 +41,7 @@ public class SortTimeBottomSheetFragment extends LandscapeExpandedRoundedBottomS TextView yearTextView; @BindView(R.id.all_time_text_view_sort_time_bottom_sheet_fragment) TextView allTimeTextView; - private Activity activity; + private BaseActivity activity; public SortTimeBottomSheetFragment() { // Required empty public constructor } @@ -100,12 +101,16 @@ public class SortTimeBottomSheetFragment extends LandscapeExpandedRoundedBottomS dismiss(); }); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - this.activity = (Activity) context; + this.activity = (BaseActivity) context; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTypeBottomSheetFragment.java index f2ab9a1b..f2d50c38 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTypeBottomSheetFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; import android.content.Context; import android.content.res.Configuration; import android.os.Build; @@ -19,7 +18,9 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; /** @@ -40,7 +41,7 @@ public class SortTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS TextView topTypeTextView; @BindView(R.id.controversial_type_text_view_sort_type_bottom_sheet_fragment) TextView controversialTypeTextView; - private Activity activity; + private BaseActivity activity; public SortTypeBottomSheetFragment() { // Required empty public constructor } @@ -90,12 +91,16 @@ public class SortTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS dismiss(); }); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (Activity) context; + activity = (BaseActivity) context; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UploadedImagesBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UploadedImagesBottomSheetFragment.java index 8b525ee8..3fa0aaff 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UploadedImagesBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UploadedImagesBottomSheetFragment.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; +import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; @@ -13,8 +14,10 @@ import com.google.android.material.button.MaterialButton; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.UploadImageEnabledActivity; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.adapters.UploadedImagesRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; public class UploadedImagesBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { @@ -49,13 +52,20 @@ public class UploadedImagesBottomSheetFragment extends LandscapeExpandedRoundedB }); uploadedImagesRecyclerView = rootView.findViewById(R.id.recycler_view_uploaded_images_bottom_sheet); - adapter = new UploadedImagesRecyclerViewAdapter( + adapter = new UploadedImagesRecyclerViewAdapter(getActivity(), getArguments().getParcelableArrayList(EXTRA_UPLOADED_IMAGES), uploadedImage -> { activity.insertImageUrl(uploadedImage); dismiss(); }); uploadedImagesRecyclerView.setAdapter(adapter); + Activity baseActivity = getActivity(); + if (baseActivity instanceof BaseActivity) { + if (((BaseActivity) activity).typeface != null) { + Utils.setFontToAllTextViews(rootView, ((BaseActivity) activity).typeface); + } + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UrlMenuBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UrlMenuBottomSheetFragment.java index 6aba619a..aaf8783b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UrlMenuBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UrlMenuBottomSheetFragment.java @@ -19,8 +19,11 @@ import androidx.annotation.NonNull; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; +import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; public class UrlMenuBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { @@ -88,6 +91,16 @@ public class UrlMenuBottomSheetFragment extends LandscapeExpandedRoundedBottomSh dismiss(); }); + if (activity instanceof BaseActivity) { + if (((BaseActivity) activity).typeface != null) { + Utils.setFontToAllTextViews(rootView, ((BaseActivity) activity).typeface); + } + } else if (activity instanceof ViewRedditGalleryActivity) { + if (((ViewRedditGalleryActivity) activity).typeface != null) { + Utils.setFontToAllTextViews(rootView, ((ViewRedditGalleryActivity) activity).typeface); + } + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UserThingSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UserThingSortTypeBottomSheetFragment.java index 510b92df..ff4888c7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UserThingSortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UserThingSortTypeBottomSheetFragment.java @@ -1,7 +1,7 @@ package ml.docilealligator.infinityforreddit.bottomsheetfragments; -import android.app.Activity; +import android.content.Context; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; @@ -18,7 +18,9 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; +import ml.docilealligator.infinityforreddit.utils.Utils; /** @@ -34,6 +36,8 @@ public class UserThingSortTypeBottomSheetFragment extends LandscapeExpandedRound TextView topTypeTextView; @BindView(R.id.controversial_type_text_view_user_thing_sort_type_bottom_sheet_fragment) TextView controversialTypeTextView; + private BaseActivity activity; + public UserThingSortTypeBottomSheetFragment() { // Required empty public constructor } @@ -45,8 +49,6 @@ public class UserThingSortTypeBottomSheetFragment extends LandscapeExpandedRound ButterKnife.bind(this, rootView); - Activity activity = getActivity(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); @@ -80,6 +82,16 @@ public class UserThingSortTypeBottomSheetFragment extends LandscapeExpandedRound dismiss(); }); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + return rootView; } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + this.activity = (BaseActivity) context; + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontListPreference.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontListPreference.java new file mode 100644 index 00000000..ac4b2771 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontListPreference.java @@ -0,0 +1,52 @@ +package ml.docilealligator.infinityforreddit.customviews; + +import android.content.Context; +import android.graphics.Typeface; +import android.util.AttributeSet; +import android.view.View; +import android.widget.TextView; + +import androidx.preference.ListPreference; +import androidx.preference.PreferenceViewHolder; + +import ml.docilealligator.infinityforreddit.CustomFontReceiver; + +public class CustomFontListPreference extends ListPreference implements CustomFontReceiver { + private Typeface typeface; + + public CustomFontListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public CustomFontListPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public CustomFontListPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public CustomFontListPreference(Context context) { + super(context); + } + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + if (typeface != null) { + View titleTextView = holder.findViewById(android.R.id.title); + if (titleTextView instanceof TextView) { + ((TextView) titleTextView).setTypeface(typeface); + } + View summaryTextView = holder.findViewById(android.R.id.summary); + if (summaryTextView instanceof TextView) { + ((TextView) summaryTextView).setTypeface(typeface); + } + } + } + + @Override + public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { + this.typeface = typeface; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreference.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreference.java new file mode 100644 index 00000000..e087b181 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreference.java @@ -0,0 +1,52 @@ +package ml.docilealligator.infinityforreddit.customviews; + +import android.content.Context; +import android.graphics.Typeface; +import android.util.AttributeSet; +import android.view.View; +import android.widget.TextView; + +import androidx.preference.Preference; +import androidx.preference.PreferenceViewHolder; + +import ml.docilealligator.infinityforreddit.CustomFontReceiver; + +public class CustomFontPreference extends Preference implements CustomFontReceiver { + private Typeface typeface; + + public CustomFontPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public CustomFontPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public CustomFontPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public CustomFontPreference(Context context) { + super(context); + } + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + if (typeface != null) { + View titleTextView = holder.findViewById(android.R.id.title); + if (titleTextView instanceof TextView) { + ((TextView) titleTextView).setTypeface(typeface); + } + View summaryTextView = holder.findViewById(android.R.id.summary); + if (summaryTextView instanceof TextView) { + ((TextView) summaryTextView).setTypeface(typeface); + } + } + } + + @Override + public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { + this.typeface = typeface; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceCategory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceCategory.java new file mode 100644 index 00000000..2c7d6740 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceCategory.java @@ -0,0 +1,52 @@ +package ml.docilealligator.infinityforreddit.customviews; + +import android.content.Context; +import android.graphics.Typeface; +import android.util.AttributeSet; +import android.view.View; +import android.widget.TextView; + +import androidx.preference.PreferenceCategory; +import androidx.preference.PreferenceViewHolder; + +import ml.docilealligator.infinityforreddit.CustomFontReceiver; + +public class CustomFontPreferenceCategory extends PreferenceCategory implements CustomFontReceiver { + private Typeface typeface; + + public CustomFontPreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public CustomFontPreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public CustomFontPreferenceCategory(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public CustomFontPreferenceCategory(Context context) { + super(context); + } + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + if (typeface != null) { + View titleTextView = holder.findViewById(android.R.id.title); + if (titleTextView instanceof TextView) { + ((TextView) titleTextView).setTypeface(typeface); + } + View summaryTextView = holder.findViewById(android.R.id.summary); + if (summaryTextView instanceof TextView) { + ((TextView) summaryTextView).setTypeface(typeface); + } + } + } + + @Override + public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { + this.typeface = typeface; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceFragmentCompat.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceFragmentCompat.java new file mode 100644 index 00000000..1984bb14 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceFragmentCompat.java @@ -0,0 +1,31 @@ +package ml.docilealligator.infinityforreddit.customviews; + +import android.content.Context; +import android.graphics.Typeface; + +import androidx.annotation.NonNull; +import androidx.preference.Preference; +import androidx.preference.PreferenceFragmentCompat; + +import ml.docilealligator.infinityforreddit.CustomFontReceiver; +import ml.docilealligator.infinityforreddit.activities.SettingsActivity; + +public abstract class CustomFontPreferenceFragmentCompat extends PreferenceFragmentCompat { + protected SettingsActivity activity; + + protected void setFont(Typeface typeface) { + int preferenceCount = getPreferenceScreen().getPreferenceCount(); + for (int i = 0; i < preferenceCount; i++) { + Preference preference = getPreferenceScreen().getPreference(i); + if (preference instanceof CustomFontReceiver) { + ((CustomFontReceiver) preference).setCustomFont(typeface, null, null); + } + } + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (SettingsActivity) context; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSeekBarPreference.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSeekBarPreference.java new file mode 100644 index 00000000..d7d9454f --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSeekBarPreference.java @@ -0,0 +1,52 @@ +package ml.docilealligator.infinityforreddit.customviews; + +import android.content.Context; +import android.graphics.Typeface; +import android.util.AttributeSet; +import android.view.View; +import android.widget.TextView; + +import androidx.preference.PreferenceViewHolder; +import androidx.preference.SeekBarPreference; + +import ml.docilealligator.infinityforreddit.CustomFontReceiver; + +public class CustomFontSeekBarPreference extends SeekBarPreference implements CustomFontReceiver { + private Typeface typeface; + + public CustomFontSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public CustomFontSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public CustomFontSeekBarPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public CustomFontSeekBarPreference(Context context) { + super(context); + } + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + if (typeface != null) { + View titleTextView = holder.findViewById(android.R.id.title); + if (titleTextView instanceof TextView) { + ((TextView) titleTextView).setTypeface(typeface); + } + View summaryTextView = holder.findViewById(android.R.id.summary); + if (summaryTextView instanceof TextView) { + ((TextView) summaryTextView).setTypeface(typeface); + } + } + } + + @Override + public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { + this.typeface = typeface; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSwitchPreference.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSwitchPreference.java new file mode 100644 index 00000000..b7c62834 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSwitchPreference.java @@ -0,0 +1,52 @@ +package ml.docilealligator.infinityforreddit.customviews; + +import android.content.Context; +import android.graphics.Typeface; +import android.util.AttributeSet; +import android.view.View; +import android.widget.TextView; + +import androidx.preference.PreferenceViewHolder; +import androidx.preference.SwitchPreference; + +import ml.docilealligator.infinityforreddit.CustomFontReceiver; + +public class CustomFontSwitchPreference extends SwitchPreference implements CustomFontReceiver { + private Typeface typeface; + + public CustomFontSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public CustomFontSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public CustomFontSwitchPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public CustomFontSwitchPreference(Context context) { + super(context); + } + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + if (typeface != null) { + View titleTextView = holder.findViewById(android.R.id.title); + if (titleTextView instanceof TextView) { + ((TextView) titleTextView).setTypeface(typeface); + } + View summaryTextView = holder.findViewById(android.R.id.summary); + if (summaryTextView instanceof TextView) { + ((TextView) summaryTextView).setTypeface(typeface); + } + } + } + + @Override + public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { + this.typeface = typeface; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ChangePullToRefreshEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangePullToRefreshEvent.java index c9aa91b9..9d75dd8d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ChangePullToRefreshEvent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangePullToRefreshEvent.java @@ -1,4 +1,4 @@ -package ml.docilealligator.infinityforreddit.fragments; +package ml.docilealligator.infinityforreddit.events; public class ChangePullToRefreshEvent { public boolean pullToRefresh; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java index 177c1777..43ad87f7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java @@ -19,7 +19,6 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.res.ResourcesCompat; import androidx.fragment.app.Fragment; @@ -104,7 +103,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni Executor mExecutor; private String mAccessToken; private RequestManager mGlide; - private AppCompatActivity mActivity; + private BaseActivity mActivity; private LinearLayoutManagerBugFixed mLinearLayoutManager; private CommentsListingRecyclerViewAdapter mAdapter; private SortType sortType; @@ -356,7 +355,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - this.mActivity = (AppCompatActivity) context; + this.mActivity = (BaseActivity) context; } @Override @@ -371,6 +370,9 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(customThemeWrapper.getCircularProgressBarBackground()); mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent()); mFetchCommentInfoTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); + if (mActivity.typeface != null) { + mFetchCommentInfoTextView.setTypeface(mActivity.typeface); + } } private void showErrorView(int stringResId) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java index 0fe9a13d..bd2eed16 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.fragments; -import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; @@ -76,7 +75,7 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo @Inject Executor mExecutor; SubscribedUserViewModel mSubscribedUserViewModel; - private Activity mActivity; + private BaseActivity mActivity; private RequestManager mGlide; private LinearLayoutManagerBugFixed mLinearLayoutManager; @@ -154,7 +153,7 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - mActivity = (Activity) context; + mActivity = (BaseActivity) context; } @Override @@ -172,6 +171,9 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo mSwipeRefreshLayout.setEnabled(false); } mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + if (mActivity.typeface != null) { + mErrorTextView.setTypeface(mActivity.typeface); + } } public void goBackToTop() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java index 567f3a1b..0ff23330 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java @@ -177,6 +177,9 @@ public class InboxFragment extends Fragment implements FragmentCommunicator { mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); mFetchMessageInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + if (mActivity.typeface != null) { + mFetchMessageInfoTextView.setTypeface(mActivity.typeface); + } } public void goBackToTop() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java index 17a2fb96..1b7d15a9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java @@ -14,7 +14,6 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.RecyclerView; @@ -78,7 +77,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm Executor mExecutor; public MultiRedditViewModel mMultiRedditViewModel; - private AppCompatActivity mActivity; + private BaseActivity mActivity; private RequestManager mGlide; private LinearLayoutManagerBugFixed mLinearLayoutManager; @@ -207,7 +206,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - mActivity = (AppCompatActivity) context; + mActivity = (BaseActivity) context; } @Override @@ -221,6 +220,9 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm } mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + if (mActivity.typeface != null) { + mErrorTextView.setTypeface(mActivity.typeface); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index e7996b94..09655d7c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -35,7 +35,6 @@ import android.widget.Toast; import androidx.annotation.DimenRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.res.ResourcesCompat; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; @@ -109,6 +108,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent; import ml.docilealligator.infinityforreddit.events.ChangeOnlyDisablePreviewInVideoAndGifPostsEvent; import ml.docilealligator.infinityforreddit.events.ChangePostLayoutEvent; +import ml.docilealligator.infinityforreddit.events.ChangePullToRefreshEvent; import ml.docilealligator.infinityforreddit.events.ChangeRememberMutingOptionInPostFeedEvent; import ml.docilealligator.infinityforreddit.events.ChangeSavePostFeedScrolledPositionEvent; import ml.docilealligator.infinityforreddit.events.ChangeShowAbsoluteNumberOfVotesEvent; @@ -212,7 +212,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Inject Executor mExecutor; private RequestManager mGlide; - private AppCompatActivity activity; + private BaseActivity activity; private LinearLayoutManagerBugFixed mLinearLayoutManager; private StaggeredGridLayoutManager mStaggeredGridLayoutManager; private MenuItem lazyModeItem; @@ -1274,19 +1274,22 @@ public class PostFragment extends Fragment implements FragmentCommunicator { return null; }); - mPostRecyclerView.setAdapter(mAdapter.withLoadStateFooter(new Paging3LoadingStateAdapter(mCustomThemeWrapper, R.string.load_more_posts_error, + mPostRecyclerView.setAdapter(mAdapter.withLoadStateFooter(new Paging3LoadingStateAdapter(activity, mCustomThemeWrapper, R.string.load_more_posts_error, view -> mAdapter.retry()))); } @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { inflater.inflate(R.menu.post_fragment, menu); + for (int i = 0; i < menu.size(); i++) { + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, menu.getItem(i), null); + } lazyModeItem = menu.findItem(R.id.action_lazy_mode_post_fragment); if (isInLazyMode) { - lazyModeItem.setTitle(R.string.action_stop_lazy_mode); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, lazyModeItem, getString(R.string.action_stop_lazy_mode)); } else { - lazyModeItem.setTitle(R.string.action_start_lazy_mode); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, lazyModeItem, getString(R.string.action_start_lazy_mode)); } if (activity instanceof FilteredPostsActivity) { @@ -1396,7 +1399,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - this.activity = (AppCompatActivity) context; + this.activity = (BaseActivity) context; } @Override @@ -1469,7 +1472,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { return false; } - lazyModeItem.setTitle(R.string.action_stop_lazy_mode); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, lazyModeItem, getString(R.string.action_stop_lazy_mode)); if (mAdapter != null && mAdapter.isAutoplay()) { mAdapter.setAutoplay(false); @@ -1490,7 +1493,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void stopLazyMode() { - lazyModeItem.setTitle(R.string.action_start_lazy_mode); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, lazyModeItem, getString(R.string.action_start_lazy_mode)); if (mAdapter != null) { String autoplayString = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER); if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ALWAYS_ON) || @@ -1609,6 +1612,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); mFetchPostInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + if (activity.typeface != null) { + mFetchPostInfoTextView.setTypeface(activity.typeface); + } } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java index 34bfca89..0b0c8465 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.fragments; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -49,6 +48,7 @@ import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditData; @@ -84,7 +84,7 @@ public class SidebarFragment extends Fragment { CustomThemeWrapper mCustomThemeWrapper; @Inject Executor mExecutor; - private Activity activity; + private BaseActivity activity; private String mAccessToken; private String subredditName; private LinearLayoutManagerBugFixed linearLayoutManager; @@ -135,6 +135,9 @@ public class SidebarFragment extends Fragment { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { + if (activity.contentTypeface != null) { + textView.setTypeface(activity.contentTypeface); + } textView.setTextColor(markdownColor); textView.setOnLongClickListener(view -> { if (sidebarDescription != null && !sidebarDescription.equals("") && textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) { @@ -219,7 +222,7 @@ public class SidebarFragment extends Fragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (Activity) context; + activity = (BaseActivity) context; } public void fetchSubredditData() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java index 46513616..470469be 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.fragments; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -99,7 +98,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun Executor mExecutor; private LinearLayoutManagerBugFixed mLinearLayoutManager; private SubredditListingRecyclerViewAdapter mAdapter; - private Activity mActivity; + private BaseActivity mActivity; private SortType sortType; public SubredditListingFragment() { @@ -218,7 +217,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - mActivity = (Activity) context; + mActivity = (BaseActivity) context; } private void showErrorView(int stringResId) { @@ -248,6 +247,9 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); mFetchSubredditListingInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + if (mActivity.typeface != null) { + mFetchSubredditListingInfoTextView.setTypeface(mActivity.contentTypeface); + } } public void goBackToTop() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java index 755f4833..3ee37f7e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.fragments; -import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; @@ -31,15 +30,15 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import me.zhanghai.android.fastscroll.FastScrollerBuilder; +import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.SubredditSelectionActivity; import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity; import ml.docilealligator.infinityforreddit.adapters.SubscribedSubredditsRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; -import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditViewModel; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -80,7 +79,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra @Inject Executor mExecutor; public SubscribedSubredditViewModel mSubscribedSubredditViewModel; - private Activity mActivity; + private BaseActivity mActivity; private RequestManager mGlide; private LinearLayoutManagerBugFixed mLinearLayoutManager; @@ -173,7 +172,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - mActivity = (Activity) context; + mActivity = (BaseActivity) context; } @Override @@ -191,6 +190,9 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra mSwipeRefreshLayout.setEnabled(false); } mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + if (mActivity.typeface != null) { + mErrorTextView.setTypeface(mActivity.contentTypeface); + } } public void goBackToTop() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ThemePreviewCommentsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ThemePreviewCommentsFragment.java index 9b5dad16..4a6a2780 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ThemePreviewCommentsFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ThemePreviewCommentsFragment.java @@ -143,6 +143,24 @@ public class ThemePreviewCommentsFragment extends Fragment { authorTextViewFullyCollapsed.setTextColor(customTheme.username); scoreTextViewFullyCollapsed.setTextColor(customTheme.secondaryTextColor); timeTextViewFullyCollapsed.setTextColor(customTheme.secondaryTextColor); + + if (activity.typeface != null) { + authorTextView.setTypeface(activity.typeface); + commentTimeTextView.setTypeface(activity.typeface); + flairTextView.setTypeface(activity.typeface); + scoreTextView.setTypeface(activity.typeface); + authorTextViewAwardBackground.setTypeface(activity.typeface); + commentTimeTextViewAwardBackground.setTypeface(activity.typeface); + flairTextViewAwardBackground.setTypeface(activity.typeface); + scoreTextViewAwardBackground.setTypeface(activity.typeface); + authorTextViewFullyCollapsed.setTypeface(activity.typeface); + scoreTextViewFullyCollapsed.setTypeface(activity.typeface); + timeTextViewFullyCollapsed.setTypeface(activity.typeface); + } + if (activity.contentTypeface != null) { + contentTextView.setTypeface(activity.contentTypeface); + contentTextViewAwardBackground.setTypeface(activity.contentTypeface); + } return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ThemePreviewPostsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ThemePreviewPostsFragment.java index 1f56b086..49aa1ea7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ThemePreviewPostsFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ThemePreviewPostsFragment.java @@ -142,6 +142,25 @@ public class ThemePreviewPostsFragment extends Fragment { saveButton.setColorFilter(customTheme.postIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); shareButton.setColorFilter(customTheme.postIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); + if (activity.typeface != null) { + subredditNameTextView.setTypeface(activity.typeface); + usernameTextView.setTypeface(activity.typeface); + postTimeTextView.setTypeface(activity.typeface); + typeTextView.setTypeface(activity.typeface); + spoilerTextView.setTypeface(activity.typeface); + nsfwTextView.setTypeface(activity.typeface); + flairTextView.setTypeface(activity.typeface); + awardsTextView.setTypeface(activity.typeface); + linkTextView.setTypeface(activity.typeface); + scoreTextView.setTypeface(activity.typeface); + commentsCountTextView.setTypeface(activity.typeface); + } + if (activity.titleTypeface != null) { + titleTextView.setTypeface(activity.titleTypeface); + } + if (activity.contentTypeface != null) { + contentTextView.setTypeface(activity.contentTypeface); + } return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java index 912176d5..824dc93e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.fragments; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -100,7 +99,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato private LinearLayoutManagerBugFixed mLinearLayoutManager; private String mQuery; private UserListingRecyclerViewAdapter mAdapter; - private Activity mActivity; + private BaseActivity mActivity; private SortType sortType; public UserListingFragment() { @@ -143,7 +142,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase())); boolean nsfw = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); - mAdapter = new UserListingRecyclerViewAdapter(getActivity(), mExecutor, mOauthRetrofit, mRetrofit, + mAdapter = new UserListingRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRetrofit, mCustomThemeWrapper, accessToken, accountName, mRedditDataRoomDatabase, getArguments().getBoolean(EXTRA_IS_MULTI_SELECTION, false), new UserListingRecyclerViewAdapter.Callback() { @@ -220,7 +219,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - mActivity = (Activity) context; + mActivity = (BaseActivity) context; } private void showErrorView(int stringResId) { @@ -250,6 +249,9 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); mFetchUserListingInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + if (mActivity.typeface != null) { + mFetchUserListingInfoTextView.setTypeface(mActivity.contentTypeface); + } } public void goBackToTop() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java index 2b6e9ea9..bc093ea1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java @@ -56,6 +56,7 @@ import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity; import ml.docilealligator.infinityforreddit.asynctasks.SaveBitmapImageToFile; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetAsWallpaperBottomSheetFragment; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; +import ml.docilealligator.infinityforreddit.utils.Utils; public class ViewImgurImageFragment extends Fragment { @@ -194,6 +195,10 @@ public class ViewImgurImageFragment extends Fragment { @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { inflater.inflate(R.menu.view_imgur_image_fragment, menu); + for (int i = 0; i < menu.size(); i++) { + MenuItem item = menu.getItem(i); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, null); + } super.onCreateOptionsMenu(menu, inflater); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java index f67e18c8..a2fcfb9e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java @@ -55,6 +55,7 @@ import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PlaybackSpeedBottomSheetFragment; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; public class ViewImgurVideoFragment extends Fragment { @@ -175,6 +176,10 @@ public class ViewImgurVideoFragment extends Fragment { @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { inflater.inflate(R.menu.view_imgur_video_fragment, menu); + for (int i = 0; i < menu.size(); i++) { + MenuItem item = menu.getItem(i); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, null); + } super.onCreateOptionsMenu(menu, inflater); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 51f0af92..675c8b87 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -626,10 +626,10 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic if (mPost.isHidden()) { hideItem.setVisible(true); - hideItem.setTitle(R.string.action_unhide_post); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, hideItem, getString(R.string.action_unhide_post)); } else { hideItem.setVisible(true); - hideItem.setTitle(R.string.action_hide_post); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, hideItem, getString(R.string.action_hide_post)); } } else { saveItem.setVisible(false); @@ -645,17 +645,17 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic MenuItem nsfwItem = mMenu.findItem(R.id.action_nsfw_view_post_detail_fragment); nsfwItem.setVisible(true); if (mPost.isNSFW()) { - nsfwItem.setTitle(R.string.action_unmark_nsfw); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, nsfwItem, getString(R.string.action_unmark_nsfw)); } else { - nsfwItem.setTitle(R.string.action_mark_nsfw); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, nsfwItem, getString(R.string.action_mark_nsfw)); } MenuItem spoilerItem = mMenu.findItem(R.id.action_spoiler_view_post_detail_fragment); spoilerItem.setVisible(true); if (mPost.isSpoiler()) { - spoilerItem.setTitle(R.string.action_unmark_spoiler); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, spoilerItem, getString(R.string.action_unmark_spoiler)); } else { - spoilerItem.setTitle(R.string.action_mark_spoiler); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, spoilerItem, getString(R.string.action_mark_spoiler)); } mMenu.findItem(R.id.action_edit_flair_view_post_detail_fragment).setVisible(true); @@ -889,17 +889,21 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic new SaveThing.SaveThingListener() { @Override public void success() { - mPost.setSaved(false); - item.setIcon(mUnsavedIcon); - showMessage(R.string.post_unsaved_success); + if (isAdded()) { + mPost.setSaved(false); + item.setIcon(mUnsavedIcon); + showMessage(R.string.post_unsaved_success); + } EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } @Override public void failed() { - mPost.setSaved(true); - item.setIcon(mSavedIcon); - showMessage(R.string.post_unsaved_failed); + if (isAdded()) { + mPost.setSaved(true); + item.setIcon(mSavedIcon); + showMessage(R.string.post_unsaved_failed); + } EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } }); @@ -909,17 +913,21 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic new SaveThing.SaveThingListener() { @Override public void success() { - mPost.setSaved(true); - item.setIcon(mSavedIcon); - showMessage(R.string.post_saved_success); + if (isAdded()) { + mPost.setSaved(true); + item.setIcon(mSavedIcon); + showMessage(R.string.post_saved_success); + } EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } @Override public void failed() { - mPost.setSaved(false); - item.setIcon(mUnsavedIcon); - showMessage(R.string.post_saved_failed); + if (isAdded()) { + mPost.setSaved(false); + item.setIcon(mUnsavedIcon); + showMessage(R.string.post_saved_failed); + } EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } }); @@ -940,42 +948,50 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic } else if (itemId == R.id.action_hide_view_post_detail_fragment) { if (mPost != null && mAccessToken != null) { if (mPost.isHidden()) { - item.setTitle(R.string.action_hide_post); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, getString(R.string.action_hide_post)); HidePost.unhidePost(mOauthRetrofit, mAccessToken, mPost.getFullName(), new HidePost.HidePostListener() { @Override public void success() { - mPost.setHidden(false); - item.setTitle(R.string.action_hide_post); - showMessage(R.string.post_unhide_success); + if (isAdded()) { + mPost.setHidden(false); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, getString(R.string.action_hide_post)); + showMessage(R.string.post_unhide_success); + } EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } @Override public void failed() { - mPost.setHidden(true); - item.setTitle(R.string.action_unhide_post); - showMessage(R.string.post_unhide_failed); + if (isAdded()) { + mPost.setHidden(true); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, getString(R.string.action_unhide_post)); + showMessage(R.string.post_unhide_failed); + } EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } }); } else { - item.setTitle(R.string.action_unhide_post); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, getString(R.string.action_unhide_post)); HidePost.hidePost(mOauthRetrofit, mAccessToken, mPost.getFullName(), new HidePost.HidePostListener() { @Override public void success() { - mPost.setHidden(true); - item.setTitle(R.string.action_unhide_post); - showMessage(R.string.post_hide_success); + if (isAdded()) { + mPost.setHidden(true); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, getString(R.string.action_unhide_post)); + showMessage(R.string.post_hide_success); + } EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } @Override public void failed() { - mPost.setHidden(false); - item.setTitle(R.string.action_hide_post); - showMessage(R.string.post_hide_failed); + if (isAdded()) { + mPost.setHidden(false); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, getString(R.string.action_hide_post)); + showMessage(R.string.post_hide_failed); + } EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); } }); @@ -1149,8 +1165,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic @SuppressLint("RestrictedApi") protected boolean applyMenuItemTheme(Menu menu) { if (mCustomThemeWrapper != null) { - int size = Math.min(menu.size(), 2); - for (int i = 0; i < size; i++) { + for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); if (((MenuItemImpl) item).requestsActionButton()) { Drawable drawable = item.getIcon(); @@ -1159,6 +1174,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic item.setIcon(drawable); } } + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, null); } } return true; @@ -1512,18 +1528,22 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic new FetchPost.FetchPostListener() { @Override public void fetchPostSuccess(Post post) { - mPost = post; - mPostAdapter.updatePost(mPost); - EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); - isRefreshing = false; - setupMenu(); - mSwipeRefreshLayout.setRefreshing(false); + if (isAdded()) { + mPost = post; + mPostAdapter.updatePost(mPost); + EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)); + isRefreshing = false; + setupMenu(); + mSwipeRefreshLayout.setRefreshing(false); + } } @Override public void fetchPostFailed() { - showMessage(R.string.refresh_post_failed); - isRefreshing = false; + if (isAdded()) { + showMessage(R.string.refresh_post_failed); + isRefreshing = false; + } } }); } @@ -1922,6 +1942,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); mSwipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); mFetchPostInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); + if (activity.typeface != null) { + mFetchPostInfoTextView.setTypeface(activity.contentTypeface); + } } private void onWindowFocusChanged(boolean hasWindowsFocus) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java index 5b7dcb2c..a053b68a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java @@ -16,7 +16,6 @@ import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.RecyclerView; @@ -55,6 +54,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RPANBroadcast; import ml.docilealligator.infinityforreddit.RPANComment; +import ml.docilealligator.infinityforreddit.activities.RPANActivity; import ml.docilealligator.infinityforreddit.adapters.RPANCommentStreamRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; @@ -105,7 +105,7 @@ public class ViewRPANBroadcastFragment extends Fragment { @Inject @Named("rpan") OkHttpClient okHttpClient; - private AppCompatActivity mActivity; + private RPANActivity mActivity; private RPANBroadcast rpanBroadcast; private SimpleExoPlayer player; private DefaultTrackSelector trackSelector; @@ -133,6 +133,12 @@ public class ViewRPANBroadcastFragment extends Fragment { ButterKnife.bind(this, rootView); + if (mActivity.typeface != null) { + subredditNameTextView.setTypeface(mActivity.typeface); + usernameTextView.setTypeface(mActivity.typeface); + titleTextView.setTypeface(mActivity.typeface); + } + rpanBroadcast = getArguments().getParcelable(EXTRA_RPAN_BROADCAST); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || getResources().getBoolean(R.bool.isTablet)) { @@ -390,7 +396,7 @@ public class ViewRPANBroadcastFragment extends Fragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - mActivity = (AppCompatActivity) context; + mActivity = (RPANActivity) context; } private static class CommentStreamWebSocketListener extends WebSocketListener { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java index 1333d7c1..30e6b913 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java @@ -68,6 +68,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetAsWallpaperB import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; +import ml.docilealligator.infinityforreddit.utils.Utils; public class ViewRedditGalleryImageOrGifFragment extends Fragment { @@ -137,6 +138,12 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { isNsfw = getArguments().getBoolean(EXTRA_IS_NSFW, false); glide = Glide.with(activity); + if (activity.typeface != null) { + titleTextView.setTypeface(activity.typeface); + captionTextView.setTypeface(activity.typeface); + captionUrlTextView.setTypeface(activity.typeface); + } + imageView.setImageViewFactory(new GlideImageViewFactory()); imageView.setImageLoaderCallback(new ImageLoader.Callback() { @@ -346,6 +353,10 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { inflater.inflate(R.menu.view_reddit_gallery_image_or_gif_fragment, menu); + for (int i = 0; i < menu.size(); i++) { + MenuItem item = menu.getItem(i); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, null); + } super.onCreateOptionsMenu(menu, inflater); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java index 343905c7..fd27d4db 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java @@ -55,6 +55,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.PlaybackSpeedBo import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; public class ViewRedditGalleryVideoFragment extends Fragment { @@ -107,6 +108,10 @@ public class ViewRedditGalleryVideoFragment extends Fragment { setHasOptionsMenu(true); + if (activity.typeface != null) { + titleTextView.setTypeface(activity.typeface); + } + activity.setVolumeControlStream(AudioManager.STREAM_MUSIC); galleryVideo = getArguments().getParcelable(EXTRA_REDDIT_GALLERY_VIDEO); @@ -181,6 +186,10 @@ public class ViewRedditGalleryVideoFragment extends Fragment { @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { inflater.inflate(R.menu.view_reddit_gallery_video_fragment, menu); + for (int i = 0; i < menu.size(); i++) { + MenuItem item = menu.getItem(i); + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, null); + } super.onCreateOptionsMenu(menu, inflater); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java index 9d5f0445..a3f72153 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchPost.java @@ -22,7 +22,7 @@ public class FetchPost { } else { postCall = retrofit.create(RedditAPI.class).getPostOauth(id, APIUtils.getOAuthHeader(accessToken)); } - postCall.enqueue(new Callback<String>() { + postCall.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { if (response.isSuccessful()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AboutPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AboutPreferenceFragment.java index c132b339..abcdb0d3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AboutPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AboutPreferenceFragment.java @@ -1,34 +1,34 @@ package ml.docilealligator.infinityforreddit.settings; -import android.app.Activity; import android.content.ActivityNotFoundException; -import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.widget.Toast; -import androidx.annotation.NonNull; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; -import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.BuildConfig; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; /** * A simple {@link PreferenceFragmentCompat} subclass. */ -public class AboutPreferenceFragment extends PreferenceFragmentCompat { - - private Activity activity; +public class AboutPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.about_preferences, rootKey); + if (activity.typeface != null) { + setFont(activity.typeface); + } + Preference openSourcePreference = findPreference(SharedPreferencesUtils.OPEN_SOURCE_KEY); Preference ratePreference = findPreference(SharedPreferencesUtils.RATE_KEY); Preference emailPreference = findPreference(SharedPreferencesUtils.EMAIL_KEY); @@ -137,10 +137,4 @@ public class AboutPreferenceFragment extends PreferenceFragmentCompat { }); } } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - activity = (Activity) context; - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AcknowledgementFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AcknowledgementFragment.java index 5a9ec266..0ea2cbba 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AcknowledgementFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AcknowledgementFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.settings; -import android.app.Activity; import android.content.Context; import android.net.Uri; import android.os.Bundle; @@ -17,8 +16,9 @@ import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.adapters.AcknowledgementRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.adapters.AcknowledgementRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; /** @@ -28,7 +28,7 @@ public class AcknowledgementFragment extends Fragment { @BindView(R.id.recycler_view_acknowledgement_fragment) RecyclerView recyclerView; - private Activity activity; + private BaseActivity activity; public AcknowledgementFragment() { // Required empty public constructor @@ -133,6 +133,6 @@ public class AcknowledgementFragment extends Fragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (Activity) context; + activity = (BaseActivity) context; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java index 2b826d4f..5bc9fd91 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AdvancedPreferenceFragment.java @@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.settings; import static android.app.Activity.RESULT_OK; import static android.content.Intent.ACTION_OPEN_DOCUMENT_TREE; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -14,10 +13,8 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; import com.google.android.material.dialog.MaterialAlertDialogBuilder; @@ -31,6 +28,7 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.activities.SettingsActivity; import ml.docilealligator.infinityforreddit.asynctasks.BackupSettings; import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllPostLayouts; import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllReadPosts; @@ -39,13 +37,14 @@ import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllSubreddits; import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllThemes; import ml.docilealligator.infinityforreddit.asynctasks.DeleteAllUsers; import ml.docilealligator.infinityforreddit.asynctasks.RestoreSettings; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; /** * A simple {@link Fragment} subclass. */ -public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { +public class AdvancedPreferenceFragment extends CustomFontPreferenceFragmentCompat { private static final int SELECT_BACKUP_SETTINGS_DIRECTORY_REQUEST_CODE = 1; private static final int SELECT_RESTORE_SETTINGS_DIRECTORY_REQUEST_CODE = 2; @@ -86,7 +85,6 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { SharedPreferences postHistorySharedPreferences; @Inject Executor executor; - private Activity activity; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { @@ -94,6 +92,10 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { ((Infinity) activity.getApplication()).getAppComponent().inject(this); + if (activity.typeface != null) { + setFont(activity.typeface); + } + Preference deleteSubredditsPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_SUBREDDITS_DATA_IN_DATABASE); Preference deleteUsersPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_USERS_DATA_IN_DATABASE); Preference deleteSortTypePreference = findPreference(SharedPreferencesUtils.DELETE_ALL_SORT_TYPE_DATA_IN_DATABASE); @@ -340,10 +342,4 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat { } } } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - activity = (AppCompatActivity) context; - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CommentPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CommentPreferenceFragment.java index a5d41885..336d7c62 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CommentPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CommentPreferenceFragment.java @@ -2,14 +2,17 @@ package ml.docilealligator.infinityforreddit.settings; import android.os.Bundle; -import androidx.preference.PreferenceFragmentCompat; - import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; -public class CommentPreferenceFragment extends PreferenceFragmentCompat { +public class CommentPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.comment_preferences, rootKey); + + if (activity.typeface != null) { + setFont(activity.typeface); + } } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java index 6cb67a5f..f49113fc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.settings; import android.annotation.SuppressLint; -import android.app.Activity; import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -25,14 +24,16 @@ import javax.inject.Inject; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.SettingsActivity; import ml.docilealligator.infinityforreddit.adapters.CrashReportsRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.utils.Utils; public class CrashReportsFragment extends Fragment { @Inject CustomThemeWrapper mCustomThemeWrapper; - private Activity activity; + private SettingsActivity activity; public CrashReportsFragment() { // Required empty public constructor @@ -48,7 +49,7 @@ public class CrashReportsFragment extends Fragment { setHasOptionsMenu(true); - recyclerView.setAdapter(new CrashReportsRecyclerViewAdapter(CrashyReporter.INSTANCE.getLogsAsStrings())); + recyclerView.setAdapter(new CrashReportsRecyclerViewAdapter(activity, CrashyReporter.INSTANCE.getLogsAsStrings())); return recyclerView; } @@ -82,6 +83,7 @@ public class CrashReportsFragment extends Fragment { item.setIcon(drawable); } } + Utils.setTitleWithCustomFontToMenuItem(activity.typeface, item, null); } } return true; @@ -90,6 +92,6 @@ public class CrashReportsFragment extends Fragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (Activity) context; + activity = (SettingsActivity) context; } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CreditsPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CreditsPreferenceFragment.java index 5ae530f2..81e11eea 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CreditsPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CreditsPreferenceFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.settings; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -11,21 +10,25 @@ import androidx.annotation.NonNull; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; -import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; +import ml.docilealligator.infinityforreddit.activities.SettingsActivity; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; /** * A simple {@link PreferenceFragmentCompat} subclass. */ -public class CreditsPreferenceFragment extends PreferenceFragmentCompat { - - private Activity activity; +public class CreditsPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.credits_preferences, rootKey); + if (activity.typeface != null) { + setFont(activity.typeface); + } + Preference iconForegroundPreference = findPreference(SharedPreferencesUtils.ICON_FOREGROUND_KEY); Preference iconBackgroundPreference = findPreference(SharedPreferencesUtils.ICON_BACKGROUND_KEY); Preference errorImagePreference = findPreference(SharedPreferencesUtils.ERROR_IMAGE_KEY); @@ -147,10 +150,4 @@ public class CreditsPreferenceFragment extends PreferenceFragmentCompat { }); } } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - activity = (Activity) context; - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeBottomAppBarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeBottomAppBarFragment.java index 2736bcb6..4a295880 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeBottomAppBarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeBottomAppBarFragment.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.settings; -import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; @@ -26,7 +25,9 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; public class CustomizeBottomAppBarFragment extends Fragment { @@ -92,7 +93,7 @@ public class CustomizeBottomAppBarFragment extends Fragment { @Inject @Named("bottom_app_bar") SharedPreferences sharedPreferences; - private Activity activity; + private BaseActivity activity; private int mainActivityOptionCount; private int mainActivityOption1; private int mainActivityOption2; @@ -120,6 +121,10 @@ public class CustomizeBottomAppBarFragment extends Fragment { ButterKnife.bind(this, rootView); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); Resources resources = activity.getResources(); @@ -357,6 +362,6 @@ public class CustomizeBottomAppBarFragment extends Fragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (Activity) context; + activity = (BaseActivity) context; } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java index 44f45eef..d593c6ba 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java @@ -29,11 +29,13 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.MultiredditSelectionActivity; import ml.docilealligator.infinityforreddit.activities.SearchActivity; import ml.docilealligator.infinityforreddit.activities.SubredditSelectionActivity; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; public class CustomizeMainPageTabsFragment extends Fragment { @@ -134,7 +136,7 @@ public class CustomizeMainPageTabsFragment extends Fragment { @Inject @Named("main_activity_tabs") SharedPreferences mainActivityTabsSharedPreferences; - private Activity activity; + private BaseActivity activity; private String accountName; private int tabCount; private String tab1CurrentTitle; @@ -161,6 +163,10 @@ public class CustomizeMainPageTabsFragment extends Fragment { ButterKnife.bind(this, rootView); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); String[] typeValues; @@ -707,6 +713,6 @@ public class CustomizeMainPageTabsFragment extends Fragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (Activity) context; + activity = (BaseActivity) context; } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java index 045f356b..00afbfb3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java @@ -1,25 +1,32 @@ package ml.docilealligator.infinityforreddit.settings; +import android.content.Context; import android.os.Bundle; +import androidx.annotation.NonNull; import androidx.preference.ListPreference; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.SettingsActivity; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.events.ChangeDataSavingModeEvent; import ml.docilealligator.infinityforreddit.events.ChangeDisableImagePreviewEvent; import ml.docilealligator.infinityforreddit.events.ChangeOnlyDisablePreviewInVideoAndGifPostsEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat { +public class DataSavingModePreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.data_saving_mode_preferences, rootKey); + if (activity.typeface != null) { + setFont(activity.typeface); + } + ListPreference dataSavingModeListPreference = findPreference(SharedPreferencesUtils.DATA_SAVING_MODE); SwitchPreference disableImagePreviewPreference = findPreference(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW); SwitchPreference onlyDisablePreviewInVideoAndGifPostsPreference = findPreference(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DownloadLocationPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DownloadLocationPreferenceFragment.java index 6bfb459e..e28f721c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DownloadLocationPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DownloadLocationPreferenceFragment.java @@ -11,16 +11,17 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; import javax.inject.Inject; import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.SettingsActivity; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class DownloadLocationPreferenceFragment extends PreferenceFragmentCompat { +public class DownloadLocationPreferenceFragment extends CustomFontPreferenceFragmentCompat { private static final int IMAGE_DOWNLOAD_LOCATION_REQUEST_CODE = 10; private static final int GIF_DOWNLOAD_LOCATION_REQUEST_CODE = 11; private static final int VIDEO_DOWNLOAD_LOCATION_REQUEST_CODE = 12; @@ -30,7 +31,6 @@ public class DownloadLocationPreferenceFragment extends PreferenceFragmentCompat Preference gifDownloadLocationPreference; Preference videoDownloadLocationPreference; Preference nsfwDownloadLocationPreference; - private Activity activity; @Inject @Named("default") SharedPreferences sharedPreferences; @@ -39,6 +39,11 @@ public class DownloadLocationPreferenceFragment extends PreferenceFragmentCompat public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { ((Infinity) activity.getApplication()).getAppComponent().inject(this); setPreferencesFromResource(R.xml.download_location_preferences, rootKey); + + if (activity.typeface != null) { + setFont(activity.typeface); + } + imageDownloadLocationPreference = findPreference(SharedPreferencesUtils.IMAGE_DOWNLOAD_LOCATION); gifDownloadLocationPreference = findPreference(SharedPreferencesUtils.GIF_DOWNLOAD_LOCATION); videoDownloadLocationPreference = findPreference(SharedPreferencesUtils.VIDEO_DOWNLOAD_LOCATION); @@ -131,10 +136,4 @@ public class DownloadLocationPreferenceFragment extends PreferenceFragmentCompat } } } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - activity = (Activity) context; - } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/FontPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/FontPreferenceFragment.java index 0d43e619..5ebae9d9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/FontPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/FontPreferenceFragment.java @@ -1,26 +1,27 @@ package ml.docilealligator.infinityforreddit.settings; -import android.app.Activity; -import android.content.Context; import android.os.Bundle; -import androidx.annotation.NonNull; import androidx.core.app.ActivityCompat; import androidx.preference.ListPreference; -import androidx.preference.PreferenceFragmentCompat; import org.greenrobot.eventbus.EventBus; -import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; +import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class FontPreferenceFragment extends PreferenceFragmentCompat { - private Activity activity; +public class FontPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.font_preferences, rootKey); + + if (activity.typeface != null) { + setFont(activity.typeface); + } + ListPreference fontFamilyPreference = findPreference(SharedPreferencesUtils.FONT_FAMILY_KEY); ListPreference titleFontFamilyPreference = findPreference(SharedPreferencesUtils.TITLE_FONT_FAMILY_KEY); ListPreference contentFontFamilyPreference = findPreference(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY); @@ -72,10 +73,4 @@ public class FontPreferenceFragment extends PreferenceFragmentCompat { }); } } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - activity = (Activity) context; - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/FontPreviewFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/FontPreviewFragment.java index ef4b96eb..c059c737 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/FontPreviewFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/FontPreviewFragment.java @@ -9,11 +9,6 @@ import androidx.fragment.app.Fragment; import ml.docilealligator.infinityforreddit.R; -/** - * A simple {@link Fragment} subclass. - * Use the {@link FontPreviewFragment#newInstance} factory method to - * create an instance of this fragment. - */ public class FontPreviewFragment extends Fragment { public FontPreviewFragment() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/GesturesAndButtonsPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/GesturesAndButtonsPreferenceFragment.java index 882455ef..e32022c4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/GesturesAndButtonsPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/GesturesAndButtonsPreferenceFragment.java @@ -1,15 +1,11 @@ package ml.docilealligator.infinityforreddit.settings; -import android.app.Activity; -import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; -import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; @@ -17,27 +13,31 @@ import org.greenrobot.eventbus.EventBus; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.events.ChangeLockBottomAppBarEvent; -import ml.docilealligator.infinityforreddit.fragments.ChangePullToRefreshEvent; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; +import ml.docilealligator.infinityforreddit.events.ChangeLockBottomAppBarEvent; +import ml.docilealligator.infinityforreddit.events.ChangePullToRefreshEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; /** * A simple {@link Fragment} subclass. */ -public class GesturesAndButtonsPreferenceFragment extends PreferenceFragmentCompat { +public class GesturesAndButtonsPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Inject @Named("default") SharedPreferences sharedPreferences; - private Activity activity; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.gestures_and_buttons_preferences, rootKey); ((Infinity) activity.getApplication()).getAppComponent().inject(this); + if (activity.typeface != null) { + setFont(activity.typeface); + } + SwitchPreference lockJumpToNextTopLevelCommentButtonSwitch = findPreference(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON); SwitchPreference lockBottomAppBarSwitch = findPreference(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR); @@ -79,10 +79,4 @@ public class GesturesAndButtonsPreferenceFragment extends PreferenceFragmentComp }); } } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - activity = (Activity) context; - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ImmersiveInterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ImmersiveInterfacePreferenceFragment.java index 73d5d305..c737e82a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ImmersiveInterfacePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ImmersiveInterfacePreferenceFragment.java @@ -2,21 +2,25 @@ package ml.docilealligator.infinityforreddit.settings; import android.os.Bundle; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class ImmersiveInterfacePreferenceFragment extends PreferenceFragmentCompat { +public class ImmersiveInterfacePreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.immersive_interface_preferences, rootKey); + if (activity.typeface != null) { + setFont(activity.typeface); + } + SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY); SwitchPreference immersiveInterfaceIgnoreNavBarSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY); SwitchPreference disableImmersiveInterfaceInLandscapeModeSwitch = findPreference(SharedPreferencesUtils.DISABLE_IMMERSIVE_INTERFACE_IN_LANDSCAPE_MODE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/InterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/InterfacePreferenceFragment.java index 2ef43ebf..0ad71c45 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/InterfacePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/InterfacePreferenceFragment.java @@ -5,22 +5,25 @@ import android.os.Build; import android.os.Bundle; import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.events.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class InterfacePreferenceFragment extends PreferenceFragmentCompat { - +public class InterfacePreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.interface_preferences, rootKey); + if (activity.typeface != null) { + setFont(activity.typeface); + } + Preference immersiveInterfaceEntryPreference = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_ENTRY_KEY); SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY); SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MainPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MainPreferenceFragment.java index 92a53a90..272af42f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MainPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MainPreferenceFragment.java @@ -1,16 +1,15 @@ package ml.docilealligator.infinityforreddit.settings; -import android.content.Context; +import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG; +import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL; + import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.biometric.BiometricManager; import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; import javax.inject.Inject; import javax.inject.Named; @@ -18,23 +17,24 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.PostFilterPreferenceActivity; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG; -import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL; - -public class MainPreferenceFragment extends PreferenceFragmentCompat { +public class MainPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Inject @Named("default") SharedPreferences sharedPreferences; - private AppCompatActivity activity; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.main_preferences, rootKey); ((Infinity) activity.getApplication()).getAppComponent().inject(this); + if (activity.typeface != null) { + setFont(activity.typeface); + } + Preference securityPreference = findPreference(SharedPreferencesUtils.SECURITY); Preference postFilterPreference = findPreference(SharedPreferencesUtils.POST_FILTER); @@ -53,10 +53,4 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { }); } } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - activity = (AppCompatActivity) context; - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java index b98f37e5..0c9d5fa7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MiscellaneousPreferenceFragment.java @@ -1,14 +1,9 @@ package ml.docilealligator.infinityforreddit.settings; -import android.app.Activity; -import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.preference.ListPreference; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; @@ -18,16 +13,16 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.events.ChangeSavePostFeedScrolledPositionEvent; import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class MiscellaneousPreferenceFragment extends PreferenceFragmentCompat { +public class MiscellaneousPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Inject @Named("post_feed_scrolled_position_cache") SharedPreferences cache; - private Activity activity; public MiscellaneousPreferenceFragment() { // Required empty public constructor @@ -39,6 +34,10 @@ public class MiscellaneousPreferenceFragment extends PreferenceFragmentCompat { ((Infinity) activity.getApplication()).getAppComponent().inject(this); + if (activity.typeface != null) { + setFont(activity.typeface); + } + ListPreference mainPageBackButtonActionListPreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_BACK_BUTTON_ACTION); SwitchPreference savePostFeedScrolledPositionSwitch = findPreference(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION); ListPreference languageListPreference = findPreference(SharedPreferencesUtils.LANGUAGE); @@ -67,10 +66,4 @@ public class MiscellaneousPreferenceFragment extends PreferenceFragmentCompat { }); } } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - activity = (AppCompatActivity) context; - } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NavigationDrawerPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NavigationDrawerPreferenceFragment.java index 6b6d7c04..36ebd09b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NavigationDrawerPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NavigationDrawerPreferenceFragment.java @@ -2,17 +2,17 @@ package ml.docilealligator.infinityforreddit.settings; import android.os.Bundle; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceManager; import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.events.ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class NavigationDrawerPreferenceFragment extends PreferenceFragmentCompat { +public class NavigationDrawerPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { @@ -20,6 +20,10 @@ public class NavigationDrawerPreferenceFragment extends PreferenceFragmentCompat preferenceManager.setSharedPreferencesName(SharedPreferencesUtils.NAVIGATION_DRAWER_SHARED_PREFERENCES_FILE); setPreferencesFromResource(R.xml.navigation_drawer_preferences, rootKey); + if (activity.typeface != null) { + setFont(activity.typeface); + } + SwitchPreference showAvatarOnTheRightSwitch = findPreference(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT); if (showAvatarOnTheRightSwitch != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NotificationPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NotificationPreferenceFragment.java index cf014c49..6f4c5313 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NotificationPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NotificationPreferenceFragment.java @@ -1,15 +1,11 @@ package ml.docilealligator.infinityforreddit.settings; -import android.app.Activity; -import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; -import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.preference.ListPreference; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; import androidx.work.Constraints; import androidx.work.ExistingPeriodicWorkPolicy; @@ -25,12 +21,13 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.PullNotificationWorker; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; /** * A simple {@link Fragment} subclass. */ -public class NotificationPreferenceFragment extends PreferenceFragmentCompat { +public class NotificationPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Inject @Named("default") @@ -38,11 +35,14 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat { private boolean enableNotification; private long notificationInterval; private WorkManager workManager; - private Activity activity; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.notification_preferences, rootKey); + + if (activity.typeface != null) { + setFont(activity.typeface); + } workManager = WorkManager.getInstance(activity); @@ -118,10 +118,4 @@ public class NotificationPreferenceFragment extends PreferenceFragmentCompat { }); } } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - activity = (Activity) context; - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NsfwAndSpoilerFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NsfwAndSpoilerFragment.java index 2f24d336..10b81408 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NsfwAndSpoilerFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NsfwAndSpoilerFragment.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.settings; -import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; @@ -11,7 +10,6 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; @@ -27,10 +25,12 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.events.ChangeSpoilerBlurEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; public class NsfwAndSpoilerFragment extends Fragment { @@ -65,7 +65,7 @@ public class NsfwAndSpoilerFragment extends Fragment { @Named("nsfw_and_spoiler") SharedPreferences nsfwAndBlurringSharedPreferences; - private Activity activity; + private BaseActivity activity; private boolean blurNsfw; private boolean doNotBlurNsfwInNsfwSubreddits; private boolean disableNsfwForever; @@ -85,6 +85,10 @@ public class NsfwAndSpoilerFragment extends Fragment { ButterKnife.bind(this, rootView); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); boolean enableNsfw = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); @@ -180,6 +184,6 @@ public class NsfwAndSpoilerFragment extends Fragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - this.activity = (AppCompatActivity) context; + this.activity = (BaseActivity) context; } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NumberOfColumnsInPostFeedPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NumberOfColumnsInPostFeedPreferenceFragment.java index dfb991dd..2ebb31a1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NumberOfColumnsInPostFeedPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NumberOfColumnsInPostFeedPreferenceFragment.java @@ -2,13 +2,16 @@ package ml.docilealligator.infinityforreddit.settings; import android.os.Bundle; -import androidx.preference.PreferenceFragmentCompat; - import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; -public class NumberOfColumnsInPostFeedPreferenceFragment extends PreferenceFragmentCompat { +public class NumberOfColumnsInPostFeedPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.number_of_columns_in_post_feed_preferences, rootKey); + + if (activity.typeface != null) { + setFont(activity.typeface); + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostDetailsPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostDetailsPreferenceFragment.java index 2e0db830..224fffd5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostDetailsPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostDetailsPreferenceFragment.java @@ -2,17 +2,21 @@ package ml.docilealligator.infinityforreddit.settings; import android.os.Bundle; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceManager; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class PostDetailsPreferenceFragment extends PreferenceFragmentCompat { +public class PostDetailsPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { PreferenceManager preferenceManager = getPreferenceManager(); preferenceManager.setSharedPreferencesName(SharedPreferencesUtils.POST_DETAILS_SHARED_PREFERENCES_FILE); setPreferencesFromResource(R.xml.post_details_preferences, rootKey); + + if (activity.typeface != null) { + setFont(activity.typeface); + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java index 647e03af..878ead80 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.settings; -import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; @@ -11,7 +10,6 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import com.google.android.material.switchmaterial.SwitchMaterial; @@ -23,7 +21,9 @@ import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; public class PostHistoryFragment extends Fragment { @@ -50,7 +50,7 @@ public class PostHistoryFragment extends Fragment { @Inject @Named("post_history") SharedPreferences postHistorySharedPreferences; - private Activity activity; + private BaseActivity activity; public PostHistoryFragment() { // Required empty public constructor @@ -66,6 +66,10 @@ public class PostHistoryFragment extends Fragment { ButterKnife.bind(this, rootView); + if (activity.typeface != null) { + Utils.setFontToAllTextViews(rootView, activity.typeface); + } + String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); if (accountName == null) { infoTextView.setText(R.string.only_for_logged_in_user); @@ -111,6 +115,6 @@ public class PostHistoryFragment extends Fragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - this.activity = (AppCompatActivity) context; + this.activity = (BaseActivity) context; } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java index 5b508a96..a93bc592 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java @@ -4,12 +4,12 @@ import android.os.Bundle; import androidx.preference.ListPreference; import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.events.ChangeCompactLayoutToolbarHiddenByDefaultEvent; import ml.docilealligator.infinityforreddit.events.ChangeDefaultLinkPostLayoutEvent; import ml.docilealligator.infinityforreddit.events.ChangeDefaultPostLayoutEvent; @@ -25,11 +25,15 @@ import ml.docilealligator.infinityforreddit.events.ShowDividerInCompactLayoutPre import ml.docilealligator.infinityforreddit.events.ShowThumbnailOnTheRightInCompactLayoutEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class PostPreferenceFragment extends PreferenceFragmentCompat { +public class PostPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.post_preferences, rootKey); + + if (activity.typeface != null) { + setFont(activity.typeface); + } ListPreference defaultPostLayoutList = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY); ListPreference defaultLinkPostLayoutList = findPreference(SharedPreferencesUtils.DEFAULT_LINK_POST_LAYOUT_KEY); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java index 83163020..7bac9841 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java @@ -3,16 +3,13 @@ package ml.docilealligator.infinityforreddit.settings; import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG; import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL; -import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.biometric.BiometricPrompt; import androidx.core.content.ContextCompat; import androidx.preference.ListPreference; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceManager; import androidx.preference.SwitchPreference; @@ -25,14 +22,14 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.events.ChangeAppLockEvent; import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent; import ml.docilealligator.infinityforreddit.events.ToggleSecureModeEvent; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class SecurityPreferenceFragment extends PreferenceFragmentCompat { +public class SecurityPreferenceFragment extends CustomFontPreferenceFragmentCompat { - private AppCompatActivity activity; @Inject @Named("default") SharedPreferences sharedPreferences; @@ -45,6 +42,10 @@ public class SecurityPreferenceFragment extends PreferenceFragmentCompat { ((Infinity) activity.getApplication()).getAppComponent().inject(this); + if (activity.typeface != null) { + setFont(activity.typeface); + } + SwitchPreference requireAuthToAccountSectionSwitch = findPreference(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER); SwitchPreference secureModeSwitch = findPreference(SharedPreferencesUtils.SECURE_MODE); SwitchPreference appLockSwitch = findPreference(SharedPreferencesUtils.APP_LOCK); @@ -96,10 +97,4 @@ public class SecurityPreferenceFragment extends PreferenceFragmentCompat { biometricPrompt.authenticate(promptInfo); } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - this.activity = (AppCompatActivity) context; - } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SortTypePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SortTypePreferenceFragment.java index 78d32b46..dbb3f615 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SortTypePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SortTypePreferenceFragment.java @@ -2,14 +2,17 @@ package ml.docilealligator.infinityforreddit.settings; import android.os.Bundle; -import androidx.preference.PreferenceFragmentCompat; - import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; -public class SortTypePreferenceFragment extends PreferenceFragmentCompat { +public class SortTypePreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.sort_type_preferences, rootKey); + + if (activity.typeface != null) { + setFont(activity.typeface); + } } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SwipeActionPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SwipeActionPreferenceFragment.java index de7860b5..a7d03631 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SwipeActionPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SwipeActionPreferenceFragment.java @@ -3,25 +3,29 @@ package ml.docilealligator.infinityforreddit.settings; import android.os.Bundle; import androidx.preference.ListPreference; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.events.ChangeDisableSwipingBetweenTabsEvent; import ml.docilealligator.infinityforreddit.events.ChangeEnableSwipeActionSwitchEvent; import ml.docilealligator.infinityforreddit.events.ChangeSwipeActionEvent; import ml.docilealligator.infinityforreddit.events.ChangeSwipeActionThresholdEvent; import ml.docilealligator.infinityforreddit.events.ChangeVibrateWhenActionTriggeredEvent; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class SwipeActionPreferenceFragment extends PreferenceFragmentCompat { +public class SwipeActionPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.swipe_action_preferences, rootKey); + if (activity.typeface != null) { + setFont(activity.typeface); + } + SwitchPreference enableSwipeActionSwitch = findPreference(SharedPreferencesUtils.ENABLE_SWIPE_ACTION); ListPreference swipeLeftActionListPreference = findPreference(SharedPreferencesUtils.SWIPE_LEFT_ACTION); ListPreference swipeRightActionListPreference = findPreference(SharedPreferencesUtils.SWIPE_RIGHT_ACTION); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java index 0f613cc0..cb0c759b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java @@ -5,7 +5,6 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; -import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; @@ -13,15 +12,12 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatDelegate; import androidx.core.app.ActivityCompat; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; import androidx.preference.ListPreference; import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; @@ -38,6 +34,7 @@ import ml.docilealligator.infinityforreddit.activities.CustomThemeListingActivit import ml.docilealligator.infinityforreddit.activities.CustomizeThemeActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeViewModel; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.MaterialYouUtils; @@ -46,9 +43,8 @@ import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; /** * A simple {@link Fragment} subclass. */ -public class ThemePreferenceFragment extends PreferenceFragmentCompat { +public class ThemePreferenceFragment extends CustomFontPreferenceFragmentCompat { - private AppCompatActivity activity; @Inject @Named("default") SharedPreferences sharedPreferences; @@ -75,6 +71,10 @@ public class ThemePreferenceFragment extends PreferenceFragmentCompat { ((Infinity) activity.getApplication()).getAppComponent().inject(this); + if (activity.typeface != null) { + setFont(activity.typeface); + } + ListPreference themePreference = findPreference(SharedPreferencesUtils.THEME_KEY); SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY); Preference customizeLightThemePreference = findPreference(SharedPreferencesUtils.CUSTOMIZE_LIGHT_THEME); @@ -233,10 +233,4 @@ public class ThemePreferenceFragment extends PreferenceFragmentCompat { } }); } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - activity = (AppCompatActivity) context; - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/TimeFormatPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/TimeFormatPreferenceFragment.java index 42ced176..21e190aa 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/TimeFormatPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/TimeFormatPreferenceFragment.java @@ -3,21 +3,25 @@ package ml.docilealligator.infinityforreddit.settings; import android.os.Bundle; import androidx.preference.ListPreference; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.events.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.events.ChangeTimeFormatEvent; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class TimeFormatPreferenceFragment extends PreferenceFragmentCompat { +public class TimeFormatPreferenceFragment extends CustomFontPreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.time_format_preferences, rootKey); + if (activity.typeface != null) { + setFont(activity.typeface); + } + SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY); ListPreference timeFormatList = findPreference(SharedPreferencesUtils.TIME_FORMAT_KEY); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/TranslationFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/TranslationFragment.java index 62f5c50a..576a6af1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/TranslationFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/TranslationFragment.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.settings; -import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; @@ -15,10 +14,11 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.adapters.TranslationFragmentRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; +import ml.docilealligator.infinityforreddit.adapters.TranslationFragmentRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; public class TranslationFragment extends Fragment { @@ -26,7 +26,7 @@ public class TranslationFragment extends Fragment { RecyclerView recyclerView; @Inject CustomThemeWrapper customThemeWrapper; - private Activity activity; + private BaseActivity activity; public TranslationFragment() { // Required empty public constructor @@ -51,6 +51,6 @@ public class TranslationFragment extends Fragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (Activity) context; + activity = (BaseActivity) context; } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java index 6a89dcd6..2eb3f6e7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java @@ -1,16 +1,11 @@ package ml.docilealligator.infinityforreddit.settings; -import android.app.Activity; -import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import androidx.preference.ListPreference; import androidx.preference.Preference; -import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SeekBarPreference; import androidx.preference.SwitchPreference; @@ -19,19 +14,19 @@ import org.greenrobot.eventbus.EventBus; import javax.inject.Inject; import javax.inject.Named; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.events.ChangeAutoplayNsfwVideosEvent; import ml.docilealligator.infinityforreddit.events.ChangeMuteAutoplayingVideosEvent; import ml.docilealligator.infinityforreddit.events.ChangeMuteNSFWVideoEvent; import ml.docilealligator.infinityforreddit.events.ChangeRememberMutingOptionInPostFeedEvent; import ml.docilealligator.infinityforreddit.events.ChangeStartAutoplayVisibleAreaOffsetEvent; import ml.docilealligator.infinityforreddit.events.ChangeVideoAutoplayEvent; -import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -public class VideoPreferenceFragment extends PreferenceFragmentCompat { +public class VideoPreferenceFragment extends CustomFontPreferenceFragmentCompat { - private Activity activity; @Inject @Named("default") SharedPreferences sharedPreferences; @@ -42,6 +37,10 @@ public class VideoPreferenceFragment extends PreferenceFragmentCompat { ((Infinity) activity.getApplication()).getAppComponent().inject(this); + if (activity.typeface != null) { + setFont(activity.typeface); + } + ListPreference videoAutoplayListPreference = findPreference(SharedPreferencesUtils.VIDEO_AUTOPLAY); SwitchPreference muteAutoplayingVideosSwitchPreference = findPreference(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS); SwitchPreference rememberMutingOptionInPostFeedSwitchPreference = findPreference(SharedPreferencesUtils.REMEMBER_MUTING_OPTION_IN_POST_FEED); @@ -113,10 +112,4 @@ public class VideoPreferenceFragment extends PreferenceFragmentCompat { }); } } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - this.activity = (AppCompatActivity) context; - } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/ParseUserData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/ParseUserData.java index c77d0985..c04b8957 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/user/ParseUserData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/ParseUserData.java @@ -148,7 +148,12 @@ public class ParseUserData { after = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY); JSONArray children = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY); for (int i = 0; i < children.length(); i++) { - userDataArrayList.add(parseUserDataBase(children.getJSONObject(i), false)); + try { + UserData userData = parseUserDataBase(children.getJSONObject(i), false); + userDataArrayList.add(userData); + } catch (JSONException e) { + e.printStackTrace(); + } } } } catch (JSONException e) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index 5107c124..cc019ac4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -5,6 +5,7 @@ import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.net.Network; @@ -15,7 +16,12 @@ import android.os.Build; import android.os.Handler; import android.provider.OpenableColumns; import android.text.Spannable; +import android.text.SpannableStringBuilder; +import android.text.style.TypefaceSpan; import android.util.DisplayMetrics; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.TextView; @@ -30,6 +36,8 @@ import androidx.core.text.HtmlCompat; import com.bumptech.glide.Glide; import com.google.android.material.snackbar.Snackbar; +import com.google.android.material.tabs.TabLayout; +import com.google.android.material.textfield.TextInputLayout; import org.json.JSONArray; import org.json.JSONException; @@ -46,6 +54,7 @@ import java.util.concurrent.Executor; import java.util.regex.Matcher; import java.util.regex.Pattern; +import io.noties.markwon.core.spans.CustomTypefaceSpan; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.UploadedImage; @@ -465,4 +474,53 @@ public final class Utils { return null; } + + public static void setTitleWithCustomFontToMenuItem(Typeface typeface, MenuItem item, String desiredTitle) { + if (typeface != null) { + CharSequence title = desiredTitle == null ? item.getTitle() : desiredTitle; + if (title != null) { + SpannableStringBuilder spannableTitle = new SpannableStringBuilder(title); + spannableTitle.setSpan(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? new TypefaceSpan(typeface) : new CustomTypefaceSpan(typeface), 0, spannableTitle.length(), 0); + item.setTitle(spannableTitle); + } + } else if (desiredTitle != null) { + item.setTitle(desiredTitle); + } + } + + public static void setTitleWithCustomFontToTab(Typeface typeface, TabLayout.Tab tab, String title) { + if (typeface != null) { + if (title != null) { + SpannableStringBuilder spannableTitle = new SpannableStringBuilder(title); + spannableTitle.setSpan(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? new TypefaceSpan(typeface) : new CustomTypefaceSpan(typeface), 0, spannableTitle.length(), 0); + tab.setText(spannableTitle); + } + } else { + tab.setText(title); + } + } + + public static CharSequence getTabTextWithCustomFont(Typeface typeface, CharSequence title) { + if (typeface != null && title != null) { + SpannableStringBuilder spannableTitle = new SpannableStringBuilder(title); + spannableTitle.setSpan(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? new TypefaceSpan(typeface) : new CustomTypefaceSpan(typeface), 0, spannableTitle.length(), 0); + return spannableTitle; + } else { + return title; + } + } + + public static void setFontToAllTextViews(View rootView, Typeface typeface) { + if (rootView instanceof TextInputLayout) { + ((TextInputLayout) rootView).setTypeface(typeface); + } else if (rootView instanceof ViewGroup) { + ViewGroup rootViewGroup = ((ViewGroup) rootView); + int childViewCount = rootViewGroup.getChildCount(); + for (int i = 0; i < childViewCount; i++) { + setFontToAllTextViews(rootViewGroup.getChildAt(i), typeface); + } + } else if (rootView instanceof TextView) { + ((TextView) rootView).setTypeface(typeface); + } + } } |