mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Re-use OfflineFragment when offline in mailbox status screen
This commit is contained in:
@@ -67,7 +67,7 @@ public class MailboxActivity extends BriarActivity {
|
||||
} else if (state instanceof MailboxState.CameraError) {
|
||||
onCameraError();
|
||||
} else if (state instanceof MailboxState.IsPaired) {
|
||||
onIsPaired();
|
||||
onIsPaired(((MailboxState.IsPaired) state).isOnline);
|
||||
} else {
|
||||
throw new AssertionError("Unknown state: " + state);
|
||||
}
|
||||
@@ -181,10 +181,13 @@ public class MailboxActivity extends BriarActivity {
|
||||
showFragment(getSupportFragmentManager(), f, ErrorFragment.TAG);
|
||||
}
|
||||
|
||||
private void onIsPaired() {
|
||||
private void onIsPaired(boolean isOnline) {
|
||||
progressBar.setVisibility(INVISIBLE);
|
||||
showFragment(getSupportFragmentManager(), new MailboxStatusFragment(),
|
||||
MailboxStatusFragment.TAG, false);
|
||||
Fragment f = isOnline ?
|
||||
new MailboxStatusFragment() : new OfflineStatusFragment();
|
||||
String tag = isOnline ?
|
||||
MailboxStatusFragment.TAG : OfflineStatusFragment.TAG;
|
||||
showFragment(getSupportFragmentManager(), f, tag, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,11 @@ class MailboxState {
|
||||
}
|
||||
|
||||
static class IsPaired extends MailboxState {
|
||||
final boolean isOnline;
|
||||
|
||||
IsPaired(boolean isOnline) {
|
||||
this.isOnline = isOnline;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -105,7 +105,8 @@ class MailboxViewModel extends DbViewModel
|
||||
if (isPaired) {
|
||||
MailboxStatus mailboxStatus =
|
||||
mailboxManager.getMailboxStatus(txn);
|
||||
pairingState.postEvent(new MailboxState.IsPaired());
|
||||
boolean isOnline = isTorActive();
|
||||
pairingState.postEvent(new MailboxState.IsPaired(isOnline));
|
||||
status.postValue(mailboxStatus);
|
||||
} else {
|
||||
pairingState.postEvent(new NotSetup());
|
||||
@@ -183,6 +184,12 @@ class MailboxViewModel extends DbViewModel
|
||||
return qrCodeDecoder;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
void checkIfOnlineWhenPaired() {
|
||||
boolean isOnline = isTorActive();
|
||||
pairingState.setEvent(new MailboxState.IsPaired(isOnline));
|
||||
}
|
||||
|
||||
LiveData<Boolean> checkConnection() {
|
||||
MutableLiveData<Boolean> liveData = new MutableLiveData<>();
|
||||
ioExecutor.execute(() -> {
|
||||
|
||||
@@ -33,10 +33,9 @@ public class OfflineFragment extends Fragment {
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
|
||||
private MailboxViewModel viewModel;
|
||||
protected MailboxViewModel viewModel;
|
||||
|
||||
private NestedScrollView scrollView;
|
||||
protected Button buttonView;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
@@ -61,8 +60,8 @@ public class OfflineFragment extends Fragment {
|
||||
Intent i = new Intent(requireContext(), TransportsActivity.class);
|
||||
startActivity(i);
|
||||
});
|
||||
buttonView = v.findViewById(R.id.button);
|
||||
buttonView.setOnClickListener(view -> viewModel.showDownloadFragment());
|
||||
Button buttonView = v.findViewById(R.id.button);
|
||||
buttonView.setOnClickListener(view -> onTryAgainClicked());
|
||||
|
||||
return v;
|
||||
}
|
||||
@@ -74,4 +73,8 @@ public class OfflineFragment extends Fragment {
|
||||
scrollView.post(() -> scrollView.fullScroll(FOCUS_DOWN));
|
||||
}
|
||||
|
||||
protected void onTryAgainClicked() {
|
||||
viewModel.showDownloadFragment();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.briarproject.briar.android.mailbox;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class OfflineStatusFragment extends OfflineFragment {
|
||||
|
||||
public static final String TAG = OfflineStatusFragment.class.getName();
|
||||
|
||||
@Override
|
||||
protected void onTryAgainClicked() {
|
||||
viewModel.checkIfOnlineWhenPaired();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user