From bee10bf37525626bff4db588070c43616e8a56bf Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sat, 12 Oct 2019 20:00:29 +0200 Subject: [PATCH] Refactor theming (#1529) * fix toolbars * use toolbar in MainActivity * update AccountActivity appbar * update material design library * remove unneeded tabs styling * fix black theme --- app/build.gradle | 2 +- .../keylesspalace/tusky/AccountActivity.kt | 42 +++++++----- .../com/keylesspalace/tusky/MainActivity.java | 7 +- .../com/keylesspalace/tusky/entity/Account.kt | 3 +- .../preference/AccountPreferencesFragment.kt | 6 +- .../preference/PreferencesFragment.kt | 10 +-- .../tusky/view/ComposeScheduleView.java | 3 +- app/src/main/res/color/tab_icon_color.xml | 5 -- .../res/drawable-night/avatar_background.xml | 6 -- .../main/res/drawable/avatar_background.xml | 6 -- app/src/main/res/drawable/ic_menu_24dp.xml | 10 --- app/src/main/res/layout/activity_account.xml | 13 ++-- app/src/main/res/layout/activity_main.xml | 65 ++++++++----------- app/src/main/res/layout/activity_search.xml | 6 +- app/src/main/res/layout/toolbar_basic.xml | 3 +- app/src/main/res/values-night/styles.xml | 3 +- app/src/main/res/values/attrs.xml | 3 +- app/src/main/res/values/colors.xml | 2 - app/src/main/res/values/dimens.xml | 2 + app/src/main/res/values/styles.xml | 11 ++-- 20 files changed, 86 insertions(+), 122 deletions(-) delete mode 100644 app/src/main/res/color/tab_icon_color.xml delete mode 100644 app/src/main/res/drawable-night/avatar_background.xml delete mode 100644 app/src/main/res/drawable/avatar_background.xml delete mode 100644 app/src/main/res/drawable/ic_menu_24dp.xml diff --git a/app/build.gradle b/app/build.gradle index d0f5750e4..38150c17a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -100,7 +100,7 @@ dependencies { implementation 'androidx.browser:browser:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'androidx.legacy:legacy-support-v13:1.0.0' - implementation 'com.google.android.material:material:1.1.0-alpha10' + implementation 'com.google.android.material:material:1.1.0-beta01' implementation 'androidx.exifinterface:exifinterface:1.0.0' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.preference:preference:1.1.0' diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt index e1d2f3ba6..30a758872 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/AccountActivity.kt @@ -18,6 +18,7 @@ package com.keylesspalace.tusky import android.animation.ArgbEvaluator import android.content.Context import android.content.Intent +import android.content.res.ColorStateList import android.graphics.Color import android.graphics.PorterDuff import android.os.Bundle @@ -40,6 +41,8 @@ import com.bumptech.glide.Glide import com.google.android.material.appbar.AppBarLayout import com.google.android.material.appbar.CollapsingToolbarLayout import com.google.android.material.floatingactionbutton.FloatingActionButton +import com.google.android.material.shape.MaterialShapeDrawable +import com.google.android.material.shape.ShapeAppearanceModel import com.google.android.material.snackbar.Snackbar import com.google.android.material.tabs.TabLayout import com.keylesspalace.tusky.adapter.AccountFieldAdapter @@ -86,8 +89,6 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI @ColorInt private var toolbarColor: Int = 0 @ColorInt - private var backgroundColor: Int = 0 - @ColorInt private var statusBarColorTransparent: Int = 0 @ColorInt private var statusBarColorOpaque: Int = 0 @@ -107,6 +108,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + loadResources() makeNotificationBarTransparent() setContentView(R.layout.activity_account) @@ -119,7 +121,6 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI animateAvatar = sharedPrefs.getBoolean("animateGifAvatars", false) hideFab = sharedPrefs.getBoolean("fabHide", false) - loadResources() setupToolbar() setupTabs() setupAccountViews() @@ -135,8 +136,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI * Load colors and dimensions from resources */ private fun loadResources() { - toolbarColor = ThemeUtils.getColor(this, R.attr.toolbar_background_color) - backgroundColor = ThemeUtils.getColor(this, android.R.attr.colorBackground) + toolbarColor = ThemeUtils.getColor(this, R.attr.colorSurface) statusBarColorTransparent = ContextCompat.getColor(this, R.color.header_background_filter) statusBarColorOpaque = ThemeUtils.getColor(this, R.attr.colorPrimaryDark) avatarSize = resources.getDimension(R.dimen.account_activity_avatar_size) @@ -211,9 +211,6 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI }) } - /** - * Setup toolbar - */ private fun setupToolbar() { // set toolbar top margin according to system window insets accountCoordinatorLayout.setOnApplyWindowInsetsListener { _, insets -> @@ -236,6 +233,23 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI ThemeUtils.setDrawableTint(this, accountToolbar.navigationIcon, R.attr.account_toolbar_icon_tint_uncollapsed) ThemeUtils.setDrawableTint(this, accountToolbar.overflowIcon, R.attr.account_toolbar_icon_tint_uncollapsed) + val appBarElevation = resources.getDimension(R.dimen.actionbar_elevation) + + val toolbarBackground = MaterialShapeDrawable.createWithElevationOverlay(this, appBarElevation) + toolbarBackground.fillColor = ColorStateList.valueOf(Color.TRANSPARENT) + accountToolbar.background = toolbarBackground + + accountHeaderInfoContainer.background = MaterialShapeDrawable.createWithElevationOverlay(this, appBarElevation) + + val avatarBackground = MaterialShapeDrawable.createWithElevationOverlay(this, appBarElevation).apply { + fillColor = ColorStateList.valueOf(toolbarColor) + elevation = appBarElevation + shapeAppearanceModel = ShapeAppearanceModel.builder() + .setAllCornerSizes(resources.getDimension(R.dimen.account_avatar_background_radius)) + .build() + } + accountAvatarImageView.background = avatarBackground + // Add a listener to change the toolbar icon color when it enters/exits its collapsed state. accountAppBarLayout.addOnOffsetChangedListener(object : AppBarLayout.OnOffsetChangedListener { @@ -281,16 +295,14 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI accountAvatarImageView.visible(scaledAvatarSize > 0) - var transparencyPercent = abs(verticalOffset) / titleVisibleHeight.toFloat() - if (transparencyPercent > 1) transparencyPercent = 1f + val transparencyPercent = (abs(verticalOffset) / titleVisibleHeight.toFloat()).coerceAtMost(1f) window.statusBarColor = argbEvaluator.evaluate(transparencyPercent, statusBarColorTransparent, statusBarColorOpaque) as Int val evaluatedToolbarColor = argbEvaluator.evaluate(transparencyPercent, Color.TRANSPARENT, toolbarColor) as Int - val evaluatedTabBarColor = argbEvaluator.evaluate(transparencyPercent, backgroundColor, toolbarColor) as Int - accountToolbar.setBackgroundColor(evaluatedToolbarColor) - accountHeaderInfoContainer.setBackgroundColor(evaluatedTabBarColor) - accountTabLayout.setBackgroundColor(evaluatedTabBarColor) + + toolbarBackground.fillColor = ColorStateList.valueOf(evaluatedToolbarColor) + swipeToRefreshLayout.isEnabled = verticalOffset == 0 } }) @@ -300,7 +312,7 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI private fun makeNotificationBarTransparent() { val decorView = window.decorView decorView.systemUiVisibility = decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - window.statusBarColor = Color.TRANSPARENT + window.statusBarColor = statusBarColorTransparent } /** diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index 1f85b0348..a532b539a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -24,7 +24,6 @@ import android.os.Handler; import android.preference.PreferenceManager; import android.util.Log; import android.view.KeyEvent; -import android.widget.ImageButton; import android.widget.ImageView; import androidx.annotation.Nullable; @@ -178,7 +177,6 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut setContentView(R.layout.activity_main); composeButton = findViewById(R.id.floating_btn); - ImageButton drawerToggle = findViewById(R.id.drawer_toggle); tabLayout = findViewById(R.id.tab_layout); viewPager = findViewById(R.id.pager); @@ -189,10 +187,6 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut setupDrawer(); - // Setup the navigation drawer toggle button. - ThemeUtils.setDrawableTint(this, drawerToggle.getDrawable(), R.attr.toolbar_icon_tint); - drawerToggle.setOnClickListener(v -> drawer.openDrawer()); - /* Fetch user info while we're doing other things. This has to be done after setting up the * drawer, though, because its callback touches the header in the drawer. */ fetchUserInfo(); @@ -401,6 +395,7 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut .withHasStableIds(true) .withSelectedItem(-1) .withDrawerItems(listItems) + .withToolbar(findViewById(R.id.main_toolbar)) .withOnDrawerItemClickListener((view, position, drawerItem) -> { if (drawerItem != null) { long drawerItemIdentifier = drawerItem.getIdentifier(); diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/Account.kt b/app/src/main/java/com/keylesspalace/tusky/entity/Account.kt index d1121f5bc..71518573e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/entity/Account.kt +++ b/app/src/main/java/com/keylesspalace/tusky/entity/Account.kt @@ -61,8 +61,7 @@ data class Account( if (other !is Account) { return false } - val account = other as Account? - return account?.id == this.id + return other.id == this.id } fun deepEquals(other: Account): Boolean { diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt index 0ab9e1369..dfc44fa61 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt @@ -92,9 +92,9 @@ class AccountPreferencesFragment : PreferenceFragmentCompat(), publicFiltersPreference = requirePreference("publicFilters") threadFiltersPreference = requirePreference("threadFilters") - notificationPreference.icon = IconicsDrawable(notificationPreference.context, GoogleMaterial.Icon.gmd_notifications).sizePx(iconSize).color(ThemeUtils.getColor(notificationPreference.context, R.attr.toolbar_icon_tint)) + notificationPreference.icon = IconicsDrawable(notificationPreference.context, GoogleMaterial.Icon.gmd_notifications).sizePx(iconSize).color(ThemeUtils.getColor(notificationPreference.context, R.attr.preference_icon_tint)) mutedUsersPreference.icon = getTintedIcon(R.drawable.ic_mute_24dp) - blockedUsersPreference.icon = IconicsDrawable(blockedUsersPreference.context, GoogleMaterial.Icon.gmd_block).sizePx(iconSize).color(ThemeUtils.getColor(blockedUsersPreference.context, R.attr.toolbar_icon_tint)) + blockedUsersPreference.icon = IconicsDrawable(blockedUsersPreference.context, GoogleMaterial.Icon.gmd_block).sizePx(iconSize).color(ThemeUtils.getColor(blockedUsersPreference.context, R.attr.preference_icon_tint)) mutedDomainsPreference.icon = getTintedIcon(R.drawable.ic_mute_24dp) notificationPreference.onPreferenceClickListener = this @@ -289,7 +289,7 @@ class AccountPreferencesFragment : PreferenceFragmentCompat(), private fun getTintedIcon(iconId: Int): Drawable? { val drawable = context?.getDrawable(iconId) - ThemeUtils.setDrawableTint(context, drawable, R.attr.toolbar_icon_tint) + ThemeUtils.setDrawableTint(context, drawable, R.attr.preference_icon_tint) return drawable } diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/PreferencesFragment.kt b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/PreferencesFragment.kt index 95b9251fc..d631b84ac 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/PreferencesFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/PreferencesFragment.kt @@ -38,13 +38,13 @@ class PreferencesFragment : PreferenceFragmentCompat() { addPreferencesFromResource(R.xml.preferences) val themePreference: Preference = requirePreference("appTheme") - themePreference.icon = IconicsDrawable(themePreference.context, GoogleMaterial.Icon.gmd_palette).sizePx(iconSize).color(ThemeUtils.getColor(themePreference.context, R.attr.toolbar_icon_tint)) + themePreference.icon = IconicsDrawable(themePreference.context, GoogleMaterial.Icon.gmd_palette).sizePx(iconSize).color(ThemeUtils.getColor(themePreference.context, R.attr.preference_icon_tint)) val emojiPreference: Preference = requirePreference("emojiCompat") - emojiPreference.icon = IconicsDrawable(emojiPreference.context, GoogleMaterial.Icon.gmd_sentiment_satisfied).sizePx(iconSize).color(ThemeUtils.getColor(emojiPreference.context, R.attr.toolbar_icon_tint)) + emojiPreference.icon = IconicsDrawable(emojiPreference.context, GoogleMaterial.Icon.gmd_sentiment_satisfied).sizePx(iconSize).color(ThemeUtils.getColor(emojiPreference.context, R.attr.preference_icon_tint)) val textSizePreference: Preference = requirePreference("statusTextSize") - textSizePreference.icon = IconicsDrawable(textSizePreference.context, GoogleMaterial.Icon.gmd_format_size).sizePx(iconSize).color(ThemeUtils.getColor(textSizePreference.context, R.attr.toolbar_icon_tint)) + textSizePreference.icon = IconicsDrawable(textSizePreference.context, GoogleMaterial.Icon.gmd_format_size).sizePx(iconSize).color(ThemeUtils.getColor(textSizePreference.context, R.attr.preference_icon_tint)) val timelineFilterPreferences: Preference = requirePreference("timelineFilterPreferences") timelineFilterPreferences.setOnPreferenceClickListener { @@ -67,11 +67,11 @@ class PreferencesFragment : PreferenceFragmentCompat() { } val languagePreference: Preference = requirePreference("language") - languagePreference.icon = IconicsDrawable(languagePreference.context, GoogleMaterial.Icon.gmd_translate).sizePx(iconSize).color(ThemeUtils.getColor(languagePreference.context, R.attr.toolbar_icon_tint)) + languagePreference.icon = IconicsDrawable(languagePreference.context, GoogleMaterial.Icon.gmd_translate).sizePx(iconSize).color(ThemeUtils.getColor(languagePreference.context, R.attr.preference_icon_tint)) val botIndicatorPreference = requirePreference("showBotOverlay") val botDrawable = botIndicatorPreference.context.getDrawable(R.drawable.ic_bot_24dp) - ThemeUtils.setDrawableTint(context, botDrawable, R.attr.toolbar_icon_tint) + ThemeUtils.setDrawableTint(context, botDrawable, R.attr.preference_icon_tint) botIndicatorPreference.icon = botDrawable } diff --git a/app/src/main/java/com/keylesspalace/tusky/view/ComposeScheduleView.java b/app/src/main/java/com/keylesspalace/tusky/view/ComposeScheduleView.java index 8efe68639..dc58f86ec 100644 --- a/app/src/main/java/com/keylesspalace/tusky/view/ComposeScheduleView.java +++ b/app/src/main/java/com/keylesspalace/tusky/view/ComposeScheduleView.java @@ -120,7 +120,8 @@ public class ComposeScheduleView extends ConstraintLayout { private void openPickDateDialog() { long yesterday = Calendar.getInstance().getTimeInMillis() - 24 * 60 * 60 * 1000; CalendarConstraints calendarConstraints = new CalendarConstraints.Builder() - .setValidator(new DateValidatorPointForward(yesterday)) + .setValidator( + DateValidatorPointForward.from(yesterday)) .build(); if (scheduleDateTime == null) { scheduleDateTime = Calendar.getInstance(TimeZone.getDefault()); diff --git a/app/src/main/res/color/tab_icon_color.xml b/app/src/main/res/color/tab_icon_color.xml deleted file mode 100644 index 8edd8d373..000000000 --- a/app/src/main/res/color/tab_icon_color.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable-night/avatar_background.xml b/app/src/main/res/drawable-night/avatar_background.xml deleted file mode 100644 index 4fb7dbda1..000000000 --- a/app/src/main/res/drawable-night/avatar_background.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/avatar_background.xml b/app/src/main/res/drawable/avatar_background.xml deleted file mode 100644 index 848919782..000000000 --- a/app/src/main/res/drawable/avatar_background.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_menu_24dp.xml b/app/src/main/res/drawable/ic_menu_24dp.xml deleted file mode 100644 index 8ec2ddf73..000000000 --- a/app/src/main/res/drawable/ic_menu_24dp.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_account.xml b/app/src/main/res/layout/activity_account.xml index e0ba686de..b1e563a09 100644 --- a/app/src/main/res/layout/activity_account.xml +++ b/app/src/main/res/layout/activity_account.xml @@ -17,16 +17,15 @@ android:id="@+id/accountAppBarLayout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?android:colorBackground" android:elevation="@dimen/actionbar_elevation"> - @@ -318,7 +314,9 @@ android:layout_gravity="top" android:background="@android:color/transparent" app:layout_collapseMode="pin" + app:contentInsetStartWithNavigation="0dp" app:layout_scrollFlags="scroll|enterAlways" /> + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 43745036c..92ae21bdf 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,49 +7,38 @@ android:layout_height="match_parent" tools:context="com.keylesspalace.tusky.MainActivity"> - + android:layout_height="wrap_content" + android:elevation="@dimen/actionbar_elevation"> - - - - - + app:contentInsetStartWithNavigation="0dp"> - + + + + + + + + + + android:layout_height="?attr/actionBarSize" /> diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml index 2733e1e6d..3e3a12ae9 100644 --- a/app/src/main/res/values-night/styles.xml +++ b/app/src/main/res/values-night/styles.xml @@ -27,8 +27,7 @@ @color/window_background_dark @color/custom_tab_toolbar_dark - @color/toolbar_background_dark - @color/toolbar_icon_dark + @color/toolbar_icon_dark @style/TuskyImageButton.Dark @drawable/ic_reblog_dark_24dp @drawable/reblog_inactive_dark diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 7477a44b8..29dbcdeba 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -12,8 +12,7 @@ - - + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index cdd9ff025..378090440 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -19,7 +19,6 @@ #ffffff #d9e1e8 #9baec8 - #4c5368 #d9e1e8 #444b5d #2f3441 @@ -46,7 +45,6 @@ #CC000000 #3c3c3c #5f636f - #f6f7f7 #7C000000 #BFBFBF #b0b0b0 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index a5ba6214d..c2f1bdd91 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -40,6 +40,8 @@ 4.5dp 3dp 160dp + 14dp + 5dp diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 919a5417f..581c5b149 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -63,6 +63,8 @@ @color/color_primary_dark_light + @style/Widget.MaterialComponents.AppBarLayout.Surface + @color/color_background_light @color/color_primary_light @color/window_background_light @@ -77,8 +79,7 @@ @color/window_background_light @color/custom_tab_toolbar_light - @color/toolbar_background_light - @color/toolbar_icon_light + @color/toolbar_icon_light @style/TuskyImageButton.Light @drawable/ic_reblog_light_24dp @drawable/reblog_inactive_light @@ -156,9 +157,6 @@ ?attr/status_text_medium true 3dp - ?attr/tab_icon_selected_tint - ?android:attr/textColorSecondary - ?attr/tab_icon_selected_tint