This commit is contained in:
Stefan Schüller 2019-01-09 17:53:26 +01:00
parent e0d7830c43
commit f3f65eb7d9
4 changed files with 48 additions and 54 deletions

View File

@ -93,13 +93,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
preference.setSummary(stringValue); preference.setSummary(stringValue);
return true; return true;
} }
//check if video quality has changed & provide selected quality
else if (preference.getKey().equals("pref_quality")) {
Toast.makeText(preference.getContext(), "Quality changed", Toast.LENGTH_LONG).show();
preference.setSummary(stringValue);
return true;
}
preference.setSummary(stringValue); preference.setSummary(stringValue);
@ -208,7 +201,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
// guidelines. // guidelines.
bindPreferenceSummaryToValue(findPreference("pref_api_base")); bindPreferenceSummaryToValue(findPreference("pref_api_base"));
bindPreferenceSummaryToValue(findPreference("pref_theme")); bindPreferenceSummaryToValue(findPreference("pref_theme"));
bindPreferenceSummaryToValue(findPreference("pref_quality"));
} }
@Override @Override

View File

@ -17,10 +17,10 @@
*/ */
package net.schueller.peertube.fragment; package net.schueller.peertube.fragment;
import android.content.Context; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -28,8 +28,11 @@ 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 net.schueller.peertube.R; import net.schueller.peertube.R;
import net.schueller.peertube.model.File; import net.schueller.peertube.model.File;
import net.schueller.peertube.model.Resolution;
import java.util.ArrayList; import java.util.ArrayList;
@ -41,7 +44,21 @@ public class VideoMenuQualityFragment extends BottomSheetDialogFragment {
public static final String TAG = "VideoMenuQuality"; public static final String TAG = "VideoMenuQuality";
public static VideoMenuQualityFragment newInstance(ArrayList<File> files) { public static VideoMenuQualityFragment newInstance(ArrayList<File> files) {
mFiles = files; mFiles = files;
// Auto quality
File autoQualityFile = new File();
Resolution autoQualityResolution = new Resolution();
autoQualityResolution.setId(0);
autoQualityResolution.setLabel("Auto");
autoQualityFile.setId(0);
autoQualityFile.setResolution(autoQualityResolution);
if (!mFiles.contains(autoQualityFile)) {
mFiles.add(0, autoQualityFile);
}
return new VideoMenuQualityFragment(); return new VideoMenuQualityFragment();
} }
@ -54,6 +71,9 @@ public class VideoMenuQualityFragment extends BottomSheetDialogFragment {
View view = inflater.inflate(R.layout.fragment_video_options_quality_popup_menu, container, View view = inflater.inflate(R.layout.fragment_video_options_quality_popup_menu, container,
false); false);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
Integer videoQuality = sharedPref.getInt("pref_quality", 0);
for (File file :mFiles) { for (File file :mFiles) {
LinearLayout menuRow = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null); LinearLayout menuRow = (LinearLayout) inflater.inflate(R.layout.row_popup_menu, null);
@ -64,13 +84,24 @@ public class VideoMenuQualityFragment extends BottomSheetDialogFragment {
Log.v(TAG, file.getResolution().getLabel()); Log.v(TAG, file.getResolution().getLabel());
textView.setText(file.getResolution().getLabel()); textView.setText(file.getResolution().getLabel());
textView.setOnClickListener(view1 -> { Log.v(TAG, file.getResolution().getLabel()); }); textView.setOnClickListener(view1 -> {
iconView.setOnClickListener(view1 -> { Log.v(TAG, file.getResolution().getLabel()); }); // Log.v(TAG, file.getResolution().getLabel());
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt("pref_quality", file.getResolution().getId());
editor.apply();
iconView.setText(R.string.video_quality_active_icon);
new Iconics.IconicsBuilder().ctx(getContext()).on(iconView).build();
});
// Add to menu // Add to menu
LinearLayout menuHolder = view.findViewById(R.id.video_quality_menu); LinearLayout menuHolder = view.findViewById(R.id.video_quality_menu);
menuHolder.addView(menuRow); menuHolder.addView(menuRow);
if (videoQuality.equals(file.getResolution().getId())) {
iconView.setText(R.string.video_quality_active_icon);
new Iconics.IconicsBuilder().ctx(getContext()).on(iconView).build();
}
} }
return view; return view;

View File

@ -210,40 +210,6 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
String videoQuality = sharedPref.getString("pref_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());
} 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());
} 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());
} 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().size());
if (sharedPref.getBoolean("pref_torrent_player", false)) { if (sharedPref.getBoolean("pref_torrent_player", false)) {
torrentStatus.setVisibility(View.VISIBLE); torrentStatus.setVisibility(View.VISIBLE);
String stream = video.getFiles().get(0).getTorrentUrl(); String stream = video.getFiles().get(0).getTorrentUrl();
@ -251,6 +217,19 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL
torrentStream = setupTorrentStream(); torrentStream = setupTorrentStream();
torrentStream.startStream(stream); torrentStream.startStream(stream);
} else { } else {
Integer videoQuality = sharedPref.getInt("pref_quality", 0);
//get video qualities
String urlToPlay = video.getFiles().get(0).getFileUrl();
for (File file :video.getFiles()) {
// Set quality if it matches
if (file.getResolution().getId().equals(videoQuality)) {
urlToPlay = file.getFileUrl();
}
}
mService.setCurrentStreamUrl(urlToPlay);
torrentStatus.setVisibility(View.GONE); torrentStatus.setVisibility(View.GONE);
startPlayer(); startPlayer();
} }

View File

@ -30,14 +30,6 @@
android:summary="@string/pref_description_language" android:summary="@string/pref_description_language"
android:title="@string/pref_language" /> android:title="@string/pref_language" />
<ListPreference
android:defaultValue="High"
android:entries="@array/quality"
android:entryValues="@array/qualityValues"
android:key="pref_quality"
android:summary="Select Video quality"
android:title="Video Quality"/>
<ListPreference <ListPreference
android:title="@string/pref_title_app_theme" android:title="@string/pref_title_app_theme"
android:summary="@string/pref_description_app_theme" android:summary="@string/pref_description_app_theme"