Merge branch 'Docile-Alligator:master' into more-regex-fix

This commit is contained in:
scria1000 2021-11-24 13:01:31 +00:00 committed by GitHub
commit ea1501b5a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 210 additions and 230 deletions

View File

@ -6,8 +6,8 @@ android {
applicationId "ml.docilealligator.infinityforreddit" applicationId "ml.docilealligator.infinityforreddit"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 30 targetSdkVersion 30
versionCode 84 versionCode 85
versionName "5.1.0" versionName "5.1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions { javaCompileOptions {
annotationProcessorOptions { annotationProcessorOptions {

View File

@ -25,7 +25,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<application <application
android:name=".Infinity" android:name="ml.docilealligator.infinityforreddit.Infinity"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/application_name" android:label="@string/application_name"

View File

@ -0,0 +1,29 @@
package ml.docilealligator.infinityforreddit;
import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy;
public class SaveMemoryCenterInisdeDownsampleStrategy extends DownsampleStrategy {
@Override
public float getScaleFactor(int sourceWidth, int sourceHeight, int requestedWidth, int requestedHeight) {
int originalSourceWidth = sourceWidth;
int originalSourceHeight = sourceHeight;
if (sourceWidth * sourceHeight > 5_000_000) {
int divisor = 2;
do {
sourceWidth /= divisor;
sourceHeight /= divisor;
} while (sourceWidth * sourceHeight > 5_000_000);
}
float widthPercentage = (float) requestedWidth / (float) sourceWidth;
float heightPercentage = (float) requestedHeight / (float) sourceHeight;
return Math.min((float) sourceWidth / (float) originalSourceWidth, (float) sourceHeight / (float) originalSourceHeight) * Math.min(1.f, Math.min(widthPercentage, heightPercentage));
}
@Override
public SampleSizeRounding getSampleSizeRounding(int sourceWidth, int sourceHeight, int requestedWidth, int requestedHeight) {
return SampleSizeRounding.MEMORY;
}
}

View File

@ -129,10 +129,10 @@ public abstract class BaseActivity extends AppCompatActivity {
} }
} }
boolean userDefinedChangeSatusBarIconColorInImmersiveInterface = boolean userDefinedChangeStatusBarIconColorInImmersiveInterface =
customThemeWrapper.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface(); customThemeWrapper.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface();
if (immersiveInterface && isImmersiveInterfaceApplicable) { if (immersiveInterface && isImmersiveInterfaceApplicable) {
changeStatusBarIconColor = userDefinedChangeSatusBarIconColorInImmersiveInterface; changeStatusBarIconColor = userDefinedChangeStatusBarIconColorInImmersiveInterface;
} else { } else {
changeStatusBarIconColor = false; changeStatusBarIconColor = false;
} }

View File

