Commit d8de0164 authored by Thomas's avatar Thomas
Browse files

Allow to mute/unmute from the list with a new icon

parent 807ff6c9
Loading
Loading
Loading
Loading
+3 −9
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@ 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;
@@ -191,7 +189,7 @@ public class ProfileActivity extends BaseActivity {
            finish();
        }
        //Check if account is homeMuted
        accountsVM.isMuted(currentAccount, account).observe(ProfileActivity.this, account1 -> homeMuted = account1 != null);
        accountsVM.isMuted(currentAccount, account).observe(this, result -> homeMuted = result != null && result);
        LocalBroadcastManager.getInstance(ProfileActivity.this).registerReceiver(broadcast_data, new IntentFilter(Helper.BROADCAST_DATA));
    }

@@ -1013,19 +1011,15 @@ 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);
                            }
                            invalidateOptionsMenu();
                            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;
                            invalidateOptionsMenu();
                            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();
                        }));
+12 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ import android.content.Context;
import android.text.Spannable;
import android.view.View;

import androidx.annotation.Nullable;

import com.google.gson.annotations.SerializedName;

import java.io.Serializable;
@@ -148,4 +150,14 @@ public class Account implements Serializable {
        public LinkedHashMap<Integer, Field.FieldParams> fields;

    }


    @Override
    public boolean equals(@Nullable Object obj) {
        boolean same = false;
        if (obj instanceof Account) {
            same = this.id.equals(((Account) obj).id);
        }
        return same;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -88,6 +88,9 @@ public class MutedAccounts implements Serializable {
        }
    }

    public void delete() {
        db.delete(Sqlite.TABLE_MUTED, null, null);
    }

    /**
     * Insert an Account in muted account in db
+25 −2
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import java.util.List;

import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.activities.ProfileActivity;
import app.fedilab.android.client.entities.api.Account;
import app.fedilab.android.databinding.DrawerAccountBinding;
@@ -56,12 +57,19 @@ public class AccountAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder

    private final List<Account> accountList;
    private Context context;
    private final boolean home_mute;

    public AccountAdapter(List<Account> accountList, boolean home_mute) {
        this.accountList = accountList;
        this.home_mute = home_mute;
    }

    public AccountAdapter(List<Account> accountList) {
        this.accountList = accountList;
        this.home_mute = false;
    }

    public static void accountManagement(Context context, AccountViewHolder accountViewHolder, Account account, int position, RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {
    public static void accountManagement(Context context, AccountViewHolder accountViewHolder, Account account, int position, RecyclerView.Adapter<RecyclerView.ViewHolder> adapter, boolean home_mute) {
        MastodonHelper.loadPPMastodon(accountViewHolder.binding.avatar, account);

        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
@@ -73,6 +81,21 @@ public class AccountAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
            accountViewHolder.binding.dividerCard.setVisibility(View.GONE);
        }

        if (home_mute) {
            accountViewHolder.binding.muteHome.setVisibility(View.VISIBLE);
            boolean muted = MainActivity.filteredAccounts != null && MainActivity.filteredAccounts.contains(account);
            accountViewHolder.binding.muteHome.setChecked(muted);
            accountViewHolder.binding.muteHome.setOnClickListener(v -> {
                if (muted) {
                    accountsVM.unmuteHome(MainActivity.currentAccount, account).observe((LifecycleOwner) context, account1 -> adapter.notifyItemChanged(accountViewHolder.getLayoutPosition()));
                } else {
                    accountsVM.muteHome(MainActivity.currentAccount, account).observe((LifecycleOwner) context, account1 -> adapter.notifyItemChanged(accountViewHolder.getLayoutPosition()));
                }
            });
        } else {
            accountViewHolder.binding.muteHome.setVisibility(View.GONE);
        }

        accountViewHolder.binding.avatar.setOnClickListener(v -> {
            Intent intent = new Intent(context, ProfileActivity.class);
            Bundle b = new Bundle();
@@ -263,7 +286,7 @@ public class AccountAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
        Account account = accountList.get(position);
        AccountViewHolder holder = (AccountViewHolder) viewHolder;
        accountManagement(context, holder, account, position, this);
        accountManagement(context, holder, account, position, this, home_mute);

    }

+0 −4
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ 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;
@@ -1663,9 +1662,6 @@ 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();
                            }));
Loading