Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 9787489

Browse files
authored
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>
1 parent 9255583 commit 9787489

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

app/src/main/java/com/zeapo/pwdstore/UserPreference.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ class UserPreference : AppCompatActivity() {
481481
// TODO: This is fragile. Workaround until PasswordItem is backed by DocumentFile
482482
val docId = DocumentsContract.getTreeDocumentId(uri)
483483
val split = docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
484-
val repoPath = "${Environment.getExternalStorageDirectory()}/${split[1]}"
484+
val repoPath = "${Environment.getExternalStorageDirectory()}/${split[1] ?: split[0]}"
485485

486486
Timber.tag(TAG).d("Selected repository path is $repoPath")
487487

app/src/main/java/com/zeapo/pwdstore/sshkeygen/ShowSshKeyFragment.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@ import org.apache.commons.io.FileUtils
2222

2323
class ShowSshKeyFragment : DialogFragment() {
2424

25-
private lateinit var activity: SshKeyGenActivity
2625
private lateinit var builder: MaterialAlertDialogBuilder
2726
private lateinit var publicKey: TextView
2827

2928
override fun onCreate(savedInstanceState: Bundle?) {
3029
super.onCreate(savedInstanceState)
31-
activity = requireActivity() as SshKeyGenActivity
32-
builder = MaterialAlertDialogBuilder(activity)
30+
builder = MaterialAlertDialogBuilder(requireActivity())
3331
}
3432

3533
@SuppressLint("InflateParams")
3634
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
35+
val activity = requireActivity()
3736
val view = activity.layoutInflater.inflate(R.layout.fragment_show_ssh_key, null)
3837
publicKey = view.findViewById(R.id.public_key)
3938
readKeyFromFile()
@@ -53,13 +52,13 @@ class ShowSshKeyFragment : DialogFragment() {
5352
private fun createMaterialDialog(view: View) {
5453
builder.setView(view)
5554
builder.setTitle(getString(R.string.your_public_key))
56-
builder.setPositiveButton(getString(R.string.dialog_ok)) { _, _ -> activity.finish() }
55+
builder.setPositiveButton(getString(R.string.dialog_ok)) { _, _ -> requireActivity().finish() }
5756
builder.setNegativeButton(getString(R.string.dialog_cancel), null)
5857
builder.setNeutralButton(resources.getString(R.string.ssh_keygen_copy), null)
5958
}
6059

6160
private fun readKeyFromFile() {
62-
val file = File(activity.filesDir.toString() + "/.ssh_key.pub")
61+
val file = File(requireActivity().filesDir.toString() + "/.ssh_key.pub")
6362
try {
6463
publicKey.text = FileUtils.readFileToString(file, StandardCharsets.UTF_8)
6564
} catch (e: Exception) {

0 commit comments

Comments
 (0)