Fix last entry in Magikeyboard memory #653

This commit is contained in:
J-Jamet
2020-08-05 14:19:37 +02:00
parent d33ed52ec2
commit 71d84d76f8
2 changed files with 21 additions and 1 deletions

View File

@@ -70,6 +70,13 @@ class Database {
val drawFactory = IconDrawableFactory() val drawFactory = IconDrawableFactory()
var loaded = false var loaded = false
set(value) {
field = value
loadTimestamp = if (field) System.currentTimeMillis() else null
}
var loadTimestamp: Long? = null
private set
val iconFactory: IconImageFactory val iconFactory: IconImageFactory
get() { get() {

View File

@@ -108,8 +108,17 @@ class MagikIME : InputMethodService(), KeyboardView.OnKeyboardActionListener {
val closeView = popupFieldsView.findViewById<View>(R.id.keyboard_popup_close) val closeView = popupFieldsView.findViewById<View>(R.id.keyboard_popup_close)
closeView.setOnClickListener { popupCustomKeys?.dismiss() } closeView.setOnClickListener { popupCustomKeys?.dismiss() }
if (!Database.getInstance().loaded) // Remove entry info if the database is not loaded
// or if entry info timestamp is before database loaded timestamp
val database = Database.getInstance()
val databaseTime = database.loadTimestamp
val entryTime = entryInfoTimestamp
if (!database.loaded
|| databaseTime == null
|| entryTime == null
|| entryTime < databaseTime) {
removeEntryInfo() removeEntryInfo()
}
assignKeyboardView() assignKeyboardView()
keyboardView?.setOnKeyboardActionListener(this) keyboardView?.setOnKeyboardActionListener(this)
keyboardView?.isPreviewEnabled = false keyboardView?.isPreviewEnabled = false
@@ -321,10 +330,13 @@ class MagikIME : InputMethodService(), KeyboardView.OnKeyboardActionListener {
private const val KEY_URL = 520 private const val KEY_URL = 520
private const val KEY_FIELDS = 530 private const val KEY_FIELDS = 530
// TODO Retrieve entry info from id and service when database is open
private var entryInfoKey: EntryInfo? = null private var entryInfoKey: EntryInfo? = null
private var entryInfoTimestamp: Long? = null
private fun removeEntryInfo() { private fun removeEntryInfo() {
entryInfoKey = null entryInfoKey = null
entryInfoTimestamp = null
} }
fun removeEntry(context: Context) { fun removeEntry(context: Context) {
@@ -334,6 +346,7 @@ class MagikIME : InputMethodService(), KeyboardView.OnKeyboardActionListener {
fun addEntryAndLaunchNotificationIfAllowed(context: Context, entry: EntryInfo, toast: Boolean = false) { fun addEntryAndLaunchNotificationIfAllowed(context: Context, entry: EntryInfo, toast: Boolean = false) {
// Add a new entry // Add a new entry
entryInfoKey = entry entryInfoKey = entry
entryInfoTimestamp = System.currentTimeMillis()
// Launch notification if allowed // Launch notification if allowed
KeyboardEntryNotificationService.launchNotificationIfAllowed(context, entry, toast) KeyboardEntryNotificationService.launchNotificationIfAllowed(context, entry, toast)
} }