Skip to content

Commit

Permalink
implemented fragment view model, removed fragment callbacks, restruct…
Browse files Browse the repository at this point in the history
…ured adapter package, bug fix, version upgrade
  • Loading branch information
nuclearfog committed Oct 3, 2023
1 parent d20c835 commit 2c0d5bc
Show file tree
Hide file tree
Showing 45 changed files with 744 additions and 560 deletions.
5 changes: 2 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId 'org.nuclearfog.apollo'
minSdkVersion 16
targetSdkVersion 34
versionCode 26
versionName '1.3.5'
versionCode 27
versionName '1.3.6'
}

buildTypes {
Expand Down Expand Up @@ -55,5 +55,4 @@ dependencies {
implementation 'androidx.preference:preference:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.media:media:1.6.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
}
93 changes: 0 additions & 93 deletions app/src/main/java/org/nuclearfog/apollo/adapters/PagerAdapter.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import androidx.recyclerview.widget.RecyclerView;

import org.nuclearfog.apollo.R;
import org.nuclearfog.apollo.adapters.EqualizerAdapter;
import org.nuclearfog.apollo.adapters.EqualizerAdapter.BandLevelChangeListener;
import org.nuclearfog.apollo.player.AudioEffects;
import org.nuclearfog.apollo.ui.adapters.recyclerview.EqualizerAdapter;
import org.nuclearfog.apollo.ui.adapters.recyclerview.EqualizerAdapter.BandLevelChangeListener;
import org.nuclearfog.apollo.utils.MusicUtils;
import org.nuclearfog.apollo.utils.PreferenceUtils;
import org.nuclearfog.apollo.utils.ThemeUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,24 @@
import androidx.appcompat.widget.SearchView.OnQueryTextListener;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.viewpager.widget.ViewPager;

import org.nuclearfog.apollo.BuildConfig;
import org.nuclearfog.apollo.R;
import org.nuclearfog.apollo.adapters.PagerAdapter;
import org.nuclearfog.apollo.cache.ImageFetcher;
import org.nuclearfog.apollo.receiver.PlaybackStatus;
import org.nuclearfog.apollo.receiver.PlaybackStatus.PlayStatusListener;
import org.nuclearfog.apollo.service.MusicPlaybackService;
import org.nuclearfog.apollo.ui.adapters.viewpager.QueueAdapter;
import org.nuclearfog.apollo.ui.dialogs.DeleteDialog.DeleteDialogCallback;
import org.nuclearfog.apollo.ui.fragments.FragmentCallback;
import org.nuclearfog.apollo.ui.fragments.QueueFragment;
import org.nuclearfog.apollo.ui.views.PlayPauseButton;
import org.nuclearfog.apollo.ui.views.RepeatButton;
import org.nuclearfog.apollo.ui.views.RepeatingImageButton;
import org.nuclearfog.apollo.ui.views.RepeatingImageButton.RepeatListener;
import org.nuclearfog.apollo.ui.views.ShuffleButton;
import org.nuclearfog.apollo.utils.ApolloUtils;
import org.nuclearfog.apollo.utils.FragmentViewModel;
import org.nuclearfog.apollo.utils.MusicUtils;
import org.nuclearfog.apollo.utils.MusicUtils.ServiceToken;
import org.nuclearfog.apollo.utils.NavUtils;
Expand Down Expand Up @@ -158,10 +157,6 @@ public class AudioPlayerActivity extends AppCompatActivity implements ServiceCon
* Handler used to update the current time
*/
private TimeHandler mTimeHandler;
/**
* Pager adpater
*/
private PagerAdapter mPagerAdapter;
/**
* ViewPager
*/
Expand All @@ -177,6 +172,8 @@ public class AudioPlayerActivity extends AppCompatActivity implements ServiceCon

private PreferenceUtils mPrefs;

private FragmentViewModel viewModel;

private long mPosOverride = -1L;
private long mStartSeekPos = 0L;
private long mLastSeekEventTime;
Expand Down Expand Up @@ -235,13 +232,13 @@ protected void onCreate(Bundle savedInstanceState) {
mResources.themeActionBar(actionBar, R.string.app_name);
actionBar.setDisplayHomeAsUpEnabled(true);
}
viewModel = new ViewModelProvider(this).get(FragmentViewModel.class);
// View pager
mViewPager = findViewById(R.id.audio_player_pager);
// Offscreen pager loading limit
mViewPager.setOffscreenPageLimit(1);
// Initialize the pager adapter and attach
mPagerAdapter = new PagerAdapter(this, getSupportFragmentManager());
mPagerAdapter.add(new QueueFragment(), null);
QueueAdapter mPagerAdapter = new QueueAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mPagerAdapter);
// set colors
int themeColor = mPrefs.getDefaultThemeColor();
Expand Down Expand Up @@ -329,7 +326,6 @@ protected void onDestroy() {
if (MusicUtils.isConnected()) {
MusicUtils.unbindFromService(mToken);
}
mPagerAdapter.clear();
super.onDestroy();
}

Expand Down Expand Up @@ -907,24 +903,14 @@ private void shareCurrentTrack() {
* reload queue tracks
*/
private void refreshQueue() {
if (mPagerAdapter != null && mPagerAdapter.getCount() > 0) {
Fragment fragment = mPagerAdapter.getItem(0);
if (fragment instanceof FragmentCallback && !fragment.isDetached()) {
((FragmentCallback) fragment).refresh();
}
}
viewModel.notify(FragmentViewModel.REFRESH);
}

/**
* set current track in the queue
*/
private void setQueueTrack() {
if (mPagerAdapter != null && mPagerAdapter.getCount() > 0) {
Fragment fragment = mPagerAdapter.getItem(0);
if (fragment instanceof FragmentCallback && !fragment.isDetached()) {
((FragmentCallback) fragment).setCurrentTrack();
}
}
viewModel.notify(FragmentViewModel.SET_CURRENT_TRACK);
}

/**
Expand Down
Loading

0 comments on commit 2c0d5bc

Please sign in to comment.