Merge pull request #657 from h4h13/maintabs

Maintabs
This commit is contained in:
Hemanth S 2020-02-20 20:52:21 +05:30 committed by GitHub
commit 05b3c18848
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 1535 additions and 1613 deletions

View file

@ -417,7 +417,6 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage
private fun loadLRCLyrics() {
lyricsView.resetView("Empty")
val song = MusicPlayerRemote.currentSong
println("${song.title} ${song.artistName}")
if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
showLyricsLocal(LyricUtil.getLocalLyricFile(song.title, song.artistName))
}

View file

@ -0,0 +1,756 @@
/*
* Copyright (c) 2020 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.activities;
import android.app.ActivityOptions;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import code.name.monkey.appthemehelper.util.ATHUtil;
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity;
import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog;
import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment;
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment;
import code.name.monkey.retromusic.fragments.mainactivity.AlbumsFragment;
import code.name.monkey.retromusic.fragments.mainactivity.ArtistsFragment;
import code.name.monkey.retromusic.fragments.mainactivity.GenresFragment;
import code.name.monkey.retromusic.fragments.mainactivity.PlayingQueueFragment;
import code.name.monkey.retromusic.fragments.mainactivity.PlaylistsFragment;
import code.name.monkey.retromusic.fragments.mainactivity.SongsFragment;
import code.name.monkey.retromusic.fragments.mainactivity.folders.FoldersFragment;
import code.name.monkey.retromusic.fragments.mainactivity.home.BannerHomeFragment;
import code.name.monkey.retromusic.helper.MusicPlayerRemote;
import code.name.monkey.retromusic.helper.SearchQueryHelper;
import code.name.monkey.retromusic.helper.SortOrder.AlbumSortOrder;
import code.name.monkey.retromusic.helper.SortOrder.ArtistSortOrder;
import code.name.monkey.retromusic.helper.SortOrder.SongSortOrder;
import code.name.monkey.retromusic.interfaces.CabHolder;
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks;
import code.name.monkey.retromusic.loaders.AlbumLoader;
import code.name.monkey.retromusic.loaders.ArtistLoader;
import code.name.monkey.retromusic.loaders.PlaylistSongsLoader;
import code.name.monkey.retromusic.model.Song;
import code.name.monkey.retromusic.service.MusicService;
import code.name.monkey.retromusic.util.AppRater;
import code.name.monkey.retromusic.util.NavigationUtil;
import code.name.monkey.retromusic.util.PreferenceUtil;
import code.name.monkey.retromusic.util.RetroColorUtil;
import code.name.monkey.retromusic.util.RetroUtil;
import com.afollestad.materialcab.MaterialCab;
import com.afollestad.materialcab.MaterialCab.Callback;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.card.MaterialCardView;
import java.util.ArrayList;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created by hemanths on 2020-02-19.
*/
public class MainActivity extends AbsSlidingMusicPanelActivity
implements CabHolder, SharedPreferences.OnSharedPreferenceChangeListener {
public static final String TAG = MainActivity.class.getSimpleName();
public static final int APP_INTRO_REQUEST = 100;
public static final String EXPAND_PANEL = "expand_panel";
@Nullable
MainActivityFragmentCallbacks currentFragment;
private boolean blockRequestPermissions = false;
private MaterialCab cab;
private AppBarLayout mAppBarLayout;
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, final Intent intent) {
String action = intent.getAction();
if (action != null && action.equals(Intent.ACTION_SCREEN_OFF)) {
if (PreferenceUtil.getInstance(context).getLockScreen() && MusicPlayerRemote.isPlaying()) {
final Intent activity = new Intent(context, LockScreenActivity.class);
activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
ActivityCompat.startActivity(context, activity, null);
}
}
}
};
private final IntentFilter mIntentFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
private Toolbar mToolbar;
private MaterialCardView mToolbarContainer;
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
setDrawUnderStatusBar();
super.onCreate(savedInstanceState);
setStatusbarColorAuto();
setNavigationbarColorAuto();
setLightNavigationBar(true);
setTaskDescriptionColorAuto();
hideStatusBar();
setBottomBarVisibility(View.VISIBLE);
getBottomNavigationView().setSelectedItemId(PreferenceUtil.getInstance(this).getLastPage());
getBottomNavigationView().setOnNavigationItemSelectedListener(item -> {
PreferenceUtil.getInstance(MainActivity.this).setLastPage(item.getItemId());
selectedFragment(item.getItemId());
return true;
});
if (savedInstanceState == null) {
setMusicChooser(PreferenceUtil.getInstance(this).getLastMusicChooser());
} else {
restoreCurrentFragment();
}
mToolbarContainer = findViewById(R.id.toolbarContainer);
mToolbar = findViewById(R.id.toolbar);
mAppBarLayout = findViewById(R.id.appBarLayout);
checkShowChangelog();
AppRater.appLaunched(this);
setupToolbar();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == APP_INTRO_REQUEST) {
blockRequestPermissions = false;
if (!hasPermissions()) {
requestPermissions();
}
}
}
@Override
protected void onResume() {
super.onResume();
registerReceiver(mBroadcastReceiver, mIntentFilter);
PreferenceUtil.getInstance(this).registerOnSharedPreferenceChangedListener(this);
if (getIntent().hasExtra(EXPAND_PANEL)) {
if (getIntent().getBooleanExtra(EXPAND_PANEL, false)) {
expandPanel();
getIntent().putExtra(EXPAND_PANEL, false);
}
}
}
@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(mBroadcastReceiver);
PreferenceUtil.getInstance(this).unregisterOnSharedPreferenceChangedListener(this);
}
public void addOnAppBarOffsetChangedListener(
@NonNull AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) {
mAppBarLayout.addOnOffsetChangedListener(onOffsetChangedListener);
}
public int getTotalAppBarScrollingRange() {
return mAppBarLayout.getTotalScrollRange();
}
@Override
public boolean handleBackPress() {
if (cab != null && cab.isActive()) {
cab.finish();
return true;
}
return super.handleBackPress() || (currentFragment != null && currentFragment.handleBackPress());
}
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
if (isPlaylistPage()) {
menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title)
.setIcon(R.drawable.ic_playlist_add_white_24dp).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
if (isHomePage()) {
menu.add(0, R.id.action_search, 0, getString(R.string.action_search))
.setIcon(R.drawable.ic_mic_white_24dp).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
Fragment fragment = getCurrentFragment();
if (fragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment) {
AbsLibraryPagerRecyclerViewCustomGridSizeFragment currentFragment
= (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) fragment;
if (currentFragment instanceof SongsFragment) {
menu.removeItem(R.id.action_grid_size);
menu.removeItem(R.id.action_layout_type);
} else {
MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size);
if (RetroUtil.isLandscape()) {
gridSizeItem.setTitle(R.string.action_grid_size_land);
}
setUpGridSizeMenu(currentFragment, gridSizeItem.getSubMenu());
MenuItem layoutItem = menu.findItem(R.id.action_layout_type);
setupLayoutMenu(currentFragment, layoutItem.getSubMenu());
}
setUpSortOrderMenu(currentFragment, menu.findItem(R.id.action_sort_order).getSubMenu());
} else {
menu.removeItem(R.id.action_layout_type);
menu.removeItem(R.id.action_grid_size);
menu.removeItem(R.id.action_sort_order);
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(@NonNull final MenuItem item) {
Fragment fragment = getCurrentFragment();
if (fragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment) {
AbsLibraryPagerRecyclerViewCustomGridSizeFragment currentFragment
= (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) fragment;
if (handleGridSizeMenuItem(currentFragment, item)) {
return true;
}
if (handleLayoutResType(currentFragment, item)) {
return true;
}
if (handleSortOrderMenuItem(currentFragment, item)) {
return true;
}
}
int id = item.getItemId();
switch (id) {
case R.id.action_search:
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, mToolbarContainer,
getString(R.string.transition_toolbar));
NavigationUtil.goToSearch(this, true, options);
break;
case R.id.action_new_playlist:
CreatePlaylistDialog.create().show(getSupportFragmentManager(), "CREATE_PLAYLIST");
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
ToolbarContentTintHelper.handleOnPrepareOptionsMenu(this, mToolbar);
return super.onPrepareOptionsMenu(menu);
}
@Override
public void onServiceConnected() {
super.onServiceConnected();
handlePlaybackIntent(getIntent());
}
@Override
public void onSharedPreferenceChanged(final @NonNull SharedPreferences sharedPreferences,
final @NonNull String key) {
if (key.equals(PreferenceUtil.GENERAL_THEME) || key.equals(PreferenceUtil.BLACK_THEME) ||
key.equals(PreferenceUtil.ADAPTIVE_COLOR_APP) || key.equals(PreferenceUtil.DOMINANT_COLOR) ||
key.equals(PreferenceUtil.USER_NAME) || key.equals(PreferenceUtil.TOGGLE_FULL_SCREEN) ||
key.equals(PreferenceUtil.TOGGLE_VOLUME) || key.equals(PreferenceUtil.ROUND_CORNERS) ||
key.equals(PreferenceUtil.CAROUSEL_EFFECT) || key == PreferenceUtil.NOW_PLAYING_SCREEN_ID ||
key == PreferenceUtil.TOGGLE_GENRE || key.equals(PreferenceUtil.BANNER_IMAGE_PATH) ||
key == PreferenceUtil.PROFILE_IMAGE_PATH || key == PreferenceUtil.CIRCULAR_ALBUM_ART ||
key == PreferenceUtil.KEEP_SCREEN_ON || key == PreferenceUtil.TOGGLE_SEPARATE_LINE ||
key == PreferenceUtil.TOGGLE_HOME_BANNER || key == PreferenceUtil.TOGGLE_ADD_CONTROLS ||
key == PreferenceUtil.ALBUM_COVER_STYLE || key == PreferenceUtil.HOME_ARTIST_GRID_STYLE ||
key == PreferenceUtil.ALBUM_COVER_TRANSFORM || key == PreferenceUtil.DESATURATED_COLOR ||
key == PreferenceUtil.TAB_TEXT_MODE || key == PreferenceUtil.LIBRARY_CATEGORIES
) {
postRecreate();
}
}
@NotNull
@Override
public MaterialCab openCab(final int menuRes, @NotNull final Callback callback) {
if (cab != null && cab.isActive()) {
cab.finish();
}
cab = new MaterialCab(this, R.id.cab_stub)
.setMenu(menuRes)
.setCloseDrawableRes(R.drawable.ic_close_white_24dp)
.setBackgroundColor(
RetroColorUtil.shiftBackgroundColorForLightText(
ATHUtil.INSTANCE.resolveColor(this, R.attr.colorSurface)))
.start(callback);
return cab;
}
public void removeOnAppBarOffsetChangedListener(
@NonNull AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) {
mAppBarLayout.removeOnOffsetChangedListener(onOffsetChangedListener);
}
public void setCurrentFragment(Fragment fragment, String tag) {
String currentTag = null;
if (getSupportFragmentManager().findFragmentByTag(tag) != null) {
currentTag = getSupportFragmentManager().findFragmentByTag(tag).getTag();
}
if (!tag.equals(currentTag)) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, fragment, tag)
.commit();
currentFragment = (MainActivityFragmentCallbacks) fragment;
}
}
public void setMusicChooser(final int option) {
PreferenceUtil.getInstance(this).setLastMusicChooser(option);
if (option == OptionsSheetDialogFragment.FOLDER) {
setCurrentFragment(FoldersFragment.newInstance(this), FoldersFragment.TAG);
} else {
selectedFragment(PreferenceUtil.getInstance(this).getLastPage());
}
}
@NotNull
@Override
protected View createContentView() {
return wrapSlidingMusicPanel(R.layout.activity_main_content);
}
@Override
protected void requestPermissions() {
if (!blockRequestPermissions) {
super.requestPermissions();
}
}
private void checkShowChangelog() {
try {
final PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
final int currentVersion = pInfo.versionCode;
if (currentVersion != PreferenceUtil.getInstance(this).getLastChangelogVersion()) {
startActivityForResult(new Intent(this, WhatsNewActivity.class), APP_INTRO_REQUEST);
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
@Nullable
private Fragment getCurrentFragment() {
return getSupportFragmentManager().findFragmentById(R.id.fragment_container);
}
private boolean handleGridSizeMenuItem(
@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment,
@NonNull MenuItem item) {
int gridSize = 0;
switch (item.getItemId()) {
case R.id.action_grid_size_1:
gridSize = 1;
break;
case R.id.action_grid_size_2:
gridSize = 2;
break;
case R.id.action_grid_size_3:
gridSize = 3;
break;
case R.id.action_grid_size_4:
gridSize = 4;
break;
case R.id.action_grid_size_5:
gridSize = 5;
break;
case R.id.action_grid_size_6:
gridSize = 6;
break;
case R.id.action_grid_size_7:
gridSize = 7;
break;
case R.id.action_grid_size_8:
gridSize = 8;
break;
}
if (gridSize > 0) {
item.setChecked(true);
fragment.setAndSaveGridSize(gridSize);
return true;
}
return false;
}
private boolean handleLayoutResType(
final AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment,
final MenuItem item) {
int layoutRes = -1;
switch (item.getItemId()) {
case R.id.action_layout_normal:
layoutRes = R.layout.item_grid;
break;
case R.id.action_layout_card:
layoutRes = R.layout.item_card;
break;
case R.id.action_layout_colored_card:
layoutRes = R.layout.item_card_color;
break;
case R.id.action_layout_circular:
layoutRes = R.layout.item_grid_circle;
break;
case R.id.action_layout_image:
layoutRes = R.layout.image;
break;
case R.id.action_layout_gradient_image:
layoutRes = R.layout.item_image_gradient;
break;
}
if (layoutRes != -1) {
item.setChecked(true);
fragment.setAndSaveLayoutRes(layoutRes);
return true;
}
return false;
}
private void handlePlaybackIntent(@Nullable Intent intent) {
if (intent == null) {
return;
}
Uri uri = intent.getData();
String mimeType = intent.getType();
boolean handled = false;
if (intent.getAction() != null && intent.getAction()
.equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
final List<Song> songs = SearchQueryHelper.getSongs(this, intent.getExtras());
if (MusicPlayerRemote.getShuffleMode() == MusicService.SHUFFLE_MODE_SHUFFLE) {
MusicPlayerRemote.openAndShuffleQueue(songs, true);
} else {
MusicPlayerRemote.openQueue(songs, 0, true);
}
handled = true;
}
if (uri != null && uri.toString().length() > 0) {
MusicPlayerRemote.playFromUri(uri);
handled = true;
} else if (MediaStore.Audio.Playlists.CONTENT_TYPE.equals(mimeType)) {
final int id = (int) parseIdFromIntent(intent, "playlistId", "playlist");
if (id >= 0) {
int position = intent.getIntExtra("position", 0);
List<Song> songs = new ArrayList<>(PlaylistSongsLoader.getPlaylistSongList(this, id));
MusicPlayerRemote.openQueue(songs, position, true);
handled = true;
}
} else if (MediaStore.Audio.Albums.CONTENT_TYPE.equals(mimeType)) {
final int id = (int) parseIdFromIntent(intent, "albumId", "album");
if (id >= 0) {
int position = intent.getIntExtra("position", 0);
MusicPlayerRemote.openQueue(AlbumLoader.getAlbum(this, id).getSongs(), position, true);
handled = true;
}
} else if (MediaStore.Audio.Artists.CONTENT_TYPE.equals(mimeType)) {
final int id = (int) parseIdFromIntent(intent, "artistId", "artist");
if (id >= 0) {
int position = intent.getIntExtra("position", 0);
MusicPlayerRemote.openQueue(ArtistLoader.getArtist(this, id).getSongs(), position, true);
handled = true;
}
}
if (handled) {
setIntent(new Intent());
}
}
private boolean handleSortOrderMenuItem(
@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment
fragment, @NonNull MenuItem item) {
String sortOrder = null;
if (fragment instanceof AlbumsFragment) {
switch (item.getItemId()) {
case R.id.action_album_sort_order_asc:
sortOrder = AlbumSortOrder.ALBUM_A_Z;
break;
case R.id.action_album_sort_order_desc:
sortOrder = AlbumSortOrder.ALBUM_Z_A;
break;
case R.id.action_album_sort_order_artist:
sortOrder = AlbumSortOrder.ALBUM_ARTIST;
break;
case R.id.action_album_sort_order_year:
sortOrder = AlbumSortOrder.ALBUM_YEAR;
break;
}
} else if (fragment instanceof ArtistsFragment) {
switch (item.getItemId()) {
case R.id.action_artist_sort_order_asc:
sortOrder = ArtistSortOrder.ARTIST_A_Z;
break;
case R.id.action_artist_sort_order_desc:
sortOrder = ArtistSortOrder.ARTIST_Z_A;
break;
}
} else if (fragment instanceof SongsFragment) {
switch (item.getItemId()) {
case R.id.action_song_sort_order_asc:
sortOrder = SongSortOrder.SONG_A_Z;
break;
case R.id.action_song_sort_order_desc:
sortOrder = SongSortOrder.SONG_Z_A;
break;
case R.id.action_song_sort_order_artist:
sortOrder = SongSortOrder.SONG_ARTIST;
break;
case R.id.action_song_sort_order_album:
sortOrder = SongSortOrder.SONG_ALBUM;
break;
case R.id.action_song_sort_order_year:
sortOrder = SongSortOrder.SONG_YEAR;
break;
case R.id.action_song_sort_order_date:
sortOrder = SongSortOrder.SONG_DATE;
break;
case R.id.action_song_sort_order_composer:
sortOrder = SongSortOrder.COMPOSER;
break;
}
}
if (sortOrder != null) {
item.setChecked(true);
fragment.setAndSaveSortOrder(sortOrder);
return true;
}
return false;
}
private boolean isHomePage() {
return getSupportFragmentManager().findFragmentByTag(BannerHomeFragment.TAG) instanceof BannerHomeFragment;
}
private boolean isPlaylistPage() {
return getSupportFragmentManager().findFragmentByTag(PlaylistsFragment.TAG) instanceof PlaylistsFragment;
}
private long parseIdFromIntent(@NonNull Intent intent, String longKey,
String stringKey) {
long id = intent.getLongExtra(longKey, -1);
if (id < 0) {
String idString = intent.getStringExtra(stringKey);
if (idString != null) {
try {
id = Long.parseLong(idString);
} catch (NumberFormatException e) {
Log.e(TAG, e.getMessage());
}
}
}
return id;
}
private void restoreCurrentFragment() {
currentFragment = (MainActivityFragmentCallbacks) getSupportFragmentManager()
.findFragmentById(R.id.fragment_container);
}
private void selectedFragment(final int itemId) {
switch (itemId) {
case R.id.action_album:
setCurrentFragment(AlbumsFragment.newInstance(), AlbumsFragment.TAG);
break;
case R.id.action_artist:
setCurrentFragment(ArtistsFragment.newInstance(), ArtistsFragment.TAG);
break;
case R.id.action_playlist:
setCurrentFragment(PlaylistsFragment.newInstance(), PlaylistsFragment.TAG);
break;
case R.id.action_genre:
setCurrentFragment(GenresFragment.newInstance(), GenresFragment.TAG);
break;
case R.id.action_playing_queue:
setCurrentFragment(PlayingQueueFragment.newInstance(), PlayingQueueFragment.TAG);
break;
case R.id.action_song:
setCurrentFragment(SongsFragment.newInstance(), SongsFragment.TAG);
break;
default:
case R.id.action_home:
setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG);
break;
}
}
private void setUpGridSizeMenu(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment,
@NonNull SubMenu gridSizeMenu) {
switch (fragment.getGridSize()) {
case 1:
gridSizeMenu.findItem(R.id.action_grid_size_1).setChecked(true);
break;
case 2:
gridSizeMenu.findItem(R.id.action_grid_size_2).setChecked(true);
break;
case 3:
gridSizeMenu.findItem(R.id.action_grid_size_3).setChecked(true);
break;
case 4:
gridSizeMenu.findItem(R.id.action_grid_size_4).setChecked(true);
break;
case 5:
gridSizeMenu.findItem(R.id.action_grid_size_5).setChecked(true);
break;
case 6:
gridSizeMenu.findItem(R.id.action_grid_size_6).setChecked(true);
break;
case 7:
gridSizeMenu.findItem(R.id.action_grid_size_7).setChecked(true);
break;
case 8:
gridSizeMenu.findItem(R.id.action_grid_size_8).setChecked(true);
break;
}
int maxGridSize = fragment.getMaxGridSize();
if (maxGridSize < 8) {
gridSizeMenu.findItem(R.id.action_grid_size_8).setVisible(false);
}
if (maxGridSize < 7) {
gridSizeMenu.findItem(R.id.action_grid_size_7).setVisible(false);
}
if (maxGridSize < 6) {
gridSizeMenu.findItem(R.id.action_grid_size_6).setVisible(false);
}
if (maxGridSize < 5) {
gridSizeMenu.findItem(R.id.action_grid_size_5).setVisible(false);
}
if (maxGridSize < 4) {
gridSizeMenu.findItem(R.id.action_grid_size_4).setVisible(false);
}
if (maxGridSize < 3) {
gridSizeMenu.findItem(R.id.action_grid_size_3).setVisible(false);
}
}
private void setUpSortOrderMenu(
@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment,
@NonNull SubMenu sortOrderMenu) {
String currentSortOrder = fragment.getSortOrder();
sortOrderMenu.clear();
if (fragment instanceof AlbumsFragment) {
sortOrderMenu.add(0, R.id.action_album_sort_order_asc, 0, R.string.sort_order_a_z)
.setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_A_Z));
sortOrderMenu.add(0, R.id.action_album_sort_order_desc, 1, R.string.sort_order_z_a)
.setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_Z_A));
sortOrderMenu.add(0, R.id.action_album_sort_order_artist, 2, R.string.sort_order_artist)
.setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_ARTIST));
sortOrderMenu.add(0, R.id.action_album_sort_order_year, 3, R.string.sort_order_year)
.setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_YEAR));
} else if (fragment instanceof ArtistsFragment) {
sortOrderMenu.add(0, R.id.action_artist_sort_order_asc, 0, R.string.sort_order_a_z)
.setChecked(currentSortOrder.equals(ArtistSortOrder.ARTIST_A_Z));
sortOrderMenu.add(0, R.id.action_artist_sort_order_desc, 1, R.string.sort_order_z_a)
.setChecked(currentSortOrder.equals(ArtistSortOrder.ARTIST_Z_A));
} else if (fragment instanceof SongsFragment) {
sortOrderMenu.add(0, R.id.action_song_sort_order_asc, 0, R.string.sort_order_a_z)
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_A_Z));
sortOrderMenu.add(0, R.id.action_song_sort_order_desc, 1, R.string.sort_order_z_a)
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_Z_A));
sortOrderMenu.add(0, R.id.action_song_sort_order_artist, 2, R.string.sort_order_artist)
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_ARTIST));
sortOrderMenu.add(0, R.id.action_song_sort_order_album, 3, R.string.sort_order_album)
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_ALBUM));
sortOrderMenu.add(0, R.id.action_song_sort_order_year, 4, R.string.sort_order_year)
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_YEAR));
sortOrderMenu.add(0, R.id.action_song_sort_order_date, 5, R.string.sort_order_date)
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_DATE));
sortOrderMenu.add(0, R.id.action_song_sort_order_composer, 6, R.string.sort_order_composer)
.setChecked(currentSortOrder.equals(SongSortOrder.COMPOSER));
}
sortOrderMenu.setGroupCheckable(0, true, true);
}
private void setupLayoutMenu(
@NonNull final AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment,
@NonNull final SubMenu subMenu) {
switch (fragment.itemLayoutRes()) {
case R.layout.item_card:
subMenu.findItem(R.id.action_layout_card).setChecked(true);
break;
case R.layout.item_grid:
subMenu.findItem(R.id.action_layout_normal).setChecked(true);
break;
case R.layout.item_card_color:
subMenu.findItem(R.id.action_layout_colored_card).setChecked(true);
break;
case R.layout.item_grid_circle:
subMenu.findItem(R.id.action_layout_circular).setChecked(true);
break;
case R.layout.image:
subMenu.findItem(R.id.action_layout_image).setChecked(true);
break;
case R.layout.item_image_gradient:
subMenu.findItem(R.id.action_layout_gradient_image).setChecked(true);
break;
}
}
private void setupToolbar() {
mToolbar.setBackgroundColor(Color.TRANSPARENT);
mToolbarContainer.setCardBackgroundColor(
ColorStateList.valueOf(ATHUtil.INSTANCE.resolveColor(this, R.attr.colorSurface)));
setSupportActionBar(mToolbar);
mToolbar.setOnClickListener(v -> {
ActivityOptions options = ActivityOptions
.makeSceneTransitionAnimation(this, mToolbarContainer, getString(R.string.transition_toolbar));
NavigationUtil.goToSearch(this, options);
});
mToolbar.setNavigationOnClickListener(
v -> {
Fragment fragment = getCurrentFragment();
if (fragment instanceof FoldersFragment) {
OptionsSheetDialogFragment.newInstance(OptionsSheetDialogFragment.FOLDER)
.show(getSupportFragmentManager(), "Main_Menu");
} else {
OptionsSheetDialogFragment.newInstance(OptionsSheetDialogFragment.LIBRARY)
.show(getSupportFragmentManager(), "Main_Menu");
}
});
}
}

