mirror of
https://github.com/TrianguloY/UrlChecker.git
synced 2024-09-19 20:02:16 +02:00
parent
e21f758f26
commit
4a43fc2025
@ -1,5 +1,7 @@
|
|||||||
package com.trianguloy.urlchecker.modules.list;
|
package com.trianguloy.urlchecker.modules.list;
|
||||||
|
|
||||||
|
import static com.trianguloy.urlchecker.utilities.methods.UrlUtils.decode;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -364,11 +366,11 @@ class ClearUrlDialog extends AModuleDialog {
|
|||||||
* Idea from https://stackoverflow.com/a/6926987, but using own implementation
|
* Idea from https://stackoverflow.com/a/6926987, but using own implementation
|
||||||
*/
|
*/
|
||||||
private static String decodeURIComponent(String text) throws UnsupportedEncodingException {
|
private static String decodeURIComponent(String text) throws UnsupportedEncodingException {
|
||||||
StringBuilder result = new StringBuilder();
|
var result = new StringBuilder();
|
||||||
String[] parts = text.split("\\+");
|
var parts = text.split("\\+");
|
||||||
for (String part : parts) {
|
for (var part : parts) {
|
||||||
if (result.length() != 0) result.append('+');
|
if (result.length() != 0) result.append('+');
|
||||||
result.append(URLDecoder.decode(part, "UTF-8"));
|
result.append(decode(part));
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.trianguloy.urlchecker.modules.list;
|
package com.trianguloy.urlchecker.modules.list;
|
||||||
|
|
||||||
|
import static com.trianguloy.urlchecker.utilities.methods.UrlUtils.decode;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@ -168,7 +170,7 @@ class PatternDialog extends AModuleDialog {
|
|||||||
|
|
||||||
// decode if required
|
// decode if required
|
||||||
if (data.optBoolean("decode")) {
|
if (data.optBoolean("decode")) {
|
||||||
message.newUrl = URLDecoder.decode(message.newUrl);
|
message.newUrl = decode(message.newUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// automatic? apply
|
// automatic? apply
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.trianguloy.urlchecker.modules.list;
|
package com.trianguloy.urlchecker.modules.list;
|
||||||
|
|
||||||
|
import static com.trianguloy.urlchecker.utilities.methods.UrlUtils.decode;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@ -197,12 +199,7 @@ class RemoveQueriesDialog extends AModuleDialog {
|
|||||||
public String getQueryValue(int index) {
|
public String getQueryValue(int index) {
|
||||||
String[] split = queries.get(index).split("=");
|
String[] split = queries.get(index).split("=");
|
||||||
if (split.length == 1) return "";
|
if (split.length == 1) return "";
|
||||||
try {
|
return decode(split[1]);
|
||||||
return URLDecoder.decode(split[1]);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// can't decode, return it directly
|
|
||||||
return split[1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,37 +9,24 @@ import android.widget.Toast;
|
|||||||
import com.trianguloy.urlchecker.R;
|
import com.trianguloy.urlchecker.R;
|
||||||
import com.trianguloy.urlchecker.utilities.wrappers.IntentApp;
|
import com.trianguloy.urlchecker.utilities.wrappers.IntentApp;
|
||||||
|
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/** Static utilities related to urls */
|
||||||
* Static utilities related to urls
|
|
||||||
*/
|
|
||||||
public interface UrlUtils {
|
public interface UrlUtils {
|
||||||
|
|
||||||
/**
|
/** Returns an intent that will open the given [url], with an optional [intentApp] */
|
||||||
* Returns an intent that will open the given url, with an optional package
|
|
||||||
*
|
|
||||||
* @param url the url that will be opened
|
|
||||||
* @param intentApp the intentApp that will be opened, null to let android choose
|
|
||||||
* @return the converted intent
|
|
||||||
*/
|
|
||||||
static Intent getViewIntent(String url, IntentApp intentApp) {
|
static Intent getViewIntent(String url, IntentApp intentApp) {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
var intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||||
if (intentApp != null) intent.setComponent(intentApp.getComponent());
|
if (intentApp != null) intent.setComponent(intentApp.getComponent());
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Opens an [url] removing this app from the chooser */
|
||||||
* Opens an url removing this app from the chooser
|
|
||||||
*
|
|
||||||
* @param url url to open
|
|
||||||
* @param cntx base context
|
|
||||||
*/
|
|
||||||
static void openUrlRemoveThis(String url, Context cntx) {
|
static void openUrlRemoveThis(String url, Context cntx) {
|
||||||
|
|
||||||
// get intents that can open the url
|
// get intents that can open the url
|
||||||
List<Intent> intents = new ArrayList<>();
|
var intents = new ArrayList<Intent>();
|
||||||
for (var pack : IntentApp.getOtherPackages(getViewIntent(url, null), cntx)) {
|
for (var pack : IntentApp.getOtherPackages(getViewIntent(url, null), cntx)) {
|
||||||
intents.add(getViewIntent(url, pack));
|
intents.add(getViewIntent(url, pack));
|
||||||
}
|
}
|
||||||
@ -51,10 +38,21 @@ public interface UrlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create chooser
|
// create chooser
|
||||||
Intent chooserIntent = Intent.createChooser(intents.remove(0), cntx.getString(R.string.title_choose));
|
var chooserIntent = Intent.createChooser(intents.remove(0), cntx.getString(R.string.title_choose));
|
||||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[0]));
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[0]));
|
||||||
|
|
||||||
// open
|
// open
|
||||||
PackageUtils.startActivity(chooserIntent, R.string.toast_noBrowser, cntx);
|
PackageUtils.startActivity(chooserIntent, R.string.toast_noBrowser, cntx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Calls URLDecoder.decode but returns the input string if the decoding failed */
|
||||||
|
static String decode(String string) {
|
||||||
|
try {
|
||||||
|
return URLDecoder.decode(string, "UTF-8");
|
||||||
|
} catch (Exception e) {
|
||||||
|
// can't decode, just leave it
|
||||||
|
e.printStackTrace();
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user