Fix loading songs after permission granted

This commit is contained in:
Hemanth S 2020-05-17 01:29:18 +05:30
parent 2892c42628
commit 6d9860016e
8 changed files with 27 additions and 20 deletions

View file

@ -24,7 +24,7 @@ android {
vectorDrawables.useSupportLibrary = true
applicationId "code.name.monkey.retromusic"
versionCode 434
versionCode 435
versionName '3.5.300'
multiDexEnabled true

View file

@ -100,10 +100,16 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
public static final int APP_INTRO_REQUEST = 100;
public static final String EXPAND_PANEL = "expand_panel";
private static final int APP_UPDATE_REQUEST_CODE = 9002;
private final IntentFilter mIntentFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
private MainActivityFragmentCallbacks currentFragment;
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
String action = intent.getAction();
Log.i(TAG, "onReceive: " + action);
if (action != null && action.equals(MusicService.MEDIA_STORE_CHANGED)) {
setCurrentFragment(SongsFragment.newInstance(), SongsFragment.TAG, true);
}
if (action != null && action.equals(Intent.ACTION_SCREEN_OFF)) {
if (PreferenceUtil.getInstance(context).getLockScreen() && MusicPlayerRemote.isPlaying()) {
final Intent activity = new Intent(context, LockScreenActivity.class);
@ -114,8 +120,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
}
}
};
private final IntentFilter mIntentFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
private MainActivityFragmentCallbacks currentFragment;
private boolean blockRequestPermissions = false;
private MaterialCab cab;
private AppBarLayout mAppBarLayout;
@ -177,6 +181,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
selectedFragment(item.getItemId());
return true;
});
mIntentFilter.addAction(MusicService.MEDIA_STORE_CHANGED);
}
@ -208,8 +213,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
blockRequestPermissions = false;
if (!hasPermissions()) {
requestPermissions();
} else {
selectedFragment(PreferenceUtil.getInstance(this).getLastPage());
}
} else if (requestCode == APP_UPDATE_REQUEST_CODE) {
if (resultCode != RESULT_OK) {
@ -412,12 +415,14 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
mAppBarLayout.removeOnOffsetChangedListener(onOffsetChangedListener);
}
public void setCurrentFragment(@NonNull Fragment fragment, @NonNull String tag) {
public void setCurrentFragment(@NonNull Fragment fragment, @NonNull String tag, boolean force) {
String currentTag = null;
if (getSupportFragmentManager().findFragmentByTag(tag) != null) {
currentTag = getSupportFragmentManager().findFragmentByTag(tag).getTag();
}
if (force) {
currentTag = null;
}
if (!tag.equals(currentTag)) {
getSupportFragmentManager()
.beginTransaction()
@ -681,29 +686,29 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
private void selectedFragment(final int itemId) {
switch (itemId) {
case R.id.action_album:
setCurrentFragment(AlbumsFragment.newInstance(), AlbumsFragment.TAG);
setCurrentFragment(AlbumsFragment.newInstance(), AlbumsFragment.TAG, false);
break;
case R.id.action_artist:
setCurrentFragment(ArtistsFragment.newInstance(), ArtistsFragment.TAG);
setCurrentFragment(ArtistsFragment.newInstance(), ArtistsFragment.TAG, false);
break;
case R.id.action_playlist:
setCurrentFragment(PlaylistsFragment.newInstance(), PlaylistsFragment.TAG);
setCurrentFragment(PlaylistsFragment.newInstance(), PlaylistsFragment.TAG, false);
break;
case R.id.action_genre:
setCurrentFragment(GenresFragment.newInstance(), GenresFragment.TAG);
setCurrentFragment(GenresFragment.newInstance(), GenresFragment.TAG, false);
break;
case R.id.action_playing_queue:
setCurrentFragment(PlayingQueueFragment.newInstance(), PlayingQueueFragment.TAG);
setCurrentFragment(PlayingQueueFragment.newInstance(), PlayingQueueFragment.TAG, false);
break;
case R.id.action_song:
setCurrentFragment(SongsFragment.newInstance(), SongsFragment.TAG);
setCurrentFragment(SongsFragment.newInstance(), SongsFragment.TAG, false);
break;
case R.id.action_folder:
setCurrentFragment(FoldersFragment.newInstance(this), FoldersFragment.TAG);
setCurrentFragment(FoldersFragment.newInstance(this), FoldersFragment.TAG, false);
break;
default:
case R.id.action_home:
setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG);
setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG,false);
break;
}
}

View file

@ -201,7 +201,7 @@ class SkuDetailsAdapter(
override fun onBindViewHolder(viewHolder: ViewHolder, i: Int) {
val skuDetails = skuDetailsList[i]
viewHolder.title.text = skuDetails.title.replace("(Retro Music Player)", "")
viewHolder.title.text = skuDetails.title.replace("(Retro Music Player \uD83C\uDFB5)", "")
.trim { it <= ' ' }
viewHolder.text.text = skuDetails.description
viewHolder.text.visibility = View.GONE

View file

@ -63,6 +63,7 @@ abstract class AbsBaseActivity : AbsThemeActivity() {
protected open fun onHasPermissionsChanged(hasPermissions: Boolean) {
// implemented by sub classes
println(hasPermissions)
}
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
@ -136,7 +137,7 @@ abstract class AbsBaseActivity : AbsThemeActivity() {
}
}
hadPermissions = true
onHasPermissionsChanged(true)
onHasPermissionsChanged(true)
}
}

View file

@ -133,6 +133,7 @@ abstract class AbsMusicServiceActivity : AbsBaseActivity(), MusicServiceEventLis
true
) // just in case we need to know this at some point
sendBroadcast(intent)
println("sendBroadcast $hasPermissions")
}
override fun getPermissionsToRequest(): Array<String> {

View file

@ -15,7 +15,7 @@ class AlbumsFragment :
AbsLibraryPagerRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridLayoutManager>(),
MainActivityFragmentCallbacks {
lateinit var albumViewModel: AlbumViewModel
private lateinit var albumViewModel: AlbumViewModel
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

View file

@ -17,7 +17,7 @@ class SongsFragment :
AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdapter, GridLayoutManager>(),
MainActivityFragmentCallbacks {
lateinit var songViewModel: SongsViewModel
private lateinit var songViewModel: SongsViewModel
override val emptyMessage: Int
get() = R.string.no_songs

View file

@ -14,7 +14,7 @@
<dimen name="list_item_image_icon_padding">8dp</dimen>
<dimen name="mini_player_height">48dp</dimen>
<dimen name="mini_player_height">56dp</dimen>
<dimen name="app_widget_classic_height">96dp</dimen>
<dimen name="app_widget_classic_image_size">96dp</dimen>