83 lines
2.4 KiB
Java
83 lines
2.4 KiB
Java
package org.mercury_im.messenger.android.ui.account.login;
|
|
|
|
import android.os.Bundle;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.Button;
|
|
import android.widget.EditText;
|
|
import android.widget.ImageButton;
|
|
import android.widget.Toast;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.lifecycle.ViewModelProvider;
|
|
|
|
import org.mercury_im.messenger.R;
|
|
|
|
import java.util.UUID;
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.ButterKnife;
|
|
|
|
public class IkeyBackupRestoreOrSkipFragment extends Fragment {
|
|
|
|
@BindView(R.id.btn_restore)
|
|
Button restoreButton;
|
|
|
|
@BindView(R.id.btn_new_key)
|
|
Button regenerateButton;
|
|
|
|
@BindView(R.id.edit_backup_code)
|
|
EditText backupCodeEditText;
|
|
|
|
@BindView(R.id.btn_scan)
|
|
ImageButton scanButton;
|
|
|
|
private final UUID accountId;
|
|
|
|
private AndroidIkeySetupViewModel viewModel;
|
|
|
|
IkeyBackupRestoreOrSkipFragment(UUID accountId) {
|
|
this.accountId = accountId;
|
|
}
|
|
|
|
public static IkeyBackupRestoreOrSkipFragment newInstance(UUID accountId) {
|
|
return new IkeyBackupRestoreOrSkipFragment(accountId);
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
View view = inflater.inflate(R.layout.fragment_ikey_backup_restore, container, false);
|
|
ButterKnife.bind(this, view);
|
|
return view;
|
|
}
|
|
|
|
@Override
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
super.onViewCreated(view, savedInstanceState);
|
|
viewModel = new ViewModelProvider(requireActivity()).get(AndroidIkeySetupViewModel.class);
|
|
|
|
restoreButton.setOnClickListener(v -> onRestore());
|
|
regenerateButton.setOnClickListener(v ->
|
|
((IkeySetupNavigator) getActivity()).generateIkeyBackup(accountId));
|
|
|
|
viewModel.getPassphraseError().observe(this, opt -> {
|
|
if (opt.isPresent()) {
|
|
Toast.makeText(getContext(), opt.getItem(), Toast.LENGTH_SHORT).show();
|
|
}
|
|
});
|
|
}
|
|
|
|
public void onRestore() {
|
|
String backupCode = backupCodeEditText.getText().toString();
|
|
|
|
if (viewModel.restoreBackup(backupCode)) {
|
|
((IkeySetupNavigator) getActivity()).restoreSuccessful(accountId);
|
|
}
|
|
|
|
}
|
|
}
|