Various fixes and improvements

This commit is contained in:
Karim Abou Zeid 2015-08-03 20:42:16 +02:00
commit 6b68c17ae2
26 changed files with 142 additions and 121 deletions

View file

@ -223,6 +223,7 @@ public class AlbumDetailActivity extends AbsSlidingMusicPanelActivity implements
@Override
public void onLoadingFailed(String imageUri, View view, @Nullable FailReason failReason) {
setUpBackground("drawable://" + R.drawable.default_album_art);
setColors(ColorUtil.resolveColor(AlbumDetailActivity.this, R.attr.default_bar_color));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
startPostponedEnterTransition();

View file

@ -311,6 +311,7 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
@Override
public void onLoadingFailed(String imageUri, View view, @Nullable FailReason failReason) {
setUpBackground("drawable://" + R.drawable.default_artist_image);
setColors(ColorUtil.resolveColor(ArtistDetailActivity.this, R.attr.default_bar_color));
toastUpdatedArtistImageIfDownloadWasForced();
}

View file

@ -25,7 +25,6 @@ import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
@ -170,9 +169,9 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
tabStripField.setAccessible(true);
Object tabStrip = tabStripField.get(tabs);
Method setSelectedIndicatorColorMethod = tabStrip.getClass().getDeclaredMethod("setSelectedIndicatorColor", int.class);
Method setSelectedIndicatorColorMethod = tabStrip.getClass().getDeclaredMethod("setSelectedIndicatorColor", Integer.TYPE);
setSelectedIndicatorColorMethod.setAccessible(true);
setSelectedIndicatorColorMethod.invoke(tabStrip, ThemeSingleton.get().positiveColor);
setSelectedIndicatorColorMethod.invoke(tabStrip, ThemeSingleton.get().positiveColor.getDefaultColor());
} catch (Exception e) {
e.printStackTrace();
}
@ -190,7 +189,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
}
private void setUpNavigationView() {
final int colorAccent = ThemeSingleton.get().positiveColor;
final int colorAccent = ThemeSingleton.get().positiveColor.getDefaultColor();
navigationView.setItemTextColor(new ColorStateList(
new int[][]{
//{-android.R.attr.state_enabled}, // disabled
@ -476,10 +475,10 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
String mimeType = intent.getType();
boolean handled = false;
if (intent.getAction() != null
&& intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
if (intent.getAction() != null && intent.getAction().equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) {
MusicPlayerRemote.openQueue(SearchQueryHelper.getSongs(this, intent.getExtras()), 0, true);
}
if (uri != null && uri.toString().length() > 0) {
MusicPlayerRemote.playFile(new File(uri.getPath()).getAbsolutePath());
handled = true;
@ -564,14 +563,12 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
// return (PlaylistViewFragment) pagerAdapter.getFragment(PagerAdapter.MusicFragments.PLAYLIST.ordinal());
// }
@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_UP) {
if (toolbar != null)
toolbar.showOverflowMenu();
return true;
}
return super.dispatchKeyEvent(event);
protected void showOverflowMenu() {
super.showOverflowMenu();
if (toolbar != null && getSlidingUpPanelLayout().getPanelState() != SlidingUpPanelLayout.PanelState.EXPANDED)
toolbar.showOverflowMenu();
}
@Override

View file

@ -29,9 +29,9 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
setStatusBarTransparent();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preferences);
setStatusBarTransparent();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setBackgroundColor(getThemeColorPrimary());

View file

@ -2,6 +2,8 @@ package com.kabouzeid.gramophone.ui.activities.base;
import android.media.AudioManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.KeyEvent;
import com.kabouzeid.gramophone.interfaces.KabViewsDisableAble;
@ -24,9 +26,22 @@ public abstract class AbsBaseActivity extends AbsThemeActivity implements KabVie
enableViews();
}
@Override
public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_UP) {
showOverflowMenu();
return true;
}
return super.dispatchKeyEvent(event);
}
protected void showOverflowMenu() {
}
/**
* Should be overwritten and re enable all {@link android.view.View} to ensure they are accessible again
* <p>
* <p/>
* This is necessary because of a bug with the shared element transition
*/
@Override
@ -36,7 +51,7 @@ public abstract class AbsBaseActivity extends AbsThemeActivity implements KabVie
/**
* Should be overwritten and disable all views that start a new activity on click to prevent opening an activity multiple times
* <p>
* <p/>
* This is necessary because of a bug with the shared element transition
*/
@Override

View file

@ -27,41 +27,48 @@ public abstract class AbsMusicStateActivity extends AbsBaseActivity implements S
private MusicPlayerRemote.ServiceToken serviceToken;
private MusicStateReceiver musicStateReceiver;
private boolean receiverRegistered;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
serviceToken = MusicPlayerRemote.bindToService(this, this);
musicStateReceiver = new MusicStateReceiver(this);
final IntentFilter filter = new IntentFilter();
filter.addAction(MusicService.PLAY_STATE_CHANGED);
filter.addAction(MusicService.SHUFFLE_MODE_CHANGED);
filter.addAction(MusicService.REPEAT_MODE_CHANGED);
filter.addAction(MusicService.META_CHANGED);
filter.addAction(MusicService.MEDIA_STORE_CHANGED);
registerReceiver(musicStateReceiver, filter);
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
onPlayStateChanged();
onRepeatModeChanged();
onShuffleModeChanged();
onPlayingMetaChanged();
if (!receiverRegistered) {
musicStateReceiver = new MusicStateReceiver(this);
final IntentFilter filter = new IntentFilter();
filter.addAction(MusicService.PLAY_STATE_CHANGED);
filter.addAction(MusicService.SHUFFLE_MODE_CHANGED);
filter.addAction(MusicService.REPEAT_MODE_CHANGED);
filter.addAction(MusicService.META_CHANGED);
filter.addAction(MusicService.MEDIA_STORE_CHANGED);
registerReceiver(musicStateReceiver, filter);
receiverRegistered = true;
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
if (receiverRegistered) {
unregisterReceiver(musicStateReceiver);
receiverRegistered = false;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
MusicPlayerRemote.unbindFromService(serviceToken);
unregisterReceiver(musicStateReceiver);
if (receiverRegistered) {
unregisterReceiver(musicStateReceiver);
receiverRegistered = false;
}
}
public void addMusicStateListenerListener(final MusicStateListener listener) {

View file

@ -72,6 +72,7 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
private static final int FAB_CIRCULAR_REVEAL_ANIMATION_TIME = 1000;
private static final long DEFAULT_PROGRESS_VIEW_REFRESH_INTERVAL = 500;
private static final int CMD_REFRESH_PROGRESS_VIEWS = 1;
private static final String PANEL_EXPANDED_KEY = "panel_state";
@Bind(R.id.play_pause_fab)
FloatingActionButton playPauseFab;
@ -161,6 +162,17 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
setUpPlayerToolbar();
progressViewsUpdateHandler = new MusicProgressViewsUpdateHandler(this);
slidingUpPanelLayout.post(new Runnable() {
@Override
public void run() {
if (slidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
mediaControllerContainer.setVisibility(View.VISIBLE);
onPanelSlide(slidingUpPanelLayout, 1);
onPanelExpanded(slidingUpPanelLayout);
}
}
});
}
protected abstract View createContentView();
@ -201,10 +213,9 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
updateFabState(false);
playPauseFab.setImageDrawable(playPauseDrawable);
final int accentColor = ThemeSingleton.get().positiveColor;
playPauseFab.setBackgroundTintList(ColorUtil.getEmptyColorStateList(accentColor));
if (accentColor == Color.WHITE) {
playPauseFab.getDrawable().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
playPauseFab.setBackgroundTintList(ThemeSingleton.get().positiveColor);
if (getThemeColorAccent() == Color.WHITE) {
playPauseFab.getDrawable().setColorFilter(getResources().getColor(R.color.primary_text_default_material_light), PorterDuff.Mode.SRC_IN);
} else {
playPauseFab.getDrawable().clearColorFilter();
}
@ -315,6 +326,10 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
@Override
public void onPanelExpanded(View view) {
onPanelSlide(view, 1);
if (!progressViewsUpdateHandler.hasMessages(CMD_REFRESH_PROGRESS_VIEWS)) {
startUpdatingProgressViews();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (mediaControllerContainer.getVisibility() == View.INVISIBLE) {
int cx = (dummyFab.getLeft() + dummyFab.getRight()) / 2;
@ -474,7 +489,7 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
}
private void setUpSeekBar() {
setTint(seekBar, !ThemeSingleton.get().darkTheme && getThemeColorAccent() == Color.WHITE ? Color.BLACK : getThemeColorAccent());
setTint(seekBar, getThemeColorAccent());
seekBar.setOnSeekBarChangeListener(new SimpleOnSeekbarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@ -520,11 +535,11 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
switch (MusicPlayerRemote.getShuffleMode()) {
case MusicService.SHUFFLE_MODE_SHUFFLE:
shuffleButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_shuffle_white_36dp,
getThemeColorAccent() == Color.WHITE ? Color.BLACK : getThemeColorAccent()));
getThemeColorAccent() == Color.WHITE ? getResources().getColor(R.color.primary_text_default_material_light) : getThemeColorAccent()));
break;
default:
shuffleButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_shuffle_white_36dp,
DialogUtils.resolveColor(this, R.attr.themed_drawable_color)));
ColorUtil.resolveColor(this, R.attr.themed_drawable_color)));
break;
}
}
@ -547,11 +562,11 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
break;
case MusicService.REPEAT_MODE_ALL:
repeatButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_repeat_white_36dp,
getThemeColorAccent() == Color.WHITE ? Color.BLACK : getThemeColorAccent()));
getThemeColorAccent() == Color.WHITE ? getResources().getColor(R.color.primary_text_default_material_light) : getThemeColorAccent()));
break;
default:
repeatButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_repeat_one_white_36dp,
getThemeColorAccent() == Color.WHITE ? Color.BLACK : getThemeColorAccent()));
getThemeColorAccent() == Color.WHITE ? getResources().getColor(R.color.primary_text_default_material_light) : getThemeColorAccent()));
break;
}
}
@ -740,7 +755,7 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
}
private void startUpdatingProgressViews() {
queueNextRefresh(0);
queueNextRefresh(1);
}
private void stopUpdatingProgressViews() {
@ -789,7 +804,11 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
if (msg.what == CMD_REFRESH_PROGRESS_VIEWS) {
activityReference.get().queueNextRefresh(activityReference.get().refreshProgressViews());
AbsSlidingMusicPanelActivity activity = activityReference.get();
if (activity != null) {
long nextDelay = activityReference.get().refreshProgressViews();
activityReference.get().queueNextRefresh(nextDelay);
}
}
}
}

