feat: show blocked domains

This commit is contained in:
FineFindus 2023-05-22 21:37:56 +02:00
parent c43f734101
commit 56835b4f2d
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
8 changed files with 298 additions and 2 deletions

View File

@ -0,0 +1,16 @@
package org.joinmastodon.android.api.requests.instance;
import com.google.gson.reflect.TypeToken;
import org.joinmastodon.android.api.MastodonAPIRequest;
import org.joinmastodon.android.model.DomainBlock;
import org.joinmastodon.android.model.ExtendedDescription;
import java.util.List;
public class GetDomainBlocks extends MastodonAPIRequest<List<DomainBlock>>{
public GetDomainBlocks(){
super(HttpMethod.GET, "/instance/domain_blocks", new TypeToken<>(){});
}
}

View File

@ -0,0 +1,185 @@
package org.joinmastodon.android.fragments;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.instance.GetDomainBlocks;
import org.joinmastodon.android.fragments.onboarding.GoogleMadeMeAddThisFragment;
import org.joinmastodon.android.model.DomainBlock;
import org.joinmastodon.android.model.Instance;
import org.joinmastodon.android.model.Severity;
import org.joinmastodon.android.ui.DividerItemDecoration;
import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.joinmastodon.android.utils.ElevationOnScrollListener;
import org.parceler.Parcels;
import java.util.List;
import me.grishka.appkit.Nav;
import me.grishka.appkit.api.SimpleCallback;
import me.grishka.appkit.fragments.LoaderFragment;
import me.grishka.appkit.fragments.ToolbarFragment;
import me.grishka.appkit.utils.BindableViewHolder;
import me.grishka.appkit.utils.MergeRecyclerAdapter;
import me.grishka.appkit.utils.SingleViewRecyclerAdapter;
import me.grishka.appkit.utils.V;
import me.grishka.appkit.views.FragmentRootLinearLayout;
import me.grishka.appkit.views.UsableRecyclerView;
public class InstanceBlockListFragment extends LoaderFragment {
private UsableRecyclerView list;
private MergeRecyclerAdapter adapter;
private View buttonBar;
private Instance instance;
private ElevationOnScrollListener onScrollListener;
private List<DomainBlock> domainBlocks;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setRetainInstance(true);
loadData();
}
@Override
public void onAttach(Activity activity){
super.onAttach(activity);
setNavigationBarColor(UiUtils.getThemeColor(activity, R.attr.colorWindowBackground));
instance=Parcels.unwrap(getArguments().getParcelable("instance"));
setTitle(R.string.mo_instance_info_moderated_servers);
}
@Override
public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View view=inflater.inflate(R.layout.fragment_onboarding_rules, container, false);
list=view.findViewById(R.id.list);
list.setLayoutManager(new LinearLayoutManager(getActivity()));
adapter=new MergeRecyclerAdapter();
adapter.addAdapter(new ItemsAdapter());
list.setAdapter(adapter);
list.addItemDecoration(new DividerItemDecoration(getActivity(), R.attr.colorM3SurfaceVariant, 1, 0, 0, DividerItemDecoration.NOT_FIRST));
buttonBar=view.findViewById(R.id.button_bar);
view.findViewById(R.id.btn_back).setOnClickListener(v->Nav.finish(this));
return view;
}
@Override
protected void doLoadData() {
currentRequest= new GetDomainBlocks().setCallback(new SimpleCallback<>(this) {
@Override
public void onSuccess(List<DomainBlock> result) {
domainBlocks=result;
dataLoaded();
}
}).execNoAuth(instance.uri);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
super.onViewCreated(view, savedInstanceState);
setStatusBarColor(UiUtils.getThemeColor(getActivity(), R.attr.colorM3Background));
view.setBackgroundColor(UiUtils.getThemeColor(getActivity(), R.attr.colorM3Background));
list.addOnScrollListener(onScrollListener=new ElevationOnScrollListener((FragmentRootLinearLayout) view, buttonBar, getToolbar()));
}
@Override
protected void onUpdateToolbar(){
super.onUpdateToolbar();
getToolbar().setBackgroundResource(R.drawable.bg_onboarding_panel);
getToolbar().setElevation(0);
if(onScrollListener!=null){
onScrollListener.setViews(buttonBar, getToolbar());
}
}
@Override
public void onApplyWindowInsets(WindowInsets insets){
if(Build.VERSION.SDK_INT>=27){
int inset=insets.getSystemWindowInsetBottom();
buttonBar.setPadding(0, 0, 0, inset>0 ? Math.max(inset, V.dp(36)) : 0);
super.onApplyWindowInsets(insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), 0));
}else{
super.onApplyWindowInsets(insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()));
}
}
@Override
public void onRefresh(){
doLoadData();
}
private class ItemsAdapter extends RecyclerView.Adapter<ItemViewHolder>{
@NonNull
@Override
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
return new ItemViewHolder();
}
@Override
public void onBindViewHolder(@NonNull ItemViewHolder holder, int position){
holder.bind(domainBlocks.get(position));
}
@Override
public int getItemCount(){
return domainBlocks.size();
}
}
private class ItemViewHolder extends BindableViewHolder<DomainBlock>{
private final TextView instanceUri, reason;
private final ImageView severity;
public ItemViewHolder(){
super(getActivity(), R.layout.item_server_block, list);
instanceUri=findViewById(R.id.instance);
reason=findViewById(R.id.reason);
severity=findViewById(R.id.severity);
}
@SuppressLint("DefaultLocale")
@Override
public void onBind(DomainBlock item){
instanceUri.setText(item.domain);
reason.setText(item.comment);
switch (item.severity) {
case SILENCE -> {
severity.setImageDrawable(getContext().getDrawable(R.drawable.ic_fluent_speaker_mute_28_regular));
severity.setContentDescription(getContext().getString(R.string.mo_severity_silence));
}
case SUSPEND -> {
severity.setImageDrawable(getContext().getDrawable(R.drawable.ic_fluent_shield_prohibited_28_regular));
severity.setContentDescription(getContext().getString(R.string.mo_severity_suspend));
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
severity.setTooltipText(severity.getContentDescription());
}
}
}
}

