Skip to content
This repository was archived by the owner on Oct 26, 2023. It is now read-only.

Commit 3dd3d6f

Browse files
authored
Merge pull request #152 from TheAndroidMaster/develop
Version 3.8-beta5
2 parents 99d40ed + 334efd6 commit 3dd3d6f

20 files changed

+578
-123
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
minSdkVersion 16
1010
targetSdkVersion 27
1111
maxSdkVersion 25
12-
versionCode 40
13-
versionName "3.8-beta4"
12+
versionCode 41
13+
versionName "3.8-beta5"
1414
vectorDrawables.useSupportLibrary = true
1515
resConfigs "ar", "en", "es", "ko", "zh"
1616
}

app/src/main/java/com/james/status/Status.java

Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
import android.app.Application;
44
import android.content.Context;
55
import android.content.Intent;
6-
import android.content.SharedPreferences;
7-
import android.preference.PreferenceManager;
86
import android.support.annotation.Nullable;
97
import android.util.Log;
10-
import android.widget.Toast;
118

129
import com.james.status.data.PreferenceData;
1310
import com.james.status.data.icon.IconData;
11+
import com.james.status.utils.tasks.PreferenceUpdateTask;
1412

1513
import java.util.ArrayList;
1614
import java.util.List;
17-
import java.util.Map;
1815

