mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
Fix bugs related to changing default post layout. Rewrite opening links to handle error. Version 2.2.0.
This commit is contained in:
parent
6e211a5821
commit
5693bc384d
@ -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 {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -0,0 +1,9 @@
|
||||
package ml.docilealligator.infinityforreddit.Event;
|
||||
|
||||
public class ChangeDefaultPostLayoutEvent {
|
||||
public int defaultPostLayout;
|
||||
|
||||
public ChangeDefaultPostLayoutEvent(int defaultPostLayout) {
|
||||
this.defaultPostLayout = defaultPostLayout;
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user