Keep icon history

This commit is contained in:
J-Jamet
2021-03-04 19:00:17 +01:00
parent a9accc8c42
commit 985f8fad3b
4 changed files with 36 additions and 10 deletions

View File

@@ -222,8 +222,8 @@ class EntryEditActivity : LockingActivity(),
openPasswordGenerator()
}
// Add listener to the icon
setOnIconViewClickListener = View.OnClickListener {
IconPickerActivity.launch(this@EntryEditActivity)
setOnIconViewClickListener = { iconImage ->
IconPickerActivity.launch(this@EntryEditActivity, iconImage)
}
setOnRemoveAttachment = { attachment ->
mAttachmentFileBinderManager?.removeBinaryAttachment(attachment)

View File

@@ -78,7 +78,7 @@ class EntryEditFragment: StylishFragment() {
var drawFactory: IconDrawableFactory? = null
var setOnDateClickListener: (() -> Unit)? = null
var setOnPasswordGeneratorClickListener: View.OnClickListener? = null
var setOnIconViewClickListener: View.OnClickListener? = null
var setOnIconViewClickListener: ((IconImage) -> Unit)? = null
var setOnEditCustomField: ((Field) -> Unit)? = null
var setOnRemoveAttachment: ((Attachment) -> Unit)? = null
@@ -100,7 +100,7 @@ class EntryEditFragment: StylishFragment() {
entryTitleView = rootView.findViewById(R.id.entry_edit_title)
entryIconView = rootView.findViewById(R.id.entry_edit_icon_button)
entryIconView.setOnClickListener {
setOnIconViewClickListener?.onClick(it)
setOnIconViewClickListener?.invoke(mEntryInfo.icon)
}
entryUserNameView = rootView.findViewById(R.id.entry_edit_user_name)

View File

@@ -37,6 +37,7 @@ import com.kunzisoft.keepass.activities.lock.LockingActivity
import com.kunzisoft.keepass.activities.lock.resetAppTimeoutWhenViewFocusedOrChanged
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
import com.kunzisoft.keepass.settings.PreferencesUtil
import com.kunzisoft.keepass.utils.UriUtil
import com.kunzisoft.keepass.view.asError
@@ -51,6 +52,8 @@ class IconPickerActivity : LockingActivity() {
private lateinit var uploadButton: View
private var lockView: View? = null
private var mIconImage: IconImage = IconImage()
private val iconPickerViewModel: IconPickerViewModel by viewModels()
private var mDatabase: Database? = null
@@ -87,11 +90,17 @@ class IconPickerActivity : LockingActivity() {
lockAndExit()
}
intent?.getParcelableExtra<IconImage>(EXTRA_ICON)?.let {
mIconImage = it
}
if (savedInstanceState == null) {
supportFragmentManager.commit {
setReorderingAllowed(true)
add(R.id.icon_picker_fragment, IconPickerFragment(), ICON_PICKER_FRAGMENT_TAG)
}
} else {
mIconImage = savedInstanceState.getParcelable(EXTRA_ICON) ?: mIconImage
}
// Focus view to reinitialize timeout
@@ -99,16 +108,20 @@ class IconPickerActivity : LockingActivity() {
mSelectFileHelper = SelectFileHelper(this)
// TODO keep previous standard icon id
iconPickerViewModel.iconStandardSelected.observe(this) { iconStandard ->
mIconImage.standard = iconStandard
// Remove the custom icon if a standard one is selected
mIconImage.custom = IconImageCustom()
setResult(Activity.RESULT_OK, Intent().apply {
putExtra(EXTRA_ICON, IconImage(iconStandard))
putExtra(EXTRA_ICON, mIconImage)
})
finish()
}
iconPickerViewModel.iconCustomSelected.observe(this) { iconCustom ->
// Keep the standard icon if a custom one is selected
mIconImage.custom = iconCustom
setResult(Activity.RESULT_OK, Intent().apply {
putExtra(EXTRA_ICON, IconImage(iconCustom))
putExtra(EXTRA_ICON, mIconImage)
})
finish()
}
@@ -120,6 +133,12 @@ class IconPickerActivity : LockingActivity() {
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putParcelable(EXTRA_ICON, mIconImage)
}
override fun onResume() {
super.onResume()
@@ -183,9 +202,16 @@ class IconPickerActivity : LockingActivity() {
}
}
fun launch(context: Activity) {
fun launch(context: Activity,
previousIcon: IconImage?) {
// Create an instance to return the picker icon
context.startActivityForResult(Intent(context, IconPickerActivity::class.java), ICON_SELECTED_REQUEST)
context.startActivityForResult(
Intent(context,
IconPickerActivity::class.java).apply {
if (previousIcon != null)
putExtra(EXTRA_ICON, previousIcon)
},
ICON_SELECTED_REQUEST)
}
}
}

View File

@@ -146,7 +146,7 @@ class GroupEditDialogFragment : DialogFragment() {
}
iconButtonView.setOnClickListener { _ ->
IconPickerActivity.launch(activity)
IconPickerActivity.launch(activity, mGroupInfo.icon)
}
return builder.create()