1916
public class Status extends Application {
2017

@@ -30,69 +27,8 @@ public void onCreate() {
3027
onColorPickedListeners = new ArrayList<>();
3128
onIconPreferenceChangedListeners = new ArrayList<>();
3229

33-
if ((int) PreferenceData.LAST_PREF_VERSION.getValue(this) == 0) {
34-
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
35-
Map<String, ?> items = prefs.getAll();
36-
SharedPreferences.Editor editor = prefs.edit();
37-
for (String key : items.keySet()) {
38-
if (key.startsWith("COLOR/")) {
39-
String[] packages = key.substring("COLOR/".length()).split("/");
40-
if (packages.length == 2 && prefs.contains("COLOR/" + packages[0] + "/" + packages[1])) {
41-
try {
42-
PreferenceData.APP_COLOR.setValue(this, prefs.getInt(key, 0), packages[0] + "/" + packages[1]);
43-
} catch (Exception ignored) {
44-
}
45-
}
46-
} else if (key.startsWith("CACHE_COLOR/")) {
47-
String[] packages = key.substring("CACHE_COLOR/".length()).split("/");
48-
if (packages.length == 2 && prefs.contains("CACHE_COLOR/" + packages[0] + "/" + packages[1])) {
49-
try {
50-
PreferenceData.APP_COLOR_CACHE.setValue(this, prefs.getInt(key, 0), packages[0] + "/" + packages[1]);
51-
} catch (Exception ignored) {
52-
}
53-
}
54-
} else if (key.startsWith("CACHE_VERSION/")) {
55-
String[] packages = key.substring("CACHE_VERSION/".length()).split("/");
56-
if (packages.length == 2 && prefs.contains("CACHE_VERSION/" + packages[0] + "/" + packages[1])) {
57-
try {
58-
PreferenceData.APP_COLOR_CACHE_VERSION.setValue(this, prefs.getInt(key, 0), packages[0] + "/" + packages[1]);
59-
} catch (Exception ignored) {
60-
}
61-
}
62-
} else if (key.startsWith("FULLSCREEN/")) {
63-
String[] packages = key.substring("FULLSCREEN/".length()).split("/");
64-
if (packages.length == 2 && prefs.contains("FULLSCREEN/" + packages[0] + "/" + packages[1])) {
65-
try {
66-
if (prefs.getBoolean(key, false))
67-
PreferenceData.APP_FULLSCREEN.setValue(this, true, packages[0] + "/" + packages[1]);
68-
} catch (Exception ignored) {
69-
}
70-
}
71-
} else if (key.startsWith("IGNORE_AUTO_DETECT/")) {
72-
String[] packages = key.substring("IGNORE_AUTO_DETECT/".length()).split("/");
73-
if (packages.length == 2 && prefs.contains("IGNORE_AUTO_DETECT/" + packages[0] + "/" + packages[1])) {
74-
try {
75-
if (prefs.getBoolean(key, false))
76-
PreferenceData.APP_FULLSCREEN.setValue(this, true, packages[0] + "/" + packages[1]);
77-
} catch (Exception ignored) {
78-
}
79-
}
80-
} else if (key.startsWith("NOTIFICATIONS/")) {
81-
String[] packages = key.substring("NOTIFICATIONS/".length()).split("/");
82-
if (packages.length == 2 && prefs.contains("NOTIFICATIONS/" + packages[0] + "/" + packages[1])) {
83-
try {
84-
if (!prefs.getBoolean(key, true))
85-
PreferenceData.APP_NOTIFICATIONS.setValue(this, false, packages[0] + "/" + packages[1]);
86-
} catch (Exception ignored) {
87-
}
88-
}
89-
} else continue;
90-
91-
editor.remove(key);
92-
}
93-
editor.putInt("LAST_PREF_VERSION", PreferenceData.PREF_VERSION);
94-
editor.apply();
95-
}
30+
if (PreferenceData.VERSION != (Integer) PreferenceData.PREF_VERSION.getValue(this))
31+
new PreferenceUpdateTask(this).execute();
9632
}
9733

9834
public void addListener(OnActivityResultListener listener) {
@@ -150,8 +86,7 @@ public interface OnIconPreferenceChangedListener {
15086
}
15187

15288
public static void showDebug(Context context, String message, int length) {
153-
if (PreferenceData.STATUS_DEBUG.getValue(context))
154-
Toast.makeText(context, message, length).show();
155-
else Log.d("Status", message);
89+
if (BuildConfig.DEBUG)
90+
Log.d("Status", message);
15691
}
15792
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
package com.james.status.adapters;
2+
3+
import android.content.Context;
4+
import android.content.pm.PackageManager;
5+
import android.graphics.Color;
6+
import android.graphics.drawable.ColorDrawable;
7+
import android.graphics.drawable.Drawable;
8+
import android.support.annotation.NonNull;
9+
import android.support.annotation.Nullable;
10+
import android.support.v7.widget.RecyclerView;
11+
import android.support.v7.widget.SwitchCompat;
12+
import android.view.LayoutInflater;
13+
import android.view.View;
14+
import android.view.ViewGroup;
15+
import android.widget.CompoundButton;
16+
import android.widget.TextView;
17+
18+
import com.afollestad.async.Action;
19+
import com.james.status.R;
20+
import com.james.status.data.AppPreferenceData;
21+
import com.james.status.data.PreferenceData;
22+
import com.james.status.utils.StringUtils;
23+
import com.james.status.views.CustomImageView;
24+
25+
import java.util.Collections;
26+
import java.util.Comparator;
27+
import java.util.List;
28+
29+
public class AppNotificationsAdapter extends RecyclerView.Adapter<AppNotificationsAdapter.ViewHolder> {
30+
31+
private Context context;
32+
private PackageManager packageManager;
33+
private List<AppPreferenceData> apps;
34+
35+
public AppNotificationsAdapter(Context context, List<AppPreferenceData> apps) {
36+
this.context = context;
37+
packageManager = context.getPackageManager();
38+
39+
this.apps = apps;
40+
Collections.sort(apps, new Comparator<AppPreferenceData>() {
41+
@Override
42+
public int compare(AppPreferenceData lhs, AppPreferenceData rhs) {
43+
String label1 = lhs.getLabel(AppNotificationsAdapter.this.context);
44+
String label2 = rhs.getLabel(AppNotificationsAdapter.this.context);
45+
if (label1 != null && label2 != null)
46+
return label1.compareToIgnoreCase(label2);
47+
else return 0;
48+
}
49+
});
50+
}
51+
52+
@Override
53+
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
54+
return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_app_switch, parent, false));
55+
}
56+
57+
@Override
58+
public void onBindViewHolder(final ViewHolder holder, int position) {
59+
AppPreferenceData app = getApp(position);
60+
if (app == null) return;
61+
62+
holder.name.setText(app.getLabel(context));
63+
holder.packageName.setText(app.getName());
64+
65+
holder.icon.setImageDrawable(new ColorDrawable(Color.TRANSPARENT));
66+
67+
new Action<Drawable>() {
68+
@NonNull
69+
@Override
70+
public String id() {
71+
return "appIcon";
72+
}
73+
74+
@Nullable
75+
@Override
76+
protected Drawable run() throws InterruptedException {
77+
AppPreferenceData app = getApp(holder.getAdapterPosition());
78+
if (app != null) {
79+
try {
80+
return packageManager.getApplicationIcon(app.getPackageName());
81+
} catch (PackageManager.NameNotFoundException ignored) {
82+
}
83+
}
84+
85+
return null;
86+
}
87+
88+
@Override
89+
protected void done(@Nullable Drawable result) {
90+
if (result != null)
91+
holder.icon.setImageDrawable(result);
92+
}
93+
}.execute();
94+
95+
holder.itemView.setOnClickListener(new View.OnClickListener() {
96+
@Override
97+
public void onClick(View v) {
98+
holder.enabledSwitch.toggle();
99+
}
100+
});
101+
102+
holder.enabledSwitch.setOnCheckedChangeListener(null);
103+
holder.enabledSwitch.setChecked((boolean) PreferenceData.APP_NOTIFICATIONS.getSpecificValue(context, apps.get(position).getPackageName()));
104+
holder.enabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
105+
@Override
106+
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
107+
AppPreferenceData app = getApp(holder.getAdapterPosition());
108+
if (app != null)
109+
PreferenceData.APP_NOTIFICATIONS.setValue(context, isChecked, app.getPackageName());
110+
}
111+
});
112+
}
113+
114+
@Nullable
115+
private AppPreferenceData getApp(int position) {
116+
if (position < 0 || position >= apps.size()) return null;
117+
else return apps.get(position);
118+
}
119+
120+
@Override
121+
public int getItemCount() {
122+
return apps.size();
123+
}
124+
125+
public void filter(@Nullable final String string) {
126+
if (string == null || string.length() < 1) {
127+
Collections.sort(apps, new Comparator<AppPreferenceData>() {
128+
@Override
129+
public int compare(AppPreferenceData lhs, AppPreferenceData rhs) {
130+
String label1 = lhs.getLabel(AppNotificationsAdapter.this.context);
131+
String label2 = rhs.getLabel(AppNotificationsAdapter.this.context);
132+
if (label1 != null && label2 != null)
133+
return label1.compareToIgnoreCase(label2);
134+
else return 0;
135+
}
136+
});
137+
} else {
138+
Collections.sort(apps, new Comparator<AppPreferenceData>() {
139+
@Override
140+
public int compare(AppPreferenceData lhs, AppPreferenceData rhs) {
141+
int value = 0;
142+
143+
String label1 = lhs.getLabel(AppNotificationsAdapter.this.context);
144+
String label2 = rhs.getLabel(AppNotificationsAdapter.this.context);
145+
if (label1 != null && label2 != null) {
146+
value += StringUtils.difference(label1.toLowerCase(), string).length();
147+
value -= StringUtils.difference(label2.toLowerCase(), string).length();
148+
}
149+
150+
value += StringUtils.difference(lhs.getComponentName(), string).length();
151+
value -= StringUtils.difference(rhs.getComponentName(), string).length();
152+
153+
return value;
154+
}
155+
});
156+
}
157+
158+
notifyDataSetChanged();
159+
}
160+
161+
public static class ViewHolder extends RecyclerView.ViewHolder {
162+
163+
View v;
164+
TextView name, packageName;
165+
CustomImageView icon;
166+
SwitchCompat enabledSwitch;
167+
168+
public ViewHolder(View v) {
169+
super(v);
170+
this.v = v;
171+
name = v.findViewById(R.id.appName);
172+
packageName = v.findViewById(R.id.appPackage);
173+
icon = v.findViewById(R.id.icon);
174+
enabledSwitch = v.findViewById(R.id.enabledSwitch);
175+
}
176+
}
177+
}

