featured tags

This commit is contained in:
tom79 2019-02-27 19:17:39 +01:00
parent 15e79d19ac
commit 35c8715a77
6 changed files with 104 additions and 5 deletions

View File

@ -39,6 +39,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.MainActivity;
@ -548,6 +549,18 @@ 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<String> featuredTagsSet = sharedpreferences.getStringSet(Helper.SET_FEATURED_TAGS, null);
if( featuredTagsSet != null && featuredTagsSet.size() > 0){
List<String> 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());
}
}
statuses = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);

View File

@ -54,6 +54,7 @@ import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.google.common.collect.ImmutableSet;
import com.tonyodev.fetch2.Download;
import com.tonyodev.fetch2.Error;
import com.tonyodev.fetch2.Fetch;
@ -72,16 +73,20 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import es.dmoral.toasty.Toasty;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.DomainBlockDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import mabbas007.tagsedittext.TagsEditText;
import static android.app.Activity.RESULT_OK;
import static fr.gouv.etalab.mastodon.helper.Helper.BACK_TO_SETTINGS;
@ -187,6 +192,39 @@ public class SettingsFragment extends Fragment {
}
});
TagsEditText set_featured_tags = rootView.findViewById(R.id.set_featured_tags);
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON){
Set<String> featuredTagsSet = sharedpreferences.getStringSet(Helper.SET_FEATURED_TAGS, null);
List<String> tags = new ArrayList<>();
if( featuredTagsSet != null){
tags = new ArrayList<>(featuredTagsSet);
}
String[] tagsString = tags.toArray(new String[tags.size()]);
set_featured_tags.setTags(tagsString);
set_featured_tags.setTagsListener(new TagsEditText.TagsEditListener() {
@Override
public void onTagsChanged(Collection<String> collection) {
Set<String> set = ImmutableSet.copyOf(collection);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putStringSet(Helper.SET_FEATURED_TAGS, set);
editor.apply();
}
@Override
public void onEditingFinished() {
}
});
}else{
set_featured_tags.setVisibility(View.GONE);
}
Button update_tracking_domains = rootView.findViewById(R.id.update_tracking_domains);
update_tracking_domains.setOnClickListener(new View.OnClickListener() {
@Override

View File

@ -304,6 +304,7 @@ public class Helper {
public static final String SET_DEFAULT_LOCALE_NEW = "set_default_locale_new";
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 int S_NO = 0;
static final int S_512KO = 1;
public static final int S_1MO = 2;

View File

@ -15,9 +15,9 @@
You should have received a copy of the GNU General Public License along with Mastalab; if not,
see <http://www.gnu.org/licenses>.
-->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:TagsEditText="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipeContainer"
android:paddingLeft="@dimen/drawer_padding"
android:paddingRight="@dimen/drawer_padding"
@ -519,7 +519,29 @@
android:layout_height="wrap_content" />
</LinearLayout>
<!-- Featured tags -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:labelFor="@+id/set_featured_tags"
android:text="@string/featured_hashtags"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<mabbas007.tagsedittext.TagsEditText
android:id="@+id/set_featured_tags"
android:layout_width="match_parent"
android:minLines="3"
android:lines="3"
android:layout_height="wrap_content"
TagsEditText:allowSpaceInTag="true"
TagsEditText:tagsCloseImageRight="@drawable/tag_close"
TagsEditText:tagsTextColor="?colorAccent"
TagsEditText:tagsTextSize="@dimen/defaultTagsTextSize"
TagsEditText:tagsCloseImagePadding="@dimen/defaultTagsCloseImagePadding"
android:inputType="textMultiLine" />
</LinearLayout>
<!-- TRUNCATE LONG TOOTS -->
<TextView

View File

@ -15,9 +15,9 @@
You should have received a copy of the GNU General Public License along with Mastalab; if not,
see <http://www.gnu.org/licenses>.
-->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:TagsEditText="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipeContainer"
android:paddingLeft="@dimen/drawer_padding"
android:paddingRight="@dimen/drawer_padding"
@ -524,6 +524,30 @@
</LinearLayout>
<!-- Featured tags -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:labelFor="@+id/set_featured_tags"
android:text="@string/featured_hashtags"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<mabbas007.tagsedittext.TagsEditText
android:id="@+id/set_featured_tags"
android:layout_width="match_parent"
android:minLines="3"
android:lines="3"
android:layout_height="wrap_content"
TagsEditText:allowSpaceInTag="true"
TagsEditText:tagsCloseImageRight="@drawable/tag_close"
TagsEditText:tagsTextColor="?colorAccent"
TagsEditText:tagsTextSize="@dimen/defaultTagsTextSize"
TagsEditText:tagsCloseImagePadding="@dimen/defaultTagsCloseImagePadding"
android:inputType="textMultiLine" />
</LinearLayout>
<!-- TRUNCATE LONG TOOTS -->
<TextView
android:layout_marginTop="10dp"

View File

@ -898,6 +898,7 @@
<string name="list_of_blocked_domains">List of blocked calls</string>
<string name="submit">Submit</string>
<string name="data_base_exported">The data base has been exported!</string>
<string name="featured_hashtags">Featured hashtags</string>
<!-- end languages -->