mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-04 07:42:30 -08:00
Prevent add empty icon
This commit is contained in:
1 parent
2c172eb8d3
commit
41316d2bd3
3 files changed
+38
-7
No files matched your search
@@ -113,7 +113,7 @@ class IconPickerActivity : LockingActivity() {
|
||||
finish()
|
||||
}
|
||||
iconPickerViewModel.iconCustomAdded.observe(this) { iconCustomAdded ->
|
||||
if (iconCustomAdded.binaryFile.length <= 0) {
|
||||
if (iconCustomAdded.error) {
|
||||
Snackbar.make(coordinatorLayout, R.string.error_upload_file, Snackbar.LENGTH_LONG).asError().show()
|
||||
}
|
||||
uploadButton.isEnabled = true
|
||||
|
||||
@@ -25,8 +25,10 @@ class IconCustomFragment : IconFragment() {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
iconPickerViewModel.iconCustomAdded.observe(viewLifecycleOwner) { iconCustom ->
|
||||
iconAdapter.addIcon(IconImage(iconCustom))
|
||||
iconsGridView.smoothScrollToPosition(iconAdapter.lastPosition)
|
||||
if (!iconCustom.error) {
|
||||
iconAdapter.addIcon(IconImage(iconCustom.iconCustom))
|
||||
iconsGridView.smoothScrollToPosition(iconAdapter.lastPosition)
|
||||
}
|
||||
}
|
||||
|
||||
iconAdapter.iconPickerListener = object : IconAdapter.IconPickerListener {
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.kunzisoft.keepass.viewmodels
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.net.Uri
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
@@ -24,8 +26,8 @@ class IconPickerViewModel: ViewModel() {
|
||||
MutableLiveData<IconImageCustom>()
|
||||
}
|
||||
|
||||
val iconCustomAdded: MutableLiveData<IconImageCustom> by lazy {
|
||||
MutableLiveData<IconImageCustom>()
|
||||
val iconCustomAdded: MutableLiveData<IconCustomState> by lazy {
|
||||
MutableLiveData<IconCustomState>()
|
||||
}
|
||||
|
||||
fun selectIconStandard(icon: IconImageStandard) {
|
||||
@@ -52,14 +54,41 @@ class IconPickerViewModel: ViewModel() {
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
asyncResult.await()?.let { customIcon ->
|
||||
iconCustomAdded.value = customIcon
|
||||
// Remove icon if data cannot be saved
|
||||
var error = false
|
||||
if (customIcon.binaryFile.length <= 0) {
|
||||
database.removeCustomIcon(customIcon.uuid)
|
||||
error = true
|
||||
}
|
||||
iconCustomAdded.value = IconCustomState(customIcon, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class IconCustomState(val iconCustom: IconImageCustom, val error: Boolean): Parcelable {
|
||||
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readParcelable(IconImageCustom::class.java.classLoader) ?: IconImageCustom(),
|
||||
parcel.readByte() != 0.toByte())
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
parcel.writeParcelable(iconCustom, flags)
|
||||
parcel.writeByte(if (error) 1 else 0)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<IconCustomState> {
|
||||
override fun createFromParcel(parcel: Parcel): IconCustomState {
|
||||
return IconCustomState(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<IconCustomState?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user