@ -38,7 +38,6 @@ import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.adapter.FragmentStateAdapter;
@ -270,9 +269,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
drawer.setFitsSystemWindows(false); drawer.setFitsSystemWindows(false);
getWindow().setDecorFitsSystemWindows(false); getWindow().setDecorFitsSystemWindows(false);
/*drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);*/
} else { } else {
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
} }
@ -855,51 +851,37 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setTabMode(TabLayout.MODE_FIXED);
} }
new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> { new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
if (mAccessToken == null) { switch (position) {
switch (position) { case 0:
case 0: tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home)));
tab.setText(R.string.home); break;
break; case 1:
case 1: tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular)));
tab.setText(R.string.popular); break;
break; case 2:
case 2: tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all)));
tab.setText(R.string.all); break;
break; }
} if (position >= tabCount && (mShowFavoriteMultiReddits || mShowMultiReddits ||
} else { mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits)
switch (position) { && sectionsPagerAdapter != null) {
case 0: if (position - tabCount < sectionsPagerAdapter.favoriteMultiReddits.size()) {
tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home))); tab.setText(sectionsPagerAdapter.favoriteMultiReddits.get(position - tabCount).getName());
break; } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() < sectionsPagerAdapter.multiReddits.size()) {
case 1: tab.setText(sectionsPagerAdapter.multiReddits.get(position - tabCount
tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular))); - sectionsPagerAdapter.favoriteMultiReddits.size()).getName());
break; } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size()
case 2: - sectionsPagerAdapter.multiReddits.size() < sectionsPagerAdapter.favoriteSubscribedSubreddits.size()) {
tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all))); tab.setText(sectionsPagerAdapter.favoriteSubscribedSubreddits.get(position - tabCount
break; - sectionsPagerAdapter.favoriteMultiReddits.size()
} - sectionsPagerAdapter.multiReddits.size()).getName());
if (position >= tabCount && (mShowFavoriteMultiReddits || mShowMultiReddits || } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size()
mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) - sectionsPagerAdapter.multiReddits.size()
&& sectionsPagerAdapter != null) { - sectionsPagerAdapter.favoriteSubscribedSubreddits.size() < sectionsPagerAdapter.subscribedSubreddits.size()) {
if (position - tabCount < sectionsPagerAdapter.favoriteMultiReddits.size()) { tab.setText(sectionsPagerAdapter.subscribedSubreddits.get(position - tabCount
tab.setText(sectionsPagerAdapter.favoriteMultiReddits.get(position - tabCount).getName()); - sectionsPagerAdapter.favoriteMultiReddits.size()
} else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() < sectionsPagerAdapter.multiReddits.size()) {
tab.setText(sectionsPagerAdapter.multiReddits.get(position - tabCount
- sectionsPagerAdapter.favoriteMultiReddits.size()).getName());
} else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size()
- sectionsPagerAdapter.multiReddits.size() < sectionsPagerAdapter.favoriteSubscribedSubreddits.size()) {
tab.setText(sectionsPagerAdapter.favoriteSubscribedSubreddits.get(position - tabCount
- sectionsPagerAdapter.favoriteMultiReddits.size()
- sectionsPagerAdapter.multiReddits.size()).getName());
} else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size()
- sectionsPagerAdapter.multiReddits.size() - sectionsPagerAdapter.multiReddits.size()
- sectionsPagerAdapter.favoriteSubscribedSubreddits.size() < sectionsPagerAdapter.subscribedSubreddits.size()) { - sectionsPagerAdapter.favoriteSubscribedSubreddits.size()).getName());
tab.setText(sectionsPagerAdapter.subscribedSubreddits.get(position - tabCount
- sectionsPagerAdapter.favoriteMultiReddits.size()
- sectionsPagerAdapter.multiReddits.size()
- sectionsPagerAdapter.favoriteSubscribedSubreddits.size()).getName());
}
} }
} }
}).attach(); }).attach();
@ -925,7 +907,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
loadSubscriptions(); loadSubscriptions();
multiRedditViewModel = new ViewModelProvider(this, new MultiRedditViewModel.Factory(getApplication(), multiRedditViewModel = new ViewModelProvider(this, new MultiRedditViewModel.Factory(getApplication(),
mRedditDataRoomDatabase, mAccountName)) mRedditDataRoomDatabase, mAccountName == null ? "-" : mAccountName))
.get(MultiRedditViewModel.class); .get(MultiRedditViewModel.class);
multiRedditViewModel.getAllFavoriteMultiReddits().observe(this, multiReddits -> { multiRedditViewModel.getAllFavoriteMultiReddits().observe(this, multiReddits -> {
@ -934,17 +916,14 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} }
}); });
multiRedditViewModel.getAllMultiReddits().observe(this, new Observer<List<MultiReddit>>() { multiRedditViewModel.getAllMultiReddits().observe(this, multiReddits -> {
@Override if (mShowMultiReddits && sectionsPagerAdapter != null) {
public void onChanged(List<MultiReddit> multiReddits) { sectionsPagerAdapter.setMultiReddits(multiReddits);
if (mShowMultiReddits && sectionsPagerAdapter != null) {
sectionsPagerAdapter.setMultiReddits(multiReddits);
}
} }
}); });
subscribedSubredditViewModel = new ViewModelProvider(this, subscribedSubredditViewModel = new ViewModelProvider(this,
new SubscribedSubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName)) new SubscribedSubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName == null ? "-" : mAccountName))
.get(SubscribedSubredditViewModel.class); .get(SubscribedSubredditViewModel.class);
subscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, subscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this,
subscribedSubredditData -> { subscribedSubredditData -> {
@ -1696,9 +1675,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Override @Override
public int getItemCount() { public int getItemCount() {
if (mAccessToken == null) {
return 3;
}
return tabCount + favoriteMultiReddits.size() + multiReddits.size() + return tabCount + favoriteMultiReddits.size() + multiReddits.size() +
favoriteSubscribedSubreddits.size() + subscribedSubreddits.size(); favoriteSubscribedSubreddits.size() + subscribedSubreddits.size();
} }

View File

@ -22,6 +22,7 @@ import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.r0adkll.slidr.Slidr; import com.r0adkll.slidr.Slidr;
@ -100,10 +101,10 @@ public class TrendingActivity extends BaseActivity {
@Inject @Inject
Executor mExecutor; Executor mExecutor;
private String mAccessToken; private String mAccessToken;
private String mAccountName;
private boolean isRefreshing = false; private boolean isRefreshing = false;
private ArrayList<TrendingSearch> trendingSearches; private ArrayList<TrendingSearch> trendingSearches;
private TrendingSearchRecyclerViewAdapter adapter; private TrendingSearchRecyclerViewAdapter adapter;
private RequestManager mGlide;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -151,7 +152,8 @@ public class TrendingActivity extends BaseActivity {
setToolbarGoToTop(toolbar); setToolbarGoToTop(toolbar);
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
mGlide = Glide.with(this);
DisplayMetrics displayMetrics = new DisplayMetrics(); DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
@ -277,7 +279,7 @@ public class TrendingActivity extends BaseActivity {
private void showErrorView(int stringId) { private void showErrorView(int stringId) {
errorLinearLayout.setVisibility(View.VISIBLE); errorLinearLayout.setVisibility(View.VISIBLE);
Glide.with(this).load(R.drawable.error_image).into(errorImageView); mGlide.load(R.drawable.error_image).into(errorImageView);
errorTextView.setText(stringId); errorTextView.setText(stringId);
} }

View File

@ -1,6 +1,12 @@
package ml.docilealligator.infinityforreddit.activities; package ml.docilealligator.infinityforreddit.activities;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
import android.Manifest; import android.Manifest;
import android.app.AlertDialog;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
@ -32,6 +38,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
@ -79,6 +86,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.apis.VReddIt; import ml.docilealligator.infinityforreddit.apis.VReddIt;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PlaybackSpeedBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PlaybackSpeedBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.font.ContentFontFamily; import ml.docilealligator.infinityforreddit.font.ContentFontFamily;
import ml.docilealligator.infinityforreddit.font.ContentFontStyle; import ml.docilealligator.infinityforreddit.font.ContentFontStyle;
import ml.docilealligator.infinityforreddit.font.FontFamily; import ml.docilealligator.infinityforreddit.font.FontFamily;
@ -150,6 +158,8 @@ public class ViewVideoActivity extends AppCompatActivity {
TextView titleTextView; TextView titleTextView;
@BindView(R.id.download_image_view_exo_playback_control_view) @BindView(R.id.download_image_view_exo_playback_control_view)
ImageView downloadImageView; ImageView downloadImageView;
@BindView(R.id.playback_speed_image_view_exo_playback_control_view)
ImageView playbackSpeedImageView;
@BindView(R.id.lockable_nested_scroll_view_view_video_activity) @BindView(R.id.lockable_nested_scroll_view_view_video_activity)
LockableNestedScrollView nestedScrollView; LockableNestedScrollView nestedScrollView;
@ -194,6 +204,9 @@ public class ViewVideoActivity extends AppCompatActivity {
@Named("default") @Named("default")
SharedPreferences mSharedPreferences; SharedPreferences mSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject @Inject
Executor mExecutor; Executor mExecutor;
@ -206,7 +219,37 @@ public class ViewVideoActivity extends AppCompatActivity {
((Infinity) getApplication()).getAppComponent().inject(this); ((Infinity) getApplication()).getAppComponent().inject(this);
getTheme().applyStyle(R.style.Theme_Normal, true); boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
int systemThemeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2"));
switch (systemThemeType) {
case 0:
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
getTheme().applyStyle(R.style.Theme_Normal, true);
break;
case 1:
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) {
getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true);
} else {
getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true);
}
break;
case 2:
if (systemDefault) {
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
} else {
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY);
}
if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) {
getTheme().applyStyle(R.style.Theme_Normal, true);
} else {
if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) {
getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true);
} else {
getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true);
}
}
}
getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences
.getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true);
@ -250,6 +293,14 @@ public class ViewVideoActivity extends AppCompatActivity {
isDownloading = true; isDownloading = true;
requestPermissionAndDownload(); requestPermissionAndDownload();
}); });
playbackSpeedImageView.setOnClickListener(view -> {
PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed);
playbackSpeedBottomSheetFragment.setArguments(bundle);
playbackSpeedBottomSheetFragment.show(getSupportFragmentManager(), playbackSpeedBottomSheetFragment.getTag());
});
} else { } else {
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
Drawable upArrow = resources.getDrawable(R.drawable.ic_arrow_back_white_24dp); Drawable upArrow = resources.getDrawable(R.drawable.ic_arrow_back_white_24dp);
@ -520,10 +571,13 @@ public class ViewVideoActivity extends AppCompatActivity {
hdButton.setVisibility(View.VISIBLE); hdButton.setVisibility(View.VISIBLE);
hdButton.setOnClickListener(view -> { hdButton.setOnClickListener(view -> {
TrackSelectionDialogBuilder build = new TrackSelectionDialogBuilder(ViewVideoActivity.this, getString(R.string.select_video_quality), trackSelector, 0); TrackSelectionDialogBuilder builder = new TrackSelectionDialogBuilder(ViewVideoActivity.this, getString(R.string.select_video_quality), trackSelector, 0);
build.setShowDisableOption(true); builder.setShowDisableOption(true);
build.setAllowAdaptiveSelections(false); builder.setAllowAdaptiveSelections(false);
build.build().show(); AlertDialog alertDialog = builder.build();
alertDialog.show();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
}); });
} }

