From 59935a12b9336855c712d366e542aa6a37e8d041 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 17 Sep 2020 01:03:16 +0200 Subject: 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 --- .../android/activity/LogViewerActivity.kt | 23 ++++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'ui/src/main/java/com/wireguard/android/activity/LogViewerActivity.kt') 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 = ConcurrentHashMap() - private const val SHARE_ACTIVITY_REQUEST = 49133 } private inner class LogEntryAdapter : RecyclerView.Adapter() { -- cgit v1.2.3-59-g8ed1b