From 807ff6c9da3f896c9cb5992631ab25d49ab4936d Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 14 Dec 2022 12:15:41 +0100 Subject: [PATCH] Some changes --- .../android/activities/ProfileActivity.java | 8 ++++++++ .../client/entities/app/MutedAccounts.java | 10 +++++++++- .../java/app/fedilab/android/helper/Helper.java | 15 +++++++++++++++ .../fedilab/android/ui/drawer/StatusAdapter.java | 4 ++++ app/src/main/res/layout/activity_list.xml | 4 ++-- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java index 9b7954433..9eef75bf3 100644 --- a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java @@ -16,6 +16,8 @@ package app.fedilab.android.activities; import static app.fedilab.android.BaseMainActivity.currentAccount; +import static app.fedilab.android.helper.Helper.addMutedAccount; +import static app.fedilab.android.helper.Helper.removeMutedAccount; import static app.fedilab.android.ui.drawer.StatusAdapter.sendAction; import android.content.BroadcastReceiver; @@ -1011,12 +1013,18 @@ public class ProfileActivity extends BaseActivity { builderInner.setPositiveButton(R.string.action_unmute, (dialog, which) -> accountsVM.unmuteHome(currentAccount, account) .observe(ProfileActivity.this, account -> { homeMuted = false; + if (account != null) { + removeMutedAccount(account); + } Toasty.info(ProfileActivity.this, getString(R.string.toast_unmute), Toasty.LENGTH_LONG).show(); })); } else { builderInner.setTitle(R.string.mute_home); builderInner.setPositiveButton(R.string.action_mute, (dialog, which) -> accountsVM.muteHome(currentAccount, account) .observe(ProfileActivity.this, account -> { + if (account != null) { + addMutedAccount(account); + } homeMuted = true; sendAction(ProfileActivity.this, Helper.ARG_STATUS_ACCOUNT_ID_DELETED, null, account.id); Toasty.info(ProfileActivity.this, getString(R.string.toast_mute), Toasty.LENGTH_LONG).show(); diff --git a/app/src/main/java/app/fedilab/android/client/entities/app/MutedAccounts.java b/app/src/main/java/app/fedilab/android/client/entities/app/MutedAccounts.java index 355fece99..d36d310ea 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/app/MutedAccounts.java +++ b/app/src/main/java/app/fedilab/android/client/entities/app/MutedAccounts.java @@ -213,9 +213,10 @@ public class MutedAccounts implements Serializable { throw new DBException("db is null. Wrong initialization."); } try { - Cursor c = db.query(Sqlite.TABLE_MUTED, null, Sqlite.COL_INSTANCE + " = '" + account.instance + "' AND " + Sqlite.COL_USER_ID + " = '" + account.user_id + "'", null, null, null, null, null); + Cursor c = db.query(Sqlite.TABLE_MUTED, null, Sqlite.COL_INSTANCE + " = '" + account.instance + "' AND " + Sqlite.COL_USER_ID + " = '" + account.user_id + "'", null, null, null, null, "1"); return convertCursorToMuted(c); } catch (Exception e) { + e.printStackTrace(); return null; } } @@ -227,12 +228,19 @@ public class MutedAccounts implements Serializable { * @return MutedAccounts */ private MutedAccounts convertCursorToMuted(Cursor c) { + if (c.getCount() == 0) { + c.close(); + return null; + } + //Take the first element + c.moveToFirst(); MutedAccounts mutedAccounts = new MutedAccounts(); mutedAccounts.id = c.getInt(c.getColumnIndexOrThrow(Sqlite.COL_ID)); mutedAccounts.instance = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_INSTANCE)); mutedAccounts.user_id = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_USER_ID)); mutedAccounts.accounts = restoreAccountsFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_MUTED_ACCOUNTS))); mutedAccounts.type = Timeline.TimeLineEnum.valueOf(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_TYPE))); + c.close(); return mutedAccounts; } } diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index 2b1aa30ab..e1d55937b 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -1953,4 +1953,19 @@ public class Helper { public interface OnAttachmentCopied { void onAttachmentCopied(Attachment attachment); } + + public static void addMutedAccount(app.fedilab.android.client.entities.api.Account target) { + if (MainActivity.filteredAccounts == null) { + MainActivity.filteredAccounts = new ArrayList<>(); + } + if (!MainActivity.filteredAccounts.contains(target)) { + MainActivity.filteredAccounts.add(target); + } + } + + public static void removeMutedAccount(app.fedilab.android.client.entities.api.Account target) { + if (MainActivity.filteredAccounts != null) { + MainActivity.filteredAccounts.remove(target); + } + } } 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 5861c8b12..2beece920 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 @@ -28,6 +28,7 @@ import static app.fedilab.android.helper.Helper.ARG_TIMELINE_REFRESH_ALL; import static app.fedilab.android.helper.Helper.PREF_USER_ID; import static app.fedilab.android.helper.Helper.PREF_USER_INSTANCE; import static app.fedilab.android.helper.Helper.PREF_USER_TOKEN; +import static app.fedilab.android.helper.Helper.addMutedAccount; import android.annotation.SuppressLint; import android.app.Activity; @@ -1662,6 +1663,9 @@ public class StatusAdapter extends RecyclerView.Adapter builderInner.setNeutralButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); builderInner.setPositiveButton(R.string.action_mute, (dialog, which) -> accountsVM.muteHome(currentAccount, statusToDeal.account) .observe((LifecycleOwner) context, account -> { + if (account != null) { + addMutedAccount(account); + } sendAction(context, Helper.ARG_STATUS_ACCOUNT_ID_DELETED, null, statusToDeal.account.id); Toasty.info(context, context.getString(R.string.toast_mute), Toasty.LENGTH_LONG).show(); })); diff --git a/app/src/main/res/layout/activity_list.xml b/app/src/main/res/layout/activity_list.xml index e55a04b5d..ad0744987 100644 --- a/app/src/main/res/layout/activity_list.xml +++ b/app/src/main/res/layout/activity_list.xml @@ -2,8 +2,8 @@ + android:layout_marginHorizontal="6dp" + android:orientation="vertical">