This commit is contained in:
Stefan Schueller 2019-01-07 22:33:10 +01:00
parent 19065b516c
commit 66a874f577
10 changed files with 403 additions and 172 deletions

View File

@ -0,0 +1,81 @@
/*
* Copyright 2018 Stefan Schüller <sschueller@techdroid.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<File> mFiles;
public static final String TAG = "VideoMenuQuality";
public static VideoMenuQualityFragment newInstance(ArrayList<File> 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;
}
}

View File

@ -0,0 +1,97 @@
/*
* Copyright 2018 Stefan Schüller <sschueller@techdroid.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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();
}
}

View File

@ -251,11 +251,10 @@ public class VideoMetaDataFragment extends Fragment {
new Iconics.IconicsBuilder().ctx(context).on(videoOptions).build(); new Iconics.IconicsBuilder().ctx(context).on(videoOptions).build();
videoOptions.setOnClickListener(v -> { videoOptions.setOnClickListener(v -> {
VideoOptionsFragment videoOptionsFragment = VideoOptionsFragment videoOptionsFragment =
VideoOptionsFragment.newInstance(mService); VideoOptionsFragment.newInstance(mService, video.getFiles());
videoOptionsFragment.show(getActivity().getSupportFragmentManager(), videoOptionsFragment.show(getActivity().getSupportFragmentManager(),
"video_options_fragment"); VideoOptionsFragment.TAG);
}); });
} }

View File

@ -18,29 +18,34 @@
package net.schueller.peertube.fragment; package net.schueller.peertube.fragment;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.mikepenz.iconics.Iconics; import com.mikepenz.iconics.Iconics;
import net.schueller.peertube.R; import net.schueller.peertube.R;
import net.schueller.peertube.model.File;
import net.schueller.peertube.service.VideoPlayerService; import net.schueller.peertube.service.VideoPlayerService;
import java.util.ArrayList;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
public class VideoOptionsFragment extends BottomSheetDialogFragment { public class VideoOptionsFragment extends BottomSheetDialogFragment {
private static VideoPlayerService videoPlayerService; private static VideoPlayerService videoPlayerService;
private static ArrayList<File> files;
private TextView speed05Icon; public static final String TAG = "VideoOptions";
private TextView speed10Icon;
private TextView speed15Icon;
private TextView speed20Icon;
public static VideoOptionsFragment newInstance(VideoPlayerService mService) {
public static VideoOptionsFragment newInstance(VideoPlayerService mService, ArrayList<File> mFiles) {
videoPlayerService = mService; videoPlayerService = mService;
files = mFiles;
return new VideoOptionsFragment(); return new VideoOptionsFragment();
} }
@ -53,43 +58,40 @@ public class VideoOptionsFragment extends BottomSheetDialogFragment {
View view = inflater.inflate(R.layout.fragment_video_options_popup_menu, container, View view = inflater.inflate(R.layout.fragment_video_options_popup_menu, container,
false); false);
// Icons LinearLayout menuHolder = view.findViewById(R.id.video_options_popup);
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 // Video Speed
TextView speed05 = view.findViewById(R.id.video_speed05); LinearLayout menuRow = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null);
TextView speed10 = view.findViewById(R.id.video_speed10); TextView iconView = menuRow.findViewById(R.id.video_quality_icon);
TextView speed15 = view.findViewById(R.id.video_speed15); TextView textView = menuRow.findViewById(R.id.video_quality_text);
TextView speed20 = view.findViewById(R.id.video_speed20); 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 // Video Quality
setVideoSpeed(1.0f, speed10Icon); LinearLayout menuRow2 = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null);
TextView iconView2 = menuRow2.findViewById(R.id.video_quality_icon);
// Attach the listener TextView textView2 = menuRow2.findViewById(R.id.video_quality_text);
speed05.setOnClickListener(v -> setVideoSpeed(0.5f, speed05Icon)); textView2.setText("Video Quality");
speed10.setOnClickListener(v -> setVideoSpeed(1.0f, speed10Icon)); iconView2.setText(R.string.video_speed_active_icon);
speed15.setOnClickListener(v -> setVideoSpeed(1.5f, speed15Icon)); new Iconics.IconicsBuilder().ctx(getContext()).on(iconView2).build();
speed20.setOnClickListener(v -> setVideoSpeed(2.0f, speed20Icon)); textView2.setOnClickListener(view1 -> {
VideoMenuQualityFragment videoMenuQualityFragment =
VideoMenuQualityFragment.newInstance(files);
videoMenuQualityFragment.show(getActivity().getSupportFragmentManager(),
videoMenuQualityFragment.TAG);
});
menuHolder.addView(menuRow2);
return view; 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();
}
} }

View File

@ -56,6 +56,7 @@ import com.mikepenz.iconics.Iconics;
import net.schueller.peertube.R; import net.schueller.peertube.R;
import net.schueller.peertube.helper.APIUrlHelper; import net.schueller.peertube.helper.APIUrlHelper;
import net.schueller.peertube.model.File;
import net.schueller.peertube.model.Video; import net.schueller.peertube.model.Video;
import net.schueller.peertube.network.GetVideoDataService; import net.schueller.peertube.network.GetVideoDataService;
import net.schueller.peertube.network.RetrofitInstance; import net.schueller.peertube.network.RetrofitInstance;
@ -211,26 +212,34 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
String videoQuality = sharedPref.getString("pref_quality", ""); 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")) { if (video.getFiles().size() > 1 && videoQuality.equals("High")) {
mService.setCurrentStreamUrl(video.getFiles().get(0).getFileUrl()); 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")) { } else if (video.getFiles().size() >= 2 && videoQuality.equals("Medium")) {
mService.setCurrentStreamUrl(video.getFiles().get(1).getFileUrl()); 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")) { } else if (video.getFiles().size() >= 3 && videoQuality.equals("Low")) {
mService.setCurrentStreamUrl(video.getFiles().get(2).getFileUrl()); 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 { } else {
//default quality //default quality
mService.setCurrentStreamUrl(video.getFiles().get(0).getFileUrl()); 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()); // Log.v(TAG, "url : " + video.getFiles().size());

View File

@ -21,7 +21,6 @@ public class File {
private Integer id; private Integer id;
private String fileDownloadUrl; private String fileDownloadUrl;
private Integer fps; private Integer fps;
private String label;
private Resolution resolution; private Resolution resolution;
private String resolutionLabel; private String resolutionLabel;
private String magnetUri; private String magnetUri;
@ -54,14 +53,6 @@ public class File {
this.fps = fps; this.fps = fps;
} }
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Resolution getResolution() { public Resolution getResolution() {
return resolution; return resolution;
} }

View File

@ -4,124 +4,7 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:background="@color/videoBackgroundColor" android:background="@color/videoBackgroundColor"
android:id="@+id/video_options_popup"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/video_speed05_icon"
android:layout_width="32dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:gravity="center|start"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="12sp" />
<TextView
android:id="@+id/video_speed05"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:gravity="center|start"
android:text="@string/video_speed_05"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/video_speed10_icon"
android:layout_width="32dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:gravity="center|start"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="12sp" />
<TextView
android:id="@+id/video_speed10"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:gravity="center|start"
android:text="@string/video_speed_10"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/video_speed15_icon"
android:layout_width="32dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:gravity="center|start"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="12sp" />
<TextView
android:id="@+id/video_speed15"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:gravity="center|start"
android:text="@string/video_speed_15"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/video_speed20_icon"
android:layout_width="32dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:gravity="center|start"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="12sp" />
<TextView
android:id="@+id/video_speed20"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:gravity="center|start"
android:text="@string/video_speed_20"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,11 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_quality_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@color/videoBackgroundColor"
android:orientation="vertical">
</LinearLayout>

View File

@ -0,0 +1,127 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@color/videoBackgroundColor"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/video_speed05_icon"
android:layout_width="32dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:gravity="center|start"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="12sp" />
<TextView
android:id="@+id/video_speed05"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:gravity="center|start"
android:text="@string/video_speed_05"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/video_speed10_icon"
android:layout_width="32dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:gravity="center|start"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="12sp" />
<TextView
android:id="@+id/video_speed10"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:gravity="center|start"
android:text="@string/video_speed_10"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/video_speed15_icon"
android:layout_width="32dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:gravity="center|start"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="12sp" />
<TextView
android:id="@+id/video_speed15"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:gravity="center|start"
android:text="@string/video_speed_15"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/video_speed20_icon"
android:layout_width="32dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:gravity="center|start"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="12sp" />
<TextView
android:id="@+id/video_speed20"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:gravity="center|start"
android:text="@string/video_speed_20"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/video_quality_icon"
android:layout_width="32dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:gravity="center|start"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="12sp" />
<TextView
android:id="@+id/video_quality_text"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="16dp"
android:gravity="center|start"
android:text=""
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="16sp" />
</LinearLayout>