Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

Notification Priority & App Detected #487

Merged
merged 2 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/src/main/assets/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ https://github.com/simple-last-fm-scrobbler/sls
For more details.

- 1.5.8 (2018-6-24)
* Notification Priority
* App Detected Notification
* Export db
* Dropped support for Gingerbread
* Themes
* Many Apps Supported (API 21+)
* Many Apps Supported (API 21+) Lollipop
* Notification Listener
* Notification Fixes
* Fixes (thanks to G00fY2)
* Features (thanks to 4-Eyes)
* Bugs & Languages fixes thanks to many
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/adam/aslfms/OptionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class OptionsActivity extends AppCompatPreferenceActivity {
private static final String KEY_BATTERY = "ao_battery";
private static final String KEY_PLUGGED = "ao_plugged";
private static final String KEY_EXPORT_DB = "export_database";
private static final String KEY_NOTIFICATION_PRIORITY = "notification_priority";

private AppSettings settings;

Expand Down Expand Up @@ -176,6 +177,7 @@ public PowerSpecificPrefs(PowerOptions power,
private ListPreference net;
private CheckBoxPreference roaming;
private Preference exportdatabase;
private ListPreference notification_priority;

public void create() {
createChooserPreference();
Expand All @@ -187,6 +189,8 @@ public void create() {
createNetPreference();
createRoamingPreference();
exportdatabase = findPreference(KEY_EXPORT_DB);
notification_priority = (ListPreference) findPreference(KEY_NOTIFICATION_PRIORITY);
notification_priority.setDefaultValue(Util.notificationStringToInt(getApplicationContext()));
}

public boolean onClick(Preference pref) {
Expand All @@ -207,6 +211,8 @@ public boolean onClick(Preference pref) {
return true;
} else if (pref == exportdatabase) {
Util.exportAllDatabases(getApplicationContext());
} else if (pref == notification_priority){
settings.setKeyNotificationPriority(notification_priority.getValue());
}
return false;
}
Expand Down
35 changes: 17 additions & 18 deletions app/src/main/java/com/adam/aslfms/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import android.view.MenuItem;
import android.widget.Toast;

import com.adam.aslfms.service.ControllerReceiverCallback;
import com.adam.aslfms.service.ControllerReceiverService;
import com.adam.aslfms.service.NetApp;
import com.adam.aslfms.service.NotificationBarService;
Expand Down Expand Up @@ -134,30 +133,30 @@ protected void onCreate(Bundle savedInstanceState) {
settings.setWhatsNewViewedVersion(v);
mDb.rebuildDataBaseOnce(); // TODO: VERSION 1.5.8 only!
}

// Start listening service if applicable
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Log.d(TAG, "launching");
Intent i = new Intent(this, NotificationBarService.class);
i.setAction(NotificationBarService.ACTION_NOTIFICATION_BAR_UPDATE);
i.putExtra("track", "");
i.putExtra("artist", "");
i.putExtra("album", "");
i.putExtra("app_name", "");
Intent ii = new Intent(this, ScrobblingService.class);
ii.setAction(ScrobblingService.ACTION_START_SCROBBLER_SERVICE);
Log.d(TAG, "(re)starting controllerreceiver");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.startForegroundService(i);
this.startForegroundService(ii);
this.startForegroundService(new Intent(this, ControllerReceiverService.class));
} else {
this.startService(i);
this.startService(ii);
this.startService(new Intent(this, ControllerReceiverService.class));
}
ControllerReceiverCallback controllerCallback = new ControllerReceiverCallback();
if (ControllerReceiverService.isListeningAuthorized(this))
ControllerReceiverCallback.registerFallbackControllerCallback(this, controllerCallback);
}
Intent i = new Intent(this, NotificationBarService.class);
i.setAction(NotificationBarService.ACTION_NOTIFICATION_BAR_UPDATE);
i.putExtra("track", "");
i.putExtra("artist", "");
i.putExtra("album", "");
i.putExtra("app_name", "");
Intent ii = new Intent(this, ScrobblingService.class);
ii.setAction(ScrobblingService.ACTION_START_SCROBBLER_SERVICE);
Log.d(TAG, "(re)starting scrobbleservice, notificationbarservice");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
this.startForegroundService(i);
this.startForegroundService(ii);
} else {
this.startService(i);
this.startService(ii);
}
}

Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/adam/aslfms/receiver/BootReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, ScrobblingService.class));
context.startService(new Intent(context, ControllerReceiverService.class));
}
if (controllerCallback == null)
controllerCallback = new ControllerReceiverCallback();
if (ControllerReceiverService.isListeningAuthorized(context))
ControllerReceiverCallback.registerFallbackControllerCallback(context, controllerCallback);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/adam/aslfms/receiver/MusicAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import com.adam.aslfms.MusicAppsActivity;
import com.adam.aslfms.R;
import com.adam.aslfms.util.Util;