View File

@ -26,6 +26,7 @@ import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.r0adkll.slidr.Slidr; import com.r0adkll.slidr.Slidr;
@ -115,6 +116,7 @@ public class WikiActivity extends BaseActivity {
private Markwon markwon; private Markwon markwon;
private MarkwonAdapter markwonAdapter; private MarkwonAdapter markwonAdapter;
private boolean isRefreshing = false; private boolean isRefreshing = false;
private RequestManager mGlide;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -156,6 +158,8 @@ public class WikiActivity extends BaseActivity {
} }
} }
mGlide = Glide.with(this);
swipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true)); swipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true));
swipeRefreshLayout.setOnRefreshListener(this::loadWiki); swipeRefreshLayout.setOnRefreshListener(this::loadWiki);
@ -286,7 +290,7 @@ public class WikiActivity extends BaseActivity {
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
mFetchWikiInfoLinearLayout.setVisibility(View.VISIBLE); mFetchWikiInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchWikiInfoTextView.setText(stringResId); mFetchWikiInfoTextView.setText(stringResId);
Glide.with(this).load(R.drawable.error_image).into(mFetchWikiInfoImageView); mGlide.load(R.drawable.error_image).into(mFetchWikiInfoImageView);
} }
@Override @Override

View File

@ -87,6 +87,7 @@ import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.saket.bettermovementmethod.BetterLinkMovementMethod; import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks; import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks;
import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.SaveThing;
@ -142,7 +143,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private RequestManager mGlide; private RequestManager mGlide;
private Markwon mPostDetailMarkwon; private Markwon mPostDetailMarkwon;
private final MarkwonAdapter mMarkwonAdapter; private final MarkwonAdapter mMarkwonAdapter;
private int mImageViewWidth;
private String mAccessToken; private String mAccessToken;
private String mAccountName; private String mAccountName;
private Post mPost; private Post mPost;
@ -211,7 +211,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
Executor executor, CustomThemeWrapper customThemeWrapper, Executor executor, CustomThemeWrapper customThemeWrapper,
Retrofit retrofit, Retrofit oauthRetrofit, Retrofit gfycatRetrofit, Retrofit retrofit, Retrofit oauthRetrofit, Retrofit gfycatRetrofit,
Retrofit redgifsRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, Retrofit redgifsRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
RequestManager glide, int imageViewWidth, RequestManager glide,
boolean separatePostAndComments, String accessToken, boolean separatePostAndComments, String accessToken,
String accountName, Post post, Locale locale, String accountName, Post post, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences sharedPreferences,
@ -300,7 +300,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
.tableLayout(R.layout.adapter_table_block, R.id.table_layout) .tableLayout(R.layout.adapter_table_block, R.id.table_layout)
.textLayoutIsRoot(R.layout.view_table_entry_cell))) .textLayoutIsRoot(R.layout.view_table_entry_cell)))
.build(); .build();
mImageViewWidth = imageViewWidth;
mSeparatePostAndComments = separatePostAndComments; mSeparatePostAndComments = separatePostAndComments;
mLegacyAutoplayVideoControllerUI = sharedPreferences.getBoolean(SharedPreferencesUtils.LEGACY_AUTOPLAY_VIDEO_CONTROLLER_UI, false); mLegacyAutoplayVideoControllerUI = sharedPreferences.getBoolean(SharedPreferencesUtils.LEGACY_AUTOPLAY_VIDEO_CONTROLLER_UI, false);
mAccessToken = accessToken; mAccessToken = accessToken;
@ -634,11 +633,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
Post.Preview preview = getSuitablePreview(mPost.getPreviews()); Post.Preview preview = getSuitablePreview(mPost.getPreviews());
if (preview != null) { if (preview != null) {
((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight()); ((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight());
if (mImageViewWidth > preview.getPreviewWidth()) { mGlide.load(preview.getPreviewUrl()).centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
mGlide.load(preview.getPreviewUrl()).override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
} else {
mGlide.load(preview.getPreviewUrl()).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
}
} else { } else {
((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); ((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
} }
@ -694,8 +689,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
int height = (int) (400 * mScale); int height = (int) (400 * mScale);
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.getLayoutParams().height = height; ((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.getLayoutParams().height = height;
preview.setPreviewWidth(mImageViewWidth);
preview.setPreviewHeight(height);
} else { } else {
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / (float) preview.getPreviewWidth()); ((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / (float) preview.getPreviewWidth());
} }
@ -812,31 +805,15 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
previewIndex = 0; previewIndex = 0;
} }
preview = previews.get(previewIndex); preview = previews.get(previewIndex);
if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) { if (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000) {
for (int i = previews.size() - 1; i >= 1; i--) { for (int i = previews.size() - 1; i >= 1; i--) {
preview = previews.get(i); preview = previews.get(i);
if (mImageViewWidth >= preview.getPreviewWidth()) { if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 5_000_000) {
if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 10_000_000) { return preview;
return preview;
}
} else {
int height = mImageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight();
if (mImageViewWidth * height <= 10_000_000) {
return preview;
}
} }
} }
} }
if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) {
int divisor = 2;
do {
preview.setPreviewWidth(preview.getPreviewWidth() / divisor);
preview.setPreviewHeight(preview.getPreviewHeight() / divisor);
divisor *= 2;
} while (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000);
}
return preview; return preview;
} }
@ -848,7 +825,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
boolean blurImage = (mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler); boolean blurImage = (mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler);
String url = mPost.getPostType() == Post.IMAGE_TYPE || blurImage ? preview.getPreviewUrl() : mPost.getUrl(); String url = mPost.getPostType() == Post.IMAGE_TYPE || blurImage ? preview.getPreviewUrl() : mPost.getUrl();
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url) RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url)
.listener(new RequestListener<Drawable>() { .listener(new RequestListener<>() {
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
((PostDetailImageAndGifAutoplayViewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE); ((PostDetailImageAndGifAutoplayViewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE);
@ -871,15 +848,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
if (blurImage) { if (blurImage) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView); imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
} else { } else {
if (mImageViewWidth > preview.getPreviewWidth()) { imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
} else {
imageRequestBuilder.into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
}
} }
} else if (holder instanceof PostDetailVideoAndGifPreviewHolder) { } else if (holder instanceof PostDetailVideoAndGifPreviewHolder) {
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl()) RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl())
.listener(new RequestListener<Drawable>() { .listener(new RequestListener<>() {
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
((PostDetailVideoAndGifPreviewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE); ((PostDetailVideoAndGifPreviewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE);
@ -903,15 +876,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView); .into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
} else { } else {
if (mImageViewWidth > preview.getPreviewWidth()) { imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
} else {
imageRequestBuilder.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
}
} }
} else if (holder instanceof PostDetailLinkViewHolder) { } else if (holder instanceof PostDetailLinkViewHolder) {
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl()) RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl())
.listener(new RequestListener<Drawable>() { .listener(new RequestListener<>() {
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
((PostDetailLinkViewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE); ((PostDetailLinkViewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE);
@ -935,15 +904,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostDetailLinkViewHolder) holder).mImageView); .into(((PostDetailLinkViewHolder) holder).mImageView);
} else { } else {
if (mImageViewWidth > preview.getPreviewWidth()) { imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailLinkViewHolder) holder).mImageView);
imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostDetailLinkViewHolder) holder).mImageView);
} else {
imageRequestBuilder.into(((PostDetailLinkViewHolder) holder).mImageView);
}
} }
} else if (holder instanceof PostDetailGalleryViewHolder) { } else if (holder instanceof PostDetailGalleryViewHolder) {
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl()) RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl())
.listener(new RequestListener<Drawable>() { .listener(new RequestListener<>() {
@Override @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
((PostDetailGalleryViewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE); ((PostDetailGalleryViewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE);
@ -966,11 +931,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
if ((mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler)) { if ((mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailGalleryViewHolder) holder).mImageView); imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailGalleryViewHolder) holder).mImageView);
} else { } else {
if (mImageViewWidth > preview.getPreviewWidth()) { imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailGalleryViewHolder) holder).mImageView);
imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostDetailGalleryViewHolder) holder).mImageView);
} else {
imageRequestBuilder.into(((PostDetailGalleryViewHolder) holder).mImageView);
}
} }
} }
} }

View File

@ -69,6 +69,7 @@ import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks; import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks;
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.SaveThing;
import ml.docilealligator.infinityforreddit.VoteThing; import ml.docilealligator.infinityforreddit.VoteThing;
@ -126,7 +127,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private Retrofit mOauthRetrofit; private Retrofit mOauthRetrofit;
private Retrofit mGfycatRetrofit; private Retrofit mGfycatRetrofit;
private Retrofit mRedgifsRetrofit; private Retrofit mRedgifsRetrofit;
private int mImageViewWidth;
private String mAccessToken; private String mAccessToken;
private RequestManager mGlide; private RequestManager mGlide;
private Locale mLocale; private Locale mLocale;
@ -206,7 +206,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
public PostRecyclerViewAdapter(AppCompatActivity activity, PostFragment fragment, Executor executor, Retrofit oauthRetrofit, public PostRecyclerViewAdapter(AppCompatActivity activity, PostFragment fragment, Executor executor, Retrofit oauthRetrofit,
Retrofit gfycatRetrofit, Retrofit redgifsRetrofit, Retrofit gfycatRetrofit, Retrofit redgifsRetrofit,
CustomThemeWrapper customThemeWrapper, Locale locale, int imageViewWidth, CustomThemeWrapper customThemeWrapper, Locale locale,
String accessToken, String accountName, int postType, int postLayout, boolean displaySubredditName, String accessToken, String accountName, int postType, int postLayout, boolean displaySubredditName,
SharedPreferences sharedPreferences, SharedPreferences nsfwAndSpoilerSharedPreferences, SharedPreferences sharedPreferences, SharedPreferences nsfwAndSpoilerSharedPreferences,
SharedPreferences postHistorySharedPreferences, SharedPreferences postHistorySharedPreferences,
@ -220,7 +220,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
mOauthRetrofit = oauthRetrofit; mOauthRetrofit = oauthRetrofit;
mGfycatRetrofit = gfycatRetrofit; mGfycatRetrofit = gfycatRetrofit;
mRedgifsRetrofit = redgifsRetrofit; mRedgifsRetrofit = redgifsRetrofit;
mImageViewWidth = imageViewWidth;
mAccessToken = accessToken; mAccessToken = accessToken;
mPostType = postType; mPostType = postType;
mDisplaySubredditName = displaySubredditName; mDisplaySubredditName = displaySubredditName;
@ -676,11 +675,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
Post.Preview preview = getSuitablePreview(post.getPreviews()); Post.Preview preview = getSuitablePreview(post.getPreviews());
if (preview != null) { if (preview != null) {
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight()); ((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight());
if (mImageViewWidth > preview.getPreviewWidth()) { mGlide.load(preview.getPreviewUrl()).centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
mGlide.load(preview.getPreviewUrl()).override(Target.SIZE_ORIGINAL).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
} else {
mGlide.load(preview.getPreviewUrl()).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
}
} else { } else {
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); ((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
} }
@ -774,8 +769,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
int height = (int) (400 * mScale); int height = (int) (400 * mScale);
((PostWithPreviewTypeViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostWithPreviewTypeViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
((PostWithPreviewTypeViewHolder) holder).imageView.getLayoutParams().height = height; ((PostWithPreviewTypeViewHolder) holder).imageView.getLayoutParams().height = height;
preview.setPreviewWidth(mImageViewWidth);
preview.setPreviewHeight(height);
} else { } else {
((PostWithPreviewTypeViewHolder) holder).imageView ((PostWithPreviewTypeViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
@ -809,11 +802,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
Post.Preview preview = getSuitablePreview(post.getPreviews()); Post.Preview preview = getSuitablePreview(post.getPreviews());
if (preview != null) { if (preview != null) {
((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight()); ((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight());
if (mImageViewWidth > preview.getPreviewWidth()) { mGlide.load(preview.getPreviewUrl()).centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostCard2VideoAutoplayViewHolder) holder).previewImageView);
mGlide.load(preview.getPreviewUrl()).override(Target.SIZE_ORIGINAL).into(((PostCard2VideoAutoplayViewHolder) holder).previewImageView);
} else {
mGlide.load(preview.getPreviewUrl()).into(((PostCard2VideoAutoplayViewHolder) holder).previewImageView);
}
} else { } else {
((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); ((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
} }
@ -909,8 +898,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
int height = (int) (400 * mScale); int height = (int) (400 * mScale);
((PostCard2WithPreviewViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostCard2WithPreviewViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
((PostCard2WithPreviewViewHolder) holder).imageView.getLayoutParams().height = height; ((PostCard2WithPreviewViewHolder) holder).imageView.getLayoutParams().height = height;
preview.setPreviewWidth(mImageViewWidth);
preview.setPreviewHeight(height);
} else { } else {
((PostCard2WithPreviewViewHolder) holder).imageView ((PostCard2WithPreviewViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
@ -1291,8 +1278,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
int height = (int) (400 * mScale); int height = (int) (400 * mScale);
((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height;
preview.setPreviewWidth(mImageViewWidth);
preview.setPreviewHeight(height);
} else { } else {
((PostGalleryViewHolder) holder).imageView ((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
@ -1327,8 +1312,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
int height = (int) (400 * mScale); int height = (int) (400 * mScale);
((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height;
preview.setPreviewWidth(mImageViewWidth);
preview.setPreviewHeight(height);
} else { } else {
((PostGalleryViewHolder) holder).imageView ((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
@ -1353,8 +1336,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
int height = (int) (400 * mScale); int height = (int) (400 * mScale);
((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height;
preview.setPreviewWidth(mImageViewWidth);
preview.setPreviewHeight(height);
} else { } else {
((PostGalleryViewHolder) holder).imageView ((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
@ -1379,8 +1360,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
int height = (int) (400 * mScale); int height = (int) (400 * mScale);
((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height;
preview.setPreviewWidth(mImageViewWidth);
preview.setPreviewHeight(height);
} else { } else {
((PostGalleryViewHolder) holder).imageView ((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
@ -1415,8 +1394,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
int height = (int) (400 * mScale); int height = (int) (400 * mScale);
((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height;
preview.setPreviewWidth(mImageViewWidth);
preview.setPreviewHeight(height);
} else { } else {
((PostGalleryViewHolder) holder).imageView ((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
@ -1447,29 +1424,11 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
if (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000) { if (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000) {
for (int i = previews.size() - 1; i >= 1; i--) { for (int i = previews.size() - 1; i >= 1; i--) {
preview = previews.get(i); preview = previews.get(i);
if (mImageViewWidth >= preview.getPreviewWidth()) { if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 5_000_000) {
if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 5_000_000) { return preview;
return preview;
}
} else {
int height = mImageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight();
if (mImageViewWidth * height <= 5_000_000) {
preview.setPreviewWidth(mImageViewWidth);
preview.setPreviewHeight(height);
return preview;
}
} }
} }
} }
if (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000) {
int divisor = 2;
do {
preview.setPreviewWidth(preview.getPreviewWidth() / divisor);
preview.setPreviewHeight(preview.getPreviewHeight() / divisor);
divisor *= 2;
} while (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000);
}
return preview; return preview;
} }
@ -1494,7 +1453,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostWithPreviewTypeViewHolder) holder).imageView); .into(((PostWithPreviewTypeViewHolder) holder).imageView);
} else { } else {
imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).centerInside().into(((PostWithPreviewTypeViewHolder) holder).imageView); imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostWithPreviewTypeViewHolder) holder).imageView);
} }
} }
} else if (holder instanceof PostCompactBaseViewHolder) { } else if (holder instanceof PostCompactBaseViewHolder) {
@ -1534,11 +1493,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostGalleryViewHolder) holder).imageView); .into(((PostGalleryViewHolder) holder).imageView);
} else { } else {
if (mImageViewWidth > preview.getPreviewWidth()) { imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostGalleryViewHolder) holder).imageView);
imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostGalleryViewHolder) holder).imageView);
} else {
imageRequestBuilder.into(((PostGalleryViewHolder) holder).imageView);
}
} }
} }
} else if (holder instanceof PostCard2WithPreviewViewHolder) { } else if (holder instanceof PostCard2WithPreviewViewHolder) {
@ -1558,11 +1513,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostCard2WithPreviewViewHolder) holder).imageView); .into(((PostCard2WithPreviewViewHolder) holder).imageView);
} else { } else {
if (mImageViewWidth > preview.getPreviewWidth()) { imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostCard2WithPreviewViewHolder) holder).imageView);
imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostCard2WithPreviewViewHolder) holder).imageView);
} else {
imageRequestBuilder.into(((PostCard2WithPreviewViewHolder) holder).imageView);
}
} }
} }
} }
@ -1916,12 +1867,15 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
} }
private void openViewPostDetailActivity(Post post, int position) { private void openViewPostDetailActivity(Post post, int position) {
Intent intent = new Intent(mActivity, ViewPostDetailActivity.class); if (canStartActivity) {
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, post); canStartActivity = false;
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_LIST_POSITION, position); Intent intent = new Intent(mActivity, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_FRAGMENT_ID, mFragment.getPostFragmentId()); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, post);
intent.putExtra(ViewPostDetailActivity.EXTRA_IS_NSFW_SUBREDDIT, mFragment.getIsNsfwSubreddit()); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_LIST_POSITION, position);
mActivity.startActivity(intent); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_FRAGMENT_ID, mFragment.getPostFragmentId());
intent.putExtra(ViewPostDetailActivity.EXTRA_IS_NSFW_SUBREDDIT, mFragment.getIsNsfwSubreddit());
mActivity.startActivity(intent);
}
} }
private void openMedia(Post post) { private void openMedia(Post post) {
@ -2113,7 +2067,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
Post post = getItem(position); Post post = getItem(position);
if (post != null) { if (post != null) {
markPostRead(post, true); markPostRead(post, true);
canStartActivity = false;
openViewPostDetailActivity(post, getBindingAdapterPosition()); openViewPostDetailActivity(post, getBindingAdapterPosition());
} }
@ -3160,8 +3113,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
Post post = getItem(position); Post post = getItem(position);
if (post != null && canStartActivity) { if (post != null && canStartActivity) {
markPostRead(post, true); markPostRead(post, true);
canStartActivity = false;
openViewPostDetailActivity(post, getBindingAdapterPosition()); openViewPostDetailActivity(post, getBindingAdapterPosition());
} }
}); });
@ -3750,7 +3701,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
Post post = getItem(position); Post post = getItem(position);
if (post != null) { if (post != null) {
markPostRead(post, true); markPostRead(post, true);
canStartActivity = false;
if (post.getPostType() == Post.TEXT_TYPE || !mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) { if (post.getPostType() == Post.TEXT_TYPE || !mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) {
openViewPostDetailActivity(post, getBindingAdapterPosition()); openViewPostDetailActivity(post, getBindingAdapterPosition());
@ -3767,7 +3717,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
Post post = getItem(position); Post post = getItem(position);
if (post != null) { if (post != null) {
markPostRead(post, true); markPostRead(post, true);
canStartActivity = false;
if (post.getPostType() == Post.TEXT_TYPE || mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) { if (post.getPostType() == Post.TEXT_TYPE || mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) {
openViewPostDetailActivity(post, getBindingAdapterPosition()); openViewPostDetailActivity(post, getBindingAdapterPosition());

View File

@ -17,7 +17,6 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.Handler; import android.os.Handler;
import android.util.DisplayMetrics;
import android.view.HapticFeedbackConstants; import android.view.HapticFeedbackConstants;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -338,10 +337,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} }
} }
DisplayMetrics displayMetrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int windowWidth = displayMetrics.widthPixels;
mGlide = Glide.with(activity); mGlide = Glide.with(activity);
lazyModeRunnable = new LazyModeRunnable() { lazyModeRunnable = new LazyModeRunnable() {
@ -452,7 +447,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mCustomThemeWrapper, locale, mRedgifsRetrofit, mCustomThemeWrapper, locale,
windowWidth, accessToken, accountName, postType, postLayout, true, accessToken, accountName, postType, postLayout, true,
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
mExoCreator, new PostRecyclerViewAdapter.Callback() { mExoCreator, new PostRecyclerViewAdapter.Callback() {
@Override @Override
@ -529,7 +524,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mCustomThemeWrapper, locale, mRedgifsRetrofit, mCustomThemeWrapper, locale,
windowWidth, accessToken, accountName, postType, postLayout, displaySubredditName, accessToken, accountName, postType, postLayout, displaySubredditName,
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
mExoCreator, new PostRecyclerViewAdapter.Callback() { mExoCreator, new PostRecyclerViewAdapter.Callback() {
@Override @Override
@ -600,7 +595,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mCustomThemeWrapper, locale, mRedgifsRetrofit, mCustomThemeWrapper, locale,
windowWidth, accessToken, accountName, postType, postLayout, true, accessToken, accountName, postType, postLayout, true,
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
mExoCreator, new PostRecyclerViewAdapter.Callback() { mExoCreator, new PostRecyclerViewAdapter.Callback() {
@Override @Override
@ -665,7 +660,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mCustomThemeWrapper, locale, mRedgifsRetrofit, mCustomThemeWrapper, locale,
windowWidth, accessToken, accountName, postType, postLayout, true, accessToken, accountName, postType, postLayout, true,
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
mExoCreator, new PostRecyclerViewAdapter.Callback() { mExoCreator, new PostRecyclerViewAdapter.Callback() {
@Override @Override
@ -726,7 +721,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mCustomThemeWrapper, locale, mRedgifsRetrofit, mCustomThemeWrapper, locale,
windowWidth, accessToken, accountName, postType, postLayout, true, accessToken, accountName, postType, postLayout, true,
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
mExoCreator, new PostRecyclerViewAdapter.Callback() { mExoCreator, new PostRecyclerViewAdapter.Callback() {
@Override @Override
@ -786,7 +781,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mCustomThemeWrapper, locale, mRedgifsRetrofit, mCustomThemeWrapper, locale,
windowWidth, accessToken, accountName, postType, postLayout, true, accessToken, accountName, postType, postLayout, true,
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
mExoCreator, new PostRecyclerViewAdapter.Callback() { mExoCreator, new PostRecyclerViewAdapter.Callback() {
@Override @Override
@ -840,7 +835,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mCustomThemeWrapper, locale, mRedgifsRetrofit, mCustomThemeWrapper, locale,
windowWidth, accessToken, accountName, postType, postLayout, true, accessToken, accountName, postType, postLayout, true,
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
mExoCreator, new PostRecyclerViewAdapter.Callback() { mExoCreator, new PostRecyclerViewAdapter.Callback() {
@Override @Override
@ -891,7 +886,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
StaggeredGridLayoutManagerItemOffsetDecoration itemDecoration = StaggeredGridLayoutManagerItemOffsetDecoration itemDecoration =
new StaggeredGridLayoutManagerItemOffsetDecoration(activity, R.dimen.staggeredLayoutManagerItemOffset, nColumns); new StaggeredGridLayoutManagerItemOffsetDecoration(activity, R.dimen.staggeredLayoutManagerItemOffset, nColumns);
mPostRecyclerView.addItemDecoration(itemDecoration); mPostRecyclerView.addItemDecoration(itemDecoration);
windowWidth /= 2;
} }
if (recyclerViewPosition > 0) { if (recyclerViewPosition > 0) {

View File

@ -16,7 +16,6 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.util.DisplayMetrics;
import android.view.HapticFeedbackConstants; import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -224,7 +223,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
private boolean mExpandChildren; private boolean mExpandChildren;
private boolean mSeparatePostAndComments = false; private boolean mSeparatePostAndComments = false;
private boolean mMarkPostsAsRead; private boolean mMarkPostsAsRead;
private int mWindowWidth;
private ConcatAdapter mConcatAdapter; private ConcatAdapter mConcatAdapter;
private PostDetailRecyclerViewAdapter mPostAdapter; private PostDetailRecyclerViewAdapter mPostAdapter;
private CommentsRecyclerViewAdapter mCommentsAdapter; private CommentsRecyclerViewAdapter mCommentsAdapter;
@ -290,10 +288,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
showToast = true; showToast = true;
} }
DisplayMetrics displayMetrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
mWindowWidth = displayMetrics.widthPixels;
mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false); mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false); mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false); mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
@ -550,7 +544,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mPostAdapter = new PostDetailRecyclerViewAdapter(activity, mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit, this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide, mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide,
mWindowWidth, mSeparatePostAndComments, mAccessToken, mAccountName, mPost, mLocale, mSeparatePostAndComments, mAccessToken, mAccountName, mPost, mLocale,
mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences,
mExoCreator, post -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition))); mExoCreator, post -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
mCommentsAdapter = new CommentsRecyclerViewAdapter(activity, mCommentsAdapter = new CommentsRecyclerViewAdapter(activity,
@ -1195,7 +1189,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mPostAdapter = new PostDetailRecyclerViewAdapter(activity, mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper, ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper,
mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit,
mRedditDataRoomDatabase, mGlide, mWindowWidth, mSeparatePostAndComments, mRedditDataRoomDatabase, mGlide, mSeparatePostAndComments,
mAccessToken, mAccountName, mPost, mLocale, mSharedPreferences, mAccessToken, mAccountName, mPost, mLocale, mSharedPreferences,
mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences,
mExoCreator, mExoCreator,

View File

@ -1,5 +1,6 @@
package ml.docilealligator.infinityforreddit.fragments; package ml.docilealligator.infinityforreddit.fragments;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
@ -207,11 +208,14 @@ public class ViewRPANBroadcastFragment extends Fragment {
hdButton.setVisibility(View.VISIBLE); hdButton.setVisibility(View.VISIBLE);
hdButton.setOnClickListener(view -> { hdButton.setOnClickListener(view -> {
TrackSelectionDialogBuilder build = new TrackSelectionDialogBuilder(mActivity, TrackSelectionDialogBuilder builder = new TrackSelectionDialogBuilder(mActivity,
getString(R.string.select_video_quality), trackSelector, 0); getString(R.string.select_video_quality), trackSelector, 0);
build.setShowDisableOption(true); builder.setShowDisableOption(true);
build.setAllowAdaptiveSelections(false); builder.setAllowAdaptiveSelections(false);
build.build().show(); AlertDialog alertDialog = builder.build();
alertDialog.show();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
}); });
for (int i = 0; i < trackGroups.length; i++) { for (int i = 0; i < trackGroups.length; i++) {

View File

@ -492,26 +492,26 @@ public class CustomizeMainPageTabsFragment extends Fragment {
tab3AddImageView.setOnClickListener(view -> selectName(2)); tab3AddImageView.setOnClickListener(view -> selectName(2));
showMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, false)); showMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, false));
showMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, b).apply()); showMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, b).apply());
showMultiredditsLinearLayout.setOnClickListener(view -> { showMultiredditsLinearLayout.setOnClickListener(view -> {
showMultiredditsSwitchMaterial.performClick(); showMultiredditsSwitchMaterial.performClick();
}); });
showFavoriteMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, false)); showFavoriteMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, false));
showFavoriteMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, b).apply()); showFavoriteMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, b).apply());
showFavoriteMultiredditsLinearLayout.setOnClickListener(view -> { showFavoriteMultiredditsLinearLayout.setOnClickListener(view -> {
showFavoriteMultiredditsSwitchMaterial.performClick(); showFavoriteMultiredditsSwitchMaterial.performClick();
}); });
showSubscribedSubredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, false)); showSubscribedSubredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, false));
showSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, b).apply()); showSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, b).apply());
showSubscribedSubredditsLinearLayout.setOnClickListener(view -> { showSubscribedSubredditsLinearLayout.setOnClickListener(view -> {
showSubscribedSubredditsSwitchMaterial.performClick(); showSubscribedSubredditsSwitchMaterial.performClick();
}); });
showFavoriteSubscribedSubredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, false)); showFavoriteSubscribedSubredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, false));
showFavoriteSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, b).apply()); showFavoriteSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, b).apply());
showFavoriteSubscribedSubredditsLinearLayout.setOnClickListener(view -> { showFavoriteSubscribedSubredditsLinearLayout.setOnClickListener(view -> {
showFavoriteSubscribedSubredditsSwitchMaterial.performClick(); showFavoriteSubscribedSubredditsSwitchMaterial.performClick();
}); });

