From bf4d0bb722dfe83753104b4caf3206b75ac12ebd Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Fri, 1 Dec 2017 21:52:10 +0100 Subject: [PATCH] change handling of font size, introduce font size setting --- .../com/keylesspalace/tusky/BaseActivity.java | 26 +++++++++++---- .../tusky/PreferencesActivity.java | 16 ++++++---- .../res/drawable/compose_button_colors.xml | 26 ++++++++++----- app/src/main/res/layout/activity_account.xml | 10 +++++- app/src/main/res/layout/activity_compose.xml | 11 +++++-- app/src/main/res/layout/item_account.xml | 4 +-- app/src/main/res/layout/item_autocomplete.xml | 32 ++++++++----------- app/src/main/res/layout/item_blocked_user.xml | 4 +-- app/src/main/res/layout/item_follow.xml | 6 +++- .../main/res/layout/item_follow_request.xml | 4 +-- app/src/main/res/layout/item_footer.xml | 9 +++--- app/src/main/res/layout/item_hashtag.xml | 8 ++--- app/src/main/res/layout/item_muted_user.xml | 4 +-- .../main/res/layout/item_report_status.xml | 7 ++-- app/src/main/res/layout/item_saved_toot.xml | 3 +- app/src/main/res/layout/item_status.xml | 12 +++++-- .../main/res/layout/item_status_detailed.xml | 31 ++++++++++++------ .../res/layout/item_status_notification.xml | 9 +++++- .../res/layout/item_status_placeholder.xml | 3 +- app/src/main/res/values-de/strings.xml | 10 +++++- app/src/main/res/values/attrs.xml | 5 +++ app/src/main/res/values/donottranslate.xml | 8 ++++- app/src/main/res/values/strings.xml | 10 +++++- app/src/main/res/values/styles.xml | 25 ++++++++++++--- app/src/main/res/xml/preferences.xml | 8 +++++ 25 files changed, 208 insertions(+), 83 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java index 5d1c9196..cc9e29c2 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java @@ -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 diff --git a/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java b/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java index 80704422..4ff4590d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/PreferencesActivity.java @@ -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); diff --git a/app/src/main/res/drawable/compose_button_colors.xml b/app/src/main/res/drawable/compose_button_colors.xml index 195d0894..2487c7a3 100644 --- a/app/src/main/res/drawable/compose_button_colors.xml +++ b/app/src/main/res/drawable/compose_button_colors.xml @@ -2,21 +2,31 @@ + - - + + + + + - - + + + + diff --git a/app/src/main/res/layout/activity_account.xml b/app/src/main/res/layout/activity_account.xml index 1e111e4f..3b4d7c24 100644 --- a/app/src/main/res/layout/activity_account.xml +++ b/app/src/main/res/layout/activity_account.xml @@ -66,6 +66,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="6dp" + android:textSize="?attr/status_text_large" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -75,6 +76,7 @@ android:layout_height="wrap_content" android:layout_marginEnd="10dp" android:layout_marginRight="10dp" + android:textSize="?attr/status_text_medium" android:text="@string/follows_you" android:textColor="?android:textColorPrimary" app:layout_constraintEnd_toEndOf="@id/follow_btn" @@ -87,7 +89,7 @@ android:ellipsize="end" android:maxLines="1" android:textColor="?android:textColorPrimary" - android:textSize="18sp" + android:textSize="?attr/status_text_large" android:textStyle="normal|bold" app:layout_constraintTop_toBottomOf="@id/account_avatar" tools:text="Tusky Mastodon Client" /> @@ -98,6 +100,7 @@ android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="1" + android:textSize="?attr/status_text_medium" android:textColor="?android:textColorSecondary" app:layout_constraintTop_toBottomOf="@id/account_display_name" tools:text="\@Tusky" /> @@ -123,6 +126,7 @@ android:layout_below="@id/account_username" android:paddingBottom="16dp" android:paddingTop="10dp" + android:textSize="?attr/status_text_medium" android:textColor="?android:textColorTertiary" app:layout_constraintTop_toBottomOf="@id/account_username" tools:text="This is a test description" /> @@ -137,6 +141,7 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="0" app:layout_constraintStart_toStartOf="parent" + android:textSize="?attr/status_text_medium" app:layout_constraintTop_toBottomOf="@id/account_note" tools:text="3000 Followers" /> @@ -149,6 +154,7 @@ app:layout_constraintEnd_toStartOf="@id/statuses_btn" app:layout_constraintHorizontal_bias="0" app:layout_constraintStart_toEndOf="@id/followers_tv" + android:textSize="?attr/status_text_medium" app:layout_constraintTop_toTopOf="@id/followers_tv" tools:text="500 Following" /> @@ -158,6 +164,7 @@ android:layout_height="wrap_content" android:textColor="@color/account_tab_font_color" app:layout_constraintEnd_toEndOf="parent" + android:textSize="?attr/status_text_medium" app:layout_constraintHorizontal_bias="0" app:layout_constraintStart_toEndOf="@id/following_tv" app:layout_constraintTop_toTopOf="@id/followers_tv" @@ -194,6 +201,7 @@ android:background="?android:colorBackground" app:tabGravity="fill" app:tabMaxWidth="0dp" + app:tabTextAppearance="@style/TuskyTabAppearance" app:tabSelectedTextColor="?attr/colorAccent"> + android:textSize="?attr/status_text_large" />