Skip to content

Commit 0e760a3

Browse files
Fix some legacy code issues and tidy up wallet naming (#3371)
1 parent 3d728ed commit 0e760a3

17 files changed

+286
-203
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ android {
5252
applicationId "io.stormbird.wallet"
5353
minSdk 24
5454
targetSdk 34
55-
versionCode 259
55+
versionCode 261
5656
versionName "3.79"
5757

5858
android.buildFeatures.buildConfig true

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<uses-permission android:name="android.permission.WAKE_LOCK" />
1515
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
1616
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
17+
<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>
1718

1819
<uses-feature
1920
android:name="android.hardware.fingerprint"

app/src/main/java/com/alphawallet/app/ui/BackupFlowActivity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,13 @@ private void initViews() {
157157
public boolean onOptionsItemSelected(MenuItem item) {
158158
if (item.getItemId() == android.R.id.home)
159159
{
160-
onBackPressed();
160+
backPressed();
161161
return true;
162162
}
163163
return super.onOptionsItemSelected(item);
164164
}
165165

166-
@Override
167-
public void onBackPressed() {
166+
public void backPressed() {
168167
Intent intent = new Intent();
169168
setResult(RESULT_CANCELED, intent);
170169
intent.putExtra("Key", wallet.address);

app/src/main/java/com/alphawallet/app/ui/BackupKeyActivity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,14 @@ public boolean onOptionsItemSelected(MenuItem item)
391391
{
392392
case android.R.id.home:
393393
{
394-
onBackPressed();
394+
backPressed();
395395
return true;
396396
}
397397
}
398398
return super.onOptionsItemSelected(item);
399399
}
400400

401-
@Override
402-
public void onBackPressed()
401+
private void backPressed()
403402
{
404403
switch (state)
405404
{

app/src/main/java/com/alphawallet/app/ui/Erc20DetailActivity.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,11 @@ private void setTokenListener()
325325
realmTokenUpdates = realm.where(RealmToken.class).equalTo("address", dbKey)
326326
.greaterThan("addedTime", System.currentTimeMillis() - 5 * DateUtils.MINUTE_IN_MILLIS).findAllAsync();
327327
realmTokenUpdates.addChangeListener(realmTokens -> {
328-
if (realmTokens.size() == 0) return;
328+
if (realmTokens.isEmpty())
329+
{
330+
return;
331+
}
332+
329333
for (RealmToken t : realmTokens)
330334
{
331335
TokenCardMeta meta = new TokenCardMeta(t.getChainId(), t.getTokenAddress(), t.getBalance(),
@@ -363,7 +367,6 @@ private void playNotification()
363367
@Override
364368
public boolean onCreateOptionsMenu(Menu menu)
365369
{
366-
// getMenuInflater().inflate(R.menu.menu_show_contract, menu);
367370
return super.onCreateOptionsMenu(menu);
368371
}
369372

app/src/main/java/com/alphawallet/app/ui/GasSettingsActivity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,12 @@ public boolean onOptionsItemSelected(MenuItem item)
228228
{
229229
if (item.getItemId() == android.R.id.home)
230230
{
231-
onBackPressed();
231+
backPressed();
232232
}
233233
return super.onOptionsItemSelected(item);
234234
}
235235

236-
@Override
237-
public void onBackPressed()
236+
private void backPressed()
238237
{
239238
Intent result = new Intent();
240239
GasSpeed gs = gasSpread.getSelectedGasFee(currentGasSpeedIndex);

app/src/main/java/com/alphawallet/app/ui/HomeActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public class HomeActivity extends BaseNavigationActivity implements View.OnClick
102102
{
103103
@Inject
104104
AWWalletConnectClient awWalletConnectClient;
105-
106105
public static final int RC_ASSET_EXTERNAL_WRITE_PERM = 223;
107106
public static final int RC_ASSET_NOTIFICATION_PERM = 224;
108107
public static final int DAPP_BARCODE_READER_REQUEST_CODE = 1;

app/src/main/java/com/alphawallet/app/ui/NetworkBaseActivity.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ else if (item.getItemId() == R.id.action_node_status)
6666
return false;
6767
}
6868

69-
@Override
70-
public void onBackPressed()
71-
{
72-
handleSetNetworks();
73-
}
74-
7569
protected abstract void handleSetNetworks();
7670

7771
protected void initTestNetDialog(TestNetDialog.TestNetDialogCallback callback)

app/src/main/java/com/alphawallet/app/ui/WalletActionsActivity.java

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,26 @@
2828
import com.alphawallet.app.R;
2929
import com.alphawallet.app.entity.BackupOperationType;
3030
import com.alphawallet.app.entity.ErrorEnvelope;
31+
import com.alphawallet.app.entity.StandardFunctionInterface;
3132
import com.alphawallet.app.entity.Wallet;
3233
import com.alphawallet.app.entity.WalletType;
3334
import com.alphawallet.app.ui.widget.entity.AddressReadyCallback;
3435
import com.alphawallet.app.util.Utils;
3536
import com.alphawallet.app.viewmodel.WalletActionsViewModel;
3637
import com.alphawallet.app.widget.AWalletAlertDialog;
38+
import com.alphawallet.app.widget.FunctionButtonBar;
3739
import com.alphawallet.app.widget.InputAddress;
40+
import com.alphawallet.app.widget.InputView;
3841
import com.alphawallet.app.widget.SettingsItemView;
3942
import com.alphawallet.app.widget.UserAvatar;
4043

44+
import java.util.ArrayList;
45+
import java.util.Collections;
46+
4147
import dagger.hilt.android.AndroidEntryPoint;
4248

4349
@AndroidEntryPoint
44-
public class WalletActionsActivity extends BaseActivity implements Runnable, View.OnClickListener, AddressReadyCallback
50+
public class WalletActionsActivity extends BaseActivity implements Runnable, View.OnClickListener, AddressReadyCallback, StandardFunctionInterface
4551
{
4652
WalletActionsViewModel viewModel;
4753

@@ -55,12 +61,12 @@ public class WalletActionsActivity extends BaseActivity implements Runnable, Vie
5561
private SettingsItemView deleteWalletSetting;
5662
private SettingsItemView backUpSetting;
5763
private InputAddress inputAddress;
64+
private InputView inputName;
5865
private LinearLayout successOverlay;
5966
private AWalletAlertDialog aDialog;
6067
private final Handler handler = new Handler();
6168

6269
private Wallet wallet;
63-
private int walletCount;
6470
private boolean isNewWallet;
6571

6672
@Override
@@ -70,10 +76,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
7076
toolbar();
7177
setTitle(getString(R.string.manage_wallet));
7278

79+
FunctionButtonBar functionBar = findViewById(R.id.layoutButtons);
80+
functionBar.setupFunctions(this, new ArrayList<>(Collections.singletonList(R.string.action_save_name)));
81+
functionBar.revealButtons();
82+
7383
if (getIntent() != null) {
7484
wallet = (Wallet) getIntent().getExtras().get("wallet");
75-
walletCount = getIntent().getIntExtra("walletCount", 0);
76-
walletCount++;
7785
isNewWallet = getIntent().getBooleanExtra("isNewWallet", false);
7886
initViews();
7987
} else {
@@ -106,13 +114,36 @@ private void initViewModel() {
106114
viewModel.exportWalletError().observe(this, this::onExportError);
107115
viewModel.deleted().observe(this, this::onDeleteWallet);
108116
viewModel.isTaskRunning().observe(this, this::onTaskStatusChanged);
117+
viewModel.walletCount().observe(this, this::setWalletName);
118+
viewModel.ensName().observe(this, this::fetchedENSName);
109119

110-
if (isNewWallet) {
111-
wallet.name = getString(R.string.wallet_name_template, walletCount);
112-
viewModel.updateWallet(wallet);
120+
if (isNewWallet)
121+
{
122+
viewModel.fetchWalletCount();
123+
}
124+
125+
if (wallet != null && TextUtils.isEmpty(wallet.ENSname))
126+
{
127+
//scan for ENS name
128+
viewModel.scanForENS(wallet, this);
113129
}
114130
}
115131

132+
private void fetchedENSName(String ensName)
133+
{
134+
if (!TextUtils.isEmpty(ensName))
135+
{
136+
inputAddress.setENSName(ensName);
137+
}
138+
}
139+
140+
private void setWalletName(int walletCount)
141+
{
142+
wallet.name = getString(R.string.wallet_name_template, walletCount + 1);
143+
inputName.setText(wallet.name);
144+
viewModel.updateWallet(wallet);
145+
}
146+
116147
@Override
117148
public boolean onCreateOptionsMenu(Menu menu)
118149
{
@@ -139,7 +170,11 @@ public boolean onOptionsItemSelected(MenuItem item)
139170
{
140171
if (item.getItemId() == android.R.id.home)
141172
{
142-
onBackPressed();
173+
if (isNewWallet)
174+
{
175+
preFinish(); //drop back to home screen, no need to recreate everything
176+
}
177+
finish();
143178
return true;
144179
}
145180
else if (item.getItemId() == R.id.action_key_status)
@@ -153,18 +188,10 @@ else if (item.getItemId() == R.id.action_key_status)
153188
return super.onOptionsItemSelected(item);
154189
}
155190

156-
@Override
157-
public void onBackPressed()
191+
private void onDeleteWallet(Boolean isDeleted)
158192
{
159-
super.onBackPressed();
160-
if (isNewWallet)
193+
if (isDeleted)
161194
{
162-
preFinish(); //drop back to home screen, no need to recreate everything
163-
}
164-
}
165-
166-
private void onDeleteWallet(Boolean isDeleted) {
167-
if (isDeleted) {
168195
showWalletsActivity();
169196
}
170197
}
@@ -193,7 +220,8 @@ private void onDeleteError(ErrorEnvelope errorEnvelope) {
193220
aDialog.show();
194221
}
195222

196-
private void initViews() {
223+
private void initViews()
224+
{
197225
walletIcon = findViewById(R.id.wallet_icon);
198226
walletBalance = findViewById(R.id.wallet_balance);
199227
walletBalanceCurrency = findViewById(R.id.wallet_currency);
@@ -204,6 +232,7 @@ private void initViews() {
204232
backUpSetting = findViewById(R.id.setting_backup);
205233
walletSelectedIcon = findViewById(R.id.selected_wallet_indicator);
206234
inputAddress = findViewById(R.id.input_ens);
235+
inputName = findViewById(R.id.input_name);
207236
walletSelectedIcon.setOnClickListener(this);
208237

209238
walletIcon.bind(wallet);
@@ -230,22 +259,43 @@ else if (wallet.type == WalletType.WATCH || wallet.type == WalletType.HARDWARE)
230259
findViewById(R.id.layout_backup_method).setVisibility(View.GONE);
231260
}
232261

233-
inputAddress.setAddress(wallet.ENSname);
234-
inputAddress.setAddressCallback(this);
262+
setupWalletNames();
263+
}
264+
265+
private void setupWalletNames()
266+
{
267+
if (!TextUtils.isEmpty(wallet.ENSname))
268+
{
269+
inputAddress.setAddress(wallet.ENSname);
270+
}
271+
272+
if (!Utils.isDefaultName(wallet.name, this))
273+
{
274+
inputName.setText(wallet.name);
275+
}
235276
}
236277

237278
private void setENSText()
238279
{
239-
if (wallet.ENSname != null && !wallet.ENSname.isEmpty()) {
280+
if (!TextUtils.isEmpty(wallet.ENSname))
281+
{
240282
walletNameText.setText(wallet.ENSname);
241283
walletNameText.setVisibility(View.VISIBLE);
242284
walletAddressSeparator.setVisibility(View.VISIBLE);
243-
} else {
285+
}
286+
else
287+
{
244288
walletNameText.setVisibility(View.GONE);
245289
walletAddressSeparator.setVisibility(View.GONE);
246290
}
247291
}
248292

293+
@Override
294+
public void handleClick(String action, int actionId)
295+
{
296+
saveWalletName();
297+
}
298+
249299
private void onDeleteWalletSettingClicked() {
250300
confirmDelete(wallet);
251301
}
@@ -254,13 +304,11 @@ private void onBackUpSettingClicked() {
254304
doBackUp();
255305
}
256306

257-
private void saveWalletName() {
258-
// wallet.name = walletNameText.getText().toString();
307+
private void saveWalletName()
308+
{
309+
wallet.name = inputName.getText().toString();
259310
viewModel.updateWallet(wallet);
260-
if (isNewWallet) {
261-
viewModel.showHome(this);
262-
preFinish(); //drop back to home screen, no need to recreate everything
263-
}
311+
finish();
264312
}
265313

266314
private void doBackUp() {

app/src/main/java/com/alphawallet/app/ui/WalletDiagnosticActivity.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.os.Handler;
99
import android.os.Looper;
1010
import android.util.Pair;
11+
import android.view.Menu;
1112
import android.view.MenuItem;
1213
import android.view.View;
1314
import android.widget.LinearLayout;
@@ -47,6 +48,7 @@
4748
import dagger.hilt.android.AndroidEntryPoint;
4849
import io.reactivex.android.schedulers.AndroidSchedulers;
4950
import io.reactivex.schedulers.Schedulers;
51+
import timber.log.Timber;
5052
import wallet.core.jni.CoinType;
5153
import wallet.core.jni.HDWallet;
5254
import wallet.core.jni.PrivateKey;
@@ -151,13 +153,18 @@ private void startKeyDiagnostic()
151153
}
152154
}
153155

156+
@Override
157+
public boolean onCreateOptionsMenu(Menu menu)
158+
{
159+
return super.onCreateOptionsMenu(menu);
160+
}
161+
154162
@Override
155163
public boolean onOptionsItemSelected(MenuItem item)
156164
{
157165
if (item.getItemId() == android.R.id.home)
158166
{
159-
onBackPressed();
160-
return true;
167+
finish();
161168
}
162169

163170
return super.onOptionsItemSelected(item);
@@ -402,7 +409,7 @@ private boolean testKeyType(String keyData)
402409

403410
private int wordCount(String value)
404411
{
405-
if (value == null || value.length() == 0) return 0;
412+
if (value == null || value.isEmpty()) return 0;
406413
String[] split = value.split("\\s+");
407414
return split.length;
408415
}
@@ -411,7 +418,7 @@ private int wordCount(String value)
411418
// Always use the ActionSheet + implement ActionSheetCallback as per SendActivity, NFTAssetDetailActivity etc
412419
private void doUnlock(UnlockCallback cb)
413420
{
414-
if (BuildConfig.DEBUG /*&& Utils.isRunningTest()*/) //running tests in debug build mode, we don't use key unlock
421+
if (BuildConfig.DEBUG && Utils.isRunningTest()) //running tests in debug build mode, we don't use key unlock
415422
{
416423
cb.carryOn(true);
417424
return;
@@ -455,7 +462,7 @@ private String dumpKeystoreFromSeedPhrase(String seedPhrase, String keystorePass
455462
}
456463
catch (Exception e)
457464
{
458-
e.printStackTrace();
465+
Timber.e(e);
459466
}
460467

461468
return "";

0 commit comments

Comments
 (0)