mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-19 18:55:05 +01:00
ViewThemeUtils: remove dependencies on Talk classes where possible
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
05c60ff4b7
commit
8c08efbf4f
@ -334,7 +334,7 @@ class ContactsController(args: Bundle) :
|
||||
val searchManager: SearchManager? = activity?.getSystemService(Context.SEARCH_SERVICE) as SearchManager?
|
||||
if (searchItem != null) {
|
||||
searchView = MenuItemCompat.getActionView(searchItem) as SearchView
|
||||
viewThemeUtils.androidx.themeSearchView(searchView!!)
|
||||
viewThemeUtils.talk.themeSearchView(searchView!!)
|
||||
searchView!!.maxWidth = Int.MAX_VALUE
|
||||
searchView!!.inputType = InputType.TYPE_TEXT_VARIATION_FILTER
|
||||
var imeOptions: Int = EditorInfo.IME_ACTION_DONE or EditorInfo.IME_FLAG_NO_FULLSCREEN
|
||||
|
@ -296,7 +296,7 @@ class ConversationsListController(bundle: Bundle) :
|
||||
val searchManager = activity!!.getSystemService(Context.SEARCH_SERVICE) as SearchManager?
|
||||
if (searchItem != null) {
|
||||
searchView = MenuItemCompat.getActionView(searchItem) as SearchView
|
||||
viewThemeUtils.androidx.themeSearchView(searchView!!)
|
||||
viewThemeUtils.talk.themeSearchView(searchView!!)
|
||||
searchView!!.maxWidth = Int.MAX_VALUE
|
||||
searchView!!.inputType = InputType.TYPE_TEXT_VARIATION_FILTER
|
||||
var imeOptions = EditorInfo.IME_ACTION_DONE or EditorInfo.IME_FLAG_NO_FULLSCREEN
|
||||
@ -361,7 +361,7 @@ class ConversationsListController(bundle: Bundle) :
|
||||
if (TextUtils.isEmpty(searchView!!.query.toString())) {
|
||||
searchView!!.onActionViewCollapsed()
|
||||
if (activity != null) {
|
||||
viewThemeUtils.platform.resetStatusBar(activity, searchView!!)
|
||||
viewThemeUtils.platform.resetStatusBar(activity)
|
||||
}
|
||||
} else {
|
||||
searchView!!.post { searchView!!.setQuery(TAG, true) }
|
||||
@ -402,7 +402,7 @@ class ConversationsListController(bundle: Bundle) :
|
||||
mainActivity.binding.searchToolbar.visibility = View.VISIBLE
|
||||
if (resources != null) {
|
||||
viewThemeUtils.platform
|
||||
.resetStatusBar(mainActivity, mainActivity.binding.searchToolbar)
|
||||
.resetStatusBar(mainActivity)
|
||||
}
|
||||
}
|
||||
val layoutManager = binding.recyclerView.layoutManager as SmoothScrollLinearLayoutManager?
|
||||
|
@ -217,7 +217,7 @@ abstract class BaseController(@LayoutRes var layoutRes: Int, args: Bundle? = nul
|
||||
private fun colorizeStatusBar(showSearchBar: Boolean, activity: Activity?, resources: Resources?) {
|
||||
if (activity != null && resources != null) {
|
||||
if (showSearchBar) {
|
||||
view?.let { viewThemeUtils.platform.resetStatusBar(activity, it) }
|
||||
view?.let { viewThemeUtils.platform.resetStatusBar(activity) }
|
||||
} else {
|
||||
view?.let { viewThemeUtils.platform.themeStatusBar(activity, it) }
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.PorterDuff
|
||||
import android.os.Build
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
@ -42,8 +43,8 @@ import androidx.core.content.res.ResourcesCompat
|
||||
import com.nextcloud.android.common.ui.color.ColorUtil
|
||||
import com.nextcloud.android.common.ui.theme.MaterialSchemes
|
||||
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
|
||||
import com.nextcloud.android.common.ui.util.PlatformThemeUtil
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
import eu.davidea.flexibleadapter.utils.FlexibleUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -68,14 +69,36 @@ class AndroidViewThemeUtils @Inject constructor(schemes: MaterialSchemes, privat
|
||||
|
||||
fun themeStatusBar(activity: Activity, view: View) {
|
||||
withScheme(view) { scheme ->
|
||||
// TODO extract from displayutils to common
|
||||
DisplayUtils.applyColorToStatusBar(activity, scheme.surface)
|
||||
applyColorToStatusBar(activity, scheme.surface)
|
||||
}
|
||||
}
|
||||
|
||||
fun resetStatusBar(activity: Activity, view: View) {
|
||||
// TODO extract from displayutils to common
|
||||
DisplayUtils.applyColorToStatusBar(
|
||||
private fun applyColorToStatusBar(activity: Activity, @ColorInt color: Int) {
|
||||
val window = activity.window
|
||||
val isLightTheme = !PlatformThemeUtil.isDarkMode(activity)
|
||||
if (window != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
val decor = window.decorView
|
||||
if (isLightTheme) {
|
||||
val systemUiFlagLightStatusBar = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or
|
||||
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
} else {
|
||||
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
||||
}
|
||||
decor.systemUiVisibility = systemUiFlagLightStatusBar
|
||||
} else {
|
||||
decor.systemUiVisibility = 0
|
||||
}
|
||||
window.statusBarColor = color
|
||||
} else if (isLightTheme) {
|
||||
window.statusBarColor = Color.BLACK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun resetStatusBar(activity: Activity) {
|
||||
applyColorToStatusBar(
|
||||
activity,
|
||||
ResourcesCompat.getColor(
|
||||
activity.resources,
|
||||
|
@ -23,8 +23,6 @@ package com.nextcloud.talk.ui.theme.viewthemeutils
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.widget.LinearLayout
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.appcompat.widget.SwitchCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
@ -38,18 +36,6 @@ import javax.inject.Inject
|
||||
*/
|
||||
class AndroidXViewThemeUtils @Inject constructor(schemes: MaterialSchemes) :
|
||||
ViewThemeUtilsBase(schemes) {
|
||||
fun themeSearchView(searchView: SearchView) {
|
||||
withScheme(searchView) { scheme ->
|
||||
// hacky as no default way is provided
|
||||
val editText = searchView.findViewById<SearchView.SearchAutoComplete>(R.id.search_src_text)
|
||||
val searchPlate = searchView.findViewById<LinearLayout>(R.id.search_plate)
|
||||
editText.textSize = SEARCH_TEXT_SIZE
|
||||
editText.setHintTextColor(scheme.onSurfaceVariant)
|
||||
editText.setTextColor(scheme.onSurface)
|
||||
editText.setBackgroundColor(scheme.surface)
|
||||
searchPlate.setBackgroundColor(scheme.surface)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorSwitchCompat(switchCompat: SwitchCompat) {
|
||||
withScheme(switchCompat) { scheme ->
|
||||
@ -97,6 +83,5 @@ class AndroidXViewThemeUtils @Inject constructor(schemes: MaterialSchemes) :
|
||||
|
||||
companion object {
|
||||
private const val SWITCH_COMPAT_TRACK_ALPHA: Int = 77
|
||||
private const val SEARCH_TEXT_SIZE: Float = 16f
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import android.widget.TextView
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.appcompat.widget.SwitchCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
@ -221,6 +222,18 @@ class TalkSpecificViewThemeUtils @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun themeSearchView(searchView: SearchView) {
|
||||
withScheme(searchView) { scheme ->
|
||||
// hacky as no default way is provided
|
||||
val editText = searchView.findViewById<SearchView.SearchAutoComplete>(R.id.search_src_text)
|
||||
val searchPlate = searchView.findViewById<LinearLayout>(R.id.search_plate)
|
||||
editText.setHintTextColor(scheme.onSurfaceVariant)
|
||||
editText.setTextColor(scheme.onSurface)
|
||||
editText.setBackgroundColor(scheme.surface)
|
||||
searchPlate.setBackgroundColor(scheme.surface)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val THEMEABLE_PLACEHOLDER_IDS = listOf(
|
||||
R.drawable.ic_mimetype_package_x_generic,
|
||||
@ -230,5 +243,6 @@ class TalkSpecificViewThemeUtils @Inject constructor(
|
||||
private val ALPHA_80_INT: Int = (255 * 0.8).roundToInt()
|
||||
|
||||
private const val HALF_ALPHA_INT: Int = 255 / 2
|
||||
private const val SEARCH_TEXT_SIZE: Float = 16f
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user