mirror of
https://github.com/TrianguloY/UrlChecker.git
synced 2024-09-20 04:12:14 +02:00
simplified RemoveQueriesModule
This commit is contained in:
parent
1e3b44c12f
commit
5e9b39a846
@ -7,10 +7,10 @@ import com.trianguloy.urlchecker.modules.list.DebugModule;
|
|||||||
import com.trianguloy.urlchecker.modules.list.HistoryModule;
|
import com.trianguloy.urlchecker.modules.list.HistoryModule;
|
||||||
import com.trianguloy.urlchecker.modules.list.OpenModule;
|
import com.trianguloy.urlchecker.modules.list.OpenModule;
|
||||||
import com.trianguloy.urlchecker.modules.list.PatternModule;
|
import com.trianguloy.urlchecker.modules.list.PatternModule;
|
||||||
|
import com.trianguloy.urlchecker.modules.list.RemoveQueriesModule;
|
||||||
import com.trianguloy.urlchecker.modules.list.StatusModule;
|
import com.trianguloy.urlchecker.modules.list.StatusModule;
|
||||||
import com.trianguloy.urlchecker.modules.list.TextInputModule;
|
import com.trianguloy.urlchecker.modules.list.TextInputModule;
|
||||||
import com.trianguloy.urlchecker.modules.list.VirusTotalModule;
|
import com.trianguloy.urlchecker.modules.list.VirusTotalModule;
|
||||||
import com.trianguloy.urlchecker.modules.list.RemoveQueriesModule;
|
|
||||||
import com.trianguloy.urlchecker.utilities.GenericPref;
|
import com.trianguloy.urlchecker.utilities.GenericPref;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -31,9 +31,9 @@ public class ModuleManager {
|
|||||||
toggleableModules.add(new StatusModule());
|
toggleableModules.add(new StatusModule());
|
||||||
toggleableModules.add(new VirusTotalModule());
|
toggleableModules.add(new VirusTotalModule());
|
||||||
toggleableModules.add(new ClearUrlModule());
|
toggleableModules.add(new ClearUrlModule());
|
||||||
|
toggleableModules.add(new RemoveQueriesModule());
|
||||||
toggleableModules.add(new PatternModule());
|
toggleableModules.add(new PatternModule());
|
||||||
toggleableModules.add(new DebugModule());
|
toggleableModules.add(new DebugModule());
|
||||||
toggleableModules.add(new RemoveQueriesModule());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static AModuleData bottomModule = new OpenModule();
|
public final static AModuleData bottomModule = new OpenModule();
|
||||||
|
@ -12,13 +12,10 @@ import com.trianguloy.urlchecker.modules.AModuleData;
|
|||||||
import com.trianguloy.urlchecker.modules.AModuleDialog;
|
import com.trianguloy.urlchecker.modules.AModuleDialog;
|
||||||
import com.trianguloy.urlchecker.modules.DescriptionConfig;
|
import com.trianguloy.urlchecker.modules.DescriptionConfig;
|
||||||
|
|
||||||
// Importing required classes
|
/**
|
||||||
|
* This module removes queries "?foo=bar" from an url
|
||||||
import java.net.URL;
|
* Originally made by PabloOQ
|
||||||
import java.net.MalformedURLException;
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class RemoveQueriesModule extends AModuleData {
|
public class RemoveQueriesModule extends AModuleData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,7 +46,9 @@ class RemoveQueriesDialog extends AModuleDialog implements View.OnClickListener
|
|||||||
|
|
||||||
private String cleared = null;
|
private String cleared = null;
|
||||||
|
|
||||||
public RemoveQueriesDialog(MainDialog dialog) { super(dialog); }
|
public RemoveQueriesDialog(MainDialog dialog) {
|
||||||
|
super(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLayoutId() {
|
public int getLayoutId() {
|
||||||
@ -65,58 +64,30 @@ class RemoveQueriesDialog extends AModuleDialog implements View.OnClickListener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewUrl(String url) {
|
public void onNewUrl(String url) {
|
||||||
info.setText("");
|
// clear
|
||||||
cleared = url;
|
// an uri is defined as [scheme:][//authority][path][?query][#fragment]
|
||||||
remove.setEnabled(false);
|
// in order to remove the query, we need to remove everything between the '?' (included) and the '#' if present (excluded)
|
||||||
URL urlObject = null;
|
// we need to match a '?' followed by anything except a '#', and remove it
|
||||||
try {
|
// this allows us to work with any string, even with non-standard urls
|
||||||
urlObject = new URL(url);
|
cleared = url.replaceAll("\\?[^#]*", "");
|
||||||
|
|
||||||
//retrieve all components
|
if (!cleared.equals(url)) {
|
||||||
String protocol = urlObject.getProtocol();
|
// query present, notify
|
||||||
protocol = protocol + ":";
|
|
||||||
String authority = urlObject.getAuthority();
|
|
||||||
authority = authority != null ? "//" + authority : "";
|
|
||||||
String path = urlObject.getPath();
|
|
||||||
String ref = urlObject.getRef();
|
|
||||||
ref = ref != null ? "#" + ref : "";
|
|
||||||
|
|
||||||
//create the url but without queries
|
|
||||||
cleared = protocol + authority + path + ref;
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// url changed, enable button
|
|
||||||
if (urlObject != null && urlObject.getQuery() != null) {
|
|
||||||
remove.setEnabled(true);
|
remove.setEnabled(true);
|
||||||
info.setText(R.string.mRemove_found);
|
info.setText(R.string.mRemove_found);
|
||||||
setColor(R.color.warning);
|
info.setBackgroundColor(getActivity().getResources().getColor(R.color.warning));
|
||||||
}
|
} else {
|
||||||
|
// no query present, nothing to notify
|
||||||
// nothing found
|
remove.setEnabled(false);
|
||||||
if (info.getText().length() == 0) {
|
|
||||||
info.setText(R.string.mRemove_noQueries);
|
info.setText(R.string.mRemove_noQueries);
|
||||||
setColor(R.color.transparent);
|
info.setBackgroundColor(getActivity().getResources().getColor(R.color.transparent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// pressed the fix button
|
// pressed the apply button
|
||||||
if (cleared != null) setUrl(cleared);
|
if (cleared != null) setUrl(cleared);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------- utils -------------------
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility to set the info background color. Manages color importance
|
|
||||||
*/
|
|
||||||
private void setColor(int color) {
|
|
||||||
if (info.getTag() != null && info.getTag().equals(R.color.bad) && color == R.color.warning) return; // keep bad instead of replacing with warning
|
|
||||||
info.setTag(color);
|
|
||||||
info.setBackgroundColor(getActivity().getResources().getColor(color));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -112,8 +112,7 @@ This module can\'t be disabled."</string>
|
|||||||
<string name="mClear_error">An error occurred while checking rules</string>
|
<string name="mClear_error">An error occurred while checking rules</string>
|
||||||
|
|
||||||
<string name="mRemove_name">Remove Queries</string>
|
<string name="mRemove_name">Remove Queries</string>
|
||||||
<string name="mRemove_desc">This module removes all queries from the url.</string>
|
<string name="mRemove_desc">This module removes all queries from the url.\nThanks to PabloOQ for the idea and original implementation!</string>
|
||||||
<string name="mRemove_remove">Remove</string>
|
|
||||||
<string name="mRemove_found">Queries found</string>
|
<string name="mRemove_found">Queries found</string>
|
||||||
<string name="mRemove_noQueries">No queries</string>
|
<string name="mRemove_noQueries">No queries</string>
|
||||||
<string name="mRemove_apply">Apply</string>
|
<string name="mRemove_apply">Apply</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user