Skip to content

Commit c7dd619

Browse files
committed
Address Gemini code assist recommendations
Change-Id: Idd34787d0ff31601fc09d034a69cdd20e8287be8
1 parent 65edf7c commit c7dd619

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

samples/user-interface/share/src/main/java/com/example/platform/ui/share/sender/ShareResultReceiver.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import android.service.chooser.ChooserResult
2525
import android.service.chooser.ChooserResult.CHOOSER_RESULT_COPY
2626
import android.service.chooser.ChooserResult.CHOOSER_RESULT_EDIT
2727
import android.service.chooser.ChooserResult.CHOOSER_RESULT_SELECTED_COMPONENT
28-
import android.service.chooser.ChooserResult.CHOOSER_RESULT_UNKNOWN
2928
import android.util.Log
3029
import androidx.annotation.RequiresApi
3130
import androidx.core.content.IntentCompat
@@ -43,13 +42,12 @@ class ShareResultReceiver : BroadcastReceiver() {
4342
Intent.EXTRA_CHOOSER_RESULT,
4443
ChooserResult::class.java,
4544
)
46-
if (chooserResult != null) {
47-
Log.i(TAG, "isShortcut: ${chooserResult.isShortcut}")
48-
Log.i(TAG, "type: ${typeToString(chooserResult.type)}")
49-
Log.i(TAG, "componentName: ${chooserResult.selectedComponent}")
50-
} else {
51-
Log.i(TAG, "chooserResult is null")
52-
}
45+
chooserResult?.let {
46+
Log.i(
47+
TAG,
48+
"Share callback: isShortcut: ${it.isShortcut}, type: ${typeToString(it.type)}, componentName: ${it.selectedComponent}",
49+
)
50+
} ?: Log.i(TAG, "chooserResult is null")
5351
} else {
5452
// This ComponentName represents the Activity that has received the data we shared.
5553
val componentName: ComponentName? = IntentCompat.getParcelableExtra(
@@ -66,7 +64,6 @@ class ShareResultReceiver : BroadcastReceiver() {
6664
CHOOSER_RESULT_SELECTED_COMPONENT -> "SELECTED_COMPONENT"
6765
CHOOSER_RESULT_COPY -> "COPY"
6866
CHOOSER_RESULT_EDIT -> "EDIT"
69-
CHOOSER_RESULT_UNKNOWN -> "UNKNOWN"
7067
else -> "UNKNOWN"
7168
}
7269
}

samples/user-interface/share/src/main/java/com/example/platform/ui/share/sender/ShareSender.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,21 @@ private val filenames = listOf(
9999
"night_highrise.jpg",
100100
)
101101

102+
private const val PLAIN_TEXT_CONTENT = "Hello, world!"
103+
private const val PLAIN_TEXT_TYPE = "text/plain"
104+
private const val SHARE_TEXT_REQUEST_CODE = 1234
105+
102106
/**
103107
* Shares a text message and demonstrates how to set up a BroadcastReceiver to be
104108
* notified who has received the data we shared. See [ShareResultReceiver].
105109
*/
106110
private fun sharePlainText(context: Context) {
107111
if (Build.VERSION.SDK_INT >= 22) {
108112
val share = Intent(Intent.ACTION_SEND)
109-
share.setType("text/plain")
110-
share.putExtra(Intent.EXTRA_TEXT,"Hello, world!")
113+
share.setType(PLAIN_TEXT_TYPE)
114+
share.putExtra(Intent.EXTRA_TEXT, PLAIN_TEXT_CONTENT)
111115
val pendingIntent = PendingIntent.getBroadcast(
112-
context, 1234,
116+
context, SHARE_TEXT_REQUEST_CODE,
113117
Intent(context, ShareResultReceiver::class.java),
114118
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
115119
)
@@ -118,8 +122,8 @@ private fun sharePlainText(context: Context) {
118122
)
119123
} else {
120124
context.startActivity(ShareCompat.IntentBuilder(context)
121-
.setType("text/plain")
122-
.setText("Hello, world!")
125+
.setType(PLAIN_TEXT_TYPE)
126+
.setText(PLAIN_TEXT_CONTENT)
123127
.createChooserIntent()
124128
)
125129
}

0 commit comments

Comments
 (0)