diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java index 2b990071..78939b83 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java @@ -5,9 +5,11 @@ import android.app.Application; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.graphics.Typeface; import android.net.ConnectivityManager; import android.os.Bundle; import android.view.WindowManager; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -26,6 +28,7 @@ import org.greenrobot.eventbus.Subscribe; import javax.inject.Inject; import javax.inject.Named; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LockScreenActivity; import ml.docilealligator.infinityforreddit.broadcastreceivers.NetworkWifiStatusReceiver; import ml.docilealligator.infinityforreddit.broadcastreceivers.WallpaperChangeReceiver; @@ -42,6 +45,9 @@ public class Infinity extends Application implements LifecycleObserver { private long appLockTimeout; private boolean canStartLockScreenActivity = false; private boolean isSecureMode; + private Typeface typeface; + private Typeface titleTypeface; + private Typeface contentTypeface; @Inject @Named("default") SharedPreferences mSharedPreferences; @@ -63,7 +69,23 @@ public class Infinity extends Application implements LifecycleObserver { appLockTimeout = Long.parseLong(mSecuritySharedPreferences.getString(SharedPreferencesUtils.APP_LOCK_TIMEOUT, "600000")); isSecureMode = mSecuritySharedPreferences.getBoolean(SharedPreferencesUtils.SECURE_MODE, false); + try { + typeface = Typeface.createFromFile(getCacheDir() + "/opensans.ttf"); + titleTypeface = Typeface.createFromFile(getCacheDir() + "/opensans.ttf"); + contentTypeface = Typeface.createFromFile(getCacheDir() + "/opensans.ttf"); + } catch (RuntimeException e) { + e.printStackTrace(); + Toast.makeText(this, "Some font files do not exist", Toast.LENGTH_SHORT).show(); + } + registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { + @Override + public void onActivityPreCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { + if (activity instanceof BaseActivity) { + ((BaseActivity) activity).setCustomFont(typeface, titleTypeface, contentTypeface); + } + } + @Override public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) { if (isSecureMode) { 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 ad840efa..9890d538 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java @@ -11,6 +11,7 @@ import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Color; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; @@ -59,6 +60,9 @@ public abstract class BaseActivity extends AppCompatActivity { private int systemVisibilityToolbarExpanded = 0; private int systemVisibilityToolbarCollapsed = 0; private CustomThemeWrapper customThemeWrapper; + public Typeface typeface; + public Typeface titleTypeface; + public Typeface contentTypeface; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -367,4 +371,10 @@ public abstract class BaseActivity extends AppCompatActivity { } } catch (NoSuchFieldException | IllegalAccessException ignore) {} } + + public void setCustomFont(Typeface typeface, Typeface titleTypeface, Typeface contentTypeface) { + this.typeface = typeface; + this.titleTypeface = titleTypeface; + this.contentTypeface = contentTypeface; + } } \ No newline at end of file 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 d9248652..106b717a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java @@ -182,7 +182,7 @@ public class EditProfileActivity extends BaseActivity { @Override public void failed(String message) { Toast.makeText(EditProfileActivity.this, - getString(R.string.message_remove_banner_failed_fmt, message), + getString(R.string.message_remove_banner_failed, message), Toast.LENGTH_SHORT).show(); } })) @@ -224,7 +224,7 @@ public class EditProfileActivity extends BaseActivity { @Override public void failed(String message) { Toast.makeText(EditProfileActivity.this, - getString(R.string.message_remove_avatar_failed_fmt, message), + getString(R.string.message_remove_avatar_failed, message), Toast.LENGTH_SHORT).show(); } })) @@ -305,7 +305,7 @@ public class EditProfileActivity extends BaseActivity { if (event.isSuccess) { Toast.makeText(this, R.string.message_change_avatar_success, Toast.LENGTH_SHORT).show(); } else { - String message = getString(R.string.message_change_avatar_failed_fmt, event.errorMessage); + String message = getString(R.string.message_change_avatar_failed, event.errorMessage); Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); } } @@ -315,7 +315,7 @@ public class EditProfileActivity extends BaseActivity { if (event.isSuccess) { Toast.makeText(this, R.string.message_change_banner_success, Toast.LENGTH_SHORT).show(); } else { - String message = getString(R.string.message_change_banner_failed_fmt, event.errorMessage); + String message = getString(R.string.message_change_banner_failed, event.errorMessage); Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); } } @@ -325,7 +325,7 @@ public class EditProfileActivity extends BaseActivity { if (event.isSuccess) { Toast.makeText(this, R.string.message_save_profile_success, Toast.LENGTH_SHORT).show(); } else { - String message = getString(R.string.message_save_profile_failed_fmt, event.errorMessage); + String message = getString(R.string.message_save_profile_failed, event.errorMessage); Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); } } 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 11a9dc13..44c284b5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -25,6 +25,7 @@ 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; @@ -354,6 +355,12 @@ 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) { 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 f69b8378..e326c11d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -75,6 +75,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.FilteredPostsActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewImageOrGifActivity; @@ -2103,6 +2104,26 @@ public class PostRecyclerViewAdapter extends PagingDataAdapterAbout You A little description of yourself Remove avatar successfully - Failed to remove avatar %s + Failed to remove avatar %s Remove banner successfully - Failed to remove banner %s + Failed to remove banner %s Change avatar successfully - Failed to change avatar %s + Failed to change avatar %s Changing banner successfully - Failed to change banner %s + Failed to change banner %s Save profile successfully - Failed to save profile %s + Failed to save profile %s