diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-07-08 14:19:08 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-07-08 14:19:08 +0000 |
commit | 6f34d854ea7552fadd9b22e934b45cd86ebc162b (patch) | |
tree | 9b4c28f6f344d6b9ccf2a277e19d0f05fb7999eb /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | 318b11da01ad843ad63d82b4ac87eb1eaa84b9dc (diff) | |
download | infinity-for-reddit-6f34d854ea7552fadd9b22e934b45cd86ebc162b.tar infinity-for-reddit-6f34d854ea7552fadd9b22e934b45cd86ebc162b.tar.gz infinity-for-reddit-6f34d854ea7552fadd9b22e934b45cd86ebc162b.tar.bz2 infinity-for-reddit-6f34d854ea7552fadd9b22e934b45cd86ebc162b.tar.lz infinity-for-reddit-6f34d854ea7552fadd9b22e934b45cd86ebc162b.tar.xz infinity-for-reddit-6f34d854ea7552fadd9b22e934b45cd86ebc162b.tar.zst infinity-for-reddit-6f34d854ea7552fadd9b22e934b45cd86ebc162b.zip |
Setting autoplay videos visible area offset is available. Remove Crashy because it will crash on some devices, such as Pixel Slate.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
9 files changed, 107 insertions, 104 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index 1a02476c..3dea5729 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -3,6 +3,8 @@ package ml.docilealligator.infinityforreddit.Adapter; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; +import android.content.res.Configuration; +import android.content.res.Resources; import android.graphics.ColorFilter; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; @@ -159,6 +161,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy private boolean mAutoplayNsfwVideos; private boolean mMuteAutoplayingVideos; private boolean mFullyCollapseComment; + private double mStartAutoplayVisibleAreaOffset; private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback; private boolean isInitiallyLoading; private boolean isInitiallyLoadingFailed; @@ -340,12 +343,17 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mMuteAutoplayingVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS, true); mFullyCollapseComment = sharedPreferences.getBoolean(SharedPreferencesUtils.FULLY_COLLAPSE_COMMENT, false); + Resources resources = activity.getResources(); + mStartAutoplayVisibleAreaOffset = resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? + sharedPreferences.getInt(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_PORTRAIT, 75) / 100.0 : + sharedPreferences.getInt(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_LANDSCAPE, 50) / 100.0; + mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback; isInitiallyLoading = true; isInitiallyLoadingFailed = false; mHasMoreComments = false; loadMoreCommentsFailed = false; - mScale = activity.getResources().getDisplayMetrics().density; + mScale = resources.getDisplayMetrics().density; mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); mColorAccent = customThemeWrapper.getColorAccent(); @@ -2259,7 +2267,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy @Override public boolean wantsToPlay() { - return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= 0.85; + return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset; } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 7bc347b6..fd277916 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -3,6 +3,8 @@ package ml.docilealligator.infinityforreddit.Adapter; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; +import android.content.res.Configuration; +import android.content.res.Resources; import android.graphics.ColorFilter; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; @@ -169,6 +171,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView private boolean mAutoplayNsfwVideos; private boolean mMuteAutoplayingVideos; private boolean mShowThumbnailOnTheRightInCompactLayout; + private double mStartAutoplayVisibleAreaOffset; private Drawable mCommentIcon; private NetworkState networkState; private ExoCreator mExoCreator; @@ -206,6 +209,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mMuteAutoplayingVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS, true); mShowThumbnailOnTheRightInCompactLayout = sharedPreferences.getBoolean( SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_RIGHT_IN_COMPACT_LAYOUT, false); + + Resources resources = activity.getResources(); + mStartAutoplayVisibleAreaOffset = resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? + sharedPreferences.getInt(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_PORTRAIT, 75) / 100.0 : + sharedPreferences.getInt(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_LANDSCAPE, 50) / 100.0; + mPostLayout = postLayout; mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme(); @@ -243,7 +252,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView if (mCommentIcon != null) { DrawableCompat.setTint(mCommentIcon, mPostIconAndInfoColor); } - mScale = activity.getResources().getDisplayMetrics().density; + + mScale = resources.getDisplayMetrics().density; mGlide = Glide.with(mActivity); mRedditDataRoomDatabase = redditDataRoomDatabase; mLocale = locale; @@ -1346,6 +1356,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView mShowThumbnailOnTheRightInCompactLayout = showThumbnailOnTheRightInCompactLayout; } + public void setStartAutoplayVisibleAreaOffset(double startAutoplayVisibleAreaOffset) { + this.mStartAutoplayVisibleAreaOffset = startAutoplayVisibleAreaOffset / 100.0; + } + @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { super.onViewRecycled(holder); @@ -2066,7 +2080,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView @Override public boolean wantsToPlay() { - return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= 0.75; + return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= mStartAutoplayVisibleAreaOffset; } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 6bbc049a..d3c471cf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -61,6 +61,7 @@ import ml.docilealligator.infinityforreddit.Settings.GesturesAndButtonsPreferenc import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.NotificationPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.ThemePreferenceFragment; +import ml.docilealligator.infinityforreddit.Settings.VideoPreferenceFragment; @Singleton @Component(modules = AppModule.class) @@ -182,4 +183,6 @@ public interface AppComponent { void inject(ViewPrivateMessagesActivity viewPrivateMessagesActivity); void inject(SendPrivateMessageActivity sendPrivateMessageActivity); + + void inject(VideoPreferenceFragment videoPreferenceFragment); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeStartAutoplayVisibleAreaOffsetEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeStartAutoplayVisibleAreaOffsetEvent.java new file mode 100644 index 00000000..34fc48a9 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeStartAutoplayVisibleAreaOffsetEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.Event; + +public class ChangeStartAutoplayVisibleAreaOffsetEvent { + public double startAutoplayVisibleAreaOffset; + + public ChangeStartAutoplayVisibleAreaOffsetEvent(double startAutoplayVisibleAreaOffset) { + this.startAutoplayVisibleAreaOffset = startAutoplayVisibleAreaOffset; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index 4f6a80fe..71132f61 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -67,6 +67,7 @@ import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVotesEvent; import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeStartAutoplayVisibleAreaOffsetEvent; import ml.docilealligator.infinityforreddit.Event.ChangeTimeFormatEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; @@ -935,6 +936,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } + @Subscribe + public void onChangeStartAutoplayVisibleAreaOffsetEvent(ChangeStartAutoplayVisibleAreaOffsetEvent changeStartAutoplayVisibleAreaOffsetEvent) { + if (mAdapter != null) { + mAdapter.setStartAutoplayVisibleAreaOffset(changeStartAutoplayVisibleAreaOffsetEvent.startAutoplayVisibleAreaOffset); + refreshAdapter(); + } + } + private void refreshAdapter() { int previousPosition = -1; if (mLinearLayoutManager != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CrashReportsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CrashReportsFragment.java deleted file mode 100644 index 04bdc0e9..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CrashReportsFragment.java +++ /dev/null @@ -1,54 +0,0 @@ -package ml.docilealligator.infinityforreddit.Settings; - -import android.app.Activity; -import android.content.Context; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.fragment.app.Fragment; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.crazylegend.crashyreporter.CrashyReporter; - -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.R; - -public class CrashReportsFragment extends Fragment { - - @BindView(R.id.recycler_view_crash_reports_fragment) - RecyclerView recyclerView; - private Activity activity; - private CrashReportsRecyclerViewAdapter adapter; - private LinearLayoutManager linearLayoutManager; - - public CrashReportsFragment() { - // Required empty public constructor - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - View rootView = inflater.inflate(R.layout.fragment_crash_reports, container, false); - - ButterKnife.bind(this, rootView); - - adapter = new CrashReportsRecyclerViewAdapter(CrashyReporter.INSTANCE.getLogsAsStrings()); - linearLayoutManager = new LinearLayoutManager(activity); - recyclerView.setLayoutManager(linearLayoutManager); - recyclerView.setAdapter(adapter); - - return rootView; - } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - this.activity = (Activity) context; - } -}
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CrashReportsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CrashReportsRecyclerViewAdapter.java deleted file mode 100644 index 47629585..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CrashReportsRecyclerViewAdapter.java +++ /dev/null @@ -1,46 +0,0 @@ -package ml.docilealligator.infinityforreddit.Settings; - -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - -import java.util.List; - -import ml.docilealligator.infinityforreddit.R; - -class CrashReportsRecyclerViewAdapter extends RecyclerView.Adapter<CrashReportsRecyclerViewAdapter.CrashReportViewHolder> { - private List<String> crashReports; - - public CrashReportsRecyclerViewAdapter(List<String> crashReports) { - this.crashReports = crashReports; - } - - @NonNull - @Override - public CrashReportViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new CrashReportViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_crash_report, parent, false)); - } - - @Override - public void onBindViewHolder(@NonNull CrashReportViewHolder holder, int position) { - holder.crashReportTextView.setText(crashReports.get(holder.getAdapterPosition())); - } - - @Override - public int getItemCount() { - return crashReports == null ? 0 : crashReports.size(); - } - - class CrashReportViewHolder extends RecyclerView.ViewHolder { - TextView crashReportTextView; - - public CrashReportViewHolder(@NonNull View itemView) { - super(itemView); - crashReportTextView = (TextView) itemView; - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/VideoPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/VideoPreferenceFragment.java index e7cd2432..4cd4ceda 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/VideoPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/VideoPreferenceFragment.java @@ -1,28 +1,50 @@ package ml.docilealligator.infinityforreddit.Settings; +import android.app.Activity; +import android.content.Context; +import android.content.SharedPreferences; +import android.content.res.Configuration; import android.os.Bundle; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; import androidx.preference.ListPreference; +import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.SeekBarPreference; import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; +import javax.inject.Inject; +import javax.inject.Named; + import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent; import ml.docilealligator.infinityforreddit.Event.ChangeMuteAutoplayingVideosEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeStartAutoplayVisibleAreaOffsetEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent; +import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; public class VideoPreferenceFragment extends PreferenceFragmentCompat { + private Activity activity; + @Inject + @Named("default") + SharedPreferences sharedPreferences; + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.video_preferences, rootKey); + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + ListPreference videoAutoplayListPreference = findPreference(SharedPreferencesUtils.VIDEO_AUTOPLAY); SwitchPreference muteAutoplayingVideosSwitchPreference = findPreference(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS); SwitchPreference autoplayNsfwVideosSwitchPreference = findPreference(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS); + SeekBarPreference startAutoplayVisibleAreaOffsetPortrait = findPreference(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_PORTRAIT); + SeekBarPreference startAutoplayVisibleAreaOffsetLandscape = findPreference(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_LANDSCAPE); if (videoAutoplayListPreference != null && autoplayNsfwVideosSwitchPreference != null) { videoAutoplayListPreference.setOnPreferenceChangeListener((preference, newValue) -> { @@ -42,5 +64,41 @@ public class VideoPreferenceFragment extends PreferenceFragmentCompat { return true; }); } + + int orientation = getResources().getConfiguration().orientation; + + if (startAutoplayVisibleAreaOffsetPortrait != null) { + startAutoplayVisibleAreaOffsetPortrait.setSummary( + getString(R.string.settings_start_autoplay_visible_area_offset_portrait_summary, + sharedPreferences.getInt(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_PORTRAIT, 75))); + startAutoplayVisibleAreaOffsetPortrait.setOnPreferenceChangeListener((Preference.OnPreferenceChangeListener) (preference, newValue) -> { + if (orientation == Configuration.ORIENTATION_PORTRAIT) { + EventBus.getDefault().post(new ChangeStartAutoplayVisibleAreaOffsetEvent((Integer) newValue)); + } + startAutoplayVisibleAreaOffsetPortrait.setSummary( + getString(R.string.settings_start_autoplay_visible_area_offset_portrait_summary, (Integer) newValue)); + return true; + }); + } + + if (startAutoplayVisibleAreaOffsetLandscape != null) { + startAutoplayVisibleAreaOffsetLandscape.setSummary( + getString(R.string.settings_start_autoplay_visible_area_offset_portrait_summary, + sharedPreferences.getInt(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_LANDSCAPE, 50))); + startAutoplayVisibleAreaOffsetLandscape.setOnPreferenceChangeListener((Preference.OnPreferenceChangeListener) (preference, newValue) -> { + if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + EventBus.getDefault().post(new ChangeStartAutoplayVisibleAreaOffsetEvent((Integer) newValue)); + } + startAutoplayVisibleAreaOffsetLandscape.setSummary( + getString(R.string.settings_start_autoplay_visible_area_offset_landscape_summary, (Integer) newValue)); + return true; + }); + } + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + this.activity = (AppCompatActivity) context; } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index 1b6d9df6..eca06f7b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -127,4 +127,6 @@ public class SharedPreferencesUtils { public static final String MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT = "3"; public static final String MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT = "4"; public static final String MAIN_PAGE_TAB_POST_TYPE_USER = "5"; + public static final String START_AUTOPLAY_VISIBLE_AREA_OFFSET_PORTRAIT = "start_autoplay_visible_area_offset_portrait"; + public static final String START_AUTOPLAY_VISIBLE_AREA_OFFSET_LANDSCAPE = "start_autoplay_visible_area_offset_landscape"; } |