28
28
import com .alphawallet .app .R ;
29
29
import com .alphawallet .app .entity .BackupOperationType ;
30
30
import com .alphawallet .app .entity .ErrorEnvelope ;
31
+ import com .alphawallet .app .entity .StandardFunctionInterface ;
31
32
import com .alphawallet .app .entity .Wallet ;
32
33
import com .alphawallet .app .entity .WalletType ;
33
34
import com .alphawallet .app .ui .widget .entity .AddressReadyCallback ;
34
35
import com .alphawallet .app .util .Utils ;
35
36
import com .alphawallet .app .viewmodel .WalletActionsViewModel ;
36
37
import com .alphawallet .app .widget .AWalletAlertDialog ;
38
+ import com .alphawallet .app .widget .FunctionButtonBar ;
37
39
import com .alphawallet .app .widget .InputAddress ;
40
+ import com .alphawallet .app .widget .InputView ;
38
41
import com .alphawallet .app .widget .SettingsItemView ;
39
42
import com .alphawallet .app .widget .UserAvatar ;
40
43
44
+ import java .util .ArrayList ;
45
+ import java .util .Collections ;
46
+
41
47
import dagger .hilt .android .AndroidEntryPoint ;
42
48
43
49
@ AndroidEntryPoint
44
- public class WalletActionsActivity extends BaseActivity implements Runnable , View .OnClickListener , AddressReadyCallback
50
+ public class WalletActionsActivity extends BaseActivity implements Runnable , View .OnClickListener , AddressReadyCallback , StandardFunctionInterface
45
51
{
46
52
WalletActionsViewModel viewModel ;
47
53
@@ -55,12 +61,12 @@ public class WalletActionsActivity extends BaseActivity implements Runnable, Vie
55
61
private SettingsItemView deleteWalletSetting ;
56
62
private SettingsItemView backUpSetting ;
57
63
private InputAddress inputAddress ;
64
+ private InputView inputName ;
58
65
private LinearLayout successOverlay ;
59
66
private AWalletAlertDialog aDialog ;
60
67
private final Handler handler = new Handler ();
61
68
62
69
private Wallet wallet ;
63
- private int walletCount ;
64
70
private boolean isNewWallet ;
65
71
66
72
@ Override
@@ -70,10 +76,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
70
76
toolbar ();
71
77
setTitle (getString (R .string .manage_wallet ));
72
78
79
+ FunctionButtonBar functionBar = findViewById (R .id .layoutButtons );
80
+ functionBar .setupFunctions (this , new ArrayList <>(Collections .singletonList (R .string .action_save_name )));
81
+ functionBar .revealButtons ();
82
+
73
83
if (getIntent () != null ) {
74
84
wallet = (Wallet ) getIntent ().getExtras ().get ("wallet" );
75
- walletCount = getIntent ().getIntExtra ("walletCount" , 0 );
76
- walletCount ++;
77
85
isNewWallet = getIntent ().getBooleanExtra ("isNewWallet" , false );
78
86
initViews ();
79
87
} else {
@@ -106,13 +114,36 @@ private void initViewModel() {
106
114
viewModel .exportWalletError ().observe (this , this ::onExportError );
107
115
viewModel .deleted ().observe (this , this ::onDeleteWallet );
108
116
viewModel .isTaskRunning ().observe (this , this ::onTaskStatusChanged );
117
+ viewModel .walletCount ().observe (this , this ::setWalletName );
118
+ viewModel .ensName ().observe (this , this ::fetchedENSName );
109
119
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 );
113
129
}
114
130
}
115
131
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
+
116
147
@ Override
117
148
public boolean onCreateOptionsMenu (Menu menu )
118
149
{
@@ -139,7 +170,11 @@ public boolean onOptionsItemSelected(MenuItem item)
139
170
{
140
171
if (item .getItemId () == android .R .id .home )
141
172
{
142
- onBackPressed ();
173
+ if (isNewWallet )
174
+ {
175
+ preFinish (); //drop back to home screen, no need to recreate everything
176
+ }
177
+ finish ();
143
178
return true ;
144
179
}
145
180
else if (item .getItemId () == R .id .action_key_status )
@@ -153,18 +188,10 @@ else if (item.getItemId() == R.id.action_key_status)
153
188
return super .onOptionsItemSelected (item );
154
189
}
155
190
156
- @ Override
157
- public void onBackPressed ()
191
+ private void onDeleteWallet (Boolean isDeleted )
158
192
{
159
- super .onBackPressed ();
160
- if (isNewWallet )
193
+ if (isDeleted )
161
194
{
162
- preFinish (); //drop back to home screen, no need to recreate everything
163
- }
164
- }
165
-
166
- private void onDeleteWallet (Boolean isDeleted ) {
167
- if (isDeleted ) {
168
195
showWalletsActivity ();
169
196
}
170
197
}
@@ -193,7 +220,8 @@ private void onDeleteError(ErrorEnvelope errorEnvelope) {
193
220
aDialog .show ();
194
221
}
195
222
196
- private void initViews () {
223
+ private void initViews ()
224
+ {
197
225
walletIcon = findViewById (R .id .wallet_icon );
198
226
walletBalance = findViewById (R .id .wallet_balance );
199
227
walletBalanceCurrency = findViewById (R .id .wallet_currency );
@@ -204,6 +232,7 @@ private void initViews() {
204
232
backUpSetting = findViewById (R .id .setting_backup );
205
233
walletSelectedIcon = findViewById (R .id .selected_wallet_indicator );
206
234
inputAddress = findViewById (R .id .input_ens );
235
+ inputName = findViewById (R .id .input_name );
207
236
walletSelectedIcon .setOnClickListener (this );
208
237
209
238
walletIcon .bind (wallet );
@@ -230,22 +259,43 @@ else if (wallet.type == WalletType.WATCH || wallet.type == WalletType.HARDWARE)
230
259
findViewById (R .id .layout_backup_method ).setVisibility (View .GONE );
231
260
}
232
261
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
+ }
235
276
}
236
277
237
278
private void setENSText ()
238
279
{
239
- if (wallet .ENSname != null && !wallet .ENSname .isEmpty ()) {
280
+ if (!TextUtils .isEmpty (wallet .ENSname ))
281
+ {
240
282
walletNameText .setText (wallet .ENSname );
241
283
walletNameText .setVisibility (View .VISIBLE );
242
284
walletAddressSeparator .setVisibility (View .VISIBLE );
243
- } else {
285
+ }
286
+ else
287
+ {
244
288
walletNameText .setVisibility (View .GONE );
245
289
walletAddressSeparator .setVisibility (View .GONE );
246
290
}
247
291
}
248
292
293
+ @ Override
294
+ public void handleClick (String action , int actionId )
295
+ {
296
+ saveWalletName ();
297
+ }
298
+
249
299
private void onDeleteWalletSettingClicked () {
250
300
confirmDelete (wallet );
251
301
}
@@ -254,13 +304,11 @@ private void onBackUpSettingClicked() {
254
304
doBackUp ();
255
305
}
256
306
257
- private void saveWalletName () {
258
- // wallet.name = walletNameText.getText().toString();
307
+ private void saveWalletName ()
308
+ {
309
+ wallet .name = inputName .getText ().toString ();
259
310
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 ();
264
312
}
265
313
266
314
private void doBackUp () {
0 commit comments