Some changes

maths
Thomas 2 years ago
parent 7a93b22f77
commit 807ff6c9da

@ -16,6 +16,8 @@ package app.fedilab.android.activities;
import static app.fedilab.android.BaseMainActivity.currentAccount; 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 static app.fedilab.android.ui.drawer.StatusAdapter.sendAction;
import android.content.BroadcastReceiver; 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) builderInner.setPositiveButton(R.string.action_unmute, (dialog, which) -> accountsVM.unmuteHome(currentAccount, account)
.observe(ProfileActivity.this, account -> { .observe(ProfileActivity.this, account -> {
homeMuted = false; homeMuted = false;
if (account != null) {
removeMutedAccount(account);
}
Toasty.info(ProfileActivity.this, getString(R.string.toast_unmute), Toasty.LENGTH_LONG).show(); Toasty.info(ProfileActivity.this, getString(R.string.toast_unmute), Toasty.LENGTH_LONG).show();
})); }));
} else { } else {
builderInner.setTitle(R.string.mute_home); builderInner.setTitle(R.string.mute_home);
builderInner.setPositiveButton(R.string.action_mute, (dialog, which) -> accountsVM.muteHome(currentAccount, account) builderInner.setPositiveButton(R.string.action_mute, (dialog, which) -> accountsVM.muteHome(currentAccount, account)
.observe(ProfileActivity.this, account -> { .observe(ProfileActivity.this, account -> {
if (account != null) {
addMutedAccount(account);
}
homeMuted = true; homeMuted = true;
sendAction(ProfileActivity.this, Helper.ARG_STATUS_ACCOUNT_ID_DELETED, null, account.id); 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(); Toasty.info(ProfileActivity.this, getString(R.string.toast_mute), Toasty.LENGTH_LONG).show();

@ -213,9 +213,10 @@ public class MutedAccounts implements Serializable {
throw new DBException("db is null. Wrong initialization."); throw new DBException("db is null. Wrong initialization.");
} }
try { 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); return convertCursorToMuted(c);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
return null; return null;
} }
} }
@ -227,12 +228,19 @@ public class MutedAccounts implements Serializable {
* @return MutedAccounts * @return MutedAccounts
*/ */
private MutedAccounts convertCursorToMuted(Cursor c) { private MutedAccounts convertCursorToMuted(Cursor c) {
if (c.getCount() == 0) {
c.close();
return null;
}
//Take the first element
c.moveToFirst();
MutedAccounts mutedAccounts = new MutedAccounts(); MutedAccounts mutedAccounts = new MutedAccounts();
mutedAccounts.id = c.getInt(c.getColumnIndexOrThrow(Sqlite.COL_ID)); mutedAccounts.id = c.getInt(c.getColumnIndexOrThrow(Sqlite.COL_ID));
mutedAccounts.instance = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_INSTANCE)); mutedAccounts.instance = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_INSTANCE));
mutedAccounts.user_id = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_USER_ID)); mutedAccounts.user_id = c.getString(c.getColumnIndexOrThrow(Sqlite.COL_USER_ID));
mutedAccounts.accounts = restoreAccountsFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_MUTED_ACCOUNTS))); mutedAccounts.accounts = restoreAccountsFromString(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_MUTED_ACCOUNTS)));
mutedAccounts.type = Timeline.TimeLineEnum.valueOf(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_TYPE))); mutedAccounts.type = Timeline.TimeLineEnum.valueOf(c.getString(c.getColumnIndexOrThrow(Sqlite.COL_TYPE)));
c.close();
return mutedAccounts; return mutedAccounts;
} }
} }

@ -1953,4 +1953,19 @@ public class Helper {
public interface OnAttachmentCopied { public interface OnAttachmentCopied {
void onAttachmentCopied(Attachment attachment); 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);
}
}
} }

@ -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_ID;
import static app.fedilab.android.helper.Helper.PREF_USER_INSTANCE; 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.PREF_USER_TOKEN;
import static app.fedilab.android.helper.Helper.addMutedAccount;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; 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.setNeutralButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builderInner.setPositiveButton(R.string.action_mute, (dialog, which) -> accountsVM.muteHome(currentAccount, statusToDeal.account) builderInner.setPositiveButton(R.string.action_mute, (dialog, which) -> accountsVM.muteHome(currentAccount, statusToDeal.account)
.observe((LifecycleOwner) context, account -> { .observe((LifecycleOwner) context, account -> {
if (account != null) {
addMutedAccount(account);
}
sendAction(context, Helper.ARG_STATUS_ACCOUNT_ID_DELETED, null, statusToDeal.account.id); 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(); Toasty.info(context, context.getString(R.string.toast_mute), Toasty.LENGTH_LONG).show();
})); }));

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

Loading…
Cancel
Save