2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-01 06:35:09 +00:00

More code review changes

This commit is contained in:
Albert Vaca Cintora
2023-06-04 15:52:05 +02:00
parent 7d3cf9690a
commit afd4219732
3 changed files with 12 additions and 5 deletions

View File

@@ -208,7 +208,7 @@
android:launchMode="singleTask" android:launchMode="singleTask"
android:noHistory="true" android:noHistory="true"
android:screenOrientation="user" android:screenOrientation="user"
android:theme="@style/Theme.AppCompat.Light.Dialog" /> android:theme="@style/Theme.Material3.DayNight.Dialog" />
<service <service
android:name="org.kde.kdeconnect.Plugins.RunCommandPlugin.CommandsRemoteViewsService" android:name="org.kde.kdeconnect.Plugins.RunCommandPlugin.CommandsRemoteViewsService"

View File

@@ -29,14 +29,18 @@ internal class RunCommandWidgetDataProvider(private val context: Context, val in
override fun onDataSetChanged() {} override fun onDataSetChanged() {}
override fun onDestroy() {} override fun onDestroy() {}
private fun getPlugin(): RunCommandPlugin? {
return KdeConnect.getInstance().getDevicePlugin(deviceId, RunCommandPlugin::class.java)
}
override fun getCount(): Int { override fun getCount(): Int {
return KdeConnect.getInstance().getDevicePlugin(deviceId, RunCommandPlugin::class.java)?.commandItems?.size ?: 0 return getPlugin()?.commandItems?.size ?: 0
} }
override fun getViewAt(i: Int): RemoteViews { override fun getViewAt(i: Int): RemoteViews {
val remoteView = RemoteViews(context.packageName, R.layout.list_item_entry) val remoteView = RemoteViews(context.packageName, R.layout.list_item_entry)
val plugin : RunCommandPlugin? = KdeConnect.getInstance().getDevicePlugin(deviceId, RunCommandPlugin::class.java) val plugin : RunCommandPlugin? = getPlugin()
if (plugin == null) { if (plugin == null) {
Log.e("getViewAt", "RunCommandWidgetDataProvider: Plugin not found"); Log.e("getViewAt", "RunCommandWidgetDataProvider: Plugin not found");
return remoteView return remoteView
@@ -67,7 +71,7 @@ internal class RunCommandWidgetDataProvider(private val context: Context, val in
} }
override fun getItemId(i: Int): Long { override fun getItemId(i: Int): Long {
return KdeConnect.getInstance().getDevicePlugin(deviceId, RunCommandPlugin::class.java)?.commandItems?.get(i)?.key?.hashCode()?.toLong() ?: 0 return getPlugin()?.commandItems?.get(i)?.key?.hashCode()?.toLong() ?: 0
} }
override fun hasStableIds(): Boolean { override fun hasStableIds(): Boolean {

View File

@@ -47,7 +47,7 @@ class RunCommandWidgetProvider : AppWidgetProvider() {
} }
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
Log.e("WidgetProvider", "onReceive " + intent.action) Log.d("WidgetProvider", "onReceive " + intent.action)
if (intent.action == RUN_COMMAND_ACTION) { if (intent.action == RUN_COMMAND_ACTION) {
val targetCommand = intent.getStringExtra(TARGET_COMMAND) val targetCommand = intent.getStringExtra(TARGET_COMMAND)
@@ -94,6 +94,9 @@ internal fun updateAppWidget(
val views = RemoteViews(BuildConfig.APPLICATION_ID, R.layout.widget_remotecommandplugin) val views = RemoteViews(BuildConfig.APPLICATION_ID, R.layout.widget_remotecommandplugin)
val setDeviceIntent = Intent(context, RunCommandWidgetConfigActivity::class.java) val setDeviceIntent = Intent(context, RunCommandWidgetConfigActivity::class.java)
setDeviceIntent.putExtra(EXTRA_APPWIDGET_ID, appWidgetId) setDeviceIntent.putExtra(EXTRA_APPWIDGET_ID, appWidgetId)
// We pass appWidgetId as requestCode even if it's not used to force the creation a new PendingIntent
// instead of reusing an existing one, which is what happens if only the "extras" field differs.
// Docs: https://developer.android.com/reference/android/app/PendingIntent.html
val setDevicePendingIntent = PendingIntent.getActivity(context, appWidgetId, setDeviceIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) val setDevicePendingIntent = PendingIntent.getActivity(context, appWidgetId, setDeviceIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
views.setOnClickPendingIntent(R.id.runcommandWidgetTitleHeader, setDevicePendingIntent) views.setOnClickPendingIntent(R.id.runcommandWidgetTitleHeader, setDevicePendingIntent)