-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
38 changed files
with
1,066 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...src/main/java/com/kunzisoft/keepass/activities/dialogs/AskMainCredentialDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright 2022 Jeremy Jamet / Kunzisoft. | ||
* | ||
* This file is part of KeePassDX. | ||
* | ||
* KeePassDX is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* KeePassDX is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
package com.kunzisoft.keepass.activities.dialogs | ||
|
||
import android.app.Dialog | ||
import android.content.Context | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AlertDialog | ||
import com.kunzisoft.keepass.activities.helpers.ExternalFileHelper | ||
import com.kunzisoft.keepass.model.MainCredential | ||
import com.kunzisoft.keepass.utils.UriUtil | ||
import com.kunzisoft.keepass.view.MainCredentialView | ||
|
||
class AskMainCredentialDialogFragment : DatabaseDialogFragment() { | ||
|
||
private var mainCredentialView: MainCredentialView? = null | ||
|
||
private var mListener: AskMainCredentialDialogListener? = null | ||
|
||
private var mExternalFileHelper: ExternalFileHelper? = null | ||
|
||
interface AskMainCredentialDialogListener { | ||
fun onAskMainCredentialDialogPositiveClick(databaseUri: Uri?, mainCredential: MainCredential) | ||
fun onAskMainCredentialDialogNegativeClick(databaseUri: Uri?, mainCredential: MainCredential) | ||
} | ||
|
||
override fun onAttach(activity: Context) { | ||
super.onAttach(activity) | ||
try { | ||
mListener = activity as AskMainCredentialDialogListener | ||
} catch (e: ClassCastException) { | ||
throw ClassCastException(activity.toString() | ||
+ " must implement " + AskMainCredentialDialogListener::class.java.name) | ||
} | ||
} | ||
|
||
override fun onDetach() { | ||
mListener = null | ||
super.onDetach() | ||
} | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
activity?.let { activity -> | ||
|
||
var databaseUri: Uri? = null | ||
arguments?.apply { | ||
if (containsKey(KEY_ASK_CREDENTIAL_URI)) | ||
databaseUri = getParcelable(KEY_ASK_CREDENTIAL_URI) | ||
} | ||
|
||
val builder = AlertDialog.Builder(activity) | ||
|
||
mainCredentialView = MainCredentialView(activity) | ||
databaseUri?.let { | ||
builder.setTitle(UriUtil.getFileData(requireContext(), it)?.name) | ||
} | ||
builder.setView(mainCredentialView) | ||
// Add action buttons | ||
.setPositiveButton(android.R.string.ok) { _, _ -> | ||
mListener?.onAskMainCredentialDialogPositiveClick( | ||
databaseUri, | ||
retrieveMainCredential() | ||
) | ||
} | ||
.setNegativeButton(android.R.string.cancel) { _, _ -> | ||
mListener?.onAskMainCredentialDialogNegativeClick( | ||
databaseUri, | ||
retrieveMainCredential() | ||
) | ||
} | ||
|
||
|
||
mExternalFileHelper = ExternalFileHelper(this) | ||
mExternalFileHelper?.buildOpenDocument { uri -> | ||
if (uri != null) { | ||
mainCredentialView?.populateKeyFileTextView(uri) | ||
} | ||
} | ||
mainCredentialView?.setOpenKeyfileClickListener(mExternalFileHelper) | ||
|
||
return builder.create() | ||
} | ||
|
||
return super.onCreateDialog(savedInstanceState) | ||
} | ||
|
||
private fun retrieveMainCredential(): MainCredential { | ||
return mainCredentialView?.getMainCredential() ?: MainCredential() | ||
} | ||
|
||
companion object { | ||
|
||
private const val KEY_ASK_CREDENTIAL_URI = "KEY_ASK_CREDENTIAL_URI" | ||
const val TAG_ASK_MAIN_CREDENTIAL = "TAG_ASK_MAIN_CREDENTIAL" | ||
|
||
fun getInstance(uri: Uri?): AskMainCredentialDialogFragment { | ||
val fragment = AskMainCredentialDialogFragment() | ||
val args = Bundle() | ||
args.putParcelable(KEY_ASK_CREDENTIAL_URI, uri) | ||
fragment.arguments = args | ||
return fragment | ||
} | ||
} | ||
} |
Oops, something went wrong.