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

Add option to configure auto-play #49

Merged
merged 5 commits into from
Aug 28, 2023
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
### Download

| Lite | Online |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Github release v0.15](https://github.com/AP-Atul/music_player_lite/releases/download/v0.15/mplite.apk) | [Github release v0.3](https://github.com/AP-Atul/music_player_lite/releases/download/v0.3/mplite_online.apk) |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Github release](https://github.com/AP-Atul/music_player_lite/releases/latest) | [Github release v0.3](https://github.com/AP-Atul/music_player_lite/releases/download/v0.3/mplite_online.apk) |
| <a href="https://apt.izzysoft.de/fdroid/index/apk/com.atul.musicplayer"><img src="https://github.com/AP-Atul/music_player_lite/raw/main/assets/IzzyOnDroid.png" width="200px"></a> | <a href="https://apt.izzysoft.de/fdroid/index/apk/com.atul.musicplayeronline"><img src="https://github.com/AP-Atul/music_player_lite/raw/main/assets/IzzyOnDroid.png" width="200px"></a> |
<a href="https://f-droid.org/packages/com.atul.musicplayer/"><img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" width="200px"></a> |
<a href="https://f-droid.org/packages/com.atul.musicplayer/"><img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" width="200px"></a> |
| <a href="https://play.google.com/store/apps/details?id=com.atul.musicplayer"><img src="https://play.google.com/intl/en_us/badges/static/images/badges/en_badge_web_generic.png" width="200px"></a> | |

### Community
Expand Down
8 changes: 3 additions & 5 deletions src/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ android {
keyPassword 'musicplayerlite'
}
}
compileSdkVersion 33
compileSdk 33
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.atul.musicplayer"
minSdkVersion 23
targetSdkVersion 33
versionCode 15
versionName "0.15"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
versionCode 16
versionName "0.16"
}

