Check the status of the mute button in NowPlaying (#294)

This commit is contained in:
tomerf 2016-11-20 16:18:43 +02:00 committed by Synced Synapse
parent b1ec57f8e6
commit d2b5449e98
1 changed files with 30 additions and 12 deletions

View File

@ -222,6 +222,16 @@ public class NowPlayingFragment extends Fragment
public void onResume() {
super.onResume();
hostConnectionObserver.registerPlayerObserver(this, true);
Application.GetProperties action = new Application.GetProperties(Application.GetProperties.MUTED);
action.execute(hostManager.getConnection(), new ApiCallback<ApplicationType.PropertyValue>() {
@Override
public void onSuccess(ApplicationType.PropertyValue result) {
setVolumeMuteButton(result.muted);
}
@Override
public void onError(int errorCode, String description) { }
}, callbackHandler);
}
@Override
@ -311,18 +321,7 @@ public class NowPlayingFragment extends Fragment
action.execute(hostManager.getConnection(), new ApiCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
if (!isAdded()) return;
if (result) {
Resources.Theme theme = getActivity().getTheme();
TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] {
R.attr.colorAccent});
volumeMuteButton.setColorFilter(
styledAttributes.getColor(0,
getActivity().getResources().getColor(R.color.accent_default)));
styledAttributes.recycle();
} else {
volumeMuteButton.clearColorFilter();
}
setVolumeMuteButton(result);
}
@Override
@ -955,6 +954,25 @@ public class NowPlayingFragment extends Fragment
}
}
/**
* Sets the color of the mute volume button according to the player's status
* @param isMuted Whether the player is muted
*/
private void setVolumeMuteButton(Boolean isMuted) {
if (!isAdded()) return;
if (isMuted) {
Resources.Theme theme = getActivity().getTheme();
TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] {
R.attr.colorAccent});
volumeMuteButton.setColorFilter(
styledAttributes.getColor(0,
getActivity().getResources().getColor(R.color.accent_default)));
styledAttributes.recycle();
} else {
volumeMuteButton.clearColorFilter();
}
}
/**
* Seekbar change listener. Sends seek commands to XBMC based on the seekbar position
*/