fedilab-Android-App/app/src/main/java/app/fedilab/android/client/Entities/ManageTimelines.java

1090 lines
52 KiB
Java
Raw Normal View History

2019-05-18 11:10:30 +02:00
package app.fedilab.android.client.Entities;
2019-04-21 10:22:07 +02:00
/* Copyright 2019 Thomas Schneider
*
2019-05-18 11:10:30 +02:00
* This file is a part of Fedilab
2019-04-21 10:22:07 +02:00
*
* 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.
*
2019-05-18 11:10:30 +02:00
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
2019-04-21 10:22:07 +02:00
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
2019-05-18 11:10:30 +02:00
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
2019-04-21 10:22:07 +02:00
* see <http://www.gnu.org/licenses>. */
2019-04-21 12:26:10 +02:00
import android.content.Context;
2019-04-25 18:40:10 +02:00
import android.content.Intent;
2019-04-21 12:26:10 +02:00
import android.content.SharedPreferences;
2019-04-21 18:50:56 +02:00
import android.database.sqlite.SQLiteDatabase;
2019-04-22 18:13:44 +02:00
import android.os.Bundle;
2019-04-21 18:50:56 +02:00
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
2019-04-22 13:16:35 +02:00
import android.widget.TextView;
2019-04-21 18:50:56 +02:00
import android.widget.Toast;
2019-04-22 18:13:44 +02:00
2019-11-15 16:32:25 +01:00
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentTransaction;
import com.google.android.material.tabs.TabLayout;
2019-04-22 18:13:44 +02:00
import java.util.ArrayList;
import java.util.Arrays;
2019-11-13 12:54:01 +01:00
import java.util.Objects;
2019-04-21 18:50:56 +02:00
import java.util.regex.Pattern;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.R;
import app.fedilab.android.activities.ListActivity;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.android.fragments.DisplayStatusFragment;
import app.fedilab.android.fragments.TabLayoutNotificationsFragment;
import app.fedilab.android.helper.Helper;
2019-11-15 16:32:25 +01:00
import app.fedilab.android.sqlite.InstancesDAO;
2019-05-18 11:10:30 +02:00
import app.fedilab.android.sqlite.SearchDAO;
import app.fedilab.android.sqlite.Sqlite;
import app.fedilab.android.sqlite.TimelinesDAO;
2019-11-15 16:32:25 +01:00
import es.dmoral.toasty.Toasty;
2019-04-22 18:13:44 +02:00
2019-05-18 11:10:30 +02:00
import static app.fedilab.android.activities.BaseMainActivity.mPageReferenceMap;
import static app.fedilab.android.sqlite.Sqlite.DB_NAME;
2019-04-21 12:26:10 +02:00
2019-04-21 10:22:07 +02:00
public class ManageTimelines {
2019-11-15 16:32:25 +01:00
private static String userId;
private static String instance;
2019-04-21 10:22:07 +02:00
private int position;
private int id;
private boolean displayed;
private Type type;
private RemoteInstance remoteInstance;
private TagTimeline tagTimeline;
2019-04-21 12:09:30 +02:00
private List listTimeline;
2019-05-25 14:20:17 +02:00
private String currentFilter;
2019-04-21 10:22:07 +02:00
2019-04-21 18:50:56 +02:00
private boolean notif_follow, notif_add, notif_mention, notif_share, notif_poll, notif_status;
2019-04-21 18:50:56 +02:00
2019-09-06 17:55:14 +02:00
public static Type typeFromDb(String value) {
switch (value) {
2019-04-21 10:22:07 +02:00
case "HOME":
return Type.HOME;
case "DIRECT":
return Type.DIRECT;
case "NOTIFICATION":
return Type.NOTIFICATION;
case "LOCAL":
return Type.LOCAL;
case "PUBLIC":
return Type.PUBLIC;
case "ART":
return Type.ART;
case "PEERTUBE":
return Type.PEERTUBE;
case "TAG":
return Type.TAG;
case "LIST":
return Type.LIST;
case "INSTANCE":
return Type.INSTANCE;
}
return null;
}
2019-09-06 17:55:14 +02:00
public static String typeToDb(Type type) {
switch (type) {
2019-04-21 10:22:07 +02:00
case HOME:
return "HOME";
case DIRECT:
return "DIRECT";
case NOTIFICATION:
return "NOTIFICATION";
case LOCAL:
return "LOCAL";
case PUBLIC:
return "PUBLIC";
case ART:
return "ART";
case PEERTUBE:
return "PEERTUBE";
case TAG:
return "TAG";
case LIST:
return "LIST";
case INSTANCE:
return "INSTANCE";
}
return null;
}
2019-09-06 17:55:14 +02:00
public static RetrieveFeedsAsyncTask.Type transform(Context context, Type type) {
2019-04-21 12:26:10 +02:00
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
2019-09-06 17:55:14 +02:00
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
switch (type) {
2019-04-21 12:26:10 +02:00
case HOME:
return RetrieveFeedsAsyncTask.Type.HOME;
case DIRECT:
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
2020-03-12 18:09:41 +01:00
return RetrieveFeedsAsyncTask.Type.CONVERSATION;
2019-04-21 12:26:10 +02:00
case NOTIFICATION:
return RetrieveFeedsAsyncTask.Type.NOTIFICATION;
case PUBLIC:
return RetrieveFeedsAsyncTask.Type.PUBLIC;
case LOCAL:
return RetrieveFeedsAsyncTask.Type.LOCAL;
case ART:
return RetrieveFeedsAsyncTask.Type.ART;
case PEERTUBE:
case INSTANCE:
return RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE;
case TAG:
return RetrieveFeedsAsyncTask.Type.TAG;
case LIST:
return RetrieveFeedsAsyncTask.Type.LIST;
}
return null;
2019-09-06 17:55:14 +02:00
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
2019-04-21 12:26:10 +02:00
switch (type) {
case HOME:
return RetrieveFeedsAsyncTask.Type.GNU_HOME;
case NOTIFICATION:
return RetrieveFeedsAsyncTask.Type.GNU_NOTIFICATION;
case DIRECT:
return RetrieveFeedsAsyncTask.Type.GNU_DM;
case LOCAL:
return RetrieveFeedsAsyncTask.Type.GNU_LOCAL;
}
return null;
2019-09-06 17:55:14 +02:00
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
2019-04-21 12:26:10 +02:00
switch (type) {
case HOME:
return RetrieveFeedsAsyncTask.Type.GNU_HOME;
case NOTIFICATION:
return RetrieveFeedsAsyncTask.Type.GNU_NOTIFICATION;
case DIRECT:
return RetrieveFeedsAsyncTask.Type.GNU_DM;
case LOCAL:
return RetrieveFeedsAsyncTask.Type.GNU_LOCAL;
case PUBLIC:
return RetrieveFeedsAsyncTask.Type.GNU_WHOLE;
case TAG:
return RetrieveFeedsAsyncTask.Type.GNU_TAG;
}
return null;
}
return null;
}
2019-11-15 16:32:25 +01:00
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
public boolean isDisplayed() {
return displayed;
}
public void setDisplayed(boolean displayed) {
this.displayed = displayed;
}
public ManageTimelines.Type getType() {
return type;
}
public void setType(ManageTimelines.Type type) {
this.type = type;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUserId() {
return userId;
}
public String getInstance() {
return instance;
}
public RemoteInstance getRemoteInstance() {
return remoteInstance;
}
public void setRemoteInstance(RemoteInstance remoteInstance) {
this.remoteInstance = remoteInstance;
}
public TagTimeline getTagTimeline() {
return tagTimeline;
}
public void setTagTimeline(TagTimeline tagTimeline) {
this.tagTimeline = tagTimeline;
}
public List getListTimeline() {
return listTimeline;
}
public void setListTimeline(List listTimeline) {
this.listTimeline = listTimeline;
}
2019-04-21 10:22:07 +02:00
2019-09-06 17:55:14 +02:00
public TabLayout createTabs(Context context, TabLayout tabLayout, java.util.List<ManageTimelines> manageTimelines) {
2019-04-21 18:50:56 +02:00
2019-04-22 18:13:44 +02:00
tabLayout.removeAllTabs();
2019-04-25 18:40:10 +02:00
int position = 0;
2019-09-06 17:55:14 +02:00
for (ManageTimelines tl : manageTimelines) {
2019-04-21 18:50:56 +02:00
TabLayout.Tab tb = tabLayout.newTab();
ImageView icon = null;
2019-09-06 17:55:14 +02:00
if (tl.getType() != Type.TAG && tl.getType() != Type.INSTANCE && tl.getType() != Type.LIST) {
2019-04-22 13:16:35 +02:00
tb.setCustomView(R.layout.tab_badge);
2019-09-06 17:55:14 +02:00
if (tb.getCustomView() != null)
2019-04-21 18:50:56 +02:00
icon = tb.getCustomView().findViewById(R.id.tab_icon);
}
2019-11-20 19:07:46 +01:00
2020-03-08 10:29:06 +01:00
Helper.changeDrawableColor(context, R.drawable.ic_home, R.attr.iconColorMenu);
Helper.changeDrawableColor(context, R.drawable.ic_notifications, R.attr.iconColorMenu);
Helper.changeDrawableColor(context, R.drawable.ic_direct_messages, R.attr.iconColorMenu);
Helper.changeDrawableColor(context, R.drawable.ic_people, R.attr.iconColorMenu);
Helper.changeDrawableColor(context, R.drawable.ic_public, R.attr.iconColorMenu);
Helper.changeDrawableColor(context, R.drawable.ic_color_lens, R.attr.iconColorMenu);
Helper.changeDrawableColor(context, R.drawable.ic_video_peertube, R.attr.iconColorMenu);
2019-09-06 17:55:14 +02:00
if (icon != null) {
switch (tl.getType()) {
2019-04-21 18:50:56 +02:00
case HOME:
icon.setImageResource(R.drawable.ic_home);
icon.setContentDescription(context.getString(R.string.home_menu));
break;
case NOTIFICATION:
icon.setImageResource(R.drawable.ic_notifications);
icon.setContentDescription(context.getString(R.string.notifications));
break;
case DIRECT:
icon.setImageResource(R.drawable.ic_direct_messages);
icon.setContentDescription(context.getString(R.string.direct_message));
break;
case LOCAL:
icon.setImageResource(R.drawable.ic_people);
icon.setContentDescription(context.getString(R.string.local_menu));
break;
case PUBLIC:
icon.setImageResource(R.drawable.ic_public);
icon.setContentDescription(context.getString(R.string.global_menu));
break;
case ART:
icon.setImageResource(R.drawable.ic_color_lens);
icon.setContentDescription(context.getString(R.string.art_menu));
break;
case PEERTUBE:
icon.setImageResource(R.drawable.ic_video_peertube);
icon.setContentDescription(context.getString(R.string.peertube_menu));
break;
}
tabLayout.addTab(tb);
2019-09-06 17:55:14 +02:00
} else {
2019-05-04 19:06:24 +02:00
String name = "";
2019-09-06 17:55:14 +02:00
if (tl.getType() == Type.TAG) {
if (tl.getTagTimeline().getDisplayname() != null) {
2019-05-04 19:06:24 +02:00
name = tl.getTagTimeline().getDisplayname();
2019-09-06 17:55:14 +02:00
} else {
2019-05-04 19:06:24 +02:00
name = tl.getTagTimeline().getName();
2019-04-22 13:16:35 +02:00
}
2019-09-06 17:55:14 +02:00
} else if (tl.getType() == Type.INSTANCE) {
2019-05-04 19:06:24 +02:00
name = tl.getRemoteInstance().getHost();
2019-09-06 17:55:14 +02:00
} else if (tl.getType() == Type.LIST) {
2019-05-04 19:06:24 +02:00
name = tl.getListTimeline().getTitle();
2019-04-22 13:16:35 +02:00
}
2020-03-12 18:09:41 +01:00
TextView tv = (TextView) LayoutInflater.from(context).inflate(R.layout.custom_tab_instance, new LinearLayout(context), false);
2019-05-04 19:06:24 +02:00
tv.setText(name);
2019-11-09 14:35:45 +01:00
2019-05-04 19:06:24 +02:00
tb.setCustomView(tv);
tabLayout.addTab(tb);
2019-04-21 18:50:56 +02:00
}
2019-05-04 19:06:24 +02:00
2019-04-21 18:50:56 +02:00
final LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0);
2019-09-06 17:55:14 +02:00
if (tl.getType() == Type.NOTIFICATION) {
2019-04-21 18:50:56 +02:00
notificationClik(context, tl, tabLayout);
2019-09-06 17:55:14 +02:00
} else if (tl.getType() == Type.PUBLIC || tl.getType() == Type.LOCAL || tl.getType() == Type.ART || tl.getType() == Type.HOME) {
if (tabStrip != null && tabStrip.getChildCount() > position) {
2019-04-25 18:40:10 +02:00
int finalPosition1 = position;
2020-03-12 18:09:41 +01:00
tabStrip.getChildAt(position).setOnLongClickListener(v -> {
manageFilters(context, tl, tabStrip, finalPosition1);
return true;
2019-04-21 18:50:56 +02:00
});
}
2019-09-06 17:55:14 +02:00
} else if (tl.getType() == Type.TAG) {
if (tabStrip != null && tabStrip.getChildCount() > position) {
2019-04-25 18:40:10 +02:00
int finalPosition = position;
2020-03-12 18:09:41 +01:00
tabStrip.getChildAt(position).setOnLongClickListener(v -> {
tagClick(context, tl, tabStrip, finalPosition);
return true;
2019-04-25 18:40:10 +02:00
});
}
2019-09-06 17:55:14 +02:00
} else if (tl.getType() == Type.INSTANCE && (tl.getRemoteInstance().getType().equals("MASTODON") || tl.getRemoteInstance().getType().equals("PEERTUBE") || tl.getRemoteInstance().getType().equals("PLEROMA") || tl.getRemoteInstance().getType().equals("GNU"))) {
if (tabStrip != null && tabStrip.getChildCount() > position) {
2019-05-25 11:29:58 +02:00
int finalPosition = position;
2020-03-12 18:09:41 +01:00
tabStrip.getChildAt(position).setOnLongClickListener(v -> {
instanceClick(context, tl, tabStrip, finalPosition);
return true;
2019-05-25 11:29:58 +02:00
});
}
2019-09-06 17:55:14 +02:00
} else if (tl.getType() == Type.LIST) {
if (tabStrip != null && tabStrip.getChildCount() > position) {
2020-03-12 18:09:41 +01:00
tabStrip.getChildAt(position).setOnLongClickListener(v -> {
Intent intent = new Intent(context, ListActivity.class);
Bundle b = new Bundle();
b.putString("id", tl.getListTimeline().getId());
b.putString("title", tl.getListTimeline().getTitle());
intent.putExtras(b);
context.startActivity(intent);
return true;
2019-04-22 18:13:44 +02:00
});
}
2019-04-21 18:50:56 +02:00
}
2019-04-25 18:40:10 +02:00
position++;
2019-04-21 18:50:56 +02:00
}
2019-06-17 11:23:13 +02:00
return tabLayout;
2019-04-21 18:50:56 +02:00
}
2019-09-06 17:55:14 +02:00
private void notificationClik(Context context, ManageTimelines tl, TabLayout tabLayout) {
2019-04-21 18:50:56 +02:00
final LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0);
2019-09-06 17:55:14 +02:00
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA)
if (tabStrip != null && tabStrip.getChildCount() > tl.getPosition()) {
2020-03-12 18:09:41 +01:00
tabStrip.getChildAt(tl.getPosition()).setOnLongClickListener(v -> {
//Only shown if the tab has focus
PopupMenu popup = new PopupMenu(context, tabStrip.getChildAt(1));
popup.getMenuInflater()
.inflate(R.menu.option_filter_notifications, popup.getMenu());
Menu menu = popup.getMenu();
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
final MenuItem itemFavourite = menu.findItem(R.id.action_favorite);
final MenuItem itemFollow = menu.findItem(R.id.action_follow);
final MenuItem itemMention = menu.findItem(R.id.action_mention);
final MenuItem itemBoost = menu.findItem(R.id.action_boost);
final MenuItem itemPoll = menu.findItem(R.id.action_poll);
final MenuItem itemStatus = menu.findItem(R.id.action_status);
2020-03-12 18:09:41 +01:00
notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW_FILTER, true);
notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD_FILTER, true);
notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION_FILTER, true);
notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE_FILTER, true);
notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL_FILTER, true);
notif_status = sharedpreferences.getBoolean(Helper.SET_NOTIF_STATUS_FILTER, true);
2020-03-12 18:09:41 +01:00
itemFavourite.setChecked(notif_add);
itemFollow.setChecked(notif_follow);
itemMention.setChecked(notif_mention);
itemBoost.setChecked(notif_share);
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
2020-03-12 18:09:41 +01:00
itemPoll.setChecked(notif_poll);
itemStatus.setChecked(notif_status);
} else
2020-03-12 18:09:41 +01:00
itemPoll.setVisible(false);
popup.setOnDismissListener(menu1 -> {
if (mPageReferenceMap != null) {
TabLayoutNotificationsFragment tabLayoutNotificationsFragment = (TabLayoutNotificationsFragment) mPageReferenceMap.get(tl.getPosition());
if (tabLayoutNotificationsFragment != null) {
tabLayoutNotificationsFragment.refreshAll();
}
}
});
popup.setOnMenuItemClickListener(item -> {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(context));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
2019-04-21 18:50:56 +02:00
@Override
2020-03-12 18:09:41 +01:00
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
2019-04-21 18:50:56 +02:00
}
2020-03-12 18:09:41 +01:00
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
2019-04-21 18:50:56 +02:00
return false;
}
});
int itemId = item.getItemId();
if (itemId == R.id.action_favorite) {
SharedPreferences.Editor editor = sharedpreferences.edit();
notif_add = !notif_add;
editor.putBoolean(Helper.SET_NOTIF_ADD_FILTER, notif_add);
itemFavourite.setChecked(notif_add);
editor.apply();
} else if (itemId == R.id.action_follow) {
SharedPreferences.Editor editor;
editor = sharedpreferences.edit();
notif_follow = !notif_follow;
editor.putBoolean(Helper.SET_NOTIF_FOLLOW_FILTER, notif_follow);
itemFollow.setChecked(notif_follow);
editor.apply();
} else if (itemId == R.id.action_mention) {
SharedPreferences.Editor editor;
editor = sharedpreferences.edit();
notif_mention = !notif_mention;
editor.putBoolean(Helper.SET_NOTIF_MENTION_FILTER, notif_mention);
itemMention.setChecked(notif_mention);
editor.apply();
} else if (itemId == R.id.action_boost) {
SharedPreferences.Editor editor;
editor = sharedpreferences.edit();
notif_share = !notif_share;
editor.putBoolean(Helper.SET_NOTIF_SHARE_FILTER, notif_share);
itemBoost.setChecked(notif_share);
editor.apply();
} else if (itemId == R.id.action_poll) {
SharedPreferences.Editor editor;
editor = sharedpreferences.edit();
notif_poll = !notif_poll;
editor.putBoolean(Helper.SET_NOTIF_POLL_FILTER, notif_poll);
itemPoll.setChecked(notif_poll);
editor.apply();
} else if (itemId == R.id.action_status) {
SharedPreferences.Editor editor;
editor = sharedpreferences.edit();
notif_status = !notif_status;
editor.putBoolean(Helper.SET_NOTIF_STATUS_FILTER, notif_status);
itemStatus.setChecked(notif_status);
editor.apply();
2020-03-12 18:09:41 +01:00
}
return false;
});
popup.show();
return true;
2019-04-21 18:50:56 +02:00
});
}
}
2019-09-06 17:55:14 +02:00
private void manageFilters(Context context, ManageTimelines tl, LinearLayout tabStrip, int position) {
2019-04-21 18:50:56 +02:00
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
//Only shown if the tab has focus
2019-04-25 18:40:10 +02:00
PopupMenu popup = new PopupMenu(context, tabStrip.getChildAt(position));
2019-09-06 17:55:14 +02:00
if (tl.getType() == Type.ART) {
2019-04-21 18:50:56 +02:00
popup.getMenuInflater()
.inflate(R.menu.option_tag_timeline, popup.getMenu());
Menu menu = popup.getMenu();
final boolean[] show_nsfw = {sharedpreferences.getBoolean(Helper.SET_ART_WITH_NSFW, false)};
final MenuItem itemShowNSFW = menu.findItem(R.id.action_show_nsfw);
final MenuItem itemMedia = menu.findItem(R.id.action_show_media_only);
2019-04-27 18:01:13 +02:00
//final MenuItem itemDelete = menu.findItem(R.id.action_delete);
2019-04-21 18:50:56 +02:00
final MenuItem itemAny = menu.findItem(R.id.action_any);
final MenuItem itemAll = menu.findItem(R.id.action_all);
final MenuItem itemNone = menu.findItem(R.id.action_none);
final MenuItem action_displayname = menu.findItem(R.id.action_displayname);
itemAny.setVisible(false);
itemAll.setVisible(false);
itemNone.setVisible(false);
action_displayname.setVisible(false);
itemMedia.setVisible(false);
2019-09-06 17:55:14 +02:00
// itemDelete.setVisible(false);
2019-04-21 18:50:56 +02:00
itemShowNSFW.setChecked(show_nsfw[0]);
final boolean[] changes = {false};
2020-03-12 18:09:41 +01:00
popup.setOnDismissListener(menu1 -> {
if (changes[0]) {
if (mPageReferenceMap != null) {
FragmentTransaction fragTransaction = ((MainActivity) context).getSupportFragmentManager().beginTransaction();
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
2020-05-16 11:32:09 +02:00
if (displayStatusFragment != null) {
fragTransaction.detach(displayStatusFragment);
fragTransaction.attach(displayStatusFragment);
fragTransaction.commit();
}
2019-04-21 18:50:56 +02:00
}
}
});
2020-03-12 18:09:41 +01:00
popup.setOnMenuItemClickListener(item -> {
changes[0] = true;
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(context));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
2019-04-21 18:50:56 +02:00
2020-03-12 18:09:41 +01:00
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
return false;
2019-04-21 18:50:56 +02:00
}
2020-03-12 18:09:41 +01:00
});
if (item.getItemId() == R.id.action_show_nsfw) {
show_nsfw[0] = !show_nsfw[0];
itemShowNSFW.setChecked(show_nsfw[0]);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_ART_WITH_NSFW, show_nsfw[0]);
editor.apply();
MainActivity.show_art_nsfw = show_nsfw[0];
2019-04-21 18:50:56 +02:00
}
2020-03-12 18:09:41 +01:00
return false;
2019-04-21 18:50:56 +02:00
});
popup.show();
2019-09-06 17:55:14 +02:00
} else {
2019-04-21 18:50:56 +02:00
popup.getMenuInflater()
.inflate(R.menu.option_filter_toots, popup.getMenu());
Menu menu = popup.getMenu();
final MenuItem itemShowBoosts = menu.findItem(R.id.action_show_boosts);
final MenuItem itemShowReplies = menu.findItem(R.id.action_show_replies);
final MenuItem itemFilter = menu.findItem(R.id.action_filter);
2019-09-06 17:55:14 +02:00
if (mPageReferenceMap == null) {
2019-08-24 17:33:10 +02:00
return;
}
2019-04-22 18:13:44 +02:00
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
2019-09-06 17:55:14 +02:00
if (tl.getType() != Type.HOME) {
2019-04-21 18:50:56 +02:00
itemShowBoosts.setVisible(false);
itemShowReplies.setVisible(false);
itemFilter.setVisible(true);
2019-09-06 17:55:14 +02:00
} else {
2019-04-21 18:50:56 +02:00
itemShowBoosts.setVisible(true);
itemShowReplies.setVisible(true);
itemFilter.setVisible(true);
}
final boolean[] show_boosts = {sharedpreferences.getBoolean(Helper.SET_SHOW_BOOSTS, true)};
final boolean[] show_replies = {sharedpreferences.getBoolean(Helper.SET_SHOW_REPLIES, true)};
String show_filtered = null;
2020-01-19 18:27:02 +01:00
if (tl.getType() == Type.HOME)
2019-04-21 18:50:56 +02:00
show_filtered = sharedpreferences.getString(Helper.SET_FILTER_REGEX_HOME, null);
2020-01-19 18:27:02 +01:00
if (tl.getType() == Type.LOCAL)
2019-04-21 18:50:56 +02:00
show_filtered = sharedpreferences.getString(Helper.SET_FILTER_REGEX_LOCAL, null);
2020-01-19 18:27:02 +01:00
if (tl.getType() == Type.PUBLIC)
2019-04-21 18:50:56 +02:00
show_filtered = sharedpreferences.getString(Helper.SET_FILTER_REGEX_PUBLIC, null);
itemShowBoosts.setChecked(show_boosts[0]);
itemShowReplies.setChecked(show_replies[0]);
2019-09-06 17:55:14 +02:00
if (show_filtered != null && show_filtered.length() > 0) {
2019-04-21 18:50:56 +02:00
itemFilter.setTitle(show_filtered);
}
2020-03-12 18:09:41 +01:00
popup.setOnDismissListener(menu12 -> {
2020-04-25 19:20:42 +02:00
if (displayStatusFragment != null && displayStatusFragment.isVisible())
2020-03-12 18:09:41 +01:00
displayStatusFragment.refreshFilter();
2019-04-21 18:50:56 +02:00
});
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
2019-09-06 17:55:14 +02:00
} else if (theme == Helper.THEME_BLACK) {
2019-04-21 18:50:56 +02:00
style = R.style.DialogBlack;
2019-09-06 17:55:14 +02:00
} else {
2019-04-21 18:50:56 +02:00
style = R.style.Dialog;
}
String finalShow_filtered = show_filtered;
2020-03-12 18:09:41 +01:00
popup.setOnMenuItemClickListener(item -> {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(context));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
2019-04-21 18:50:56 +02:00
2020-03-12 18:09:41 +01:00
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
return false;
}
});
final SharedPreferences.Editor editor = sharedpreferences.edit();
switch (item.getItemId()) {
case R.id.action_show_boosts:
show_boosts[0] = !show_boosts[0];
editor.putBoolean(Helper.SET_SHOW_BOOSTS, show_boosts[0]);
itemShowBoosts.setChecked(show_boosts[0]);
editor.apply();
MainActivity.show_boosts = show_boosts[0];
break;
case R.id.action_show_replies:
show_replies[0] = !show_replies[0];
editor.putBoolean(Helper.SET_SHOW_REPLIES, show_replies[0]);
itemShowReplies.setChecked(show_replies[0]);
editor.apply();
MainActivity.show_replies = show_replies[0];
break;
case R.id.action_filter:
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, style);
LayoutInflater inflater = ((MainActivity) context).getLayoutInflater();
View dialogView = inflater.inflate(R.layout.filter_regex, new LinearLayout(context), false);
dialogBuilder.setView(dialogView);
final EditText editText = dialogView.findViewById(R.id.filter_regex);
Toast alertRegex = Toasty.warning(context, context.getString(R.string.alert_regex), Toast.LENGTH_LONG);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
2019-09-06 17:55:14 +02:00
2020-03-12 18:09:41 +01:00
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
2019-09-06 17:55:14 +02:00
2020-03-12 18:09:41 +01:00
@Override
public void afterTextChanged(Editable s) {
try {
Pattern.compile("(" + s.toString() + ")", Pattern.CASE_INSENSITIVE);
} catch (Exception e) {
if (!alertRegex.getView().isShown()) {
alertRegex.show();
2019-04-21 18:50:56 +02:00
}
}
2020-03-12 18:09:41 +01:00
2019-04-21 18:50:56 +02:00
}
2020-03-12 18:09:41 +01:00
});
if (finalShow_filtered != null) {
editText.setText(finalShow_filtered);
editText.setSelection(editText.getText().toString().length());
}
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
itemFilter.setTitle(editText.getText().toString().trim());
if (tl.getType() == Type.HOME) {
editor.putString(Helper.SET_FILTER_REGEX_HOME, editText.getText().toString().trim());
MainActivity.regex_home = editText.getText().toString().trim();
}
if (tl.getType() == Type.LOCAL) {
editor.putString(Helper.SET_FILTER_REGEX_LOCAL, editText.getText().toString().trim());
MainActivity.regex_local = editText.getText().toString().trim();
}
if (tl.getType() == Type.PUBLIC) {
editor.putString(Helper.SET_FILTER_REGEX_PUBLIC, editText.getText().toString().trim());
MainActivity.regex_public = editText.getText().toString().trim();
}
editor.apply();
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
break;
2019-04-21 18:50:56 +02:00
}
2020-03-12 18:09:41 +01:00
return false;
2019-04-21 18:50:56 +02:00
});
popup.show();
}
}
2019-09-06 17:55:14 +02:00
private void tagClick(Context context, ManageTimelines tl, LinearLayout tabStrip, int position) {
2019-04-22 18:13:44 +02:00
2019-04-25 18:40:10 +02:00
PopupMenu popup = new PopupMenu(context, tabStrip.getChildAt(position));
2019-09-06 17:55:14 +02:00
TabLayout tabLayout = ((MainActivity) context).findViewById(R.id.tabLayout);
2019-11-13 12:54:01 +01:00
tabLayout.setBackgroundColor(ContextCompat.getColor(Objects.requireNonNull(context), R.color.cyanea_primary));
2020-04-09 18:57:12 +02:00
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), DB_NAME, null, Sqlite.DB_VERSION).open();
2019-04-22 18:13:44 +02:00
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
2019-09-06 17:55:14 +02:00
} else if (theme == Helper.THEME_BLACK) {
2019-04-22 18:13:44 +02:00
style = R.style.DialogBlack;
2019-09-06 17:55:14 +02:00
} else {
2019-04-22 18:13:44 +02:00
style = R.style.Dialog;
}
String tag;
2019-04-26 19:05:09 +02:00
tagTimeline = tl.getTagTimeline();
2019-09-06 17:55:14 +02:00
if (tagTimeline == null)
2019-04-26 15:50:26 +02:00
return;
2019-09-06 17:55:14 +02:00
if (tagTimeline.getDisplayname() != null)
2019-04-26 19:05:09 +02:00
tag = tagTimeline.getDisplayname();
2019-04-22 18:13:44 +02:00
else
2019-04-26 19:05:09 +02:00
tag = tagTimeline.getName();
2019-04-22 18:13:44 +02:00
popup.getMenuInflater()
.inflate(R.menu.option_tag_timeline, popup.getMenu());
Menu menu = popup.getMenu();
final MenuItem itemMediaOnly = menu.findItem(R.id.action_show_media_only);
final MenuItem itemShowNSFW = menu.findItem(R.id.action_show_nsfw);
final boolean[] changes = {false};
final boolean[] mediaOnly = {false};
final boolean[] showNSFW = {false};
2019-04-26 19:05:09 +02:00
mediaOnly[0] = tagTimeline.isART();
showNSFW[0] = tagTimeline.isNSFW();
2019-04-22 18:13:44 +02:00
itemMediaOnly.setChecked(mediaOnly[0]);
itemShowNSFW.setChecked(showNSFW[0]);
2020-03-12 18:09:41 +01:00
popup.setOnDismissListener(menu1 -> {
if (changes[0]) {
if (mPageReferenceMap == null)
return;
FragmentTransaction fragTransaction = ((MainActivity) context).getSupportFragmentManager().beginTransaction();
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
if (displayStatusFragment == null)
return;
fragTransaction.detach(displayStatusFragment);
Bundle bundle = new Bundle();
bundle.putString("tag", tl.getTagTimeline().getName());
bundle.putInt("timelineId", tl.getId());
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.TAG);
if (mediaOnly[0])
bundle.putString("instanceType", "ART");
else
bundle.putString("instanceType", "MASTODON");
displayStatusFragment.setArguments(bundle);
fragTransaction.attach(displayStatusFragment);
fragTransaction.commit();
2019-04-22 18:13:44 +02:00
}
});
2020-03-12 18:09:41 +01:00
popup.setOnMenuItemClickListener(item -> {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(context));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
2019-04-22 18:13:44 +02:00
2020-03-12 18:09:41 +01:00
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
return false;
}
});
changes[0] = true;
switch (item.getItemId()) {
case R.id.action_show_media_only:
mediaOnly[0] = !mediaOnly[0];
tagTimeline.setART(mediaOnly[0]);
new SearchDAO(context, db).updateSearch(tagTimeline);
tl.setTagTimeline(tagTimeline);
itemMediaOnly.setChecked(mediaOnly[0]);
new TimelinesDAO(context, db).updateTag(tl);
break;
case R.id.action_show_nsfw:
showNSFW[0] = !showNSFW[0];
tagTimeline.setNSFW(showNSFW[0]);
new SearchDAO(context, db).updateSearch(tagTimeline);
tl.setTagTimeline(tagTimeline);
itemShowNSFW.setChecked(showNSFW[0]);
new TimelinesDAO(context, db).updateTag(tl);
break;
case R.id.action_any:
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, style);
LayoutInflater inflater = ((MainActivity) context).getLayoutInflater();
View dialogView = inflater.inflate(R.layout.tags_any, new LinearLayout(context), false);
dialogBuilder.setView(dialogView);
final EditText editText = dialogView.findViewById(R.id.filter_any);
if (tagTimeline.getAny() != null) {
StringBuilder valuesTag = new StringBuilder();
for (String val : tagTimeline.getAny())
valuesTag.append(val).append(" ");
editText.setText(valuesTag.toString());
editText.setSelection(editText.getText().toString().length());
2019-04-22 18:13:44 +02:00
}
2020-03-12 18:09:41 +01:00
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
String[] values = editText.getText().toString().trim().split("\\s+");
java.util.List<String> any =
new ArrayList<>(Arrays.asList(values));
tagTimeline.setAny(any);
2019-04-26 19:05:09 +02:00
new SearchDAO(context, db).updateSearch(tagTimeline);
2019-04-26 15:50:26 +02:00
tl.setTagTimeline(tagTimeline);
2019-04-26 19:05:09 +02:00
new TimelinesDAO(context, db).updateTag(tl);
2020-03-12 18:09:41 +01:00
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
break;
case R.id.action_all:
dialogBuilder = new AlertDialog.Builder(context, style);
inflater = ((MainActivity) context).getLayoutInflater();
2020-04-08 12:42:15 +02:00
dialogView = inflater.inflate(R.layout.tags_all, new LinearLayout(context), false);
2020-03-12 18:09:41 +01:00
dialogBuilder.setView(dialogView);
final EditText editTextAll = dialogView.findViewById(R.id.filter_all);
if (tagTimeline.getAll() != null) {
StringBuilder valuesTag = new StringBuilder();
for (String val : tagTimeline.getAll())
valuesTag.append(val).append(" ");
editTextAll.setText(valuesTag.toString());
editTextAll.setSelection(editTextAll.getText().toString().length());
}
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
String[] values = editTextAll.getText().toString().trim().split("\\s+");
java.util.List<String> all =
new ArrayList<>(Arrays.asList(values));
tagTimeline.setAll(all);
2019-04-26 19:05:09 +02:00
new SearchDAO(context, db).updateSearch(tagTimeline);
2019-04-26 15:50:26 +02:00
tl.setTagTimeline(tagTimeline);
2019-04-26 19:05:09 +02:00
new TimelinesDAO(context, db).updateTag(tl);
2020-03-12 18:09:41 +01:00
});
alertDialog = dialogBuilder.create();
alertDialog.show();
break;
case R.id.action_none:
dialogBuilder = new AlertDialog.Builder(context, style);
inflater = ((MainActivity) context).getLayoutInflater();
dialogView = inflater.inflate(R.layout.tags_all, new LinearLayout(context), false);
dialogBuilder.setView(dialogView);
final EditText editTextNone = dialogView.findViewById(R.id.filter_all);
if (tagTimeline.getNone() != null) {
StringBuilder valuesTag = new StringBuilder();
for (String val : tagTimeline.getNone())
valuesTag.append(val).append(" ");
editTextNone.setText(valuesTag.toString());
editTextNone.setSelection(editTextNone.getText().toString().length());
}
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
String[] values = editTextNone.getText().toString().trim().split("\\s+");
java.util.List<String> none =
new ArrayList<>(Arrays.asList(values));
tagTimeline.setNone(none);
new SearchDAO(context, db).updateSearch(tagTimeline);
tl.setTagTimeline(tagTimeline);
new TimelinesDAO(context, db).updateTag(tl);
});
alertDialog = dialogBuilder.create();
alertDialog.show();
break;
case R.id.action_displayname:
dialogBuilder = new AlertDialog.Builder(context, style);
inflater = ((MainActivity) context).getLayoutInflater();
dialogView = inflater.inflate(R.layout.tags_name, new LinearLayout(context), false);
dialogBuilder.setView(dialogView);
final EditText editTextName = dialogView.findViewById(R.id.column_name);
if (tagTimeline.getDisplayname() != null) {
editTextName.setText(tagTimeline.getDisplayname());
editTextName.setSelection(editTextName.getText().toString().length());
}
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
String values = editTextName.getText().toString();
if (values.trim().length() == 0)
values = tag;
if (tabLayout.getTabAt(position) != null)
Objects.requireNonNull(tabLayout.getTabAt(position)).setText(values);
tagTimeline.setDisplayname(values);
new SearchDAO(context, db).updateSearch(tagTimeline);
tl.setTagTimeline(tagTimeline);
new TimelinesDAO(context, db).updateTag(tl);
});
alertDialog = dialogBuilder.create();
alertDialog.show();
break;
2019-04-22 18:13:44 +02:00
}
2020-03-12 18:09:41 +01:00
return false;
2019-04-22 18:13:44 +02:00
});
popup.show();
}
2019-09-06 17:55:14 +02:00
private void instanceClick(Context context, ManageTimelines tl, LinearLayout tabStrip, int position) {
2019-05-25 11:29:58 +02:00
PopupMenu popup = new PopupMenu(context, tabStrip.getChildAt(position));
2020-04-09 18:57:12 +02:00
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), DB_NAME, null, Sqlite.DB_VERSION).open();
2019-05-25 11:29:58 +02:00
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
2019-09-06 17:55:14 +02:00
} else if (theme == Helper.THEME_BLACK) {
2019-05-25 11:29:58 +02:00
style = R.style.DialogBlack;
2019-09-06 17:55:14 +02:00
} else {
2019-05-25 11:29:58 +02:00
style = R.style.Dialog;
}
remoteInstance = tl.getRemoteInstance();
2019-09-06 17:55:14 +02:00
if (remoteInstance == null)
2019-05-25 11:29:58 +02:00
return;
2019-05-25 14:20:17 +02:00
currentFilter = remoteInstance.getFilteredWith();
final boolean[] changes = {false};
String title;
2019-09-06 17:55:14 +02:00
if (currentFilter == null) {
2019-05-25 14:20:17 +02:00
title = "" + context.getString(R.string.all);
2019-09-06 17:55:14 +02:00
} else {
2019-05-25 14:20:17 +02:00
title = context.getString(R.string.all);
}
MenuItem itemall = popup.getMenu().add(0, 0, Menu.NONE, title);
2020-03-12 18:09:41 +01:00
itemall.setOnMenuItemClickListener(item -> {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(context));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
2019-05-25 14:20:17 +02:00
2020-03-12 18:09:41 +01:00
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
2019-05-25 14:20:17 +02:00
return false;
2020-03-12 18:09:41 +01:00
}
});
changes[0] = true;
FragmentTransaction fragTransaction = ((MainActivity) context).getSupportFragmentManager().beginTransaction();
if (mPageReferenceMap == null)
return true;
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
if (displayStatusFragment == null)
2019-05-25 14:20:17 +02:00
return false;
2020-03-12 18:09:41 +01:00
tl.getRemoteInstance().setFilteredWith(null);
remoteInstance.setFilteredWith(null);
currentFilter = null;
new InstancesDAO(context, db).updateInstance(remoteInstance);
tl.setRemoteInstance(remoteInstance);
new TimelinesDAO(context, db).updateRemoteInstance(tl);
fragTransaction.detach(displayStatusFragment);
Bundle bundle = new Bundle();
bundle.putString("remote_instance", tl.getRemoteInstance().getHost() != null ? tl.getRemoteInstance().getHost() : "");
bundle.putString("instanceType", tl.getRemoteInstance().getType());
bundle.putInt("timelineId", tl.getId());
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
displayStatusFragment.setArguments(bundle);
fragTransaction.attach(displayStatusFragment);
fragTransaction.commit();
popup.getMenu().close();
return false;
2019-05-25 14:20:17 +02:00
});
2019-05-25 11:29:58 +02:00
java.util.List<String> tags = remoteInstance.getTags();
2019-09-06 17:55:14 +02:00
if (tags != null && tags.size() > 0) {
2019-05-25 11:29:58 +02:00
java.util.Collections.sort(tags);
2019-09-06 17:55:14 +02:00
for (String tag : tags) {
if (tag == null || tag.length() == 0)
2019-05-25 14:20:17 +02:00
continue;
2019-09-06 17:55:14 +02:00
if (currentFilter != null && currentFilter.equals(tag)) {
2019-05-25 11:29:58 +02:00
title = "" + tag;
2019-09-06 17:55:14 +02:00
} else {
2019-05-25 11:29:58 +02:00
title = tag;
}
MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title);
2020-03-12 18:09:41 +01:00
item.setOnMenuItemClickListener(item1 -> {
2019-09-06 17:55:14 +02:00
FragmentTransaction fragTransaction = ((MainActivity) context).getSupportFragmentManager().beginTransaction();
if (mPageReferenceMap == null)
2020-03-12 18:09:41 +01:00
return true;
2019-05-25 11:29:58 +02:00
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
2019-09-06 17:55:14 +02:00
if (displayStatusFragment == null)
2020-03-12 18:09:41 +01:00
return false;
tl.getRemoteInstance().setFilteredWith(tag);
remoteInstance.setFilteredWith(tag);
new InstancesDAO(context, db).updateInstance(remoteInstance);
tl.setRemoteInstance(remoteInstance);
new TimelinesDAO(context, db).updateRemoteInstance(tl);
currentFilter = tl.getRemoteInstance().getFilteredWith();
2019-05-25 11:29:58 +02:00
fragTransaction.detach(displayStatusFragment);
Bundle bundle = new Bundle();
2019-09-06 17:55:14 +02:00
bundle.putString("remote_instance", tl.getRemoteInstance().getHost() != null ? tl.getRemoteInstance().getHost() : "");
2019-05-25 11:29:58 +02:00
bundle.putString("instanceType", tl.getRemoteInstance().getType());
bundle.putInt("timelineId", tl.getId());
2020-03-12 18:09:41 +01:00
bundle.putString("currentfilter", tl.getRemoteInstance().getFilteredWith());
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE_FILTERED);
2019-05-25 11:29:58 +02:00
displayStatusFragment.setArguments(bundle);
fragTransaction.attach(displayStatusFragment);
fragTransaction.commit();
2020-03-12 18:09:41 +01:00
return false;
});
}
}
MenuItem itemadd = popup.getMenu().add(0, 0, Menu.NONE, context.getString(R.string.add_tags));
itemadd.setOnMenuItemClickListener(item -> {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(context));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
return false;
2019-05-25 11:29:58 +02:00
}
2020-03-12 18:09:41 +01:00
});
changes[0] = true;
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, style);
LayoutInflater inflater = ((MainActivity) context).getLayoutInflater();
View dialogView = inflater.inflate(R.layout.tags_instance, new LinearLayout(context), false);
dialogBuilder.setView(dialogView);
final EditText editText = dialogView.findViewById(R.id.filter_words);
if (remoteInstance.getTags() != null) {
StringBuilder valuesTag = new StringBuilder();
for (String val : remoteInstance.getTags())
valuesTag.append(val).append(" ");
editText.setText(valuesTag.toString());
editText.setSelection(editText.getText().toString().length());
}
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
String[] values = editText.getText().toString().trim().split("\\s+");
java.util.List<String> tags1 =
new ArrayList<>(Arrays.asList(values));
remoteInstance.setTags(tags1);
new InstancesDAO(context, db).updateInstance(remoteInstance);
tl.setRemoteInstance(remoteInstance);
new TimelinesDAO(context, db).updateRemoteInstance(tl);
popup.getMenu().clear();
popup.getMenu().close();
instanceClick(context, tl, tabStrip, position);
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
return false;
});
popup.setOnDismissListener(menu -> {
if (changes[0]) {
FragmentTransaction fragTransaction = ((MainActivity) context).getSupportFragmentManager().beginTransaction();
if (mPageReferenceMap == null)
return;
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
if (displayStatusFragment == null)
return;
fragTransaction.detach(displayStatusFragment);
Bundle bundle = new Bundle();
bundle.putString("remote_instance", tl.getRemoteInstance().getHost() != null ? tl.getRemoteInstance().getHost() : "");
bundle.putString("instanceType", tl.getRemoteInstance().getType());
bundle.putInt("timelineId", tl.getId());
if (currentFilter == null) {
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
} else {
bundle.putString("currentfilter", tl.getRemoteInstance().getFilteredWith());
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE_FILTERED);
}
displayStatusFragment.setArguments(bundle);
fragTransaction.attach(displayStatusFragment);
fragTransaction.commit();
2019-05-25 11:29:58 +02:00
}
});
popup.show();
}
2019-11-15 16:32:25 +01:00
public enum Type {
HOME,
DIRECT,
NOTIFICATION,
LOCAL,
PUBLIC,
ART,
PEERTUBE,
TAG,
LIST,
INSTANCE
}
2019-04-21 10:22:07 +02:00
}