buildTypes {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class MPConstants {
};
public static final String SETTINGS_THEME = "shared_pref_theme";
public static final String SETTINGS_ALBUM_REQUEST = "shared_pref_album_request";
public static final String SETTINGS_AUTO_PLAY = "shared_pref_auto_play_music";
public static final String SETTINGS_THEME_MODE = "shared_pref_theme_mode";
public static final String SETTINGS_EXCLUDED_FOLDER = "shared_pref_excluded_folders";
public static final String EXCLUDED_FOLDER_SEPARATOR = ":::";
Expand Down
8 changes: 8 additions & 0 deletions src/app/src/main/java/com/atul/musicplayer/MPPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,18 @@ public static void storeAlbumRequest(Context context, boolean val) {
getEditor(context).putBoolean(MPConstants.SETTINGS_ALBUM_REQUEST, val).apply();
}

public static void storeAutoPlay(Context context, boolean val) {
getEditor(context).putBoolean(MPConstants.SETTINGS_AUTO_PLAY, val).apply();
}

public static boolean getAlbumRequest(Context context) {
return getSharedPref(context).getBoolean(MPConstants.SETTINGS_ALBUM_REQUEST, false);
}

public static boolean getAutoPlay(Context context) {
return getSharedPref(context).getBoolean(MPConstants.SETTINGS_AUTO_PLAY, true);
}

public static void storeThemeMode(Context context, int theme) {
getEditor(context).putInt(MPConstants.SETTINGS_THEME_MODE, theme).apply();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ public MyViewHolder(@NonNull View itemView) {
songName = itemView.findViewById(R.id.song_name);
albumName = itemView.findViewById(R.id.song_album);


itemView.findViewById(R.id.root_layout).setOnClickListener(v -> {
List<Music> toPlay = new ArrayList<>();
toPlay.add(musicList.get(getAdapterPosition()));
boolean autoPlay = MPPreferences.getAutoPlay(itemView.getContext());
if (autoPlay) {
toPlay.addAll(musicList.subList(getAdapterPosition(), musicList.size()));
} else {
toPlay.add(musicList.get(getAdapterPosition()));
}
listener.playQueue(toPlay, false);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SettingsFragment extends Fragment implements View.OnClickListener {
private MainViewModel viewModel;
private RecyclerView accentView;
private boolean state;
private boolean autoPlayState;
private LinearLayout chipLayout;
private ImageView currentThemeMode;

Expand All @@ -43,6 +44,7 @@ public class SettingsFragment extends Fragment implements View.OnClickListener {
private FolderDialog folderDialog;

public SettingsFragment() {
// Unused
}

public static SettingsFragment newInstance() {
Expand All @@ -69,6 +71,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
});

SwitchMaterial switchMaterial = view.findViewById(R.id.album_switch);
SwitchMaterial autoPlaySwitch = view.findViewById(R.id.auto_play_switch);
accentView = view.findViewById(R.id.accent_view);
chipLayout = view.findViewById(R.id.chip_layout);
currentThemeMode = view.findViewById(R.id.current_theme_mode);
Expand All @@ -81,7 +84,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
LinearLayout refreshOption = view.findViewById(R.id.refresh_options);

state = MPPreferences.getAlbumRequest(requireActivity().getApplicationContext());
autoPlayState = MPPreferences.getAutoPlay(requireActivity().getApplicationContext());
switchMaterial.setChecked(state);
autoPlaySwitch.setChecked(autoPlayState);
setCurrentThemeMode();

accentView.setLayoutManager(new LinearLayoutManager(getActivity(), RecyclerView.HORIZONTAL, false));
Expand All @@ -90,6 +95,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
accentOption.setOnClickListener(this);
albumOption.setOnClickListener(this);
switchMaterial.setOnClickListener(this);
autoPlaySwitch.setOnClickListener(this);
themeModeOption.setOnClickListener(this);
folderOption.setOnClickListener(this);
refreshOption.setOnClickListener(this);
Expand Down Expand Up @@ -149,6 +155,9 @@ public void onClick(View v) {
else if (id == R.id.album_switch)
setAlbumRequest();

else if (id == R.id.auto_play_switch)
setAutoPlay();

else if (id == R.id.theme_mode_option) {
int mode = chipLayout.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE;
chipLayout.setVisibility(mode);
Expand Down Expand Up @@ -204,6 +213,10 @@ private void setAlbumRequest() {
ThemeHelper.applySettings(getActivity());
}

private void setAutoPlay() {
MPPreferences.storeAutoPlay(requireActivity().getApplicationContext(), (!autoPlayState));
}

private void setUpRateReview() {
startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(MPConstants.PLAY_STORE_LINK)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,15 @@ public void onCompletion(MediaPlayer mp) {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
playerService.startForeground(NOTIFICATION_ID, notificationManager.createNotification());
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
playerService.startForeground(NOTIFICATION_ID, notificationManager.createNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
} else {
playerService.startForeground(NOTIFICATION_ID, notificationManager.createNotification());
}
} catch (Exception e) {
e.printStackTrace();
}

for (PlayerListener listener : playerListeners)
listener.onMusicSet(playerQueue.getCurrentMusic());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public Notification createNotification() {
notificationBuilder
.setContentTitle(song.title)
.setContentText(song.artist)
.setProgress(100, playerService.getPlayerManager().getCurrentPosition(), true)
.setColor(MusicLibraryHelper.getDominantColorFromThumbnail(albumArt))
.setLargeIcon(albumArt)
.setStyle(notificationStyle);
Expand Down Expand Up @@ -124,21 +123,13 @@ public void updateNotification() {

@NonNull
private NotificationCompat.Action notificationAction(@NonNull final String action) {
int icon = R.drawable.ic_controls_pause;

switch (action) {
case PREV_ACTION:
icon = R.drawable.ic_controls_prev;
break;
case PLAY_PAUSE_ACTION:
icon = playerService.getPlayerManager().isPlaying() ? R.drawable.ic_controls_pause : R.drawable.ic_controls_play;
break;
case NEXT_ACTION:
icon = R.drawable.ic_controls_next;
break;
default:
break;
}
int icon = -1;
if (action.equals(PREV_ACTION)) icon = R.drawable.ic_controls_prev;
else if (action.equals(NEXT_ACTION)) icon = R.drawable.ic_controls_next;
else if (action.equals(PLAY_PAUSE_ACTION)) icon =
playerService.getPlayerManager().isPlaying()
? R.drawable.ic_controls_pause
: R.drawable.ic_controls_play;
return new NotificationCompat.Action.Builder(icon, action, playerAction(action)).build();
}

Expand Down
63 changes: 56 additions & 7 deletions src/app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
android:id="@+id/theme_mode_option"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="10dp"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
Expand Down Expand Up @@ -129,7 +129,6 @@
android:id="@+id/accent_option"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
Expand Down Expand Up @@ -183,7 +182,6 @@
android:id="@+id/album_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
Expand Down Expand Up @@ -236,7 +234,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginTop="20dp"
android:fontFamily="@font/nunito_sans_semibold"
android:text="@string/general"
android:textColor="?colorPrimary"
Expand All @@ -248,7 +246,7 @@
android:id="@+id/folder_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="10dp"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
Expand Down Expand Up @@ -295,7 +293,6 @@
android:id="@+id/refresh_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
Expand Down Expand Up @@ -338,11 +335,63 @@

</LinearLayout>

<LinearLayout
android:id="@+id/play_next_song_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:padding="10dp">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:contentDescription="@string/image"
android:src="@drawable/ic_music_queue"
app:tint="?colorPrimary" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/nunito_sans"
android:text="@string/auto_play_next_songs"
android:textColor="@color/colorTextHigh"
android:textSize="@dimen/text_big" />

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/nunito_sans"
android:text="@string/auto_play_summary"
android:textColor="@color/colorTextMed"
android:textSize="@dimen/text_big_med" />

</LinearLayout>

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/auto_play_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:checked="false" />

</LinearLayout>

<LinearLayout
android:id="@+id/review_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="?selectableItemBackground"
android:clickable="true"
android:focusable="true"
Expand Down
2 changes: 2 additions & 0 deletions src/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<string name="cancel">Cancel</string>
<string name="view_pager_title">Main page</string>
<string name="tab_layout_title">Bottom horizontal menu</string>
<string name="auto_play_next_songs">Auto play the song list</string>
<string name="auto_play_summary">when enabled, will play the song list automatically</string>


</resources>
17 changes: 0 additions & 17 deletions src/app/src/test/java/com/atul/musicplayer/ExampleUnitTest.java

This file was deleted.