Fix bugs related to changing default post layout. Rewrite opening links to handle error. Version 2.2.0.

This commit is contained in:
Alex Ning 2020-02-05 13:41:20 +08:00
parent 6e211a5821
commit 5693bc384d
7 changed files with 84 additions and 18 deletions

View File

@ -6,8 +6,8 @@ android {
applicationId "ml.docilealligator.infinityforreddit" applicationId "ml.docilealligator.infinityforreddit"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 26 versionCode 27
versionName "2.1.0" versionName "2.2.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {

View File

@ -155,17 +155,21 @@ public class LinkResolverActivity extends AppCompatActivity {
private void deepLinkError(Uri uri) { private void deepLinkError(Uri uri) {
PackageManager pm = getPackageManager(); PackageManager pm = getPackageManager();
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.OPEN_LINK_IN_APP, false)) {
openInCustomTabs(uri, pm);
return;
}
String authority = uri.getAuthority(); String authority = uri.getAuthority();
if(authority != null && (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app.link"))) { if(authority != null && (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app.link"))) {
openInCustomTabs(uri, pm); openInCustomTabs(uri, pm, false);
return; return;
} }
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.OPEN_LINK_IN_APP, false)) {
openInCustomTabs(uri, pm, true);
} else {
openInBrowser(uri, pm, true);
}
}
private void openInBrowser(Uri uri, PackageManager pm, boolean handleError) {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri); intent.setData(uri);
@ -184,12 +188,21 @@ public class LinkResolverActivity extends AppCompatActivity {
try { try {
startActivity(intent); startActivity(intent);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
openInCustomTabs(uri, pm); if (handleError) {
openInCustomTabs(uri, pm, false);
} else {
Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show();
}
} }
} else { } else {
openInCustomTabs(uri, pm); if (handleError) {
openInCustomTabs(uri, pm, false);
} else {
Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show();
} }
} }
}
private ArrayList<ResolveInfo> getCustomTabsPackages(PackageManager pm) { private ArrayList<ResolveInfo> getCustomTabsPackages(PackageManager pm) {
// Get default VIEW intent handler. // Get default VIEW intent handler.
@ -210,7 +223,7 @@ public class LinkResolverActivity extends AppCompatActivity {
return packagesSupportingCustomTabs; return packagesSupportingCustomTabs;
} }
private void openInCustomTabs(Uri uri, PackageManager pm) { private void openInCustomTabs(Uri uri, PackageManager pm, boolean handleError) {
ArrayList<ResolveInfo> resolveInfos = getCustomTabsPackages(pm); ArrayList<ResolveInfo> resolveInfos = getCustomTabsPackages(pm);
if (!resolveInfos.isEmpty()) { if (!resolveInfos.isEmpty()) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
@ -225,10 +238,18 @@ public class LinkResolverActivity extends AppCompatActivity {
try { try {
customTabsIntent.launchUrl(this, uri); customTabsIntent.launchUrl(this, uri);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show(); if (handleError) {
} openInBrowser(uri, pm, false);
} else { } else {
Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show();
} }
} }
} else {
if (handleError) {
openInBrowser(uri, pm, false);
} else {
Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show();
}
}
}
} }

View File

@ -1305,7 +1305,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}); });
if ((mPost.isNSFW() && mNeedBlurNSFW) || (mPost.isSpoiler() && mNeedBlurSpoiler)) { if ((mPost.isNSFW() && mNeedBlurNSFW) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 2))) imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(holder.mImageView); .into(holder.mImageView);
} else { } else {
imageRequestBuilder.into(holder.mImageView); imageRequestBuilder.into(holder.mImageView);

View File

@ -1297,7 +1297,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}); });
if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) { if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 2))) imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostViewHolder) holder).imageView); .into(((PostViewHolder) holder).imageView);
} else { } else {
imageRequestBuilder.into(((PostViewHolder) holder).imageView); imageRequestBuilder.into(((PostViewHolder) holder).imageView);
@ -1320,7 +1320,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}); });
if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) { if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) {
imageRequestBuilder imageRequestBuilder
.transform(new BlurTransformation(50, 2)) .transform(new BlurTransformation(50, 10))
.into(((PostCompactViewHolder) holder).imageView); .into(((PostCompactViewHolder) holder).imageView);
} else { } else {
imageRequestBuilder.into(((PostCompactViewHolder) holder).imageView); imageRequestBuilder.into(((PostCompactViewHolder) holder).imageView);

View File

@ -0,0 +1,9 @@
package ml.docilealligator.infinityforreddit.Event;
public class ChangeDefaultPostLayoutEvent {
public int defaultPostLayout;
public ChangeDefaultPostLayoutEvent(int defaultPostLayout) {
this.defaultPostLayout = defaultPostLayout;
}
}

View File

@ -52,6 +52,7 @@ import ml.docilealligator.infinityforreddit.Activity.FilteredThingActivity;
import ml.docilealligator.infinityforreddit.Activity.MainActivity; import ml.docilealligator.infinityforreddit.Activity.MainActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.Adapter.PostRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Adapter.PostRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
@ -114,6 +115,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private AppCompatActivity activity; private AppCompatActivity activity;
private LinearLayoutManager mLinearLayoutManager; private LinearLayoutManager mLinearLayoutManager;
private StaggeredGridLayoutManager mStaggeredGridLayoutManager; private StaggeredGridLayoutManager mStaggeredGridLayoutManager;
private int postType;
private boolean isInLazyMode = false; private boolean isInLazyMode = false;
private boolean isLazyModePaused = false; private boolean isLazyModePaused = false;
private boolean hasPost = false; private boolean hasPost = false;
@ -311,7 +313,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}); });
} }
int postType = getArguments().getInt(EXTRA_POST_TYPE); postType = getArguments().getInt(EXTRA_POST_TYPE);
int filter = getArguments().getInt(EXTRA_FILTER); int filter = getArguments().getInt(EXTRA_FILTER);
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
@ -769,6 +771,40 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
refreshAdapter(); refreshAdapter();
} }
@Subscribe
public void onChangeDefaultPostLayoutEvent(ChangeDefaultPostLayoutEvent changeDefaultPostLayoutEvent) {
Bundle bundle = getArguments();
if (bundle != null) {
switch (postType) {
case PostDataSource.TYPE_SUBREDDIT:
if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + bundle.getString(EXTRA_NAME))) {
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
}
break;
case PostDataSource.TYPE_USER:
if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + bundle.getString(EXTRA_USER_NAME))) {
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
}
break;
case PostDataSource.TYPE_MULTI_REDDIT:
if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + bundle.getString(EXTRA_NAME))) {
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
}
break;
case PostDataSource.TYPE_SEARCH:
if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST)) {
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
}
break;
case PostDataSource.TYPE_FRONT_PAGE:
if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST)) {
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
}
break;
}
}
}
private void refreshAdapter() { private void refreshAdapter() {
int previousPosition = -1; int previousPosition = -1;
if (mLinearLayoutManager != null) { if (mLinearLayoutManager != null) {

View File

@ -11,7 +11,7 @@ import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
@ -70,7 +70,7 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
if (defaultPostLayoutSwitch != null) { if (defaultPostLayoutSwitch != null) {
defaultPostLayoutSwitch.setOnPreferenceChangeListener((preference, newValue) -> { defaultPostLayoutSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangePostLayoutEvent(Integer.parseInt((String) newValue))); EventBus.getDefault().post(new ChangeDefaultPostLayoutEvent(Integer.parseInt((String) newValue)));
return true; return true;
}); });
} }