View File

@ -178,7 +178,6 @@ public class InstanceInfoFragment extends LoaderFragment {
instance = result; instance = result;
bindHeaderView(); bindHeaderView();
dataLoaded(); dataLoaded();
} }
}) })
.execNoAuth(targetDomain); .execNoAuth(targetDomain);
@ -349,7 +348,9 @@ public class InstanceInfoFragment extends LoaderFragment {
args.putParcelable("instance", Parcels.wrap(instance)); args.putParcelable("instance", Parcels.wrap(instance));
Nav.go(getActivity(), InstanceRulesFragment.class, args); Nav.go(getActivity(), InstanceRulesFragment.class, args);
} else if (id==R.id.moderated_servers) { } else if (id==R.id.moderated_servers) {
Bundle args=new Bundle();
args.putParcelable("instance", Parcels.wrap(instance));
Nav.go(getActivity(), InstanceBlockListFragment.class, args);
} }
return true; return true;
} }

View File

@ -0,0 +1,27 @@
package org.joinmastodon.android.model;
import org.joinmastodon.android.api.RequiredField;
import org.parceler.Parcel;
@Parcel
public class DomainBlock extends BaseModel {
@RequiredField
public String domain;
@RequiredField
public String digest;
@RequiredField
public Severity severity;
public String comment;
@Override
public String toString() {
return "DomainBlock{" +
"domain='" + domain + '\'' +
", digest='" + digest + '\'' +
", severity='" + severity + '\'' +
", comment='" + comment + '\'' +
'}';
}
}

View File

@ -0,0 +1,12 @@
package org.joinmastodon.android.model;
import com.google.gson.annotations.SerializedName;
import org.parceler.Parcel;
public enum Severity {
@SerializedName("silence")
SILENCE,
@SerializedName("suspend")
SUSPEND
}

View File

@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="28dp" android:height="28dp" android:viewportWidth="24" android:viewportHeight="24">
<path android:pathData="M3.75 5C3.336 5 3 5.336 3 5.75V11c0 5.001 2.958 8.676 8.725 10.948 0.177 0.07 0.373 0.07 0.55 0 0.144-0.057 0.286-0.114 0.426-0.173-0.659-0.475-1.225-1.071-1.667-1.756C6.64 17.962 4.5 14.975 4.5 11V6.478c2.577-0.152 5.08-1.09 7.5-2.8 2.42 1.71 4.923 2.648 7.5 2.8v4.254c0.54 0.282 1.037 0.638 1.475 1.054C20.992 11.528 21 11.266 21 11V5.75C21 5.336 20.664 5 20.25 5c-2.663 0-5.258-0.944-7.8-2.85-0.267-0.2-0.633-0.2-0.9 0C9.008 4.056 6.413 5 3.75 5zM16.5 22c3.038 0 5.5-2.462 5.5-5.5S19.538 11 16.5 11 11 13.462 11 16.5s2.462 5.5 5.5 5.5zm-3.309-3.252c-0.436-0.64-0.691-1.415-0.691-2.248 0-2.21 1.79-4 4-4 0.834 0 1.608 0.255 2.248 0.691l-5.557 5.557zm1.06 1.06l5.558-5.556c0.436 0.64 0.691 1.414 0.691 2.248 0 2.21-1.79 4-4 4-0.834 0-1.607-0.255-2.248-0.691z" android:fillColor="@color/fluent_default_icon_tint"/>
</vector>

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingEnd="24dp"
android:paddingBottom="12dp"
android:paddingStart="12dp"
android:baselineAligned="false">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="@+id/instance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="?android:attr/textColorPrimary"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView android:id="@+id/reason"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/instance"
android:layout_alignStart="@id/instance"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="4" />
</RelativeLayout>
<ImageView
android:id="@+id/severity"
android:src="@drawable/ic_fluent_speaker_mute_28_regular"
android:contentDescription="@string/mo_severity_silence"
android:minHeight="32dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

View File

@ -60,4 +60,6 @@
<string name="mo_instance_info_open_timeline">Local timeline</string> <string name="mo_instance_info_open_timeline">Local timeline</string>
<string name="mo_instance_info_moderated_servers">Moderated servers</string> <string name="mo_instance_info_moderated_servers">Moderated servers</string>
<string name="mo_severity_silence">Silenced</string>
<string name="mo_severity_suspend">Blocked</string>
</resources> </resources>