mirror of
https://codeberg.org/anoncontributorxmr/mysu.git
synced 2024-11-22 07:22:26 +00:00
Add button in settings to display recovery seed
This commit is contained in:
parent
5d93041ee3
commit
66b92bb0b1
9 changed files with 162 additions and 17 deletions
|
@ -48,9 +48,8 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
|||
init(walletFile, "");
|
||||
} else {
|
||||
PasswordBottomSheetDialog passwordDialog = new PasswordBottomSheetDialog();
|
||||
passwordDialog.setCancelable(false);
|
||||
passwordDialog.listener = this;
|
||||
passwordDialog.show(getSupportFragmentManager(), null);
|
||||
passwordDialog.show(getSupportFragmentManager(), "password_dialog");
|
||||
}
|
||||
} else {
|
||||
navigate(R.id.onboarding_fragment);
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package com.m2049r.xmrwallet.fragment.dialog;
|
||||
|
||||
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.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
import com.m2049r.xmrwallet.R;
|
||||
import com.m2049r.xmrwallet.model.Wallet;
|
||||
import com.m2049r.xmrwallet.model.WalletManager;
|
||||
import com.m2049r.xmrwallet.util.Constants;
|
||||
import com.m2049r.xmrwallet.util.Helper;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class InformationBottomSheetDialog extends BottomSheetDialogFragment {
|
||||
public boolean showCopyButton = false;
|
||||
public String information = "";
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.information_bottom_sheet_dialog, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
ImageButton copyInformationImageButton = view.findViewById(R.id.copy_information_imagebutton);
|
||||
if(showCopyButton) {
|
||||
copyInformationImageButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
copyInformationImageButton.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
TextView informationTextView = view.findViewById(R.id.information_textview);
|
||||
informationTextView.setText(information);
|
||||
copyInformationImageButton.setOnClickListener(view1 -> Helper.clipBoardCopy(getContext(), "information", information));
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@ public class PasswordBottomSheetDialog extends BottomSheetDialogFragment {
|
|||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
setCancelable(false);
|
||||
File walletFile = new File(getActivity().getApplicationInfo().dataDir, Constants.WALLET_NAME);
|
||||
|
||||
ImageButton pastePasswordImageButton = view.findViewById(R.id.paste_password_imagebutton);
|
||||
|
@ -60,10 +61,7 @@ public class PasswordBottomSheetDialog extends BottomSheetDialogFragment {
|
|||
}
|
||||
|
||||
private boolean checkPassword(File walletFile, String password) {
|
||||
Wallet wallet = WalletManager.getInstance().openWallet(walletFile.getAbsolutePath(), password);
|
||||
boolean ok = wallet.getStatus().isOk();
|
||||
wallet.close();
|
||||
return ok;
|
||||
return WalletManager.getInstance().verifyWalletPasswordOnly(walletFile.getAbsolutePath() + ".keys", password);
|
||||
}
|
||||
|
||||
public interface PasswordListener {
|
||||
|
|
|
@ -4,8 +4,10 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -14,13 +16,17 @@ import androidx.fragment.app.Fragment;
|
|||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.m2049r.xmrwallet.R;
|
||||
import com.m2049r.xmrwallet.fragment.dialog.InformationBottomSheetDialog;
|
||||
import com.m2049r.xmrwallet.fragment.dialog.PasswordBottomSheetDialog;
|
||||
import com.m2049r.xmrwallet.model.Wallet;
|
||||
import com.m2049r.xmrwallet.model.WalletManager;
|
||||
import com.m2049r.xmrwallet.service.BlockchainService;
|
||||
import com.m2049r.xmrwallet.service.PrefService;
|
||||
import com.m2049r.xmrwallet.util.Constants;
|
||||
import com.m2049r.xmrwallet.util.DayNightMode;
|
||||
import com.m2049r.xmrwallet.util.NightmodeHelper;
|
||||
|
||||
public class SettingsFragment extends Fragment {
|
||||
public class SettingsFragment extends Fragment implements PasswordBottomSheetDialog.PasswordListener {
|
||||
|
||||
private SettingsViewModel mViewModel;
|
||||
|
||||
|
@ -36,11 +42,11 @@ public class SettingsFragment extends Fragment {
|
|||
mViewModel = new ViewModelProvider(this).get(SettingsViewModel.class);
|
||||
Wallet wallet = WalletManager.getInstance().getWallet();
|
||||
|
||||
Button displaySeedButton = view.findViewById(R.id.display_seed_button);
|
||||
TextView walletInfoTextView = view.findViewById(R.id.wallet_info_textview);
|
||||
SwitchCompat nightModeSwitch = view.findViewById(R.id.day_night_switch);
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("Seed: " + wallet.getSeed("")+"\n\n");
|
||||
stringBuilder.append("Private view-key: " + wallet.getSecretViewKey()+"\n\n");
|
||||
stringBuilder.append("Restore height: " + wallet.getRestoreHeight() + "\n\n");
|
||||
stringBuilder.append("Wallet height: " + wallet.getBlockChainHeight() + "\n\n");
|
||||
|
@ -55,5 +61,33 @@ public class SettingsFragment extends Fragment {
|
|||
NightmodeHelper.setAndSavePreferredNightmode(getContext(), DayNightMode.DAY);
|
||||
}
|
||||
});
|
||||
|
||||
displaySeedButton.setOnClickListener(view1 -> {
|
||||
boolean usesPassword = PrefService.getInstance().getBoolean(Constants.PREF_USES_PASSWORD, false);
|
||||
if(usesPassword) {
|
||||
PasswordBottomSheetDialog passwordDialog = new PasswordBottomSheetDialog();
|
||||
passwordDialog.listener = this;
|
||||
passwordDialog.show(getActivity().getSupportFragmentManager(), "password_dialog");
|
||||
} else {
|
||||
displaySeedDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void displaySeedDialog() {
|
||||
InformationBottomSheetDialog informationDialog = new InformationBottomSheetDialog();
|
||||
informationDialog.showCopyButton = true;
|
||||
informationDialog.information = WalletManager.getInstance().getWallet().getSeed("");
|
||||
informationDialog.show(getActivity().getSupportFragmentManager(), "information_seed_dialog");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPasswordSuccess(String password) {
|
||||
displaySeedDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPasswordFail() {
|
||||
Toast.makeText(getContext(), R.string.bad_password, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
|
@ -39,6 +39,7 @@ import android.view.WindowManager;
|
|||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
@ -244,9 +245,12 @@ public class Helper {
|
|||
}
|
||||
|
||||
static public void clipBoardCopy(Context context, String label, String text) {
|
||||
ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText(label, text);
|
||||
clipboardManager.setPrimaryClip(clip);
|
||||
if(context != null) {
|
||||
ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText(label, text);
|
||||
clipboardManager.setPrimaryClip(clip);
|
||||
Toast.makeText(context, context.getText(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
static public String getClipBoardText(Context context) {
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/btn_color_selector"
|
||||
android:fillColor="@color/oled_textColorPrimary"
|
||||
android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z"/>
|
||||
</vector>
|
||||
|
|
|
@ -16,11 +16,31 @@
|
|||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/display_seed_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Display recovery phrase"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/night_mode_label"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/night_mode"
|
||||
app:layout_constraintTop_toTopOf="@id/day_night_switch"
|
||||
app:layout_constraintBottom_toBottomOf="@id/day_night_switch"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/day_night_switch"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/wallet_info_textview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/day_night_switch"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
|
@ -28,9 +48,7 @@
|
|||
android:id="@+id/day_night_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:layout_marginStart="24dp"/>
|
||||
app:layout_constraintTop_toBottomOf="@id/display_seed_button"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
44
app/src/main/res/layout/information_bottom_sheet_dialog.xml
Normal file
44
app/src/main/res/layout/information_bottom_sheet_dialog.xml
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true"
|
||||
android:fitsSystemWindows="true"
|
||||
android:padding="16dp">
|
||||
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/information_textview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="INFORMATION"
|
||||
app:layout_constraintEnd_toStartOf="@id/copy_information_imagebutton"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<ImageButton
|
||||
android:id="@+id/copy_information_imagebutton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
android:padding="8dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:src="@drawable/ic_content_copy_24dp"
|
||||
app:layout_constraintTop_toTopOf="@id/information_textview"
|
||||
app:layout_constraintBottom_toBottomOf="@id/information_textview"
|
||||
app:layout_constraintStart_toEndOf="@id/information_textview"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</ScrollView>
|
|
@ -544,4 +544,6 @@
|
|||
<string name="error_sending_tx">Error sending tx</string>
|
||||
<string name="create_wallet">Create wallet</string>
|
||||
<string name="invalid_mnemonic_code">Invalid mnemonic</string>
|
||||
<string name="copied_to_clipboard">Copied to clipboard</string>
|
||||
<string name="night_mode">Night mode</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue