add handling for status bar color changing

This commit is contained in:
tibbi
2022-12-30 17:59:52 +01:00
parent 3b8cd4f9fd
commit e9be5878de
7 changed files with 38 additions and 18 deletions

View File

@@ -62,7 +62,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:4da0ee0cf4' implementation 'com.github.SimpleMobileTools:Simple-Commons:d82297ad77'
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61' implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
implementation 'me.grantland:autofittextview:0.2.1' implementation 'me.grantland:autofittextview:0.2.1'
} }

View File

@@ -53,11 +53,13 @@ class MainActivity : SimpleActivity() {
var cachedContacts = ArrayList<SimpleContact>() var cachedContacts = ArrayList<SimpleContact>()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
appLaunched(BuildConfig.APPLICATION_ID) appLaunched(BuildConfig.APPLICATION_ID)
setupOptionsMenu() setupOptionsMenu()
refreshMenuItems() refreshMenuItems()
updateMaterialActivityViews(main_coordinator, main_holder, false)
launchedDialer = savedInstanceState?.getBoolean(OPEN_DIAL_PAD_AT_LAUNCH) ?: false launchedDialer = savedInstanceState?.getBoolean(OPEN_DIAL_PAD_AT_LAUNCH) ?: false
@@ -95,13 +97,19 @@ class MainActivity : SimpleActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
val statusBarColor = if (getCurrentFragment()?.getScrollingView() == null) {
getProperBackgroundColor()
} else {
window.statusBarColor
}
val properPrimaryColor = getProperPrimaryColor() val properPrimaryColor = getProperPrimaryColor()
val dialpadIcon = resources.getColoredDrawableWithColor(R.drawable.ic_dialpad_vector, properPrimaryColor.getContrastColor()) val dialpadIcon = resources.getColoredDrawableWithColor(R.drawable.ic_dialpad_vector, properPrimaryColor.getContrastColor())
main_dialpad_button.setImageDrawable(dialpadIcon) main_dialpad_button.setImageDrawable(dialpadIcon)
setupTabColors() setupToolbar(main_toolbar, statusBarColor = statusBarColor, searchMenuItem = mSearchMenuItem)
setupToolbar(main_toolbar, searchMenuItem = mSearchMenuItem)
updateTextColors(main_holder) updateTextColors(main_holder)
setupTabColors()
getAllFragments().forEach { getAllFragments().forEach {
it?.setupColors(getProperTextColor(), getProperPrimaryColor(), getProperPrimaryColor()) it?.setupColors(getProperTextColor(), getProperPrimaryColor(), getProperPrimaryColor())
@@ -268,6 +276,11 @@ class MainActivity : SimpleActivity() {
.build() .build()
} }
private fun updateStatusBarChanger() {
setupMaterialScrollListener(getCurrentFragment()?.getScrollingView(), main_toolbar)
updateStatusBarOnPageChange()
}
private fun setupTabColors() { private fun setupTabColors() {
val activeView = main_tabs_holder.getTabAt(view_pager.currentItem)?.customView val activeView = main_tabs_holder.getTabAt(view_pager.currentItem)?.customView
updateBottomTabItemColors(activeView, true) updateBottomTabItemColors(activeView, true)
@@ -297,6 +310,7 @@ class MainActivity : SimpleActivity() {
it?.finishActMode() it?.finishActMode()
} }
refreshMenuItems() refreshMenuItems()
updateStatusBarChanger()
} }
}) })
@@ -359,6 +373,9 @@ class MainActivity : SimpleActivity() {
) )
main_tabs_holder.beGoneIf(main_tabs_holder.tabCount == 1) main_tabs_holder.beGoneIf(main_tabs_holder.tabCount == 1)
main_tabs_holder.onGlobalLayout {
updateStatusBarChanger()
}
storedShowTabs = config.showTabs storedShowTabs = config.showTabs
} }

View File

@@ -157,4 +157,6 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
} }
} }
} }
override fun getScrollingView() = fragment_list
} }

View File

@@ -190,4 +190,6 @@ class FavoritesFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
(fragment_list.adapter as? ContactsAdapter)?.updateItems(contacts, text) (fragment_list.adapter as? ContactsAdapter)?.updateItems(contacts, text)
setupLetterFastscroller(contacts) setupLetterFastscroller(contacts)
} }
override fun getScrollingView() = fragment_list
} }

View File

@@ -3,6 +3,7 @@ package com.simplemobiletools.dialer.fragments
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.widget.RelativeLayout import android.widget.RelativeLayout
import androidx.core.view.ScrollingView
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.getProperPrimaryColor import com.simplemobiletools.commons.extensions.getProperPrimaryColor
import com.simplemobiletools.commons.extensions.getProperTextColor import com.simplemobiletools.commons.extensions.getProperTextColor
@@ -39,4 +40,6 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
abstract fun onSearchClosed() abstract fun onSearchClosed()
abstract fun onSearchQueryChanged(text: String) abstract fun onSearchQueryChanged(text: String)
abstract fun getScrollingView(): ScrollingView?
} }

View File

@@ -143,4 +143,6 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
recents_placeholder.beVisibleIf(recentCalls.isEmpty()) recents_placeholder.beVisibleIf(recentCalls.isEmpty())
(recents_list.adapter as? RecentCallsAdapter)?.updateItems(recentCalls, text) (recents_list.adapter as? RecentCallsAdapter)?.updateItems(recentCalls, text)
} }
override fun getScrollingView() = recents_list
} }

View File

@@ -5,27 +5,21 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.MaterialToolbar
android:id="@+id/main_app_bar_layout" android:id="@+id/main_toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="?attr/actionBarSize"
android:background="@color/color_primary"
<com.google.android.material.appbar.MaterialToolbar app:menu="@menu/menu"
android:id="@+id/main_toolbar" app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_primary"
app:menu="@menu/menu"
app:title="@string/app_launcher_name"
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/main_holder" android:id="@+id/main_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"> android:layout_marginTop="?attr/actionBarSize"
android:fillViewport="true"
android:scrollbars="none">
<com.simplemobiletools.commons.views.MyViewPager <com.simplemobiletools.commons.views.MyViewPager
android:id="@+id/view_pager" android:id="@+id/view_pager"