2019-01-07 22:33:10 +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/>.
|
|
|
|
*/
|
|
|
|
package net.schueller.peertube.fragment;
|
|
|
|
|
2019-01-09 17:53:26 +01:00
|
|
|
import android.content.SharedPreferences;
|
2019-01-07 22:33:10 +01:00
|
|
|
import android.os.Bundle;
|
2019-01-09 17:53:26 +01:00
|
|
|
import android.preference.PreferenceManager;
|
2019-01-07 22:33:10 +01:00
|
|
|
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;
|
2019-01-09 17:53:26 +01:00
|
|
|
import com.mikepenz.iconics.Iconics;
|
|
|
|
|
2019-01-07 22:33:10 +01:00
|
|
|
import net.schueller.peertube.R;
|
|
|
|
import net.schueller.peertube.model.File;
|
2019-01-09 17:53:26 +01:00
|
|
|
import net.schueller.peertube.model.Resolution;
|
2019-01-07 22:33:10 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
|
|
public class VideoMenuQualityFragment extends BottomSheetDialogFragment {
|
|
|
|
|
|
|
|
private static ArrayList<File> mFiles;
|
|
|
|
public static final String TAG = "VideoMenuQuality";
|
2019-01-09 18:05:56 +01:00
|
|
|
private static File autoQualityFile;
|
2019-01-07 22:33:10 +01:00
|
|
|
|
|
|
|
public static VideoMenuQualityFragment newInstance(ArrayList<File> files) {
|
2019-01-09 17:53:26 +01:00
|
|
|
|
2019-01-07 22:33:10 +01:00
|
|
|
mFiles = files;
|
2019-01-09 17:53:26 +01:00
|
|
|
|
|
|
|
// Auto quality
|
2019-01-09 18:05:56 +01:00
|
|
|
if (autoQualityFile == null) {
|
|
|
|
autoQualityFile = new File();
|
|
|
|
Resolution autoQualityResolution = new Resolution();
|
|
|
|
autoQualityResolution.setId(0);
|
|
|
|
autoQualityResolution.setLabel("Auto");
|
|
|
|
autoQualityFile.setId(0);
|
|
|
|
autoQualityFile.setResolution(autoQualityResolution);
|
|
|
|
}
|
2019-01-09 17:53:26 +01:00
|
|
|
if (!mFiles.contains(autoQualityFile)) {
|
|
|
|
mFiles.add(0, autoQualityFile);
|
|
|
|
}
|
|
|
|
|
2019-01-07 22:33:10 +01:00
|
|
|
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);
|
|
|
|
|
2019-01-09 17:53:26 +01:00
|
|
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
Integer videoQuality = sharedPref.getInt("pref_quality", 0);
|
|
|
|
|
2019-01-09 18:05:56 +01:00
|
|
|
for (File file : mFiles) {
|
2019-01-07 22:33:10 +01:00
|
|
|
|
|
|
|
LinearLayout menuRow = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null);
|
|
|
|
|
|
|
|
TextView iconView = menuRow.findViewById(R.id.video_quality_icon);
|
2019-01-09 18:13:42 +01:00
|
|
|
iconView.setId(file.getResolution().getId());
|
2019-01-07 22:33:10 +01:00
|
|
|
TextView textView = menuRow.findViewById(R.id.video_quality_text);
|
|
|
|
|
|
|
|
Log.v(TAG, file.getResolution().getLabel());
|
|
|
|
textView.setText(file.getResolution().getLabel());
|
|
|
|
|
2019-01-09 17:53:26 +01:00
|
|
|
textView.setOnClickListener(view1 -> {
|
|
|
|
// Log.v(TAG, file.getResolution().getLabel());
|
|
|
|
SharedPreferences.Editor editor = sharedPref.edit();
|
|
|
|
editor.putInt("pref_quality", file.getResolution().getId());
|
|
|
|
editor.apply();
|
2019-01-09 18:05:56 +01:00
|
|
|
|
2019-01-09 18:13:42 +01:00
|
|
|
for (File fileV : mFiles) {
|
|
|
|
TextView iconViewV = view.findViewById(fileV.getResolution().getId());
|
|
|
|
iconViewV.setText("");
|
|
|
|
}
|
2019-01-09 18:05:56 +01:00
|
|
|
|
2019-01-09 17:53:26 +01:00
|
|
|
iconView.setText(R.string.video_quality_active_icon);
|
|
|
|
new Iconics.IconicsBuilder().ctx(getContext()).on(iconView).build();
|
2019-01-09 18:13:42 +01:00
|
|
|
|
|
|
|
//TODO: set new video quality on running video
|
|
|
|
|
2019-01-09 17:53:26 +01:00
|
|
|
});
|
2019-01-07 22:33:10 +01:00
|
|
|
|
|
|
|
// Add to menu
|
|
|
|
LinearLayout menuHolder = view.findViewById(R.id.video_quality_menu);
|
|
|
|
menuHolder.addView(menuRow);
|
|
|
|
|
2019-01-09 18:13:42 +01:00
|
|
|
// Set current
|
2019-01-09 17:53:26 +01:00
|
|
|
if (videoQuality.equals(file.getResolution().getId())) {
|
|
|
|
iconView.setText(R.string.video_quality_active_icon);
|
|
|
|
new Iconics.IconicsBuilder().ctx(getContext()).on(iconView).build();
|
|
|
|
}
|
|
|
|
|
2019-01-07 22:33:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|