Fix read only mode and back pressed

This commit is contained in:
J-Jamet
2020-10-17 15:35:01 +02:00
parent b4d26fd35a
commit 49297adf97
4 changed files with 51 additions and 31 deletions

View File

@@ -315,7 +315,7 @@ class EntryEditActivity : LockingActivity(),
entryValidatedForAutofillSelection(entry)
},
{
entryValidatedForRegistration()
onValidateSpecialMode()
}
)
}
@@ -330,6 +330,12 @@ class EntryEditActivity : LockingActivity(),
}
}
override fun onValidateSpecialMode() {
super.onValidateSpecialMode()
// Don't keep activity history for entry edition
finish()
}
private fun entryValidatedForKeyboardSelection(entry: Entry) {
// Populate Magikeyboard with entry
mDatabase?.let { database ->
@@ -337,8 +343,7 @@ class EntryEditActivity : LockingActivity(),
entry.getEntryInfo(database),
intent)
}
super.onCancelSpecialMode()
finish()
onValidateSpecialMode()
}
private fun entryValidatedForAutofillSelection(entry: Entry) {
@@ -349,14 +354,7 @@ class EntryEditActivity : LockingActivity(),
entry.getEntryInfo(database))
}
}
super.onCancelSpecialMode()
super.finish()
}
private fun entryValidatedForRegistration() {
// Entry registered, finish naturally
super.onCancelSpecialMode()
finish()
onValidateSpecialMode()
}
override fun onResume() {
@@ -742,7 +740,6 @@ class EntryEditActivity : LockingActivity(),
override fun onCancelSpecialMode() {
onApprovedBackPressed {
super.onCancelSpecialMode()
finish()
}
}

View File

@@ -219,17 +219,14 @@ class GroupActivity : LockingActivity(),
}
},
{ searchInfo ->
if (PreferencesUtil.isKeyboardSaveSearchInfoEnable(this@GroupActivity)) {
mCurrentGroup?.let { currentGroup ->
EntryEditActivity.launchForKeyboardSelectionResult(this@GroupActivity,
currentGroup, searchInfo)
}
mCurrentGroup?.let { currentGroup ->
EntryEditActivity.launchForKeyboardSelectionResult(this@GroupActivity,
currentGroup, searchInfo)
}
},
{ searchInfo, assistStructure ->
var finishActivity = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& PreferencesUtil.isAutofillSaveSearchInfoEnable(this@GroupActivity)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mCurrentGroup?.let { currentGroup ->
assistStructure?.let { autofillStructure ->
finishActivity = false
@@ -582,14 +579,14 @@ class GroupActivity : LockingActivity(),
EntryActivity.launch(this@GroupActivity, entryVersioned, mReadOnly)
},
{ searchInfo ->
if (PreferencesUtil.isKeyboardSaveSearchInfoEnable(this@GroupActivity)) {
if (!mReadOnly && PreferencesUtil.isKeyboardSaveSearchInfoEnable(this@GroupActivity)) {
updateEntryWithSearchInfo(entryVersioned, searchInfo)
} else {
entrySelectedForKeyboardSelection(entryVersioned)
}
},
{ searchInfo, _ ->
if (PreferencesUtil.isAutofillSaveSearchInfoEnable(this@GroupActivity)) {
if (!mReadOnly && PreferencesUtil.isAutofillSaveSearchInfoEnable(this@GroupActivity)) {
updateEntryWithSearchInfo(entryVersioned, searchInfo)
} else {
entrySelectedForAutofillSelection(entryVersioned)
@@ -612,7 +609,7 @@ class GroupActivity : LockingActivity(),
entry.getEntryInfo(database),
intent)
}
super.onCancelSpecialMode()
onValidateSpecialMode()
}
private fun entrySelectedForAutofillSelection(entry: Entry) {
@@ -623,7 +620,7 @@ class GroupActivity : LockingActivity(),
entry.getEntryInfo(database))
}
}
super.onCancelSpecialMode()
onValidateSpecialMode()
}
private fun entrySelectedForRegistration(entry: Entry, registerInfo: RegisterInfo?) {
@@ -632,8 +629,7 @@ class GroupActivity : LockingActivity(),
// TODO box update confirmation
EntryEditActivity.launchForRegistration(this@GroupActivity,
entry, registerInfo)
super.onCancelSpecialMode()
finish()
onValidateSpecialMode()
}
private fun updateEntryWithSearchInfo(entry: Entry, searchInfo: SearchInfo?) {
@@ -1121,7 +1117,7 @@ class GroupActivity : LockingActivity(),
}
}
override fun onCancelSpecialMode() {
private fun removeFragmentHistory() {
val fragmentManager = supportFragmentManager
if (mSelectionModeCountBackStack > 0) {
for (selectionMode in 0 .. mSelectionModeCountBackStack) {
@@ -1130,6 +1126,15 @@ class GroupActivity : LockingActivity(),
}
// Reinit the counter for navigation history
mSelectionModeCountBackStack = 0
}
override fun onValidateSpecialMode() {
removeFragmentHistory()
super.onValidateSpecialMode()
}
override fun onCancelSpecialMode() {
removeFragmentHistory()
super.onCancelSpecialMode()
}

View File

@@ -632,7 +632,7 @@ open class PasswordActivity : SpecialModeActivity() {
val inflater = menuInflater
// Read menu
inflater.inflate(R.menu.open_file, menu)
if (mSpecialMode != SpecialMode.DEFAULT || mForceReadOnly) {
if (mForceReadOnly) {
menu.removeItem(R.id.menu_open_file_read_mode_key)
} else {
changeOpenFileReadIcon(menu.findItem(R.id.menu_open_file_read_mode_key))

View File

@@ -47,12 +47,30 @@ abstract class SpecialModeActivity : StylishActivity() {
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
}
open fun onCancelSpecialMode() {
if (!isIntentSender()) {
open fun onValidateSpecialMode() {
if (isIntentSender()) {
super.finish()
} else {
EntrySelectionHelper.removeModesFromIntent(intent)
EntrySelectionHelper.removeInfoFromIntent(intent)
if (mSpecialMode != SpecialMode.DEFAULT)
backToTheAppCaller()
if (mSpecialMode != SpecialMode.DEFAULT) {
// To move the app in background
moveTaskToBack(true)
}
}
}
open fun onCancelSpecialMode() {
if (isIntentSender()) {
// To get the app caller, only for IntentSender
super.onBackPressed()
} else {
EntrySelectionHelper.removeModesFromIntent(intent)
EntrySelectionHelper.removeInfoFromIntent(intent)
if (mSpecialMode != SpecialMode.DEFAULT) {
// To move the app in background
moveTaskToBack(true)
}
}
}