Show view by fading

This commit is contained in:
J-Jamet
2021-05-16 17:52:10 +02:00
parent 3c55e3a3f0
commit 9c28d5c5c5
7 changed files with 57 additions and 35 deletions

View File

@@ -38,6 +38,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.isVisible
import androidx.core.widget.NestedScrollView
import androidx.lifecycle.lifecycleScope
import com.google.android.material.snackbar.Snackbar
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.dialogs.*
@@ -218,30 +219,11 @@ class EntryEditActivity : LockingActivity(),
add(TemplateAttribute("Another password", TemplateAttributeType.INLINE, true, TemplateAttributeAction.PASSWORD_GENERATION))
})))
templateSelectorSpinner = findViewById(R.id.entry_edit_template_selector)
templateSelectorSpinner?.apply {
adapter = TemplatesSelectorAdapter(this@EntryEditActivity, mDatabase, templates)
onItemSelectedListener = object: AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val newTemplate = templates[position]
entryEditFragment?.apply {
if (getTemplate() != newTemplate) {
assignTemplate(newTemplate)
}
}
}
override fun onNothingSelected(parent: AdapterView<*>?) {}
}
}
// Build fragment to manage entry modification
entryEditFragment = supportFragmentManager.findFragmentByTag(ENTRY_EDIT_FRAGMENT_TAG) as? EntryEditFragment?
if (entryEditFragment == null) {
entryEditFragment = EntryEditFragment.getInstance(tempEntryInfo)
}
supportFragmentManager.beginTransaction()
.replace(R.id.entry_edit_contents, entryEditFragment!!, ENTRY_EDIT_FRAGMENT_TAG)
.commit()
entryEditFragment?.apply {
drawFactory = mDatabase?.iconDrawableFactory
onDateTimeClickListener = { dateInstant ->
@@ -269,6 +251,32 @@ class EntryEditActivity : LockingActivity(),
}
}
// To show Fragment asynchronously
lifecycleScope.launchWhenResumed {
entryEditFragment?.let { fragment ->
supportFragmentManager.beginTransaction()
.replace(R.id.entry_edit_contents, fragment, ENTRY_EDIT_FRAGMENT_TAG)
.commit()
}
}
// Change template dynamically
templateSelectorSpinner = findViewById(R.id.entry_edit_template_selector)
templateSelectorSpinner?.apply {
adapter = TemplatesSelectorAdapter(this@EntryEditActivity, mDatabase, templates)
onItemSelectedListener = object: AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val newTemplate = templates[position]
entryEditFragment?.apply {
if (getTemplate() != newTemplate) {
assignTemplate(newTemplate)
}
}
}
override fun onNothingSelected(parent: AdapterView<*>?) {}
}
}
// Retrieve temp attachments in case of deletion
if (savedInstanceState?.containsKey(TEMP_ATTACHMENTS) == true) {
mTempAttachments = savedInstanceState.getParcelableArrayList(TEMP_ATTACHMENTS) ?: mTempAttachments

View File

@@ -68,12 +68,13 @@ class EntryEditFragment : StylishFragment() {
private var mInflater: LayoutInflater? = null
private lateinit var rootView: View
private lateinit var entryIconView: ImageView
private lateinit var entryTitleView: EntryEditFieldView
private lateinit var templateContainerView: ViewGroup
private lateinit var customFieldsContainerView: SectionView
private lateinit var attachmentsContainerView: View
private lateinit var attachmentsContainerView: ViewGroup
private lateinit var attachmentsListView: RecyclerView
private lateinit var attachmentsAdapter: EntryAttachmentsItemsAdapter
@@ -99,7 +100,7 @@ class EntryEditFragment : StylishFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
val rootView = inflater.cloneInContext(contextThemed)
rootView = inflater.cloneInContext(contextThemed)
.inflate(R.layout.fragment_entry_edit_contents, container, false)
mInflater = inflater
@@ -110,7 +111,6 @@ class EntryEditFragment : StylishFragment() {
entryIconView.setOnClickListener {
onIconClickListener?.invoke(mEntryInfo.icon)
}
entryTitleView = rootView.findViewById(R.id.entry_edit_title)
templateContainerView = rootView.findViewById(R.id.template_fields_container)
// To fix card view margin in KitKat-
@@ -145,7 +145,7 @@ class EntryEditFragment : StylishFragment() {
iconColor = taIconColor?.getColor(0, Color.WHITE) ?: Color.WHITE
taIconColor?.recycle()
rootView?.resetAppTimeoutWhenViewFocusedOrChanged(requireContext())
rootView.resetAppTimeoutWhenViewFocusedOrChanged(requireContext())
// Retrieve the new entry after an orientation change
if (arguments?.containsKey(KEY_TEMP_ENTRY_INFO) == true)
@@ -167,6 +167,8 @@ class EntryEditFragment : StylishFragment() {
onRemoveAttachment?.invoke(attachment)
}
rootView.showByFading()
return rootView
}
@@ -219,6 +221,7 @@ class EntryEditFragment : StylishFragment() {
populateEntryWithViews()
this.mTemplate = template
populateViewsWithEntry()
rootView.showByFading()
}
private fun populateViewsWithEntry() {

View File

@@ -21,7 +21,7 @@ class TemplatesSelectorAdapter(context: Context,
private var mIconColor = Color.BLACK
init {
val taIconColor = context.theme.obtainStyledAttributes(intArrayOf(R.attr.colorAccent))
val taIconColor = context.theme.obtainStyledAttributes(intArrayOf(R.attr.colorPrimary))
mIconColor = taIconColor.getColor(0, Color.BLACK)
taIconColor.recycle()
}

View File

@@ -56,14 +56,7 @@ class SectionView @JvmOverloads constructor(context: Context,
override fun addView(child: View?) {
visibility = View.VISIBLE
containerSectionView.apply {
alpha = 0f
addView(child)
animate()
.alpha(1f)
.setDuration(200)
.setListener(null)
}
containerSectionView.addView(child)
}
fun removeViewById(@IdRes viewId: Int, onFinish: ((View) ->Unit)? = null) {

View File

@@ -158,6 +158,23 @@ fun View.expand(animate: Boolean = true,
}.start()
}
fun View.hideByFading() {
alpha = 1f
animate()
.alpha(0f)
.setDuration(400)
.setListener(null)
}
fun View.showByFading() {
// Trick to keep the focus
alpha = 0.01f
animate()
.alpha(1f)
.setDuration(400)
.setListener(null)
}
fun View.updateLockPaddingLeft() {
updatePadding(resources.getDimensionPixelSize(
if (PreferencesUtil.showLockDatabaseButton(context)) {

View File

@@ -26,7 +26,7 @@
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="@+id/entry_edit_container"
android:id="@+id/entry_edit_header_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?attr/cardViewStyle"
@@ -60,7 +60,7 @@
android:id="@+id/template_fields_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/entry_edit_container"
app:layout_constraintTop_toBottomOf="@+id/entry_edit_header_container"
app:layout_constraintBottom_toTopOf="@+id/custom_fields_container"
android:orientation="vertical" />

View File

@@ -37,11 +37,12 @@
android:layout_marginLeft="12dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:src="@drawable/ic_new_field_white_24dp"
android:contentDescription="@string/content_description_entry_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:tint="?attr/colorAccent" />
app:tint="?attr/colorPrimary" />
<TextView
android:id="@+id/template_name"