0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-19 20:02:16 +02:00

ACTIVITY_NEW_TASK=on ACTIVITY_EXCLUDE_FROM_RECENTS=off by default

should fix #281
This commit is contained in:
TrianguloY 2023-11-27 00:10:36 +01:00
parent 2f431da657
commit 5cd491d923
6 changed files with 48 additions and 114 deletions

View File

@ -28,6 +28,9 @@
<activity android:name=".activities.TutorialActivity" />
<activity
android:name=".dialogs.MainDialog"
android:excludeFromRecents="true"
android:clearTaskOnLaunch="true"
android:launchMode="singleInstance"
android:exported="true"
android:noHistory="true"
android:windowSoftInputMode="adjustResize|stateHidden"

View File

@ -5,7 +5,6 @@ import android.animation.ValueAnimator;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
@ -230,7 +229,7 @@ public class MainDialog extends Activity {
onNewUrl(new UrlData(links_array[which]));
dialog.dismiss();
})
.setOnCancelListener(o -> this.finish())
.setOnCancelListener(o -> finish())
.show();
}
}
@ -346,18 +345,6 @@ public class MainDialog extends Activity {
}
}
/**
* Remove from recent programmatically (https://stackoverflow.com/a/47688494)
*/
@Override
public void finish() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
finishAndRemoveTask();
} else {
super.finish();
}
}
// ------------------- drawer module -------------------
/**

View File

@ -57,7 +57,7 @@ public abstract class AModuleDialog implements Fragment {
/**
* @return this activity context
*/
protected final Activity getActivity() {
public final Activity getActivity() {
return dialog;
}

View File

@ -1,8 +1,5 @@
package com.trianguloy.urlchecker.modules.companions;
import static com.trianguloy.urlchecker.utilities.methods.JavaUtils.valueOrDefault;
import android.app.Activity;
import android.content.Intent;
import com.trianguloy.urlchecker.modules.AModuleDialog;
@ -11,7 +8,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
/**
* Represents intent flags
@ -20,6 +16,14 @@ import java.util.TreeSet;
*/
public class Flags {
/**
* Default flags (name, on/off). Default visibility is 'hidden'
*/
public static final Map<String, Boolean> DEFAULT_STATE = Map.of(
"ACTIVITY_NEW_TASK", true,
"ACTIVITY_EXCLUDE_FROM_RECENTS", false
);
// ------------------- static -------------------
// https://github.com/MuntashirAkon/AppManager/blob/19782da4c8556c817ba5795554a1cc21f38af13a/app/src/main/java/io/github/muntashirakon/AppManager/intercept/ActivityInterceptor.java#L92
@ -99,10 +103,6 @@ public class Flags {
return flagsSetToHex(flags);
}
public Set<String> getFlagsAsSet() {
return new TreeSet<>(flags); // TreeSet to have the entries sorted
}
/**
* Replaces the stored flags with the received hex
*/
@ -110,15 +110,6 @@ public class Flags {
this.flags = hexFlagsToSet(hex);
}
/**
* Replaces the stored flags with the received list
*/
public void setFlags(Set<String> names) {
Set<String> res = new HashSet<>(names);
res.retainAll(compatibleFlags.keySet());
this.flags = res;
}
/**
* Sets the flag to the received boolean
*/
@ -134,52 +125,6 @@ public class Flags {
}
}
/**
* Add flags by applying a mask
*/
public void addFlags(int hex) {
flags.addAll(hexFlagsToSet(hex));
}
/**
* Add a list of flags based on its name
*/
public void addFlags(Set<String> flags) {
this.flags.addAll(flags);
}
/**
* Add a flag based on its name
*/
public boolean addFlag(String name) {
if (compatibleFlags.containsKey(name)) {
return flags.add(name);
} else {
return false;
}
}
/**
* Remove flags by applying a mask
*/
public boolean removeFlags(int hex) {
return flags.removeAll(hexFlagsToSet(hex));
}
/**
* Remove a list of flags based on its name
*/
public boolean removeFlags(Set<String> flags) {
return this.flags.removeAll(flags);
}
/**
* Remove a flag based on its name
*/
public boolean removeFlag(String name) {
return flags.remove(name);
}
// ------------------- utils -------------------
/**
@ -202,8 +147,9 @@ public class Flags {
private static int flagsSetToHex(Set<String> set) {
int hex = 0x00000000;
for (var flag : set) {
if (compatibleFlags.containsKey(flag)) {
hex = hex | compatibleFlags.get(flag);
var flagHex = compatibleFlags.get(flag);
if (flagHex != null) {
hex = hex | flagHex;
}
}
return hex;
@ -238,26 +184,20 @@ public class Flags {
}
/**
* Retrieves the flags from GlobalData, if it is not defined it will return null
* Applies the custom (or default) flags to an intent
*/
public static Integer getGlobalFlagsNullable(AModuleDialog instance) {
return toInteger(instance.getData(DATA_FLAGS));
}
public static void applyGlobalFlags(Intent intent, AModuleDialog instance) {
var flags = toInteger(instance.getData(DATA_FLAGS));
if (flags == null) {
// the flags module is disabled, apply the default
var computedFlags = new Flags(intent.getFlags());
for (var flag_state : DEFAULT_STATE.entrySet()) {
computedFlags.setFlag(flag_state.getKey(), flag_state.getValue());
}
flags = computedFlags.getFlagsAsInt();
}
/**
* Loads the flags from GlobalData, if none were found it gets the flags from the intent that
* started this activity
*/
public static int getGlobalFlagsNonNull(AModuleDialog instance, Activity cntx) {
return getGlobalFlagsOrDefault(instance, cntx.getIntent().getFlags());
}
/**
* Loads the flags from GlobalData, if none were found it gets the flags from default
* Can be used by other modules
*/
public static int getGlobalFlagsOrDefault(AModuleDialog instance, int defaultFlags) {
return valueOrDefault(toInteger(instance.getData(DATA_FLAGS)), defaultFlags);
intent.setFlags(flags);
}
/**

View File

@ -3,7 +3,6 @@ package com.trianguloy.urlchecker.modules.list;
import static com.trianguloy.urlchecker.utilities.methods.JavaUtils.valueOrDefault;
import android.app.AlertDialog;
import android.content.Context;
import android.text.Editable;
import android.view.View;
import android.view.ViewGroup;
@ -23,7 +22,6 @@ import com.trianguloy.urlchecker.modules.AModuleDialog;
import com.trianguloy.urlchecker.modules.companions.Flags;
import com.trianguloy.urlchecker.url.UrlData;
import com.trianguloy.urlchecker.utilities.Enums;
import com.trianguloy.urlchecker.utilities.generics.GenericPref;
import com.trianguloy.urlchecker.utilities.methods.AndroidUtils;
import com.trianguloy.urlchecker.utilities.methods.Inflater;
import com.trianguloy.urlchecker.utilities.methods.JavaUtils;
@ -47,9 +45,6 @@ import java.util.TreeSet;
*/
public class FlagsModule extends AModuleData {
public static GenericPref.Str DEFAULTFLAGS_PREF(Context cntx) {
return new GenericPref.Str("flagsEditor_defaultFlags", null, cntx);
}
public static final String DEFAULT_GROUP = "default";
@ -195,6 +190,11 @@ class FlagsDialog extends AModuleDialog {
} catch (JSONException ignored) {
}
}
} else {
// default flags
for (var flag_state : Flags.DEFAULT_STATE.entrySet()) {
flagsStatePref.put(flag_state.getKey(), flag_state.getValue() ? FlagsConfig.FlagState.ON : FlagsConfig.FlagState.OFF);
}
}
// If it is not in shownFlags it must be in hiddenFlags
@ -378,18 +378,24 @@ class FlagsConfig extends AModuleConfig {
// Load preferences from settings
Boolean showValue = null;
Integer stateValue = null;
FlagState stateValue = null;
// Get current preferences
if (oldPref != null) {
JSONObject flagPref;
try {
flagPref = oldPref.getJSONObject(flag);
showValue = flagPref.getBoolean("show");
stateValue = flagPref.getInt("state");
stateValue = Enums.toEnum(FlagState.class, flagPref.getInt("state"));
} catch (JSONException ignored) {
}
} else {
var defaultState = Flags.DEFAULT_STATE.get(flag);
if (defaultState != null) {
stateValue = defaultState ? FlagState.ON : FlagState.OFF;
showValue = false;
}
}
flagState.setCurrentState(Enums.toEnum(FlagState.class, valueOrDefault(stateValue, FlagState.AUTO.id)));
flagState.setCurrentState(valueOrDefault(stateValue, FlagState.AUTO));
var show = entryView.<ImageButton>findViewById(R.id.show);
show.setTag(valueOrDefault(showValue, false));
AndroidUtils.toggleableListener(show,
@ -441,8 +447,10 @@ class FlagsConfig extends AModuleConfig {
private void resetFlags(ViewGroup vg) {
// Set everything to default values
for (int i = 0; i < vg.getChildCount(); i++) {
View v = vg.getChildAt(i);
v.<CycleImageButton<FlagState>>findViewById(R.id.state).setCurrentState(FlagState.AUTO);
var v = vg.getChildAt(i);
var defaultState = Flags.DEFAULT_STATE.get(v.<TextView>findViewById(R.id.text).getText().toString());
v.<CycleImageButton<FlagState>>findViewById(R.id.state).setCurrentState(defaultState == null ? FlagState.AUTO : defaultState ? FlagState.ON : FlagState.OFF);
var visible = v.<ImageButton>findViewById(R.id.show);
visible.setImageResource(R.drawable.hide);
visible.setTag(Boolean.FALSE);

View File

@ -241,11 +241,8 @@ class OpenDialog extends AModuleDialog {
// incognito
incognito.apply(intent);
// Get flags from global data (probably set by flags module, if active)
var flags = Flags.getGlobalFlagsNullable(this);
if (flags != null) {
intent.setFlags(flags);
}
// apply flags from global data (probably set by flags module, if active) or by default
Flags.applyGlobalFlags(intent, this);
// rejection detector: mark as open
rejectionDetector.markAsOpen(getUrl(), chosen);
@ -278,7 +275,6 @@ class OpenDialog extends AModuleDialog {
// share intent
var chooser = Intent.createChooser(sendIntent, getActivity().getString(R.string.mOpen_share));
chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // to still show after finishAndRemoveTask
PackageUtils.startActivity(
chooser,
R.string.mOpen_noapps,