mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-14 06:22:50 +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"
|
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 {
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -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);
|
||||||
|
@ -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.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) {
|
||||||
|
@ -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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user