Small improvements, refactoring

pull/162/head
M66B 5 years ago
parent 0d6edc2bfb
commit e6e0a00767

@ -4201,7 +4201,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return;
}
String keyword = Helper.sanitizeKeyword(etKeyword.getText().toString());
String keyword = MessageHelper.sanitizeKeyword(etKeyword.getText().toString());
if (!TextUtils.isEmpty(keyword)) {
Bundle args = new Bundle();
args.putLong("id", id);

@ -407,11 +407,10 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
if (keywords)
term = new OrTerm(term, new FlagTerm(
new Flags(Helper.sanitizeKeyword(search)), true));
new Flags(MessageHelper.sanitizeKeyword(search)), true));
return state.ifolder.search(term);
}
} catch (MessagingException ex) {
Log.e(ex);
return ex;

@ -32,7 +32,6 @@ import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.Menu;
@ -380,12 +379,13 @@ public class FragmentSetup extends FragmentBase {
super.onResume();
// Doze
boolean ignoring = true;
Boolean ignoring = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
if (intent.resolveActivity(getContext().getPackageManager()) != null) {
PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
ignoring = (pm != null && pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID));
ignoring = Helper.isIgnoringOptimizations(getContext());
if (ignoring == null)
ignoring = true;
}
}

@ -40,6 +40,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcel;
import android.os.PowerManager;
import android.text.Spannable;
import android.text.Spanned;
import android.text.format.DateUtils;
@ -178,6 +179,20 @@ public class Helper {
return pm.hasSystemFeature(PackageManager.FEATURE_PRINTING);
}
static Boolean isIgnoringOptimizations(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (pm == null)
return null;
return pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID);
}
return null;
}
static boolean isPlayStoreInstall() {
return BuildConfig.PLAY_STORE_RELEASE;
}
// View
static Intent getChooser(Context context, Intent intent) {
@ -522,6 +537,20 @@ public class Helper {
}
}
static void linkPro(final TextView tv) {
if (ActivityBilling.isPro(tv.getContext()) && !BuildConfig.DEBUG)
hide(tv);
else {
tv.getPaint().setUnderlineText(true);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv.getContext().startActivity(new Intent(tv.getContext(), ActivityBilling.class));
}
});
}
}
// Files
static String sanitizeFilename(String name) {
@ -796,49 +825,6 @@ public class Helper {
// Miscellaneous
static String sanitizeKeyword(String keyword) {
// https://tools.ietf.org/html/rfc3501
StringBuilder sb = new StringBuilder();
for (int i = 0; i < keyword.length(); i++) {
// flag-keyword = atom
// atom = 1*ATOM-CHAR
// ATOM-CHAR = <any CHAR except atom-specials>
char kar = keyword.charAt(i);
// atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards / quoted-specials / resp-specials
if (kar == '(' || kar == ')' || kar == '{' || kar == ' ' || Character.isISOControl(kar))
continue;
// list-wildcards = "%" / "*"
if (kar == '%' || kar == '*')
continue;
// quoted-specials = DQUOTE / "\"
if (kar == '"' || kar == '\\')
continue;
// resp-specials = "]"
if (kar == ']')
continue;
sb.append(kar);
}
return sb.toString();
}
static boolean isPlayStoreInstall() {
return BuildConfig.PLAY_STORE_RELEASE;
}
static void linkPro(final TextView tv) {
if (ActivityBilling.isPro(tv.getContext()) && !BuildConfig.DEBUG)
hide(tv);
else {
tv.getPaint().setUnderlineText(true);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv.getContext().startActivity(new Intent(tv.getContext(), ActivityBilling.class));
}
});
}
}
static <T> List<List<T>> chunkList(List<T> list, int size) {
List<List<T>> result = new ArrayList<>(list.size() / size);
for (int i = 0; i < list.size(); i += size)

@ -1266,6 +1266,31 @@ public class MessageHelper {
"Unable to load BODYSTRUCTURE".equals(ex.getMessage()));
}
static String sanitizeKeyword(String keyword) {
// https://tools.ietf.org/html/rfc3501
StringBuilder sb = new StringBuilder();
for (int i = 0; i < keyword.length(); i++) {
// flag-keyword = atom
// atom = 1*ATOM-CHAR
// ATOM-CHAR = <any CHAR except atom-specials>
char kar = keyword.charAt(i);
// atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards / quoted-specials / resp-specials
if (kar == '(' || kar == ')' || kar == '{' || kar == ' ' || Character.isISOControl(kar))
continue;
// list-wildcards = "%" / "*"
if (kar == '%' || kar == '*')
continue;
// quoted-specials = DQUOTE / "\"
if (kar == '"' || kar == '\\')
continue;
// resp-specials = "]"
if (kar == ']')
continue;
sb.append(kar);
}
return sb.toString();
}
static boolean equal(Address[] a1, Address[] a2) {
if (a1 == null && a2 == null)
return true;

@ -289,12 +289,7 @@ public class ServiceSynchronize extends ServiceBase {
setUnseen(null);
if (state != null && state.isRunning()) {
Boolean ignoring = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
ignoring = (pm != null && pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID));
}
Log.e("Destroy while running ignoring=" + ignoring);
Log.e("Destroy while monitor running ignoring=" + Helper.isIgnoringOptimizations(this));
state.stop();
}
@ -576,6 +571,11 @@ public class ServiceSynchronize extends ServiceBase {
final Thread main = Thread.currentThread();
if (state != null && state.isRunning()) {
Log.e("Monitor running ignoring=" + Helper.isIgnoringOptimizations(this));
state.stop();
}
state = new Core.State(networkState);
state.runnable(new Runnable() {
private PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

Loading…
Cancel
Save