Skip to content
Snippets Groups Projects
Commit 0a4d74ee authored by Alexandre Lision's avatar Alexandre Lision
Browse files

account: fix crash in details screen

This was due to the account observer not being removed. When reopening
the details, the previous observer was still alive and was trying to
refresh the UI account on a destroyed view instance

Change-Id: I14021b9ae231e32bb019d6c10d4d88f558b150db
Tuleap: #894
parent 5137ad4a
No related branches found
No related tags found
No related merge requests found
...@@ -94,7 +94,31 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe ...@@ -94,7 +94,31 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
@Override @Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
processAccount(); if (mAccSelected == null || mService == null) {
return;
}
final Account acc = mAccSelected;
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(acc.getAlias());
}
final IDRingService remote = getRemoteService();
if (remote == null) {
Log.w(TAG, "Error updating account, remote service is null");
return;
}
mService.getThreadPool().submit(new Runnable() {
@Override
public void run() {
try {
remote.setCredentials(acc.getAccountID(), acc.getCredentialsHashMapList());
remote.setAccountDetails(acc.getAccountID(), acc.getDetails());
} catch (RemoteException e) {
e.printStackTrace();
}
}
});
} }
}; };
...@@ -106,12 +130,13 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe ...@@ -106,12 +130,13 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
mService = binder.getService(); mService = binder.getService();
mBound = true; mBound = true;
String account_id = getIntent().getData().getLastPathSegment(); String accountId = getIntent().getData().getLastPathSegment();
Log.i(TAG, "Service connected " + className.getClassName() + " " + getIntent().getData().toString()); Log.i(TAG, "Service connected " + className.getClassName() + " " + getIntent().getData().toString());
mAccSelected = mService.getAccount(account_id); mAccSelected = mService.getAccount(accountId);
if (mAccSelected == null) if (mAccSelected == null) {
finish(); finish();
}
mAccSelected.addObserver(mAccountObserver); mAccSelected.addObserver(mAccountObserver);
getSupportActionBar().setTitle(mAccSelected.getAlias()); getSupportActionBar().setTitle(mAccSelected.getAlias());
...@@ -134,6 +159,7 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe ...@@ -134,6 +159,7 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
@Override @Override
public void onServiceDisconnected(ComponentName arg0) { public void onServiceDisconnected(ComponentName arg0) {
// Called in case of service crashing or getting killed
mAccSelected.deleteObserver(mAccountObserver); mAccSelected.deleteObserver(mAccountObserver);
mBound = false; mBound = false;
} }
...@@ -167,6 +193,9 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe ...@@ -167,6 +193,9 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
if (mBound) { if (mBound) {
unbindService(mConnection); unbindService(mConnection);
if (mAccSelected != null) {
mAccSelected.deleteObserver(mAccountObserver);
}
mBound = false; mBound = false;
} }
} }
...@@ -184,33 +213,13 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe ...@@ -184,33 +213,13 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
case R.id.menuitem_export: case R.id.menuitem_export:
startExport(); startExport();
break; break;
default:
break;
} }
return true; return true;
} }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
private void processAccount() {
final Account acc = mAccSelected;
final IDRingService remote = getRemoteService();
getSupportActionBar().setTitle(acc.getAlias());
mService.getThreadPool().submit(new Runnable() {
@Override
public void run() {
try {
remote.setCredentials(acc.getAccountID(), acc.getCredentialsHashMapList());
remote.setAccountDetails(acc.getAccountID(), acc.getDetails());
} catch (RemoteException e) {
e.printStackTrace();
}
}
});
}
private AlertDialog createDeleteDialog() { private AlertDialog createDeleteDialog() {
Activity ownerActivity = this; Activity ownerActivity = this;
AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
...@@ -268,7 +277,7 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe ...@@ -268,7 +277,7 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
} }
private void startExport() { private void startExport() {
boolean hasPermission = (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED); boolean hasPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
if (hasPermission) { if (hasPermission) {
showExportDialog(); showExportDialog();
} else { } else {
...@@ -297,7 +306,7 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe ...@@ -297,7 +306,7 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = getLayoutInflater();
ViewGroup v = (ViewGroup) inflater.inflate(R.layout.dialog_account_export, null); ViewGroup v = (ViewGroup) inflater.inflate(R.layout.dialog_account_export, null);
final TextView pwd = (TextView) v.findViewById(R.id.newpwd_txt); final TextView pwd = (TextView) v.findViewById(R.id.newpwd_txt);
final TextView pwd_confirm = (TextView) v.findViewById(R.id.newpwd_confirm_txt); final TextView pwdConfirm = (TextView) v.findViewById(R.id.newpwd_confirm_txt);
builder.setMessage(R.string.account_export_message) builder.setMessage(R.string.account_export_message)
.setTitle(R.string.account_export_title) .setTitle(R.string.account_export_title)
.setPositiveButton(R.string.account_export, null) .setPositiveButton(R.string.account_export, null)
...@@ -313,10 +322,8 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe ...@@ -313,10 +322,8 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
pwd.setOnEditorActionListener(new TextView.OnEditorActionListener() { pwd.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override @Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.w(TAG, "onEditorAction " + actionId + " " + (event == null ? null : event.toString())); Log.i(TAG, "onEditorAction " + actionId + " " + (event == null ? null : event.toString()));
if (actionId == EditorInfo.IME_ACTION_NEXT) return actionId == EditorInfo.IME_ACTION_NEXT && checkPassword(v, null);
return checkPassword(v, null);
return false;
} }
}); });
pwd.setOnFocusChangeListener(new View.OnFocusChangeListener() { pwd.setOnFocusChangeListener(new View.OnFocusChangeListener() {
...@@ -329,16 +336,14 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe ...@@ -329,16 +336,14 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
} }
} }
}); });
pwd_confirm.setOnEditorActionListener(new TextView.OnEditorActionListener() { pwdConfirm.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override @Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Log.w(TAG, "onEditorAction " + actionId + " " + (event == null ? null : event.toString())); Log.w(TAG, "onEditorAction " + actionId + " " + (event == null ? null : event.toString()));
if (actionId == EditorInfo.IME_ACTION_DONE) { if (actionId == EditorInfo.IME_ACTION_DONE && !checkPassword(pwd, v)) {
if (!checkPassword(pwd, v)) {
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).callOnClick(); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).callOnClick();
return true; return true;
} }
}
return false; return false;
} }
}); });
...@@ -349,7 +354,7 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe ...@@ -349,7 +354,7 @@ public class AccountEditionActivity extends AppCompatActivity implements LocalSe
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (!checkPassword(pwd, pwd_confirm)) { if (!checkPassword(pwd, pwdConfirm)) {
final String pwd_txt = pwd.getText().toString(); final String pwd_txt = pwd.getText().toString();
alertDialog.dismiss(); alertDialog.dismiss();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment