mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-04-04 05:17:36 +03:00
Nav header as dedicated view
This commit is contained in:
parent
17c26e2a96
commit
aab3f8c56f
4 changed files with 62 additions and 26 deletions
|
@ -42,15 +42,11 @@ import androidx.appcompat.view.ActionMode
|
|||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||
import androidx.core.graphics.BlendModeCompat
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.dialogs.*
|
||||
import com.kunzisoft.keepass.activities.fragments.GroupFragment
|
||||
|
@ -96,12 +92,7 @@ class GroupActivity : DatabaseLockActivity(),
|
|||
|
||||
// Views
|
||||
private var drawerLayout: DrawerLayout? = null
|
||||
private var databaseNavView: NavigationView? = null
|
||||
private var databaseNavContainerView: View? = null
|
||||
private var databaseNavIconView: ImageView? = null
|
||||
private var databaseNavColorView: ImageView? = null
|
||||
private var databaseNavNameView: TextView? = null
|
||||
private var databaseNavVersionView: TextView? = null
|
||||
private var databaseNavView: NavigationDatabaseView? = null
|
||||
private var rootContainerView: ViewGroup? = null
|
||||
private var coordinatorLayout: CoordinatorLayout? = null
|
||||
private var lockView: View? = null
|
||||
|
@ -118,8 +109,6 @@ class GroupActivity : DatabaseLockActivity(),
|
|||
private var breadcrumbListView: RecyclerView? = null
|
||||
private var loadingView: ProgressBar? = null
|
||||
|
||||
private lateinit var appBarConfiguration: AppBarConfiguration
|
||||
|
||||
private val mGroupViewModel: GroupViewModel by viewModels()
|
||||
private val mGroupEditViewModel: GroupEditViewModel by viewModels()
|
||||
|
||||
|
@ -235,11 +224,6 @@ class GroupActivity : DatabaseLockActivity(),
|
|||
// Initialize views
|
||||
drawerLayout = findViewById(R.id.drawer_layout)
|
||||
databaseNavView = findViewById(R.id.database_nav_view)
|
||||
databaseNavContainerView = databaseNavView?.getHeaderView(0)
|
||||
databaseNavIconView = databaseNavContainerView?.findViewById(R.id.nav_database_icon)
|
||||
databaseNavColorView = databaseNavContainerView?.findViewById(R.id.nav_database_color)
|
||||
databaseNavNameView = databaseNavContainerView?.findViewById(R.id.nav_database_name)
|
||||
databaseNavVersionView = databaseNavContainerView?.findViewById(R.id.nav_database_version)
|
||||
rootContainerView = findViewById(R.id.activity_group_container_view)
|
||||
coordinatorLayout = findViewById(R.id.group_coordinator)
|
||||
numberChildrenView = findViewById(R.id.group_numbers)
|
||||
|
@ -567,21 +551,18 @@ class GroupActivity : DatabaseLockActivity(),
|
|||
// Search suggestion
|
||||
database?.let {
|
||||
val databaseName = it.name.ifEmpty { getString(R.string.database) }
|
||||
databaseNavNameView?.text = databaseName
|
||||
databaseNavView?.setDatabaseName(databaseName)
|
||||
databaseNameView?.text = databaseName
|
||||
databaseNavVersionView?.text = it.version
|
||||
databaseNavView?.setDatabaseVersion(it.version)
|
||||
val customColor = it.customColor
|
||||
databaseNavView?.setDatabaseColor(customColor)
|
||||
if (customColor != null) {
|
||||
databaseNavColorView?.drawable?.colorFilter = BlendModeColorFilterCompat
|
||||
.createBlendModeColorFilterCompat(customColor, BlendModeCompat.SRC_IN)
|
||||
databaseNavColorView?.visibility = View.VISIBLE
|
||||
databaseColorView?.visibility = View.VISIBLE
|
||||
databaseColorView?.setColorFilter(
|
||||
customColor,
|
||||
PorterDuff.Mode.SRC_IN
|
||||
)
|
||||
} else {
|
||||
databaseNavColorView?.visibility = View.GONE
|
||||
databaseColorView?.visibility = View.GONE
|
||||
}
|
||||
mBreadcrumbAdapter?.iconDrawableFactory = it.iconDrawableFactory
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package com.kunzisoft.keepass.view
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||
import androidx.core.graphics.BlendModeCompat
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import com.kunzisoft.keepass.R
|
||||
|
||||
class NavigationDatabaseView @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyle: Int = 0)
|
||||
: NavigationView(context, attrs, defStyle) {
|
||||
|
||||
private var databaseNavContainerView: View? = null
|
||||
private var databaseNavIconView: ImageView? = null
|
||||
private var databaseNavColorView: ImageView? = null
|
||||
private var databaseNavNameView: TextView? = null
|
||||
private var databaseNavVersionView: TextView? = null
|
||||
|
||||
init {
|
||||
inflateHeaderView(R.layout.nav_header_database)
|
||||
databaseNavIconView = databaseNavContainerView?.findViewById(R.id.nav_database_icon)
|
||||
databaseNavColorView = databaseNavContainerView?.findViewById(R.id.nav_database_color)
|
||||
databaseNavNameView = databaseNavContainerView?.findViewById(R.id.nav_database_name)
|
||||
databaseNavVersionView = databaseNavContainerView?.findViewById(R.id.nav_database_version)
|
||||
}
|
||||
|
||||
override fun inflateHeaderView(res: Int): View {
|
||||
val headerView = super.inflateHeaderView(res)
|
||||
databaseNavContainerView = headerView
|
||||
return headerView
|
||||
}
|
||||
|
||||
fun setDatabaseName(name: String) {
|
||||
databaseNavNameView?.text = name
|
||||
}
|
||||
|
||||
fun setDatabaseVersion(version: String) {
|
||||
databaseNavVersionView?.text = version
|
||||
}
|
||||
|
||||
fun setDatabaseColor(color: Int?) {
|
||||
if (color != null) {
|
||||
databaseNavColorView?.drawable?.colorFilter = BlendModeColorFilterCompat
|
||||
.createBlendModeColorFilterCompat(color, BlendModeCompat.SRC_IN)
|
||||
databaseNavColorView?.visibility = View.VISIBLE
|
||||
} else {
|
||||
databaseNavColorView?.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
|
@ -164,12 +164,11 @@
|
|||
|
||||
</RelativeLayout>
|
||||
|
||||
<com.google.android.material.navigation.NavigationView
|
||||
<com.kunzisoft.keepass.view.NavigationDatabaseView
|
||||
android:id="@+id/database_nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
app:headerLayout="@layout/nav_header_main"
|
||||
app:itemTextColor="?android:attr/textColor"
|
||||
app:subheaderColor="?attr/colorAccent"
|
||||
android:fitsSystemWindows="true" />
|
||||
|
|
|
@ -29,7 +29,8 @@
|
|||
android:paddingRight="8dp"
|
||||
style="@style/KeepassDXStyle.TextAppearance.Info"
|
||||
android:textSize="10sp"
|
||||
tools:text="version" />
|
||||
tools:text="version"
|
||||
tools:ignore="SmallSp" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/nav_database_icon"
|
Loading…
Add table
Add a link
Reference in a new issue