From 75edaa27d22763ecc4911d8742bed2c0671e8d4d Mon Sep 17 00:00:00 2001 From: David Luhmer Date: Mon, 29 Apr 2019 19:55:14 -0400 Subject: [PATCH] remove youtube support --- .../YoutubePlayerManager.java | 50 ------ .../podcast/YoutubePlaybackService.java | 168 ------------------ .../PodcastFragmentActivity.java | 38 ---- .../events/podcast/RegisterYoutubeOutput.java | 13 -- .../YoutubePlayerManager.java | 12 -- .../podcast/YoutubePlaybackService.java | 45 ----- 6 files changed, 326 deletions(-) delete mode 100644 News-Android-App/src/extra/java/de/luhmer/owncloudnewsreader/YoutubePlayerManager.java delete mode 100644 News-Android-App/src/extra/java/de/luhmer/owncloudnewsreader/services/podcast/YoutubePlaybackService.java delete mode 100644 News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/RegisterYoutubeOutput.java delete mode 100644 News-Android-App/src/oss/java/de/luhmer/owncloudnewsreader/YoutubePlayerManager.java delete mode 100644 News-Android-App/src/oss/java/de/luhmer/owncloudnewsreader/services/podcast/YoutubePlaybackService.java diff --git a/News-Android-App/src/extra/java/de/luhmer/owncloudnewsreader/YoutubePlayerManager.java b/News-Android-App/src/extra/java/de/luhmer/owncloudnewsreader/YoutubePlayerManager.java deleted file mode 100644 index c694c1b5..00000000 --- a/News-Android-App/src/extra/java/de/luhmer/owncloudnewsreader/YoutubePlayerManager.java +++ /dev/null @@ -1,50 +0,0 @@ -package de.luhmer.owncloudnewsreader; - -import android.app.Activity; -import android.app.Fragment; -import android.app.FragmentTransaction; - -import com.google.android.youtube.player.YouTubeInitializationResult; -import com.google.android.youtube.player.YouTubePlayer; -import com.google.android.youtube.player.YouTubePlayerFragment; - -import org.greenrobot.eventbus.EventBus; - -import java.lang.ref.WeakReference; - -public class YoutubePlayerManager { - - static Fragment.SavedState savedState; - static WeakReference youTubePlayerFragmentRef; - - - public static void StartYoutubePlayer(final Activity activity, int YOUTUBE_CONTENT_VIEW_ID, final EventBus eventBus, final Runnable onInitSuccess) { - YouTubePlayerFragment youTubePlayerFragment = YouTubePlayerFragment.newInstance(); - if(savedState != null) { - youTubePlayerFragment.setInitialSavedState(savedState); - } - FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); - ft.add(YOUTUBE_CONTENT_VIEW_ID, youTubePlayerFragment).commit(); - - youTubePlayerFragment.initialize("AIzaSyA2OHKWvF_hRVtPmLcwnO8yF6-iah2hjbk", new YouTubePlayer.OnInitializedListener() { - @Override - public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) { - eventBus.post(new RegisterYoutubeOutput(youTubePlayer, wasRestored)); - onInitSuccess.run(); - } - - @Override - public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) { - youTubeInitializationResult.getErrorDialog(activity, 0).show(); - //Toast.makeText(activity, "Error while playing youtube video! (InitializationFailure)", Toast.LENGTH_LONG).show(); - } - }); - youTubePlayerFragmentRef = new WeakReference<>(youTubePlayerFragment); - } - - protected static void safeYoutubeState(Activity activity) { - if(youTubePlayerFragmentRef != null && youTubePlayerFragmentRef.get() != null) { - savedState = activity.getFragmentManager().saveFragmentInstanceState(youTubePlayerFragmentRef.get()); - } - } -} diff --git a/News-Android-App/src/extra/java/de/luhmer/owncloudnewsreader/services/podcast/YoutubePlaybackService.java b/News-Android-App/src/extra/java/de/luhmer/owncloudnewsreader/services/podcast/YoutubePlaybackService.java deleted file mode 100644 index 959cb95a..00000000 --- a/News-Android-App/src/extra/java/de/luhmer/owncloudnewsreader/services/podcast/YoutubePlaybackService.java +++ /dev/null @@ -1,168 +0,0 @@ -package de.luhmer.owncloudnewsreader.services.podcast; - -import android.content.Context; -import android.util.Log; -import android.widget.Toast; - -import com.google.android.youtube.player.YouTubePlayer; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import de.luhmer.owncloudnewsreader.model.MediaItem; - -/** - * Created by david on 31.01.17. - */ - -public class YoutubePlaybackService extends PlaybackService { - - private static final String TAG = YoutubePlaybackService.class.getCanonicalName(); - YouTubePlayer youTubePlayer; - Context context; - - public YoutubePlaybackService(Context context, PodcastStatusListener podcastStatusListener, MediaItem mediaItem) { - super(podcastStatusListener, mediaItem); - this.context = context; - setStatus(Status.PREPARING); - } - - @Override - public void destroy() { - if(youTubePlayer != null) { - youTubePlayer.pause(); - youTubePlayer = null; - } - } - - @Override - public void play() { - if(youTubePlayer != null) { - youTubePlayer.play(); - } - } - - @Override - public void pause() { - if(youTubePlayer != null) { - youTubePlayer.pause(); - } - } - - @Override - public void playbackSpeedChanged(float currentPlaybackSpeed) { - - } - - public void seekTo(double percent) { - if(youTubePlayer != null) { - double totalDuration = getTotalDuration(); - int position = (int) ((totalDuration / 100d) * percent); - youTubePlayer.seekToMillis(position); - } - } - public int getCurrentDuration() { - if(youTubePlayer != null) { - return youTubePlayer.getCurrentTimeMillis(); - } - return 0; - } - - public int getTotalDuration() { - if(youTubePlayer != null) { - return youTubePlayer.getDurationMillis(); - } - return 0; - } - - @Override - public VideoType getVideoType() { - return VideoType.YouTube; - } - - public void setYoutubePlayer(Object youTubePlayer, boolean wasRestored) { - this.youTubePlayer = (YouTubePlayer) youTubePlayer; - this.youTubePlayer.setPlaybackEventListener(youtubePlaybackEventListener); - this.youTubePlayer.setPlayerStateChangeListener(youtubePlayerStateChangeListener); - - this.youTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL); - - // Start buffering - if (!wasRestored) { - Pattern youtubeIdPattern = Pattern.compile(".*?v=([^&]*)"); - Matcher matcher = youtubeIdPattern.matcher(getMediaItem().link); - if(matcher.matches()) { - String youtubeId = matcher.group(1); - this.youTubePlayer.cueVideo(youtubeId); - } else { - Toast.makeText(context, "Cannot find youtube video id", Toast.LENGTH_LONG).show(); - setStatus(Status.FAILED); - } - } - } - - - YouTubePlayer.PlayerStateChangeListener youtubePlayerStateChangeListener = new YouTubePlayer.PlayerStateChangeListener() { - @Override - public void onLoading() { - Log.d(TAG, "onLoading() called"); - } - - @Override - public void onLoaded(String s) { - Log.d(TAG, "onLoaded() called with: s = [" + s + "]"); - youTubePlayer.play(); - } - - @Override - public void onAdStarted() { - Log.d(TAG, "onAdStarted() called"); - } - - @Override - public void onVideoStarted() { - Log.d(TAG, "onVideoStarted() called"); - } - - @Override - public void onVideoEnded() { - Log.d(TAG, "onVideoEnded() called"); - } - - @Override - public void onError(YouTubePlayer.ErrorReason errorReason) { - Log.d(TAG, "onError() called with: errorReason = [" + errorReason + "]"); - } - }; - - - YouTubePlayer.PlaybackEventListener youtubePlaybackEventListener = new YouTubePlayer.PlaybackEventListener() { - @Override - public void onPlaying() { - Log.d(TAG, "onPlaying() called"); - setStatus(Status.PLAYING); - } - - @Override - public void onPaused() { - Log.d(TAG, "onPaused() called"); - setStatus(Status.PAUSED); - } - - @Override - public void onStopped() { - Log.d(TAG, "onStopped() called"); - setStatus(Status.PAUSED); - } - - @Override - public void onBuffering(boolean b) { - Log.d(TAG, "onBuffering() called with: b = [" + b + "]"); - } - - @Override - public void onSeekTo(int i) { - Log.d(TAG, "onSeekTo() called with: i = [" + i + "]"); - } - }; -} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java index 3e37c8ed..dac6544a 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/PodcastFragmentActivity.java @@ -47,7 +47,6 @@ import de.luhmer.owncloudnewsreader.database.model.RssItem; import de.luhmer.owncloudnewsreader.di.ApiProvider; import de.luhmer.owncloudnewsreader.events.podcast.PodcastCompletedEvent; import de.luhmer.owncloudnewsreader.events.podcast.RegisterVideoOutput; -import de.luhmer.owncloudnewsreader.events.podcast.RegisterYoutubeOutput; import de.luhmer.owncloudnewsreader.events.podcast.UpdatePodcastStatusEvent; import de.luhmer.owncloudnewsreader.events.podcast.VideoDoubleClicked; import de.luhmer.owncloudnewsreader.helper.PostDelayHandler; @@ -88,10 +87,8 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP protected ZoomableRelativeLayout rlVideoPodcastSurfaceWrapper; @BindView(R.id.sliding_layout) protected PodcastSlidingUpPanelLayout sliding_layout; - //YouTubePlayerFragment youtubeplayerfragment; private boolean currentlyPlaying = false; - private boolean showedYoutubeFeatureNotAvailableDialog = false; private boolean videoViewInitialized = false; private boolean isVideoViewVisible = true; @@ -210,14 +207,12 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP Log.d(TAG, "onPause"); eventBus.unregister(this); - YoutubePlayerManager.safeYoutubeState(this); //TODO THIS IS NEVER REACHED! isVideoViewVisible = false; videoViewInitialized = false; eventBus.post(new RegisterVideoOutput(null, null)); - eventBus.post(new RegisterYoutubeOutput(null, false)); rlVideoPodcastSurfaceWrapper.setVisibility(View.GONE); rlVideoPodcastSurfaceWrapper.removeAllViews(); @@ -392,44 +387,11 @@ public class PodcastFragmentActivity extends AppCompatActivity implements IPlayP togglePodcastVideoViewAnimation(); } } else if(podcast.getVideoType() == PlaybackService.VideoType.YouTube) { - if(BuildConfig.FLAVOR.equals("extra")) { - if (!videoViewInitialized) { - isVideoViewVisible = true; - videoViewInitialized = true; - rlVideoPodcastSurfaceWrapper.removeAllViews(); - - rlVideoPodcastSurfaceWrapper.setVisibility(View.VISIBLE); - - togglePodcastVideoViewAnimation(); - - final int YOUTUBE_CONTENT_VIEW_ID = 10101010; - FrameLayout frame = new FrameLayout(this); - frame.setId(YOUTUBE_CONTENT_VIEW_ID); - rlVideoPodcastSurfaceWrapper.addView(frame); - //setContentView(frame, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); - - YoutubePlayerManager.StartYoutubePlayer(this, YOUTUBE_CONTENT_VIEW_ID, eventBus, new Runnable() { - @Override - public void run() { - togglePodcastVideoViewAnimation(); - } - }); - } - } else if(!showedYoutubeFeatureNotAvailableDialog) { - showedYoutubeFeatureNotAvailableDialog = true; - new AlertDialog.Builder(this) - .setTitle(getString(R.string.warning)) - .setMessage(R.string.dialog_feature_not_available) - .setCancelable(true) - .setPositiveButton(getString(android.R.string.ok), null) - .show(); - } } else { isVideoViewVisible = false; videoViewInitialized = false; eventBus.post(new RegisterVideoOutput(null, null)); - eventBus.post(new RegisterYoutubeOutput(null, false)); rlVideoPodcastSurfaceWrapper.setVisibility(View.GONE); //AlphaAnimator.AnimateVisibilityChange(rlVideoPodcastSurfaceWrapper, View.GONE); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/RegisterYoutubeOutput.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/RegisterYoutubeOutput.java deleted file mode 100644 index 700f2e96..00000000 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/events/podcast/RegisterYoutubeOutput.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.luhmer.owncloudnewsreader.events.podcast; - -public class RegisterYoutubeOutput { - - public RegisterYoutubeOutput(Object youTubePlayer, boolean wasRestored) { - this.youTubePlayer = youTubePlayer; - this.wasRestored = wasRestored; - } - - public Object youTubePlayer; // (Type: com.google.android.youtube.player.YouTubePlayer;) - public boolean wasRestored; - -} diff --git a/News-Android-App/src/oss/java/de/luhmer/owncloudnewsreader/YoutubePlayerManager.java b/News-Android-App/src/oss/java/de/luhmer/owncloudnewsreader/YoutubePlayerManager.java deleted file mode 100644 index 98307d34..00000000 --- a/News-Android-App/src/oss/java/de/luhmer/owncloudnewsreader/YoutubePlayerManager.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.luhmer.owncloudnewsreader; - -import android.app.Activity; - -import org.greenrobot.eventbus.EventBus; - -public class YoutubePlayerManager { - - public static void StartYoutubePlayer(final Activity activity, int YOUTUBE_CONTENT_VIEW_ID, final EventBus eventBus, final Runnable onInitSuccess) { - // Dummy - } -} diff --git a/News-Android-App/src/oss/java/de/luhmer/owncloudnewsreader/services/podcast/YoutubePlaybackService.java b/News-Android-App/src/oss/java/de/luhmer/owncloudnewsreader/services/podcast/YoutubePlaybackService.java deleted file mode 100644 index 74d338e4..00000000 --- a/News-Android-App/src/oss/java/de/luhmer/owncloudnewsreader/services/podcast/YoutubePlaybackService.java +++ /dev/null @@ -1,45 +0,0 @@ -package de.luhmer.owncloudnewsreader.services.podcast; - -import android.content.Context; - -import de.luhmer.owncloudnewsreader.model.MediaItem; - -/** - * Created by david on 31.01.17. - */ - -public class YoutubePlaybackService extends PlaybackService { - - public YoutubePlaybackService(Context context, PodcastStatusListener podcastStatusListener, MediaItem mediaItem) { - super(podcastStatusListener, mediaItem); - setStatus(Status.FAILED); - } - - @Override - public void destroy() { } - - @Override - public void play() { } - - @Override - public void pause() { } - - @Override - public void playbackSpeedChanged(float currentPlaybackSpeed) { } - - public void seekTo(double percent) { } - public int getCurrentDuration() { - return 0; - } - - public int getTotalDuration() { - return 0; - } - - @Override - public VideoType getVideoType() { - return VideoType.YouTube; - } - - public void setYoutubePlayer(Object youTubePlayer, boolean wasRestored) { } -}