From f213b0ddcbdc6504de2da0ab041181e81b2e947d Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 12 Nov 2022 17:30:06 +0100 Subject: [PATCH] Display reports --- .../activities/AccountReportActivity.java | 1 - .../android/activities/LoginActivity.java | 49 ++++++++++--------- .../android/ui/drawer/StatusAdapter.java | 2 +- app/src/main/res/layout/drawer_report.xml | 1 - 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/AccountReportActivity.java b/app/src/main/java/app/fedilab/android/activities/AccountReportActivity.java index 018f9105..cb686ec2 100644 --- a/app/src/main/java/app/fedilab/android/activities/AccountReportActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/AccountReportActivity.java @@ -330,7 +330,6 @@ public class AccountReportActivity extends BaseActivity { } } - @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { diff --git a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java index 21731560..8d0fc38a 100644 --- a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java @@ -67,29 +67,34 @@ public class LoginActivity extends BaseActivity { String scope = requestedAdmin ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES; oauthVM.createToken(currentInstanceLogin, "authorization_code", client_idLogin, client_secretLogin, Helper.REDIRECT_CONTENT_WEB, scope, code) .observe(LoginActivity.this, tokenObj -> { - Account account = new Account(); - account.client_id = client_idLogin; - account.client_secret = client_secretLogin; - account.token = tokenObj.token_type + " " + tokenObj.access_token; - account.api = apiLogin; - account.software = softwareLogin; - account.instance = currentInstanceLogin; - //API call to retrieve account information for the new token - AccountsVM accountsVM = new ViewModelProvider(LoginActivity.this).get(AccountsVM.class); - accountsVM.getConnectedAccount(currentInstanceLogin, account.token).observe(LoginActivity.this, mastodonAccount -> { - account.mastodon_account = mastodonAccount; - account.user_id = mastodonAccount.id; - //We check if user have really moderator rights - if (requestedAdmin) { - AdminVM adminVM = new ViewModelProvider(LoginActivity.this).get(AdminVM.class); - adminVM.getAccount(account.instance, account.token, account.user_id).observe(LoginActivity.this, adminAccount -> { - account.admin = adminAccount != null; + if (tokenObj != null) { + Account account = new Account(); + account.client_id = client_idLogin; + account.client_secret = client_secretLogin; + account.token = tokenObj.token_type + " " + tokenObj.access_token; + account.api = apiLogin; + account.software = softwareLogin; + account.instance = currentInstanceLogin; + //API call to retrieve account information for the new token + AccountsVM accountsVM = new ViewModelProvider(LoginActivity.this).get(AccountsVM.class); + accountsVM.getConnectedAccount(currentInstanceLogin, account.token).observe(LoginActivity.this, mastodonAccount -> { + account.mastodon_account = mastodonAccount; + account.user_id = mastodonAccount.id; + //We check if user have really moderator rights + if (requestedAdmin) { + AdminVM adminVM = new ViewModelProvider(LoginActivity.this).get(AdminVM.class); + adminVM.getAccount(account.instance, account.token, account.user_id).observe(LoginActivity.this, adminAccount -> { + account.admin = adminAccount != null; + WebviewConnectActivity.proceedLogin(LoginActivity.this, account); + }); + } else { WebviewConnectActivity.proceedLogin(LoginActivity.this, account); - }); - } else { - WebviewConnectActivity.proceedLogin(LoginActivity.this, account); - } - }); + } + }); + } else { + Toasty.error(LoginActivity.this, getString(R.string.toast_token), Toast.LENGTH_LONG).show(); + } + }); } } diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index b5e4e9d4..d5feb55d 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -1786,7 +1786,7 @@ public class StatusAdapter extends RecyclerView.Adapter MastodonHelper.scheduleBoost(context, MastodonHelper.ScheduleType.BOOST, statusToDeal, null, null); } else if (itemId == R.id.action_admin) { Intent intent = new Intent(context, AccountReportActivity.class); - intent.putExtra(Helper.ARG_ACCOUNT, statusToDeal.account); + intent.putExtra(Helper.ARG_ACCOUNT_ID, statusToDeal.account.id); context.startActivity(intent); } else if (itemId == R.id.action_open_browser) { Helper.openBrowser(context, statusToDeal.url); diff --git a/app/src/main/res/layout/drawer_report.xml b/app/src/main/res/layout/drawer_report.xml index 3419ac3d..2f70482d 100644 --- a/app/src/main/res/layout/drawer_report.xml +++ b/app/src/main/res/layout/drawer_report.xml @@ -27,7 +27,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> -