forked from upstream-mirrors/OpenTracks
Cleanup: settings for layout uses ViewBinding.
This commit is contained in:
+21
-35
@@ -9,7 +9,6 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
@@ -17,8 +16,6 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
import com.google.android.material.textfield.TextInputEditText;
|
|
||||||
import com.google.android.material.textfield.TextInputLayout;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.AbstractActivity;
|
import de.dennisguse.opentracks.AbstractActivity;
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
@@ -31,49 +28,38 @@ public class SettingsCustomLayoutListActivity extends AbstractActivity implement
|
|||||||
|
|
||||||
private ActivitySettingsCustomLayoutListBinding viewBinding;
|
private ActivitySettingsCustomLayoutListBinding viewBinding;
|
||||||
private SettingsCustomLayoutListAdapter adapter;
|
private SettingsCustomLayoutListAdapter adapter;
|
||||||
private RecyclerView recyclerView;
|
|
||||||
private View addProfileLayout;
|
|
||||||
private TextInputEditText addProfileEditText;
|
|
||||||
private TextInputLayout addProfileInputLayout;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
adapter = new SettingsCustomLayoutListAdapter(this, this);
|
adapter = new SettingsCustomLayoutListAdapter(this, this);
|
||||||
recyclerView = viewBinding.recyclerView;
|
viewBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
viewBinding.recyclerView.setAdapter(adapter);
|
||||||
recyclerView.setAdapter(adapter);
|
|
||||||
|
|
||||||
Button cancelButton = findViewById(R.id.custom_layout_list_cancel_button);
|
viewBinding.customLayoutListCancelButton.setOnClickListener(view -> clearAndHideEditLayout());
|
||||||
Button okButton = findViewById(R.id.custom_layout_list_ok_button);
|
|
||||||
|
|
||||||
cancelButton.setOnClickListener(view -> clearAndHideEditLayout());
|
viewBinding.customLayoutListOkButton.setEnabled(false);
|
||||||
|
viewBinding.customLayoutListOkButton.setOnClickListener(view -> {
|
||||||
okButton.setEnabled(false);
|
PreferencesUtils.addCustomLayout(viewBinding.customLayoutListEditName.getText().toString());
|
||||||
okButton.setOnClickListener(view -> {
|
|
||||||
PreferencesUtils.addCustomLayout(addProfileEditText.getText().toString());
|
|
||||||
clearAndHideEditLayout();
|
clearAndHideEditLayout();
|
||||||
adapter.reloadLayouts();
|
adapter.reloadLayouts();
|
||||||
});
|
});
|
||||||
|
|
||||||
addProfileLayout = findViewById(R.id.custom_layout_list_add_linear_layout);
|
viewBinding.customLayoutListEditName.addTextChangedListener(new TextWatcher() {
|
||||||
addProfileInputLayout = findViewById(R.id.custom_layout_list_input_layout);
|
|
||||||
addProfileEditText = findViewById(R.id.custom_layout_list_edit_name);
|
|
||||||
addProfileEditText.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
if (s == null || s.toString().isEmpty()) {
|
if (s == null || s.toString().isEmpty()) {
|
||||||
okButton.setEnabled(false);
|
viewBinding.customLayoutListOkButton.setEnabled(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (adapter.getLayouts().stream().anyMatch(layout -> layout.sameName(s.toString()))) {
|
if (adapter.getLayouts().stream().anyMatch(layout -> layout.sameName(s.toString()))) {
|
||||||
okButton.setEnabled(false);
|
viewBinding.customLayoutListOkButton.setEnabled(false);
|
||||||
addProfileInputLayout.setError(getString(R.string.custom_layout_list_edit_already_exists));
|
viewBinding.customLayoutListInputLayout.setError(getString(R.string.custom_layout_list_edit_already_exists));
|
||||||
} else {
|
} else {
|
||||||
okButton.setEnabled(true);
|
viewBinding.customLayoutListOkButton.setEnabled(true);
|
||||||
addProfileInputLayout.setError("");
|
viewBinding.customLayoutListInputLayout.setError("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,10 +86,10 @@ public class SettingsCustomLayoutListActivity extends AbstractActivity implement
|
|||||||
|
|
||||||
adapter.removeLayout(position);
|
adapter.removeLayout(position);
|
||||||
|
|
||||||
Snackbar snackbar = Snackbar.make(recyclerView, getString(R.string.custom_layout_list_layout_removed), Snackbar.LENGTH_LONG);
|
Snackbar snackbar = Snackbar.make(viewBinding.recyclerView, getString(R.string.custom_layout_list_layout_removed), Snackbar.LENGTH_LONG);
|
||||||
snackbar.setAction(getString(R.string.generic_undo).toUpperCase(), view -> {
|
snackbar.setAction(getString(R.string.generic_undo).toUpperCase(), view -> {
|
||||||
adapter.restoreItem(item, position);
|
adapter.restoreItem(item, position);
|
||||||
recyclerView.scrollToPosition(position);
|
viewBinding.recyclerView.scrollToPosition(position);
|
||||||
});
|
});
|
||||||
|
|
||||||
snackbar.show();
|
snackbar.show();
|
||||||
@@ -111,7 +97,7 @@ public class SettingsCustomLayoutListActivity extends AbstractActivity implement
|
|||||||
};
|
};
|
||||||
|
|
||||||
ItemTouchHelper itemTouchhelper = new ItemTouchHelper(recyclerViewSwipeDeleteCallback);
|
ItemTouchHelper itemTouchhelper = new ItemTouchHelper(recyclerViewSwipeDeleteCallback);
|
||||||
itemTouchhelper.attachToRecyclerView(recyclerView);
|
itemTouchhelper.attachToRecyclerView(viewBinding.recyclerView);
|
||||||
|
|
||||||
setSupportActionBar(viewBinding.bottomAppBarLayout.bottomAppBar);
|
setSupportActionBar(viewBinding.bottomAppBarLayout.bottomAppBar);
|
||||||
}
|
}
|
||||||
@@ -138,10 +124,10 @@ public class SettingsCustomLayoutListActivity extends AbstractActivity implement
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
if (item.getItemId() == R.id.custom_layout_edit_add_profile) {
|
if (item.getItemId() == R.id.custom_layout_edit_add_profile) {
|
||||||
addProfileLayout.setVisibility(View.VISIBLE);
|
viewBinding.customLayoutListAddLinearLayout.setVisibility(View.VISIBLE);
|
||||||
addProfileEditText.requestFocus();
|
viewBinding.customLayoutListEditName.requestFocus();
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
imm.showSoftInput(addProfileEditText, InputMethodManager.SHOW_IMPLICIT);
|
imm.showSoftInput(viewBinding.customLayoutListEditName, InputMethodManager.SHOW_IMPLICIT);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,8 +142,8 @@ public class SettingsCustomLayoutListActivity extends AbstractActivity implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void clearAndHideEditLayout() {
|
private void clearAndHideEditLayout() {
|
||||||
addProfileEditText.setText("");
|
viewBinding.customLayoutListEditName.setText("");
|
||||||
addProfileInputLayout.setError("");
|
viewBinding.customLayoutListInputLayout.setError("");
|
||||||
addProfileLayout.setVisibility(View.GONE);
|
viewBinding.customLayoutListAddLinearLayout.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user