mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Popup dialog on shards sent for custodian
This commit is contained in:
@@ -13,7 +13,6 @@ import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import org.briarproject.briar.api.socialbackup.recovery.CustodianTask;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
@@ -21,17 +20,12 @@ import javax.inject.Inject;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
||||
|
||||
public class CustodianReturnShardActivity extends BriarActivity
|
||||
implements BaseFragment.BaseFragmentListener {
|
||||
|
||||
private CustodianReturnShardViewModel viewModel;
|
||||
private static final Logger LOG =
|
||||
getLogger(CustodianReturnShardActivity.class.getName());
|
||||
private ContactId contactId;
|
||||
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
@@ -52,7 +46,7 @@ public class CustodianReturnShardActivity extends BriarActivity
|
||||
Intent intent = getIntent();
|
||||
int id = intent.getIntExtra(CONTACT_ID, -1);
|
||||
if (id == -1) throw new IllegalStateException("No ContactId");
|
||||
contactId = new ContactId(id);
|
||||
ContactId contactId = new ContactId(id);
|
||||
|
||||
try {
|
||||
viewModel.start(contactId);
|
||||
@@ -96,7 +90,8 @@ public class CustodianReturnShardActivity extends BriarActivity
|
||||
"It looks like you are not connected to a Wifi network",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
if (fm.findFragmentByTag(CustodianReturnShardFragment.TAG) == null) {
|
||||
if (fm.findFragmentByTag(CustodianReturnShardFragment.TAG) ==
|
||||
null) {
|
||||
BaseFragment f = new CustodianReturnShardErrorFragment();
|
||||
fm.beginTransaction()
|
||||
.replace(R.id.fragmentContainer, f, f.getUniqueTag())
|
||||
@@ -106,19 +101,15 @@ public class CustodianReturnShardActivity extends BriarActivity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void onReturnShardStateChanged(CustodianTask.State state) {
|
||||
if (state instanceof CustodianTask.State.Success) {
|
||||
CustodianReturnShardSuccessFragment fragment = new CustodianReturnShardSuccessFragment();
|
||||
showNextFragment(fragment);
|
||||
} else if (state instanceof CustodianTask.State.Failure) {
|
||||
// TODO error fragment here
|
||||
// TODO handle reason
|
||||
Toast.makeText(this,
|
||||
"Backup piece transfer failed",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
if (state instanceof CustodianTask.State.Failure) {
|
||||
// TODO error fragment here
|
||||
// TODO handle reason
|
||||
Toast.makeText(this,
|
||||
"Backup piece transfer failed",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void showCameraFragment() {
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -24,6 +25,7 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
|
||||
@@ -53,6 +55,7 @@ public class CustodianReturnShardFragment extends BaseFragment
|
||||
private LinearLayout cameraOverlay;
|
||||
private View statusView;
|
||||
private TextView status;
|
||||
private ProgressBar bottomSpinner;
|
||||
|
||||
public static CustodianReturnShardFragment newInstance() {
|
||||
Bundle args = new Bundle();
|
||||
@@ -84,6 +87,7 @@ public class CustodianReturnShardFragment extends BaseFragment
|
||||
cameraOverlay = view.findViewById(R.id.camera_overlay);
|
||||
statusView = view.findViewById(R.id.status_container);
|
||||
status = view.findViewById(R.id.connect_status);
|
||||
bottomSpinner = view.findViewById(R.id.qr_code_progress_bar);
|
||||
|
||||
viewModel.getState().observe(getViewLifecycleOwner(),
|
||||
this::onReturnShardStateChanged);
|
||||
@@ -141,7 +145,6 @@ public class CustodianReturnShardFragment extends BaseFragment
|
||||
|
||||
@UiThread
|
||||
private void onReturnShardStateChanged(@Nullable CustodianTask.State state) {
|
||||
LOG.info("State changed");
|
||||
// if (state instanceof CustodianTask.State.Connecting) {
|
||||
// try {
|
||||
// cameraView.stop();
|
||||
@@ -163,8 +166,9 @@ public class CustodianReturnShardFragment extends BaseFragment
|
||||
} else if (state instanceof CustodianTask.State.ReceivingAck) {
|
||||
status.setText("Receiving Ack");
|
||||
} else if (state instanceof CustodianTask.State.Success) {
|
||||
// TODO
|
||||
status.setText(R.string.exchanging_contact_details);
|
||||
statusView.setVisibility(INVISIBLE);
|
||||
bottomSpinner.setVisibility(INVISIBLE);
|
||||
showSuccessDialog();
|
||||
} else if (state instanceof CustodianTask.State.Failure) {
|
||||
// the activity will replace this fragment with an error fragment
|
||||
statusView.setVisibility(INVISIBLE);
|
||||
@@ -190,4 +194,15 @@ public class CustodianReturnShardFragment extends BaseFragment
|
||||
requireActivity().getSupportFragmentManager().popBackStack();
|
||||
}
|
||||
|
||||
private void showSuccessDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(),
|
||||
R.style.BriarDialogTheme);
|
||||
builder.setTitle(R.string.custodian_shard_sent);
|
||||
//builder.setMessage();
|
||||
builder.setPositiveButton(R.string.ok,
|
||||
(dialog, which) -> viewModel.onSuccessDismissed());
|
||||
builder.setIcon(R.drawable.ic_baseline_done_outline_24);
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,6 @@ public class CustodianReturnShardViewModel extends AndroidViewModel
|
||||
successDismissed.setEvent(true);
|
||||
}
|
||||
|
||||
|
||||
QrCodeDecoder getQrCodeDecoder() {
|
||||
return qrCodeDecoder;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
<ProgressBar
|
||||
style="?android:attr/progressBarStyleLarge"
|
||||
android:id="@+id/qr_code_progress_bar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
Reference in New Issue
Block a user