View File

@ -119,6 +119,14 @@
android:src="@drawable/ic_file_download_toolbar_white_24dp" android:src="@drawable/ic_file_download_toolbar_white_24dp"
android:background="?attr/selectableItemBackgroundBorderless" /> android:background="?attr/selectableItemBackgroundBorderless" />
<ImageView
android:id="@+id/playback_speed_image_view_exo_playback_control_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:src="@drawable/ic_playback_speed_toolbar_24dp"
android:background="?attr/selectableItemBackgroundBorderless" />
</LinearLayout> </LinearLayout>
</com.google.android.material.bottomappbar.BottomAppBar> </com.google.android.material.bottomappbar.BottomAppBar>

View File

@ -31,6 +31,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:show_timeout="1500" app:show_timeout="1500"
app:auto_show="false"
app:controller_layout_id="@layout/exo_autoplay_playback_control_view" /> app:controller_layout_id="@layout/exo_autoplay_playback_control_view" />
<pl.droidsonroids.gif.GifImageView <pl.droidsonroids.gif.GifImageView

View File

@ -31,6 +31,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:show_timeout="1500" app:show_timeout="1500"
app:auto_show="false"
app:controller_layout_id="@layout/exo_autoplay_playback_control_view_legacy" /> app:controller_layout_id="@layout/exo_autoplay_playback_control_view_legacy" />
<pl.droidsonroids.gif.GifImageView <pl.droidsonroids.gif.GifImageView

