Some changes

This commit is contained in:
Thomas 2022-12-14 12:15:41 +01:00
parent 7a93b22f77
commit 807ff6c9da
5 changed files with 38 additions and 3 deletions

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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);
}
}
}

View File

@ -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<RecyclerView.ViewHolder>
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();
}));

View File

@ -2,8 +2,8 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/fab_margin">
android:layout_marginHorizontal="6dp"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"