convert MainActivity to Kotlin and upgrade MaterialDrawer to version 8 (#1748)

* convert MainActivity to Kotlin

* migrate to MaterialDrawer 8

* fix drawer styles

* revert removing BezelImageView and material_drawer_header override

* fix tests

* add lost comment back to material_drawer_header.xml

* add tools:parentTag to material_drawer_header.xml

* use when instead of if in MainActivity

* fix statusbar color over the drawer

* cleanup drawer item creation

* tint secondary drawer items as well

* remove unnecessary ids

* fix header text color in the light theme

* improve header text contrast
This commit is contained in:
Konrad Pozniak 2020-04-15 18:57:53 +02:00 committed by GitHub
commit 2cf1e366b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 878 additions and 791 deletions

View file

@ -1,57 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:id="@+id/mainDrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.keylesspalace.tusky.MainActivity">
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/main_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevationOverlayEnabled="false"
android:elevation="@dimen/actionbar_elevation">
<androidx.appcompat.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentInsetStartWithNavigation="0dp">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
style="@style/TuskyTabAppearance"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabMode="fixed"
app:tabUnboundedRipple="false" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:background="?attr/windowBackgroundColor"
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tab_layout"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
tools:context="com.keylesspalace.tusky.MainActivity">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floating_btn"
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/actionbar_elevation"
app:elevationOverlayEnabled="false">
<androidx.appcompat.widget.Toolbar
android:id="@+id/mainToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentInsetStartWithNavigation="0dp">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
style="@style/TuskyTabAppearance"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabMode="fixed"
app:tabUnboundedRipple="false" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tabLayout"
android:background="?attr/windowBackgroundColor"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/composeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:contentDescription="@string/action_compose"
app:layout_anchor="@id/viewPager"
app:layout_anchorGravity="bottom|end"
app:srcCompat="@drawable/ic_create_24dp" />
<include layout="@layout/item_status_bottom_sheet" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
android:id="@+id/mainDrawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:contentDescription="@string/action_compose"
app:layout_anchor="@id/pager"
app:layout_anchorGravity="bottom|end"
app:srcCompat="@drawable/ic_create_24dp" />
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true" />
<include layout="@layout/item_status_bottom_sheet" />
</androidx.drawerlayout.widget.DrawerLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -1,10 +1,12 @@
<!-- this replaces the default material_drawer_header.xml from the MaterialDrawer library -->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<!-- this replaces the default material_drawer_header.xml from the MaterialDrawer library to enable rounded avatars -->
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/material_drawer_account_header"
android:layout_width="match_parent"
android:layout_height="@dimen/material_drawer_account_header_height"
android:clickable="true">
android:clickable="true"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/material_drawer_account_header_background"
@ -25,64 +27,132 @@
<com.keylesspalace.tusky.view.BezelImageView
android:id="@+id/material_drawer_account_header_current"
style="@style/BezelImageView"
android:layout_width="@dimen/material_drawer_account_header_selected"
android:layout_height="@dimen/material_drawer_account_header_selected"
android:layout_marginStart="@dimen/material_drawer_vertical_padding"
android:layout_marginLeft="@dimen/material_drawer_vertical_padding"
android:layout_marginTop="@dimen/material_drawer_account_header_horizontal_top"
android:clickable="true"
android:elevation="8dp"
android:elevation="2dp"
android:focusable="true"
android:src="@drawable/avatar_default"
app:biv_maskDrawable="@drawable/materialdrawer_shape_large"
android:scaleType="fitCenter"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/material_drawer_statusbar_guideline" />
app:layout_constraintTop_toBottomOf="@+id/material_drawer_statusbar_guideline"
app:materialDrawerMaskDrawable="@drawable/materialdrawer_shape_large" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/material_drawer_account_header_current_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="4dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:lines="1"
android:minWidth="20dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:singleLine="true"
android:textSize="@dimen/material_drawer_item_badge_text"
app:layout_constraintBottom_toBottomOf="@id/material_drawer_account_header_current"
app:layout_constraintStart_toStartOf="@id/material_drawer_account_header_current"
tools:text="99" />
<com.keylesspalace.tusky.view.BezelImageView
android:id="@+id/material_drawer_account_header_small_first"
style="@style/BezelImageView"
android:layout_width="@dimen/material_drawer_account_header_secondary"
android:layout_height="@dimen/material_drawer_account_header_secondary"
android:layout_marginTop="@dimen/material_drawer_account_header_horizontal_top"
android:layout_marginEnd="@dimen/material_drawer_vertical_padding"
android:layout_marginRight="@dimen/material_drawer_vertical_padding"
android:clickable="true"
android:elevation="8dp"
android:elevation="2dp"
android:focusable="true"
android:src="@drawable/avatar_default"
app:biv_maskDrawable="@drawable/materialdrawer_shape_small"
android:scaleType="fitCenter"
android:visibility="visible"
app:layout_constraintEnd_toStartOf="@id/material_drawer_account_header_small_second"
app:layout_constraintTop_toBottomOf="@+id/material_drawer_statusbar_guideline" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/material_drawer_account_header_small_first_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="4dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:lines="1"
android:minWidth="20dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:singleLine="true"
android:textSize="@dimen/material_drawer_item_badge_small_text"
app:layout_constraintBottom_toBottomOf="@id/material_drawer_account_header_small_first"
app:layout_constraintStart_toStartOf="@id/material_drawer_account_header_small_first"
tools:text="99" />
<com.keylesspalace.tusky.view.BezelImageView
android:id="@+id/material_drawer_account_header_small_second"
style="@style/BezelImageView"
android:layout_width="@dimen/material_drawer_account_header_secondary"
android:layout_height="@dimen/material_drawer_account_header_secondary"
android:layout_marginTop="@dimen/material_drawer_account_header_horizontal_top"
android:layout_marginEnd="@dimen/material_drawer_vertical_padding"
android:layout_marginRight="@dimen/material_drawer_vertical_padding"
android:clickable="true"
android:elevation="8dp"
android:elevation="2dp"
android:focusable="true"
android:src="@drawable/avatar_default"
app:biv_maskDrawable="@drawable/materialdrawer_shape_small"
android:scaleType="fitCenter"
android:visibility="visible"
app:layout_constraintEnd_toStartOf="@id/material_drawer_account_header_small_third"
app:layout_constraintTop_toBottomOf="@+id/material_drawer_statusbar_guideline" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/material_drawer_account_header_small_second_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="4dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:lines="1"
android:minWidth="20dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:singleLine="true"
android:textSize="@dimen/material_drawer_item_badge_small_text"
app:layout_constraintBottom_toBottomOf="@id/material_drawer_account_header_small_second"
app:layout_constraintStart_toStartOf="@id/material_drawer_account_header_small_second"
tools:text="99" />
<com.keylesspalace.tusky.view.BezelImageView
android:id="@+id/material_drawer_account_header_small_third"
style="@style/BezelImageView"
android:layout_width="@dimen/material_drawer_account_header_secondary"
android:layout_height="@dimen/material_drawer_account_header_secondary"
android:layout_marginTop="@dimen/material_drawer_account_header_horizontal_top"
android:layout_marginEnd="@dimen/material_drawer_vertical_padding"
android:layout_marginRight="@dimen/material_drawer_vertical_padding"
android:clickable="true"
android:elevation="8dp"
android:elevation="2dp"
android:focusable="true"
android:src="@drawable/avatar_default"
app:biv_maskDrawable="@drawable/materialdrawer_shape_small"
android:scaleType="fitCenter"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/material_drawer_statusbar_guideline" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/material_drawer_account_header_small_third_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="4dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:lines="1"
android:minWidth="20dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:singleLine="true"
android:textSize="@dimen/material_drawer_item_badge_small_text"
app:layout_constraintBottom_toBottomOf="@id/material_drawer_account_header_small_third"
app:layout_constraintStart_toStartOf="@id/material_drawer_account_header_small_third"
tools:text="99" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/material_drawer_text_guideline"
android:layout_width="wrap_content"
@ -95,7 +165,6 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/material_drawer_vertical_padding"
android:layout_marginLeft="@dimen/material_drawer_vertical_padding"
android:fontFamily="sans-serif-medium"
android:lines="1"
android:maxLines="1"
@ -111,7 +180,6 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/material_drawer_vertical_padding"
android:layout_marginLeft="@dimen/material_drawer_vertical_padding"
android:layout_marginBottom="@dimen/material_drawer_padding"
android:fontFamily="sans-serif"
android:lines="1"
@ -127,8 +195,7 @@
android:layout_width="@dimen/material_drawer_account_header_dropdown"
android:layout_height="@dimen/material_drawer_account_header_dropdown"
android:layout_marginEnd="@dimen/material_drawer_vertical_padding"
android:layout_marginRight="@dimen/material_drawer_vertical_padding"
android:layout_marginBottom="@dimen/material_drawer_account_header_dropdown_margin_bottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</merge>

View file

@ -19,6 +19,8 @@
<color name="favoriteButtonActiveColor">@color/tusky_orange</color>
<color name="headerBackgroundFilter">@color/header_background_filter_dark</color>
<bool name="lightNavigationBar">false</bool>
</resources>

View file

@ -26,7 +26,9 @@
<color name="transparent_tusky_blue">#8c2b90d9</color>
<color name="transparent_black">#8f000000</color>
<color name="header_background_filter">#44000000</color>
<color name="header_background_filter_dark">#44000000</color>
<color name="header_background_filter_light">#66FFFFFF</color>
<color name="transparent_statusbar_background">#44000000</color>
<!-- colors used in the elephant friend drawables -->
<color name="elephant_friend_border_color">#121419</color>

View file

@ -67,14 +67,8 @@
<item name="textColorDisabled">@color/textColorDisabled</item>
<item name="material_drawer_background">@color/colorBackground</item>
<item name="material_drawer_primary_text">@color/textColorSecondary</item>
<item name="material_drawer_primary_icon">@color/iconColor</item>
<item name="material_drawer_secondary_text">@color/textColorTertiary</item>
<item name="material_drawer_hint_text">@color/textColorTertiary</item>
<item name="material_drawer_divider">?attr/dividerColor</item>
<item name="material_drawer_header_selection_text">@color/white</item>
<item name="material_drawer_header_selection_subtext">@color/white</item>
<item name="materialDrawerStyle">@style/TuskyDrawerStyle</item>
<item name="materialDrawerHeaderStyle">@style/TuskyDrawerHeaderStyle</item>
<item name="alertDialogTheme">@style/TuskyDialog</item>
<item name="snackbarButtonStyle">@style/TuskyButton.TextButton</item>
@ -142,17 +136,26 @@
<item name="colorBackgroundAccent">@color/tusky_grey_20</item>
<item name="dividerColor">@color/tusky_grey_10</item>
<item name="material_drawer_background">@color/black</item>
<item name="material_drawer_primary_icon">@color/tusky_grey_40</item>
</style>
<style name="TuskyBlackTheme" parent="TuskyBlackThemeBase" />
<style name="TuskyDrawerStyle" parent ="Widget.MaterialDrawerStyle">
<item name="materialDrawerBackground">?android:colorBackground</item>
<item name="materialDrawerPrimaryIcon">?iconColor</item>
<item name="materialDrawerSecondaryIcon">?iconColor</item>
<item name="materialDrawerDividerColor">?dividerColor</item>
</style>
<style name="TuskyDrawerHeaderStyle" parent ="Widget.MaterialDrawerHeaderStyle">
<item name="materialDrawerHeaderSelectionText">?android:textColorPrimary</item>
<item name="materialDrawerHeaderSelectionSubtext">?android:textColorPrimary</item>
</style>
<!-- customize the shape of the avatars in account selection list -->
<style name="BezelImageView">
<item name="biv_maskDrawable">@drawable/materialdrawer_shape_small</item>
<item name="biv_drawCircularShadow">false</item>
<item name="materialDrawerMaskDrawable">@drawable/materialdrawer_shape_small</item>
<item name="materialDrawerDrawCircularShadow">false</item>
</style>
</resources>

View file

@ -19,6 +19,8 @@
<color name="favoriteButtonActiveColor">@color/tusky_orange_light</color>
<color name="headerBackgroundFilter">@color/header_background_filter_light</color>
<bool name="lightNavigationBar">true</bool>
</resources>