View File

@ -214,6 +214,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:show_timeout="1500" app:show_timeout="1500"
app:auto_show="false"
app:controller_layout_id="@layout/exo_autoplay_playback_control_view" /> app:controller_layout_id="@layout/exo_autoplay_playback_control_view" />
<pl.droidsonroids.gif.GifImageView <pl.droidsonroids.gif.GifImageView

View File

@ -214,6 +214,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:show_timeout="1500" app:show_timeout="1500"
app:auto_show="false"
app:controller_layout_id="@layout/exo_autoplay_playback_control_view_legacy" /> app:controller_layout_id="@layout/exo_autoplay_playback_control_view_legacy" />
<pl.droidsonroids.gif.GifImageView <pl.droidsonroids.gif.GifImageView

View File

@ -208,6 +208,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:show_timeout="1500" app:show_timeout="1500"
app:auto_show="false"
app:controller_layout_id="@layout/exo_autoplay_playback_control_view" /> app:controller_layout_id="@layout/exo_autoplay_playback_control_view" />
<pl.droidsonroids.gif.GifImageView <pl.droidsonroids.gif.GifImageView

View File

@ -208,6 +208,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:show_timeout="1500" app:show_timeout="1500"
app:auto_show="false"
app:controller_layout_id="@layout/exo_autoplay_playback_control_view_legacy" /> app:controller_layout_id="@layout/exo_autoplay_playback_control_view_legacy" />
<pl.droidsonroids.gif.GifImageView <pl.droidsonroids.gif.GifImageView

View File

@ -216,8 +216,7 @@
android:id="@+id/image_view_item_post_with_preview" android:id="@+id/image_view_item_post_with_preview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:adjustViewBounds="true" android:adjustViewBounds="true" />
android:scaleType="fitStart" />
<ImageView <ImageView
android:id="@+id/video_or_gif_indicator_image_view_item_post_with_preview" android:id="@+id/video_or_gif_indicator_image_view_item_post_with_preview"