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"
minSdkVersion 21
targetSdkVersion 29
versionCode 26
versionName "2.1.0"
versionCode 27
versionName "2.2.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {

View File

@ -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();
}
}
}
}

View File

@ -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);

View File

@ -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);

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.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) {

View File

@ -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;
});
}