mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
[android] Fix climbing snackbar
Use a fresh snackbar for pending contacts each time it needs to be shown. Don't re-use the old instance and clear it in onStop().
This commit is contained in:
@@ -61,7 +61,7 @@ import io.github.kobakei.materialfabspeeddial.FabSpeedDial.OnMenuItemClickListen
|
|||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static androidx.core.app.ActivityOptionsCompat.makeSceneTransitionAnimation;
|
import static androidx.core.app.ActivityOptionsCompat.makeSceneTransitionAnimation;
|
||||||
import static androidx.core.view.ViewCompat.getTransitionName;
|
import static androidx.core.view.ViewCompat.getTransitionName;
|
||||||
import static com.google.android.material.snackbar.Snackbar.LENGTH_INDEFINITE;
|
import static com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_INDEFINITE;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
@@ -87,7 +87,12 @@ public class ContactListFragment extends BaseFragment implements EventListener,
|
|||||||
|
|
||||||
private ContactListAdapter adapter;
|
private ContactListAdapter adapter;
|
||||||
private BriarRecyclerView list;
|
private BriarRecyclerView list;
|
||||||
private Snackbar snackbar;
|
/**
|
||||||
|
* The Snackbar is non-null when shown and null otherwise.
|
||||||
|
* Use {@link #showSnackBar()} and {@link #dismissSnackBar()} to interact.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private Snackbar snackbar = null;
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject
|
@Inject
|
||||||
@@ -163,13 +168,6 @@ public class ContactListFragment extends BaseFragment implements EventListener,
|
|||||||
list.setEmptyText(getString(R.string.no_contacts));
|
list.setEmptyText(getString(R.string.no_contacts));
|
||||||
list.setEmptyAction(getString(R.string.no_contacts_action));
|
list.setEmptyAction(getString(R.string.no_contacts_action));
|
||||||
|
|
||||||
snackbar = new BriarSnackbarBuilder()
|
|
||||||
.setAction(R.string.show, v ->
|
|
||||||
startActivity(new Intent(getContext(),
|
|
||||||
PendingContactListActivity.class)))
|
|
||||||
.make(contentView, R.string.pending_contact_requests_snackbar,
|
|
||||||
LENGTH_INDEFINITE);
|
|
||||||
|
|
||||||
return contentView;
|
return contentView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,9 +201,9 @@ public class ContactListFragment extends BaseFragment implements EventListener,
|
|||||||
listener.runOnDbThread(() -> {
|
listener.runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
if (contactManager.getPendingContacts().isEmpty()) {
|
if (contactManager.getPendingContacts().isEmpty()) {
|
||||||
runOnUiThreadUnlessDestroyed(() -> snackbar.dismiss());
|
runOnUiThreadUnlessDestroyed(this::dismissSnackBar);
|
||||||
} else {
|
} else {
|
||||||
runOnUiThreadUnlessDestroyed(() -> snackbar.show());
|
runOnUiThreadUnlessDestroyed(this::showSnackBar);
|
||||||
}
|
}
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
@@ -220,6 +218,7 @@ public class ContactListFragment extends BaseFragment implements EventListener,
|
|||||||
adapter.clear();
|
adapter.clear();
|
||||||
list.showProgressBar();
|
list.showProgressBar();
|
||||||
list.stopPeriodicUpdate();
|
list.stopPeriodicUpdate();
|
||||||
|
dismissSnackBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadContacts() {
|
private void loadContacts() {
|
||||||
@@ -315,4 +314,27 @@ public class ContactListFragment extends BaseFragment implements EventListener,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
private void showSnackBar() {
|
||||||
|
if (snackbar != null) return;
|
||||||
|
View v = requireNonNull(getView());
|
||||||
|
int stringRes = R.string.pending_contact_requests_snackbar;
|
||||||
|
snackbar = new BriarSnackbarBuilder()
|
||||||
|
.setAction(R.string.show, view -> showPendingContactList())
|
||||||
|
.make(v, stringRes, LENGTH_INDEFINITE);
|
||||||
|
snackbar.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
private void dismissSnackBar() {
|
||||||
|
if (snackbar == null) return;
|
||||||
|
snackbar.dismiss();
|
||||||
|
snackbar = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showPendingContactList() {
|
||||||
|
Intent i = new Intent(getContext(), PendingContactListActivity.class);
|
||||||
|
startActivity(i);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user