Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mediastyle Notifications #914

Open
wants to merge 4 commits into
base: edge
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
import java.util.concurrent.CopyOnWriteArrayList;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Service;
import android.content.ComponentCallbacks2;
import android.content.ComponentName;
Expand Down Expand Up @@ -111,6 +110,8 @@ public class DownloadService extends Service {
public static final String CMD_NEXT = "github.daneren2005.dsub.CMD_NEXT";
public static final String CANCEL_DOWNLOADS = "github.daneren2005.dsub.CANCEL_DOWNLOADS";
public static final String START_PLAY = "github.daneren2005.dsub.START_PLAYING";
public static final String THUMBS_UP = "github.daneren2005.dsub.THUMBS_UP";
public static final String THUMBS_DOWN = "github.daneren2005.dsub.THUMBS_DOWN";
private static final long DEFAULT_DELAY_UPDATE_PROGRESS = 1000L;
private static final double DELETE_CUTOFF = 0.84;
private static final int REQUIRED_ALBUM_MATCHES = 4;
Expand Down Expand Up @@ -310,7 +311,7 @@ public boolean onError(MediaPlayer mediaPlayer, int what, int more) {
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
lifecycleSupport.onStart(intent);
if(Build.VERSION.SDK_INT >= 26 && !this.isForeground()) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && intent.getAction() == null) {
Notifications.shutGoogleUpNotification(this);
}
return START_NOT_STICKY;
Expand Down Expand Up @@ -390,7 +391,12 @@ public void onDestroy() {
unregisterReceiver(audioNoisyReceiver);
}
mediaRouter.destroy();
Notifications.hidePlayingNotification(this, this, handler);
if (Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false)
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
stopForeground(android.app.Service.STOP_FOREGROUND_DETACH);
} else {
Notifications.hidePlayingNotification(this, this, handler);
}
Notifications.hideDownloadingNotification(this, this, handler);
}

Expand Down Expand Up @@ -970,6 +976,10 @@ synchronized void setNextPlaying() {
}
}

public int getDownloadListSize() {
return downloadList.size();
}

public int getCurrentPlayingIndex() {
return currentPlayingIndex;
}
Expand Down Expand Up @@ -1119,7 +1129,11 @@ private synchronized void play(int index, boolean start, int position) {
reset();
if(index >= size && size != 0) {
setCurrentPlaying(0, false);
Notifications.hidePlayingNotification(this, this, handler);
if(Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false)) {
Notifications.showPlayingNotification(this, this, handler, currentPlaying.getSong());
} else {
Notifications.hidePlayingNotification(this, this, handler);
}
} else {
setCurrentPlaying(null, false);
}
Expand Down Expand Up @@ -2792,7 +2806,8 @@ public void starCommited(boolean starred) {
}
});
}
public void toggleRating(int rating) {
public void toggleRating(int rating) {toggleRating(rating, false);}
public void toggleRating(int rating, boolean updateNotification) {
if(currentPlaying == null) {
return;
}
Expand All @@ -2803,6 +2818,9 @@ public void toggleRating(int rating) {
} else {
setRating(rating);
}
if (updateNotification) {
Notifications.showPlayingNotification(this, this, handler, entry);
}
}
public void setRating(int rating) {
final DownloadFile currentPlaying = this.currentPlaying;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ public void run() {
downloadService.previous();
} else if(DownloadService.CANCEL_DOWNLOADS.equals(action)) {
downloadService.clearBackground();
} else if (DownloadService.THUMBS_UP.equals(action)) {
downloadService.toggleRating(5, true);
} else if (DownloadService.THUMBS_DOWN.equals(action)) {
downloadService.toggleRating(1, true);
} else if(intent.getExtras() != null) {
final KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
if (event != null) {
Expand Down
Loading