diff --git a/app/src/main/java/com/alphawallet/app/ui/BackupFlowActivity.java b/app/src/main/java/com/alphawallet/app/ui/BackupFlowActivity.java index 514775b54d..f3b27455c6 100644 --- a/app/src/main/java/com/alphawallet/app/ui/BackupFlowActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/BackupFlowActivity.java @@ -163,13 +163,20 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } - public void backPressed() { + public void backPressed() + { Intent intent = new Intent(); setResult(RESULT_CANCELED, intent); intent.putExtra("Key", wallet.address); finish(); } + @Override + public void handleBackPressed() + { + backPressed(); + } + @Override public void onClick(View view) { // Passing an empty String as this class handles clicks based on state diff --git a/app/src/main/java/com/alphawallet/app/ui/BackupKeyActivity.java b/app/src/main/java/com/alphawallet/app/ui/BackupKeyActivity.java index 436c6dd689..3777061f89 100644 --- a/app/src/main/java/com/alphawallet/app/ui/BackupKeyActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/BackupKeyActivity.java @@ -387,17 +387,20 @@ private void initViews() @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) + if (item.getItemId() == android.R.id.home) { - case android.R.id.home: - { - backPressed(); - return true; - } + backPressed(); + return true; } return super.onOptionsItemSelected(item); } + @Override + public void handleBackPressed() + { + backPressed(); + } + private void backPressed() { switch (state) diff --git a/app/src/main/java/com/alphawallet/app/ui/BaseActivity.java b/app/src/main/java/com/alphawallet/app/ui/BaseActivity.java index 7e66cb0884..e5766b2883 100644 --- a/app/src/main/java/com/alphawallet/app/ui/BaseActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/BaseActivity.java @@ -5,6 +5,7 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.DrawableRes; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; @@ -48,6 +49,8 @@ protected void setTitle(String title) } toolbarTitle.setText(title); } + + setDispatcher(); } protected void setSubtitle(String subtitle) @@ -88,7 +91,7 @@ protected void enableDisplayHomeAsHome(boolean active) } } - protected void dissableDisplayHomeAsUp() + protected void disableDisplayHomeAsUp() { ActionBar actionBar = getSupportActionBar(); if (actionBar != null) @@ -120,7 +123,7 @@ public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { - onBackPressed(); + handleBackPressed(); finish(); } return true; @@ -173,4 +176,23 @@ protected void displayErrorMessage(String message) dialog.setButtonListener(v -> dialog.dismiss()); dialog.show(); } + + public void setDispatcher() + { + // Create an OnBackPressedCallback + final OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() + { + handleBackPressed(); + } + }; + + this.getOnBackPressedDispatcher().addCallback(callback); + } + + public void handleBackPressed() + { + finish(); + }; } diff --git a/app/src/main/java/com/alphawallet/app/ui/GasSettingsActivity.java b/app/src/main/java/com/alphawallet/app/ui/GasSettingsActivity.java index 389aa68cbd..266fcec555 100644 --- a/app/src/main/java/com/alphawallet/app/ui/GasSettingsActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/GasSettingsActivity.java @@ -233,6 +233,12 @@ public boolean onOptionsItemSelected(MenuItem item) return super.onOptionsItemSelected(item); } + @Override + public void handleBackPressed() + { + backPressed(); + } + private void backPressed() { Intent result = new Intent(); diff --git a/app/src/main/java/com/alphawallet/app/ui/HomeActivity.java b/app/src/main/java/com/alphawallet/app/ui/HomeActivity.java index 11ac88cf91..eaf9e230fc 100644 --- a/app/src/main/java/com/alphawallet/app/ui/HomeActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/HomeActivity.java @@ -262,7 +262,7 @@ public void onPageScrollStateChanged(int state) }); initBottomNavigation(); - dissableDisplayHomeAsUp(); + disableDisplayHomeAsUp(); viewModel.error().observe(this, this::onError); viewModel.walletName().observe(this, this::onWalletName); diff --git a/app/src/main/java/com/alphawallet/app/ui/ImportTokenActivity.java b/app/src/main/java/com/alphawallet/app/ui/ImportTokenActivity.java index b2b5a03bb6..7a03a69111 100644 --- a/app/src/main/java/com/alphawallet/app/ui/ImportTokenActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/ImportTokenActivity.java @@ -209,17 +209,25 @@ protected void onPause() //TODO: Use Activity Launcher model (eg see tokenManagementLauncher in WalletFragment) @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: { - new HomeRouter().open(this, true); - finish(); - return true; - } + public boolean onOptionsItemSelected(MenuItem item) + { + if (item.getItemId() == android.R.id.home) + { + new HomeRouter().open(this, true); + finish(); + return true; } return super.onOptionsItemSelected(item); } + @Override + public void handleBackPressed() + { + setResult(RESULT_CANCELED); + new HomeRouter().open(this, true); + finish(); + } + private void setTicket(boolean ticket, boolean progress, boolean invalid) { LinearLayout progress_ticket = findViewById(R.id.layout_select_overlay); @@ -591,12 +599,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent) } } - @Override - public void onBackPressed() { - setResult(RESULT_CANCELED); - super.onBackPressed(); - } - /** * Return from key authorisation either through activity result (for PIN) or directly through the callback from fingerprint unlock * @param gotAuth authorisation was successful diff --git a/app/src/main/java/com/alphawallet/app/ui/ImportWalletActivity.java b/app/src/main/java/com/alphawallet/app/ui/ImportWalletActivity.java index ce16b9db6a..32cd3818ff 100644 --- a/app/src/main/java/com/alphawallet/app/ui/ImportWalletActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/ImportWalletActivity.java @@ -37,6 +37,7 @@ import com.alphawallet.app.entity.analytics.QrScanSource; import com.alphawallet.app.entity.cryptokeys.KeyEncodingType; import com.alphawallet.app.repository.EthereumNetworkBase; +import com.alphawallet.app.router.HomeRouter; import com.alphawallet.app.service.KeyService; import com.alphawallet.app.ui.QRScanning.QRScannerActivity; import com.alphawallet.app.ui.widget.OnImportKeystoreListener; @@ -342,6 +343,19 @@ else if (item.getItemId() == R.id.action_scan) return super.onOptionsItemSelected(item); } + @Override + public void handleBackPressed() + { + if (currentPage == ImportType.KEYSTORE_FORM_INDEX) + { + ((ImportKeystoreFragment) pages.get(ImportType.KEYSTORE_FORM_INDEX.ordinal()).second).backPressed(); + } + else + { + finish(); + } + } + @Override public void onSeed(String seedPhrase, Activity ctx) { diff --git a/app/src/main/java/com/alphawallet/app/ui/NetworkBaseActivity.java b/app/src/main/java/com/alphawallet/app/ui/NetworkBaseActivity.java index f16cbb4adc..129f27e80c 100644 --- a/app/src/main/java/com/alphawallet/app/ui/NetworkBaseActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/NetworkBaseActivity.java @@ -6,6 +6,7 @@ import android.view.MenuItem; import android.view.View; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -39,6 +40,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) toolbar(); initViews(); + + setDispatcher(); } @Override @@ -66,6 +69,12 @@ else if (item.getItemId() == R.id.action_node_status) return false; } + @Override + public void handleBackPressed() + { + handleSetNetworks(); + } + protected abstract void handleSetNetworks(); protected void initTestNetDialog(TestNetDialog.TestNetDialogCallback callback) diff --git a/app/src/main/java/com/alphawallet/app/ui/SelectCurrencyActivity.java b/app/src/main/java/com/alphawallet/app/ui/SelectCurrencyActivity.java index 2f4dab85bc..a6c617df0c 100644 --- a/app/src/main/java/com/alphawallet/app/ui/SelectCurrencyActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/SelectCurrencyActivity.java @@ -49,7 +49,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) } @Override - public void onBackPressed() + public void handleBackPressed() { if (!currentCurrency.equals(adapter.getSelectedItemId())) { @@ -57,7 +57,7 @@ public void onBackPressed() } else { - super.onBackPressed(); + finish(); } } diff --git a/app/src/main/java/com/alphawallet/app/ui/SendActivity.java b/app/src/main/java/com/alphawallet/app/ui/SendActivity.java index 181b1d7c98..375d4280f9 100644 --- a/app/src/main/java/com/alphawallet/app/ui/SendActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/SendActivity.java @@ -178,6 +178,12 @@ public boolean onCreateOptionsMenu(Menu menu) return super.onCreateOptionsMenu(menu); } + @Override + public void handleBackPressed() + { + onBack(); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { diff --git a/app/src/main/java/com/alphawallet/app/ui/StaticViewer.java b/app/src/main/java/com/alphawallet/app/ui/StaticViewer.java index 289cc2a150..ae2bf5c099 100644 --- a/app/src/main/java/com/alphawallet/app/ui/StaticViewer.java +++ b/app/src/main/java/com/alphawallet/app/ui/StaticViewer.java @@ -32,18 +32,13 @@ protected void onCreate(Bundle savedInstanceState) { //allow back @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: { - onBackPressed(); - return true; - } + public boolean onOptionsItemSelected(MenuItem item) + { + if (item.getItemId() == android.R.id.home) + { + finish(); + return true; } return super.onOptionsItemSelected(item); } - - @Override - public void onBackPressed() { - finish(); - } } diff --git a/app/src/main/java/com/alphawallet/app/ui/TransactionDetailActivity.java b/app/src/main/java/com/alphawallet/app/ui/TransactionDetailActivity.java index 6e07dd5adc..d2919200d2 100644 --- a/app/src/main/java/com/alphawallet/app/ui/TransactionDetailActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/TransactionDetailActivity.java @@ -581,7 +581,7 @@ private void txError(TransactionReturn txError) } @Override - public void onBackPressed() + public void handleBackPressed() { if (isFromNotification) { @@ -589,7 +589,7 @@ public void onBackPressed() } else { - super.onBackPressed(); + finish(); } } } diff --git a/app/src/main/java/com/alphawallet/app/ui/WalletActionsActivity.java b/app/src/main/java/com/alphawallet/app/ui/WalletActionsActivity.java index a3482d94e0..f9c4c5f30a 100644 --- a/app/src/main/java/com/alphawallet/app/ui/WalletActionsActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/WalletActionsActivity.java @@ -165,6 +165,15 @@ private void onSaved(Integer integer) setENSText(); } + @Override + public void handleBackPressed() + { + if (isNewWallet) + { + preFinish(); //drop back to home screen, no need to recreate everything + } + } + @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -311,10 +320,14 @@ private void saveWalletName() finish(); } - private void doBackUp() { - if (wallet.type == WalletType.HDKEY) { + private void doBackUp() + { + if (wallet.type == WalletType.HDKEY) + { testSeedPhrase(wallet); - } else { + } + else + { exportJSON(wallet); } } @@ -382,11 +395,15 @@ private void hideDialog() { } @Override - public void run() { - if (successOverlay.getAlpha() > 0) { + public void run() + { + if (successOverlay.getAlpha() > 0) + { successOverlay.animate().alpha(0.0f).setDuration(500); handler.postDelayed(this, 750); - } else { + } + else + { successOverlay.setVisibility(View.GONE); successOverlay.setAlpha(1.0f); } diff --git a/app/src/main/java/com/alphawallet/app/ui/WalletsActivity.java b/app/src/main/java/com/alphawallet/app/ui/WalletsActivity.java index bcd56587d9..08d6894eee 100644 --- a/app/src/main/java/com/alphawallet/app/ui/WalletsActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/WalletsActivity.java @@ -264,6 +264,12 @@ private void backPressed() } } + @Override + public void handleBackPressed() + { + backPressed(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) {