aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-10-12 12:41:21 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-10-12 12:41:21 +0900
commit20c91cce4edb83d747bd1e78e9b473e93a6eb441 (patch)
tree012490f8c39e98fd30d874bc2ac37055e09a604b
parent59fb103862ecdc926831370e2d853f14a0d81aea (diff)
downloadSmileEssence-20c91cce4edb83d747bd1e78e9b473e93a6eb441.tar.gz
ManageAccountsActivity: アクティビティを閉じる時に CurrentAccount を変更する
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java45
1 files changed, 27 insertions, 18 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java b/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java
index 4f0ae216..2063b694 100644
--- a/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java
+++ b/app/src/main/java/net/lacolaco/smileessence/activity/ManageAccountsActivity.java
@@ -49,6 +49,7 @@ import java.util.List;
public class ManageAccountsActivity extends Activity implements AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener {
private static final int REQUEST_OAUTH = 10;
private EditAccountsAdapter adapter;
+ private Account newAccount;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -56,6 +57,8 @@ public class ManageAccountsActivity extends Activity implements AdapterView.OnIt
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_edit_list);
+ newAccount = Application.getInstance().getCurrentAccount();
+
adapter = new EditAccountsAdapter();
ListView listView = (ListView) findViewById(R.id.listview_edit_list);
listView.setAdapter(adapter);
@@ -76,8 +79,8 @@ public class ManageAccountsActivity extends Activity implements AdapterView.OnIt
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Account account = adapter.getItem(i);
- if (account != Application.getInstance().getCurrentAccount()) {
- setCurrentAccount(account);
+ if (account != newAccount) {
+ newAccount = account;
adapter.notifyDataSetChanged();
}
}
@@ -90,8 +93,9 @@ public class ManageAccountsActivity extends Activity implements AdapterView.OnIt
ConfirmDialogFragment.show(this, getString(R.string.dialog_confirm_clear_account, account.getUser().getScreenName()), () -> {
adapter.removeAt(i);
Account.unregister(account.getModelId());
- if (account == Application.getInstance().getCurrentAccount()) {
- setCurrentAccount(adapter.getItem(0));
+ if (account == newAccount) {
+ newAccount = adapter.getItem(0);
+ adapter.notifyDataSetChanged();
}
}, false);
return true;
@@ -121,7 +125,11 @@ public class ManageAccountsActivity extends Activity implements AdapterView.OnIt
}
private void safeFinish() {
- if (Application.getInstance().getCurrentAccount() != null) {
+ if (newAccount != null) {
+ if (newAccount != Application.getInstance().getCurrentAccount()) {
+ Application.getInstance().setCurrentAccount(newAccount);
+ InternalPreferenceHelper.getInstance().set(R.string.key_last_used_account_id, newAccount.getModelId());
+ }
setResult(RESULT_OK);
finish();
} else {
@@ -152,21 +160,16 @@ public class ManageAccountsActivity extends Activity implements AdapterView.OnIt
data.getStringExtra(OAuthSession.KEY_TOKEN_SECRET),
data.getLongExtra(OAuthSession.KEY_USER_ID, -1L),
data.getStringExtra(OAuthSession.KEY_SCREEN_NAME));
- adapter.add(account);
- if (Application.getInstance().getCurrentAccount() == null) {
- setCurrentAccount(account);
+ if (newAccount == null) {
+ newAccount = account;
}
+ adapter.add(account);
} else {
Logger.error(requestCode);
Notificator.getInstance().alert(R.string.notice_error_authenticate);
}
}
- private void setCurrentAccount(Account account) {
- Application.getInstance().setCurrentAccount(account);
- InternalPreferenceHelper.getInstance().set(R.string.key_last_used_account_id, account.getModelId());
- }
-
private class EditAccountsAdapter extends BaseAdapter {
private final List<Account> accounts;
@@ -203,20 +206,26 @@ public class ManageAccountsActivity extends Activity implements AdapterView.OnIt
textView.setText(text);
RadioButton radioButton = (RadioButton) convertView.findViewById(R.id.account_radio_button);
- radioButton.setChecked(account == Application.getInstance().getCurrentAccount());
+ radioButton.setChecked(account == newAccount);
return convertView;
}
public int add(Account account) {
- accounts.add(account);
- notifyDataSetChanged();
- return accounts.size() - 1;
+ if (!accounts.contains(account)) {
+ accounts.add(account);
+ notifyDataSetChanged();
+ return accounts.size() - 1;
+ } else {
+ return accounts.indexOf(account);
+ }
}
public Account removeAt(int position) {
Account account = accounts.remove(position);
- notifyDataSetChanged();
+ if (account != null) {
+ notifyDataSetChanged();
+ }
return account;
}
}