mirror of
https://github.com/TrianguloY/UrlChecker.git
synced 2024-09-19 20:02:16 +02:00
commit
71ed251579
@ -10,6 +10,7 @@ import com.trianguloy.urlchecker.modules.list.PatternModule;
|
||||
import com.trianguloy.urlchecker.modules.list.StatusModule;
|
||||
import com.trianguloy.urlchecker.modules.list.TextInputModule;
|
||||
import com.trianguloy.urlchecker.modules.list.VirusTotalModule;
|
||||
import com.trianguloy.urlchecker.modules.list.RemoveQueriesModule;
|
||||
import com.trianguloy.urlchecker.utilities.GenericPref;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -32,6 +33,7 @@ public class ModuleManager {
|
||||
toggleableModules.add(new ClearUrlModule());
|
||||
toggleableModules.add(new PatternModule());
|
||||
toggleableModules.add(new DebugModule());
|
||||
toggleableModules.add(new RemoveQueriesModule());
|
||||
}
|
||||
|
||||
public final static AModuleData bottomModule = new OpenModule();
|
||||
|
@ -0,0 +1,122 @@
|
||||
package com.trianguloy.urlchecker.modules.list;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.trianguloy.urlchecker.R;
|
||||
import com.trianguloy.urlchecker.activities.ConfigActivity;
|
||||
import com.trianguloy.urlchecker.dialogs.MainDialog;
|
||||
import com.trianguloy.urlchecker.modules.AModuleConfig;
|
||||
import com.trianguloy.urlchecker.modules.AModuleData;
|
||||
import com.trianguloy.urlchecker.modules.AModuleDialog;
|
||||
import com.trianguloy.urlchecker.modules.DescriptionConfig;
|
||||
|
||||
// Importing required classes
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
|
||||
|
||||
public class RemoveQueriesModule extends AModuleData {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "removeQueries";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getName() {
|
||||
return R.string.mRemove_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AModuleDialog getDialog(MainDialog cntx) {
|
||||
return new RemoveQueriesDialog(cntx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AModuleConfig getConfig(ConfigActivity cntx) {
|
||||
return new DescriptionConfig(R.string.mRemove_desc);
|
||||
}
|
||||
}
|
||||
|
||||
class RemoveQueriesDialog extends AModuleDialog implements View.OnClickListener {
|
||||
|
||||
private TextView info;
|
||||
private Button remove;
|
||||
|
||||
private String cleared = null;
|
||||
|
||||
public RemoveQueriesDialog(MainDialog dialog) { super(dialog); }
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return R.layout.dialog_removequeries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitialize(View views) {
|
||||
info = views.findViewById(R.id.text);
|
||||
remove = views.findViewById(R.id.fix);
|
||||
remove.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewUrl(String url) {
|
||||
info.setText("");
|
||||
cleared = url;
|
||||
remove.setEnabled(false);
|
||||
URL urlObject = null;
|
||||
try {
|
||||
urlObject = new URL(url);
|
||||
|
||||
//retrieve all components
|
||||
String protocol = urlObject.getProtocol();
|
||||
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);
|
||||
info.setText(R.string.mRemove_found);
|
||||
setColor(R.color.warning);
|
||||
}
|
||||
|
||||
// nothing found
|
||||
if (info.getText().length() == 0) {
|
||||
info.setText(R.string.mRemove_noQueries);
|
||||
setColor(R.color.transparent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// pressed the fix button
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
21
app/src/main/res/layout/dialog_removequeries.xml
Normal file
21
app/src/main/res/layout/dialog_removequeries.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/fix"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:text="@string/mRemove_apply" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
@ -111,4 +111,10 @@ This module can\'t be disabled."</string>
|
||||
<string name="mClear_toggleVerbose">Enable verbose info for the matching process</string>
|
||||
<string name="mClear_error">An error occurred while checking rules</string>
|
||||
|
||||
<string name="mRemove_name">Remove Queries</string>
|
||||
<string name="mRemove_desc">This module removes all queries from the url.</string>
|
||||
<string name="mRemove_remove">Remove</string>
|
||||
<string name="mRemove_found">Queries found</string>
|
||||
<string name="mRemove_noQueries">No queries</string>
|
||||
<string name="mRemove_apply">Apply</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user