mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 15:19:53 +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) {
|
} else if (state instanceof MailboxState.CameraError) {
|
||||||
onCameraError();
|
onCameraError();
|
||||||
} else if (state instanceof MailboxState.IsPaired) {
|
} else if (state instanceof MailboxState.IsPaired) {
|
||||||
onIsPaired();
|
onIsPaired(((MailboxState.IsPaired) state).isOnline);
|
||||||
} else {
|
} else {
|
||||||
throw new AssertionError("Unknown state: " + state);
|
throw new AssertionError("Unknown state: " + state);
|
||||||
}
|
}
|
||||||
@@ -181,10 +181,13 @@ public class MailboxActivity extends BriarActivity {
|
|||||||
showFragment(getSupportFragmentManager(), f, ErrorFragment.TAG);
|
showFragment(getSupportFragmentManager(), f, ErrorFragment.TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onIsPaired() {
|
private void onIsPaired(boolean isOnline) {
|
||||||
progressBar.setVisibility(INVISIBLE);
|
progressBar.setVisibility(INVISIBLE);
|
||||||
showFragment(getSupportFragmentManager(), new MailboxStatusFragment(),
|
Fragment f = isOnline ?
|
||||||
MailboxStatusFragment.TAG, false);
|
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 {
|
static class IsPaired extends MailboxState {
|
||||||
|
final boolean isOnline;
|
||||||
|
|
||||||
|
IsPaired(boolean isOnline) {
|
||||||
|
this.isOnline = isOnline;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,7 +105,8 @@ class MailboxViewModel extends DbViewModel
|
|||||||
if (isPaired) {
|
if (isPaired) {
|
||||||
MailboxStatus mailboxStatus =
|
MailboxStatus mailboxStatus =
|
||||||
mailboxManager.getMailboxStatus(txn);
|
mailboxManager.getMailboxStatus(txn);
|
||||||
pairingState.postEvent(new MailboxState.IsPaired());
|
boolean isOnline = isTorActive();
|
||||||
|
pairingState.postEvent(new MailboxState.IsPaired(isOnline));
|
||||||
status.postValue(mailboxStatus);
|
status.postValue(mailboxStatus);
|
||||||
} else {
|
} else {
|
||||||
pairingState.postEvent(new NotSetup());
|
pairingState.postEvent(new NotSetup());
|
||||||
@@ -183,6 +184,12 @@ class MailboxViewModel extends DbViewModel
|
|||||||
return qrCodeDecoder;
|
return qrCodeDecoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
void checkIfOnlineWhenPaired() {
|
||||||
|
boolean isOnline = isTorActive();
|
||||||
|
pairingState.setEvent(new MailboxState.IsPaired(isOnline));
|
||||||
|
}
|
||||||
|
|
||||||
LiveData<Boolean> checkConnection() {
|
LiveData<Boolean> checkConnection() {
|
||||||
MutableLiveData<Boolean> liveData = new MutableLiveData<>();
|
MutableLiveData<Boolean> liveData = new MutableLiveData<>();
|
||||||
ioExecutor.execute(() -> {
|
ioExecutor.execute(() -> {
|
||||||
|
|||||||
@@ -33,10 +33,9 @@ public class OfflineFragment extends Fragment {
|
|||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
private MailboxViewModel viewModel;
|
protected MailboxViewModel viewModel;
|
||||||
|
|
||||||
private NestedScrollView scrollView;
|
private NestedScrollView scrollView;
|
||||||
protected Button buttonView;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
@@ -61,8 +60,8 @@ public class OfflineFragment extends Fragment {
|
|||||||
Intent i = new Intent(requireContext(), TransportsActivity.class);
|
Intent i = new Intent(requireContext(), TransportsActivity.class);
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
});
|
});
|
||||||
buttonView = v.findViewById(R.id.button);
|
Button buttonView = v.findViewById(R.id.button);
|
||||||
buttonView.setOnClickListener(view -> viewModel.showDownloadFragment());
|
buttonView.setOnClickListener(view -> onTryAgainClicked());
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@@ -74,4 +73,8 @@ public class OfflineFragment extends Fragment {
|
|||||||
scrollView.post(() -> scrollView.fullScroll(FOCUS_DOWN));
|
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