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:
parent
bfc7f934bf
commit
642617b1ce
@ -44,6 +44,7 @@ public class AccountTypeListActivity extends AppCompatActivity {
|
|||||||
adapter = new AccountTypeListAdapter(accountType -> {
|
adapter = new AccountTypeListAdapter(accountType -> {
|
||||||
if (!(accountType.getAccountType() == Account.AccountType.LOCAL)) {
|
if (!(accountType.getAccountType() == Account.AccountType.LOCAL)) {
|
||||||
Intent intent = new Intent(getApplicationContext(), AddAccountActivity.class);
|
Intent intent = new Intent(getApplicationContext(), AddAccountActivity.class);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
|
||||||
intent.putExtra("accountType", accountType);
|
intent.putExtra("accountType", accountType);
|
||||||
|
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
@ -28,6 +28,7 @@ public class AddAccountActivity extends AppCompatActivity {
|
|||||||
private AccountViewModel viewModel;
|
private AccountViewModel viewModel;
|
||||||
|
|
||||||
private AccountType accountType;
|
private AccountType accountType;
|
||||||
|
private boolean forwardResult;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -38,6 +39,9 @@ public class AddAccountActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
accountType = getIntent().getParcelableExtra("accountType");
|
accountType = getIntent().getParcelableExtra("accountType");
|
||||||
|
|
||||||
|
int flag = getIntent().getFlags();
|
||||||
|
forwardResult = flag == Intent.FLAG_ACTIVITY_FORWARD_RESULT;
|
||||||
|
|
||||||
binding.providerImage.setImageResource(accountType.getLogoId());
|
binding.providerImage.setImageResource(accountType.getLogoId());
|
||||||
binding.providerName.setText(accountType.getName());
|
binding.providerName.setText(accountType.getName());
|
||||||
|
|
||||||
@ -80,9 +84,17 @@ public class AddAccountActivity extends AppCompatActivity {
|
|||||||
if (success) {
|
if (success) {
|
||||||
saveLoginPassword(account);
|
saveLoginPassword(account);
|
||||||
|
|
||||||
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
|
if (forwardResult) {
|
||||||
intent.putExtra(MainActivity.ACCOUNT_KEY, account);
|
Intent intent = new Intent();
|
||||||
startActivity(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();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
|
@ -178,7 +178,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
|||||||
.withName(getString(R.string.add_account))
|
.withName(getString(R.string.add_account))
|
||||||
.withIcon(R.drawable.ic_add_account_grey)
|
.withIcon(R.drawable.ic_add_account_grey)
|
||||||
.withOnDrawerItemClickListener((view, position, drawerItem) -> {
|
.withOnDrawerItemClickListener((view, position, drawerItem) -> {
|
||||||
Intent intent = new Intent(this, AddAccountActivity.class);
|
Intent intent = new Intent(this, AccountTypeListActivity.class);
|
||||||
startActivityForResult(intent, ADD_ACCOUNT_REQUEST);
|
startActivityForResult(intent, ADD_ACCOUNT_REQUEST);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -508,6 +508,17 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
|||||||
}
|
}
|
||||||
} else if (requestCode == MANAGE_FEEDS_REQUEST) {
|
} else if (requestCode == MANAGE_FEEDS_REQUEST) {
|
||||||
updateDrawerFeeds();
|
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);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user