diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-09-17 01:03:16 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-09-17 14:50:37 +0200 |
commit | 59935a12b9336855c712d366e542aa6a37e8d041 (patch) | |
tree | 1a3ddd7cf67279366fab38d2593e8d07ebf1fc79 /ui/src/main/java/com/wireguard/android/activity/LogViewerActivity.kt | |
parent | DownloadsFileSaver: encapsulate permission checks (diff) | |
download | wireguard-android-59935a12b9336855c712d366e542aa6a37e8d041.tar.xz wireguard-android-59935a12b9336855c712d366e542aa6a37e8d041.zip |
activityx: use contracts more and refine
This is the beginning; there are still many of the old API's callsites
to convert.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/activity/LogViewerActivity.kt | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/ui/src/main/java/com/wireguard/android/activity/LogViewerActivity.kt b/ui/src/main/java/com/wireguard/android/activity/LogViewerActivity.kt index 19f67834..84cc6c7c 100644 --- a/ui/src/main/java/com/wireguard/android/activity/LogViewerActivity.kt +++ b/ui/src/main/java/com/wireguard/android/activity/LogViewerActivity.kt @@ -24,6 +24,7 @@ import android.view.Menu import android.view.MenuItem import android.view.View import android.view.ViewGroup +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ShareCompat import androidx.core.content.res.ResourcesCompat @@ -109,6 +110,10 @@ class LogViewerActivity : AppCompatActivity() { lifecycleScope.launch(Dispatchers.IO) { streamingLog() } + val revokeLastActivityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { + revokeLastUri() + } + binding.shareFab.setOnClickListener { revokeLastUri() val key = KeyPair().privateKey.toHex() @@ -122,15 +127,8 @@ class LogViewerActivity : AppCompatActivity() { .createChooserIntent() .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) grantUriPermission("android", lastUri, Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(shareIntent, SHARE_ACTIVITY_REQUEST) - } - } - - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - if (requestCode == SHARE_ACTIVITY_REQUEST) { - revokeLastUri() + revokeLastActivityResultLauncher.launch(shareIntent) } - super.onActivityResult(requestCode, resultCode, data) } override fun onCreateOptionsMenu(menu: Menu?): Boolean { @@ -207,10 +205,10 @@ class LogViewerActivity : AppCompatActivity() { it.scrollToPosition(logLines.size - 1) } } else { - /* I'd prefer for the next line to be: - * logLines.lastOrNull()?.msg += "\n$line" - * However, as of writing, that causes the kotlin compiler to freak out and crash, spewing bytecode. - */ + /* TODO: I'd prefer for the next line to be: + * logLines.lastOrNull()?.msg += "\n$line" + * However, as of writing, that causes the kotlin compiler to freak out and crash, spewing bytecode. + */ logLines.lastOrNull()?.apply { msg += "\n$line" } if (haveScrolled) logAdapter.notifyDataSetChanged() } @@ -259,7 +257,6 @@ class LogViewerActivity : AppCompatActivity() { */ private val THREADTIME_LINE: Pattern = Pattern.compile("^(\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3})(?:\\s+[0-9A-Za-z]+)?\\s+(\\d+)\\s+(\\d+)\\s+([A-Z])\\s+(.+?)\\s*: (.*)$") private val LOGS: MutableMap<String, ByteArray> = ConcurrentHashMap() - private const val SHARE_ACTIVITY_REQUEST = 49133 } private inner class LogEntryAdapter : RecyclerView.Adapter<LogEntryAdapter.ViewHolder>() { |