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

Use view binding in CustomDevicesActivity.

This commit is contained in:
Isira Seneviratne
2020-07-08 05:40:31 +05:30
committed by Nicolas Fella
parent 3207e4b0eb
commit d064cf6a1e

View File

@@ -28,26 +28,22 @@ import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar;
import org.kde.kdeconnect.BackgroundService;
import org.kde.kdeconnect_tp.R;
import java.util.ArrayList;
import java.util.Collections;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.TooltipCompat; import androidx.appcompat.widget.TooltipCompat;
import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import butterknife.OnClick; import com.google.android.material.snackbar.BaseTransientBottomBar;
import butterknife.Unbinder; import com.google.android.material.snackbar.Snackbar;
import org.kde.kdeconnect_tp.R;
import org.kde.kdeconnect_tp.databinding.ActivityCustomDevicesBinding;
import java.util.ArrayList;
import java.util.Collections;
//TODO: Require wifi connection so entries can be verified //TODO: Require wifi connection so entries can be verified
//TODO: Resolve to ip address and don't allow unresolvable or duplicates based on ip address //TODO: Resolve to ip address and don't allow unresolvable or duplicates based on ip address
@@ -59,13 +55,10 @@ public class CustomDevicesActivity extends AppCompatActivity implements CustomDe
private static final String IP_DELIM = ","; private static final String IP_DELIM = ",";
private static final String KEY_EDITING_DEVICE_AT_POSITION = "EditingDeviceAtPosition"; private static final String KEY_EDITING_DEVICE_AT_POSITION = "EditingDeviceAtPosition";
@BindView(R.id.recyclerView) RecyclerView recyclerView; private RecyclerView recyclerView;
@BindView(R.id.emptyListMessage) TextView emptyListMessage; private TextView emptyListMessage;
@BindView(R.id.floatingActionButton) FloatingActionButton fab;
private ArrayList<String> customDeviceList; private ArrayList<String> customDeviceList;
private boolean dialogAlreadyShown = false;
private Unbinder unbinder;
private EditTextAlertDialogFragment addDeviceDialog; private EditTextAlertDialogFragment addDeviceDialog;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private CustomDevicesAdapter customDevicesAdapter; private CustomDevicesAdapter customDevicesAdapter;
@@ -77,9 +70,15 @@ public class CustomDevicesActivity extends AppCompatActivity implements CustomDe
ThemeUtil.setUserPreferredTheme(this); ThemeUtil.setUserPreferredTheme(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_devices); final ActivityCustomDevicesBinding binding = ActivityCustomDevicesBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
recyclerView = binding.recyclerView;
emptyListMessage = binding.emptyListMessage;
final FloatingActionButton fab = binding.floatingActionButton;
fab.setOnClickListener(v -> showEditTextDialog(""));
unbinder = ButterKnife.bind(this);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
customDeviceList = getCustomDeviceList(sharedPreferences); customDeviceList = getCustomDeviceList(sharedPreferences);
@@ -109,27 +108,16 @@ public class CustomDevicesActivity extends AppCompatActivity implements CustomDe
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putInt(KEY_EDITING_DEVICE_AT_POSITION, editingDeviceAtPosition); outState.putInt(KEY_EDITING_DEVICE_AT_POSITION, editingDeviceAtPosition);
} }
@Override
protected void onDestroy() {
unbinder.unbind();
super.onDestroy();
}
private void showEmptyListMessageIfRequired() { private void showEmptyListMessageIfRequired() {
emptyListMessage.setVisibility(customDeviceList.isEmpty() ? View.VISIBLE : View.GONE); emptyListMessage.setVisibility(customDeviceList.isEmpty() ? View.VISIBLE : View.GONE);
} }
@OnClick(R.id.floatingActionButton)
void onFabClicked() {
showEditTextDialog("");
}
private void showEditTextDialog(@NonNull String text) { private void showEditTextDialog(@NonNull String text) {
addDeviceDialog = new EditTextAlertDialogFragment.Builder() addDeviceDialog = new EditTextAlertDialogFragment.Builder()
.setTitle(R.string.add_device_dialog_title) .setTitle(R.string.add_device_dialog_title)