View file

@ -1,272 +0,0 @@
package code.name.monkey.retromusic.activities
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.SharedPreferences
import android.os.Bundle
import android.provider.MediaStore
import android.util.Log
import android.view.View
import androidx.core.app.ActivityCompat
import androidx.fragment.app.Fragment
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
import code.name.monkey.retromusic.fragments.mainactivity.LibraryFragment
import code.name.monkey.retromusic.fragments.mainactivity.folders.FoldersFragment
import code.name.monkey.retromusic.fragments.mainactivity.home.BannerHomeFragment
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.helper.SearchQueryHelper
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks
import code.name.monkey.retromusic.loaders.AlbumLoader
import code.name.monkey.retromusic.loaders.ArtistLoader
import code.name.monkey.retromusic.loaders.PlaylistSongsLoader
import code.name.monkey.retromusic.service.MusicService
import code.name.monkey.retromusic.util.AppRater
import code.name.monkey.retromusic.util.PreferenceUtil
import java.util.ArrayList
class MainActivity : AbsSlidingMusicPanelActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
private lateinit var currentFragment: MainActivityFragmentCallbacks
private var blockRequestPermissions: Boolean = false
private val broadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val action = intent.action
if (action != null && action == Intent.ACTION_SCREEN_OFF) {
if (PreferenceUtil.getInstance(this@MainActivity).lockScreen && MusicPlayerRemote.isPlaying) {
val activity = Intent(context, LockScreenActivity::class.java)
activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
activity.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
ActivityCompat.startActivity(context, activity, null)
}
}
}
}
override fun createContentView(): View {
return wrapSlidingMusicPanel(R.layout.activity_main_content)
}
override fun onCreate(
savedInstanceState: Bundle?
) {
setDrawUnderStatusBar()
super.onCreate(savedInstanceState)
getBottomNavigationView().selectedItemId = PreferenceUtil.getInstance(this).lastPage
getBottomNavigationView().setOnNavigationItemSelectedListener {
PreferenceUtil.getInstance(this).lastPage = it.itemId
selectedFragment(it.itemId)
true
}
if (savedInstanceState == null) {
setMusicChooser(PreferenceUtil.getInstance(this).lastMusicChooser)
} else {
restoreCurrentFragment()
}
checkShowChangelog()
AppRater.appLaunched(this)
}
private fun checkShowChangelog() {
try {
val pInfo = packageManager.getPackageInfo(packageName, 0)
val currentVersion = pInfo.versionCode
if (currentVersion != PreferenceUtil.getInstance(this).lastChangelogVersion) {
startActivityForResult(
Intent(this, WhatsNewActivity::class.java),
APP_INTRO_REQUEST
)
}
} catch (e: Throwable) {
e.printStackTrace()
}
}
override fun onResume() {
super.onResume()
val screenOnOff = IntentFilter()
screenOnOff.addAction(Intent.ACTION_SCREEN_OFF)
registerReceiver(broadcastReceiver, screenOnOff)
PreferenceUtil.getInstance(this).registerOnSharedPreferenceChangedListener(this)
if (intent.hasExtra("expand")) {
if (intent.getBooleanExtra("expand", false)) {
expandPanel()
intent.putExtra("expand", false)
}
}
}
override fun onDestroy() {
super.onDestroy()
unregisterReceiver(broadcastReceiver)
PreferenceUtil.getInstance(this).unregisterOnSharedPreferenceChangedListener(this)
}
private fun setCurrentFragment(fragment: Fragment, tag: String) {
if (tag != supportFragmentManager.findFragmentById(R.id.fragment_container)?.tag) {
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, fragment, tag).commit()
currentFragment = fragment as MainActivityFragmentCallbacks
}
}
private fun restoreCurrentFragment() {
currentFragment =
supportFragmentManager.findFragmentById(R.id.fragment_container) as MainActivityFragmentCallbacks
}
private fun handlePlaybackIntent(intent: Intent?) {
if (intent == null) {
return
}
val uri = intent.data
val mimeType = intent.type
var handled = false
if (intent.action != null && intent.action == MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH) {
val songs = SearchQueryHelper.getSongs(this, intent.extras!!)
if (MusicPlayerRemote.shuffleMode == MusicService.SHUFFLE_MODE_SHUFFLE) {
MusicPlayerRemote.openAndShuffleQueue(songs, true)
} else {
MusicPlayerRemote.openQueue(songs, 0, true)
}
handled = true
}
if (uri != null && uri.toString().isNotEmpty()) {
MusicPlayerRemote.playFromUri(uri)
handled = true
} else if (MediaStore.Audio.Playlists.CONTENT_TYPE == mimeType) {
val id = parseIdFromIntent(intent, "playlistId", "playlist").toInt()
if (id >= 0) {
val position = intent.getIntExtra("position", 0)
val songs = ArrayList(PlaylistSongsLoader.getPlaylistSongList(this, id))
MusicPlayerRemote.openQueue(songs, position, true)
handled = true
}
} else if (MediaStore.Audio.Albums.CONTENT_TYPE == mimeType) {
val id = parseIdFromIntent(intent, "albumId", "album").toInt()
if (id >= 0) {
val position = intent.getIntExtra("position", 0)
MusicPlayerRemote.openQueue(AlbumLoader.getAlbum(this, id).songs!!, position, true)
handled = true
}
} else if (MediaStore.Audio.Artists.CONTENT_TYPE == mimeType) {
val id = parseIdFromIntent(intent, "artistId", "artist").toInt()
if (id >= 0) {
val position = intent.getIntExtra("position", 0)
MusicPlayerRemote.openQueue(ArtistLoader.getArtist(this, id).songs, position, true)
handled = true
}
}
if (handled) {
setIntent(Intent())
}
}
private fun parseIdFromIntent(intent: Intent, longKey: String, stringKey: String): Long {
var id = intent.getLongExtra(longKey, -1)
if (id < 0) {
val idString = intent.getStringExtra(stringKey)
if (idString != null) {
try {
id = java.lang.Long.parseLong(idString)
} catch (e: NumberFormatException) {
Log.e(TAG, e.message)
}
}
}
return id
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
APP_INTRO_REQUEST -> {
blockRequestPermissions = false
if (!hasPermissions()) {
requestPermissions()
}
}
REQUEST_CODE_THEME, APP_USER_INFO_REQUEST -> postRecreate()
PURCHASE_REQUEST -> {
if (resultCode == RESULT_OK) {
//checkSetUpPro();
}
}
}
}
override fun handleBackPress(): Boolean {
return super.handleBackPress() || currentFragment.handleBackPress()
}
override fun onServiceConnected() {
super.onServiceConnected()
handlePlaybackIntent(intent)
}
override fun requestPermissions() {
if (!blockRequestPermissions) {
super.requestPermissions()
}
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
if (key == PreferenceUtil.GENERAL_THEME || key == PreferenceUtil.BLACK_THEME ||
key == PreferenceUtil.ADAPTIVE_COLOR_APP || key == PreferenceUtil.DOMINANT_COLOR ||
key == PreferenceUtil.USER_NAME || key == PreferenceUtil.TOGGLE_FULL_SCREEN ||
key == PreferenceUtil.TOGGLE_VOLUME || key == PreferenceUtil.ROUND_CORNERS ||
key == PreferenceUtil.CAROUSEL_EFFECT || key == PreferenceUtil.NOW_PLAYING_SCREEN_ID ||
key == PreferenceUtil.TOGGLE_GENRE || key == PreferenceUtil.BANNER_IMAGE_PATH ||
key == PreferenceUtil.PROFILE_IMAGE_PATH || key == PreferenceUtil.CIRCULAR_ALBUM_ART ||
key == PreferenceUtil.KEEP_SCREEN_ON || key == PreferenceUtil.TOGGLE_SEPARATE_LINE ||
key == PreferenceUtil.TOGGLE_HOME_BANNER || key == PreferenceUtil.TOGGLE_ADD_CONTROLS ||
key == PreferenceUtil.ALBUM_COVER_STYLE || key == PreferenceUtil.HOME_ARTIST_GRID_STYLE ||
key == PreferenceUtil.ALBUM_COVER_TRANSFORM || key == PreferenceUtil.DESATURATED_COLOR ||
key == PreferenceUtil.TAB_TEXT_MODE || key == PreferenceUtil.LIBRARY_CATEGORIES
)
postRecreate()
}
private fun selectedFragment(itemId: Int) {
when (itemId) {
R.id.action_album,
R.id.action_artist,
R.id.action_playlist,
R.id.action_genre,
R.id.action_playing_queue,
R.id.action_song -> setCurrentFragment(LibraryFragment.newInstance(itemId), itemId.toString())
R.id.action_home -> setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG)
else -> {
setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG)
}
}
}
fun setMusicChooser(key: Int) {
PreferenceUtil.getInstance(this).lastMusicChooser = key
when (key) {
FOLDER -> setCurrentFragment(FoldersFragment.newInstance(this), FoldersFragment.TAG)
else -> selectedFragment(PreferenceUtil.getInstance(this).lastPage)
}
}
companion object {
const val APP_INTRO_REQUEST = 2323
const val HOME = 0
const val FOLDER = 1
const val LIBRARY = 2
private const val TAG = "MainActivity"
private const val APP_USER_INFO_REQUEST = 9003
private const val REQUEST_CODE_THEME = 9002
private const val PURCHASE_REQUEST = 101
}
}

