From f3f65eb7d9a1ce95cbe9c77864b326b9c984c211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Schu=CC=88ller?= Date: Wed, 9 Jan 2019 17:53:26 +0100 Subject: [PATCH] Wip --- .../peertube/activity/SettingsActivity.java | 8 ---- .../fragment/VideoMenuQualityFragment.java | 39 +++++++++++++-- .../fragment/VideoPlayerFragment.java | 47 +++++-------------- app/src/main/res/xml/pref_general.xml | 8 ---- 4 files changed, 48 insertions(+), 54 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java b/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java index fa10209..3d7352d 100644 --- a/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java @@ -93,13 +93,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { preference.setSummary(stringValue); 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); @@ -208,7 +201,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { // guidelines. bindPreferenceSummaryToValue(findPreference("pref_api_base")); bindPreferenceSummaryToValue(findPreference("pref_theme")); - bindPreferenceSummaryToValue(findPreference("pref_quality")); } @Override diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoMenuQualityFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoMenuQualityFragment.java index 6bc2986..8f361a7 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoMenuQualityFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoMenuQualityFragment.java @@ -17,10 +17,10 @@ */ package net.schueller.peertube.fragment; -import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.util.Log; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -28,8 +28,11 @@ 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.model.Resolution; import java.util.ArrayList; @@ -41,7 +44,21 @@ public class VideoMenuQualityFragment extends BottomSheetDialogFragment { public static final String TAG = "VideoMenuQuality"; public static VideoMenuQualityFragment newInstance(ArrayList 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(); } @@ -54,6 +71,9 @@ public class VideoMenuQualityFragment extends BottomSheetDialogFragment { View view = inflater.inflate(R.layout.fragment_video_options_quality_popup_menu, container, false); + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); + Integer videoQuality = sharedPref.getInt("pref_quality", 0); + for (File file :mFiles) { 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()); textView.setText(file.getResolution().getLabel()); - textView.setOnClickListener(view1 -> { Log.v(TAG, file.getResolution().getLabel()); }); - iconView.setOnClickListener(view1 -> { Log.v(TAG, file.getResolution().getLabel()); }); + textView.setOnClickListener(view1 -> { +// 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 LinearLayout menuHolder = view.findViewById(R.id.video_quality_menu); 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; 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 a6c6c21..b92023d 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -210,40 +210,6 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL 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)) { torrentStatus.setVisibility(View.VISIBLE); String stream = video.getFiles().get(0).getTorrentUrl(); @@ -251,6 +217,19 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL torrentStream = setupTorrentStream(); torrentStream.startStream(stream); } 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); startPlayer(); } diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index cee8c5c..98b1da9 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -30,14 +30,6 @@ android:summary="@string/pref_description_language" android:title="@string/pref_language" /> - -