Loading app/src/main/java/app/fedilab/android/activities/FilterActivity.java +16 −3 Original line number Diff line number Diff line Loading @@ -126,9 +126,22 @@ public class FilterActivity extends BaseActivity implements FilterAdapter.Delete } } popupAddFilterBinding.contextWholeWord.setChecked(filter.whole_word); popupAddFilterBinding.contextDrop.setChecked(filter.irreversible); if (filter.irreversible) { popupAddFilterBinding.actionRemove.setChecked(true); popupAddFilterBinding.actionHide.setChecked(false); } else { popupAddFilterBinding.actionRemove.setChecked(false); popupAddFilterBinding.actionHide.setChecked(true); } } popupAddFilterBinding.actionRemove.setOnClickListener(v -> { popupAddFilterBinding.actionHide.setChecked(false); popupAddFilterBinding.actionRemove.setChecked(true); }); popupAddFilterBinding.actionHide.setOnClickListener(v -> { popupAddFilterBinding.actionRemove.setChecked(false); popupAddFilterBinding.actionHide.setChecked(true); }); AlertDialog alertDialog = dialogBuilder.setPositiveButton(R.string.validate, null) .setNegativeButton(R.string.cancel, null).create(); Loading Loading @@ -161,7 +174,7 @@ public class FilterActivity extends BaseActivity implements FilterAdapter.Delete filterSent.expires_at_sent = expire[0]; filterSent.phrase = popupAddFilterBinding.addPhrase.getText().toString(); filterSent.whole_word = popupAddFilterBinding.contextWholeWord.isChecked(); filterSent.irreversible = popupAddFilterBinding.contextDrop.isChecked(); filterSent.irreversible = popupAddFilterBinding.actionRemove.isChecked(); if (filter != null) { accountsVM.editFilter(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, filter.id, filterSent.phrase, filterSent.context, filterSent.irreversible, filterSent.whole_word, filterSent.expires_at_sent) .observe((LifecycleOwner) context, listener::callback); Loading app/src/main/java/app/fedilab/android/client/endpoints/MastodonAccountsService.java +0 −44 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ import java.util.List; import app.fedilab.android.client.entities.api.Account; import app.fedilab.android.client.entities.api.FeaturedTag; import app.fedilab.android.client.entities.api.Filter; import app.fedilab.android.client.entities.api.IdentityProof; import app.fedilab.android.client.entities.api.MastodonList; import app.fedilab.android.client.entities.api.Preferences; Loading @@ -40,7 +39,6 @@ import retrofit2.http.Headers; import retrofit2.http.Multipart; import retrofit2.http.PATCH; import retrofit2.http.POST; import retrofit2.http.PUT; import retrofit2.http.Part; import retrofit2.http.Path; import retrofit2.http.Query; Loading Loading @@ -320,48 +318,6 @@ public interface MastodonAccountsService { @Field("domain") String domain ); //Get filters @GET("filters") Call<List<Filter>> getFilters( @Header("Authorization") String token); //Get a filter with its id @GET("filters/{id}") Call<Filter> getFilter( @Header("Authorization") String token, @Path("id") String id); //Add a filter @FormUrlEncoded @POST("filters") Call<Filter> addFilter( @Header("Authorization") String token, @Field("phrase") String phrase, @Field("context[]") List<String> context, @Field("irreversible") boolean irreversible, @Field("whole_word") boolean whole_word, @Field("expires_in") String expires_in ); //Edit a filter @FormUrlEncoded @PUT("filters/{id}") Call<Filter> editFilter( @Header("Authorization") String token, @Path("id") String id, @Field("phrase") String phrase, @Field("context[]") List<String> context, @Field("irreversible") boolean irreversible, @Field("whole_word") boolean whole_word, @Field("expires_in") String expires_in ); //Remove a filter @DELETE("filters/{id}") Call<Void> removeFilter( @Header("Authorization") String token, @Path("id") String id ); //Post a report @Headers({"Accept: application/json"}) Loading app/src/main/java/app/fedilab/android/client/endpoints/MastodonFiltersService.java 0 → 100644 +113 −0 Original line number Diff line number Diff line package app.fedilab.android.client.endpoints; /* 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; import app.fedilab.android.client.entities.api.Filter; import retrofit2.Call; import retrofit2.http.DELETE; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.POST; import retrofit2.http.PUT; import retrofit2.http.Path; public interface MastodonFiltersService { //Get filters @GET("filters") Call<List<Filter>> getFilters( @Header("Authorization") String token); //Get a filter with its id @GET("filters/{id}") Call<Filter> getFilter( @Header("Authorization") String token, @Path("id") String id); //Add a filter @FormUrlEncoded @POST("filters") Call<Filter> addFilter( @Header("Authorization") String token, @Field("title") String title, @Field("expires_in") Integer expires_in, @Field("filter_action") String filter_action, @Field("context[]") List<String> context, @Field("keywords_attributes") List<Filter.KeywordsAttributes> keywordsAttributes ); //Edit a filter @FormUrlEncoded @PUT("filters/{id}") Call<Filter> editFilter( @Header("Authorization") String token, @Path("id") String id, @Field("title") String title, @Field("expires_in") Integer expires_in, @Field("filter_action") String filter_action, @Field("context[]") List<String> context, @Field("keywords_attributes") List<Filter.KeywordsAttributes> keywordsAttributes ); //Remove a filter @DELETE("filters/{id}") Call<Void> removeFilter( @Header("Authorization") String token, @Path("id") String id ); //Get a filter with its id @GET("filters/{id}/keywords") Call<List<Filter.KeywordsAttributes>> getKeywordFilter( @Header("Authorization") String token, @Path("id") String id); //Add a keyword to a filter @FormUrlEncoded @POST("filters/{filter_id}/keywords/{id}") Call<Filter.KeywordsAttributes> addKeywordFilter( @Header("Authorization") String token, @Path("filter_id") String filter_id, @Path("id") String id, @Field("keyword") Filter.Keyword keyword ); //Edit a keyword for a filter @FormUrlEncoded @PUT("filters/{filter_id}/keywords/{id}") Call<Filter.KeywordsAttributes> editKeywordFilter( @Header("Authorization") String token, @Path("filter_id") String filter_id, @Path("id") String id, @Field("keyword") Filter.Keyword keyword ); //Remove a keyword for a filter @DELETE("filters/keywords/{id}") Call<Void> removeKeywordFilter( @Header("Authorization") String token, @Path("id") String id ); } app/src/main/java/app/fedilab/android/client/entities/api/Filter.java +49 −6 Original line number Diff line number Diff line Loading @@ -2,10 +2,11 @@ package app.fedilab.android.client.entities.api; import com.google.gson.annotations.SerializedName; import java.io.Serializable; import java.util.Date; import java.util.List; /* Copyright 2021 Thomas Schneider /* Copyright 2022 Thomas Schneider * * This file is a part of Fedilab * Loading @@ -20,7 +21,7 @@ import java.util.List; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see <http://www.gnu.org/licenses>. */ public class Filter { public class Filter implements Serializable { @SerializedName("id") public String id; @SerializedName("phrase") Loading @@ -31,8 +32,50 @@ public class Filter { public boolean whole_word; @SerializedName("expires_at") public Date expires_at; @SerializedName("expires_at_sent") public long expires_at_sent; @SerializedName("irreversible") public boolean irreversible; @SerializedName("filter_action") public String filter_action; @SerializedName("keywords") public List<FilterKeyword> keywords; public static class FilterKeyword implements Serializable { @SerializedName("id") public String id; @SerializedName("keyword") public String keyword; @SerializedName("whole_word") public boolean whole_word; } public static class FilterResult implements Serializable { @SerializedName("id") public String id; @SerializedName("phrase") public String phrase; @SerializedName("context") public List<String> context; @SerializedName("whole_word") public boolean whole_word; @SerializedName("expires_at") public Date expires_at; @SerializedName("filter_action") public String filter_action; } public static class Keyword { @SerializedName("keyword") public String keyword; @SerializedName("whole_word") public boolean whole_word; } public static class KeywordsAttributes { @SerializedName("id") public String id; @SerializedName("keyword") public String keyword; @SerializedName("whole_word") public boolean whole_word; @SerializedName("_destroy") public boolean _destroy; } } app/src/main/java/app/fedilab/android/client/entities/api/Status.java +2 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,8 @@ public class Status implements Serializable, Cloneable { public Card card; @SerializedName("poll") public Poll poll; @SerializedName("filtered") public Filter.FilterResult filtered; @SerializedName("pleroma") public Pleroma pleroma; @SerializedName("cached") Loading Loading
app/src/main/java/app/fedilab/android/activities/FilterActivity.java +16 −3 Original line number Diff line number Diff line Loading @@ -126,9 +126,22 @@ public class FilterActivity extends BaseActivity implements FilterAdapter.Delete } } popupAddFilterBinding.contextWholeWord.setChecked(filter.whole_word); popupAddFilterBinding.contextDrop.setChecked(filter.irreversible); if (filter.irreversible) { popupAddFilterBinding.actionRemove.setChecked(true); popupAddFilterBinding.actionHide.setChecked(false); } else { popupAddFilterBinding.actionRemove.setChecked(false); popupAddFilterBinding.actionHide.setChecked(true); } } popupAddFilterBinding.actionRemove.setOnClickListener(v -> { popupAddFilterBinding.actionHide.setChecked(false); popupAddFilterBinding.actionRemove.setChecked(true); }); popupAddFilterBinding.actionHide.setOnClickListener(v -> { popupAddFilterBinding.actionRemove.setChecked(false); popupAddFilterBinding.actionHide.setChecked(true); }); AlertDialog alertDialog = dialogBuilder.setPositiveButton(R.string.validate, null) .setNegativeButton(R.string.cancel, null).create(); Loading Loading @@ -161,7 +174,7 @@ public class FilterActivity extends BaseActivity implements FilterAdapter.Delete filterSent.expires_at_sent = expire[0]; filterSent.phrase = popupAddFilterBinding.addPhrase.getText().toString(); filterSent.whole_word = popupAddFilterBinding.contextWholeWord.isChecked(); filterSent.irreversible = popupAddFilterBinding.contextDrop.isChecked(); filterSent.irreversible = popupAddFilterBinding.actionRemove.isChecked(); if (filter != null) { accountsVM.editFilter(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, filter.id, filterSent.phrase, filterSent.context, filterSent.irreversible, filterSent.whole_word, filterSent.expires_at_sent) .observe((LifecycleOwner) context, listener::callback); Loading
app/src/main/java/app/fedilab/android/client/endpoints/MastodonAccountsService.java +0 −44 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ import java.util.List; import app.fedilab.android.client.entities.api.Account; import app.fedilab.android.client.entities.api.FeaturedTag; import app.fedilab.android.client.entities.api.Filter; import app.fedilab.android.client.entities.api.IdentityProof; import app.fedilab.android.client.entities.api.MastodonList; import app.fedilab.android.client.entities.api.Preferences; Loading @@ -40,7 +39,6 @@ import retrofit2.http.Headers; import retrofit2.http.Multipart; import retrofit2.http.PATCH; import retrofit2.http.POST; import retrofit2.http.PUT; import retrofit2.http.Part; import retrofit2.http.Path; import retrofit2.http.Query; Loading Loading @@ -320,48 +318,6 @@ public interface MastodonAccountsService { @Field("domain") String domain ); //Get filters @GET("filters") Call<List<Filter>> getFilters( @Header("Authorization") String token); //Get a filter with its id @GET("filters/{id}") Call<Filter> getFilter( @Header("Authorization") String token, @Path("id") String id); //Add a filter @FormUrlEncoded @POST("filters") Call<Filter> addFilter( @Header("Authorization") String token, @Field("phrase") String phrase, @Field("context[]") List<String> context, @Field("irreversible") boolean irreversible, @Field("whole_word") boolean whole_word, @Field("expires_in") String expires_in ); //Edit a filter @FormUrlEncoded @PUT("filters/{id}") Call<Filter> editFilter( @Header("Authorization") String token, @Path("id") String id, @Field("phrase") String phrase, @Field("context[]") List<String> context, @Field("irreversible") boolean irreversible, @Field("whole_word") boolean whole_word, @Field("expires_in") String expires_in ); //Remove a filter @DELETE("filters/{id}") Call<Void> removeFilter( @Header("Authorization") String token, @Path("id") String id ); //Post a report @Headers({"Accept: application/json"}) Loading
app/src/main/java/app/fedilab/android/client/endpoints/MastodonFiltersService.java 0 → 100644 +113 −0 Original line number Diff line number Diff line package app.fedilab.android.client.endpoints; /* 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; import app.fedilab.android.client.entities.api.Filter; import retrofit2.Call; import retrofit2.http.DELETE; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.POST; import retrofit2.http.PUT; import retrofit2.http.Path; public interface MastodonFiltersService { //Get filters @GET("filters") Call<List<Filter>> getFilters( @Header("Authorization") String token); //Get a filter with its id @GET("filters/{id}") Call<Filter> getFilter( @Header("Authorization") String token, @Path("id") String id); //Add a filter @FormUrlEncoded @POST("filters") Call<Filter> addFilter( @Header("Authorization") String token, @Field("title") String title, @Field("expires_in") Integer expires_in, @Field("filter_action") String filter_action, @Field("context[]") List<String> context, @Field("keywords_attributes") List<Filter.KeywordsAttributes> keywordsAttributes ); //Edit a filter @FormUrlEncoded @PUT("filters/{id}") Call<Filter> editFilter( @Header("Authorization") String token, @Path("id") String id, @Field("title") String title, @Field("expires_in") Integer expires_in, @Field("filter_action") String filter_action, @Field("context[]") List<String> context, @Field("keywords_attributes") List<Filter.KeywordsAttributes> keywordsAttributes ); //Remove a filter @DELETE("filters/{id}") Call<Void> removeFilter( @Header("Authorization") String token, @Path("id") String id ); //Get a filter with its id @GET("filters/{id}/keywords") Call<List<Filter.KeywordsAttributes>> getKeywordFilter( @Header("Authorization") String token, @Path("id") String id); //Add a keyword to a filter @FormUrlEncoded @POST("filters/{filter_id}/keywords/{id}") Call<Filter.KeywordsAttributes> addKeywordFilter( @Header("Authorization") String token, @Path("filter_id") String filter_id, @Path("id") String id, @Field("keyword") Filter.Keyword keyword ); //Edit a keyword for a filter @FormUrlEncoded @PUT("filters/{filter_id}/keywords/{id}") Call<Filter.KeywordsAttributes> editKeywordFilter( @Header("Authorization") String token, @Path("filter_id") String filter_id, @Path("id") String id, @Field("keyword") Filter.Keyword keyword ); //Remove a keyword for a filter @DELETE("filters/keywords/{id}") Call<Void> removeKeywordFilter( @Header("Authorization") String token, @Path("id") String id ); }
app/src/main/java/app/fedilab/android/client/entities/api/Filter.java +49 −6 Original line number Diff line number Diff line Loading @@ -2,10 +2,11 @@ package app.fedilab.android.client.entities.api; import com.google.gson.annotations.SerializedName; import java.io.Serializable; import java.util.Date; import java.util.List; /* Copyright 2021 Thomas Schneider /* Copyright 2022 Thomas Schneider * * This file is a part of Fedilab * Loading @@ -20,7 +21,7 @@ import java.util.List; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see <http://www.gnu.org/licenses>. */ public class Filter { public class Filter implements Serializable { @SerializedName("id") public String id; @SerializedName("phrase") Loading @@ -31,8 +32,50 @@ public class Filter { public boolean whole_word; @SerializedName("expires_at") public Date expires_at; @SerializedName("expires_at_sent") public long expires_at_sent; @SerializedName("irreversible") public boolean irreversible; @SerializedName("filter_action") public String filter_action; @SerializedName("keywords") public List<FilterKeyword> keywords; public static class FilterKeyword implements Serializable { @SerializedName("id") public String id; @SerializedName("keyword") public String keyword; @SerializedName("whole_word") public boolean whole_word; } public static class FilterResult implements Serializable { @SerializedName("id") public String id; @SerializedName("phrase") public String phrase; @SerializedName("context") public List<String> context; @SerializedName("whole_word") public boolean whole_word; @SerializedName("expires_at") public Date expires_at; @SerializedName("filter_action") public String filter_action; } public static class Keyword { @SerializedName("keyword") public String keyword; @SerializedName("whole_word") public boolean whole_word; } public static class KeywordsAttributes { @SerializedName("id") public String id; @SerializedName("keyword") public String keyword; @SerializedName("whole_word") public boolean whole_word; @SerializedName("_destroy") public boolean _destroy; } }
app/src/main/java/app/fedilab/android/client/entities/api/Status.java +2 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,8 @@ public class Status implements Serializable, Cloneable { public Card card; @SerializedName("poll") public Poll poll; @SerializedName("filtered") public Filter.FilterResult filtered; @SerializedName("pleroma") public Pleroma pleroma; @SerializedName("cached") Loading