View file

@ -67,7 +67,6 @@ class ContributorAdapter(
internal fun bindData(contributor: Contributor) {
title.text = contributor.name
text.text = contributor.summary
println(contributor.profileImage)
Glide.with(image.context).load(contributor.profileImage)
.error(R.drawable.ic_account_white_24dp)
.placeholder(R.drawable.ic_account_white_24dp).dontAnimate().into(image)

View file

@ -52,7 +52,6 @@ class HomeAdapter(
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
println("ViewType ${getItemViewType(position)}")
when (getItemViewType(position)) {
RECENT_ALBUMS -> {
val viewHolder = holder as AlbumViewHolder

View file

@ -19,8 +19,7 @@ abstract class AbsOffsetSongAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SongAdapter.ViewHolder {
if (viewType == OFFSET_ITEM) {
val view = LayoutInflater.from(activity)
.inflate(R.layout.item_list_quick_actions, parent, false)
val view = LayoutInflater.from(activity).inflate(R.layout.item_list_quick_actions, parent, false)
return createViewHolder(view)
}
return super.onCreateViewHolder(parent, viewType)

View file

@ -1,12 +1,16 @@
package code.name.monkey.retromusic.adapter.song
import android.view.View
import android.widget.PopupMenu
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatImageView
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.helper.SortOrder.SongSortOrder
import code.name.monkey.retromusic.interfaces.CabHolder
import code.name.monkey.retromusic.model.Song
import com.google.android.material.button.MaterialButton
import code.name.monkey.retromusic.util.PreferenceUtil
import com.google.android.material.textview.MaterialTextView
class ShuffleButtonSongAdapter(
activity: AppCompatActivity,
@ -22,24 +26,83 @@ class ShuffleButtonSongAdapter(
override fun onBindViewHolder(holder: SongAdapter.ViewHolder, position: Int) {
if (holder.itemViewType == OFFSET_ITEM) {
val viewHolder = holder as ViewHolder
viewHolder.playAction?.let {
it.setOnClickListener {
viewHolder.playAction?.setOnClickListener {
MusicPlayerRemote.openQueue(dataSet, 0, true)
}
}
viewHolder.shuffleAction?.let {
it.setOnClickListener {
viewHolder.shuffleAction?.setOnClickListener {
MusicPlayerRemote.openAndShuffleQueue(dataSet, true)
}
val songCount = activity.resources.getQuantityString(R.plurals.songCount, dataSet.size, dataSet.size)
viewHolder.songCount?.text = songCount
viewHolder.sortAction?.setOnClickListener {
showSortPopupMenu(it)
}
} else {
super.onBindViewHolder(holder, position - 1)
}
}
private fun showGridPopupMenu(view: View) {
val popupMenu = PopupMenu(activity, view)
popupMenu.menuInflater.inflate(R.menu.menu_grid_options, popupMenu.menu)
popupMenu.setOnMenuItemClickListener {
when (it.itemId) {
R.id.action_grid_size_1 -> {
PreferenceUtil.getInstance(activity).setSongGridSize(1)
}
R.id.action_grid_size_2 -> {
PreferenceUtil.getInstance(activity).setSongGridSize(2)
}
R.id.action_grid_size_3 -> {
PreferenceUtil.getInstance(activity).setSongGridSize(3)
}
R.id.action_grid_size_4 -> {
PreferenceUtil.getInstance(activity).setSongGridSize(4)
}
}
return@setOnMenuItemClickListener true
}
popupMenu.show()
}
private fun showSortPopupMenu(view: View) {
val popupMenu = PopupMenu(activity, view)
popupMenu.menuInflater.inflate(R.menu.menu_song_sort, popupMenu.menu)
popupMenu.setOnMenuItemClickListener {
when (it.itemId) {
R.id.action_song_sort_order_asc -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_A_Z
}
R.id.action_song_sort_order_desc -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_Z_A
}
R.id.action_song_sort_order_artist -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_ARTIST
}
R.id.action_song_sort_order_album -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_ALBUM
}
R.id.action_song_sort_order_date -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_DATE
}
R.id.action_song_sort_order_composer -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.COMPOSER
}
R.id.action_song_sort_order_year -> {
PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_YEAR
}
}
return@setOnMenuItemClickListener true
}
popupMenu.show()
}
inner class ViewHolder(itemView: View) : AbsOffsetSongAdapter.ViewHolder(itemView) {
val playAction: MaterialButton? = itemView.findViewById(R.id.playAction)
val shuffleAction: MaterialButton? = itemView.findViewById(R.id.shuffleAction)
val playAction: AppCompatImageView? = itemView.findViewById(R.id.playAction)
val shuffleAction: AppCompatImageView? = itemView.findViewById(R.id.shuffleAction)
val sortAction: AppCompatImageView? = itemView.findViewById(R.id.sortAction)
val songCount: MaterialTextView? = itemView.findViewById(R.id.songCount)
override fun onClick(v: View?) {
if (itemViewType == OFFSET_ITEM) {

View file

@ -35,7 +35,6 @@ import com.afollestad.materialdialogs.customview.getCustomView
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
class CreatePlaylistDialog : DialogFragment() {
private lateinit var playlistView: TextInputEditText
@ -73,12 +72,14 @@ class CreatePlaylistDialog : DialogFragment() {
MaterialUtil.setTint(actionNewPlaylistContainer, false)
val playlistId = arguments!!.getLong(MediaStore.Audio.Playlists.Members.PLAYLIST_ID)
playlistView.appHandleColor().setText(PlaylistsUtil.getNameForPlaylist(requireContext(), playlistId), TextView.BufferType.EDITABLE)
playlistView.appHandleColor()
.setText(PlaylistsUtil.getNameForPlaylist(requireContext(), playlistId), TextView.BufferType.EDITABLE)
return materialDialog
}
companion object {
@JvmOverloads
@JvmStatic
fun create(song: Song? = null): CreatePlaylistDialog {
val list = ArrayList<Song>()
if (song != null) {
@ -87,6 +88,7 @@ class CreatePlaylistDialog : DialogFragment() {
return create(list)
}
@JvmStatic
fun create(songs: ArrayList<Song>): CreatePlaylistDialog {
val dialog = CreatePlaylistDialog()
val args = Bundle()

View file

@ -37,8 +37,8 @@ class OptionsSheetDialogFragment : DialogFragment(), View.OnClickListener {
override fun onClick(view: View) {
val mainActivity = activity as MainActivity? ?: return
when (view.id) {
R.id.actionFolders -> mainActivity.setMusicChooser(MainActivity.FOLDER)
R.id.actionLibrary -> mainActivity.setMusicChooser(MainActivity.LIBRARY)
R.id.actionFolders -> mainActivity.setMusicChooser(FOLDER)
R.id.actionLibrary -> mainActivity.setMusicChooser(LIBRARY)
R.id.actionSettings -> NavigationUtil.goToSettings(mainActivity)
R.id.actionDriveMode -> NavigationUtil.gotoDriveMode(mainActivity)
R.id.actionRate -> NavigationUtil.goToPlayStore(mainActivity)
@ -105,6 +105,7 @@ class OptionsSheetDialogFragment : DialogFragment(), View.OnClickListener {
@JvmField
var FOLDER: Int = 1
@JvmStatic
fun newInstance(selectedId: Int): OptionsSheetDialogFragment {
val bundle = Bundle()
bundle.putInt(WHICH_ONE, selectedId)
@ -113,6 +114,7 @@ class OptionsSheetDialogFragment : DialogFragment(), View.OnClickListener {
return fragment
}
@JvmStatic
fun newInstance(): OptionsSheetDialogFragment {
return OptionsSheetDialogFragment()
}

View file

@ -1,32 +0,0 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.extensions
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.model.Song
/**
* Created by hemanths on 2019-11-01.
*/
fun ArrayList<Song>.lastElement(): Boolean {
println("${this.size} ${this.indexOf(MusicPlayerRemote.currentSong)}")
return this.size - 1 == this.indexOf(MusicPlayerRemote.currentSong)
}
fun ArrayList<Song>.fistElement(): Boolean {
return 0 == this.indexOf(MusicPlayerRemote.currentSong)
}

View file

@ -1,13 +1,12 @@
package code.name.monkey.retromusic.fragments.base
import android.os.Bundle
import code.name.monkey.retromusic.fragments.mainactivity.LibraryFragment
import code.name.monkey.retromusic.activities.MainActivity
open class AbsLibraryPagerFragment : AbsMusicServiceFragment() {
val libraryFragment: LibraryFragment
get() = parentFragment as LibraryFragment
val mainActivity: MainActivity
get() = requireActivity() as MainActivity
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)

View file

@ -35,7 +35,7 @@ abstract class AbsLibraryPagerRecyclerViewFragment<A : RecyclerView.Adapter<*>,
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
libraryFragment.addOnAppBarOffsetChangedListener(this)
mainActivity.addOnAppBarOffsetChangedListener(this)
initLayoutManager()
initAdapter()
setUpRecyclerView()
@ -109,7 +109,7 @@ abstract class AbsLibraryPagerRecyclerViewFragment<A : RecyclerView.Adapter<*>,
container.paddingLeft,
container.paddingTop,
container.paddingRight,
libraryFragment.totalAppBarScrollingRange + i
mainActivity.totalAppBarScrollingRange + i
)
}
@ -136,7 +136,7 @@ abstract class AbsLibraryPagerRecyclerViewFragment<A : RecyclerView.Adapter<*>,
override fun onDestroyView() {
super.onDestroyView()
libraryFragment.removeOnAppBarOffsetChangedListener(this)
mainActivity.removeOnAppBarOffsetChangedListener(this)
}
fun recyclerView(): RecyclerView {

View file

@ -7,6 +7,7 @@ import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.album.AlbumAdapter
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks
import code.name.monkey.retromusic.model.Album
import code.name.monkey.retromusic.mvp.presenter.AlbumsPresenter
import code.name.monkey.retromusic.mvp.presenter.AlbumsView
@ -14,7 +15,7 @@ import code.name.monkey.retromusic.util.PreferenceUtil
import javax.inject.Inject
class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<AlbumAdapter, GridLayoutManager>(),
AlbumsView {
AlbumsView, MainActivityFragmentCallbacks {
@Inject
lateinit var albumsPresenter: AlbumsPresenter
@ -49,16 +50,16 @@ class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<AlbumAd
get() = R.string.no_albums
override fun createLayoutManager(): GridLayoutManager {
return GridLayoutManager(activity, getGridSize())
return GridLayoutManager(requireActivity(), getGridSize())
}
override fun createAdapter(): AlbumAdapter {
val dataSet = if (adapter == null) ArrayList() else adapter!!.dataSet
return AlbumAdapter(
libraryFragment.mainActivity,
mainActivity,
dataSet,
itemLayoutRes(),
libraryFragment
mainActivity
)
}
@ -117,7 +118,7 @@ class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<AlbumAd
companion object {
@JvmField
var TAG: String = AlbumsFragment::class.java.simpleName
@JvmStatic
fun newInstance(): AlbumsFragment {
val args = Bundle()
val fragment = AlbumsFragment()
@ -125,4 +126,8 @@ class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<AlbumAd
return fragment
}
}
override fun handleBackPress(): Boolean {
return false
}
}

View file

@ -7,6 +7,7 @@ import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.artist.ArtistAdapter
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks
import code.name.monkey.retromusic.model.Artist
import code.name.monkey.retromusic.mvp.presenter.ArtistsPresenter
import code.name.monkey.retromusic.mvp.presenter.ArtistsView
@ -14,7 +15,11 @@ import code.name.monkey.retromusic.util.PreferenceUtil
import javax.inject.Inject
class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<ArtistAdapter, GridLayoutManager>(),
ArtistsView {
ArtistsView, MainActivityFragmentCallbacks {
override fun handleBackPress(): Boolean {
return false
}
override fun artists(artists: List<Artist>) {
adapter?.swapDataSet(artists)
@ -57,21 +62,21 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
}
override fun createLayoutManager(): GridLayoutManager {
return GridLayoutManager(activity, getGridSize())
return GridLayoutManager(requireActivity(), getGridSize())
}
override fun createAdapter(): ArtistAdapter {
val dataSet = if (adapter == null) ArrayList() else adapter!!.dataSet
return ArtistAdapter(
libraryFragment.mainActivity,
mainActivity,
dataSet,
itemLayoutRes(),
libraryFragment
mainActivity
)
}
override fun loadGridSize(): Int {
return PreferenceUtil.getInstance(requireContext()).getArtistGridSize(activity!!)
return PreferenceUtil.getInstance(requireContext()).getArtistGridSize(requireActivity())
}
override fun saveGridSize(gridColumns: Int) {
@ -79,7 +84,7 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
}
override fun loadGridSizeLand(): Int {
return PreferenceUtil.getInstance(requireContext()).getArtistGridSizeLand(activity!!)
return PreferenceUtil.getInstance(requireContext()).getArtistGridSizeLand(requireActivity())
}
override fun saveGridSizeLand(gridColumns: Int) {
@ -106,7 +111,7 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<Artist
companion object {
@JvmField
val TAG: String = ArtistsFragment::class.java.simpleName
@JvmStatic
fun newInstance(): ArtistsFragment {
val args = Bundle()
val fragment = ArtistsFragment()

View file

@ -21,12 +21,19 @@ import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.GenreAdapter
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewFragment
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks
import code.name.monkey.retromusic.model.Genre
import code.name.monkey.retromusic.mvp.presenter.GenresPresenter
import code.name.monkey.retromusic.mvp.presenter.GenresView
import javax.inject.Inject
class GenresFragment : AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearLayoutManager>(), GenresView {
class GenresFragment : AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearLayoutManager>(),
GenresView, MainActivityFragmentCallbacks {
override fun handleBackPress(): Boolean {
return false
}
override fun genres(genres: List<Genre>) {
adapter?.swapDataSet(genres)
}
@ -40,7 +47,7 @@ class GenresFragment : AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearL
override fun createAdapter(): GenreAdapter {
val dataSet = if (adapter == null) ArrayList() else adapter!!.dataSet
return GenreAdapter(libraryFragment.mainActivity, dataSet, R.layout.item_list_no_image)
return GenreAdapter(mainActivity, dataSet, R.layout.item_list_no_image)
}
override val emptyMessage: Int
@ -78,7 +85,7 @@ class GenresFragment : AbsLibraryPagerRecyclerViewFragment<GenreAdapter, LinearL
companion object {
@JvmField
val TAG: String = GenresFragment::class.java.simpleName
@JvmStatic
fun newInstance(): GenresFragment {
return GenresFragment()
}

View file

@ -1,529 +0,0 @@
package code.name.monkey.retromusic.fragments.mainactivity;
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import code.name.monkey.appthemehelper.common.ATHToolbarActivity;
import code.name.monkey.appthemehelper.util.ATHUtil;
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog;
import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment;
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment;
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment;
import code.name.monkey.retromusic.helper.SortOrder.AlbumSortOrder;
import code.name.monkey.retromusic.helper.SortOrder.ArtistSortOrder;
import code.name.monkey.retromusic.helper.SortOrder.SongSortOrder;
import code.name.monkey.retromusic.interfaces.CabHolder;
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks;
import code.name.monkey.retromusic.util.NavigationUtil;
import code.name.monkey.retromusic.util.RetroColorUtil;
import code.name.monkey.retromusic.util.RetroUtil;
import com.afollestad.materialcab.MaterialCab;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.card.MaterialCardView;
import org.jetbrains.annotations.NotNull;
public class LibraryFragment extends AbsMainActivityFragment implements CabHolder, MainActivityFragmentCallbacks {
public static final String TAG = "LibraryFragment";
private static final String CURRENT_TAB_ID = "current_tab_id";
private AppBarLayout appBarLayout;
private MaterialCab cab;
private FragmentManager fragmentManager;
private Toolbar toolbar;
private MaterialCardView toolbarContainer;
@NonNull
public static Fragment newInstance(int tab) {
Bundle args = new Bundle();
args.putInt(CURRENT_TAB_ID, tab);
LibraryFragment fragment = new LibraryFragment();
fragment.setArguments(args);
return fragment;
}
@NonNull
public static Fragment newInstance() {
return new LibraryFragment();
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_library, container, false);
appBarLayout = view.findViewById(R.id.appBarLayout);
toolbarContainer = view.findViewById(R.id.toolbarContainer);
toolbar = view.findViewById(R.id.toolbar);
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setStatusBarColorAuto(view);
setupToolbar();
inflateFragment();
}
public void addOnAppBarOffsetChangedListener(
@NonNull AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) {
appBarLayout.addOnOffsetChangedListener(onOffsetChangedListener);
}
public int getTotalAppBarScrollingRange() {
return appBarLayout.getTotalScrollRange();
}
@Override
public boolean handleBackPress() {
if (cab != null && cab.isActive()) {
cab.finish();
return true;
}
return false;
}
@Override
public void onCreateOptionsMenu(@NotNull Menu menu, @NonNull MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_main, menu);
Fragment currentFragment = getCurrentFragment();
if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment
&& currentFragment.isAdded()) {
AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment
= (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment;
if (fragment instanceof SongsFragment) {
menu.removeItem(R.id.action_grid_size);
menu.removeItem(R.id.action_layout_type);
} else {
MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size);
if (RetroUtil.isLandscape()) {
gridSizeItem.setTitle(R.string.action_grid_size_land);
}
setUpGridSizeMenu(fragment, gridSizeItem.getSubMenu());
MenuItem layoutItem = menu.findItem(R.id.action_layout_type);
setupLayoutMenu(fragment, layoutItem.getSubMenu());
}
setUpSortOrderMenu(fragment, menu.findItem(R.id.action_sort_order).getSubMenu());
} else if (currentFragment instanceof GenresFragment || currentFragment instanceof PlayingQueueFragment) {
menu.removeItem(R.id.action_new_playlist);
menu.removeItem(R.id.action_layout_type);
menu.removeItem(R.id.action_grid_size);
menu.removeItem(R.id.action_sort_order);
} else {
menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title)
.setIcon(R.drawable.ic_playlist_add_white_24dp).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.removeItem(R.id.action_grid_size);
menu.removeItem(R.id.action_layout_type);
}
ToolbarContentTintHelper.handleOnCreateOptionsMenu(requireActivity(), toolbar, menu,
ATHToolbarActivity.getToolbarBackgroundColor(toolbar));
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
//if (pager == null) return false;
Fragment currentFragment = getCurrentFragment();
if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment) {
AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment
= (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment;
if (handleGridSizeMenuItem(fragment, item)) {
return true;
}
if (handleLayoutResType(fragment, item)) {
return true;
}
if (handleSortOrderMenuItem(fragment, item)) {
return true;
}
}
int id = item.getItemId();
switch (id) {
case R.id.action_search:
ActivityOptions options = ActivityOptions
.makeSceneTransitionAnimation(getMainActivity(), toolbarContainer,
getString(R.string.transition_toolbar));
NavigationUtil.goToSearch(getMainActivity(), options);
break;
case R.id.action_new_playlist:
CreatePlaylistDialog.Companion.create().show(getChildFragmentManager(), "CREATE_PLAYLIST");
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
Activity activity = getActivity();
if (activity == null) {
return;
}
ToolbarContentTintHelper.handleOnPrepareOptionsMenu(activity, toolbar);
}
@NonNull
@Override
public MaterialCab openCab(int menuRes, @NonNull MaterialCab.Callback callback) {
if (cab != null && cab.isActive()) {
cab.finish();
}
cab = new MaterialCab(getMainActivity(), R.id.cab_stub)
.setMenu(menuRes)
.setCloseDrawableRes(R.drawable.ic_close_white_24dp)
.setBackgroundColor(
RetroColorUtil.shiftBackgroundColorForLightText(
ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorSurface)))
.start(callback);
return cab;
}
public void removeOnAppBarOffsetChangedListener(
@NonNull AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) {
appBarLayout.removeOnOffsetChangedListener(onOffsetChangedListener);
}
public void setTitle(@StringRes int name) {
toolbar.setTitle(getString(name));
}
private Fragment getCurrentFragment() {
if (fragmentManager == null) {
return SongsFragment.Companion.newInstance();
}
return fragmentManager.findFragmentByTag(LibraryFragment.TAG);
}
private boolean handleGridSizeMenuItem(
@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment,
@NonNull MenuItem item) {
int gridSize = 0;
switch (item.getItemId()) {
case R.id.action_grid_size_1:
gridSize = 1;
break;
case R.id.action_grid_size_2:
gridSize = 2;
break;
case R.id.action_grid_size_3:
gridSize = 3;
break;
case R.id.action_grid_size_4:
gridSize = 4;
break;
case R.id.action_grid_size_5:
gridSize = 5;
break;
case R.id.action_grid_size_6:
gridSize = 6;
break;
case R.id.action_grid_size_7:
gridSize = 7;
break;
case R.id.action_grid_size_8:
gridSize = 8;
break;
}
if (gridSize > 0) {
item.setChecked(true);
fragment.setAndSaveGridSize(gridSize);
return true;
}
return false;
}
private boolean handleLayoutResType(
final AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment,
final MenuItem item) {
int layoutRes = -1;
switch (item.getItemId()) {
case R.id.action_layout_normal:
layoutRes = R.layout.item_grid;
break;
case R.id.action_layout_card:
layoutRes = R.layout.item_card;
break;
case R.id.action_layout_colored_card:
layoutRes = R.layout.item_card_color;
break;
case R.id.action_layout_circular:
layoutRes = R.layout.item_grid_circle;
break;
case R.id.action_layout_image:
layoutRes = R.layout.image;
break;
case R.id.action_layout_gradient_image:
layoutRes = R.layout.item_image_gradient;
break;
}
if (layoutRes != -1) {
item.setChecked(true);
fragment.setAndSaveLayoutRes(layoutRes);
return true;
}
return false;
}
private boolean handleSortOrderMenuItem(
@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment
fragment, @NonNull MenuItem item) {
String sortOrder = null;
if (fragment instanceof AlbumsFragment) {
switch (item.getItemId()) {
case R.id.action_album_sort_order_asc:
sortOrder = AlbumSortOrder.ALBUM_A_Z;
break;
case R.id.action_album_sort_order_desc:
sortOrder = AlbumSortOrder.ALBUM_Z_A;
break;
case R.id.action_album_sort_order_artist:
sortOrder = AlbumSortOrder.ALBUM_ARTIST;
break;
case R.id.action_album_sort_order_year:
sortOrder = AlbumSortOrder.ALBUM_YEAR;
break;
}
} else if (fragment instanceof ArtistsFragment) {
switch (item.getItemId()) {
case R.id.action_artist_sort_order_asc:
sortOrder = ArtistSortOrder.ARTIST_A_Z;
break;
case R.id.action_artist_sort_order_desc:
sortOrder = ArtistSortOrder.ARTIST_Z_A;
break;
}
} else if (fragment instanceof SongsFragment) {
switch (item.getItemId()) {
case R.id.action_song_sort_order_asc:
sortOrder = SongSortOrder.SONG_A_Z;
break;
case R.id.action_song_sort_order_desc:
sortOrder = SongSortOrder.SONG_Z_A;
break;
case R.id.action_song_sort_order_artist:
sortOrder = SongSortOrder.SONG_ARTIST;
break;
case R.id.action_song_sort_order_album:
sortOrder = SongSortOrder.SONG_ALBUM;
break;
case R.id.action_song_sort_order_year:
sortOrder = SongSortOrder.SONG_YEAR;
break;
case R.id.action_song_sort_order_date:
sortOrder = SongSortOrder.SONG_DATE;
break;
case R.id.action_song_sort_order_composer:
sortOrder = SongSortOrder.COMPOSER;
break;
}
}
if (sortOrder != null) {
item.setChecked(true);
fragment.setAndSaveSortOrder(sortOrder);
return true;
}
return false;
}
private void inflateFragment() {
if (getArguments() == null) {
selectedFragment(SongsFragment.Companion.newInstance());
return;
}
switch (getArguments().getInt(CURRENT_TAB_ID)) {
default:
case R.id.action_song:
selectedFragment(SongsFragment.Companion.newInstance());
break;
case R.id.action_album:
selectedFragment(AlbumsFragment.Companion.newInstance());
break;
case R.id.action_artist:
selectedFragment(ArtistsFragment.Companion.newInstance());
break;
case R.id.action_playlist:
selectedFragment(PlaylistsFragment.Companion.newInstance());
break;
case R.id.action_genre:
selectedFragment(GenresFragment.Companion.newInstance());
break;
case R.id.action_playing_queue:
selectedFragment(PlayingQueueFragment.Companion.newInstance());
break;
}
}
private void selectedFragment(Fragment fragment) {
fragmentManager = getChildFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction
.replace(R.id.fragmentContainer, fragment, LibraryFragment.TAG)
.commit();
}
private void setUpGridSizeMenu(
@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment,
@NonNull SubMenu gridSizeMenu) {
switch (fragment.getGridSize()) {
case 1:
gridSizeMenu.findItem(R.id.action_grid_size_1).setChecked(true);
break;
case 2:
gridSizeMenu.findItem(R.id.action_grid_size_2).setChecked(true);
break;
case 3:
gridSizeMenu.findItem(R.id.action_grid_size_3).setChecked(true);
break;
case 4:
gridSizeMenu.findItem(R.id.action_grid_size_4).setChecked(true);
break;
case 5:
gridSizeMenu.findItem(R.id.action_grid_size_5).setChecked(true);
break;
case 6:
gridSizeMenu.findItem(R.id.action_grid_size_6).setChecked(true);
break;
case 7:
gridSizeMenu.findItem(R.id.action_grid_size_7).setChecked(true);
break;
case 8:
gridSizeMenu.findItem(R.id.action_grid_size_8).setChecked(true);
break;
}
int maxGridSize = fragment.getMaxGridSize();
if (maxGridSize < 8) {
gridSizeMenu.findItem(R.id.action_grid_size_8).setVisible(false);
}
if (maxGridSize < 7) {
gridSizeMenu.findItem(R.id.action_grid_size_7).setVisible(false);
}
if (maxGridSize < 6) {
gridSizeMenu.findItem(R.id.action_grid_size_6).setVisible(false);
}
if (maxGridSize < 5) {
gridSizeMenu.findItem(R.id.action_grid_size_5).setVisible(false);
}
if (maxGridSize < 4) {
gridSizeMenu.findItem(R.id.action_grid_size_4).setVisible(false);
}
if (maxGridSize < 3) {
gridSizeMenu.findItem(R.id.action_grid_size_3).setVisible(false);
}
}
private void setUpSortOrderMenu(
@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment,
@NonNull SubMenu sortOrderMenu) {
String currentSortOrder = fragment.getSortOrder();
sortOrderMenu.clear();
if (fragment instanceof AlbumsFragment) {
sortOrderMenu.add(0, R.id.action_album_sort_order_asc, 0, R.string.sort_order_a_z)
.setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_A_Z));
sortOrderMenu.add(0, R.id.action_album_sort_order_desc, 1, R.string.sort_order_z_a)
.setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_Z_A));
sortOrderMenu.add(0, R.id.action_album_sort_order_artist, 2, R.string.sort_order_artist)
.setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_ARTIST));
sortOrderMenu.add(0, R.id.action_album_sort_order_year, 3, R.string.sort_order_year)
.setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_YEAR));
} else if (fragment instanceof ArtistsFragment) {
sortOrderMenu.add(0, R.id.action_artist_sort_order_asc, 0, R.string.sort_order_a_z)
.setChecked(currentSortOrder.equals(ArtistSortOrder.ARTIST_A_Z));
sortOrderMenu.add(0, R.id.action_artist_sort_order_desc, 1, R.string.sort_order_z_a)
.setChecked(currentSortOrder.equals(ArtistSortOrder.ARTIST_Z_A));
} else if (fragment instanceof SongsFragment) {
sortOrderMenu.add(0, R.id.action_song_sort_order_asc, 0, R.string.sort_order_a_z)
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_A_Z));
sortOrderMenu.add(0, R.id.action_song_sort_order_desc, 1, R.string.sort_order_z_a)
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_Z_A));
sortOrderMenu.add(0, R.id.action_song_sort_order_artist, 2, R.string.sort_order_artist)
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_ARTIST));
sortOrderMenu.add(0, R.id.action_song_sort_order_album, 3, R.string.sort_order_album)
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_ALBUM));
sortOrderMenu.add(0, R.id.action_song_sort_order_year, 4, R.string.sort_order_year)
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_YEAR));
sortOrderMenu.add(0, R.id.action_song_sort_order_date, 5, R.string.sort_order_date)
.setChecked(currentSortOrder.equals(SongSortOrder.SONG_DATE));
sortOrderMenu.add(0, R.id.action_song_sort_order_composer, 6, R.string.sort_order_composer)
.setChecked(currentSortOrder.equals(SongSortOrder.COMPOSER));
}
sortOrderMenu.setGroupCheckable(0, true, true);
}
private void setupLayoutMenu(
@NonNull final AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment,
@NonNull final SubMenu subMenu) {
switch (fragment.itemLayoutRes()) {
case R.layout.item_card:
subMenu.findItem(R.id.action_layout_card).setChecked(true);
break;
case R.layout.item_grid:
subMenu.findItem(R.id.action_layout_normal).setChecked(true);
break;
case R.layout.item_card_color:
subMenu.findItem(R.id.action_layout_colored_card).setChecked(true);
break;
case R.layout.item_grid_circle:
subMenu.findItem(R.id.action_layout_circular).setChecked(true);
break;
case R.layout.image:
subMenu.findItem(R.id.action_layout_image).setChecked(true);
break;
case R.layout.item_image_gradient:
subMenu.findItem(R.id.action_layout_gradient_image).setChecked(true);
break;
}
}
private void setupToolbar() {
toolbar.setBackgroundColor(Color.TRANSPARENT);
toolbarContainer.setCardBackgroundColor(
ColorStateList.valueOf(ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorSurface)));
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
toolbar.setOnClickListener(v -> {
ActivityOptions options = ActivityOptions
.makeSceneTransitionAnimation(getMainActivity(), toolbarContainer,
getString(R.string.transition_toolbar));
NavigationUtil.goToSearch(getMainActivity(), options);
});
getMainActivity().setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(v -> showMainMenu(OptionsSheetDialogFragment.LIBRARY));
ToolbarContentTintHelper.colorBackButton(toolbar);
}
}

View file

@ -22,6 +22,7 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.song.PlayingQueueAdapter
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewFragment
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks
import com.h6ah4i.android.widget.advrecyclerview.animator.DraggableItemAnimator
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager
import com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager
@ -32,7 +33,12 @@ import kotlinx.android.synthetic.main.activity_playing_queue.recyclerView
/**
* Created by hemanths on 2019-12-08.
*/
class PlayingQueueFragment : AbsLibraryPagerRecyclerViewFragment<PlayingQueueAdapter, LinearLayoutManager>() {
class PlayingQueueFragment : AbsLibraryPagerRecyclerViewFragment<PlayingQueueAdapter, LinearLayoutManager>(),
MainActivityFragmentCallbacks {
override fun handleBackPress(): Boolean {
return false
}
private lateinit var wrappedAdapter: RecyclerView.Adapter<*>
private var recyclerViewDragDropManager: RecyclerViewDragDropManager? = null
@ -131,7 +137,7 @@ class PlayingQueueFragment : AbsLibraryPagerRecyclerViewFragment<PlayingQueueAda
companion object {
@JvmField
val TAG: String = PlayingQueueFragment::class.java.simpleName
@JvmStatic
fun newInstance(): PlayingQueueFragment {
return PlayingQueueFragment()
}

View file

@ -9,12 +9,18 @@ import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.playlist.PlaylistAdapter
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewFragment
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks
import code.name.monkey.retromusic.model.Playlist
import code.name.monkey.retromusic.mvp.presenter.PlaylistView
import code.name.monkey.retromusic.mvp.presenter.PlaylistsPresenter
import javax.inject.Inject
class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment<PlaylistAdapter, LinearLayoutManager>(), PlaylistView {
class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment<PlaylistAdapter, LinearLayoutManager>(), PlaylistView,
MainActivityFragmentCallbacks {
override fun handleBackPress(): Boolean {
return false
}
@Inject
lateinit var playlistsPresenter: PlaylistsPresenter
@ -38,8 +44,10 @@ class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment<PlaylistAdapter, L
override fun createAdapter(): PlaylistAdapter {
return PlaylistAdapter(
libraryFragment.mainActivity, ArrayList(),
R.layout.item_list, libraryFragment
mainActivity,
ArrayList(),
R.layout.item_list,
mainActivity
)
}
@ -80,6 +88,7 @@ class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment<PlaylistAdapter, L
@JvmField
val TAG: String = PlaylistsFragment::class.java.simpleName
@JvmStatic
fun newInstance(): PlaylistsFragment {
val args = Bundle()
val fragment = PlaylistsFragment()

View file

@ -1,5 +1,7 @@
package code.name.monkey.retromusic.fragments.mainactivity
import android.content.SharedPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.os.Bundle
import android.view.View
import androidx.annotation.LayoutRes
@ -9,6 +11,7 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.song.ShuffleButtonSongAdapter
import code.name.monkey.retromusic.adapter.song.SongAdapter
import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment
import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.mvp.presenter.SongPresenter
import code.name.monkey.retromusic.mvp.presenter.SongView
@ -17,7 +20,7 @@ import java.util.ArrayList
import javax.inject.Inject
class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdapter, LinearLayoutManager>(),
SongView {
SongView, MainActivityFragmentCallbacks, OnSharedPreferenceChangeListener {
@Inject
lateinit var songPresenter: SongPresenter
@ -36,16 +39,16 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
}
override fun createLayoutManager(): LinearLayoutManager {
return LinearLayoutManager(activity)
return LinearLayoutManager(requireActivity())
}
override fun createAdapter(): SongAdapter {
val dataSet = if (adapter == null) mutableListOf() else adapter!!.dataSet
return ShuffleButtonSongAdapter(
libraryFragment.mainActivity,
mainActivity,
dataSet,
R.layout.item_list,
libraryFragment
mainActivity
)
}
@ -58,7 +61,7 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
}
override fun loadGridSize(): Int {
return PreferenceUtil.getInstance(requireContext()).getSongGridSize(activity!!)
return PreferenceUtil.getInstance(requireContext()).getSongGridSize(requireActivity())
}
override fun saveGridSize(gridColumns: Int) {
@ -66,7 +69,7 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
}
override fun loadGridSizeLand(): Int {
return PreferenceUtil.getInstance(requireContext()).getSongGridSizeLand(activity!!)
return PreferenceUtil.getInstance(requireContext()).getSongGridSizeLand(requireActivity())
}
override fun saveGridSizeLand(gridColumns: Int) {
@ -81,11 +84,13 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
super.onResume()
if (adapter?.dataSet.isNullOrEmpty())
songPresenter.loadSongs()
PreferenceUtil.getInstance(requireContext()).registerOnSharedPreferenceChangedListener(this)
}
override fun onDestroyView() {
super.onDestroyView()
songPresenter.detachView()
PreferenceUtil.getInstance(requireContext()).unregisterOnSharedPreferenceChangedListener(this)
}
override fun showEmptyView() {
@ -109,6 +114,7 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
@JvmField
var TAG: String = SongsFragment::class.java.simpleName
@JvmStatic
fun newInstance(): SongsFragment {
val args = Bundle()
val fragment = SongsFragment()
@ -127,4 +133,14 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment<SongAdap
override fun saveLayoutRes(@LayoutRes layoutRes: Int) {
}
override fun handleBackPress(): Boolean {
return false
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
if (key == PreferenceUtil.SONG_SORT_ORDER || key == PreferenceUtil.SONG_GRID_SIZE) {
songPresenter.loadSongs()
}
}
}

View file

@ -1,9 +1,7 @@
package code.name.monkey.retromusic.fragments.mainactivity.folders;
import android.app.ActivityOptions;
import android.app.Dialog;
import android.content.Context;
import android.content.res.ColorStateList;
import android.media.MediaScannerConnection;
import android.os.Bundle;
import android.os.Environment;
@ -20,18 +18,14 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import code.name.monkey.appthemehelper.ThemeStore;
import code.name.monkey.appthemehelper.common.ATHToolbarActivity;
import code.name.monkey.appthemehelper.util.ATHUtil;
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.adapter.SongFileAdapter;
import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment;
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment;
import code.name.monkey.retromusic.helper.MusicPlayerRemote;
import code.name.monkey.retromusic.helper.menu.SongMenuHelper;
@ -43,17 +37,13 @@ import code.name.monkey.retromusic.misc.DialogAsyncTask;
import code.name.monkey.retromusic.misc.UpdateToastMediaScannerCompletionListener;
import code.name.monkey.retromusic.misc.WrappedAsyncTaskLoader;
import code.name.monkey.retromusic.model.Song;
import code.name.monkey.retromusic.util.DensityUtil;
import code.name.monkey.retromusic.util.FileUtil;
import code.name.monkey.retromusic.util.NavigationUtil;
import code.name.monkey.retromusic.util.PreferenceUtil;
import code.name.monkey.retromusic.util.RetroColorUtil;
import code.name.monkey.retromusic.util.ThemedFastScroller;
import code.name.monkey.retromusic.views.BreadCrumbLayout;
import code.name.monkey.retromusic.views.ScrollingViewOnApplyWindowInsetsListener;
import com.afollestad.materialcab.MaterialCab;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import java.io.File;
@ -71,7 +61,7 @@ import me.zhanghai.android.fastscroll.FastScroller;
public class FoldersFragment extends AbsMainActivityFragment implements
MainActivityFragmentCallbacks,
CabHolder, BreadCrumbLayout.SelectionCallback, SongFileAdapter.Callbacks,
AppBarLayout.OnOffsetChangedListener, LoaderManager.LoaderCallbacks<List<File>> {
LoaderManager.LoaderCallbacks<List<File>> {
public static class ListPathsAsyncTask extends
ListingFilesDialogAsyncTask<ListPathsAsyncTask.LoadingInfo, String, String[]> {
@ -327,8 +317,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements
private SongFileAdapter adapter;
private AppBarLayout appBarLayout;
private BreadCrumbLayout breadCrumbs;
private MaterialCab cab;
@ -350,9 +338,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements
private RecyclerView recyclerView;
private Toolbar toolbar;
private MaterialCardView toolbarContainer;
public static File getDefaultStartDirectory() {
File musicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
@ -434,12 +419,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements
}
@Override
public void onDestroyView() {
appBarLayout.removeOnOffsetChangedListener(this);
super.onDestroyView();
}
@Override
public boolean handleBackPress() {
if (cab != null && cab.isActive()) {
@ -463,8 +442,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_folders, menu);
ToolbarContentTintHelper.handleOnCreateOptionsMenu(getActivity(), toolbar, menu,
ATHToolbarActivity.getToolbarBackgroundColor(toolbar));
}
@Override
@ -590,13 +567,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements
.execute(new ListSongsAsyncTask.LoadingInfo(files, AUDIO_FILE_FILTER, getFileComparator()));
}
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
recyclerView.setPadding(recyclerView.getPaddingLeft(), recyclerView.getPaddingTop(),
recyclerView.getPaddingRight(), DensityUtil.dip2px(requireContext(), 52f) +
this.appBarLayout.getTotalScrollRange() + verticalOffset);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
@ -617,11 +587,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements
return super.onOptionsItemSelected(item);
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
ToolbarContentTintHelper.handleOnPrepareOptionsMenu(getActivity(), toolbar);
}
@NonNull
@Override
@ -661,11 +626,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements
private void initViews(View view) {
coordinatorLayout = view.findViewById(R.id.coordinatorLayout);
toolbarContainer = view.findViewById(R.id.toolbarContainer);
recyclerView = view.findViewById(R.id.recyclerView);
appBarLayout = view.findViewById(R.id.appBarLayout);
breadCrumbs = view.findViewById(R.id.breadCrumbs);
toolbar = view.findViewById(R.id.toolbar);
empty = view.findViewById(android.R.id.empty);
emojiText = view.findViewById(R.id.emptyEmoji);
}
@ -703,7 +665,7 @@ public class FoldersFragment extends AbsMainActivityFragment implements
}
private void setUpAdapter() {
adapter = new SongFileAdapter(getMainActivity(), new LinkedList<File>(), R.layout.item_list,
adapter = new SongFileAdapter(getMainActivity(), new LinkedList<>(), R.layout.item_list,
this, this);
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
@ -717,26 +679,10 @@ public class FoldersFragment extends AbsMainActivityFragment implements
}
private void setUpAppbarColor() {
int primaryColor = ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorSurface);
getMainActivity().setSupportActionBar(toolbar);
toolbar.setBackgroundTintList(ColorStateList.valueOf(primaryColor));
toolbarContainer.setCardBackgroundColor(ColorStateList.valueOf(primaryColor));
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
toolbar.setNavigationOnClickListener(v -> {
showMainMenu(OptionsSheetDialogFragment.FOLDER);
});
breadCrumbs.setActivatedContentColor(
ATHUtil.INSTANCE.resolveColor(requireContext(), android.R.attr.textColorPrimary));
breadCrumbs.setDeactivatedContentColor(
ATHUtil.INSTANCE.resolveColor(requireContext(), android.R.attr.textColorSecondary));
appBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> getMainActivity()
.setLightStatusbar(!ATHUtil.INSTANCE.isWindowBackgroundDark(requireContext())));
toolbar.setOnClickListener(v -> {
ActivityOptions options = ActivityOptions
.makeSceneTransitionAnimation(getMainActivity(), toolbarContainer,
getString(R.string.transition_toolbar));
NavigationUtil.goToSearch(getMainActivity(), options);
});
}
private void setUpBreadCrumbs() {
@ -745,7 +691,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements
private void setUpRecyclerView() {
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
appBarLayout.addOnOffsetChangedListener(this);
FastScroller fastScroller = ThemedFastScroller.INSTANCE.create(recyclerView);
recyclerView.setOnApplyWindowInsetsListener(
new ScrollingViewOnApplyWindowInsetsListener(recyclerView, fastScroller));

View file

@ -1,26 +1,17 @@
package code.name.monkey.retromusic.fragments.mainactivity.home
import android.app.ActivityOptions
import android.content.res.ColorStateList
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.recyclerview.widget.LinearLayoutManager
import code.name.monkey.appthemehelper.common.ATHToolbarActivity
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.Constants
import code.name.monkey.retromusic.Constants.USER_BANNER
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.HomeAdapter
import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment
import code.name.monkey.retromusic.extensions.show
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
import code.name.monkey.retromusic.helper.MusicPlayerRemote
@ -42,7 +33,6 @@ import kotlinx.android.synthetic.main.abs_playlists.lastAdded
import kotlinx.android.synthetic.main.abs_playlists.topPlayed
import kotlinx.android.synthetic.main.fragment_banner_home.bannerImage
import kotlinx.android.synthetic.main.fragment_banner_home.titleWelcome
import kotlinx.android.synthetic.main.fragment_banner_home.toolbarContainer
import kotlinx.android.synthetic.main.fragment_banner_home.userImage
import kotlinx.android.synthetic.main.home_content.emptyContainer
import kotlinx.android.synthetic.main.home_content.recyclerView
@ -56,10 +46,8 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
lateinit var homePresenter: HomePresenter
private lateinit var homeAdapter: HomeAdapter
private lateinit var toolbar: Toolbar
override fun sections(sections: List<Home>) {
println(sections.size)
homeAdapter.swapData(sections)
}
@ -93,7 +81,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setStatusBarColorAuto(view)
toolbar = view.findViewById(R.id.toolbar)
bannerImage?.setOnClickListener {
val options = ActivityOptions.makeSceneTransitionAnimation(
@ -120,8 +107,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
NavigationUtil.goToPlaylistNew(requireActivity(), HistoryPlaylist(requireActivity()))
}
setupToolbar()
userImage?.setOnClickListener {
val options = ActivityOptions.makeSceneTransitionAnimation(
mainActivity,
@ -143,24 +128,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
homePresenter.loadSections()
}
private fun setupToolbar() {
toolbar.apply {
backgroundTintList = ColorStateList.valueOf(ATHUtil.resolveColor(requireContext(), R.attr.colorSurface))
setNavigationIcon(R.drawable.ic_menu_white_24dp)
setOnClickListener {
val options = ActivityOptions.makeSceneTransitionAnimation(
mainActivity,
toolbarContainer,
getString(R.string.transition_toolbar)
)
NavigationUtil.goToSearch(requireActivity(), options)
}
}
mainActivity.setSupportActionBar(toolbar)
toolbar.setNavigationOnClickListener { showMainMenu(OptionsSheetDialogFragment.LIBRARY) }
}
override fun handleBackPress(): Boolean {
return false
}
@ -179,35 +146,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
emptyContainer.show()
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.menu_search, menu)
ToolbarContentTintHelper.handleOnCreateOptionsMenu(
requireActivity(),
toolbar,
menu,
ATHToolbarActivity.getToolbarBackgroundColor(toolbar)
)
}
override fun onPrepareOptionsMenu(menu: Menu) {
super.onPrepareOptionsMenu(menu)
ToolbarContentTintHelper.handleOnPrepareOptionsMenu(requireActivity(), toolbar)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == R.id.action_search) {
val options = ActivityOptions.makeSceneTransitionAnimation(
mainActivity,
toolbarContainer,
getString(R.string.transition_toolbar)
)
NavigationUtil.goToSearch(requireActivity(), true, options)
}
return super.onOptionsItemSelected(item)
}
private fun getTimeOfTheDay() {
val c = Calendar.getInstance()
val timeOfDay = c.get(Calendar.HOUR_OF_DAY)
@ -250,6 +188,7 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba
const val TAG: String = "BannerHomeFragment"
@JvmStatic
fun newInstance(): BannerHomeFragment {
return BannerHomeFragment()
}

View file

@ -265,7 +265,7 @@ class PlayerPlaybackControlsFragment : AbsPlayerControlsFragment(), OnSharedPref
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
println(key)
if (key == PreferenceUtil.EXTRA_SONG_INFO) {
if (activity != null) updateSong()
}

View file

@ -152,14 +152,12 @@ class PeakPlayerControlFragment : AbsPlayerControlsFragment() {
private fun setUpShuffleButton() {
shuffleButton.setOnClickListener {
println("shuffleButton Click")
MusicPlayerRemote.toggleShuffleMode()
}
}
private fun setUpRepeatButton() {
repeatButton.setOnClickListener {
println("repeatButton Click")
MusicPlayerRemote.cycleRepeatMode()
}
}

View file

@ -44,7 +44,7 @@ object MusicPlayerRemote {
val TAG: String = MusicPlayerRemote::class.java.simpleName
private val mConnectionMap = WeakHashMap<Context, ServiceBinder>()
var musicService: MusicService? = null
@JvmStatic
val isPlaying: Boolean
get() = musicService != null && musicService!!.isPlaying
@ -91,7 +91,7 @@ object MusicPlayerRemote {
get() = if (musicService != null) {
musicService!!.repeatMode
} else MusicService.REPEAT_MODE_NONE
@JvmStatic
val shuffleMode: Int
get() = if (musicService != null) {
musicService!!.shuffleMode
@ -207,6 +207,7 @@ object MusicPlayerRemote {
/**
* Async
*/
@JvmStatic
fun openQueue(queue: List<Song>, startPosition: Int, startPlaying: Boolean) {
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
musicService?.openQueue(queue, startPosition, startPlaying)
@ -218,6 +219,7 @@ object MusicPlayerRemote {
/**
* Async
*/
@JvmStatic
fun openAndShuffleQueue(queue: List<Song>, startPlaying: Boolean) {
var startPosition = 0
if (queue.isNotEmpty()) {
@ -388,7 +390,7 @@ object MusicPlayerRemote {
}
return false
}
@JvmStatic
fun playFromUri(uri: Uri) {
if (musicService != null) {

View file

@ -20,8 +20,7 @@ import android.os.Bundle
import android.provider.MediaStore
import code.name.monkey.retromusic.loaders.SongLoader
import code.name.monkey.retromusic.model.Song
import java.util.*
import java.util.ArrayList
object SearchQueryHelper {
private const val TITLE_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.TITLE + ") = ?"
@ -29,7 +28,7 @@ object SearchQueryHelper {
private const val ARTIST_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.ARTIST + ") = ?"
private const val AND = " AND "
var songs = ArrayList<Song>()
@JvmStatic
fun getSongs(context: Context, extras: Bundle): ArrayList<Song> {
val query = extras.getString(SearchManager.QUERY, null)
val artistName = extras.getString(MediaStore.EXTRA_MEDIA_ARTIST, null)
@ -38,42 +37,79 @@ object SearchQueryHelper {
var songs = ArrayList<Song>()
if (artistName != null && albumName != null && titleName != null) {
songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ARTIST_SELECTION + AND + ALBUM_SELECTION + AND + TITLE_SELECTION, arrayOf(artistName.toLowerCase(), albumName.toLowerCase(), titleName.toLowerCase())))
songs = SongLoader.getSongs(
SongLoader.makeSongCursor(
context,
ARTIST_SELECTION + AND + ALBUM_SELECTION + AND + TITLE_SELECTION,
arrayOf(artistName.toLowerCase(), albumName.toLowerCase(), titleName.toLowerCase())
)
)
}
if (songs.isNotEmpty()) {
return songs
}
if (artistName != null && titleName != null) {
songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ARTIST_SELECTION + AND + TITLE_SELECTION, arrayOf(artistName.toLowerCase(), titleName.toLowerCase())))
songs = SongLoader.getSongs(
SongLoader.makeSongCursor(
context,
ARTIST_SELECTION + AND + TITLE_SELECTION,
arrayOf(artistName.toLowerCase(), titleName.toLowerCase())
)
)
}
if (songs.isNotEmpty()) {
return songs
}
if (albumName != null && titleName != null) {
songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ALBUM_SELECTION + AND + TITLE_SELECTION, arrayOf(albumName.toLowerCase(), titleName.toLowerCase())))
songs = SongLoader.getSongs(
SongLoader.makeSongCursor(
context,
ALBUM_SELECTION + AND + TITLE_SELECTION,
arrayOf(albumName.toLowerCase(), titleName.toLowerCase())
)
)
}
if (songs.isNotEmpty()) {
return songs
}
if (artistName != null) {
songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ARTIST_SELECTION, arrayOf(artistName.toLowerCase())))
songs = SongLoader.getSongs(
SongLoader.makeSongCursor(
context,
ARTIST_SELECTION,
arrayOf(artistName.toLowerCase())
)
)
}
if (songs.isNotEmpty()) {
return songs
}
if (albumName != null) {
songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ALBUM_SELECTION, arrayOf(albumName.toLowerCase())))
songs = SongLoader.getSongs(
SongLoader.makeSongCursor(
context,
ALBUM_SELECTION,
arrayOf(albumName.toLowerCase())
)
)
}
if (songs.isNotEmpty()) {
return songs
}
if (titleName != null) {
songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, TITLE_SELECTION, arrayOf(titleName.toLowerCase())))
songs = SongLoader.getSongs(
SongLoader.makeSongCursor(
context,
TITLE_SELECTION,
arrayOf(titleName.toLowerCase())
)
)
}
if (songs.isNotEmpty()) {
return songs
}
songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ARTIST_SELECTION, arrayOf(query.toLowerCase())))
songs =
SongLoader.getSongs(SongLoader.makeSongCursor(context, ARTIST_SELECTION, arrayOf(query.toLowerCase())))
if (songs.isNotEmpty()) {
return songs
@ -87,6 +123,4 @@ object SearchQueryHelper {
songs
} else ArrayList()
}
}

View file

@ -21,6 +21,7 @@ class SortOrder {
* Artist sort order entries.
*/
interface ArtistSortOrder {
companion object {
/* Artist sort order A-Z */
@ -41,6 +42,7 @@ class SortOrder {
* Album sort order entries.
*/
interface AlbumSortOrder {
companion object {
/* Album sort order A-Z */
@ -65,6 +67,7 @@ class SortOrder {
* Song sort order entries.
*/
interface SongSortOrder {
companion object {
/* Song sort order A-Z */
@ -88,6 +91,9 @@ class SortOrder {
/* Song sort order date */
const val SONG_DATE = MediaStore.Audio.Media.DATE_ADDED + " DESC"
/* Song sort modified date */
const val SONG_MODIFIED = MediaStore.Audio.Media.DATE_MODIFIED + " DESC"
/* Song sort order composer*/
const val COMPOSER = MediaStore.Audio.Media.COMPOSER
}
@ -97,6 +103,7 @@ class SortOrder {
* Album song sort order entries.
*/
interface AlbumSongSortOrder {
companion object {
/* Album song sort order A-Z */
@ -118,6 +125,7 @@ class SortOrder {
* Artist song sort order entries.
*/
interface ArtistSongSortOrder {
companion object {
/* Artist song sort order A-Z */
@ -144,6 +152,7 @@ class SortOrder {
* Artist album sort order entries.
*/
interface ArtistAlbumSortOrder {
companion object {
/* Artist album sort order A-Z */
@ -164,6 +173,7 @@ class SortOrder {
* Genre sort order entries.
*/
interface GenreSortOrder {
companion object {
/* Genre sort order A-Z */
@ -173,5 +183,4 @@ class SortOrder {
const val ALBUM_Z_A = "$GENRE_A_Z DESC"
}
}
}

View file

@ -19,7 +19,6 @@ package code.name.monkey.retromusic.interfaces
*/
interface MainActivityFragmentCallbacks {
fun handleBackPress(): Boolean
//void selectedFragment(Fragment fragment);
fun handleBackPress(): Boolean
}

View file

@ -19,8 +19,7 @@ import android.provider.MediaStore.Audio.AudioColumns
import code.name.monkey.retromusic.model.Album
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.PreferenceUtil
import java.util.*
import kotlin.collections.ArrayList
import java.util.Comparator
/**
@ -41,7 +40,7 @@ object AlbumLoader {
)
return splitIntoAlbums(songs)
}
@JvmStatic
fun getAlbum(
context: Context,
albumId: Int

View file

@ -20,27 +20,32 @@ import code.name.monkey.retromusic.model.Album
import code.name.monkey.retromusic.model.Artist
import code.name.monkey.retromusic.util.PreferenceUtil
object ArtistLoader {
private fun getSongLoaderSortOrder(context: Context): String {
return PreferenceUtil.getInstance(context).artistSortOrder + ", " + PreferenceUtil.getInstance(context).artistAlbumSortOrder + ", " + PreferenceUtil.getInstance(context).albumSongSortOrder
return PreferenceUtil.getInstance(context).artistSortOrder + ", " + PreferenceUtil.getInstance(context).artistAlbumSortOrder + ", " + PreferenceUtil.getInstance(
context
).albumSongSortOrder
}
fun getAllArtists(context: Context): ArrayList<Artist> {
val songs = SongLoader.getSongs(SongLoader.makeSongCursor(
val songs = SongLoader.getSongs(
SongLoader.makeSongCursor(
context,
null, null,
getSongLoaderSortOrder(context))
getSongLoaderSortOrder(context)
)
)
return splitIntoArtists(AlbumLoader.splitIntoAlbums(songs))
}
fun getArtists(context: Context, query: String): ArrayList<Artist> {
val songs = SongLoader.getSongs(SongLoader.makeSongCursor(
val songs = SongLoader.getSongs(
SongLoader.makeSongCursor(
context,
AudioColumns.ARTIST + " LIKE ?",
arrayOf("%$query%"),
getSongLoaderSortOrder(context))
getSongLoaderSortOrder(context)
)
)
return splitIntoArtists(AlbumLoader.splitIntoAlbums(songs))
}
@ -66,12 +71,15 @@ object ArtistLoader {
return album
}
@JvmStatic
fun getArtist(context: Context, artistId: Int): Artist {
val songs = SongLoader.getSongs(SongLoader.makeSongCursor(
val songs = SongLoader.getSongs(
SongLoader.makeSongCursor(
context,
AudioColumns.ARTIST_ID + "=?",
arrayOf(artistId.toString()),
getSongLoaderSortOrder(context))
getSongLoaderSortOrder(context)
)
)
return Artist(AlbumLoader.splitIntoAlbums(songs))
}

View file

@ -38,7 +38,7 @@ object PlaylistSongsLoader {
return (playlist as? AbsCustomPlaylist)?.getSongs(context)
?: getPlaylistSongList(context, playlist.id)
}
@JvmStatic
fun getPlaylistSongList(context: Context, playlistId: Int): ArrayList<Song> {
val songs = arrayListOf<Song>()
val cursor = makePlaylistSongCursor(context, playlistId)

View file

@ -17,6 +17,7 @@ package code.name.monkey.retromusic.model
import java.util.ArrayList
class Album {
val songs: ArrayList<Song>?
val id: Int

View file

@ -124,7 +124,6 @@ class MaterialListPreferenceDialog : PreferenceDialogFragmentCompat() {
fun newInstance(listPreference: ListPreference): MaterialListPreferenceDialog {
val entries = listPreference.entries.toList() as ArrayList<String>
val entriesValues = listPreference.entryValues.toList() as ArrayList<String>
println("List value: ${listPreference.value}")
val position = listPreference.findIndexOfValue(listPreference.value)
val args = Bundle()
args.putString(ARG_KEY, listPreference.key)

View file

@ -34,7 +34,7 @@ object AppRater {
private const val DAYS_UNTIL_PROMPT = 3//Min number of days
private const val LAUNCHES_UNTIL_PROMPT = 5//Min number of launches
@JvmStatic
fun appLaunched(context: Context) {
val prefs = context.getSharedPreferences(APP_RATING, 0)
if (prefs.getBoolean(DO_NOT_SHOW_AGAIN, false)) {
@ -72,7 +72,12 @@ object AppRater {
title(text = "Rate this App")
message(text = "If you enjoy using Retro Music, please take a moment to rate it. Thanks for your support!")
positiveButton(R.string.app_name) {
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=${context.packageName}")))
context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=${context.packageName}")
)
)
editor.putBoolean(DO_NOT_SHOW_AGAIN, true)
editor.commit()
dismiss()

View file

@ -29,7 +29,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
import androidx.viewpager.widget.ViewPager;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.activities.MainActivity;
import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment;
import code.name.monkey.retromusic.fragments.AlbumCoverStyle;
import code.name.monkey.retromusic.fragments.NowPlayingScreen;
import code.name.monkey.retromusic.fragments.mainactivity.folders.FoldersFragment;
@ -153,13 +153,13 @@ public final class PreferenceUtil {
private static final String ALBUM_SONG_SORT_ORDER = "album_song_sort_order";
private static final String SONG_SORT_ORDER = "song_sort_order";
public static final String SONG_SORT_ORDER = "song_sort_order";
private static final String ALBUM_GRID_SIZE = "album_grid_size";
private static final String ALBUM_GRID_SIZE_LAND = "album_grid_size_land";
private static final String SONG_GRID_SIZE = "song_grid_size";
public static final String SONG_GRID_SIZE = "song_grid_size";
private static final String SONG_GRID_SIZE_LAND = "song_grid_size_land";
@ -586,7 +586,7 @@ public final class PreferenceUtil {
}
public final int getLastMusicChooser() {
return mPreferences.getInt(LAST_MUSIC_CHOOSER, MainActivity.HOME);
return mPreferences.getInt(LAST_MUSIC_CHOOSER, OptionsSheetDialogFragment.LIBRARY);
}
public void setLastMusicChooser(int value) {

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2020 Hemanth Savarala.
~
~ Licensed under the GNU General Public License v3
~
~ This is free software: you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by
~ the Free Software Foundation either version 3 of the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="16dp" />
<solid android:color="?attr/colorSurface" />
</shape>

View file

@ -12,22 +12,9 @@
~ See the GNU General Public License for more details.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/status_bar" />
</FrameLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -62,33 +49,6 @@
tools:srcCompat="@tools:sample/backgrounds/scenic[9]" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/toolbarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/toolbar_margin_horizontal"
android:layout_marginTop="8dp"
android:layout_marginEnd="@dimen/toolbar_margin_horizontal"
app:cardBackgroundColor="@android:color/transparent"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_scrollFlags="scroll|enterAlways"
app:shapeAppearance="@style/ToolbarCornerCardView">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="?attr/colorSurface"
app:popupTheme="?toolbarPopupTheme"
app:title="@string/action_search"
app:titleTextAppearance="@style/TextViewHeadline6"
tools:ignore="UnusedAttribute" />
</com.google.android.material.card.MaterialCardView>
<View
android:layout_width="match_parent"
android:layout_height="52dp"
@ -138,4 +98,3 @@
<include layout="@layout/home_content" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>

View file

@ -12,58 +12,9 @@
~ See the GNU General Public License for more details.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="UnusedAttribute">
<include layout="@layout/status_bar" />
</FrameLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:elevation="0dp"
app:elevation="0dp">
<com.google.android.material.card.MaterialCardView
android:id="@+id/toolbarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="?colorSurface"
app:popupTheme="?toolbarPopupTheme"
app:title="@string/action_search"
app:titleTextAppearance="@style/TextViewHeadline6"
tools:ignore="UnusedAttribute" />
</com.google.android.material.card.MaterialCardView>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -122,5 +73,3 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>

View file

@ -1,5 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?colorSurface"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
tools:ignore="UnusedAttribute">
<include layout="@layout/status_bar" />
</FrameLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:elevation="0dp"
app:elevation="0dp"
app:liftOnScroll="true">
<com.google.android.material.card.MaterialCardView
android:id="@+id/toolbarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
app:layout_scrollFlags="scroll|enterAlways">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="?attr/colorSurface"
app:navigationIcon="@drawable/ic_menu_white_24dp"
app:popupTheme="?attr/toolbarPopupTheme"
app:title="@string/action_search"
app:titleTextAppearance="@style/TextViewHeadline6"
app:titleTextColor="?android:attr/textColorSecondary"
tools:ignore="UnusedAttribute" />
<ViewStub
android:id="@+id/cab_stub"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height" />
</FrameLayout>
</com.google.android.material.card.MaterialCardView>
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>

View file

@ -11,22 +11,9 @@
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/status_bar" />
</FrameLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -38,28 +25,6 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.card.MaterialCardView
android:id="@+id/toolbarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_scrollFlags="scroll|enterAlways"
app:shapeAppearance="@style/ToolbarCornerCardView">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="?attr/colorSurface"
app:popupTheme="?toolbarPopupTheme"
app:title="@string/action_search"
app:titleTextAppearance="@style/TextViewHeadline6"
tools:ignore="UnusedAttribute" />
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/imageContainer"
@ -140,4 +105,3 @@
app:layout_constraintTop_toBottomOf="@+id/imageContainer" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>

View file

@ -1,90 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
tools:ignore="UnusedAttribute">
<include layout="@layout/status_bar" />
</FrameLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:elevation="0dp"
app:elevation="0dp">
<com.google.android.material.card.MaterialCardView
android:id="@+id/toolbarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="?toolbarPopupTheme"
app:title="@string/action_search"
app:titleMarginStart="0dp"
app:titleTextAppearance="@style/ToolbarTextAppearanceSearch"
tools:ignore="UnusedAttribute" />
<ViewStub
android:id="@+id/cab_stub"
android:layout_width="match_parent"
android:layout_height="48dp" />
</FrameLayout>
<code.name.monkey.retromusic.views.BreadCrumbLayout
android:id="@+id/breadCrumbs"
android:layout_width="match_parent"
android:layout_height="@dimen/tab_height"
android:paddingStart="60dp"
android:paddingEnd="8dp"
app:layout_collapseMode="pin" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:layoutAnimation="@anim/layout_animation_fall_down"
android:scrollbars="none"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
<LinearLayout
android:id="@android:id/empty"
android:layout_width="wrap_content"
@ -114,5 +36,27 @@
tools:visibility="visible" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<code.name.monkey.retromusic.views.BreadCrumbLayout
android:id="@+id/breadCrumbs"
android:layout_width="match_parent"
android:layout_height="@dimen/tab_height"
android:paddingStart="60dp"
android:paddingEnd="8dp"
app:layout_collapseMode="pin" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:layoutAnimation="@anim/layout_animation_fall_down"
android:scrollbars="none"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</LinearLayout>
</FrameLayout>

View file

@ -11,58 +11,9 @@
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/status_bar" />
</FrameLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:elevation="0dp"
app:elevation="0dp"
app:liftOnScroll="true">
<com.google.android.material.card.MaterialCardView
android:id="@+id/toolbarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="?attr/colorSurface"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="?attr/colorSurface"
app:popupTheme="?toolbarPopupTheme"
app:title="@string/action_search"
app:titleTextAppearance="@style/TextViewHeadline6"
tools:ignore="UnusedAttribute" />
</com.google.android.material.card.MaterialCardView>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -119,5 +70,3 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>

View file

@ -14,32 +14,44 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingStart="8dp"
android:paddingEnd="8dp">
android:paddingStart="16dp"
android:paddingEnd="0dp">
<com.google.android.material.button.MaterialButton
android:id="@+id/playAction"
android:layout_width="wrap_content"
<com.google.android.material.textview.MaterialTextView
android:id="@+id/songCount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_weight="1"
android:text="@string/action_play_all"
app:backgroundTint="?attr/colorSurface"
app:icon="@drawable/ic_play_arrow_white_24dp" />
android:textAppearance="@style/TextViewSubtitle1"
android:textStyle="bold" />
<com.google.android.material.button.MaterialButton
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/shuffleAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_weight="1"
android:text="@string/shuffle"
app:backgroundTint="?attr/colorSurface"
app:icon="@drawable/ic_shuffle_white_24dp" />
android:layout_weight="0"
android:background="?attr/roundSelector"
android:padding="16dp"
app:srcCompat="@drawable/ic_shuffle_white_24dp"
app:tint="?attr/colorControlNormal"
tools:tint="@color/black_color" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/sortAction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="?attr/roundSelector"
android:padding="16dp"
app:srcCompat="@drawable/ic_sort_white_24dp"
app:tint="?attr/colorControlNormal"
tools:tint="@color/black_color" />
</LinearLayout>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2020 Hemanth Savarala.
~
~ Licensed under the GNU General Public License v3
~
~ This is free software: you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by
~ the Free Software Foundation either version 3 of the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_grid_size_1"
android:title="@string/grid_size_1" />
<item
android:id="@+id/action_grid_size_2"
android:title="@string/grid_size_2" />
<item
android:id="@+id/action_grid_size_3"
android:title="@string/grid_size_3" />
<item
android:id="@+id/action_grid_size_4"
android:title="@string/grid_size_4" />
</menu>

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2020 Hemanth Savarala.
~
~ Licensed under the GNU General Public License v3
~
~ This is free software: you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by
~ the Free Software Foundation either version 3 of the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_song_sort_order_asc"
android:title="@string/sort_order_a_z" />
<item
android:id="@+id/action_song_sort_order_desc"
android:title="@string/sort_order_z_a" />
<item
android:id="@+id/action_song_sort_order_artist"
android:title="@string/sort_order_artist" />
<item
android:id="@+id/action_song_sort_order_album"
android:title="@string/sort_order_album" />
<item
android:id="@+id/action_song_sort_order_date"
android:title="@string/sort_order_date" />
<item
android:id="@+id/action_song_sort_order_year"
android:title="@string/sort_order_year" />
<item
android:id="@+id/action_song_sort_order_composer"
android:title="@string/sort_order_composer" />
</menu>

View file

@ -34,5 +34,7 @@
<item name="android:windowLightNavigationBar">false</item>
<!--Manual setting colors-->
<item name="colorSurface">@color/darkColorSurface</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style>
</resources>

View file

@ -34,5 +34,6 @@
<!--Manual setting colors-->
<item name="colorPrimary">@color/darkColorPrimary</item>
<item name="colorSurface">@color/darkColorSurface</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
</style>
</resources>

View file

@ -31,6 +31,8 @@
<item name="rectSelector">@drawable/rect_selector</item>
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style>
<style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar">
@ -55,6 +57,8 @@
<item name="android:windowLightNavigationBar">false</item>
<!--Manual setting colors-->
<item name="colorSurface">@color/darkColorSurface</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style>
<style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
@ -76,5 +80,7 @@
<item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item>
<item name="materialButtonStyle">@style/MaterialButtonTheme</item>
<item name="android:windowLightNavigationBar">false</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style>
</resources>

View file

@ -307,7 +307,7 @@
<string name="grid_size_7">7</string>
<string name="grid_size_8">8</string>
<string name="grid_style_label"><![CDATA[Grids & Style]]></string>
<string name="grid_style_label">Grid style</string>
<string name="hinge">Hinge</string>
@ -827,4 +827,8 @@
<string name="retro_music_player">Retro Music Player</string>
<string name="pro">Pro</string>
<string name="free">Free</string>
<plurals name="songCount">
<item quantity="one">%d Song</item>
<item quantity="other">%d Songs</item>
</plurals>
</resources>

View file

@ -184,4 +184,8 @@
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="RetroPopupTheme">
<item name="android:popupBackground">@drawable/popup_background</item>
<item name="android:popupElevation">4dp</item>
</style>
</resources>

View file

@ -17,6 +17,8 @@
<item name="roundSelector">@drawable/round_selector</item>
<item name="rectSelector">@drawable/rect_selector</item>
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style>
<style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar">
@ -41,6 +43,8 @@
<!--Manual setting colors-->
<item name="colorSurface">@color/darkColorSurface</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style>
<style name="Theme.RetroMusic.Base.Black" parent="Theme.MaterialComponents.NoActionBar">
@ -61,6 +65,8 @@
<item name="colorOnBackground">@color/blackColorSurface</item>
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
<item name="mcab_popup_theme">@style/ThemeOverlay.AppCompat.Dark</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style>
<style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
@ -81,6 +87,8 @@
<item name="windowActionBar">false</item>
<item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item>
<item name="materialButtonStyle">@style/MaterialButtonTheme</item>
<item name="popupMenuStyle">@style/RetroPopupTheme</item>
<item name="android:popupMenuStyle">@style/RetroPopupTheme</item>
</style>