summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorHarsh Shandilya <msfjarvis@gmail.com>2020-02-21 12:42:27 +0530
committerGitHub <noreply@github.com>2020-02-21 12:42:27 +0530
commit9787489bc5b7e7bb10ab92e257d31fef50fe9255 (patch)
tree5938a1bb282f64994bf090871e23bcfd5dd65046 /app/src/main/java
parent9255583f2d0e5cfb7a88ee54ceb4f5284d41cbfa (diff)
Resolve some crashes reported on Play Store (#631)
* ShowSshKeyFragment: Resolve illegal casts * UserPreference: Try harder to not crash Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.kt2
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt9
2 files changed, 5 insertions, 6 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt b/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
index bce432ea..469e3773 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.kt
@@ -481,7 +481,7 @@ class UserPreference : AppCompatActivity() {
// TODO: This is fragile. Workaround until PasswordItem is backed by DocumentFile
val docId = DocumentsContract.getTreeDocumentId(uri)
val split = docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
- val repoPath = "${Environment.getExternalStorageDirectory()}/${split[1]}"
+ val repoPath = "${Environment.getExternalStorageDirectory()}/${split[1] ?: split[0]}"
Timber.tag(TAG).d("Selected repository path is $repoPath")
diff --git a/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt b/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt
index a44b3599..e3395d41 100644
--- a/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt
@@ -22,18 +22,17 @@ import org.apache.commons.io.FileUtils
class ShowSshKeyFragment : DialogFragment() {
- private lateinit var activity: SshKeyGenActivity
private lateinit var builder: MaterialAlertDialogBuilder
private lateinit var publicKey: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- activity = requireActivity() as SshKeyGenActivity
- builder = MaterialAlertDialogBuilder(activity)
+ builder = MaterialAlertDialogBuilder(requireActivity())
}
@SuppressLint("InflateParams")
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+ val activity = requireActivity()
val view = activity.layoutInflater.inflate(R.layout.fragment_show_ssh_key, null)
publicKey = view.findViewById(R.id.public_key)
readKeyFromFile()
@@ -53,13 +52,13 @@ class ShowSshKeyFragment : DialogFragment() {
private fun createMaterialDialog(view: View) {
builder.setView(view)
builder.setTitle(getString(R.string.your_public_key))
- builder.setPositiveButton(getString(R.string.dialog_ok)) { _, _ -> activity.finish() }
+ builder.setPositiveButton(getString(R.string.dialog_ok)) { _, _ -> requireActivity().finish() }
builder.setNegativeButton(getString(R.string.dialog_cancel), null)
builder.setNeutralButton(resources.getString(R.string.ssh_keygen_copy), null)
}
private fun readKeyFromFile() {
- val file = File(activity.filesDir.toString() + "/.ssh_key.pub")
+ val file = File(requireActivity().filesDir.toString() + "/.ssh_key.pub")
try {
publicKey.text = FileUtils.readFileToString(file, StandardCharsets.UTF_8)
} catch (e: Exception) {