2018-12-29 14:19:17 +01:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2018-12-25 14:22:16 +01:00
|
|
|
package net.schueller.peertube.fragment;
|
|
|
|
|
2019-01-09 08:40:28 +01:00
|
|
|
import android.annotation.SuppressLint;
|
2020-07-04 22:30:58 +02:00
|
|
|
import android.content.SharedPreferences;
|
2018-12-25 14:22:16 +01:00
|
|
|
import android.os.Bundle;
|
2020-07-04 22:30:58 +02:00
|
|
|
import android.preference.PreferenceManager;
|
2019-01-07 22:33:10 +01:00
|
|
|
import android.util.Log;
|
2018-12-25 14:22:16 +01:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2019-01-07 22:33:10 +01:00
|
|
|
import android.widget.LinearLayout;
|
2018-12-25 14:44:52 +01:00
|
|
|
import android.widget.TextView;
|
2018-12-25 14:22:16 +01:00
|
|
|
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
2018-12-26 16:15:34 +01:00
|
|
|
import com.mikepenz.iconics.Iconics;
|
2018-12-25 14:22:16 +01:00
|
|
|
import net.schueller.peertube.R;
|
2019-01-07 22:33:10 +01:00
|
|
|
import net.schueller.peertube.model.File;
|
2018-12-25 14:44:52 +01:00
|
|
|
import net.schueller.peertube.service.VideoPlayerService;
|
2018-12-25 14:22:16 +01:00
|
|
|
|
2019-01-07 22:33:10 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2018-12-25 14:22:16 +01:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
|
|
public class VideoOptionsFragment extends BottomSheetDialogFragment {
|
|
|
|
|
2018-12-25 14:44:52 +01:00
|
|
|
private static VideoPlayerService videoPlayerService;
|
2019-01-07 22:33:10 +01:00
|
|
|
private static ArrayList<File> files;
|
|
|
|
|
|
|
|
public static final String TAG = "VideoOptions";
|
2018-12-25 14:44:52 +01:00
|
|
|
|
2018-12-26 16:15:34 +01:00
|
|
|
|
2019-01-07 22:33:10 +01:00
|
|
|
public static VideoOptionsFragment newInstance(VideoPlayerService mService, ArrayList<File> mFiles) {
|
2018-12-25 14:44:52 +01:00
|
|
|
videoPlayerService = mService;
|
2019-01-07 22:33:10 +01:00
|
|
|
files = mFiles;
|
2018-12-25 14:22:16 +01:00
|
|
|
return new VideoOptionsFragment();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater,
|
|
|
|
@Nullable ViewGroup container,
|
|
|
|
@Nullable Bundle savedInstanceState) {
|
|
|
|
|
2019-01-06 02:14:03 +01:00
|
|
|
View view = inflater.inflate(R.layout.fragment_video_options_popup_menu, container,
|
2018-12-25 14:22:16 +01:00
|
|
|
false);
|
|
|
|
|
2019-01-07 22:33:10 +01:00
|
|
|
LinearLayout menuHolder = view.findViewById(R.id.video_options_popup);
|
|
|
|
|
|
|
|
// 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);
|
2020-07-04 22:30:58 +02:00
|
|
|
textView.setText(String.format(getString(R.string.menu_video_options_playback_speed), videoPlayerService.getPlayBackSpeed()));
|
2019-01-09 08:40:28 +01:00
|
|
|
iconView.setText(R.string.video_option_speed_icon);
|
2019-01-07 22:33:10 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
// 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);
|
2020-07-04 22:30:58 +02:00
|
|
|
textView2.setText(String.format(getString(R.string.menu_video_options_quality), getCurrentVideoQuality(files)));
|
2019-01-09 08:40:28 +01:00
|
|
|
iconView2.setText(R.string.video_option_quality_icon);
|
2019-01-07 22:33:10 +01:00
|
|
|
new Iconics.IconicsBuilder().ctx(getContext()).on(iconView2).build();
|
|
|
|
textView2.setOnClickListener(view1 -> {
|
|
|
|
VideoMenuQualityFragment videoMenuQualityFragment =
|
2020-07-05 09:38:03 +02:00
|
|
|
VideoMenuQualityFragment.newInstance(getContext(), files);
|
2019-01-07 22:33:10 +01:00
|
|
|
videoMenuQualityFragment.show(getActivity().getSupportFragmentManager(),
|
|
|
|
videoMenuQualityFragment.TAG);
|
|
|
|
});
|
|
|
|
menuHolder.addView(menuRow2);
|
2018-12-25 14:44:52 +01:00
|
|
|
|
2018-12-25 14:22:16 +01:00
|
|
|
return view;
|
|
|
|
|
|
|
|
}
|
2018-12-26 16:15:34 +01:00
|
|
|
|
2020-07-04 22:30:58 +02:00
|
|
|
private String getCurrentVideoQuality(ArrayList<File> files) {
|
|
|
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
Integer videoQuality = sharedPref.getInt("pref_quality", 0);
|
|
|
|
|
|
|
|
for (File file : files) {
|
|
|
|
if (videoQuality.equals(file.getResolution().getId())) {
|
|
|
|
return file.getResolution().getLabel();
|
|
|
|
}
|
|
|
|
}
|
2020-07-05 09:38:03 +02:00
|
|
|
// Returning Automated as a placeholder
|
|
|
|
return getString(R.string.menu_video_options_quality_automated);
|
2020-07-04 22:30:58 +02:00
|
|
|
}
|
2018-12-25 14:22:16 +01:00
|
|
|
}
|