diff --git a/app/build.gradle b/app/build.gradle index e70eeda9..76f05962 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -87,10 +87,6 @@ dependencies { implementation 'com.google.code.gson:gson:2.8.6' implementation 'me.zhanghai.android.fastscroll:library:1.1.2' implementation "com.thefuntasty.hauler:core:3.1.0" - // androidX startup for auto-init - implementation "androidx.startup:startup-runtime:1.0.0-alpha01" - //crashy - implementation 'com.github.CraZyLegenD:Crashy:1.0.3' def toroVersion = '3.7.0.2010003' implementation "im.ene.toro3:toro:$toroVersion" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ca502970..4d30b837 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -328,16 +328,6 @@ android:resource="@xml/file_paths" /> - - - - = 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= 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 { - private List crashReports; - - public CrashReportsRecyclerViewAdapter(List 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"; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 23c3e314..6c31ed48 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -347,6 +347,10 @@ Video Autoplay Mute Autoplaying Videos Autoplay NSFW Videos + Autoplay Videos Visible Area Offset (Portrait) + Start autoplaying videos when %1$d%% of them are visible + Autoplay Videos Visible Area Offset (Landscape) + Start autoplaying videos when %1$d%% of them are visible Immersive Interface Ignore Navigation Bar in Immersive Interface Prevent the Bottom Navigation Bar Having Extra Padding @@ -425,8 +429,6 @@ Share Share this app to other people if you enjoy it Infinity For Reddit - Crash Reports - See the error logs and send them to me when you report bugs Version %s Customization Light Theme diff --git a/app/src/main/res/xml/about_preferences.xml b/app/src/main/res/xml/about_preferences.xml index 6561eec3..a73f9aaa 100644 --- a/app/src/main/res/xml/about_preferences.xml +++ b/app/src/main/res/xml/about_preferences.xml @@ -45,11 +45,6 @@ app:title="@string/settings_share_title" app:summary="@string/settings_share_summary" /> - - + + + + \ No newline at end of file