mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 21:55:10 +00:00
Use view binding in RunCommandActivity.
This commit is contained in:
committed by
Nicolas Fella
parent
74f9aba31a
commit
32c9dc5ad5
@@ -5,7 +5,7 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/runcommandslist"
|
||||
android:id="@+id/run_commands_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="4dp"
|
||||
@@ -20,11 +20,11 @@
|
||||
android:layout_margin="16dp"
|
||||
app:srcCompat="@drawable/ic_action_image_edit_24dp"
|
||||
app:backgroundTint="@color/primary"
|
||||
app:layout_anchor="@id/runcommandslist"
|
||||
app:layout_anchor="@id/run_commands_list"
|
||||
app:layout_anchorGravity="bottom|end" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/addcomand_explanation"
|
||||
android:id="@+id/add_comand_explanation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
@@ -29,7 +29,7 @@
|
||||
|
||||
</LinearLayout>
|
||||
<ListView
|
||||
android:id="@+id/runcommandslist"
|
||||
android:id="@+id/run_commands_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="4dp"
|
||||
|
@@ -30,8 +30,6 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
@@ -39,14 +37,13 @@ import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.kde.kdeconnect.BackgroundService;
|
||||
import org.kde.kdeconnect.UserInterface.List.ListAdapter;
|
||||
import org.kde.kdeconnect.UserInterface.ThemeUtil;
|
||||
import org.kde.kdeconnect_tp.R;
|
||||
import org.kde.kdeconnect_tp.databinding.ActivityRunCommandBinding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -54,15 +51,14 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class RunCommandActivity extends AppCompatActivity {
|
||||
private ActivityRunCommandBinding binding;
|
||||
private String deviceId;
|
||||
private final RunCommandPlugin.CommandsChangedCallback commandsChangedCallback = this::updateView;
|
||||
private List<CommandEntry> commandItems;
|
||||
|
||||
private void updateView() {
|
||||
BackgroundService.RunWithPlugin(this, deviceId, RunCommandPlugin.class, plugin -> runOnUiThread(() -> {
|
||||
ListView view = findViewById(R.id.runcommandslist);
|
||||
|
||||
registerForContextMenu(view);
|
||||
registerForContextMenu(binding.runCommandsList);
|
||||
|
||||
commandItems = new ArrayList<>();
|
||||
for (JSONObject obj : plugin.getCommandList()) {
|
||||
@@ -78,16 +74,16 @@ public class RunCommandActivity extends AppCompatActivity {
|
||||
|
||||
ListAdapter adapter = new ListAdapter(RunCommandActivity.this, commandItems);
|
||||
|
||||
view.setAdapter(adapter);
|
||||
view.setOnItemClickListener((adapterView, view1, i, l) -> plugin.runCommand(commandItems.get(i).getKey()));
|
||||
binding.runCommandsList.setAdapter(adapter);
|
||||
binding.runCommandsList.setOnItemClickListener((adapterView, view1, i, l) ->
|
||||
plugin.runCommand(commandItems.get(i).getKey()));
|
||||
|
||||
TextView explanation = findViewById(R.id.addcomand_explanation);
|
||||
String text = getString(R.string.addcommand_explanation);
|
||||
if (!plugin.canAddCommand()) {
|
||||
text += "\n" + getString(R.string.addcommand_explanation2);
|
||||
}
|
||||
explanation.setText(text);
|
||||
explanation.setVisibility(commandItems.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
binding.addComandExplanation.setText(text);
|
||||
binding.addComandExplanation.setVisibility(commandItems.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -95,7 +91,9 @@ public class RunCommandActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ThemeUtil.setUserPreferredTheme(this);
|
||||
setContentView(R.layout.activity_runcommand);
|
||||
|
||||
binding = ActivityRunCommandBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
deviceId = getIntent().getStringExtra("deviceId");
|
||||
|
||||
@@ -105,14 +103,13 @@ public class RunCommandActivity extends AppCompatActivity {
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
|
||||
FloatingActionButton addCommandButton = findViewById(R.id.add_command_button);
|
||||
if (canAddCommands) {
|
||||
addCommandButton.show();
|
||||
binding.addCommandButton.show();
|
||||
} else {
|
||||
addCommandButton.hide();
|
||||
binding.addCommandButton.hide();
|
||||
}
|
||||
|
||||
addCommandButton.setOnClickListener(v -> BackgroundService.RunWithPlugin(RunCommandActivity.this, deviceId, RunCommandPlugin.class, plugin -> {
|
||||
binding.addCommandButton.setOnClickListener(v -> BackgroundService.RunWithPlugin(RunCommandActivity.this, deviceId, RunCommandPlugin.class, plugin -> {
|
||||
plugin.sendSetupPacket();
|
||||
new AlertDialog.Builder(RunCommandActivity.this)
|
||||
.setTitle(R.string.add_command)
|
||||
|
@@ -101,11 +101,11 @@ public class RunCommandWidget extends AppWidgetProvider {
|
||||
|
||||
if (getCurrentDevice() == null || !getCurrentDevice().isReachable()) {
|
||||
views.setTextViewText(R.id.runcommandWidgetTitle, context.getString(R.string.pref_plugin_runcommand));
|
||||
views.setViewVisibility(R.id.runcommandslist, View.GONE);
|
||||
views.setViewVisibility(R.id.run_commands_list, View.GONE);
|
||||
views.setViewVisibility(R.id.not_reachable_message, View.VISIBLE);
|
||||
} else {
|
||||
views.setTextViewText(R.id.runcommandWidgetTitle, getCurrentDevice().getName());
|
||||
views.setViewVisibility(R.id.runcommandslist, View.VISIBLE);
|
||||
views.setViewVisibility(R.id.run_commands_list, View.VISIBLE);
|
||||
views.setViewVisibility(R.id.not_reachable_message, View.GONE);
|
||||
}
|
||||
|
||||
@@ -114,14 +114,14 @@ public class RunCommandWidget extends AppWidgetProvider {
|
||||
intent = new Intent(context, RunCommandWidgetDataProviderService.class);
|
||||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
|
||||
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
|
||||
views.setRemoteAdapter(R.id.runcommandslist, intent);
|
||||
views.setRemoteAdapter(R.id.run_commands_list, intent);
|
||||
|
||||
intent = new Intent(context, RunCommandWidget.class);
|
||||
pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
views.setPendingIntentTemplate(R.id.runcommandslist, pendingIntent);
|
||||
views.setPendingIntentTemplate(R.id.run_commands_list, pendingIntent);
|
||||
|
||||
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, views);
|
||||
AppWidgetManager.getInstance(context).notifyAppWidgetViewDataChanged(appWidgetId, R.id.runcommandslist);
|
||||
AppWidgetManager.getInstance(context).notifyAppWidgetViewDataChanged(appWidgetId, R.id.run_commands_list);
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user