mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-27 19:38:22 +01:00
Start adding custom font support.
This commit is contained in:
parent
b11a568169
commit
e0c849e135
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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 PagingDataAdapter<Post, RecyclerVie
|
||||
} else {
|
||||
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 (((BaseActivity) mActivity).titleTypeface != null) {
|
||||
titleTextView.setTypeface(((BaseActivity) mActivity).titleTypeface);
|
||||
}
|
||||
if (((BaseActivity) mActivity).contentTypeface != null) {
|
||||
|
||||
}
|
||||
|
||||
subredditTextView.setTextColor(mSubredditColor);
|
||||
userTextView.setTextColor(mUsernameColor);
|
||||
postTimeTextView.setTextColor(mSecondaryTextColor);
|
||||
|
@ -1235,14 +1235,14 @@
|
||||
<string name="about_you_text">About You</string>
|
||||
<string name="about_you_hint">A little description of yourself</string>
|
||||
<string name="message_remove_avatar_success">Remove avatar successfully</string>
|
||||
<string name="message_remove_avatar_failed_fmt">Failed to remove avatar %s</string>
|
||||
<string name="message_remove_avatar_failed">Failed to remove avatar %s</string>
|
||||
<string name="message_remove_banner_success">Remove banner successfully</string>
|
||||
<string name="message_remove_banner_failed_fmt">Failed to remove banner %s</string>
|
||||
<string name="message_remove_banner_failed">Failed to remove banner %s</string>
|
||||
<string name="message_change_avatar_success">Change avatar successfully</string>
|
||||
<string name="message_change_avatar_failed_fmt">Failed to change avatar %s</string>
|
||||
<string name="message_change_avatar_failed">Failed to change avatar %s</string>
|
||||
<string name="message_change_banner_success">Changing banner successfully</string>
|
||||
<string name="message_change_banner_failed_fmt">Failed to change banner %s</string>
|
||||
<string name="message_change_banner_failed">Failed to change banner %s</string>
|
||||
<string name="message_save_profile_success">Save profile successfully</string>
|
||||
<string name="message_save_profile_failed_fmt">Failed to save profile %s</string>
|
||||
<string name="message_save_profile_failed">Failed to save profile %s</string>
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user