Skip to content

Commit

Permalink
Fix Navbar back click response
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesSmartCell committed Mar 26, 2024
1 parent 2f1161a commit 83a71b2
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/com/alphawallet/app/ui/BackupKeyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 24 additions & 2 deletions app/src/main/java/com/alphawallet/app/ui/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +49,8 @@ protected void setTitle(String title)
}
toolbarTitle.setText(title);
}

setDispatcher();
}

protected void setSubtitle(String subtitle)
Expand Down Expand Up @@ -88,7 +91,7 @@ protected void enableDisplayHomeAsHome(boolean active)
}
}

protected void dissableDisplayHomeAsUp()
protected void disableDisplayHomeAsUp()
{
ActionBar actionBar = getSupportActionBar();
if (actionBar != null)
Expand Down Expand Up @@ -120,7 +123,7 @@ public boolean onOptionsItemSelected(MenuItem item)
{
if (item.getItemId() == android.R.id.home)
{
onBackPressed();
handleBackPressed();
finish();
}
return true;
Expand Down Expand Up @@ -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();
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/alphawallet/app/ui/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public void onPageScrollStateChanged(int state)
});

initBottomNavigation();
dissableDisplayHomeAsUp();
disableDisplayHomeAsUp();

viewModel.error().observe(this, this::onError);
viewModel.walletName().observe(this, this::onWalletName);
Expand Down
28 changes: 15 additions & 13 deletions app/src/main/java/com/alphawallet/app/ui/ImportTokenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/alphawallet/app/ui/ImportWalletActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,6 +40,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState)
toolbar();

initViews();

setDispatcher();
}

@Override
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ protected void onCreate(@Nullable Bundle savedInstanceState)
}

@Override
public void onBackPressed()
public void handleBackPressed()
{
if (!currentCurrency.equals(adapter.getSelectedItemId()))
{
setCurrency();
}
else
{
super.onBackPressed();
finish();
}
}

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/alphawallet/app/ui/SendActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ public boolean onCreateOptionsMenu(Menu menu)
return super.onCreateOptionsMenu(menu);
}

@Override
public void handleBackPressed()
{
onBack();
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
Expand Down
17 changes: 6 additions & 11 deletions app/src/main/java/com/alphawallet/app/ui/StaticViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,15 @@ private void txError(TransactionReturn txError)
}

@Override
public void onBackPressed()
public void handleBackPressed()
{
if (isFromNotification)
{
new HomeRouter().open(this, true);
}
else
{
super.onBackPressed();
finish();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/alphawallet/app/ui/WalletsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ private void backPressed()
}
}

@Override
public void handleBackPressed()
{
backPressed();
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
Expand Down

0 comments on commit 83a71b2

Please sign in to comment.