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>
This commit is contained in:
parent
9255583f2d
commit
9787489bc5
2 changed files with 5 additions and 6 deletions
|
@ -481,7 +481,7 @@ class UserPreference : AppCompatActivity() {
|
||||||
// TODO: This is fragile. Workaround until PasswordItem is backed by DocumentFile
|
// TODO: This is fragile. Workaround until PasswordItem is backed by DocumentFile
|
||||||
val docId = DocumentsContract.getTreeDocumentId(uri)
|
val docId = DocumentsContract.getTreeDocumentId(uri)
|
||||||
val split = docId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
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")
|
Timber.tag(TAG).d("Selected repository path is $repoPath")
|
||||||
|
|
||||||
|
|
|
@ -22,18 +22,17 @@ import org.apache.commons.io.FileUtils
|
||||||
|
|
||||||
class ShowSshKeyFragment : DialogFragment() {
|
class ShowSshKeyFragment : DialogFragment() {
|
||||||
|
|
||||||
private lateinit var activity: SshKeyGenActivity
|
|
||||||
private lateinit var builder: MaterialAlertDialogBuilder
|
private lateinit var builder: MaterialAlertDialogBuilder
|
||||||
private lateinit var publicKey: TextView
|
private lateinit var publicKey: TextView
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
activity = requireActivity() as SshKeyGenActivity
|
builder = MaterialAlertDialogBuilder(requireActivity())
|
||||||
builder = MaterialAlertDialogBuilder(activity)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
|
val activity = requireActivity()
|
||||||
val view = activity.layoutInflater.inflate(R.layout.fragment_show_ssh_key, null)
|
val view = activity.layoutInflater.inflate(R.layout.fragment_show_ssh_key, null)
|
||||||
publicKey = view.findViewById(R.id.public_key)
|
publicKey = view.findViewById(R.id.public_key)
|
||||||
readKeyFromFile()
|
readKeyFromFile()
|
||||||
|
@ -53,13 +52,13 @@ class ShowSshKeyFragment : DialogFragment() {
|
||||||
private fun createMaterialDialog(view: View) {
|
private fun createMaterialDialog(view: View) {
|
||||||
builder.setView(view)
|
builder.setView(view)
|
||||||
builder.setTitle(getString(R.string.your_public_key))
|
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.setNegativeButton(getString(R.string.dialog_cancel), null)
|
||||||
builder.setNeutralButton(resources.getString(R.string.ssh_keygen_copy), null)
|
builder.setNeutralButton(resources.getString(R.string.ssh_keygen_copy), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readKeyFromFile() {
|
private fun readKeyFromFile() {
|
||||||
val file = File(activity.filesDir.toString() + "/.ssh_key.pub")
|
val file = File(requireActivity().filesDir.toString() + "/.ssh_key.pub")
|
||||||
try {
|
try {
|
||||||
publicKey.text = FileUtils.readFileToString(file, StandardCharsets.UTF_8)
|
publicKey.text = FileUtils.readFileToString(file, StandardCharsets.UTF_8)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
Loading…
Reference in a new issue