diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoMenuQualityFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoMenuQualityFragment.java new file mode 100644 index 0000000..6bc2986 --- /dev/null +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoMenuQualityFragment.java @@ -0,0 +1,81 @@ +/* + * Copyright 2018 Stefan Schüller + * + * License: GPL-3.0+ + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.schueller.peertube.fragment; + +import android.content.Context; +import android.os.Bundle; +import android.util.Log; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.google.android.material.bottomsheet.BottomSheetDialogFragment; +import net.schueller.peertube.R; +import net.schueller.peertube.model.File; + +import java.util.ArrayList; + +import androidx.annotation.Nullable; + +public class VideoMenuQualityFragment extends BottomSheetDialogFragment { + + private static ArrayList mFiles; + public static final String TAG = "VideoMenuQuality"; + + public static VideoMenuQualityFragment newInstance(ArrayList files) { + mFiles = files; + return new VideoMenuQualityFragment(); + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + + View view = inflater.inflate(R.layout.fragment_video_options_quality_popup_menu, container, + false); + + for (File file :mFiles) { + + LinearLayout menuRow = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null); + + TextView iconView = menuRow.findViewById(R.id.video_quality_icon); + TextView textView = menuRow.findViewById(R.id.video_quality_text); + + Log.v(TAG, file.getResolution().getLabel()); + textView.setText(file.getResolution().getLabel()); + + textView.setOnClickListener(view1 -> { Log.v(TAG, file.getResolution().getLabel()); }); + iconView.setOnClickListener(view1 -> { Log.v(TAG, file.getResolution().getLabel()); }); + + // Add to menu + LinearLayout menuHolder = view.findViewById(R.id.video_quality_menu); + menuHolder.addView(menuRow); + + } + + return view; + + } + + +} \ No newline at end of file diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoMenuSpeedFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoMenuSpeedFragment.java new file mode 100644 index 0000000..52e9378 --- /dev/null +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoMenuSpeedFragment.java @@ -0,0 +1,97 @@ +/* + * Copyright 2018 Stefan Schüller + * + * License: GPL-3.0+ + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.schueller.peertube.fragment; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +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; + +import androidx.annotation.Nullable; + +public class VideoMenuSpeedFragment extends BottomSheetDialogFragment { + + private static VideoPlayerService videoPlayerService; + public static final String TAG = "VideoMenuSpeed"; + + private TextView speed05Icon; + private TextView speed10Icon; + private TextView speed15Icon; + private TextView speed20Icon; + + public static VideoMenuSpeedFragment newInstance(VideoPlayerService mService) { + videoPlayerService = mService; + return new VideoMenuSpeedFragment(); + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + + View view = inflater.inflate(R.layout.fragment_video_options_speed_popup_menu, container, + false); + + // 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); + + // 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); + + // 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/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java index f97ebf7..d58eab7 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoMetaDataFragment.java @@ -251,11 +251,10 @@ public class VideoMetaDataFragment extends Fragment { new Iconics.IconicsBuilder().ctx(context).on(videoOptions).build(); videoOptions.setOnClickListener(v -> { - VideoOptionsFragment videoOptionsFragment = - VideoOptionsFragment.newInstance(mService); + VideoOptionsFragment.newInstance(mService, video.getFiles()); videoOptionsFragment.show(getActivity().getSupportFragmentManager(), - "video_options_fragment"); + VideoOptionsFragment.TAG); }); } 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 7c5758e..fb68c09 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoOptionsFragment.java @@ -18,29 +18,34 @@ package net.schueller.peertube.fragment; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; 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.model.File; import net.schueller.peertube.service.VideoPlayerService; +import java.util.ArrayList; + import androidx.annotation.Nullable; public class VideoOptionsFragment extends BottomSheetDialogFragment { private static VideoPlayerService videoPlayerService; + private static ArrayList files; - private TextView speed05Icon; - private TextView speed10Icon; - private TextView speed15Icon; - private TextView speed20Icon; + public static final String TAG = "VideoOptions"; - public static VideoOptionsFragment newInstance(VideoPlayerService mService) { + + public static VideoOptionsFragment newInstance(VideoPlayerService mService, ArrayList mFiles) { videoPlayerService = mService; + files = mFiles; return new VideoOptionsFragment(); } @@ -53,43 +58,40 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment { View view = inflater.inflate(R.layout.fragment_video_options_popup_menu, container, false); - // 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); + LinearLayout menuHolder = view.findViewById(R.id.video_options_popup); - // 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); + // Video Speed + LinearLayout menuRow = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null); + TextView iconView = menuRow.findViewById(R.id.video_quality_icon); + TextView textView = menuRow.findViewById(R.id.video_quality_text); + textView.setText("Video Speed"); + iconView.setText(R.string.video_speed_active_icon); + new Iconics.IconicsBuilder().ctx(getContext()).on(iconView).build(); + textView.setOnClickListener(view1 -> { + VideoMenuSpeedFragment videoMenuSpeedFragment = + VideoMenuSpeedFragment.newInstance(videoPlayerService); + videoMenuSpeedFragment.show(getActivity().getSupportFragmentManager(), + VideoMenuSpeedFragment.TAG); + }); + menuHolder.addView(menuRow); - // 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)); + // Video Quality + LinearLayout menuRow2 = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null); + TextView iconView2 = menuRow2.findViewById(R.id.video_quality_icon); + TextView textView2 = menuRow2.findViewById(R.id.video_quality_text); + textView2.setText("Video Quality"); + iconView2.setText(R.string.video_speed_active_icon); + new Iconics.IconicsBuilder().ctx(getContext()).on(iconView2).build(); + textView2.setOnClickListener(view1 -> { + VideoMenuQualityFragment videoMenuQualityFragment = + VideoMenuQualityFragment.newInstance(files); + videoMenuQualityFragment.show(getActivity().getSupportFragmentManager(), + videoMenuQualityFragment.TAG); + }); + menuHolder.addView(menuRow2); 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/java/net/schueller/peertube/fragment/VideoPlayerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java index e1ca9d2..a6c6c21 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -56,6 +56,7 @@ import com.mikepenz.iconics.Iconics; import net.schueller.peertube.R; import net.schueller.peertube.helper.APIUrlHelper; +import net.schueller.peertube.model.File; import net.schueller.peertube.model.Video; import net.schueller.peertube.network.GetVideoDataService; import net.schueller.peertube.network.RetrofitInstance; @@ -211,26 +212,34 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL String videoQuality = sharedPref.getString("pref_quality", ""); - //get video quality + //get video qualities + + for (File file :video.getFiles()) { + // Add to menu + + + } + + if (video.getFiles().size() > 1 && videoQuality.equals("High")) { mService.setCurrentStreamUrl(video.getFiles().get(0).getFileUrl()); - Log.v(TAG, "urlHigh : " + video.getFiles().get(0).getFileUrl()); +// Log.v(TAG, "urlHigh : " + video.getFiles().get(0).getFileUrl()); } else if (video.getFiles().size() >= 2 && videoQuality.equals("Medium")) { mService.setCurrentStreamUrl(video.getFiles().get(1).getFileUrl()); - Log.v(TAG, "urlMed : " + video.getFiles().get(1).getFileUrl()); +// Log.v(TAG, "urlMed : " + video.getFiles().get(1).getFileUrl()); } else if (video.getFiles().size() >= 3 && videoQuality.equals("Low")) { mService.setCurrentStreamUrl(video.getFiles().get(2).getFileUrl()); - Log.v(TAG, "urlLow : " + video.getFiles().get(2).getFileUrl()); + // Log.v(TAG, "urlLow : " + video.getFiles().get(2).getFileUrl()); } else { //default quality mService.setCurrentStreamUrl(video.getFiles().get(0).getFileUrl()); - Log.v(TAG, "url : " + video.getFiles().get(0).getFileUrl()); + // Log.v(TAG, "url : " + video.getFiles().get(0).getFileUrl()); } // Log.v(TAG, "url : " + video.getFiles().size()); diff --git a/app/src/main/java/net/schueller/peertube/model/File.java b/app/src/main/java/net/schueller/peertube/model/File.java index fe993da..4cf30c9 100644 --- a/app/src/main/java/net/schueller/peertube/model/File.java +++ b/app/src/main/java/net/schueller/peertube/model/File.java @@ -21,7 +21,6 @@ public class File { private Integer id; private String fileDownloadUrl; private Integer fps; - private String label; private Resolution resolution; private String resolutionLabel; private String magnetUri; @@ -54,14 +53,6 @@ public class File { this.fps = fps; } - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - public Resolution getResolution() { return resolution; } diff --git a/app/src/main/res/layout/fragment_video_options_popup_menu.xml b/app/src/main/res/layout/fragment_video_options_popup_menu.xml index ca15827..b6dd933 100644 --- a/app/src/main/res/layout/fragment_video_options_popup_menu.xml +++ b/app/src/main/res/layout/fragment_video_options_popup_menu.xml @@ -4,124 +4,7 @@ android:layout_marginTop="8dp" android:layout_marginBottom="8dp" android:background="@color/videoBackgroundColor" + android:id="@+id/video_options_popup" android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_video_options_quality_popup_menu.xml b/app/src/main/res/layout/fragment_video_options_quality_popup_menu.xml new file mode 100644 index 0000000..a9fa70c --- /dev/null +++ b/app/src/main/res/layout/fragment_video_options_quality_popup_menu.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_video_options_speed_popup_menu.xml b/app/src/main/res/layout/fragment_video_options_speed_popup_menu.xml new file mode 100644 index 0000000..ca15827 --- /dev/null +++ b/app/src/main/res/layout/fragment_video_options_speed_popup_menu.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/row_popup_menu.xml b/app/src/main/res/layout/row_popup_menu.xml new file mode 100644 index 0000000..8906d5b --- /dev/null +++ b/app/src/main/res/layout/row_popup_menu.xml @@ -0,0 +1,31 @@ + + + + + + + + + \ No newline at end of file