4444import android .view .ViewGroup ;
4545import android .view .WindowManager ;
4646import android .widget .Button ;
47+ import android .widget .ImageButton ;
4748import android .widget .ImageView ;
4849import android .widget .LinearLayout ;
4950
@@ -187,11 +188,15 @@ public void onClick(DialogInterface dialogInterface, int i) {
187188 .show ();
188189 }
189190
191+ private boolean newContact = false ;
192+
190193 // Callbacks from NodeInfoAdapter
191194 @ Override
192195 public void onSelectContact (final View view , final Contact contact ) {
193196 Timber .d ("onSelectContact" );
194197
198+ newContact = false ;
199+
195200 if (readonly ) {
196201 Config .write (Config .CONFIG_KEY_SELECTED_ADDRESS , contact .getAddress ());
197202 activityCallback .onBackPressed ();
@@ -208,6 +213,8 @@ public void onSelectContact(final View view, final Contact contact) {
208213 public void onClick (View v ) {
209214 int id = v .getId ();
210215 if (id == R .id .fabAddContact ) {
216+ newContact = true ;
217+
211218 EditDialog diag = createEditDialog (null );
212219 if (diag != null ) {
213220 diag .show ();
@@ -236,29 +243,20 @@ public void refreshContacts() {
236243 private EditDialog editDialog = null ; // for preventing opening of multiple dialogs
237244
238245 private EditDialog createEditDialog (final Contact contact ) {
239- if (contactEditTmp != null ) {
240- if (editDialog != null ) {
241- editDialog .closeDialog ();
242- editDialog = null ;
243- }
244-
245- return new EditDialog (contact );
246+ if (editDialog != null ) {
247+ editDialog .closeDialog ();
248+ editDialog = null ;
246249 }
247250
248- if (editDialog != null )
249- return null ; // we are already open
250-
251251 editDialog = new EditDialog (contact );
252252
253253 return editDialog ;
254254 }
255255
256- private Contact contactEditTmp = null ;
256+ private Contact contactEdit = null ;
257+ private Contact contactEditBackup = null ;
257258
258259 class EditDialog {
259- Contact contactEdit ;
260- Contact contactEditBackup ;
261-
262260 private boolean applyChanges () {
263261 final String contactName = etContactName .getEditText ().getText ().toString ().trim ();
264262 if (contactName .isEmpty ()) {
@@ -272,7 +270,7 @@ private boolean applyChanges() {
272270 if (walletAddress .isEmpty ()) {
273271 etWalletAddress .setError (getString (R .string .contact_value_empty ));
274272 return false ;
275- } else if (!Wallet .isAddressValid (walletAddress )){
273+ } else if (!Wallet .isAddressValid (walletAddress )) {
276274 etWalletAddress .setError (getString (R .string .generate_check_address ));
277275 return false ;
278276 } else {
@@ -283,26 +281,23 @@ private boolean applyChanges() {
283281 }
284282
285283 private boolean applyChangesTmp () {
286- contactEditTmp = new Contact ();
287-
288284 final String contactName = etContactName .getEditText ().getText ().toString ().trim ();
289- contactEditTmp .setName (contactName );
285+ contactEdit .setName (contactName );
290286
291287 final String walletAddress = etWalletAddress .getEditText ().getText ().toString ().trim ();
292- contactEditTmp .setAddress (walletAddress );
288+ contactEdit .setAddress (walletAddress );
293289
294290 return true ;
295291 }
296292
297- private boolean shutdown = false ;
298-
299293 private void apply () {
300294 if (applyChanges ()) {
301295 closeDialog ();
302296
303- contactsAdapter .addContact (contactEdit );
297+ if (newContact )
298+ contactsAdapter .addContact (contactEdit );
304299
305- shutdown = true ;
300+ contactsAdapter . dataSetChanged () ;
306301
307302 refreshContacts ();
308303 }
@@ -328,10 +323,6 @@ private void show() {
328323 editDialog .show ();
329324 }
330325
331- private void showKeyboard () {
332- Helper .showKeyboard (editDialog );
333- }
334-
335326 androidx .appcompat .app .AlertDialog editDialog = null ;
336327
337328 TextInputLayout etContactName ;
@@ -350,6 +341,17 @@ private void showKeyboard() {
350341 etWalletAddress = promptsView .findViewById (R .id .etWalletAddress );
351342 ivAvatar = promptsView .findViewById (R .id .ivAvatar );
352343
344+ ImageButton bPasteAddress = promptsView .findViewById (R .id .bPasteAddress );
345+ bPasteAddress .setOnClickListener (new View .OnClickListener () {
346+ @ Override
347+ public void onClick (View view ) {
348+ final String clip = Helper .getClipBoardText (getActivity ());
349+ if (clip == null ) return ;
350+
351+ etWalletAddress .getEditText ().setText (clip );
352+ }
353+ });
354+
353355 Button btnSelectImage = promptsView .findViewById (R .id .btnSelectImage );
354356 btnSelectImage .setOnClickListener (new View .OnClickListener () {
355357 @ Override
@@ -361,7 +363,10 @@ public void onClick(View view) {
361363
362364 if (contact != null ) {
363365 contactEdit = contact ;
364- contactEditBackup = new Contact (contact );
366+
367+ if (contactEditBackup == null )
368+ contactEditBackup = new Contact (contact );
369+
365370 etContactName .getEditText ().setText (contact .getName ());
366371 etWalletAddress .getEditText ().setText (contact .getAddress ());
367372
@@ -435,9 +440,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
435440 // Already save the cropped image
436441 Bitmap bitmap = Helper .getCroppedBitmap ((Bitmap ) data .getExtras ().get ("data" ));
437442
438- contactEditTmp .setAvatar (bitmap );
443+ contactEdit .setAvatar (bitmap );
439444
440- EditDialog diag = createEditDialog (contactEditTmp );
445+ EditDialog diag = createEditDialog (contactEdit );
441446 if (diag != null ) {
442447 diag .show ();
443448 }
0 commit comments