From de52e1d9d5fad1895fe029f39b467f78067f0642 Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Wed, 26 Dec 2018 15:24:02 +0100 Subject: [PATCH 1/3] - Kill notification when app is killed --- .../peertube/activity/VideoListActivity.java | 6 ++++++ .../peertube/service/VideoPlayerService.java | 20 ++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java index a256766..67514c3 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoListActivity.java @@ -38,6 +38,7 @@ import net.schueller.peertube.model.VideoList; import net.schueller.peertube.network.GetVideoDataService; import net.schueller.peertube.network.RetrofitInstance; import net.schueller.peertube.provider.SearchSuggestionsProvider; +import net.schueller.peertube.service.VideoPlayerService; import java.util.ArrayList; @@ -151,6 +152,11 @@ public class VideoListActivity extends AppCompatActivity { return true; } + @Override + protected void onDestroy() { + super.onDestroy(); + stopService(new Intent(this, VideoPlayerService.class)); + } @Override public boolean onOptionsItemSelected(MenuItem item) { diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java index 063bde0..e50d66e 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java @@ -37,6 +37,8 @@ import static net.schueller.peertube.activity.VideoListActivity.EXTRA_VIDEOID; public class VideoPlayerService extends Service { + private static final String TAG = "VideoPlayerService"; + private final IBinder mBinder = new LocalBinder(); private static final String PLAYBACK_CHANNEL_ID = "playback_channel"; @@ -64,12 +66,12 @@ public class VideoPlayerService extends Service { public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playbackState == ACTION_PAUSE) { // this means that pause is available, hence the audio is playing - Log.v("VideoPlayerService", "ACTION_PLAY: " + playbackState); + Log.v(TAG, "ACTION_PLAY: " + playbackState); registerReceiver(myNoisyAudioStreamReceiver, becomeNoisyIntentFilter); } if (playbackState == ACTION_PLAY) { // this means that play is available, hence the audio is paused or stopped - Log.v("VideoPlayerService", "ACTION_PAUSE: " + playbackState); + Log.v(TAG, "ACTION_PAUSE: " + playbackState); unregisterReceiver(myNoisyAudioStreamReceiver); } } @@ -89,7 +91,7 @@ public class VideoPlayerService extends Service { @Override public void onDestroy() { - Log.v("VideoPlayerService", "onDestroy..."); + Log.v(TAG, "onDestroy..."); playerNotificationManager.setPlayer(null); player.release(); @@ -106,7 +108,7 @@ public class VideoPlayerService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { - Log.v("VideoPlayerService", "onStartCommand..."); + Log.v(TAG, "onStartCommand..."); playVideo(); return START_STICKY; } @@ -114,27 +116,27 @@ public class VideoPlayerService extends Service { public void setCurrentVideo(Video video) { - Log.v("VideoPlayerService", "setCurrentVideo..."); + Log.v(TAG, "setCurrentVideo..."); currentVideo = video; } public void setCurrentStreamUrl(String streamUrl) { - Log.v("VideoPlayerService", "setCurrentStreamUrl..."); + Log.v(TAG, "setCurrentStreamUrl..."); currentStreamUrl = streamUrl; } //Playback speed control public void setPlayBackSpeed(float speed) { - Log.v("VideoPlayerService", "setPlayBackSpeed..."); + Log.v(TAG, "setPlayBackSpeed..."); player.setPlaybackParameters(new PlaybackParameters(speed)); } public void playVideo() { Context context = this; - Log.v("VideoPlayerService", "playVideo..."); + Log.v(TAG, "playVideo..."); // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(), @@ -203,7 +205,7 @@ public class VideoPlayerService extends Service { @Override public void onNotificationCancelled(int notificationId) { - Log.v("VideoPlayerService", "onNotificationCancelled..."); + Log.v(TAG, "onNotificationCancelled..."); // TODO: only kill the notification if we no longer have a bound activity stopForeground(true); From a98ae31d35949c7d09ac779f826a658eb5f609e4 Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Wed, 26 Dec 2018 16:15:34 +0100 Subject: [PATCH 2/3] - Video speed UI improvements --- .../fragment/VideoOptionsFragment.java | 43 ++++- .../bottom_sheet_video_options_fragment.xml | 154 ++++++++++++------ app/src/main/res/values/strings.xml | 3 + 3 files changed, 146 insertions(+), 54 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java index d2a9cf9..1ed17e0 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java @@ -7,7 +7,7 @@ import android.view.ViewGroup; import android.widget.TextView; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; - +import com.mikepenz.iconics.Iconics; import net.schueller.peertube.R; import net.schueller.peertube.service.VideoPlayerService; @@ -17,6 +17,11 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { private static VideoPlayerService videoPlayerService; + private TextView speed05Icon; + private TextView speed10Icon; + private TextView speed15Icon; + private TextView speed20Icon; + public static VideoOptionsFragment newInstance(VideoPlayerService mService) { videoPlayerService = mService; return new VideoOptionsFragment(); @@ -31,21 +36,43 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { View view = inflater.inflate(R.layout.bottom_sheet_video_options_fragment, container, false); - // get the views and attach the listener + // Icons + speed05Icon = view.findViewById(R.id.video_speed05_icon); + speed10Icon = view.findViewById(R.id.video_speed10_icon); + speed15Icon = view.findViewById(R.id.video_speed15_icon); + speed20Icon = view.findViewById(R.id.video_speed20_icon); - //Playback speed buttons + // Buttons TextView speed05 = view.findViewById(R.id.video_speed05); TextView speed10 = view.findViewById(R.id.video_speed10); TextView speed15 = view.findViewById(R.id.video_speed15); TextView speed20 = view.findViewById(R.id.video_speed20); - //Playback speed controls - speed05.setOnClickListener(v -> videoPlayerService.setPlayBackSpeed(0.5f)); - speed10.setOnClickListener(v -> videoPlayerService.setPlayBackSpeed(1.0f)); - speed15.setOnClickListener(v -> videoPlayerService.setPlayBackSpeed(1.5f)); - speed20.setOnClickListener(v -> videoPlayerService.setPlayBackSpeed(2.0f)); + // Default + setVideoSpeed(1.0f, speed10Icon); + + // Attach the listener + speed05.setOnClickListener(v -> setVideoSpeed(0.5f, speed05Icon)); + speed10.setOnClickListener(v -> setVideoSpeed(1.0f, speed10Icon)); + speed15.setOnClickListener(v -> setVideoSpeed(1.5f, speed15Icon)); + speed20.setOnClickListener(v -> setVideoSpeed(2.0f, speed20Icon)); return view; } + + + private void setVideoSpeed(Float speed, TextView icon) { + + speed05Icon.setText(""); + speed10Icon.setText(""); + speed15Icon.setText(""); + speed20Icon.setText(""); + + videoPlayerService.setPlayBackSpeed(speed); + + icon.setText(R.string.video_speed_active_icon); + new Iconics.IconicsBuilder().ctx(getContext()).on(icon).build(); + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_sheet_video_options_fragment.xml b/app/src/main/res/layout/bottom_sheet_video_options_fragment.xml index c016aca..ca15827 100644 --- a/app/src/main/res/layout/bottom_sheet_video_options_fragment.xml +++ b/app/src/main/res/layout/bottom_sheet_video_options_fragment.xml @@ -6,60 +6,122 @@ android:background="@color/videoBackgroundColor" android:orientation="vertical"> - - android:text="@string/video_speed_05" - android:textAllCaps="false" - /> + - - android:layout_width="wrap_content" - android:layout_height="56dp" - android:layout_marginStart="16dp" - android:layout_marginEnd="16dp" - android:gravity="center" - android:textColor="#ffffff" - android:textSize="16sp" + - android:textAllCaps="false" - android:text="@string/video_speed_10" - /> + - - android:text="@string/video_speed_15" - android:textAllCaps="false" /> + + android:textColor="#ffffff" + android:textSize="16sp" /> + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f3a20a0..6e367c6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -89,4 +89,7 @@ 1.5x 2x + + {faw-check} + From 187e7f2dc36eb2467ca81906643cb1e344d59e13 Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Wed, 26 Dec 2018 16:30:54 +0100 Subject: [PATCH 3/3] - Version Bump --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 233ead1..dfa2701 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "net.schueller.peertube" minSdkVersion 21 targetSdkVersion 28 - versionCode 1013 - versionName "1.0.13" + versionCode 1014 + versionName "1.0.14" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" dependencies { implementation fileTree(dir: 'libs', include: ['*.jar'])