View file

@ -1,6 +1,7 @@
package com.kabouzeid.gramophone.ui.activities.base;
import android.app.ActivityManager;
import android.content.res.ColorStateList;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.ColorInt;
@ -49,9 +50,10 @@ public abstract class AbsThemeActivity extends AppCompatActivity implements KabV
darkTheme = PreferenceUtil.getInstance(this).getGeneralTheme() == R.style.Theme_MaterialMusic;
coloredNavigationBar = PreferenceUtil.getInstance(this).shouldUseColoredNavigationBar();
ThemeSingleton.get().positiveColor = colorAccent;
ThemeSingleton.get().negativeColor = colorAccent;
ThemeSingleton.get().neutralColor = colorAccent;
final ColorStateList accentColorStateList = ColorStateList.valueOf(colorAccent);
ThemeSingleton.get().positiveColor = accentColorStateList;
ThemeSingleton.get().negativeColor = accentColorStateList;
ThemeSingleton.get().neutralColor = accentColorStateList;
ThemeSingleton.get().widgetColor = colorAccent;
ThemeSingleton.get().darkTheme = darkTheme;

View file

@ -192,7 +192,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
save();
}
});
fab.setRippleColor(ThemeSingleton.get().positiveColor);
fab.setBackgroundTintList(ThemeSingleton.get().positiveColor);
}
protected abstract void save();