Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Party Mode option #21

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Squeezer/src/main/java/uk/org/ngo/squeezer/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public final class Preferences {
// Fade-in period? (0 = disable fade-in)
public static final String KEY_FADE_IN_SECS = "squeezer.fadeInSecs";

// Are we having a party?
public static final String KEY_PARTYMODE_ENABLED = "squeezer.partymode.enabled";

// Pin to disable the party mode
public static final String KEY_PARTYMODE_PIN = "squeezer.partymode.pin";

// What do to when an album is selected in the list view
public static final String KEY_ON_SELECT_ALBUM_ACTION = "squeezer.action.onselect.album";

Expand All @@ -86,6 +92,31 @@ public Preferences(Context context) {
sharedPreferences = context.getSharedPreferences(Preferences.NAME, Context.MODE_PRIVATE);
}

public Boolean getPartyModeStatus() {
return sharedPreferences.getBoolean(Preferences.KEY_PARTYMODE_ENABLED, true);
}

public void setPartyModeStatus(Boolean status){
SharedPreferences.Editor editor = sharedPreferences.edit();

editor.putBoolean(Preferences.KEY_PARTYMODE_ENABLED, status);
editor.commit();
}

public String getPartyModePin() {
return getPartyModePin(null);
}

public String getPartyModePin(String defaultValue) {
return getStringPreference(Preferences.KEY_PARTYMODE_PIN, defaultValue);
}

public void setPartyModePin (String password){
SharedPreferences.Editor editor = sharedPreferences.edit();

editor.putString(Preferences.KEY_PARTYMODE_PIN, password);
editor.commit();
}

private String getStringPreference(String preference, String defaultValue) {
final String pref = sharedPreferences.getString(preference, null);
Expand Down
23 changes: 22 additions & 1 deletion Squeezer/src/main/java/uk/org/ngo/squeezer/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ protected void onCreate(Bundle savedInstanceState) {
CheckBoxPreference startSqueezePlayerPref = (CheckBoxPreference) findPreference(
Preferences.KEY_SQUEEZEPLAYER_ENABLED);
startSqueezePlayerPref.setChecked(preferences.getBoolean(Preferences.KEY_SQUEEZEPLAYER_ENABLED, true));

if(preferences.getBoolean(Preferences.KEY_PARTYMODE_ENABLED, false)) {
SetAllSettingEnabled(false);
}
}

private void SetAllSettingEnabled(boolean status)
{
findPreference(Preferences.KEY_SCROBBLE_ENABLED).setEnabled(status);
findPreference(Preferences.KEY_ANALYTICS_ENABLED).setEnabled(status);
findPreference(Preferences.KEY_FADE_IN_SECS).setEnabled(status);
findPreference(Preferences.KEY_SQUEEZEPLAYER_ENABLED).setEnabled(status);
findPreference(Preferences.KEY_NOTIFY_OF_CONNECTION).setEnabled(status);
findPreference(Preferences.KEY_AUTO_CONNECT).setEnabled(status);
findPreference(Preferences.KEY_SERVERADDR).setEnabled(status);
findPreference(Preferences.KEY_ON_THEME_SELECT_ACTION).setEnabled(status);
findPreference(Preferences.KEY_ON_SELECT_SONG_ACTION).setEnabled(status);
findPreference(Preferences.KEY_ON_SELECT_ALBUM_ACTION).setEnabled(status);
}

private void fillScrobblePreferences(SharedPreferences preferences) {
Expand Down Expand Up @@ -331,8 +349,11 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
} else {
Log.v(TAG, "service is null!");
}
}

if (Preferences.KEY_PARTYMODE_ENABLED.equals(key)) {
finish();
}
}
@Override
@Deprecated
protected Dialog onCreateDialog(int id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2012 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package uk.org.ngo.squeezer.dialog;

import android.content.Context;
import android.os.Parcelable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import uk.org.ngo.squeezer.Preferences;
import uk.org.ngo.squeezer.R;

/**
* Shows a preference dialog that allows the user to enable party mode, and choose an
* optional pin to disable party mode.
*/
public class PartyModePin extends DialogPreference {

private EditText passwordEditText;
private boolean previousPartyModeEnabled;
private Preferences preferences;

public PartyModePin(Context context, AttributeSet attrs) {
super(context, attrs);
setDialogLayoutResource(R.layout.party_mode_pin);
}

@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);

preferences = new Preferences(getContext());
passwordEditText = (EditText) view.findViewById(R.id.partypin);

previousPartyModeEnabled = preferences.getPartyModeStatus();

TextView statusText = (TextView) view.findViewById(R.id.PartyStatus);
if (previousPartyModeEnabled) {
statusText.setText("Disable Party Mode:");
} else {
statusText.setText("Enable Party Mode:");
}
}

@Override
protected void onDialogClosed(boolean positiveResult) {

// If the user has pressed ok
if (positiveResult) {

// If party mode wasn't enabled before
if (!previousPartyModeEnabled) {
String pin = passwordEditText.getText().toString();
preferences.setPartyModePin(pin);
preferences.setPartyModeStatus(true);

} else {
String storedPin = preferences.getPartyModePin(null);
String pin = passwordEditText.getText().toString();

if (storedPin == null || pin.equals(preferences.getPartyModePin())) {
preferences.setPartyModeStatus(false);
}
}
}
}

@Override
protected Parcelable onSaveInstanceState() {
return super.onSaveInstanceState();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,23 @@ public String getServerString(ServerString stringToken) {
// This section is just an easier way to call squeeze service

public void play(PlaylistItem item) {
playlistControl(PlaylistControlCmd.load, item, R.string.ITEM_PLAYING);
if (new Preferences(this).getPartyModeStatus()) {
playlistControl(PlaylistControlCmd.add, item, R.string.ITEM_ADDED);
} else {
playlistControl(PlaylistControlCmd.load, item, R.string.ITEM_PLAYING);
}
}

public void add(PlaylistItem item) {
playlistControl(PlaylistControlCmd.add, item, R.string.ITEM_ADDED);
}

public void insert(PlaylistItem item) {
playlistControl(PlaylistControlCmd.insert, item, R.string.ITEM_INSERTED);
if (new Preferences(this).getPartyModeStatus()) {
playlistControl(PlaylistControlCmd.add, item, R.string.ITEM_ADDED);
} else {
playlistControl(PlaylistControlCmd.insert, item, R.string.ITEM_INSERTED);
}
}

private void playlistControl(PlaylistControlCmd cmd, PlaylistItem item, int resId)
Expand Down
Loading