Fix clear database

This commit is contained in:
J-Jamet
2021-08-04 17:41:38 +02:00
parent 65f4a708cd
commit 0ced9c8e26
3 changed files with 37 additions and 36 deletions

View File

@@ -71,7 +71,7 @@ abstract class LockingActivity : SpecialModeActivity(),
mReadOnlyToSave = value mReadOnlyToSave = value
} }
private var mReadOnlyToSave: Boolean = false private var mReadOnlyToSave: Boolean = false
protected var mAutoSaveEnable: Boolean = true private var mAutoSaveEnable: Boolean = true
protected var mIconDrawableFactory: IconDrawableFactory? = null protected var mIconDrawableFactory: IconDrawableFactory? = null
@@ -88,45 +88,46 @@ abstract class LockingActivity : SpecialModeActivity(),
intent.getBooleanExtra(TIMEOUT_ENABLE_KEY, TIMEOUT_ENABLE_KEY_DEFAULT) intent.getBooleanExtra(TIMEOUT_ENABLE_KEY, TIMEOUT_ENABLE_KEY_DEFAULT)
} }
if (mTimeoutEnable) {
mLockReceiver = LockReceiver {
closeDatabase()
if (LOCKING_ACTIVITY_UI_VISIBLE_DURING_LOCK == null)
LOCKING_ACTIVITY_UI_VISIBLE_DURING_LOCK = LOCKING_ACTIVITY_UI_VISIBLE
// Add onActivityForResult response
setResult(RESULT_EXIT_LOCK)
closeOptionsMenu()
finish()
}
registerLockReceiver(mLockReceiver)
}
mExitLock = false mExitLock = false
} }
override fun onDatabaseRetrieved(database: Database?) { override fun onDatabaseRetrieved(database: Database?) {
super.onDatabaseRetrieved(database) super.onDatabaseRetrieved(database)
mDatabase = database mDatabase = database
// End activity if database not loaded
if (database?.loaded != true) {
finish()
}
// check timeout
if (mTimeoutEnable) {
// After the first creation
// or If simply swipe with another application
// If the time is out -> close the Activity
TimeoutHelper.checkTimeAndLockIfTimeout(this)
// If onCreate already record time
database?.let { it ->
if (!mExitLock)
TimeoutHelper.recordTime(this, it)
}
}
// Force read only if the database is like that database?.let {
mReadOnly = database?.isReadOnly != false || mReadOnly // End activity if database not loaded
mIconDrawableFactory = database?.iconDrawableFactory if (!database.loaded) {
finish()
}
// check timeout
if (mTimeoutEnable) {
if (mLockReceiver == null) {
mLockReceiver = LockReceiver {
closeDatabase(database)
if (LOCKING_ACTIVITY_UI_VISIBLE_DURING_LOCK == null)
LOCKING_ACTIVITY_UI_VISIBLE_DURING_LOCK = LOCKING_ACTIVITY_UI_VISIBLE
// Add onActivityForResult response
setResult(RESULT_EXIT_LOCK)
closeOptionsMenu()
finish()
}
registerLockReceiver(mLockReceiver)
}
// After the first creation
// or If simply swipe with another application
// If the time is out -> close the Activity
TimeoutHelper.checkTimeAndLockIfTimeout(this)
// If onCreate already record time
if (!mExitLock)
TimeoutHelper.recordTime(this, database)
}
// Force read only if the database is like that
mReadOnly = database.isReadOnly || mReadOnly
mIconDrawableFactory = database.iconDrawableFactory
}
} }
override fun onDatabaseActionFinished( override fun onDatabaseActionFinished(

View File

@@ -471,7 +471,7 @@ open class DatabaseTaskNotificationService : LockNotificationService(), Progress
override fun actionOnLock() { override fun actionOnLock() {
if (!TimeoutHelper.temporarilyDisableTimeout) { if (!TimeoutHelper.temporarilyDisableTimeout) {
closeDatabase() closeDatabase(mDatabase)
// Remove the lock timer (no more needed if it exists) // Remove the lock timer (no more needed if it exists)
TimeoutHelper.cancelLockTimer(this) TimeoutHelper.cancelLockTimer(this)
// Service is stopped after receive the broadcast // Service is stopped after receive the broadcast

View File

@@ -125,7 +125,7 @@ fun Context.unregisterLockReceiver(lockReceiver: LockReceiver?) {
} }
} }
fun Context.closeDatabase() { fun Context.closeDatabase(database: Database) {
// Stop the Magikeyboard service // Stop the Magikeyboard service
stopService(Intent(this, KeyboardEntryNotificationService::class.java)) stopService(Intent(this, KeyboardEntryNotificationService::class.java))
MagikIME.removeEntry(this) MagikIME.removeEntry(this)
@@ -138,5 +138,5 @@ fun Context.closeDatabase() {
cancelAll() cancelAll()
} }
// Clear data // Clear data
// TODO Database.getInstance().clearAndClose(this) database.clearAndClose(this)
} }