Skip to content

Commit

Permalink
Fix visibility of add button in alert log tab
Browse files Browse the repository at this point in the history
  • Loading branch information
frimtec committed Jun 5, 2022
1 parent 0749a5e commit dd79431
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,28 +194,24 @@ public boolean onFragmentContextItemSelected(MenuItem item) {

@Override
protected Optional<View.OnClickListener> addAction() {
if (Feature.PERMISSION_CALENDAR_READ.isAllowed(getContext()) &&
new ShiftService(getContext()).getShiftState().isOn()) {
return Optional.of(view -> {
AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
builder.setTitle(getString(R.string.manually_created_alarm_reason));
EditText input = new EditText(getContext());
input.setInputType(InputType.TYPE_CLASS_TEXT);
input.setText(R.string.manually_created_alarm_reason_default);
input.requestFocus();
builder.setView(input);
builder.setPositiveButton(R.string.general_ok, (dialog, which) -> {
dialog.dismiss();
String comment = input.getText().toString();
AlertService alertService = new AlertService(getContext());
alertService.newManuallyAlert(Instant.now(), comment);
refresh();
});
builder.setNegativeButton(R.string.general_cancel, (dialog, which) -> dialog.cancel());
builder.show();
return Optional.of(view -> {
AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
builder.setTitle(getString(R.string.manually_created_alarm_reason));
EditText input = new EditText(getContext());
input.setInputType(InputType.TYPE_CLASS_TEXT);
input.setText(R.string.manually_created_alarm_reason_default);
input.requestFocus();
builder.setView(input);
builder.setPositiveButton(R.string.general_ok, (dialog, which) -> {
dialog.dismiss();
String comment = input.getText().toString();
AlertService alertService = new AlertService(getContext());
alertService.newManuallyAlert(Instant.now(), comment);
refresh();
});
}
return Optional.empty();
builder.setNegativeButton(R.string.general_cancel, (dialog, which) -> dialog.cancel());
builder.show();
});
}

private void showAlertDetails(Alert selectedAlert) {
Expand Down Expand Up @@ -269,4 +265,10 @@ private static String readTextFromUri(ContentResolver contentResolver, Uri uri)
}
return stringBuilder.toString();
}

@Override
protected boolean isAddButtonVisible() {
return Feature.PERMISSION_CALENDAR_READ.isAllowed(getContext()) &&
new ShiftService(getContext()).getShiftState().isOn();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
public abstract class AbstractListFragment<T> extends Fragment {

private ListView listView;
private FloatingActionButton addButton;

private final FragmentPosition fragmentPosition;

Expand All @@ -41,9 +42,7 @@ public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bun
});

listView = view.findViewById(R.id.fragment_list_list);


FloatingActionButton addButton = view.findViewById(R.id.list_add_button);
addButton = view.findViewById(R.id.list_add_button);
addAction().map(onClickListener -> {
addButton.setVisibility(View.VISIBLE);
addButton.setOnClickListener(onClickListener);
Expand All @@ -68,6 +67,11 @@ protected Optional<View.OnClickListener> addAction() {
public final void refresh() {
ArrayAdapter<T> adapter = createAdapter();
listView.setAdapter(adapter);
addButton.setVisibility(isAddButtonVisible() ? View.VISIBLE : View.INVISIBLE);
}

protected boolean isAddButtonVisible() {
return false;
}

protected abstract void configureListView(ListView listView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,9 @@ private List<TestAlarmContext> loadTestAlarmList() {
}
return list;
}

@Override
protected boolean isAddButtonVisible() {
return true;
}
}

0 comments on commit dd79431

Please sign in to comment.