It's now possible to add an account (other than local) from the main activity, the activity will switch to this new account

This commit is contained in:
Shinokuni 2019-05-21 14:53:16 +02:00
parent bfc7f934bf
commit 642617b1ce
3 changed files with 28 additions and 4 deletions

View File

@ -44,6 +44,7 @@ public class AccountTypeListActivity extends AppCompatActivity {
adapter = new AccountTypeListAdapter(accountType -> {
if (!(accountType.getAccountType() == Account.AccountType.LOCAL)) {
Intent intent = new Intent(getApplicationContext(), AddAccountActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
intent.putExtra("accountType", accountType);
startActivity(intent);

View File

@ -28,6 +28,7 @@ public class AddAccountActivity extends AppCompatActivity {
private AccountViewModel viewModel;
private AccountType accountType;
private boolean forwardResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -38,6 +39,9 @@ public class AddAccountActivity extends AppCompatActivity {
accountType = getIntent().getParcelableExtra("accountType");
int flag = getIntent().getFlags();
forwardResult = flag == Intent.FLAG_ACTIVITY_FORWARD_RESULT;
binding.providerImage.setImageResource(accountType.getLogoId());
binding.providerName.setText(accountType.getName());
@ -80,9 +84,17 @@ public class AddAccountActivity extends AppCompatActivity {
if (success) {
saveLoginPassword(account);
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra(MainActivity.ACCOUNT_KEY, account);
startActivity(intent);
if (forwardResult) {
Intent intent = new Intent();
intent.putExtra(MainActivity.ACCOUNT_KEY, account);
setResult(RESULT_OK, intent);
finish();
} else {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra(MainActivity.ACCOUNT_KEY, account);
startActivity(intent);
}
finish();
} else {

View File

@ -178,7 +178,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
.withName(getString(R.string.add_account))
.withIcon(R.drawable.ic_add_account_grey)
.withOnDrawerItemClickListener((view, position, drawerItem) -> {
Intent intent = new Intent(this, AddAccountActivity.class);
Intent intent = new Intent(this, AccountTypeListActivity.class);
startActivityForResult(intent, ADD_ACCOUNT_REQUEST);
return true;
@ -508,6 +508,17 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
}
} else if (requestCode == MANAGE_FEEDS_REQUEST) {
updateDrawerFeeds();
} else if (requestCode == ADD_ACCOUNT_REQUEST) {
Account newAccount = data.getParcelableExtra(ACCOUNT_KEY);
if (newAccount != null) {
account = newAccount;
viewModel.setRepository(account.getAccountType(), getApplication());
refreshLayout.setRefreshing(true);
onRefresh();
buildDrawer();
}
}
super.onActivityResult(requestCode, resultCode, data);