2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 14:15:14 +00:00

Use view binding in ShareActivity.

This commit is contained in:
Isira Seneviratne
2020-07-08 05:37:09 +05:30
committed by Nicolas Fella
parent 32c9dc5ad5
commit 3207e4b0eb

View File

@@ -25,7 +25,9 @@ import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.ListView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import org.kde.kdeconnect.BackgroundService; import org.kde.kdeconnect.BackgroundService;
import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Device;
@@ -34,18 +36,14 @@ import org.kde.kdeconnect.UserInterface.List.ListAdapter;
import org.kde.kdeconnect.UserInterface.List.SectionItem; import org.kde.kdeconnect.UserInterface.List.SectionItem;
import org.kde.kdeconnect.UserInterface.ThemeUtil; import org.kde.kdeconnect.UserInterface.ThemeUtil;
import org.kde.kdeconnect_tp.R; import org.kde.kdeconnect_tp.R;
import org.kde.kdeconnect_tp.databinding.DevicesListBinding;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
public class ShareActivity extends AppCompatActivity { public class ShareActivity extends AppCompatActivity {
private DevicesListBinding binding;
private SwipeRefreshLayout mSwipeRefreshLayout;
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
@@ -70,18 +68,17 @@ public class ShareActivity extends AppCompatActivity {
updateComputerList(); updateComputerList();
BackgroundService.RunCommand(ShareActivity.this, BackgroundService::onNetworkChange); BackgroundService.RunCommand(ShareActivity.this, BackgroundService::onNetworkChange);
mSwipeRefreshLayout.setRefreshing(true); binding.refreshListLayout.setRefreshing(true);
new Thread(() -> { new Thread(() -> {
try { try {
Thread.sleep(1500); Thread.sleep(1500);
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
} }
runOnUiThread(() -> mSwipeRefreshLayout.setRefreshing(false)); runOnUiThread(() -> binding.refreshListLayout.setRefreshing(false));
}).start(); }).start();
} }
private void updateComputerList() { private void updateComputerList() {
final Intent intent = getIntent(); final Intent intent = getIntent();
String action = intent.getAction(); String action = intent.getAction();
@@ -108,16 +105,13 @@ public class ShareActivity extends AppCompatActivity {
} }
runOnUiThread(() -> { runOnUiThread(() -> {
ListView list = findViewById(R.id.devices_list); binding.devicesList.setAdapter(new ListAdapter(ShareActivity.this, items));
list.setAdapter(new ListAdapter(ShareActivity.this, items)); binding.devicesList.setOnItemClickListener((adapterView, view, i, l) -> {
list.setOnItemClickListener((adapterView, view, i, l) -> {
Device device = devicesList.get(i - 1); //NOTE: -1 because of the title! Device device = devicesList.get(i - 1); //NOTE: -1 because of the title!
BackgroundService.RunWithPlugin(this, device.getDeviceId(), SharePlugin.class, plugin -> plugin.share(intent)); BackgroundService.RunWithPlugin(this, device.getDeviceId(), SharePlugin.class, plugin -> plugin.share(intent));
finish(); finish();
}); });
}); });
}); });
} }
@@ -126,19 +120,16 @@ public class ShareActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ThemeUtil.setUserPreferredTheme(this); ThemeUtil.setUserPreferredTheme(this);
setContentView(R.layout.devices_list); binding = DevicesListBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
mSwipeRefreshLayout = findViewById(R.id.refresh_list_layout); binding.refreshListLayout.setOnRefreshListener(this::updateComputerListAction);
mSwipeRefreshLayout.setOnRefreshListener(
this::updateComputerListAction
);
if (actionBar != null) { if (actionBar != null) {
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
} }
} }
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
@@ -152,7 +143,6 @@ public class ShareActivity extends AppCompatActivity {
finish(); finish();
}); });
} else { } else {
BackgroundService.RunCommand(this, service -> { BackgroundService.RunCommand(this, service -> {
service.onNetworkChange(); service.onNetworkChange();
service.addDeviceListChangedCallback("ShareActivity", this::updateComputerList); service.addDeviceListChangedCallback("ShareActivity", this::updateComputerList);
@@ -161,11 +151,9 @@ public class ShareActivity extends AppCompatActivity {
} }
} }
@Override @Override
protected void onStop() { protected void onStop() {
BackgroundService.RunCommand(this, service -> service.removeDeviceListChangedCallback("ShareActivity")); BackgroundService.RunCommand(this, service -> service.removeDeviceListChangedCallback("ShareActivity"));
super.onStop(); super.onStop();
} }
} }