aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2017-04-17 17:19:49 -0700
committerScott Jackson <daneren2005@gmail.com>2017-04-17 17:19:49 -0700
commit8a7d214e7d7d5b47832f44de3e232e03ec7f10d3 (patch)
tree3e0790cc6d3c36287be13f4bc939c80aa8246b0e /app/src
parent544d65124e3e3a85694238da4639749f7c9f34ef (diff)
parent594e5ac1a5b86f495c60857e45c5eca16229faac (diff)
downloaddsub-8a7d214e7d7d5b47832f44de3e232e03ec7f10d3.tar.gz
dsub-8a7d214e7d7d5b47832f44de3e232e03ec7f10d3.tar.bz2
dsub-8a7d214e7d7d5b47832f44de3e232e03ec7f10d3.zip
Merge branch 'enhanced-playback-speed' of https://github.com/SilentViking/Subsonic into SilentViking-enhanced-playback-speed
# Conflicts: # app/src/main/java/github/daneren2005/dsub/util/Constants.java
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java137
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java17
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/DroppySpeedControl.java82
-rw-r--r--app/src/main/res/layout/set_playback_speed.xml62
-rw-r--r--app/src/main/res/menu/playback_speed_options.xml26
6 files changed, 203 insertions, 123 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
index c2debd4d..08cbf150 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
@@ -729,7 +729,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
editor.putString(Constants.PREFERENCES_KEY_SERVER_NAME + 1, "Demo Server");
editor.putString(Constants.PREFERENCES_KEY_SERVER_URL + 1, "http://demo.subsonic.org");
- editor.putString(Constants.PREFERENCES_KEY_USERNAME + 1, "guest");
+ editor.putString(Constants.PREFERENCES_KEY_USERNAME + 1, "guest2");
editor.putString(Constants.PREFERENCES_KEY_PASSWORD + 1, "guest");
editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
editor.commit();
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
index bf91bd1a..19df9bfb 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
@@ -55,6 +55,9 @@ import android.widget.PopupMenu;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ViewFlipper;
+import com.shehabic.droppy.DroppyClickCallbackInterface;
+import com.shehabic.droppy.DroppyMenuPopup;
+import com.shehabic.droppy.animations.DroppyFadeInAnimation;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.adapter.SectionAdapter;
@@ -132,6 +135,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
private int lastY = 0;
private int currentPlayingSize = 0;
private MenuItem timerMenu;
+ private DroppySpeedControl speed;
/**
* Called when the activity is first created.
@@ -391,41 +395,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
});
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- playbackSpeedButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- PopupMenu popup = new PopupMenu(context, v);
- popup.getMenuInflater().inflate(R.menu.playback_speed_options, popup.getMenu());
-
- popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem menuItem) {
- float playbackSpeed = 1.0f;
- switch (menuItem.getItemId()) {
- case R.id.playback_speed_half:
- playbackSpeed = 0.5f;
- break;
- case R.id.playback_speed_one_half:
- playbackSpeed = 1.5f;
- break;
- case R.id.playback_speed_double:
- playbackSpeed = 2.0f;
- break;
- case R.id.playback_speed_tripple:
- playbackSpeed = 3.0f;
- break;
- case R.id.playback_speed_custom:
- setPlaybackSpeed();
- return true;
- }
-
- setPlaybackSpeed(playbackSpeed);
- return true;
- }
- });
- popup.show();
- }
- });
+ setPlaybackSpeed();
} else {
playbackSpeedButton.setVisibility(View.GONE);
}
@@ -1277,6 +1247,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
}
}
updateTitle();
+ setPlaybackSpeed();
}
private void setupSubtitle(int currentPlayingIndex) {
@@ -1345,6 +1316,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
toggleListButton.setVisibility(View.VISIBLE);
repeatButton.setVisibility(View.VISIBLE);
}
+ setPlaybackSpeed();
}
@Override
@@ -1546,55 +1518,52 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
}
private void setPlaybackSpeed() {
- View dialogView = context.getLayoutInflater().inflate(R.layout.set_playback_speed, null);
-
- // Setup playbackSpeed label
- final TextView playbackSpeedBox = (TextView) dialogView.findViewById(R.id.playback_speed_label);
- final SharedPreferences prefs = Util.getPreferences(context);
- String playbackSpeedString = prefs.getString(Constants.PREFERENCES_KEY_CUSTOM_PLAYBACK_SPEED, "17");
- int playbackSpeed = Integer.parseInt(playbackSpeedString);
- playbackSpeedBox.setText(new Float(playbackSpeed / 10.0).toString());
-
- // Setup playbackSpeed slider
- final SeekBar playbackSpeedBar = (SeekBar) dialogView.findViewById(R.id.playback_speed_bar);
- playbackSpeedBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- if (fromUser) {
- playbackSpeedBox.setText(new Float((progress + 5) / 10.0).toString());
- seekBar.setProgress(progress);
- }
- }
-
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- }
-
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- }
- });
- playbackSpeedBar.setProgress(playbackSpeed - 5);
-
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setTitle(R.string.download_playback_speed_custom)
- .setView(dialogView)
- .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- int playbackSpeed = playbackSpeedBar.getProgress() + 5;
-
- SharedPreferences.Editor editor = prefs.edit();
- editor.putString(Constants.PREFERENCES_KEY_CUSTOM_PLAYBACK_SPEED, Integer.toString(playbackSpeed));
- editor.commit();
-
- setPlaybackSpeed(new Float(playbackSpeed / 10.0));
- }
- })
- .setNegativeButton(R.string.common_cancel, null);
- AlertDialog dialog = builder.create();
- dialog.show();
- }
+ if (playbackSpeedButton.getVisibility() == View.GONE)
+ return;
+ speed = new DroppySpeedControl(R.layout.set_playback_speed);
+ DroppyMenuPopup.Builder builder = new DroppyMenuPopup.Builder(context,playbackSpeedButton);
+ speed.setClickable(true);
+ float playbackSpeed;
+
+ playbackSpeed = getDownloadService() != null ? getDownloadService().getPlaybackSpeed() : 1.0f;
+
+ final DroppyMenuPopup popup = builder.triggerOnAnchorClick(true).addMenuItem(speed).setPopupAnimation(new DroppyFadeInAnimation()).build();
+ speed.setOnSeekBarChangeListener(context, new DroppyClickCallbackInterface() {
+ @Override
+ public void call(View v, int id) {
+ SeekBar playbackSpeedBar = (SeekBar) v;
+ int playbackSpeed = playbackSpeedBar.getProgress() +5 ;
+ setPlaybackSpeed(playbackSpeed/10f);
+ }
+ },R.id.playback_speed_bar,R.id.playback_speed_label,playbackSpeed);
+ speed.setOnClicks(context,
+ new DroppyClickCallbackInterface() {
+ @Override
+ public void call(View v, int id) {
+ float playbackSpeed = 1.0f;
+ switch (id) {
+ case R.id.playback_speed_one_half:
+ playbackSpeed = 1.5f;
+ break;
+ case R.id.playback_speed_double:
+ playbackSpeed = 2.0f;
+ break;
+ case R.id.playback_speed_triple:
+ playbackSpeed = 3.0f;
+ break;
+ default:
+ break;
+ }
+ setPlaybackSpeed(playbackSpeed);
+ speed.updateSeekBar(playbackSpeed);
+ popup.dismiss(true);
+ }
+ }
+ ,R.id.playback_speed_normal,R.id.playback_speed_one_half,R.id.playback_speed_double,
+ R.id.playback_speed_triple);
+ speed.updateSeekBar(playbackSpeed);
+
+ }
private void setPlaybackSpeed(float playbackSpeed) {
DownloadService downloadService = getDownloadService();
if (downloadService == null) {
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
index b346f499..636745d6 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -873,7 +873,7 @@ public class DownloadService extends Service {
this.currentPlaying.setPlaying(false);
}
if(delayUpdateProgress != DEFAULT_DELAY_UPDATE_PROGRESS && !isNextPlayingSameAlbum(currentPlaying, this.currentPlaying)) {
- resetPlaybackSpeed();
+// resetPlaybackSpeed();
}
this.currentPlaying = currentPlaying;
if(currentPlaying == null) {
@@ -2660,7 +2660,10 @@ public class DownloadService extends Service {
}
public void setPlaybackSpeed(float playbackSpeed) {
- Util.getPreferences(this).edit().putFloat(Constants.PREFERENCES_KEY_PLAYBACK_SPEED, playbackSpeed).commit();
+ if(currentPlaying.isSong())
+ Util.getPreferences(this).edit().putFloat(Constants.PREFERENCES_KEY_SONG_PLAYBACK_SPEED, playbackSpeed).commit();
+ else
+ Util.getPreferences(this).edit().putFloat(Constants.PREFERENCES_KEY_PLAYBACK_SPEED, playbackSpeed).commit();
if(mediaPlayer != null && (playerState == PREPARED || playerState == STARTED || playerState == PAUSED || playerState == PAUSED_TEMP)) {
applyPlaybackParamsMain();
}
@@ -2669,10 +2672,18 @@ public class DownloadService extends Service {
}
private void resetPlaybackSpeed() {
Util.getPreferences(this).edit().remove(Constants.PREFERENCES_KEY_PLAYBACK_SPEED).commit();
+ Util.getPreferences(this).edit().remove(Constants.PREFERENCES_KEY_SONG_PLAYBACK_SPEED).commit();
}
public float getPlaybackSpeed() {
- return Util.getPreferences(this).getFloat(Constants.PREFERENCES_KEY_PLAYBACK_SPEED, 1.0f);
+ if (currentPlaying == null)
+ return 1.0f;
+ else {
+ if (currentPlaying.isSong())
+ return Util.getPreferences(this).getFloat(Constants.PREFERENCES_KEY_SONG_PLAYBACK_SPEED, 1.0f);
+ else
+ return Util.getPreferences(this).getFloat(Constants.PREFERENCES_KEY_PLAYBACK_SPEED, 1.0f);
+ }
}
private synchronized void applyPlaybackParamsMain() {
diff --git a/app/src/main/java/github/daneren2005/dsub/util/DroppySpeedControl.java b/app/src/main/java/github/daneren2005/dsub/util/DroppySpeedControl.java
new file mode 100644
index 00000000..8f58e60e
--- /dev/null
+++ b/app/src/main/java/github/daneren2005/dsub/util/DroppySpeedControl.java
@@ -0,0 +1,82 @@
+package github.daneren2005.dsub.util;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.view.View;
+import android.widget.SeekBar;
+import android.widget.TextView;
+import com.shehabic.droppy.DroppyClickCallbackInterface;
+import com.shehabic.droppy.DroppyMenuCustomItem;
+
+/**
+ * Created by marcus on 2/14/2017.
+ */
+public class DroppySpeedControl extends DroppyMenuCustomItem {
+
+ private Context context;
+ private SeekBar seekBar;
+ private DroppyClickCallbackInterface updateBarCallback;
+ public DroppySpeedControl(int customResourceId) {
+ super(customResourceId);
+
+ }
+
+ @Override
+ public View render(Context context) {
+ return super.render(context);
+
+
+ }
+
+ public DroppySpeedControl setOnClicks(Context context, final DroppyClickCallbackInterface callback, int ... elementsByID){
+ render(context);
+ View.OnClickListener listener = new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ callback.call(v, v.getId());
+ }
+ };
+ for (Integer element : elementsByID) {
+ renderedView.findViewById(element).setOnClickListener(listener);
+ }
+ return this;
+ }
+
+
+ public void updateSeekBar(float playbackSpeed){
+ TextView tv = (TextView)seekBar.getTag();
+ tv.setText(Float.toString(playbackSpeed));
+ seekBar.setProgress((int)(playbackSpeed*10)-5);
+ }
+
+ public DroppySpeedControl setOnSeekBarChangeListener(Context context, final DroppyClickCallbackInterface callback, int seekBarByID, int textViewByID, float playbackSpeed) {
+ updateBarCallback = callback;
+ render(context);
+ final TextView textBox = (TextView) renderedView.findViewById(textViewByID);
+ textBox.setText(Float.toString(playbackSpeed));
+ SeekBar seekBar = ((SeekBar) renderedView.findViewById(seekBarByID));
+ this.seekBar = seekBar;
+ seekBar.setTag(textBox);
+ seekBar.setProgress((int)(playbackSpeed*10)-5);
+ seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ if (fromUser) {
+ textBox.setText(new Float((progress + 5) / 10.0).toString());
+ seekBar.setProgress(progress);
+ callback.call(seekBar,seekBar.getId());
+ }
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ }
+ });
+ seekBar.setProgress((int)((playbackSpeed/10.0) - 5));
+ return this;
+ }
+}
diff --git a/app/src/main/res/layout/set_playback_speed.xml b/app/src/main/res/layout/set_playback_speed.xml
index 42f23a35..c85719bb 100644
--- a/app/src/main/res/layout/set_playback_speed.xml
+++ b/app/src/main/res/layout/set_playback_speed.xml
@@ -1,8 +1,48 @@
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center">
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:background="?android:colorBackground"
+ >
+
+
+ <LinearLayout
+ android:id="@+id/playback_speed_buttons"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:orientation="horizontal"
+ >
+
+ <Button
+ android:id="@+id/playback_speed_normal"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="1.0x"
+ android:tag="1.0"/>
+ <Button
+ android:id="@+id/playback_speed_one_half"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:tag="1.5"
+ android:text="1.5x"/>
+
+ <Button
+ android:id="@+id/playback_speed_double"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:tag="2.0"
+ android:text="2.0x"/>
+
+
+ <Button
+ android:id="@+id/playback_speed_triple"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="3.0x"
+ android:tag="3.0"/>
+ </LinearLayout>
<TextView
android:id="@+id/playback_speed_label"
@@ -11,12 +51,16 @@
android:layout_marginLeft="8dp"
android:textSize="20dp"
android:paddingRight="10px"
- android:layout_gravity="center"
- android:textColor="?android:textColorPrimary"/>
+ android:textColor="?android:textColorPrimary"
+ android:layout_below="@+id/playback_speed_buttons"/>
<SeekBar
android:id="@+id/playback_speed_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
- android:max="25"/>
-</LinearLayout> \ No newline at end of file
+ android:max="25"
+ android:layout_toRightOf="@+id/playback_speed_label"
+ android:layout_below="@+id/playback_speed_buttons"
+ />
+
+</RelativeLayout> \ No newline at end of file
diff --git a/app/src/main/res/menu/playback_speed_options.xml b/app/src/main/res/menu/playback_speed_options.xml
deleted file mode 100644
index 909d3b3c..00000000
--- a/app/src/main/res/menu/playback_speed_options.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<menu xmlns:android="http://schemas.android.com/apk/res/android">
- <item
- android:id="@+id/playback_speed_half"
- android:title="@string/download.playback_speed_half"/>
-
- <item
- android:id="@+id/playback_speed_normal"
- android:title="@string/download.playback_speed_normal"/>
-
- <item
- android:id="@+id/playback_speed_one_half"
- android:title="@string/download.playback_speed_one_half"/>
-
- <item
- android:id="@+id/playback_speed_double"
- android:title="@string/download.playback_speed_double"/>
-
- <item
- android:id="@+id/playback_speed_tripple"
- android:title="@string/download.playback_speed_tripple"/>
-
- <item
- android:id="@+id/playback_speed_custom"
- android:title="@string/download.playback_speed_custom"/>
-</menu> \ No newline at end of file