app/src/main/java/com/james/status/data/NotificationData.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class NotificationData implements Parcelable {
2929

3030
public String category, title, subtitle, packageName, group, key, tag = "";
3131
public int priority, id, iconRes, color = Color.BLACK;
32-
private boolean isAlert;
32+
private boolean isAlert, isOngoing;
3333
private Bitmap icon, scaledIcon;
3434
private Bitmap largeIcon;
3535
private Icon unloadedIcon, unloadedLargeIcon;
@@ -43,6 +43,7 @@ public class NotificationData implements Parcelable {
4343
public NotificationData(StatusBarNotification sbn, String key) {
4444
this.key = key;
4545
init(sbn.getNotification(), sbn.getId(), sbn.getPackageName());
46+
isOngoing = sbn.isOngoing();
4647
}
4748

4849
public NotificationData(Notification notification, String packageName) {
@@ -129,9 +130,6 @@ private void init(Notification notification, int id, String packageName) {
129130
for (int i = 0; i < actions.length; i++) {
130131
actions[i] = new ActionData(NotificationCompat.getAction(notification, i), packageName);
131132
}
132-
133-
scale = new AnimatedFloat(0);
134-
scale.to(1f);
135133
}
136134

137135
public boolean set(NotificationData notification) {
@@ -195,6 +193,10 @@ public NotificationData[] newArray(int size) {
195193
}
196194
};
197195

196+
public boolean isOngoing() {
197+
return isOngoing;
198+
}
199+
198200
public Bitmap getIcon(float height) {
199201
if (icon.getHeight() == Math.round(height))
200202
return icon;
@@ -308,6 +310,11 @@ private Drawable getDrawable(Context context, int resource, String packageName)
308310
}
309311

310312
public AnimatedFloat getScale() {
313+
if (scale == null) {
314+
scale = new AnimatedFloat(0);
315+
scale.to(1f);
316+
}
317+
311318
return scale;
312319
}
313320

app/src/main/java/com/james/status/data/PreferenceData.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import android.os.Environment;
99
import android.preference.PreferenceManager;
1010
import android.support.annotation.Nullable;
11+
import android.support.v4.app.NotificationCompat;
1112
import android.widget.Toast;
1213

1314
import com.google.gson.Gson;
14-
import com.james.status.BuildConfig;
1515

1616
import java.io.File;
1717
import java.io.FileInputStream;
@@ -21,7 +21,7 @@
2121
import java.util.Set;
2222

2323
public enum PreferenceData {
24-
LAST_PREF_VERSION(0),
24+
PREF_VERSION(0),
2525
STATUS_ENABLED(false),
2626
STATUS_NOTIFICATIONS_COMPAT(false),
2727
//STATUS_NOTIFICATIONS_HEADS_UP(false), TODO: #137
@@ -44,7 +44,6 @@ public enum PreferenceData {
4444
STATUS_BURNIN_PROTECTION(false),
4545
STATUS_SIDE_PADDING(6),
4646
STATUS_HEIGHT(0),
47-
STATUS_DEBUG(BuildConfig.DEBUG),
4847
ICON_VISIBILITY("%1$s/VISIBILITY", true),
4948
ICON_POSITION("%1$s/POSITION", 0),
5049
ICON_GRAVITY("%1$s/GRAVITY", 0),
@@ -71,9 +70,11 @@ public enum PreferenceData {
7170
APP_COLOR_CACHE_VERSION("%1$s/APP_COLOR_CACHE_VERSION", 0),
7271
APP_FULLSCREEN("%1$s/APP_FULLSCREEN", false),
7372
APP_FULLSCREEN_IGNORE("%1$s/APP_FULLSCREEN_IGNORE", false),
74-
APP_NOTIFICATIONS("%1$s/APP_NOTIFICATIONS", true);
73+
APP_NOTIFICATIONS("%1$s/APP_NOTIFICATIONS", true),
74+
APP_NOTIFICATIONS_MIN_PRIORITY(NotificationCompat.PRIORITY_LOW),
75+
APP_NOTIFICATIONS_IGNORE_ONGOING(false);
7576

76-
public static final int PREF_VERSION = 1;
77+
public static final int VERSION = 1;
7778

7879
private String name;
7980
private Object defaultValue;

0 commit comments

Comments
 (0)