mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
Make notification blacklist actually working
This commit is contained in:
parent
03b9f02b2c
commit
914d1b9625
@ -5,16 +5,20 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
@ -22,6 +26,7 @@ import android.widget.TextView;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
@ -40,6 +45,39 @@ public class AppBlacklistActivity extends Activity {
|
||||
}
|
||||
};
|
||||
|
||||
private SharedPreferences sharedPrefs;
|
||||
|
||||
private HashSet<String> blacklist = null;
|
||||
|
||||
private void loadBlackList() {
|
||||
blacklist = (HashSet<String>) sharedPrefs.getStringSet("package_blacklist", null);
|
||||
if (blacklist == null) {
|
||||
blacklist = new HashSet<>();
|
||||
}
|
||||
}
|
||||
|
||||
private void saveBlackList() {
|
||||
SharedPreferences.Editor editor = sharedPrefs.edit();
|
||||
if (blacklist.isEmpty()) {
|
||||
editor.putStringSet("package_blacklist", null);
|
||||
} else {
|
||||
editor.putStringSet("package_blacklist", blacklist);
|
||||
}
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private synchronized void addToBlacklist(String packageName) {
|
||||
if (!blacklist.contains(packageName)) {
|
||||
blacklist.add(packageName);
|
||||
saveBlackList();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void removeFromBlacklist(String packageName) {
|
||||
blacklist.remove(packageName);
|
||||
saveBlackList();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -47,40 +85,53 @@ public class AppBlacklistActivity extends Activity {
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
final PackageManager pm = getPackageManager();
|
||||
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
|
||||
loadBlackList();
|
||||
|
||||
final List<ApplicationInfo> packageList = pm.getInstalledApplications(PackageManager.GET_META_DATA);
|
||||
ListView appListView = (ListView) findViewById(R.id.appListView);
|
||||
|
||||
final ArrayAdapter<ApplicationInfo> adapter = new ArrayAdapter<ApplicationInfo>(this, R.layout.item_with_details, packageList) {
|
||||
|
||||
final ArrayAdapter<ApplicationInfo> adapter = new ArrayAdapter<ApplicationInfo>(this, R.layout.item_with_checkbox, packageList) {
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup parent) {
|
||||
if (view == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = inflater.inflate(R.layout.item_with_details, parent, false);
|
||||
view = inflater.inflate(R.layout.item_with_checkbox, parent, false);
|
||||
}
|
||||
|
||||
ApplicationInfo appInfo = packageList.get(position);
|
||||
//TextView deviceAppVersionAuthorLabel = (TextView) view.findViewById(R.id.item_details);
|
||||
TextView deviceAppVersionAuthorLabel = (TextView) view.findViewById(R.id.item_details);
|
||||
TextView deviceAppNameLabel = (TextView) view.findViewById(R.id.item_name);
|
||||
ImageView deviceImageView = (ImageView) view.findViewById(R.id.item_image);
|
||||
CheckBox checkbox = (CheckBox) view.findViewById(R.id.item_checkbox);
|
||||
|
||||
//deviceAppVersionAuthorLabel.setText(appInfo.loadDescription(pm));
|
||||
deviceAppVersionAuthorLabel.setText(appInfo.packageName);
|
||||
deviceAppNameLabel.setText(appInfo.loadLabel(pm));
|
||||
deviceImageView.setImageDrawable(appInfo.loadIcon(pm));
|
||||
|
||||
if (blacklist.contains(appInfo.packageName)) {
|
||||
checkbox.setChecked(true);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
};
|
||||
appListView.setAdapter(adapter);
|
||||
/*
|
||||
|
||||
appListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView parent, View v, int position, long id) {
|
||||
// do something
|
||||
String packageName = packageList.get(position).packageName;
|
||||
CheckBox checkBox = ((CheckBox) v.findViewById(R.id.item_checkbox));
|
||||
checkBox.toggle();
|
||||
if (checkBox.isChecked()) {
|
||||
addToBlacklist(packageName);
|
||||
} else {
|
||||
removeFromBlacklist(packageName);
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ControlCenter.ACTION_QUIT);
|
||||
|
@ -64,7 +64,7 @@ public class AppManagerActivity extends Activity {
|
||||
}
|
||||
};
|
||||
|
||||
SharedPreferences sharedPrefs;
|
||||
private SharedPreferences sharedPrefs;
|
||||
|
||||
private final List<GBDeviceApp> appList = new ArrayList<>();
|
||||
private GBDeviceAppAdapter mGBDeviceAppAdapter;
|
||||
|
@ -19,6 +19,8 @@ import android.support.v4.content.LocalBroadcastManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||
|
||||
@ -146,6 +148,11 @@ public class NotificationListener extends NotificationListenerService {
|
||||
}
|
||||
}
|
||||
|
||||
HashSet<String> blacklist = (HashSet<String>) sharedPrefs.getStringSet("package_blacklist", null);
|
||||
if (blacklist != null && blacklist.contains(source)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG.info("Processing notification from source " + source);
|
||||
|
||||
Bundle extras = notification.extras;
|
||||
|
Loading…
Reference in New Issue
Block a user