Skip to content

Commit

Permalink
bug fix, code cleanup, moved notification helper class to service pac…
Browse files Browse the repository at this point in the history
…kage
  • Loading branch information
nuclearfog committed Jun 22, 2024
1 parent cc68135 commit 023c4a8
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import androidx.media.AudioManagerCompat;

import org.nuclearfog.apollo.BuildConfig;
import org.nuclearfog.apollo.NotificationHelper;
import org.nuclearfog.apollo.model.Album;
import org.nuclearfog.apollo.model.Song;
import org.nuclearfog.apollo.player.AudioEffects;
Expand Down Expand Up @@ -316,11 +315,7 @@ public void onRebind(Intent intent) {
public boolean onUnbind(Intent intent) {
mServiceInUse = false;
saveQueue(true);
if (!mPlayer.isPlaying()) {
shutdownHandler.start();
} else {
stopSelf(mServiceStartId);
}
stopSelf(mServiceStartId);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* governing permissions and limitations under the License.
*/

package org.nuclearfog.apollo;
package org.nuclearfog.apollo.service;

import android.app.Notification;
import android.app.PendingIntent;
Expand All @@ -30,9 +30,10 @@
import androidx.core.app.NotificationManagerCompat;
import androidx.media.app.NotificationCompat.MediaStyle;

import org.nuclearfog.apollo.BuildConfig;
import org.nuclearfog.apollo.R;
import org.nuclearfog.apollo.model.Album;
import org.nuclearfog.apollo.model.Song;
import org.nuclearfog.apollo.service.MusicPlaybackService;
import org.nuclearfog.apollo.utils.BitmapUtils;
import org.nuclearfog.apollo.utils.PreferenceUtils;

Expand All @@ -43,7 +44,7 @@
* @author Andrew Neal ([email protected])
* @author nuclearfog
*/
public class NotificationHelper {
class NotificationHelper {

private static final String TAG = "NotificationHelper";

Expand All @@ -56,7 +57,7 @@ public class NotificationHelper {
/**
* Notification channel ID
*/
public static final String NOTIFICAITON_CHANNEL_ID = BuildConfig.APPLICATION_ID + ".controlpanel";
private static final String NOTIFICAITON_CHANNEL_ID = BuildConfig.APPLICATION_ID + ".controlpanel";

/**
* intent used to open audio player after clicking on notification
Expand Down Expand Up @@ -100,7 +101,7 @@ public class NotificationHelper {
*
* @param service callback to the service
*/
public NotificationHelper(MusicPlaybackService service, MediaSessionCompat mSession) {
NotificationHelper(MusicPlaybackService service, MediaSessionCompat mSession) {
mService = service;
mPreferences = PreferenceUtils.getInstance(service.getApplicationContext());
// init notification manager & channel
Expand Down Expand Up @@ -157,7 +158,7 @@ public NotificationHelper(MusicPlaybackService service, MediaSessionCompat mSess
/**
* create a new notification and attach it to the foreground service
*/
public void createNotification() {
void createNotification() {
Notification notification = buildNotification();
if (VERSION.SDK_INT >= VERSION_CODES.Q) {
mService.startForeground(APOLLO_MUSIC_SERVICE, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
Expand All @@ -169,14 +170,14 @@ public void createNotification() {
/**
* update existing notification
*/
public void updateNotification() {
void updateNotification() {
postNotification(buildNotification());
}

/**
* dismiss existing notification
*/
public void dismissNotification() {
void dismissNotification() {
postNotification(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static class WidgetRemoteViewsFactory implements RemoteViewsFactory {
*
* @param context The {@link Context} to use.
*/
public WidgetRemoteViewsFactory(Context context) {
WidgetRemoteViewsFactory(Context context) {
// Initialize the image cache
mFetcher = ImageFetcher.getInstance(context);
mFetcher.setImageCache(ImageCache.getInstance(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

/**
* callback used to communicate with activities
*
* @author nuclearfog
*/
public class ServiceStub extends IApolloService.Stub {
class ServiceStub extends IApolloService.Stub {

private final WeakReference<MusicPlaybackService> mService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void run() {
* start scheduled shutdown
*/
public void start() {
removeCallbacks(this);
postDelayed(this, IDLE_DELAY);
}

Expand All @@ -43,4 +44,4 @@ public void start() {
public void stop() {
removeCallbacks(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,25 @@ public class PlaylistDialog extends DialogFragment implements TextWatcher, OnCli
* key to define what action should be performed {@link #COPY,#MOVE,#CREATE}
* value type is int
*/
public static final String PLAYLIST_MODE = "playlist_mode";
private static final String PLAYLIST_MODE = "playlist_mode";

/**
* key to set playlist name
* value type is String
*/
public static final String PLAYLIST_NAME = "playlist_name";
private static final String PLAYLIST_NAME = "playlist_name";

/**
* key to set an ID of an existing playlist
* value type is long
*/
public static final String PLAYLIST_ID = "playlist_id";
private static final String PLAYLIST_ID = "playlist_id";

/**
* key used to set song IDs to insert in the playlist
* value type is long[]
*/
public static final String PLAYLIST_SONGS = "playlist_songs";
private static final String PLAYLIST_SONGS = "playlist_songs";

/**
* The actual dialog
Expand Down Expand Up @@ -187,7 +187,10 @@ public final void onClick(DialogInterface dialog, int which) {
dismiss();
}
} else if (which == Dialog.BUTTON_NEGATIVE) {
closeKeyboard();
InputMethodManager iManager = (InputMethodManager) requireActivity().getSystemService(INPUT_METHOD_SERVICE);
if (iManager != null) {
iManager.hideSoftInputFromWindow(playlistName.getWindowToken(), 0);
}
MusicUtils.refresh(getActivity());
}
}
Expand Down Expand Up @@ -215,16 +218,6 @@ public final void afterTextChanged(Editable s) {
public final void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

/**
* Closes the soft keyboard
*/
protected void closeKeyboard() {
InputMethodManager iManager = (InputMethodManager) requireActivity().getSystemService(INPUT_METHOD_SERVICE);
if (iManager != null) {
iManager.hideSoftInputFromWindow(playlistName.getWindowToken(), 0);
}
}

/**
* shows a dialog window
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,17 @@ private void doRepeat(boolean shouldRepeat) {
/**
* Sets the correct drawable for playback.
*/
public void updateState() {
private void updateState() {
if (getId() == R.id.action_button_next) {
setImageResource(R.drawable.btn_playback_next);
} else if (getId() == R.id.action_button_previous) {
setImageResource(R.drawable.btn_playback_previous);
}
}

/**
* Click listener for this button
*/
public interface RepeatListener {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class RecentWidgetProvider extends AppWidgetBase {

public static final String CMDAPPWIDGETUPDATE = "app_widget_recents_update";

public static final String CLICK_ACTION = PACKAGE_NAME + ".recents.appwidget.action.CLICK";
private static final String CLICK_ACTION = PACKAGE_NAME + ".recents.appwidget.action.CLICK";

private static final int REQUEST_RECENT = 0x5103;

Expand Down
43 changes: 19 additions & 24 deletions app/src/main/java/org/nuclearfog/apollo/utils/MusicUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,6 @@ public static void unbindFromService(Activity activity) {
ServiceBinder mBinder = mConnectionMap.remove(activity);
if (mBinder != null) {
activity.unbindService(mBinder);
if (mConnectionMap.isEmpty()) {
if (BuildConfig.DEBUG) {
Log.v("MusicUtils", "All connections closed");
}
}
}
}

Expand Down Expand Up @@ -799,25 +794,6 @@ public static long getIdForAlbum(Context context, String albumName, String artis
return id;
}

/**
*
*/
public static void makeInsertItems(long[] ids, int offset, int len, int base) {
if (offset + len > ids.length) {
len = ids.length - offset;
}
if (mContentValuesCache == null || mContentValuesCache.length != len) {
mContentValuesCache = new ContentValues[len];
}
for (int i = 0; i < len; i++) {
if (mContentValuesCache[i] == null) {
mContentValuesCache[i] = new ContentValues();
}
mContentValuesCache[i].put(Playlists.Members.PLAY_ORDER, base + offset + i);
mContentValuesCache[i].put(Playlists.Members.AUDIO_ID, ids[offset + i]);
}
}

/**
* @param name The name of the new playlist.
* @return A new playlist ID.
Expand Down Expand Up @@ -1564,4 +1540,23 @@ private static IApolloService getService(@Nullable Activity activity) {
}
return null;
}

/**
*
*/
private static void makeInsertItems(long[] ids, int offset, int len, int base) {
if (offset + len > ids.length) {
len = ids.length - offset;
}
if (mContentValuesCache == null || mContentValuesCache.length != len) {
mContentValuesCache = new ContentValues[len];
}
for (int i = 0; i < len; i++) {
if (mContentValuesCache[i] == null) {
mContentValuesCache[i] = new ContentValues();
}
mContentValuesCache[i].put(Playlists.Members.PLAY_ORDER, base + offset + i);
mContentValuesCache[i].put(Playlists.Members.AUDIO_ID, ids[offset + i]);
}
}
}

0 comments on commit 023c4a8

Please sign in to comment.