diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java index 626be7e93..b39d7c129 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java @@ -14,6 +14,7 @@ * see . */ package fr.gouv.etalab.mastodon.activities; +import android.app.Dialog; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -50,9 +51,12 @@ import android.text.style.UnderlineSpan; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.Window; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.RadioButton; +import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; @@ -67,6 +71,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import es.dmoral.toasty.Toasty; import fr.gouv.etalab.mastodon.R; @@ -1011,6 +1016,8 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt final boolean isOwner = account.getId().equals(userId); String[] splitAcct = account.getAcct().split("@"); + if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) + popup.getMenu().findItem(R.id.action_filter).setVisible(true); if( splitAcct.length <= 1) { popup.getMenu().findItem(R.id.action_follow_instance).setVisible(false); popup.getMenu().findItem(R.id.action_block_instance).setVisible(false); @@ -1130,6 +1137,41 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt } }).start(); return true; + case R.id.action_filter: + AlertDialog.Builder filterTagDialog = new AlertDialog.Builder(ShowAccountActivity.this, style); + Set featuredTagsSet = sharedpreferences.getStringSet(Helper.SET_FEATURED_TAGS, null); + List tags = new ArrayList<>(); + if( featuredTagsSet != null){ + tags = new ArrayList<>(featuredTagsSet); + } + tags.add(0,getString(R.string.no_tags)); + String[] tagsString = tags.toArray(new String[tags.size()]); + List finalTags = tags; + String tag = sharedpreferences.getString(Helper.SET_FEATURED_TAG_ACTION, null); + int checkedposition = 0; + int i = 0; + for(String _t: tags){ + if( tag != null && _t.equals(tag)) + checkedposition = i; + i++; + } + filterTagDialog.setSingleChoiceItems(tagsString, checkedposition, new DialogInterface + .OnClickListener() { + public void onClick(DialogInterface dialog, int item) { + String tag; + if( item == 0){ + tag = null; + }else { + tag = finalTags.get(item); + } + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(Helper.SET_FEATURED_TAG_ACTION, tag); + editor.apply(); + dialog.dismiss(); + } + }); + filterTagDialog.show(); + return true; case R.id.action_endorse: if( relationship != null) if(relationship.isEndorsed()){ diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index 0ae88a1a9..e7e103a08 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -549,17 +549,10 @@ public class API { params.put("pinned", Boolean.toString(true)); params.put("exclude_replies", Boolean.toString(exclude_replies)); params.put("limit", String.valueOf(limit)); - if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON){ - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - Set featuredTagsSet = sharedpreferences.getStringSet(Helper.SET_FEATURED_TAGS, null); - if( featuredTagsSet != null && featuredTagsSet.size() > 0){ - List tags = new ArrayList<>(featuredTagsSet); - StringBuilder parameters = new StringBuilder(); - for(String tag: tags) - parameters.append("tagged[]=").append(tag).append("&"); - parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(9)); - params.put("tagged[]", parameters.toString()); - } + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + String tag = sharedpreferences.getString(Helper.SET_FEATURED_TAG_ACTION, null); + if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON && tag != null){ + params.put("tagged", tag); } statuses = new ArrayList<>(); try { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 770dcac32..933044389 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -305,6 +305,7 @@ public class Helper { public static final String SET_NOTIFICATION_ACTION = "set_notification_action"; public static final String SET_DISPLAY_CONTENT_AFTER_FM = "set_display_content_after_fm"; public static final String SET_FEATURED_TAGS ="set_featured_tags"; + public static final String SET_FEATURED_TAG_ACTION ="set_featured_tag_action"; public static final int S_NO = 0; static final int S_512KO = 1; public static final int S_1MO = 2; diff --git a/app/src/main/res/menu/main_showaccount.xml b/app/src/main/res/menu/main_showaccount.xml index 7c10c37df..68977a29e 100644 --- a/app/src/main/res/menu/main_showaccount.xml +++ b/app/src/main/res/menu/main_showaccount.xml @@ -26,6 +26,11 @@ android:title="@string/more_action_7" android:icon="@drawable/ic_chat_bubble_outline" app:showAsAction="ifRoom" /> + Submit The data base has been exported! Featured hashtags + Filter timeline with tags + No tags