diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-02-05 05:41:20 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-02-05 05:41:20 +0000 |
commit | 5693bc384d2a6b8267b098e828fae2ef875a68a7 (patch) | |
tree | 75271f909cff5b6c2098368c6b49fd0d26e01f8f /app/src | |
parent | 6e211a582135c1d12cd2e7ff036ad6e40c8e82f2 (diff) | |
download | infinity-for-reddit-5693bc384d2a6b8267b098e828fae2ef875a68a7.tar infinity-for-reddit-5693bc384d2a6b8267b098e828fae2ef875a68a7.tar.gz infinity-for-reddit-5693bc384d2a6b8267b098e828fae2ef875a68a7.tar.bz2 infinity-for-reddit-5693bc384d2a6b8267b098e828fae2ef875a68a7.tar.lz infinity-for-reddit-5693bc384d2a6b8267b098e828fae2ef875a68a7.tar.xz infinity-for-reddit-5693bc384d2a6b8267b098e828fae2ef875a68a7.tar.zst infinity-for-reddit-5693bc384d2a6b8267b098e828fae2ef875a68a7.zip |
Fix bugs related to changing default post layout. Rewrite opening links to handle error. Version 2.2.0.
Diffstat (limited to 'app/src')
6 files changed, 82 insertions, 16 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index b066cb99..a049e9e0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -155,17 +155,21 @@ public class LinkResolverActivity extends AppCompatActivity { private void deepLinkError(Uri uri) { PackageManager pm = getPackageManager(); - if (mSharedPreferences.getBoolean(SharedPreferencesUtils.OPEN_LINK_IN_APP, false)) { - openInCustomTabs(uri, pm); - return; - } String authority = uri.getAuthority(); if(authority != null && (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app.link"))) { - openInCustomTabs(uri, pm); + openInCustomTabs(uri, pm, false); 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.setData(uri); @@ -184,13 +188,22 @@ public class LinkResolverActivity extends AppCompatActivity { try { startActivity(intent); } 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 { - 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) { // Get default VIEW intent handler. Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.example.com")); @@ -210,7 +223,7 @@ public class LinkResolverActivity extends AppCompatActivity { return packagesSupportingCustomTabs; } - private void openInCustomTabs(Uri uri, PackageManager pm) { + private void openInCustomTabs(Uri uri, PackageManager pm, boolean handleError) { ArrayList<ResolveInfo> resolveInfos = getCustomTabsPackages(pm); if (!resolveInfos.isEmpty()) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); @@ -225,10 +238,18 @@ public class LinkResolverActivity extends AppCompatActivity { try { customTabsIntent.launchUrl(this, uri); } catch (ActivityNotFoundException e) { - Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show(); + if (handleError) { + openInBrowser(uri, pm, false); + } else { + Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show(); + } } } else { - Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show(); + if (handleError) { + openInBrowser(uri, pm, false); + } else { + Toast.makeText(this, R.string.no_browser_found, Toast.LENGTH_SHORT).show(); + } } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index a506ceba..52372b76 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -1305,7 +1305,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy }); 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); } else { imageRequestBuilder.into(holder.mImageView); 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 12d6ac8e..1a2b4ea5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -1297,7 +1297,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView }); 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); } else { imageRequestBuilder.into(((PostViewHolder) holder).imageView); @@ -1320,7 +1320,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView }); if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) { imageRequestBuilder - .transform(new BlurTransformation(50, 2)) + .transform(new BlurTransformation(50, 10)) .into(((PostCompactViewHolder) holder).imageView); } else { imageRequestBuilder.into(((PostCompactViewHolder) holder).imageView); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeDefaultPostLayoutEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeDefaultPostLayoutEvent.java new file mode 100644 index 00000000..2a5819fb --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeDefaultPostLayoutEvent.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.Event; + +public class ChangeDefaultPostLayoutEvent { + public int defaultPostLayout; + + public ChangeDefaultPostLayoutEvent(int defaultPostLayout) { + this.defaultPostLayout = defaultPostLayout; + } +} 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 7ebd735a..e309343c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -52,6 +52,7 @@ import ml.docilealligator.infinityforreddit.Activity.FilteredThingActivity; import ml.docilealligator.infinityforreddit.Activity.MainActivity; import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.Adapter.PostRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; @@ -114,6 +115,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { private AppCompatActivity activity; private LinearLayoutManager mLinearLayoutManager; private StaggeredGridLayoutManager mStaggeredGridLayoutManager; + private int postType; private boolean isInLazyMode = false; private boolean isLazyModePaused = 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); String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); @@ -769,6 +771,40 @@ public class PostFragment extends Fragment implements FragmentCommunicator { 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() { int previousPosition = -1; if (mLinearLayoutManager != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java index e4b64d27..3ce67392 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java @@ -11,7 +11,7 @@ import androidx.preference.SwitchPreference; 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.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; @@ -70,7 +70,7 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { if (defaultPostLayoutSwitch != null) { defaultPostLayoutSwitch.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new ChangePostLayoutEvent(Integer.parseInt((String) newValue))); + EventBus.getDefault().post(new ChangeDefaultPostLayoutEvent(Integer.parseInt((String) newValue))); return true; }); } |