Fixes #457 - Add warning when there is an error with the regular expression for filtering

This commit is contained in:
stom79 2018-05-13 15:50:48 +02:00
parent 003d583e00
commit 5d5c7a86f5
3 changed files with 25 additions and 2 deletions

View File

@ -25,7 +25,6 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.AsyncTask;
@ -45,6 +44,8 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.SwitchCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.Gravity;
import android.view.LayoutInflater;
@ -74,6 +75,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveInstanceAsyncTask;
@ -1021,6 +1023,27 @@ public abstract class BaseMainActivity extends BaseActivity
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.filter_regex, null);
dialogBuilder.setView(dialogView);
final EditText editText = dialogView.findViewById(R.id.filter_regex);
Toast alertRegex = Toast.makeText(BaseMainActivity.this, R.string.alert_regex, Toast.LENGTH_LONG);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
try {
//noinspection ResultOfMethodCallIgnored
Pattern.compile("(" + s.toString() + ")", Pattern.CASE_INSENSITIVE);
}catch (Exception e){
if( !alertRegex.getView().isShown()){
alertRegex.show();
}
}
}
});
if( show_filtered != null) {
editText.setText(show_filtered);
editText.setSelection(editText.getText().toString().length());

View File

@ -419,7 +419,6 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
}else {
changeDrawableColor(getApplicationContext(), R.drawable.ic_lock_outline,R.color.mastodonC4);
}
String urlHeader = account.getHeader();
if (urlHeader.startsWith("/")) {
urlHeader = Helper.getLiveInstanceWithProtocol(ShowAccountActivity.this) + account.getHeader();

View File

@ -536,6 +536,7 @@
<string name="set_compact_mode">Compact mode</string>
<string name="set_share_details">Add toot details when sharing</string>
<string name="support_the_app_on_liberapay">Support the app on Liberapay</string>
<string name="alert_regex">There is an error in the regular expression!</string>
<string-array translatable="false" name="proxy_type_choice">
<item>HTTP</item>
<item>SOCKS</item>