Issue #43 - Filter home timeline with regex
This commit is contained in:
parent
03fa84a09a
commit
a29fcbde6b
|
@ -54,6 +54,7 @@ import android.support.v7.widget.Toolbar;
|
|||
import android.view.MenuItem;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
@ -144,6 +145,7 @@ public abstract class BaseMainActivity extends AppCompatActivity
|
|||
private Intent streamingIntent;
|
||||
public static String lastHomeId = null, lastNotificationId = null;
|
||||
boolean notif_follow, notif_add, notif_mention, notif_share, show_boosts, show_replies;
|
||||
String show_filtered;
|
||||
private AppBarLayout appBar;
|
||||
private static boolean activityPaused;
|
||||
|
||||
|
@ -330,11 +332,17 @@ public abstract class BaseMainActivity extends AppCompatActivity
|
|||
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);
|
||||
|
||||
show_boosts = sharedpreferences.getBoolean(Helper.SET_SHOW_BOOSTS, true);
|
||||
show_replies = sharedpreferences.getBoolean(Helper.SET_SHOW_REPLIES, true);
|
||||
show_filtered = sharedpreferences.getString(Helper.SET_FILTER_REGEX_HOME, null);
|
||||
itemShowBoosts.setChecked(show_boosts);
|
||||
itemShowReplies.setChecked(show_replies);
|
||||
if( show_filtered != null && show_filtered.length() > 0){
|
||||
itemFilter.setTitle(show_filtered);
|
||||
}
|
||||
|
||||
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(PopupMenu menu) {
|
||||
|
@ -357,21 +365,42 @@ public abstract class BaseMainActivity extends AppCompatActivity
|
|||
return false;
|
||||
}
|
||||
});
|
||||
final SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_show_boosts:
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
|
||||
show_boosts = !show_boosts;
|
||||
editor.putBoolean(Helper.SET_SHOW_BOOSTS, show_boosts);
|
||||
itemShowBoosts.setChecked(show_boosts);
|
||||
editor.apply();
|
||||
break;
|
||||
case R.id.action_show_replies:
|
||||
editor = sharedpreferences.edit();
|
||||
show_replies = !show_replies;
|
||||
editor.putBoolean(Helper.SET_SHOW_REPLIES, show_replies);
|
||||
itemShowReplies.setChecked(show_replies);
|
||||
editor.apply();
|
||||
break;
|
||||
case R.id.action_filter:
|
||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BaseMainActivity.this);
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.filter_regex, null);
|
||||
dialogBuilder.setView(dialogView);
|
||||
final EditText editText = dialogView.findViewById(R.id.filter_regex);
|
||||
if( show_filtered != null) {
|
||||
editText.setText(show_filtered);
|
||||
editText.setSelection(editText.getText().toString().length());
|
||||
}
|
||||
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
itemFilter.setTitle(editText.getText().toString().trim());
|
||||
editor.putString(Helper.SET_FILTER_REGEX_HOME, editText.getText().toString().trim());
|
||||
editor.apply();
|
||||
}
|
||||
});
|
||||
AlertDialog alertDialog = dialogBuilder.create();
|
||||
alertDialog.show();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -283,6 +283,20 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
Status status = statuses.get(position);
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
int HIDDEN_STATUS = 0;
|
||||
String filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_HOME, null);
|
||||
|
||||
if( filter != null && filter.length() > 0){
|
||||
Pattern filterPattern = Pattern.compile("(" + filter + ")");
|
||||
String content;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
|
||||
else
|
||||
//noinspection deprecation
|
||||
content = Html.fromHtml(status.getContent()).toString();
|
||||
Matcher matcher = filterPattern.matcher(content);
|
||||
if(matcher.find())
|
||||
return HIDDEN_STATUS;
|
||||
}
|
||||
if (status.getReblog() != null && !sharedpreferences.getBoolean(Helper.SET_SHOW_BOOSTS, true))
|
||||
return HIDDEN_STATUS;
|
||||
else if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null") && !sharedpreferences.getBoolean(Helper.SET_SHOW_REPLIES, true)) {
|
||||
|
|
|
@ -239,6 +239,9 @@ public class Helper {
|
|||
public static final String SET_NOTIF_ADD_FILTER = "set_notif_follow_add_filter";
|
||||
public static final String SET_NOTIF_MENTION_FILTER = "set_notif_follow_mention_filter";
|
||||
public static final String SET_NOTIF_SHARE_FILTER = "set_notif_follow_share_filter";
|
||||
public static final String SET_FILTER_REGEX_HOME = "set_filter_regex_home";
|
||||
public static final String SET_FILTER_REGEX_LOCAL = "set_filter_regex_local";
|
||||
public static final String SET_FILTER_REGEX_PUBLIC = "set_filter_regex_public";
|
||||
|
||||
public static final String SET_NOTIF_VALIDATION = "set_share_validation";
|
||||
public static final String SET_NOTIF_VALIDATION_FAV = "set_share_validation_fav";
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<EditText
|
||||
android:id="@+id/filter_regex"
|
||||
android:inputType="text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/filter_regex"
|
||||
android:maxLines="1"
|
||||
/>
|
||||
</LinearLayout>
|
|
@ -15,4 +15,8 @@
|
|||
android:title="@string/show_replies"
|
||||
app:actionViewClass="android.widget.CheckBox"
|
||||
app:showAsAction="always" />
|
||||
<item
|
||||
android:id="@+id/action_filter"
|
||||
app:showAsAction="always"
|
||||
android:title="@string/filter_regex" />
|
||||
</menu>
|
||||
|
|
|
@ -431,4 +431,5 @@
|
|||
<string name="insert_emoji">Emoji einfügen</string>
|
||||
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
||||
<string name="live_notif">Live notifications</string>
|
||||
<string name="filter_regex">Mit regulären Ausdrücken filtern</string>
|
||||
</resources>
|
||||
|
|
|
@ -438,4 +438,5 @@
|
|||
<string name="insert_emoji">Insérer un émoji</string>
|
||||
<string name="no_emoji">L\'application n\'a pas encore collecté d\'emojis personnalisés</string>
|
||||
<string name="live_notif">Notifications en direct</string>
|
||||
<string name="filter_regex">Filtrer avec une expression rationnelle</string>
|
||||
</resources>
|
||||
|
|
|
@ -435,4 +435,5 @@
|
|||
<string name="insert_emoji">Emoji toevoegen</string>
|
||||
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
||||
<string name="live_notif">Live notifications</string>
|
||||
<string name="filter_regex">Wegfilteren met reguliere expressies</string>
|
||||
</resources>
|
||||
|
|
|
@ -437,4 +437,5 @@
|
|||
<string name="insert_emoji">Inserir Emoji</string>
|
||||
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
||||
<string name="live_notif">Live notifications</string>
|
||||
<string name="filter_regex">Filtrar com uma expressão regular</string>
|
||||
</resources>
|
||||
|
|
|
@ -443,4 +443,6 @@
|
|||
<string name="thanks_text_dev">
|
||||
Thank you to:
|
||||
</string>
|
||||
|
||||
<string name="filter_regex">Filter out by regular expressions</string>
|
||||
</resources>
|
Loading…
Reference in New Issue