From 38eaf4e25f0b6a3919b87e53e356e088c51f494d Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Tue, 15 May 2018 21:36:55 +0200 Subject: [PATCH] Check the selected account and use it when posting --- .../java/eu/stuifzand/micropub/MainActivity.java | 16 +++++++++++++--- .../stuifzand/micropub/auth/Authenticator.java | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/stuifzand/micropub/MainActivity.java b/app/src/main/java/eu/stuifzand/micropub/MainActivity.java index c5b2804..7e5561d 100644 --- a/app/src/main/java/eu/stuifzand/micropub/MainActivity.java +++ b/app/src/main/java/eu/stuifzand/micropub/MainActivity.java @@ -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) { diff --git a/app/src/main/java/eu/stuifzand/micropub/auth/Authenticator.java b/app/src/main/java/eu/stuifzand/micropub/auth/Authenticator.java index fc4a72b..68dd6ff 100644 --- a/app/src/main/java/eu/stuifzand/micropub/auth/Authenticator.java +++ b/app/src/main/java/eu/stuifzand/micropub/auth/Authenticator.java @@ -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);