Skip to content

Commit

Permalink
Merge pull request #25 from AP-Atul/fix/bugs
Browse files Browse the repository at this point in the history
Fix/bugs
  • Loading branch information
ap-atul authored Jan 2, 2023
2 parents b51869a + 41ad689 commit 7771907
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

| Lite | Online |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Github release v0.12](https://github.com/AP-Atul/music_player_lite/releases/download/v0.12/mplite.apk) | [Github release v0.3](https://github.com/AP-Atul/music_player_lite/releases/download/v0.3/mplite_online.apk) |
| [Github release v0.13](https://github.com/AP-Atul/music_player_lite/releases/download/v0.13/mplite.apk) | [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://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> | |

Expand Down
17 changes: 9 additions & 8 deletions src/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "com.atul.musicplayer"
minSdkVersion 23
targetSdkVersion 33
versionCode 12
versionName "0.12"
versionCode 13
versionName "0.13"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -35,14 +35,15 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'com.atul.musicplayer'
}

dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-livedata:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.3.1'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.5.1'
implementation 'com.github.bumptech.glide:glide:4.14.2'
}
3 changes: 1 addition & 2 deletions src/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.atul.musicplayer">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
Expand Down
20 changes: 13 additions & 7 deletions src/app/src/main/java/com/atul/musicplayer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public class MainActivity extends AppCompatActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(ThemeHelper.getTheme(MPPreferences.getTheme(getApplicationContext())));
AppCompatDelegate.setDefaultNightMode(MPPreferences.getThemeMode(getApplicationContext()));
setTheme(ThemeHelper.getTheme(MPPreferences.getTheme(MainActivity.this)));
AppCompatDelegate.setDefaultNightMode(MPPreferences.getThemeMode(MainActivity.this));
setContentView(R.layout.activity_main);
MPConstants.musicSelectListener = this;

