Commit 5f1cd065 authored by Thomas's avatar Thomas
Browse files

Fix issue #513 - Add the ability to check blocked domains and to unblock them.

parent 2d80e899
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import app.fedilab.android.databinding.ActivityActionsBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonAccount;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonDomainBlock;
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline;

public class ActionActivity extends BaseActivity {
@@ -37,6 +38,7 @@ public class ActionActivity extends BaseActivity {
    private boolean canGoBack;
    private FragmentMastodonTimeline fragmentMastodonTimeline;
    private FragmentMastodonAccount fragmentMastodonAccount;
    private FragmentMastodonDomainBlock fragmentMastodonDomainBlock;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -54,6 +56,7 @@ public class ActionActivity extends BaseActivity {
        binding.bookmarks.setOnClickListener(v -> displayTimeline(Timeline.TimeLineEnum.BOOKMARK_TIMELINE));
        binding.muted.setOnClickListener(v -> displayTimeline(Timeline.TimeLineEnum.MUTED_TIMELINE));
        binding.blocked.setOnClickListener(v -> displayTimeline(Timeline.TimeLineEnum.BLOCKED_TIMELINE));
        binding.domainBlock.setOnClickListener(v -> displayTimeline(Timeline.TimeLineEnum.BLOCKED_DOMAIN_TIMELINE));
    }

    private void displayTimeline(Timeline.TimeLineEnum type) {
@@ -73,6 +76,15 @@ public class ActionActivity extends BaseActivity {
                fragmentTransaction.commit();
            });

        } else if (type == Timeline.TimeLineEnum.BLOCKED_DOMAIN_TIMELINE) {
            ThemeHelper.slideViewsToLeft(binding.buttonContainer, binding.fragmentContainer, () -> {
                fragmentMastodonDomainBlock = new FragmentMastodonDomainBlock();
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction =
                        fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.fragment_container, fragmentMastodonDomainBlock);
                fragmentTransaction.commit();
            });
        } else {

            ThemeHelper.slideViewsToLeft(binding.buttonContainer, binding.fragmentContainer, () -> {
@@ -102,6 +114,9 @@ public class ActionActivity extends BaseActivity {
            case BOOKMARK_TIMELINE:
                setTitle(R.string.bookmarks);
                break;
            case BLOCKED_DOMAIN_TIMELINE:
                setTitle(R.string.blocked_domains);
                break;
        }
    }

@@ -116,6 +131,9 @@ public class ActionActivity extends BaseActivity {
                if (fragmentMastodonAccount != null) {
                    fragmentMastodonAccount.onDestroyView();
                }
                if (fragmentMastodonDomainBlock != null) {
                    fragmentMastodonDomainBlock.onDestroyView();
                }
            });
            setTitle(R.string.interactions);
        } else {
+1 −1
Original line number Diff line number Diff line
@@ -316,7 +316,7 @@ public interface MastodonAccountsService {
    @DELETE("domain_blocks")
    Call<Void> removeDomainBlocks(
            @Header("Authorization") String token,
            @Field("domain") String domain
            @Query("domain") String domain
    );


+22 −0
Original line number Diff line number Diff line
package app.fedilab.android.client.entities.api;
/* Copyright 2022 Thomas Schneider
 *
 * This file is a part of Fedilab
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with Fedilab; if not,
 * see <http://www.gnu.org/licenses>. */

import java.util.List;

public class Domains {
    public Pagination pagination = new Pagination();
    public List<String> domains;
}
+2 −0
Original line number Diff line number Diff line
@@ -390,6 +390,8 @@ public class Timeline {
        MUTED_TIMELINE("MUTED_TIMELINE"),
        @SerializedName("BOOKMARK_TIMELINE")
        BOOKMARK_TIMELINE("BOOKMARK_TIMELINE"),
        @SerializedName("BLOCKED_DOMAIN_TIMELINE")
        BLOCKED_DOMAIN_TIMELINE("BLOCKED_DOMAIN_TIMELINE"),
        @SerializedName("BLOCKED_TIMELINE")
        BLOCKED_TIMELINE("BLOCKED_TIMELINE"),
        @SerializedName("FAVOURITE_TIMELINE")
+95 −0
Original line number Diff line number Diff line
package app.fedilab.android.ui.drawer;
/* Copyright 2022 Thomas Schneider
 *
 * This file is a part of Fedilab
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with Fedilab; if not,
 * see <http://www.gnu.org/licenses>. */

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.databinding.DrawerDomainBlockBinding;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.viewmodel.mastodon.AccountsVM;


public class DomainBlockAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private final List<String> domainList;
    private Context context;

    public DomainBlockAdapter(List<String> domainList) {
        this.domainList = domainList;
    }

    public int getCount() {
        return domainList.size();
    }

    public String getItem(int position) {
        return domainList.get(position);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        context = parent.getContext();
        DrawerDomainBlockBinding itemBinding = DrawerDomainBlockBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new DomainBlockViewHolder(itemBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
        String domain = domainList.get(position);
        DomainBlockViewHolder holder = (DomainBlockViewHolder) viewHolder;
        holder.binding.domainName.setText(domain);
        AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class);
        holder.binding.unblockDomain.setOnClickListener(v -> {
            AlertDialog.Builder alt_bld = new AlertDialog.Builder(context, Helper.dialogStyle());
            alt_bld.setMessage(context.getString(R.string.unblock_domain_confirm, domain));
            alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> {
                accountsVM.removeDomainBlocks(MainActivity.currentInstance, MainActivity.currentToken, domain);
                domainList.remove(position);
                notifyItemRemoved(position);
                dialog.dismiss();
            });
            alt_bld.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
            AlertDialog alert = alt_bld.create();
            alert.show();
        });
    }

    @Override
    public int getItemCount() {
        return domainList.size();
    }


    public static class DomainBlockViewHolder extends RecyclerView.ViewHolder {
        DrawerDomainBlockBinding binding;

        DomainBlockViewHolder(DrawerDomainBlockBinding itemView) {
            super(itemView.getRoot());
            binding = itemView;
        }
    }
}
Loading