/**
* A class for representing and dealing different scrobbling APIs / music apps.
Expand Down Expand Up @@ -291,6 +292,7 @@ public static MusicAPI fromReceiver(Context ctx, String name, String pkg,
if (id == -1) {
Log.e(TAG, "new mapi couldn't be inserted into db");
} else {
Util.myNotify(ctx, name, ctx.getString(R.string.new_music_app), 12473, MusicAppsActivity.class);
Log.d(TAG, "new mapiinserted into db");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public class ControllerReceiverCallback {
private Handler handler = new Handler();
private Bitmap lastBitmap;

public ControllerReceiverCallback() {

}


@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static void registerFallbackControllerCallback(Context context, ControllerReceiverCallback controllerReceiverCallback) {
MediaSessionManager mediaSessionManager = ((MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,22 @@ public IBinder onBind(Intent intent) {
@SuppressWarnings("NewApi")
public void onCreate() {
super.onCreate();
if (NotificationManagerCompat.getEnabledListenerPackages (getApplicationContext()).contains(getApplicationContext().getPackageName())) {
mRemoteController = new WeakReference<>(new RemoteController(this, this));
mRemoteController.get().setArtworkConfiguration(3000, 3000);
if (!((AudioManager) getSystemService(Context.AUDIO_SERVICE)).registerRemoteController(mRemoteController.get())) {
throw new RuntimeException("Error while registering RemoteController!");
}
controllerReceiverCallback = new ControllerReceiverCallback();
}

registerControllerReceiverCallback();

Bundle extras = new Bundle();
extras.putString("track", track);
extras.putString("artist", artist);
extras.putString("album", album);
extras.putString("app_name", albumArtist);
this.startForeground(NotificationCreator.FOREGROUND_ID, NotificationCreator.prepareNotification(extras, this));

}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

registerControllerReceiverCallback();

Bundle extras = new Bundle();
extras.putString("track", track);
extras.putString("artist", artist);
Expand Down Expand Up @@ -211,5 +208,22 @@ public static boolean isNotificationListenerServiceEnabled(Context context) {
return packageNames.contains(context.getPackageName());
}

public void registerControllerReceiverCallback(){
ControllerReceiverCallback controllerCallback = new ControllerReceiverCallback();
if (controllerCallback == null)
controllerCallback = new ControllerReceiverCallback();
if (ControllerReceiverService.isListeningAuthorized(this))
ControllerReceiverCallback.registerFallbackControllerCallback(this, controllerCallback);

if (NotificationManagerCompat.getEnabledListenerPackages (getApplicationContext()).contains(getApplicationContext().getPackageName())) {
mRemoteController = new WeakReference<>(new RemoteController(this, this));
mRemoteController.get().setArtworkConfiguration(3000, 3000);
if (!((AudioManager) getSystemService(Context.AUDIO_SERVICE)).registerRemoteController(mRemoteController.get())) {
throw new RuntimeException("Error while registering RemoteController!");
}
controllerReceiverCallback = new ControllerReceiverCallback();
}
}

// END listener stuff
}
5 changes: 3 additions & 2 deletions app/src/main/java/com/adam/aslfms/service/Handshaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.util.Log;

import com.adam.aslfms.R;
import com.adam.aslfms.SettingsActivity;
import com.adam.aslfms.util.AppSettings;
import com.adam.aslfms.util.AuthStatus;
import com.adam.aslfms.util.AuthStatus.BadAuthException;
Expand Down Expand Up @@ -154,7 +155,7 @@ public void run() {
// the scrobbles already prepared will be sent at a later time
e.getStackTrace();
Util.myNotify(mCtx, getNetApp().getName(),
mCtx.getString(R.string.auth_bad_auth), 39201);
mCtx.getString(R.string.auth_bad_auth), 39201, SettingsActivity.class);

getNetworker().unlaunchScrobblingAndNPNotifying();
} catch (TemporaryFailureException e) {
Expand Down Expand Up @@ -184,7 +185,7 @@ public void run() {
// TODO: what?? notify user
notifyAuthStatusUpdate(AuthStatus.AUTHSTATUS_CLIENTBANNED);
Util.myNotify(mCtx, getNetApp().getName(),
mCtx.getString(R.string.auth_client_banned), 39201);
mCtx.getString(R.string.auth_client_banned), 39201, SettingsActivity.class);
e.getStackTrace();
} catch (UnknownResponseException e) {
if (Util.checkForOkNetwork(getContext()) != Util.NetworkStatus.OK) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/adam/aslfms/service/NPNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.util.Log;

import com.adam.aslfms.R;
import com.adam.aslfms.SettingsActivity;
import com.adam.aslfms.service.Handshaker.HandshakeResult;
import com.adam.aslfms.util.AppSettings;
import com.adam.aslfms.util.AuthStatus;
Expand All @@ -37,7 +38,6 @@
import com.adam.aslfms.util.Track;
import com.adam.aslfms.util.Util;
import com.adam.aslfms.util.enums.SubmissionType;
import com.adam.aslfms.service.MySecureSSLSocketFactory;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -97,7 +97,7 @@ protected boolean doRun(HandshakeResult hInfo) {
notifySubmissionStatusFailure(getContext().getString(
R.string.auth_just_error));
Util.myNotify(mCtx, getNetApp().getName(),
mCtx.getString(R.string.auth_bad_auth), 39201);
mCtx.getString(R.string.auth_bad_auth), 39201, SettingsActivity.class);
ret = true;
} catch (TemporaryFailureException e) {
Log.i(TAG, "Tempfail: " + e.getMessage() + ": "
Expand All @@ -112,7 +112,7 @@ protected boolean doRun(HandshakeResult hInfo) {
// TODO: what?? notify user
notifyAuthStatusUpdate(AuthStatus.AUTHSTATUS_CLIENTBANNED);
Util.myNotify(mCtx, getNetApp().getName(),
mCtx.getString(R.string.auth_client_banned), 39201);
mCtx.getString(R.string.auth_client_banned), 39201, SettingsActivity.class);
e.getStackTrace();
ret = true;
} catch (AuthStatus.UnknownResponseException e) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/adam/aslfms/service/Scrobbler.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.util.Log;

import com.adam.aslfms.R;
import com.adam.aslfms.SettingsActivity;
import com.adam.aslfms.service.Handshaker.HandshakeResult;
import com.adam.aslfms.util.AppSettings;
import com.adam.aslfms.util.AuthStatus;
Expand All @@ -38,7 +39,6 @@
import com.adam.aslfms.util.Util;
import com.adam.aslfms.util.enums.PowerOptions;
import com.adam.aslfms.util.enums.SubmissionType;
import com.adam.aslfms.service.MySecureSSLSocketFactory;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -135,7 +135,7 @@ public boolean doRun(HandshakeResult hInfo) {
R.string.auth_just_error));
e.getStackTrace();
Util.myNotify(mCtx, getNetApp().getName(),
mCtx.getString(R.string.auth_bad_auth), 39201);
mCtx.getString(R.string.auth_bad_auth), 39201, SettingsActivity.class);
ret = true;
} catch (TemporaryFailureException e) {
Log.i(TAG, "Tempfail: " + e.getMessage() + ": "
Expand All @@ -151,7 +151,7 @@ public boolean doRun(HandshakeResult hInfo) {
// TODO: what?? notify user
notifyAuthStatusUpdate(AuthStatus.AUTHSTATUS_CLIENTBANNED);
Util.myNotify(mCtx, getNetApp().getName(),
mCtx.getString(R.string.auth_client_banned), 39201);
mCtx.getString(R.string.auth_client_banned), 39201, SettingsActivity.class);
e.getStackTrace();
ret = true;
} catch (AuthStatus.UnknownResponseException e) {
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/adam/aslfms/util/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public class AppSettings {

private static final String KEY_ACTIVE_MUSIC_NOTIFICATION_APP = "active_music_notification_app";

private static final String KEY_NOTIFICATION_PRIORITY = "key_notification_priority";

private static final String KEY_AUTH_STATUS = "authstatus";

private static final String KEY_WHATSNEW_VIEWED_VERSION = "whatsnew_viewed_version";
Expand Down Expand Up @@ -223,6 +225,20 @@ public void setKeyActiveMusicNotificationApp(String s) {
e.commit();
}

public String getKeyNotificationPriority() {
String temp = prefs.getString(KEY_NOTIFICATION_PRIORITY,null);
if (temp == null){
return "default";
}
return temp;
}

public void setKeyNotificationPriority(String s) {
Editor e = prefs.edit();
e.putString(KEY_NOTIFICATION_PRIORITY, s);
e.commit();
}

/**
* Saves the password in plain-text for a user account at the {@link NetApp}
* {@code napp}. This is only used as an intermediary step, and is removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void initChannels(Context context) {
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel(FOREGROUND_CHANNEL_ID,
context.getString(R.string.app_name_short),
NotificationManager.IMPORTANCE_DEFAULT);
Util.notificationStringToInt(context));
channel.setDescription(context.getString(R.string.app_name));
channel.setSound(null,null);
notificationManager.createNotificationChannel(channel);
Expand Down Expand Up @@ -103,6 +103,7 @@ public static Notification prepareNotification(Bundle extras, Context context) {
.setOngoing(true)
.setAutoCancel(false)
.setColor(Color.RED)
.setPriority(Util.oldNotificationStringToInt(context))
.addAction(heartAction)
.addAction(copyAction)
.setChannelId(FOREGROUND_CHANNEL_ID);
Expand Down
Loading