Expand All @@ -82,7 +82,6 @@ protected void onCreate(Bundle savedInstanceState) {
manageStoragePermission(MainActivity.this);

albumState = MPPreferences.getAlbumRequest(this);
MPConstants.musicSelectListener = this;

MaterialCardView playerLayout = findViewById(R.id.player_layout);
albumArt = findViewById(R.id.albumArt);
Expand Down Expand Up @@ -274,7 +273,6 @@ else if (id == R.id.player_layout)

private void setUpPlayerDialog() {
playerDialog = new PlayerDialog(this, playerManager, this);

playerDialog.show();
}

Expand Down Expand Up @@ -324,7 +322,11 @@ public void sleepTimerOptionSelect() {

private void setUpQueueDialog() {
queueDialog = new QueueDialog(MainActivity.this, playerManager.getPlayerQueue());
queueDialog.setOnDismissListener(v -> playerDialog.show());
queueDialog.setOnDismissListener(v -> {
if(!this.isDestroyed()) {
playerDialog.show();
}
});

playerDialog.dismiss();
queueDialog.show();
Expand All @@ -341,15 +343,19 @@ private void setUpSleepTimerDialog() {
return;
}
SleepTimerDialog sleepTimerDialog = new SleepTimerDialog(MainActivity.this, this);
sleepTimerDialog.setOnDismissListener(v -> playerDialog.show());
sleepTimerDialog.setOnDismissListener(v -> {
if(!this.isDestroyed()) playerDialog.show();
});

playerDialog.dismiss();
sleepTimerDialog.show();
}

private void setUpSleepTimerDisplayDialog() {
SleepTimerDisplayDialog sleepTimerDisplayDialog = new SleepTimerDisplayDialog(MainActivity.this, this);
sleepTimerDisplayDialog.setOnDismissListener(v -> playerDialog.show());
sleepTimerDisplayDialog.setOnDismissListener(v -> {
if(!this.isDestroyed()) playerDialog.show();
});

playerDialog.dismiss();
sleepTimerDisplayDialog.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ public void onClick(View v) {
else if (id == R.id.music_queue) this.playerDialogListener.queueOptionSelect();
else if (id == R.id.sleep_timer) this.playerDialogListener.sleepTimerOptionSelect();

setUpUi();
}

private void setRepeat() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ public class QueueAdapter extends RecyclerView.Adapter<QueueAdapter.MyViewHolder

private final List<Music> musicList;
private final PlayerQueue playerQueue;
private final Music currentMusic;
private final @ColorInt
int colorInt;
int defaultTint;

public QueueAdapter(Context context, List<Music> musics, PlayerQueue playerQueue) {
this.musicList = musics;
this.playerQueue = playerQueue;
this.currentMusic = playerQueue.getCurrentMusic();

colorInt = ThemeHelper.resolveColorAttr(
context,
Expand All @@ -51,7 +53,7 @@ public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
holder.songName.setText(musicList.get(position).title);

if (playerQueue.getCurrentMusic().title.equals(musicList.get(position).title)) {
if (currentMusic.title.equals(musicList.get(position).title)) {
holder.albumName.setText(R.string.now_playing);
holder.albumName.setTextColor(colorInt);
holder.drag.setImageResource(R.drawable.ic_current_playing);
Expand Down Expand Up @@ -106,9 +108,17 @@ public MyViewHolder(@NonNull View itemView) {
drag = itemView.findViewById(R.id.control_drag);

itemView.findViewById(R.id.control_close).setOnClickListener(v -> {
musicList.remove(getAdapterPosition());
playerQueue.removeMusicFromQueue(getAdapterPosition());
notifyDataSetChanged();
int position = getAdapterPosition();

if(position >= 0 && position < musicList.size()) {
boolean isPlaying = currentMusic.title.equals(musicList.get(position).title);

if (!isPlaying) {
musicList.remove(position);
playerQueue.removeMusicFromQueue(position);
notifyItemRemoved(position);
}
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,21 @@ private void setUpSearchView() {

@Override
public boolean onQueryTextSubmit(String query) {
updateAdapter(ListHelper.searchMusicByName(unChangedList, query.toLowerCase()));
if(query.length() > 0) {
updateAdapter(ListHelper.searchMusicByName(unChangedList, query.toLowerCase()));
} else {
updateAdapter(unChangedList);
}
return true;
}

@Override
public boolean onQueryTextChange(String newText) {
updateAdapter(ListHelper.searchMusicByName(unChangedList, newText.toLowerCase()));
public boolean onQueryTextChange(String query) {
if(query.length() > 0) {
updateAdapter(ListHelper.searchMusicByName(unChangedList, query.toLowerCase()));
}else {
updateAdapter(unChangedList);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ public static HashMap<Integer, Integer> getThemeMap() {
}

public static Integer getTheme(Integer accentColor) {
return getThemeMap().get(accentColor);
Integer theme = getThemeMap().get(accentColor);
if(theme == null) {
return getThemeMap().get(R.color.blue);
}
return theme;
}

public static void applySettings(Activity activity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void onAudioFocusChange(final int focusChange) {
public PlayerManager(@NonNull PlayerService playerService) {
this.playerService = playerService;
this.context = playerService.getApplicationContext();
this.playerQueue = new PlayerQueue();
this.playerQueue = PlayerQueue.getInstance();
this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

Observer<Integer> progressObserver = percent -> {
Expand Down Expand Up @@ -174,7 +174,7 @@ public void setPlayerListener(PlayerListener listener) {
}

public void setMusicList(List<Music> musicList) {
playerQueue.setCurrentQueue(musicList);
playerQueue.setCurrentQueue(new ArrayList<>(musicList));
initMediaPlayer(); // play now
}

Expand All @@ -186,7 +186,7 @@ public void setMusic(Music music) {
}

public void addMusicQueue(List<Music> musicList) {
playerQueue.addMusicListToQueue(musicList);
playerQueue.addMusicListToQueue(new ArrayList<>(musicList));

if (!mediaPlayer.isPlaying())
initMediaPlayer(); // play when ready
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@
import java.util.Random;

public class PlayerQueue {
private static PlayerQueue instance = null;
private final Random random = new Random();
private List<Music> currentQueue;
private List<Integer> played;
private boolean shuffle = false;
private boolean repeat = false;
private int currentPosition = 0;

public static PlayerQueue getInstance() {
if (instance == null) {
instance = new PlayerQueue();
}
return instance;
}

private boolean isCurrentPositionOutOfBound(int pos) {
return pos >= currentQueue.size() || pos <= 0;
return pos >= currentQueue.size() || pos < 0;
}

public boolean isShuffle() {
Expand Down Expand Up @@ -85,11 +93,19 @@ public void prev() {
public void removeMusicFromQueue(int position) {
if (!isCurrentPositionOutOfBound(position)) {
currentQueue.remove(position);
if(currentPosition > position)
currentPosition -= 1;
}
}

public void swap(int one, int two) {
if (!isCurrentPositionOutOfBound(one) && !isCurrentPositionOutOfBound(two)) {
if(one == currentPosition) {
currentPosition = two;
}
else if(two == currentPosition) {
currentPosition = one;
}
Collections.swap(currentQueue, one, two);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ private void configureMediaSession() {

private boolean handleMediaButtonEvent(Intent mediaButtonEvent) {
boolean isSuccess = false;
if (mediaButtonEvent == null) {
return false;
}

KeyEvent keyEvent = mediaButtonEvent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);

Expand Down
2 changes: 1 addition & 1 deletion src/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath 'com.android.tools.build:gradle:7.3.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion src/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip

0 comments on commit 7771907

Please sign in to comment.