Check the selected account and use it when posting

This commit is contained in:
Peter Stuifzand 2018-05-15 21:36:55 +02:00
parent 5cccd03e2f
commit 38eaf4e25f
2 changed files with 14 additions and 3 deletions

View File

@ -62,8 +62,14 @@ public class MainActivity extends AppCompatActivity {
Account[] accounts = accountManager.getAccountsByType(accountType);
if (accounts.length == 0)
return;
selectedAccount = accounts[0];
authToken = token;
for (int i = 0; i < accounts.length; i++) {
Log.i("micropub", "accounts["+i+"] = " + accounts[i].name + " " + accounts[i].type);
if (accounts[i].type.equals(accountType)&&accounts[i].name.equals(accountName)) {
selectedAccount = accounts[i];
authToken = token;
break;
}
}
String micropubBackend = accountManager.getUserData(selectedAccount, "micropub");
if (micropubBackend == null) return;
@ -202,7 +208,11 @@ public class MainActivity extends AppCompatActivity {
});
};
accountManager.getAuthTokenByFeatures("Indieauth", "token", null, this, options, null, new OnTokenAcquired(this, callback, onError), null);
if (selectedAccount == null || authToken == null) {
accountManager.getAuthTokenByFeatures("Indieauth", "token", null, this, options, null, new OnTokenAcquired(this, callback, onError), null);
} else {
callback.tokenReady(selectedAccount.type, selectedAccount.name, authToken);
}
}
public void galleryIntent(View view) {

View File

@ -99,6 +99,7 @@ public class Authenticator extends AbstractAccountAuthenticator {
JsonParser parser = new JsonParser();
JsonObject element = parser.parse(body.string()).getAsJsonObject();
authToken = element.get("access_token").getAsString();
am.setAuthToken(account, authTokenType, authToken);
}
} catch (IOException e) {
Log.e("micropub", "Failed getting token response", e);