change handling of font size, introduce font size setting
This commit is contained in:
parent
8f8d49f421
commit
bf4d0bb722
25 changed files with 208 additions and 83 deletions
|
@ -15,8 +15,6 @@
|
|||
|
||||
package com.keylesspalace.tusky;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -46,9 +44,7 @@ import okhttp3.logging.HttpLoggingInterceptor;
|
|||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
@SuppressLint("Registered")
|
||||
public class BaseActivity extends AppCompatActivity {
|
||||
protected static final int SERVICE_REQUEST_CODE = 8574603; // This number is arbitrary.
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
|
||||
public MastodonApi mastodonApi;
|
||||
protected Dispatcher mastodonApiDispatcher;
|
||||
|
@ -60,12 +56,30 @@ public class BaseActivity extends AppCompatActivity {
|
|||
redirectIfNotLoggedIn();
|
||||
createMastodonApi();
|
||||
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
/* There isn't presently a way to globally change the theme of a whole application at
|
||||
* runtime, just individual activities. So, each activity has to set its theme before any
|
||||
* views are created. */
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("lightTheme", false)) {
|
||||
if (preferences.getBoolean("lightTheme", false)) {
|
||||
setTheme(R.style.AppTheme_Light);
|
||||
}
|
||||
|
||||
int style;
|
||||
switch(preferences.getString("statusTextSize", "small")) {
|
||||
case "large":
|
||||
style = R.style.TextSizeLarge;
|
||||
break;
|
||||
case "medium":
|
||||
style = R.style.TextSizeMedium;
|
||||
break;
|
||||
case "small":
|
||||
default:
|
||||
style = R.style.TextSizeSmall;
|
||||
break;
|
||||
}
|
||||
getTheme().applyStyle(style, false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,7 +31,7 @@ import com.keylesspalace.tusky.fragment.PreferencesFragment;
|
|||
public class PreferencesActivity extends BaseActivity
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private boolean themeSwitched;
|
||||
private boolean restartActivitiesOnExit;
|
||||
private @XmlRes int currentPreferences;
|
||||
private @StringRes int currentTitle;
|
||||
|
||||
|
@ -39,10 +39,10 @@ public class PreferencesActivity extends BaseActivity
|
|||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
themeSwitched = savedInstanceState.getBoolean("themeSwitched");
|
||||
restartActivitiesOnExit = savedInstanceState.getBoolean("restart");
|
||||
} else {
|
||||
Bundle extras = getIntent().getExtras();
|
||||
themeSwitched = extras != null && extras.getBoolean("themeSwitched");
|
||||
restartActivitiesOnExit = extras != null && extras.getBoolean("restart");
|
||||
}
|
||||
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
@ -91,7 +91,7 @@ public class PreferencesActivity extends BaseActivity
|
|||
}
|
||||
|
||||
private void saveInstanceState(Bundle outState) {
|
||||
outState.putBoolean("themeSwitched", themeSwitched);
|
||||
outState.putBoolean("restart", restartActivitiesOnExit);
|
||||
outState.putInt("preferences", currentPreferences);
|
||||
outState.putInt("title", currentTitle);
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public class PreferencesActivity extends BaseActivity
|
|||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
switch (key) {
|
||||
case "lightTheme": {
|
||||
themeSwitched = true;
|
||||
restartActivitiesOnExit = true;
|
||||
// recreate() could be used instead, but it doesn't have an animation B).
|
||||
Intent intent = getIntent();
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
@ -117,6 +117,10 @@ public class PreferencesActivity extends BaseActivity
|
|||
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
|
||||
break;
|
||||
}
|
||||
case "statusTextSize": {
|
||||
restartActivitiesOnExit = true;
|
||||
break;
|
||||
}
|
||||
case "notificationsEnabled": {
|
||||
boolean enabled = sharedPreferences.getBoolean("notificationsEnabled", true);
|
||||
if (enabled) {
|
||||
|
@ -146,7 +150,7 @@ public class PreferencesActivity extends BaseActivity
|
|||
* Either the back stack activities need to all be recreated, or do the easier thing, which
|
||||
* is hijack the back button press and use it to launch a new MainActivity and clear the
|
||||
* back stack. */
|
||||
if (themeSwitched) {
|
||||
if (restartActivitiesOnExit) {
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue