aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java59
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RPANBroadcast.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RedditGalleryPayload.java96
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/TrendingSearch.java54
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java145
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java93
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java76
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java148
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java46
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java132
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java24
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java46
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/MotionTestActivity.java41
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java42
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java709
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java153
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java31
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java114
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java126
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java274
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java25
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java128
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java328
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java144
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java54
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java76
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java44
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java77
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java142
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java370
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java71
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java149
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java266
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java204
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RPANCommentStreamRecyclerViewAdapter.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java231
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java228
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java22
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/apis/Strapi.java48
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java29
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostTypeBottomSheetFragment.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectOrCaptureImageBottomSheetFragment.java52
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/WallpaperChangeReceiver.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/customviews/LinearLayoutManagerBugFixed.java25
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MarkwonLinearLayoutManager.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/customviews/ViewPagerBugFixed.java37
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeDefaultLinkPostLayoutEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeRememberMutingOptionInPostFeedEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/events/SubmitGalleryPostEvent.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/events/ToggleSecureModeEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java74
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java25
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java189
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java64
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java175
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java40
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java159
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java66
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java25
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/SubmitPost.java34
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/services/MaterialYouService.java55
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java93
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/AcknowledgementFragment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostDetailsPreferenceFragment.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/TranslationFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java58
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/NotificationUtils.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/UploadImageUtils.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java25
108 files changed, 5090 insertions, 1559 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index fe68ecd4..2fc08bd9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -27,6 +27,7 @@ import ml.docilealligator.infinityforreddit.activities.MainActivity;
import ml.docilealligator.infinityforreddit.activities.MultiredditSelectionActivity;
import ml.docilealligator.infinityforreddit.activities.PostFilterPreferenceActivity;
import ml.docilealligator.infinityforreddit.activities.PostFilterUsageListingActivity;
+import ml.docilealligator.infinityforreddit.activities.PostGalleryActivity;
import ml.docilealligator.infinityforreddit.activities.PostImageActivity;
import ml.docilealligator.infinityforreddit.activities.PostLinkActivity;
import ml.docilealligator.infinityforreddit.activities.PostTextActivity;
@@ -47,6 +48,7 @@ import ml.docilealligator.infinityforreddit.activities.SubredditMultiselectionAc
import ml.docilealligator.infinityforreddit.activities.SubredditSelectionActivity;
import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity;
import ml.docilealligator.infinityforreddit.activities.SuicidePreventionActivity;
+import ml.docilealligator.infinityforreddit.activities.TrendingActivity;
import ml.docilealligator.infinityforreddit.activities.ViewImageOrGifActivity;
import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity;
import ml.docilealligator.infinityforreddit.activities.ViewMultiRedditDetailActivity;
@@ -57,6 +59,7 @@ import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivi
import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.activities.ViewVideoActivity;
import ml.docilealligator.infinityforreddit.activities.WebViewActivity;
+import ml.docilealligator.infinityforreddit.activities.WikiActivity;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
import ml.docilealligator.infinityforreddit.fragments.CommentsListingFragment;
import ml.docilealligator.infinityforreddit.fragments.FollowedUsersListingFragment;
@@ -275,4 +278,12 @@ public interface AppComponent {
void inject(RPANActivity rpanActivity);
void inject(ViewRPANBroadcastFragment viewRPANBroadcastFragment);
+
+ void inject(PostGalleryActivity postGalleryActivity);
+
+ void inject(TrendingActivity trendingActivity);
+
+ void inject(WikiActivity wikiActivity);
+
+ void inject(Infinity infinity);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
index 435969a0..49120eca 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
@@ -277,6 +277,12 @@ class AppModule {
}
@Provides
+ @Named("post_details")
+ SharedPreferences providePostDetailsSharedPreferences() {
+ return mApplication.getSharedPreferences(SharedPreferencesUtils.POST_DETAILS_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
+ }
+
+ @Provides
@Singleton
CustomThemeWrapper provideCustomThemeWrapper(@Named("light_theme") SharedPreferences lightThemeSharedPreferences,
@Named("dark_theme") SharedPreferences darkThemeSharedPreferences,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
index 1ea45d67..1c7c7649 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
@@ -1,10 +1,13 @@
package ml.docilealligator.infinityforreddit;
+import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.os.Bundle;
+import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -15,15 +18,26 @@ import com.livefront.bridge.Bridge;
import com.livefront.bridge.SavedStateHandler;
import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+
+import javax.inject.Inject;
+import javax.inject.Named;
import ml.docilealligator.infinityforreddit.broadcastreceivers.NetworkWifiStatusReceiver;
import ml.docilealligator.infinityforreddit.broadcastreceivers.WallpaperChangeReceiver;
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
+import ml.docilealligator.infinityforreddit.events.ToggleSecureModeEvent;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
public class Infinity extends Application implements LifecycleObserver {
private AppComponent mAppComponent;
private NetworkWifiStatusReceiver mNetworkWifiStatusReceiver;
+ //private boolean lock = false;
+ private boolean isSecureMode;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
@Override
public void onCreate() {
@@ -33,12 +47,16 @@ public class Infinity extends Application implements LifecycleObserver {
.appModule(new AppModule(this))
.build();
- //ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
+ mAppComponent.inject(this);
- /*registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
+ isSecureMode = mSharedPreferences.getBoolean(SharedPreferencesUtils.SECURE_MODE, false);
+
+ registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
- activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
+ if (isSecureMode) {
+ activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
+ }
}
@Override
@@ -48,7 +66,11 @@ public class Infinity extends Application implements LifecycleObserver {
@Override
public void onActivityResumed(@NonNull Activity activity) {
-
+ /*if (lock && !(activity instanceof LockScreenActivity)) {
+ lock = false;
+ Intent intent = new Intent(activity, LockScreenActivity.class);
+ activity.startActivity(intent);
+ }*/
}
@Override
@@ -70,7 +92,9 @@ public class Infinity extends Application implements LifecycleObserver {
public void onActivityDestroyed(@NonNull Activity activity) {
}
- });*/
+ });
+
+ //ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
Bridge.initialize(getApplicationContext(), new SavedStateHandler() {
@Override
@@ -86,6 +110,8 @@ public class Infinity extends Application implements LifecycleObserver {
EventBus.builder().addIndex(new EventBusIndex()).installDefaultEventBus();
+ EventBus.getDefault().register(this);
+
mNetworkWifiStatusReceiver =
new NetworkWifiStatusReceiver(() -> EventBus.getDefault().post(new ChangeNetworkStatusEvent(Utils.getConnectedNetwork(getApplicationContext()))));
registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
@@ -93,17 +119,22 @@ public class Infinity extends Application implements LifecycleObserver {
registerReceiver(new WallpaperChangeReceiver(), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
}
-// @OnLifecycleEvent(Lifecycle.Event.ON_START)
-// public void appInForeground(){
-// Toast.makeText(this, "Foreground", Toast.LENGTH_SHORT).show();
-// }
-//
-// @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
-// public void appInBackground(){
-// Toast.makeText(this, "Background", Toast.LENGTH_SHORT).show();
-// }
+ /*@OnLifecycleEvent(Lifecycle.Event.ON_START)
+ public void appInForeground() {
+ lock = true;
+ }
+
+ @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
+ public void appInBackground(){
+
+ }*/
public AppComponent getAppComponent() {
return mAppComponent;
}
+
+ @Subscribe
+ public void onToggleSecureModeEvent(ToggleSecureModeEvent secureModeEvent) {
+ isSecureMode = secureModeEvent.isSecureMode;
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RPANBroadcast.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RPANBroadcast.java
index 43b8ef55..d7c936c2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/RPANBroadcast.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RPANBroadcast.java
@@ -3,6 +3,8 @@ package ml.docilealligator.infinityforreddit;
import android.os.Parcel;
import android.os.Parcelable;
+import ml.docilealligator.infinityforreddit.utils.APIUtils;
+
public class RPANBroadcast implements Parcelable {
public int upvotes;
@@ -76,7 +78,8 @@ public class RPANBroadcast implements Parcelable {
parcel.writeParcelable(rpanStream, i);
}
- public static class RPANPost implements Parcelable{
+ public static class RPANPost implements Parcelable {
+ public String fullname;
public String title;
public String subredditName;
public String subredditIconUrl;
@@ -85,6 +88,7 @@ public class RPANBroadcast implements Parcelable {
public String voteState;
public double upvoteRatio;
public String postPermalink;
+ public String rpanUrl;
public boolean isNsfw;
public boolean isLocked;
public boolean isArchived;
@@ -92,10 +96,11 @@ public class RPANBroadcast implements Parcelable {
public String suggestedCommentSort;
public String liveCommentsWebsocketUrl;
- public RPANPost(String title, String subredditName, String subredditIconUrl, String username,
+ public RPANPost(String fullname, String title, String subredditName, String subredditIconUrl, String username,
int postScore, String voteState, double upvoteRatio, String postPermalink, String rpanUrl,
boolean isNsfw, boolean isLocked, boolean isArchived, boolean isSpoiler,
String suggestedCommentSort, String liveCommentsWebsocketUrl) {
+ this.fullname = fullname;
this.title = title;
this.subredditName = subredditName;
this.subredditIconUrl = subredditIconUrl;
@@ -103,7 +108,8 @@ public class RPANBroadcast implements Parcelable {
this.postScore = postScore;
this.voteState = voteState;
this.upvoteRatio = upvoteRatio;
- this.postPermalink = postPermalink;
+ this.postPermalink = APIUtils.API_BASE_URI + postPermalink;
+ this.rpanUrl = rpanUrl;
this.isNsfw = isNsfw;
this.isLocked = isLocked;
this.isArchived = isArchived;
@@ -113,6 +119,7 @@ public class RPANBroadcast implements Parcelable {
}
protected RPANPost(Parcel in) {
+ fullname = in.readString();
title = in.readString();
subredditName = in.readString();
subredditIconUrl = in.readString();
@@ -121,6 +128,7 @@ public class RPANBroadcast implements Parcelable {
voteState = in.readString();
upvoteRatio = in.readDouble();
postPermalink = in.readString();
+ rpanUrl = in.readString();
isNsfw = in.readByte() != 0;
isLocked = in.readByte() != 0;
isArchived = in.readByte() != 0;
@@ -148,6 +156,7 @@ public class RPANBroadcast implements Parcelable {
@Override
public void writeToParcel(Parcel parcel, int i) {
+ parcel.writeString(fullname);
parcel.writeString(title);
parcel.writeString(subredditName);
parcel.writeString(subredditIconUrl);
@@ -156,6 +165,7 @@ public class RPANBroadcast implements Parcelable {
parcel.writeString(voteState);
parcel.writeDouble(upvoteRatio);
parcel.writeString(postPermalink);
+ parcel.writeString(rpanUrl);
parcel.writeByte((byte) (isNsfw ? 1 : 0));
parcel.writeByte((byte) (isLocked ? 1 : 0));
parcel.writeByte((byte) (isArchived ? 1 : 0));
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditGalleryPayload.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditGalleryPayload.java
new file mode 100644
index 00000000..ef91d6d9
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditGalleryPayload.java
@@ -0,0 +1,96 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.util.ArrayList;
+
+public class RedditGalleryPayload {
+ @SerializedName("sr")
+ public String subredditName;
+ @SerializedName("submit_type")
+ public String submitType;
+ @SerializedName("api_type")
+ public String apiType = "json";
+ @SerializedName("show_error_list")
+ public boolean showErrorList = true;
+ public String title;
+ @SerializedName("spoiler")
+ public boolean isSpoiler;
+ @SerializedName("nsfw")
+ public boolean isNSFW;
+ public String kind = "self";
+ @SerializedName("original_content")
+ public boolean originalContent = false;
+ @SerializedName("post_to_twitter")
+ public boolean postToTwitter = false;
+ public boolean sendReplies;
+ @SerializedName("validate_on_submit")
+ public boolean validateOnSubmit = true;
+ @SerializedName("flair_id")
+ public String flairId;
+ @SerializedName("flair_text")
+ public String flairText;
+ public ArrayList<Item> items;
+
+ public RedditGalleryPayload(String subredditName, String submitType, String title,
+ boolean isSpoiler, boolean isNSFW, boolean sendReplies, Flair flair, ArrayList<Item> items) {
+ this.subredditName = subredditName;
+ this.submitType = submitType;
+ this.title = title;
+ this.isSpoiler = isSpoiler;
+ this.isNSFW = isNSFW;
+ this.sendReplies = sendReplies;
+ if (flair != null) {
+ flairId = flair.getId();
+ flairText = flair.getText();
+ }
+ this.items = items;
+ }
+
+ public static class Item implements Parcelable {
+ public String caption;
+ @SerializedName("outbound_url")
+ public String outboundUrl;
+ @SerializedName("media_id")
+ public String mediaId;
+
+ public Item(String caption, String outboundUrl, String mediaId) {
+ this.caption = caption;
+ this.outboundUrl = outboundUrl;
+ this.mediaId = mediaId;
+ }
+
+ protected Item(Parcel in) {
+ caption = in.readString();
+ outboundUrl = in.readString();
+ mediaId = in.readString();
+ }
+
+ public static final Creator<Item> CREATOR = new Creator<Item>() {
+ @Override
+ public Item createFromParcel(Parcel in) {
+ return new Item(in);
+ }
+
+ @Override
+ public Item[] newArray(int size) {
+ return new Item[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel parcel, int i) {
+ parcel.writeString(caption);
+ parcel.writeString(outboundUrl);
+ parcel.writeString(mediaId);
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/TrendingSearch.java b/app/src/main/java/ml/docilealligator/infinityforreddit/TrendingSearch.java
new file mode 100644
index 00000000..f0afc541
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/TrendingSearch.java
@@ -0,0 +1,54 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.ArrayList;
+
+import ml.docilealligator.infinityforreddit.post.Post;
+
+public class TrendingSearch implements Parcelable {
+ public String queryString;
+ public String displayString;
+ public String title;
+ public ArrayList<Post.Preview> previews;
+
+ public TrendingSearch(String queryString, String displayString, String title, ArrayList<Post.Preview> previews) {
+ this.queryString = queryString;
+ this.displayString = displayString;
+ this.title = title;
+ this.previews = previews;
+ }
+
+ protected TrendingSearch(Parcel in) {
+ queryString = in.readString();
+ displayString = in.readString();
+ title = in.readString();
+ previews = in.createTypedArrayList(Post.Preview.CREATOR);
+ }
+
+ public static final Creator<TrendingSearch> CREATOR = new Creator<TrendingSearch>() {
+ @Override
+ public TrendingSearch createFromParcel(Parcel in) {
+ return new TrendingSearch(in);
+ }
+
+ @Override
+ public TrendingSearch[] newArray(int size) {
+ return new TrendingSearch[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel parcel, int i) {
+ parcel.writeString(queryString);
+ parcel.writeString(displayString);
+ parcel.writeString(title);
+ parcel.writeTypedList(previews);
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
index a7e675b2..a244fafe 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
@@ -4,7 +4,6 @@ import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -26,10 +25,8 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.FileProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
-import com.bumptech.glide.Glide;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
@@ -37,13 +34,10 @@ import com.google.android.material.snackbar.Snackbar;
import org.commonmark.ext.gfm.tables.TableBlock;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
-import org.json.JSONException;
-import org.xmlpull.v1.XmlPullParserException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import javax.inject.Inject;
@@ -71,9 +65,9 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesB
import ml.docilealligator.infinityforreddit.comment.Comment;
import ml.docilealligator.infinityforreddit.comment.SendComment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
-import ml.docilealligator.infinityforreddit.utils.UploadImageUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
import retrofit2.Retrofit;
@@ -91,6 +85,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
public static final int WRITE_COMMENT_REQUEST_CODE = 1;
private static final int PICK_IMAGE_REQUEST_CODE = 100;
private static final int CAPTURE_IMAGE_REQUEST_CODE = 200;
+ private static final int MARKDOWN_PREVIEW_REQUEST_CODE = 300;
private static final String UPLOADED_IMAGES_STATE = "UIS";
@BindView(R.id.coordinator_layout_comment_activity)
@@ -134,6 +129,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
private int markdownColor;
private Uri capturedImageUri;
private ArrayList<UploadedImage> uploadedImages = new ArrayList<>();
+ private Menu mMenu;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -245,7 +241,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
.tableLayout(R.layout.adapter_table_block, R.id.table_layout)
.textLayoutIsRoot(R.layout.view_table_entry_cell)))
.build();
- contentMarkdownRecyclerView.setLayoutManager(new LinearLayoutManager(this));
+ contentMarkdownRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this));
contentMarkdownRecyclerView.setAdapter(markwonAdapter);
markwonAdapter.setMarkdown(postBodyMarkwon, parentBodyMarkdown);
markwonAdapter.notifyDataSetChanged();
@@ -284,8 +280,8 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
}
});
- markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManager(this,
- LinearLayoutManager.HORIZONTAL, false));
+ markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this,
+ LinearLayoutManagerBugFixed.HORIZONTAL, false));
markdownBottomBarRecyclerView.setAdapter(adapter);
commentEditText.requestFocus();
@@ -335,6 +331,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.comment_activity, menu);
+ mMenu = menu;
applyMenuItemTheme(menu);
return true;
}
@@ -348,59 +345,70 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
} else if (itemId == R.id.action_preview_comment_activity) {
Intent intent = new Intent(this, FullMarkdownActivity.class);
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, commentEditText.getText().toString());
- startActivity(intent);
+ intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true);
+ startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE);
} else if (itemId == R.id.action_send_comment_activity) {
- if (!isSubmitting) {
- isSubmitting = true;
- if (commentEditText.getText() == null || commentEditText.getText().toString().equals("")) {
- isSubmitting = false;
- Snackbar.make(coordinatorLayout, R.string.comment_content_required, Snackbar.LENGTH_SHORT).show();
- return true;
- }
+ sendComment(item);
+ return true;
+ }
+
+ return false;
+ }
+
+ public void sendComment(@Nullable MenuItem item) {
+ if (!isSubmitting) {
+ isSubmitting = true;
+ if (commentEditText.getText() == null || commentEditText.getText().toString().equals("")) {
+ isSubmitting = false;
+ Snackbar.make(coordinatorLayout, R.string.comment_content_required, Snackbar.LENGTH_SHORT).show();
+ return;
+ }
+ if (item != null) {
item.setEnabled(false);
item.getIcon().setAlpha(130);
- Snackbar sendingSnackbar = Snackbar.make(coordinatorLayout, R.string.sending_comment, Snackbar.LENGTH_INDEFINITE);
- sendingSnackbar.show();
-
- SendComment.sendComment(mExecutor, new Handler(), commentEditText.getText().toString(),
- parentFullname, parentDepth, mOauthRetrofit, mAccessToken,
- new SendComment.SendCommentListener() {
- @Override
- public void sendCommentSuccess(Comment comment) {
- isSubmitting = false;
+ }
+ Snackbar sendingSnackbar = Snackbar.make(coordinatorLayout, R.string.sending_comment, Snackbar.LENGTH_INDEFINITE);
+ sendingSnackbar.show();
+
+ SendComment.sendComment(mExecutor, new Handler(), commentEditText.getText().toString(),
+ parentFullname, parentDepth, mOauthRetrofit, mAccessToken,
+ new SendComment.SendCommentListener() {
+ @Override
+ public void sendCommentSuccess(Comment comment) {
+ isSubmitting = false;
+ if (item != null) {
item.setEnabled(true);
item.getIcon().setAlpha(255);
- Toast.makeText(CommentActivity.this, R.string.send_comment_success, Toast.LENGTH_SHORT).show();
- Intent returnIntent = new Intent();
- returnIntent.putExtra(RETURN_EXTRA_COMMENT_DATA_KEY, comment);
- returnIntent.putExtra(EXTRA_PARENT_FULLNAME_KEY, parentFullname);
- if (isReplying) {
- returnIntent.putExtra(EXTRA_PARENT_POSITION_KEY, parentPosition);
- }
- setResult(RESULT_OK, returnIntent);
- finish();
}
+ Toast.makeText(CommentActivity.this, R.string.send_comment_success, Toast.LENGTH_SHORT).show();
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(RETURN_EXTRA_COMMENT_DATA_KEY, comment);
+ returnIntent.putExtra(EXTRA_PARENT_FULLNAME_KEY, parentFullname);
+ if (isReplying) {
+ returnIntent.putExtra(EXTRA_PARENT_POSITION_KEY, parentPosition);
+ }
+ setResult(RESULT_OK, returnIntent);
+ finish();
+ }
- @Override
- public void sendCommentFailed(@Nullable String errorMessage) {
- isSubmitting = false;
- sendingSnackbar.dismiss();
+ @Override
+ public void sendCommentFailed(@Nullable String errorMessage) {
+ isSubmitting = false;
+ sendingSnackbar.dismiss();
+ if (item != null) {
item.setEnabled(true);
item.getIcon().setAlpha(255);
+ }
- if (errorMessage == null || !errorMessage.equals("")) {
- Snackbar.make(coordinatorLayout, R.string.send_comment_failed, Snackbar.LENGTH_SHORT).show();
- } else {
- Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_SHORT).show();
- }
+ if (errorMessage == null || !errorMessage.equals("")) {
+ Snackbar.make(coordinatorLayout, R.string.send_comment_failed, Snackbar.LENGTH_SHORT).show();
+ } else {
+ Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_SHORT).show();
}
- });
- }
- return true;
+ }
+ });
}
-
- return false;
}
private void promptAlertDialog(int titleResId, int messageResId) {
@@ -427,45 +435,12 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
mAccessToken, commentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
+ } else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
+ sendComment(mMenu == null ? null : mMenu.findItem(R.id.action_send_comment_activity));
}
}
}
- private void uploadImageToReddit(Uri imageUri) {
- Toast.makeText(this, R.string.uploading_image, Toast.LENGTH_SHORT).show();
- Handler handler = new Handler();
- mExecutor.execute(() -> {
- try {
- Bitmap bitmap = Glide.with(CommentActivity.this).asBitmap().load(imageUri).submit().get();
- String imageUrlOrError = UploadImageUtils.uploadImage(mOauthRetrofit, mUploadMediaRetrofit, mAccessToken, bitmap);
- handler.post(() -> {
- if (imageUrlOrError != null && !imageUrlOrError.startsWith("Error: ")) {
- String fileName = Utils.getFileName(this, imageUri);
- if (fileName == null) {
- fileName = imageUrlOrError;
- }
- uploadedImages.add(new UploadedImage(fileName, imageUrlOrError));
-
- int start = Math.max(commentEditText.getSelectionStart(), 0);
- int end = Math.max(commentEditText.getSelectionEnd(), 0);
- commentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
- "[" + fileName + "](" + imageUrlOrError + ")",
- 0, "[]()".length() + fileName.length() + imageUrlOrError.length());
- Snackbar.make(coordinatorLayout, R.string.upload_image_success, Snackbar.LENGTH_LONG).show();
- } else {
- Toast.makeText(CommentActivity.this, R.string.upload_image_failed, Toast.LENGTH_LONG).show();
- }
- });
- } catch (ExecutionException | InterruptedException e) {
- e.printStackTrace();
- handler.post(() -> Toast.makeText(CommentActivity.this, R.string.get_image_bitmap_failed, Toast.LENGTH_LONG).show());
- } catch (XmlPullParserException | JSONException | IOException e) {
- e.printStackTrace();
- handler.post(() -> Toast.makeText(CommentActivity.this, R.string.error_processing_image, Toast.LENGTH_LONG).show());
- }
- });
- }
-
@Override
public void onBackPressed() {
if (isSubmitting) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java
index 9f9207e5..144898bb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java
@@ -1,5 +1,7 @@
package ml.docilealligator.infinityforreddit.activities;
+import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
+
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
@@ -17,7 +19,6 @@ import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat;
import androidx.lifecycle.ViewModelProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
@@ -37,6 +38,9 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.adapters.CustomThemeListingRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.asynctasks.ChangeThemeName;
import ml.docilealligator.infinityforreddit.asynctasks.DeleteTheme;
@@ -48,13 +52,8 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomTheme;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeViewModel;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.events.RecreateActivityEvent;
-import ml.docilealligator.infinityforreddit.Infinity;
-import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils;
-import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
-
public class CustomThemeListingActivity extends BaseActivity implements
CustomThemeOptionsBottomSheetFragment.CustomThemeOptionsBottomSheetFragmentListener,
CreateThemeBottomSheetFragment.SelectBaseThemeBottomSheetFragmentListener {
@@ -110,7 +109,6 @@ public class CustomThemeListingActivity extends BaseActivity implements
CustomThemeListingRecyclerViewAdapter adapter = new CustomThemeListingRecyclerViewAdapter(this,
CustomThemeWrapper.getPredefinedThemes(this));
recyclerView.setAdapter(adapter);
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java
index dbd40c31..e3d232e6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java
@@ -1,5 +1,10 @@
package ml.docilealligator.infinityforreddit.activities;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
+
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
@@ -43,22 +48,18 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customtheme.CustomTheme;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeSettingsItem;
+import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed;
import ml.docilealligator.infinityforreddit.font.ContentFontStyle;
import ml.docilealligator.infinityforreddit.font.FontStyle;
import ml.docilealligator.infinityforreddit.font.TitleFontStyle;
import ml.docilealligator.infinityforreddit.fragments.ThemePreviewCommentsFragment;
import ml.docilealligator.infinityforreddit.fragments.ThemePreviewPostsFragment;
-import ml.docilealligator.infinityforreddit.Infinity;
-import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
-
public class CustomThemePreviewActivity extends AppCompatActivity {
public static final String EXTRA_CUSTOM_THEME_SETTINGS_ITEMS = "ECTSI";
@@ -66,7 +67,7 @@ public class CustomThemePreviewActivity extends AppCompatActivity {
@BindView(R.id.coordinator_layout_theme_preview_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.view_pager_theme_preview_activity)
- ViewPager viewPager;
+ ViewPagerBugFixed viewPager;
@BindView(R.id.appbar_layout_theme_preview_activity)
AppBarLayout appBarLayout;
@BindView(R.id.collapsing_toolbar_layout_theme_preview_activity)
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java
index fc238c34..989eb34f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java
@@ -12,7 +12,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
@@ -104,8 +103,6 @@ public class CustomizeThemeActivity extends BaseActivity {
setTitle(R.string.customize_theme_activity_create_theme_label);
}
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
-
if (savedInstanceState != null) {
customThemeSettingsItems = savedInstanceState.getParcelableArrayList(CUSTOM_THEME_SETTINGS_ITEMS_STATE);
themeName = savedInstanceState.getString(THEME_NAME_STATE);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java
index 8ebb0015..e46f581b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java
@@ -50,6 +50,7 @@ import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerVi
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.utils.APIUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@@ -69,6 +70,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
private static final int PICK_IMAGE_REQUEST_CODE = 100;
private static final int CAPTURE_IMAGE_REQUEST_CODE = 200;
+ private static final int MARKDOWN_PREVIEW_REQUEST_CODE = 300;
private static final String UPLOADED_IMAGES_STATE = "UIS";
@@ -157,7 +159,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
}
});
- markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManager(this,
+ markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this,
LinearLayoutManager.HORIZONTAL, false));
markdownBottomBarRecyclerView.setAdapter(adapter);
@@ -206,47 +208,10 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
if (item.getItemId() == R.id.action_preview_edit_comment_activity) {
Intent intent = new Intent(this, FullMarkdownActivity.class);
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString());
- startActivity(intent);
+ intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true);
+ startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE);
} else if (item.getItemId() == R.id.action_send_edit_comment_activity) {
- if (!isSubmitting) {
- isSubmitting = true;
-
- Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_SHORT).show();
-
- String content = contentEditText.getText().toString();
-
- Map<String, String> params = new HashMap<>();
- params.put(APIUtils.THING_ID_KEY, mFullName);
- params.put(APIUtils.TEXT_KEY, content);
-
- mOauthRetrofit.create(RedditAPI.class)
- .editPostOrComment(APIUtils.getOAuthHeader(mAccessToken), params)
- .enqueue(new Callback<String>() {
- @Override
- public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
- isSubmitting = false;
- if (response.isSuccessful()) {
- Toast.makeText(EditCommentActivity.this, R.string.edit_success, Toast.LENGTH_SHORT).show();
-
- Intent returnIntent = new Intent();
- returnIntent.putExtra(EXTRA_EDITED_COMMENT_CONTENT, Utils.modifyMarkdown(content));
- returnIntent.putExtra(EXTRA_EDITED_COMMENT_POSITION, getIntent().getExtras().getInt(EXTRA_POSITION));
- setResult(RESULT_OK, returnIntent);
-
- finish();
- } else {
- Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
- }
- }
-
- @Override
- public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
- isSubmitting = false;
- Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
- }
- });
-
- }
+ editComment();
return true;
} else if (item.getItemId() == android.R.id.home) {
onBackPressed();
@@ -255,11 +220,53 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
return false;
}
+ private void editComment() {
+ if (!isSubmitting) {
+ isSubmitting = true;
+
+ Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_SHORT).show();
+
+ String content = contentEditText.getText().toString();
+
+ Map<String, String> params = new HashMap<>();
+ params.put(APIUtils.THING_ID_KEY, mFullName);
+ params.put(APIUtils.TEXT_KEY, content);
+
+ mOauthRetrofit.create(RedditAPI.class)
+ .editPostOrComment(APIUtils.getOAuthHeader(mAccessToken), params)
+ .enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ isSubmitting = false;
+ if (response.isSuccessful()) {
+ Toast.makeText(EditCommentActivity.this, R.string.edit_success, Toast.LENGTH_SHORT).show();
+
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(EXTRA_EDITED_COMMENT_CONTENT, Utils.modifyMarkdown(content));
+ returnIntent.putExtra(EXTRA_EDITED_COMMENT_POSITION, getIntent().getExtras().getInt(EXTRA_POSITION));
+ setResult(RESULT_OK, returnIntent);
+
+ finish();
+ } else {
+ Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ isSubmitting = false;
+ Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
+ }
+ });
+
+ }
+ }
+
private void promptAlertDialog(int titleResId, int messageResId) {
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(titleResId)
.setMessage(messageResId)
- .setPositiveButton(R.string.yes, (dialogInterface, i)
+ .setPositiveButton(R.string.discard_dialog_button, (dialogInterface, i)
-> finish())
.setNegativeButton(R.string.no, null)
.show();
@@ -279,6 +286,8 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
+ } else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
+ editComment();
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java
index 50574e15..21e1418d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java
@@ -22,7 +22,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.FileProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
@@ -53,6 +52,7 @@ import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerVi
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.utils.APIUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@@ -70,6 +70,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
private static final int PICK_IMAGE_REQUEST_CODE = 100;
private static final int CAPTURE_IMAGE_REQUEST_CODE = 200;
+ private static final int MARKDOWN_PREVIEW_REQUEST_CODE = 300;
private static final String UPLOADED_IMAGES_STATE = "UIS";
@@ -167,8 +168,8 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
}
});
- markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManager(this,
- LinearLayoutManager.HORIZONTAL, false));
+ markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this,
+ LinearLayoutManagerBugFixed.HORIZONTAL, false));
markdownBottomBarRecyclerView.setAdapter(adapter);
contentEditText.requestFocus();
@@ -218,37 +219,10 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
if (item.getItemId() == R.id.action_preview_edit_post_activity) {
Intent intent = new Intent(this, FullMarkdownActivity.class);
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString());
- startActivity(intent);
+ intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true);
+ startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE);
} else if (item.getItemId() == R.id.action_send_edit_post_activity) {
- if (!isSubmitting) {
- isSubmitting = true;
-
- Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_SHORT).show();
-
- Map<String, String> params = new HashMap<>();
- params.put(APIUtils.THING_ID_KEY, mFullName);
- params.put(APIUtils.TEXT_KEY, contentEditText.getText().toString());
-
- mOauthRetrofit.create(RedditAPI.class)
- .editPostOrComment(APIUtils.getOAuthHeader(mAccessToken), params)
- .enqueue(new Callback<String>() {
- @Override
- public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
- isSubmitting = false;
- Toast.makeText(EditPostActivity.this, R.string.edit_success, Toast.LENGTH_SHORT).show();
- Intent returnIntent = new Intent();
- setResult(RESULT_OK, returnIntent);
- finish();
- }
-
- @Override
- public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
- isSubmitting = false;
- Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
- }
- });
-
- }
+ editPost();
return true;
} else if (item.getItemId() == android.R.id.home) {
onBackPressed();
@@ -257,6 +231,38 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
return false;
}
+ private void editPost() {
+ if (!isSubmitting) {
+ isSubmitting = true;
+
+ Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_SHORT).show();
+
+ Map<String, String> params = new HashMap<>();
+ params.put(APIUtils.THING_ID_KEY, mFullName);
+ params.put(APIUtils.TEXT_KEY, contentEditText.getText().toString());
+
+ mOauthRetrofit.create(RedditAPI.class)
+ .editPostOrComment(APIUtils.getOAuthHeader(mAccessToken), params)
+ .enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ isSubmitting = false;
+ Toast.makeText(EditPostActivity.this, R.string.edit_success, Toast.LENGTH_SHORT).show();
+ Intent returnIntent = new Intent();
+ setResult(RESULT_OK, returnIntent);
+ finish();
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ isSubmitting = false;
+ Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
+ }
+ });
+
+ }
+ }
+
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -271,6 +277,8 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
+ } else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
+ editPost();
}
}
}
@@ -285,7 +293,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(titleResId)
.setMessage(messageResId)
- .setPositiveButton(R.string.yes, (dialogInterface, i)
+ .setPositiveButton(R.string.discard_dialog_button, (dialogInterface, i)
-> finish())
.setNegativeButton(R.string.no, null)
.show();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java
index e14e8499..4d2ff01f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java
@@ -62,6 +62,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
public static final String EXTRA_NAME = "ESN";
public static final String EXTRA_QUERY = "EQ";
+ public static final String EXTRA_TRENDING_SOURCE = "ETS";
public static final String EXTRA_FILTER = "EF";
public static final String EXTRA_CONTAIN_FLAIR = "ECF";
public static final String EXTRA_POST_TYPE = "EPT";
@@ -312,6 +313,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
} else if (postType == PostDataSource.TYPE_SEARCH) {
bundle.putString(PostFragment.EXTRA_NAME, name);
bundle.putString(PostFragment.EXTRA_QUERY, getIntent().getStringExtra(EXTRA_QUERY));
+ bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
}
mFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();
@@ -359,81 +361,81 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- finish();
- return true;
- case R.id.action_sort_filtered_thing_activity:
- switch (postType) {
- case PostDataSource.TYPE_FRONT_PAGE:
- SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
- Bundle bestBundle = new Bundle();
- bestBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, false);
- bestSortTypeBottomSheetFragment.setArguments(bestBundle);
- bestSortTypeBottomSheetFragment.show(getSupportFragmentManager(), bestSortTypeBottomSheetFragment.getTag());
- break;
- case PostDataSource.TYPE_SEARCH:
- SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = new SearchPostSortTypeBottomSheetFragment();
- Bundle searchBundle = new Bundle();
- searchPostSortTypeBottomSheetFragment.setArguments(searchBundle);
- searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag());
- break;
- case PostDataSource.TYPE_SUBREDDIT:
- if (name.equals("popular") || name.equals("all")) {
- SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
- Bundle popularBundle = new Bundle();
- popularBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
- popularAndAllSortTypeBottomSheetFragment.setArguments(popularBundle);
- popularAndAllSortTypeBottomSheetFragment.show(getSupportFragmentManager(), popularAndAllSortTypeBottomSheetFragment.getTag());
- } else {
- SortTypeBottomSheetFragment subredditSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
- Bundle subredditSheetBundle = new Bundle();
- subredditSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
- subredditSortTypeBottomSheetFragment.setArguments(subredditSheetBundle);
- subredditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), subredditSortTypeBottomSheetFragment.getTag());
- }
- break;
- case PostDataSource.TYPE_MULTI_REDDIT:
- SortTypeBottomSheetFragment multiRedditSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
- Bundle multiRedditBundle = new Bundle();
- multiRedditBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
- multiRedditSortTypeBottomSheetFragment.setArguments(multiRedditBundle);
- multiRedditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), multiRedditSortTypeBottomSheetFragment.getTag());
- break;
- case PostDataSource.TYPE_USER:
- UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment();
- userThingSortTypeBottomSheetFragment.show(getSupportFragmentManager(), userThingSortTypeBottomSheetFragment.getTag());
- }
- return true;
- case R.id.action_refresh_filtered_thing_activity:
- if (mMenu != null) {
- mMenu.findItem(R.id.action_lazy_mode_filtered_thing_activity).setTitle(R.string.action_start_lazy_mode);
- }
- if (mFragment instanceof FragmentCommunicator) {
- ((FragmentCommunicator) mFragment).refresh();
- }
- return true;
- case R.id.action_lazy_mode_filtered_thing_activity:
- MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_filtered_thing_activity);
- if (isInLazyMode) {
- ((FragmentCommunicator) mFragment).stopLazyMode();
- isInLazyMode = false;
- lazyModeItem.setTitle(R.string.action_start_lazy_mode);
- params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
- collapsingToolbarLayout.setLayoutParams(params);
- } else {
- if (((FragmentCommunicator) mFragment).startLazyMode()) {
- isInLazyMode = true;
- lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
- params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
- collapsingToolbarLayout.setLayoutParams(params);
+ int itemId = item.getItemId();
+ if (itemId == android.R.id.home) {
+ finish();
+ return true;
+ } else if (itemId == R.id.action_sort_filtered_thing_activity) {
+ switch (postType) {
+ case PostDataSource.TYPE_FRONT_PAGE:
+ SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
+ Bundle bestBundle = new Bundle();
+ bestBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, false);
+ bestSortTypeBottomSheetFragment.setArguments(bestBundle);
+ bestSortTypeBottomSheetFragment.show(getSupportFragmentManager(), bestSortTypeBottomSheetFragment.getTag());
+ break;
+ case PostDataSource.TYPE_SEARCH:
+ SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = new SearchPostSortTypeBottomSheetFragment();
+ Bundle searchBundle = new Bundle();
+ searchPostSortTypeBottomSheetFragment.setArguments(searchBundle);
+ searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag());
+ break;
+ case PostDataSource.TYPE_SUBREDDIT:
+ if (name.equals("popular") || name.equals("all")) {
+ SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
+ Bundle popularBundle = new Bundle();
+ popularBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
+ popularAndAllSortTypeBottomSheetFragment.setArguments(popularBundle);
+ popularAndAllSortTypeBottomSheetFragment.show(getSupportFragmentManager(), popularAndAllSortTypeBottomSheetFragment.getTag());
+ } else {
+ SortTypeBottomSheetFragment subredditSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
+ Bundle subredditSheetBundle = new Bundle();
+ subredditSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
+ subredditSortTypeBottomSheetFragment.setArguments(subredditSheetBundle);
+ subredditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), subredditSortTypeBottomSheetFragment.getTag());
}
+ break;
+ case PostDataSource.TYPE_MULTI_REDDIT:
+ SortTypeBottomSheetFragment multiRedditSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
+ Bundle multiRedditBundle = new Bundle();
+ multiRedditBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
+ multiRedditSortTypeBottomSheetFragment.setArguments(multiRedditBundle);
+ multiRedditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), multiRedditSortTypeBottomSheetFragment.getTag());
+ break;
+ case PostDataSource.TYPE_USER:
+ UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment();
+ userThingSortTypeBottomSheetFragment.show(getSupportFragmentManager(), userThingSortTypeBottomSheetFragment.getTag());
+ }
+ return true;
+ } else if (itemId == R.id.action_refresh_filtered_thing_activity) {
+ if (mMenu != null) {
+ mMenu.findItem(R.id.action_lazy_mode_filtered_thing_activity).setTitle(R.string.action_start_lazy_mode);
+ }
+ if (mFragment != null) {
+ ((FragmentCommunicator) mFragment).refresh();
+ }
+ return true;
+ } else if (itemId == R.id.action_lazy_mode_filtered_thing_activity) {
+ MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_filtered_thing_activity);
+ if (isInLazyMode) {
+ ((FragmentCommunicator) mFragment).stopLazyMode();
+ isInLazyMode = false;
+ lazyModeItem.setTitle(R.string.action_start_lazy_mode);
+ params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
+ collapsingToolbarLayout.setLayoutParams(params);
+ } else {
+ if (((FragmentCommunicator) mFragment).startLazyMode()) {
+ isInLazyMode = true;
+ lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
+ params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
+ collapsingToolbarLayout.setLayoutParams(params);
}
- return true;
- case R.id.action_change_post_layout_filtered_post_activity:
- PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
- postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
- return true;
+ }
+ return true;
+ } else if (itemId == R.id.action_change_post_layout_filtered_post_activity) {
+ PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
+ postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
+ return true;
}
return false;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java
index 312fe6cd..9eb9fb86 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java
@@ -1,5 +1,6 @@
package ml.docilealligator.infinityforreddit.activities;
+import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
@@ -11,6 +12,7 @@ import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.text.util.Linkify;
+import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
@@ -20,15 +22,15 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
-import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.r0adkll.slidr.Slidr;
import com.r0adkll.slidr.model.SlidrInterface;
import org.commonmark.ext.gfm.tables.TableBlock;
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -51,20 +53,21 @@ import io.noties.markwon.recycler.table.TableEntryPlugin;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager;
+import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class FullMarkdownActivity extends BaseActivity {
public static final String EXTRA_COMMENT_MARKDOWN = "ECM";
public static final String EXTRA_IS_NSFW = "EIN";
+ public static final String EXTRA_SUBMIT_POST = "ESP";
@BindView(R.id.coordinator_layout_comment_full_markdown_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_comment_full_markdown_activity)
AppBarLayout appBarLayout;
- @BindView(R.id.collapsing_toolbar_layout_comment_full_markdown_activity)
- CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.toolbar_comment_full_markdown_activity)
Toolbar toolbar;
@BindView(R.id.content_markdown_view_comment_full_markdown_activity)
@@ -85,6 +88,8 @@ public class FullMarkdownActivity extends BaseActivity {
ButterKnife.bind(this);
+ EventBus.getDefault().register(this);
+
applyCustomTheme();
setSupportActionBar(toolbar);
@@ -112,7 +117,7 @@ public class FullMarkdownActivity extends BaseActivity {
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
adjustToolbar(toolbar);
- markdownRecyclerView.setPadding(0, 0, 0, getNavBarHeight());
+ markdownRecyclerView.setPadding(markdownRecyclerView.getPaddingLeft(), 0, markdownRecyclerView.getPaddingRight(), getNavBarHeight());
}
}
@@ -212,7 +217,7 @@ public class FullMarkdownActivity extends BaseActivity {
.tableLayout(R.layout.adapter_table_block, R.id.table_layout)
.textLayoutIsRoot(R.layout.view_table_entry_cell)))
.build();
- LinearLayoutManager linearLayoutManager = new MarkwonLinearLayoutManager(this, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
+ LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(this, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
@Override
public void onScrolledLeft() {
if (mSlidrInterface != null) {
@@ -234,10 +239,26 @@ public class FullMarkdownActivity extends BaseActivity {
}
@Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ if (getIntent().getBooleanExtra(EXTRA_SUBMIT_POST, false)) {
+ getMenuInflater().inflate(R.menu.full_markdown_activity, menu);
+ applyMenuItemTheme(menu);
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
+ } else if (item.getItemId() == R.id.action_send_full_markdown_activity) {
+ Intent returnIntent = new Intent();
+ setResult(Activity.RESULT_OK, returnIntent);
+ finish();
+ return true;
}
return false;
@@ -258,4 +279,17 @@ public class FullMarkdownActivity extends BaseActivity {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
}
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ EventBus.getDefault().unregister(this);
+ }
+
+ @Subscribe
+ public void onAccountSwitchEvent(SwitchAccountEvent event) {
+ if (!getClass().getName().equals(event.excludeActivityClassName)) {
+ finish();
+ }
+ }
} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java
index a3cc4cdb..98e1b604 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java
@@ -17,7 +17,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
@@ -39,6 +38,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.adapters.AwardRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.award.GiveAward;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
@@ -162,7 +162,7 @@ public class GiveAwardActivity extends BaseActivity {
.setNegativeButton(R.string.no, null)
.show();
});
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
+ recyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this));
recyclerView.setAdapter(adapter);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java
index 52ff2e14..2437103f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java
@@ -9,7 +9,6 @@ import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
@@ -21,15 +20,17 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
-import androidx.fragment.app.FragmentPagerAdapter;
-import androidx.viewpager.widget.ViewPager;
+import androidx.viewpager2.adapter.FragmentStateAdapter;
+import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
+import com.google.android.material.tabs.TabLayoutMediator;
import com.google.android.material.textfield.TextInputEditText;
import com.r0adkll.slidr.Slidr;
import com.r0adkll.slidr.model.SlidrInterface;
@@ -81,7 +82,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
@BindView(R.id.tab_layout_inbox_activity)
TabLayout tabLayout;
@BindView(R.id.view_pager_inbox_activity)
- ViewPager viewPager;
+ ViewPager2 viewPager2;
@BindView(R.id.fab_inbox_activity)
FloatingActionButton fab;
@Inject
@@ -101,6 +102,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
Executor mExecutor;
private SlidrInterface mSlidrInterface;
private SectionsPagerAdapter sectionsPagerAdapter;
+ private FragmentManager fragmentManager;
private String mAccessToken;
private String mAccountName;
private String mNewAccountName;
@@ -153,6 +155,8 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
setSupportActionBar(mToolbar);
setToolbarGoToTop(mToolbar);
+ fragmentManager = getSupportFragmentManager();
+
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
@@ -163,7 +167,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
}
getCurrentAccountAndFetchMessage(savedInstanceState);
- viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
+ viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
fab.show();
@@ -263,8 +267,8 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
}
private void bindView(Bundle savedInstanceState) {
- sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
- viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
+ sectionsPagerAdapter = new SectionsPagerAdapter(this);
+ viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
if (position == 0) {
@@ -274,12 +278,23 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
}
}
});
- viewPager.setAdapter(sectionsPagerAdapter);
- viewPager.setOffscreenPageLimit(2);
- tabLayout.setupWithViewPager(viewPager);
+ viewPager2.setAdapter(sectionsPagerAdapter);
+ viewPager2.setOffscreenPageLimit(2);
+ new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
+ switch (position) {
+ case 0:
+ tab.setText(R.string.notifications);
+ break;
+ case 1:
+ tab.setText(R.string.messages);
+ break;
+ }
+ }).attach();
if (savedInstanceState == null && getIntent().getBooleanExtra(EXTRA_VIEW_MESSAGE, false)) {
- viewPager.setCurrentItem(1);
+ viewPager2.setCurrentItem(1, false);
}
+
+ fixViewPager2Sensitivity(viewPager2);
}
@Override
@@ -389,17 +404,44 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
fab.hide();
}
- private class SectionsPagerAdapter extends FragmentPagerAdapter {
- private InboxFragment tab1;
- private InboxFragment tab2;
+ private class SectionsPagerAdapter extends FragmentStateAdapter {
- public SectionsPagerAdapter(@NonNull FragmentManager fm) {
- super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
+ SectionsPagerAdapter(FragmentActivity fa) {
+ super(fa);
+ }
+
+ @Nullable
+ private Fragment getCurrentFragment() {
+ if (viewPager2 == null || fragmentManager == null) {
+ return null;
+ }
+ return fragmentManager.findFragmentByTag("f" + viewPager2.getCurrentItem());
+ }
+
+ void refresh() {
+ InboxFragment fragment = (InboxFragment) getCurrentFragment();
+ if (fragment != null) {
+ fragment.refresh();
+ }
+ }
+
+ void goBackToTop() {
+ InboxFragment fragment = (InboxFragment) getCurrentFragment();
+ if (fragment != null) {
+ fragment.goBackToTop();
+ }
+ }
+
+ void readAllMessages() {
+ InboxFragment fragment = (InboxFragment) getCurrentFragment();
+ if (fragment != null) {
+ fragment.markAllMessagesRead();
+ }
}
@NonNull
@Override
- public Fragment getItem(int position) {
+ public Fragment createFragment(int position) {
if (position == 0) {
InboxFragment fragment = new InboxFragment();
Bundle bundle = new Bundle();
@@ -418,62 +460,8 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
}
@Override
- public int getCount() {
+ public int getItemCount() {
return 2;
}
-
- @Nullable
- @Override
- public CharSequence getPageTitle(int position) {
- if (position == 0) {
- return getString(R.string.notifications);
- }
-
- return getString(R.string.messages);
- }
-
- @NonNull
- @Override
- public Object instantiateItem(@NonNull ViewGroup container, int position) {
- Fragment fragment = (Fragment) super.instantiateItem(container, position);
- if (position == 0) {
- tab1 = (InboxFragment) fragment;
- } else if (position == 1) {
- tab2 = (InboxFragment) fragment;
- }
-
- return fragment;
- }
-
- void refresh() {
- if (viewPager.getCurrentItem() == 0) {
- if (tab1 != null) {
- tab1.refresh();
- }
- } else if (viewPager.getCurrentItem() == 1 && tab2 != null) {
- tab2.refresh();
- }
- }
-
- void goBackToTop() {
- if (viewPager.getCurrentItem() == 0) {
- if (tab1 != null) {
- tab1.goBackToTop();
- }
- } else if (viewPager.getCurrentItem() == 1) {
- if (tab2 != null) {
- tab2.goBackToTop();
- }
- }
- }
-
- void readAllMessages() {
- if (tab1 != null) {
- tab1.markAllMessagesRead();
- }
- if (tab2 != null) {
- tab2.markAllMessagesRead();
- }
- }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java
index 7f834f48..a6596edb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java
@@ -48,6 +48,8 @@ public class LinkResolverActivity extends AppCompatActivity {
private static final String IMGUR_GALLERY_PATTERN = "/gallery/\\w+/?";
private static final String IMGUR_ALBUM_PATTERN = "/(album|a)/\\w+/?";
private static final String IMGUR_IMAGE_PATTERN = "/\\w+/?";
+ private static final String RPAN_BROADCAST_PATTERN = "/rpan/r/[\\w-]+/\\w+/?\\w+/?";
+ private static final String WIKI_PATTERN = "/[rR]/[\\w-]+/(wiki|w)/?\\w+";
@Inject
@Named("default")
@@ -117,7 +119,19 @@ public class LinkResolverActivity extends AppCompatActivity {
List<String> segments = uri.getPathSegments();
if (authority != null) {
- if (authority.equals("v.redd.it")) {
+ if (authority.equals("reddit-uploaded-media.s3-accelerate.amazonaws.com")) {
+ String unescapedUrl = uri.toString().replace("%2F", "/");
+ int lastSlashIndex = unescapedUrl.lastIndexOf("/");
+ if (lastSlashIndex < 0 || lastSlashIndex == unescapedUrl.length() - 1) {
+ deepLinkError(uri);
+ return;
+ }
+ String id = unescapedUrl.substring(lastSlashIndex + 1);
+ Intent intent = new Intent(this, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, uri.toString());
+ intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, id + ".jpg");
+ startActivity(intent);
+ } else if (authority.equals("v.redd.it")) {
Intent intent = new Intent(this, ViewVideoActivity.class);
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_V_REDD_IT);
intent.putExtra(ViewVideoActivity.EXTRA_V_REDD_IT_URL, uri.toString());
@@ -158,6 +172,10 @@ public class LinkResolverActivity extends AppCompatActivity {
} else {
deepLinkError(uri);
}
+ } else if (path.matches(WIKI_PATTERN)) {
+ Intent intent = new Intent(this, WikiActivity.class);
+ intent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, segments.get(1));
+ startActivity(intent);
} else if (path.matches(SUBREDDIT_PATTERN)) {
Intent intent = new Intent(this, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3));
@@ -186,6 +204,10 @@ public class LinkResolverActivity extends AppCompatActivity {
intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
+ } else if (path.matches(RPAN_BROADCAST_PATTERN)) {
+ Intent intent = new Intent(this, RPANActivity.class);
+ intent.putExtra(RPANActivity.EXTRA_RPAN_BROADCAST_FULLNAME_OR_ID, path.substring(path.lastIndexOf('/') + 1));
+ startActivity(intent);
} else if (authority.equals("redd.it") && path.matches(REDD_IT_POST_PATTERN)) {
Intent intent = new Intent(this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1));
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java
index 8dc39275..3ba73440 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LockScreenActivity.java
@@ -1,5 +1,8 @@
package ml.docilealligator.infinityforreddit.activities;
+import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
+import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
+
import android.content.SharedPreferences;
import android.os.Bundle;
@@ -17,9 +20,6 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
-import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
-import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
-
public class LockScreenActivity extends BaseActivity {
@Inject
@@ -79,7 +79,5 @@ public class LockScreenActivity extends BaseActivity {
}
@Override
- public void onBackPressed() {
- moveTaskToBack(true);
- }
+ public void onBackPressed() { }
} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
index 4a2c945a..55522aa9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
@@ -1,5 +1,8 @@
package ml.docilealligator.infinityforreddit.activities;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
+
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -9,6 +12,8 @@ import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
+import android.text.Editable;
+import android.text.TextWatcher;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
@@ -36,7 +41,6 @@ import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
@@ -81,6 +85,8 @@ import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.account.AccountViewModel;
import ml.docilealligator.infinityforreddit.adapters.NavigationDrawerRecyclerViewAdapter;
+import ml.docilealligator.infinityforreddit.adapters.SubredditAutocompleteRecyclerViewAdapter;
+import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings;
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
import ml.docilealligator.infinityforreddit.asynctasks.SwitchToAnonymousMode;
@@ -91,6 +97,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.RandomBottomShe
import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTimeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.events.ChangeConfirmToExitEvent;
import ml.docilealligator.infinityforreddit.events.ChangeDisableSwipingBetweenTabsEvent;
import ml.docilealligator.infinityforreddit.events.ChangeLockBottomAppBarEvent;
@@ -106,21 +113,22 @@ import ml.docilealligator.infinityforreddit.multireddit.MultiRedditViewModel;
import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.post.PostDataSource;
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
+import ml.docilealligator.infinityforreddit.subreddit.ParseSubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditViewModel;
import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData;
import ml.docilealligator.infinityforreddit.user.FetchUserData;
import ml.docilealligator.infinityforreddit.user.UserData;
+import ml.docilealligator.infinityforreddit.utils.APIUtils;
import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
import retrofit2.Retrofit;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
-
public class MainActivity extends BaseActivity implements SortTypeSelectionCallback,
PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback,
ActivityToolbarInterface, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback,
@@ -754,6 +762,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} else if (stringId == R.string.multi_reddit) {
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true);
+ } else if (stringId == R.string.rpan) {
+ intent = new Intent(MainActivity.this, RPANActivity.class);
+ } else if (stringId == R.string.trending) {
+ intent = new Intent(MainActivity.this, TrendingActivity.class);
} else if (stringId == R.string.upvoted) {
intent = new Intent(MainActivity.this, AccountPostsActivity.class);
intent.putExtra(AccountPostsActivity.EXTRA_USER_WHERE, PostDataSource.USER_WHERE_UPVOTED);
@@ -835,7 +847,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
});
adapter.setInboxCount(inboxCount);
- navDrawerRecyclerView.setLayoutManager(new LinearLayoutManager(this));
+ navDrawerRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this));
navDrawerRecyclerView.setAdapter(adapter);
int tabCount = mMainActivityTabsSharedPreferences.getInt((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_COUNT, 3);
@@ -1216,6 +1228,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
case PostTypeBottomSheetFragment.TYPE_VIDEO:
intent = new Intent(MainActivity.this, PostVideoActivity.class);
startActivity(intent);
+ break;
+ case PostTypeBottomSheetFragment.TYPE_GALLERY:
+ intent = new Intent(MainActivity.this, PostGalleryActivity.class);
+ startActivity(intent);
}
}
@@ -1293,7 +1309,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
adapter.setShowAvatarOnTheRightInTheNavigationDrawer(event.showAvatarOnTheRightInTheNavigationDrawer);
int previousPosition = -1;
if (navDrawerRecyclerView.getLayoutManager() != null) {
- previousPosition = ((LinearLayoutManager) navDrawerRecyclerView.getLayoutManager()).findFirstVisibleItemPosition();
+ previousPosition = ((LinearLayoutManagerBugFixed) navDrawerRecyclerView.getLayoutManager()).findFirstVisibleItemPosition();
}
RecyclerView.LayoutManager layoutManager = navDrawerRecyclerView.getLayoutManager();
@@ -1373,7 +1389,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
private void goToSubreddit() {
- /*View rootView = getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, coordinatorLayout, false);
+ View rootView = getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, coordinatorLayout, false);
TextInputEditText thingEditText = rootView.findViewById(R.id.text_input_edit_text_go_to_thing_edit_text);
RecyclerView recyclerView = rootView.findViewById(R.id.recycler_view_go_to_thing_edit_text);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
@@ -1461,15 +1477,17 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
startActivity(subredditIntent);
})
- .setNegativeButton(R.string.cancel, null)
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
+ }
+ })
.setOnDismissListener(dialogInterface -> {
if (imm != null) {
imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
}
})
- .show();*/
- Intent intent = new Intent(this, RPANActivity.class);
- startActivity(intent);
+ .show();
}
private void goToUser() {
@@ -1504,7 +1522,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
startActivity(userIntent);
})
- .setNegativeButton(R.string.cancel, null)
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
+ }
+ })
.setOnDismissListener(dialogInterface -> {
if (imm != null) {
imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MotionTestActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MotionTestActivity.java
deleted file mode 100644
index ba8d0681..00000000
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MotionTestActivity.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package ml.docilealligator.infinityforreddit.activities;
-
-import android.os.Bundle;
-import android.util.Log;
-
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.constraintlayout.motion.widget.MotionLayout;
-
-import ml.docilealligator.infinityforreddit.R;
-
-public class MotionTestActivity extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_motion_test);
-
- MotionLayout motionLayout = findViewById(R.id.motion_layout);
- motionLayout.addTransitionListener(new MotionLayout.TransitionListener() {
- @Override
- public void onTransitionStarted(MotionLayout motionLayout, int i, int i1) {
- Log.i("asdfasdf", "start " + (i == R.id.start) + " " + (i1 == R.id.end));
- }
-
- @Override
- public void onTransitionChange(MotionLayout motionLayout, int i, int i1, float v) {
- Log.i("asdfasdf", "start " + (i == R.id.start) + " " + (i1 == R.id.end) + " " + v);
- }
-
- @Override
- public void onTransitionCompleted(MotionLayout motionLayout, int i) {
- Log.i("asdfasdf", "complete " + (i == R.id.start));
- }
-
- @Override
- public void onTransitionTrigger(MotionLayout motionLayout, int i, boolean b, float v) {
- Log.i("asdfasdf", "trigger " + (i == R.id.start) + " " + v + " " + b);
- }
- });
- }
-} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java
index e64bf21e..4ed7534d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java
@@ -36,6 +36,8 @@ import ml.docilealligator.infinityforreddit.postfilter.PostFilterViewModel;
public class PostFilterPreferenceActivity extends BaseActivity {
public static final String EXTRA_POST = "EP";
+ public static final String EXTRA_SUBREDDIT_NAME = "ESN";
+ public static final String EXTRA_USER_NAME = "EUN";
@BindView(R.id.coordinator_layout_post_filter_preference_activity)
CoordinatorLayout coordinatorLayout;
@@ -76,26 +78,36 @@ public class PostFilterPreferenceActivity extends BaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Post post = getIntent().getParcelableExtra(EXTRA_POST);
+ String subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
+ String username = getIntent().getStringExtra(EXTRA_USER_NAME);
fab.setOnClickListener(view -> {
- if (post == null) {
+ if (post != null) {
+ showPostFilterOptions(post, null);
+ } else if (subredditName != null) {
+ excludeSubredditInFilter(subredditName, null);
+ } else if (username != null) {
+ excludeUserInFilter(username, null);
+ } else {
Intent intent = new Intent(PostFilterPreferenceActivity.this, CustomizePostFilterActivity.class);
intent.putExtra(CustomizePostFilterActivity.EXTRA_FROM_SETTINGS, true);
startActivity(intent);
- } else {
- showPostFilterOptions(post, null);
}
});
adapter = new PostFilterRecyclerViewAdapter(postFilter -> {
- if (post == null) {
+ if (post != null) {
+ showPostFilterOptions(post, postFilter);
+ } else if (subredditName != null) {
+ excludeSubredditInFilter(subredditName, postFilter);
+ } else if (username != null) {
+ excludeUserInFilter(username, postFilter);
+ } else {
PostFilterOptionsBottomSheetFragment postFilterOptionsBottomSheetFragment = new PostFilterOptionsBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(PostFilterOptionsBottomSheetFragment.EXTRA_POST_FILTER, postFilter);
postFilterOptionsBottomSheetFragment.setArguments(bundle);
postFilterOptionsBottomSheetFragment.show(getSupportFragmentManager(), postFilterOptionsBottomSheetFragment.getTag());
- } else {
- showPostFilterOptions(post, postFilter);
}
});
@@ -145,6 +157,24 @@ public class PostFilterPreferenceActivity extends BaseActivity {
.show();
}
+ public void excludeSubredditInFilter(String subredditName, PostFilter postFilter) {
+ Intent intent = new Intent(this, CustomizePostFilterActivity.class);
+ intent.putExtra(CustomizePostFilterActivity.EXTRA_EXCLUDE_SUBREDDIT, subredditName);
+ if (postFilter != null) {
+ intent.putExtra(CustomizePostFilterActivity.EXTRA_POST_FILTER, postFilter);
+ }
+ startActivity(intent);
+ }
+
+ public void excludeUserInFilter(String username, PostFilter postFilter) {
+ Intent intent = new Intent(this, CustomizePostFilterActivity.class);
+ intent.putExtra(CustomizePostFilterActivity.EXTRA_EXCLUDE_USER, username);
+ if (postFilter != null) {
+ intent.putExtra(CustomizePostFilterActivity.EXTRA_POST_FILTER, postFilter);
+ }
+ startActivity(intent);
+ }
+
public void editPostFilter(PostFilter postFilter) {
Intent intent = new Intent(PostFilterPreferenceActivity.this, CustomizePostFilterActivity.class);
intent.putExtra(CustomizePostFilterActivity.EXTRA_POST_FILTER, postFilter);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java
new file mode 100644
index 00000000..8edb4516
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java
@@ -0,0 +1,709 @@
+package ml.docilealligator.infinityforreddit.activities;
+
+import android.content.ActivityNotFoundException;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Rect;
+import android.net.Uri;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.Handler;
+import android.provider.MediaStore;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.widget.Toolbar;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.core.content.ContextCompat;
+import androidx.core.content.FileProvider;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.RequestManager;
+import com.bumptech.glide.request.RequestOptions;
+import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.button.MaterialButton;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
+import com.google.android.material.snackbar.Snackbar;
+import com.google.android.material.switchmaterial.SwitchMaterial;
+import com.google.gson.Gson;
+import com.libRG.CustomTextView;
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executor;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
+import ml.docilealligator.infinityforreddit.Flair;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.RedditGalleryPayload;
+import ml.docilealligator.infinityforreddit.adapters.RedditGallerySubmissionRecyclerViewAdapter;
+import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon;
+import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.bottomsheetfragments.SelectOrCaptureImageBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.events.SubmitGalleryPostEvent;
+import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
+import ml.docilealligator.infinityforreddit.services.SubmitPostService;
+import ml.docilealligator.infinityforreddit.utils.JSONUtils;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.utils.UploadImageUtils;
+import ml.docilealligator.infinityforreddit.utils.Utils;
+import pl.droidsonroids.gif.GifImageView;
+import retrofit2.Retrofit;
+
+public class PostGalleryActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback {
+
+ static final String EXTRA_SUBREDDIT_NAME = "ESN";
+
+ private static final String SUBREDDIT_NAME_STATE = "SNS";
+ private static final String SUBREDDIT_ICON_STATE = "SIS";
+ private static final String SUBREDDIT_SELECTED_STATE = "SSS";
+ private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
+ private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS";
+ private static final String IS_POSTING_STATE = "IPS";
+ private static final String FLAIR_STATE = "FS";
+ private static final String IS_SPOILER_STATE = "ISS";
+ private static final String IS_NSFW_STATE = "INS";
+ private static final String REDDIT_GALLERY_IMAGE_INFO_STATE = "RGIIS";
+
+ private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
+ private static final int PICK_IMAGE_REQUEST_CODE = 1;
+ private static final int CAPTURE_IMAGE_REQUEST_CODE = 2;
+
+ @BindView(R.id.coordinator_layout_post_gallery_activity)
+ CoordinatorLayout coordinatorLayout;
+ @BindView(R.id.appbar_layout_post_gallery_activity)
+ AppBarLayout appBarLayout;
+ @BindView(R.id.toolbar_post_gallery_activity)
+ Toolbar toolbar;
+ @BindView(R.id.subreddit_icon_gif_image_view_post_gallery_activity)
+ GifImageView iconGifImageView;
+ @BindView(R.id.subreddit_name_text_view_post_gallery_activity)
+ TextView subredditNameTextView;
+ @BindView(R.id.rules_button_post_gallery_activity)
+ MaterialButton rulesButton;
+ @BindView(R.id.divider_1_post_gallery_activity)
+ View divider1;
+ @BindView(R.id.flair_custom_text_view_post_gallery_activity)
+ CustomTextView flairTextView;
+ @BindView(R.id.spoiler_custom_text_view_post_gallery_activity)
+ CustomTextView spoilerTextView;
+ @BindView(R.id.nsfw_custom_text_view_post_gallery_activity)
+ CustomTextView nsfwTextView;
+ @BindView(R.id.divider_2_post_gallery_activity)
+ View divider2;
+ @BindView(R.id.receive_post_reply_notifications_linear_layout_post_gallery_activity)
+ LinearLayout receivePostReplyNotificationsLinearLayout;
+ @BindView(R.id.receive_post_reply_notifications_text_view_post_gallery_activity)
+ TextView receivePostReplyNotificationsTextView;
+ @BindView(R.id.receive_post_reply_notifications_switch_material_post_gallery_activity)
+ SwitchMaterial receivePostReplyNotificationsSwitchMaterial;
+ @BindView(R.id.divider_3_post_gallery_activity)
+ View divider3;
+ @BindView(R.id.post_title_edit_text_post_gallery_activity)
+ EditText titleEditText;
+ @BindView(R.id.divider_4_post_gallery_activity)
+ View divider4;
+ @BindView(R.id.images_recycler_view_post_gallery_activity)
+ RecyclerView imagesRecyclerView;
+ @Inject
+ @Named("no_oauth")
+ Retrofit mRetrofit;
+ @Inject
+ @Named("oauth")
+ Retrofit mOauthRetrofit;
+ @Inject
+ @Named("upload_media")
+ Retrofit mUploadMediaRetrofit;
+ @Inject
+ RedditDataRoomDatabase mRedditDataRoomDatabase;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ @Inject
+ @Named("current_account")
+ SharedPreferences mCurrentAccountSharedPreferences;
+ @Inject
+ CustomThemeWrapper mCustomThemeWrapper;
+ @Inject
+ Executor mExecutor;
+ private ArrayList<RedditGallerySubmissionRecyclerViewAdapter.RedditGalleryImageInfo> redditGalleryImageInfoList;
+ private String mAccessToken;
+ private String mAccountName;
+ private String iconUrl;
+ private String subredditName;
+ private boolean subredditSelected = false;
+ private boolean subredditIsUser;
+ private boolean loadSubredditIconSuccessful = true;
+ private boolean isPosting;
+ private int primaryTextColor;
+ private int flairBackgroundColor;
+ private int flairTextColor;
+ private int spoilerBackgroundColor;
+ private int spoilerTextColor;
+ private int nsfwBackgroundColor;
+ private int nsfwTextColor;
+ private Flair flair;
+ private boolean isSpoiler = false;
+ private boolean isNSFW = false;
+ private Resources resources;
+ private Menu mMemu;
+ private RequestManager mGlide;
+ private FlairBottomSheetFragment flairSelectionBottomSheetFragment;
+ private Snackbar mPostingSnackbar;
+ private RedditGallerySubmissionRecyclerViewAdapter adapter;
+ private Uri imageUri;
+ private boolean isUploading;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
+ setImmersiveModeNotApplicable();
+
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_post_gallery);
+
+ ButterKnife.bind(this);
+
+ EventBus.getDefault().register(this);
+
+ applyCustomTheme();
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
+ addOnOffsetChangedListener(appBarLayout);
+ }
+
+ setSupportActionBar(toolbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
+ mGlide = Glide.with(this);
+
+ mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);
+
+ resources = getResources();
+
+ mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
+ mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
+
+ adapter = new RedditGallerySubmissionRecyclerViewAdapter(this, mCustomThemeWrapper, new RedditGallerySubmissionRecyclerViewAdapter.ItemClickListener() {
+ @Override
+ public void onAddImageClicked() {
+ if (!isUploading) {
+ SelectOrCaptureImageBottomSheetFragment fragment = new SelectOrCaptureImageBottomSheetFragment();
+ fragment.show(getSupportFragmentManager(), fragment.getTag());
+ } else {
+ Snackbar.make(coordinatorLayout, R.string.please_wait_image_is_uploading, Snackbar.LENGTH_SHORT).show();
+ }
+ }
+ });
+ imagesRecyclerView.setAdapter(adapter);
+ Resources resources = getResources();
+ int nColumns = resources.getBoolean(R.bool.isTablet) || resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 3 : 2;
+ ((GridLayoutManager) imagesRecyclerView.getLayoutManager()).setSpanCount(nColumns);
+ imagesRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
+ @Override
+ public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
+ GridLayoutManager.LayoutParams layoutParams = (GridLayoutManager.LayoutParams) view.getLayoutParams();
+
+ int spanIndex = layoutParams.getSpanIndex();
+
+ int offset = (int) (Utils.convertDpToPixel(16, PostGalleryActivity.this));
+ int halfOffset = offset / 2;
+
+ if (nColumns == 2) {
+ if (spanIndex == 0) {
+ outRect.set(halfOffset, 0, halfOffset, offset);
+ } else {
+ outRect.set(halfOffset, 0, halfOffset, offset);
+ }
+ } else if (nColumns == 3) {
+ if (spanIndex == 0) {
+ outRect.set(halfOffset, 0, halfOffset, offset);
+ } else if (spanIndex == 1) {
+ outRect.set(halfOffset, 0, halfOffset, offset);
+ } else {
+ outRect.set(halfOffset, 0, halfOffset, offset);
+ }
+ }
+ }
+ });
+
+ if (savedInstanceState != null) {
+ subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
+ iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
+ subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
+ subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
+ loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE);
+ isPosting = savedInstanceState.getBoolean(IS_POSTING_STATE);
+ flair = savedInstanceState.getParcelable(FLAIR_STATE);
+ isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE);
+ isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE);
+ redditGalleryImageInfoList = savedInstanceState.getParcelableArrayList(REDDIT_GALLERY_IMAGE_INFO_STATE);
+ if (redditGalleryImageInfoList != null && !redditGalleryImageInfoList.isEmpty()) {
+ if (redditGalleryImageInfoList.get(redditGalleryImageInfoList.size() - 1).payload == null) {
+ imageUri = Uri.parse(redditGalleryImageInfoList.get(redditGalleryImageInfoList.size() - 1).imageUrlString);
+ uploadImage();
+ }
+ }
+ adapter.setRedditGalleryImageInfoList(redditGalleryImageInfoList);
+
+ if (subredditName != null) {
+ subredditNameTextView.setTextColor(primaryTextColor);
+ subredditNameTextView.setText(subredditName);
+ flairTextView.setVisibility(View.VISIBLE);
+ if (!loadSubredditIconSuccessful) {
+ loadSubredditIcon();
+ }
+ }
+ displaySubredditIcon();
+
+ if (isPosting) {
+ mPostingSnackbar.show();
+ }
+
+ if (flair != null) {
+ flairTextView.setText(flair.getText());
+ flairTextView.setBackgroundColor(flairBackgroundColor);
+ flairTextView.setBorderColor(flairBackgroundColor);
+ flairTextView.setTextColor(flairTextColor);
+ }
+ if (isSpoiler) {
+ spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
+ spoilerTextView.setBorderColor(spoilerBackgroundColor);
+ spoilerTextView.setTextColor(spoilerTextColor);
+ }
+ if (isNSFW) {
+ nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
+ nsfwTextView.setBorderColor(nsfwBackgroundColor);
+ nsfwTextView.setTextColor(nsfwTextColor);
+ }
+ } else {
+ isPosting = false;
+
+ if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
+ loadSubredditIconSuccessful = false;
+ subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
+ subredditSelected = true;
+ subredditNameTextView.setTextColor(primaryTextColor);
+ subredditNameTextView.setText(subredditName);
+ flairTextView.setVisibility(View.VISIBLE);
+ loadSubredditIcon();
+ } else {
+ mGlide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(iconGifImageView);
+ }
+ }
+
+ iconGifImageView.setOnClickListener(view -> {
+ Intent intent = new Intent(this, SubredditSelectionActivity.class);
+ startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
+ });
+
+ subredditNameTextView.setOnClickListener(view -> {
+ Intent intent = new Intent(this, SubredditSelectionActivity.class);
+ startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
+ });
+
+ rulesButton.setOnClickListener(view -> {
+ if (subredditName == null) {
+ Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
+ } else {
+ Intent intent = new Intent(this, RulesActivity.class);
+ if (subredditIsUser) {
+ intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
+ } else {
+ intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ }
+ startActivity(intent);
+ }
+ });
+
+ flairTextView.setOnClickListener(view -> {
+ if (flair == null) {
+ flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
+ Bundle bundle = new Bundle();
+ bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
+ bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
+ flairSelectionBottomSheetFragment.setArguments(bundle);
+ flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
+ } else {
+ flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
+ flairTextView.setTextColor(primaryTextColor);
+ flairTextView.setText(getString(R.string.flair));
+ flair = null;
+ }
+ });
+
+ spoilerTextView.setOnClickListener(view -> {
+ if (!isSpoiler) {
+ spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
+ spoilerTextView.setBorderColor(spoilerBackgroundColor);
+ spoilerTextView.setTextColor(spoilerTextColor);
+ isSpoiler = true;
+ } else {
+ spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
+ spoilerTextView.setTextColor(primaryTextColor);
+ isSpoiler = false;
+ }
+ });
+
+ nsfwTextView.setOnClickListener(view -> {
+ if (!isNSFW) {
+ nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
+ nsfwTextView.setBorderColor(nsfwBackgroundColor);
+ nsfwTextView.setTextColor(nsfwTextColor);
+ isNSFW = true;
+ } else {
+ nsfwTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
+ nsfwTextView.setTextColor(primaryTextColor);
+ isNSFW = false;
+ }
+ });
+
+ receivePostReplyNotificationsLinearLayout.setOnClickListener(view -> {
+ receivePostReplyNotificationsSwitchMaterial.performClick();
+ });
+ }
+
+ @Override
+ protected SharedPreferences getDefaultSharedPreferences() {
+ return mSharedPreferences;
+ }
+
+ @Override
+ protected CustomThemeWrapper getCustomThemeWrapper() {
+ return mCustomThemeWrapper;
+ }
+
+ @Override
+ protected void applyCustomTheme() {
+ coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
+ applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
+ int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor();
+ subredditNameTextView.setTextColor(secondaryTextColor);
+ rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor());
+ rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
+ primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ receivePostReplyNotificationsTextView.setTextColor(primaryTextColor);
+ int dividerColor = mCustomThemeWrapper.getDividerColor();
+ divider1.setBackgroundColor(dividerColor);
+ divider2.setBackgroundColor(dividerColor);
+ divider3.setBackgroundColor(dividerColor);
+ divider4.setBackgroundColor(dividerColor);
+ flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor();
+ flairTextColor = mCustomThemeWrapper.getFlairTextColor();
+ spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor();
+ spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
+ nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
+ nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
+ flairTextView.setTextColor(primaryTextColor);
+ spoilerTextView.setTextColor(primaryTextColor);
+ nsfwTextView.setTextColor(primaryTextColor);
+ titleEditText.setTextColor(primaryTextColor);
+ titleEditText.setHintTextColor(secondaryTextColor);
+ }
+
+ public void selectImage() {
+ Intent intent = new Intent();
+ intent.setType("image/*");
+ intent.setAction(Intent.ACTION_GET_CONTENT);
+ startActivityForResult(Intent.createChooser(intent, resources.getString(R.string.select_from_gallery)), PICK_IMAGE_REQUEST_CODE);
+ }
+
+ public void captureImage() {
+ Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
+ try {
+ imageUri = FileProvider.getUriForFile(this, "ml.docilealligator.infinityforreddit.provider",
+ File.createTempFile("temp_img", ".jpg", getExternalFilesDir(Environment.DIRECTORY_PICTURES)));
+ pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
+ startActivityForResult(pictureIntent, CAPTURE_IMAGE_REQUEST_CODE);
+ } catch (IOException ex) {
+ Snackbar.make(coordinatorLayout, R.string.error_creating_temp_file, Snackbar.LENGTH_SHORT).show();
+ } catch (ActivityNotFoundException e) {
+ Snackbar.make(coordinatorLayout, R.string.no_camera_available, Snackbar.LENGTH_SHORT).show();
+ }
+ }
+
+ private void uploadImage() {
+ Handler handler = new Handler();
+ isUploading = true;
+ mExecutor.execute(() -> {
+ try {
+ Bitmap resource = Glide.with(PostGalleryActivity.this).asBitmap().load(imageUri).submit().get();
+ String response = UploadImageUtils.uploadImage(mOauthRetrofit, mUploadMediaRetrofit, mAccessToken, resource, true);
+ String mediaId = new JSONObject(response).getJSONObject(JSONUtils.ASSET_KEY).getString(JSONUtils.ASSET_ID_KEY);
+ handler.post(() -> {
+ adapter.setImageAsUploaded(mediaId);
+ isUploading = false;
+ });
+ } catch (ExecutionException | InterruptedException e) {
+ e.printStackTrace();
+ handler.post(() -> {
+ adapter.removeFailedToUploadImage();
+ Snackbar.make(coordinatorLayout, R.string.get_image_bitmap_failed, Snackbar.LENGTH_LONG).show();
+ isUploading = false;
+ });
+ } catch (XmlPullParserException | JSONException | IOException e) {
+ e.printStackTrace();
+ handler.post(() -> {
+ adapter.removeFailedToUploadImage();
+ Snackbar.make(coordinatorLayout, R.string.upload_image_failed, Snackbar.LENGTH_LONG).show();
+ isUploading = false;
+ });
+ }
+ });
+ }
+
+ private void displaySubredditIcon() {
+ if (iconUrl != null && !iconUrl.equals("")) {
+ mGlide.load(iconUrl)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .error(mGlide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
+ .into(iconGifImageView);
+ } else {
+ mGlide.load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(iconGifImageView);
+ }
+ }
+
+ private void loadSubredditIcon() {
+ LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mRetrofit, iconImageUrl -> {
+ iconUrl = iconImageUrl;
+ displaySubredditIcon();
+ loadSubredditIconSuccessful = true;
+ });
+ }
+
+ private void promptAlertDialog(int titleResId, int messageResId) {
+ new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
+ .setTitle(titleResId)
+ .setMessage(messageResId)
+ .setPositiveButton(R.string.discard_dialog_button, (dialogInterface, i)
+ -> finish())
+ .setNegativeButton(R.string.no, null)
+ .show();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.post_gallery_activity, menu);
+ applyMenuItemTheme(menu);
+ mMemu = menu;
+ if (isPosting) {
+ mMemu.findItem(R.id.action_send_post_gallery_activity).setEnabled(false);
+ mMemu.findItem(R.id.action_send_post_gallery_activity).getIcon().setAlpha(130);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ int itemId = item.getItemId();
+ if (itemId == android.R.id.home) {
+ if (isPosting) {
+ promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail);
+ return true;
+ } else {
+ if (!titleEditText.getText().toString().equals("") || redditGalleryImageInfoList != null) {
+ promptAlertDialog(R.string.discard, R.string.discard_detail);
+ return true;
+ }
+ }
+ finish();
+ return true;
+ } else if (itemId == R.id.action_send_post_gallery_activity) {
+ if (!subredditSelected) {
+ Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
+ return true;
+ }
+
+ if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
+ Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
+ return true;
+ }
+
+ if (redditGalleryImageInfoList == null || redditGalleryImageInfoList.isEmpty()) {
+ Snackbar.make(coordinatorLayout, R.string.select_an_image, Snackbar.LENGTH_SHORT).show();
+ return true;
+ }
+
+ if (redditGalleryImageInfoList.get(redditGalleryImageInfoList.size() - 1).payload == null) {
+ Snackbar.make(coordinatorLayout, R.string.please_wait_image_is_uploading, Snackbar.LENGTH_LONG).show();
+ return true;
+ }
+
+ isPosting = true;
+
+ item.setEnabled(false);
+ item.getIcon().setAlpha(130);
+
+ mPostingSnackbar.show();
+
+ String subredditName;
+ if (subredditIsUser) {
+ subredditName = "u_" + subredditNameTextView.getText().toString();
+ } else {
+ subredditName = subredditNameTextView.getText().toString();
+ }
+
+ Intent intent = new Intent(this, SubmitPostService.class);
+ intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
+ intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
+ intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_GALLERY);
+ ArrayList<RedditGalleryPayload.Item> items = new ArrayList<>();
+ for (RedditGallerySubmissionRecyclerViewAdapter.RedditGalleryImageInfo i : redditGalleryImageInfoList) {
+ items.add(i.payload);
+ }
+ RedditGalleryPayload payload = new RedditGalleryPayload(subredditName, subredditIsUser ? "profile" : "subreddit",
+ titleEditText.getText().toString(), isSpoiler, isNSFW, receivePostReplyNotificationsSwitchMaterial.isChecked(),
+ flair, items);
+ intent.putExtra(SubmitPostService.EXTRA_REDDIT_GALLERY_PAYLOAD, new Gson().toJson(payload));
+
+ ContextCompat.startForegroundService(this, intent);
+
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (isPosting) {
+ promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail);
+ } else {
+ if (!titleEditText.getText().toString().equals("") || redditGalleryImageInfoList != null) {
+ promptAlertDialog(R.string.discard, R.string.discard_detail);
+ } else {
+ finish();
+ }
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putString(SUBREDDIT_NAME_STATE, subredditName);
+ outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
+ outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
+ outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser);
+ outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful);
+ outState.putBoolean(IS_POSTING_STATE, isPosting);
+ outState.putParcelable(FLAIR_STATE, flair);
+ outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
+ outState.putBoolean(IS_NSFW_STATE, isNSFW);
+ redditGalleryImageInfoList = adapter.getRedditGalleryImageInfoList();
+ outState.putParcelableArrayList(REDDIT_GALLERY_IMAGE_INFO_STATE, redditGalleryImageInfoList);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
+ if (resultCode == RESULT_OK) {
+ subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
+ iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
+ subredditSelected = true;
+ subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
+
+ subredditNameTextView.setTextColor(primaryTextColor);
+ subredditNameTextView.setText(subredditName);
+ displaySubredditIcon();
+
+ flairTextView.setVisibility(View.VISIBLE);
+ flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
+ flairTextView.setTextColor(primaryTextColor);
+ flairTextView.setText(getString(R.string.flair));
+ flair = null;
+ }
+ } else if (requestCode == PICK_IMAGE_REQUEST_CODE) {
+ if (resultCode == RESULT_OK) {
+ if (data == null) {
+ Snackbar.make(coordinatorLayout, R.string.error_getting_image, Snackbar.LENGTH_SHORT).show();
+ return;
+ }
+
+ imageUri = data.getData();
+ adapter.addImage(imageUri.toString());
+ uploadImage();
+ }
+ } else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
+ if (resultCode == RESULT_OK) {
+ adapter.addImage(imageUri.toString());
+ uploadImage();
+ }
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ EventBus.getDefault().unregister(this);
+ super.onDestroy();
+ }
+
+ @Override
+ public void flairSelected(Flair flair) {
+ this.flair = flair;
+ flairTextView.setText(flair.getText());
+ flairTextView.setBackgroundColor(flairBackgroundColor);
+ flairTextView.setBorderColor(flairBackgroundColor);
+ flairTextView.setTextColor(flairTextColor);
+ }
+
+ @Subscribe
+ public void onAccountSwitchEvent(SwitchAccountEvent event) {
+ finish();
+ }
+
+ @Subscribe
+ public void onSubmitGalleryPostEvent(SubmitGalleryPostEvent submitGalleryPostEvent) {
+ isPosting = false;
+ mPostingSnackbar.dismiss();
+ if (submitGalleryPostEvent.postSuccess) {
+ Intent intent = new Intent(this, LinkResolverActivity.class);
+ intent.setData(Uri.parse(submitGalleryPostEvent.postUrl));
+ startActivity(intent);
+ finish();
+ } else {
+ mMemu.findItem(R.id.action_send_post_gallery_activity).setEnabled(true);
+ mMemu.findItem(R.id.action_send_post_gallery_activity).getIcon().setAlpha(255);
+ if (submitGalleryPostEvent.errorMessage == null || submitGalleryPostEvent.errorMessage.equals("")) {
+ Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
+ } else {
+ Snackbar.make(coordinatorLayout, submitGalleryPostEvent.errorMessage.substring(0, 1).toUpperCase()
+ + submitGalleryPostEvent.errorMessage.substring(1), Snackbar.LENGTH_SHORT).show();
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java
index cbab1914..acf5034d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java
@@ -1,8 +1,8 @@
package ml.docilealligator.infinityforreddit.activities;
+import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
@@ -13,9 +13,9 @@ import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
+import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -30,9 +30,11 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
+import com.google.android.material.switchmaterial.SwitchMaterial;
import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus;
@@ -93,7 +95,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
@BindView(R.id.subreddit_name_text_view_post_image_activity)
TextView subredditNameTextView;
@BindView(R.id.rules_button_post_image_activity)
- Button rulesButton;
+ MaterialButton rulesButton;
@BindView(R.id.divider_1_post_image_activity)
View divider1;
@BindView(R.id.flair_custom_text_view_post_image_activity)
@@ -104,10 +106,18 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
CustomTextView nsfwTextView;
@BindView(R.id.divider_2_post_image_activity)
View divider2;
- @BindView(R.id.post_title_edit_text_post_image_activity)
- EditText titleEditText;
+ @BindView(R.id.receive_post_reply_notifications_linear_layout_post_image_activity)
+ LinearLayout receivePostReplyNotificationsLinearLayout;
+ @BindView(R.id.receive_post_reply_notifications_text_view_post_image_activity)
+ TextView receivePostReplyNotificationsTextView;
+ @BindView(R.id.receive_post_reply_notifications_switch_material_post_image_activity)
+ SwitchMaterial receivePostReplyNotificationsSwitchMaterial;
@BindView(R.id.divider_3_post_image_activity)
View divider3;
+ @BindView(R.id.post_title_edit_text_post_image_activity)
+ EditText titleEditText;
+ @BindView(R.id.divider_4_post_image_activity)
+ View divider4;
@BindView(R.id.select_image_constraint_layout_post_image_activity)
ConstraintLayout constraintLayout;
@BindView(R.id.capture_fab_post_image_activity)
@@ -331,18 +341,20 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
}
});
+ receivePostReplyNotificationsLinearLayout.setOnClickListener(view -> {
+ receivePostReplyNotificationsSwitchMaterial.performClick();
+ });
+
captureFab.setOnClickListener(view -> {
Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- if (pictureIntent.resolveActivity(getPackageManager()) != null) {
- try {
- imageUri = FileProvider.getUriForFile(this, "ml.docilealligator.infinityforreddit.provider",
- File.createTempFile("temp_img", ".jpg", getExternalFilesDir(Environment.DIRECTORY_PICTURES)));
- pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
- startActivityForResult(pictureIntent, CAPTURE_IMAGE_REQUEST_CODE);
- } catch (IOException ex) {
- Snackbar.make(coordinatorLayout, R.string.error_creating_temp_file, Snackbar.LENGTH_SHORT).show();
- }
- } else {
+ try {
+ imageUri = FileProvider.getUriForFile(this, "ml.docilealligator.infinityforreddit.provider",
+ File.createTempFile("temp_img", ".jpg", getExternalFilesDir(Environment.DIRECTORY_PICTURES)));
+ pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
+ startActivityForResult(pictureIntent, CAPTURE_IMAGE_REQUEST_CODE);
+ } catch (IOException ex) {
+ Snackbar.make(coordinatorLayout, R.string.error_creating_temp_file, Snackbar.LENGTH_SHORT).show();
+ } catch (ActivityNotFoundException e) {
Snackbar.make(coordinatorLayout, R.string.no_camera_available, Snackbar.LENGTH_SHORT).show();
}
});
@@ -380,12 +392,14 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor();
subredditNameTextView.setTextColor(secondaryTextColor);
rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor());
- rulesButton.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimaryLightTheme()));
+ rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
+ primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ receivePostReplyNotificationsTextView.setTextColor(primaryTextColor);
int dividerColor = mCustomThemeWrapper.getDividerColor();
divider1.setBackgroundColor(dividerColor);
divider2.setBackgroundColor(dividerColor);
divider3.setBackgroundColor(dividerColor);
- primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ divider4.setBackgroundColor(dividerColor);
flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor();
flairTextColor = mCustomThemeWrapper.getFlairTextColor();
spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor();
@@ -435,7 +449,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(titleResId)
.setMessage(messageResId)
- .setPositiveButton(R.string.yes, (dialogInterface, i)
+ .setPositiveButton(R.string.discard_dialog_button, (dialogInterface, i)
-> finish())
.setNegativeButton(R.string.no, null)
.show();
@@ -455,68 +469,69 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- if (isPosting) {
- promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail);
- return true;
- } else {
- if (!titleEditText.getText().toString().equals("") || imageUri != null) {
- promptAlertDialog(R.string.discard, R.string.discard_detail);
- return true;
- }
- }
- finish();
+ int itemId = item.getItemId();
+ if (itemId == android.R.id.home) {
+ if (isPosting) {
+ promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail);
return true;
- case R.id.action_send_post_image_activity:
- if (!subredditSelected) {
- Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
+ } else {
+ if (!titleEditText.getText().toString().equals("") || imageUri != null) {
+ promptAlertDialog(R.string.discard, R.string.discard_detail);
return true;
}
+ }
+ finish();
+ return true;
+ } else if (itemId == R.id.action_send_post_image_activity) {
+ if (!subredditSelected) {
+ Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
+ return true;
+ }
- if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
- Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
- return true;
- }
+ if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
+ Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
+ return true;
+ }
- if (imageUri == null) {
- Snackbar.make(coordinatorLayout, R.string.select_an_image, Snackbar.LENGTH_SHORT).show();
- return true;
- }
+ if (imageUri == null) {
+ Snackbar.make(coordinatorLayout, R.string.select_an_image, Snackbar.LENGTH_SHORT).show();
+ return true;
+ }
- isPosting = true;
+ isPosting = true;
- item.setEnabled(false);
- item.getIcon().setAlpha(130);
+ item.setEnabled(false);
+ item.getIcon().setAlpha(130);
- mPostingSnackbar.show();
+ mPostingSnackbar.show();
- String subredditName;
- if (subredditIsUser) {
- subredditName = "u_" + subredditNameTextView.getText().toString();
- } else {
- subredditName = subredditNameTextView.getText().toString();
- }
+ String subredditName;
+ if (subredditIsUser) {
+ subredditName = "u_" + subredditNameTextView.getText().toString();
+ } else {
+ subredditName = subredditNameTextView.getText().toString();
+ }
- Intent intent = new Intent(this, SubmitPostService.class);
- intent.setData(imageUri);
- intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
- intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
- intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
- intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
- intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
- intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
- String mimeType = getContentResolver().getType(imageUri);
- if (mimeType != null && mimeType.contains("gif")) {
- intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_VIDEO);
- } else {
- intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_IMAGE);
- }
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ Intent intent = new Intent(this, SubmitPostService.class);
+ intent.setData(imageUri);
+ intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
+ intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
+ intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
+ intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
+ intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
+ intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
+ intent.putExtra(SubmitPostService.EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, receivePostReplyNotificationsSwitchMaterial.isChecked());
+ String mimeType = getContentResolver().getType(imageUri);
+ if (mimeType != null && mimeType.contains("gif")) {
+ intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_VIDEO);
+ } else {
+ intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_IMAGE);
+ }
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- ContextCompat.startForegroundService(this, intent);
+ ContextCompat.startForegroundService(this, intent);
- return true;
+ return true;
}
return false;
@@ -631,7 +646,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
}
@Subscribe
- public void onSubmitVideoOrGifPostEvent(SubmitVideoOrGifPostEvent submitVideoOrGifPostEvent) {
+ public void onSubmitGifPostEvent(SubmitVideoOrGifPostEvent submitVideoOrGifPostEvent) {
isPosting = false;
mPostingSnackbar.dismiss();
mMemu.findItem(R.id.action_send_post_image_activity).setEnabled(true);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java
index ab1852bc..8ce97d55 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java
@@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit.activities;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
@@ -10,8 +9,8 @@ import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.widget.Button;
import android.widget.EditText;
+import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -28,6 +27,7 @@ import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
+import com.google.android.material.switchmaterial.SwitchMaterial;
import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus;
@@ -89,19 +89,27 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
@BindView(R.id.subreddit_name_text_view_post_link_activity)
TextView subredditNameTextView;
@BindView(R.id.rules_button_post_link_activity)
- Button rulesButton;
+ MaterialButton rulesButton;
@BindView(R.id.divider_1_post_link_activity)
View divider1;
@BindView(R.id.divider_2_post_link_activity)
View divider2;
- @BindView(R.id.divider_3_post_link_activity)
- View divider3;
+ @BindView(R.id.divider_4_post_link_activity)
+ View divider4;
@BindView(R.id.flair_custom_text_view_post_link_activity)
CustomTextView flairTextView;
@BindView(R.id.spoiler_custom_text_view_post_link_activity)
CustomTextView spoilerTextView;
@BindView(R.id.nsfw_custom_text_view_post_link_activity)
CustomTextView nsfwTextView;
+ @BindView(R.id.receive_post_reply_notifications_linear_layout_post_link_activity)
+ LinearLayout receivePostReplyNotificationsLinearLayout;
+ @BindView(R.id.receive_post_reply_notifications_text_view_post_link_activity)
+ TextView receivePostReplyNotificationsTextView;
+ @BindView(R.id.receive_post_reply_notifications_switch_material_post_link_activity)
+ SwitchMaterial receivePostReplyNotificationsSwitchMaterial;
+ @BindView(R.id.divider_3_post_link_activity)
+ View divider3;
@BindView(R.id.post_title_edit_text_post_link_activity)
EditText titleEditText;
@BindView(R.id.suggest_title_button_post_link_activity)
@@ -310,6 +318,10 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
}
});
+ receivePostReplyNotificationsLinearLayout.setOnClickListener(view -> {
+ receivePostReplyNotificationsSwitchMaterial.performClick();
+ });
+
suggestTitleButton.setOnClickListener(view -> {
Toast.makeText(this, R.string.please_wait, Toast.LENGTH_SHORT).show();
String url = linkEditText.getText().toString().trim();
@@ -354,12 +366,14 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor();
subredditNameTextView.setTextColor(secondaryTextColor);
rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor());
- rulesButton.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimaryLightTheme()));
+ rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
+ primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ receivePostReplyNotificationsTextView.setTextColor(primaryTextColor);
int dividerColor = mCustomThemeWrapper.getDividerColor();
divider1.setBackgroundColor(dividerColor);
divider2.setBackgroundColor(dividerColor);
divider3.setBackgroundColor(dividerColor);
- primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ divider4.setBackgroundColor(dividerColor);
flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor();
flairTextColor = mCustomThemeWrapper.getFlairTextColor();
spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor();
@@ -404,7 +418,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(titleResId)
.setMessage(messageResId)
- .setPositiveButton(R.string.yes, (dialogInterface, i) -> finish())
+ .setPositiveButton(R.string.discard_dialog_button, (dialogInterface, i) -> finish())
.setNegativeButton(R.string.no, null)
.show();
}
@@ -475,6 +489,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
+ intent.putExtra(SubmitPostService.EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, receivePostReplyNotificationsSwitchMaterial.isChecked());
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
ContextCompat.startForegroundService(this, intent);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
index f1cd11cc..a03f7355 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
@@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.activities;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
@@ -14,8 +13,8 @@ import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.widget.Button;
import android.widget.EditText;
+import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -32,8 +31,10 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
+import com.google.android.material.switchmaterial.SwitchMaterial;
import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus;
@@ -61,6 +62,7 @@ import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.events.SubmitTextOrLinkPostEvent;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
@@ -90,6 +92,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
private static final int PICK_IMAGE_REQUEST_CODE = 100;
private static final int CAPTURE_IMAGE_REQUEST_CODE = 200;
+ private static final int MARKDOWN_PREVIEW_REQUEST_CODE = 300;
@BindView(R.id.coordinator_layout_post_text_activity)
CoordinatorLayout coordinatorLayout;
@@ -97,12 +100,12 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
AppBarLayout appBarLayout;
@BindView(R.id.toolbar_post_text_activity)
Toolbar toolbar;
- @BindView(R.id.subreddit_icon_gif_image_view_search_activity)
+ @BindView(R.id.subreddit_icon_gif_image_view_post_text_activity)
GifImageView iconGifImageView;
- @BindView(R.id.subreddit_name_text_view_search_activity)
+ @BindView(R.id.subreddit_name_text_view_post_text_activity)
TextView subredditNameTextView;
@BindView(R.id.rules_button_post_text_activity)
- Button rulesButton;
+ MaterialButton rulesButton;
@BindView(R.id.divider_1_post_text_activity)
View divider1;
@BindView(R.id.flair_custom_text_view_post_text_activity)
@@ -113,10 +116,18 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
CustomTextView nsfwTextView;
@BindView(R.id.divider_2_post_text_activity)
View divider2;
- @BindView(R.id.post_title_edit_text_post_text_activity)
- EditText titleEditText;
+ @BindView(R.id.receive_post_reply_notifications_linear_layout_post_text_activity)
+ LinearLayout receivePostReplyNotificationsLinearLayout;
+ @BindView(R.id.receive_post_reply_notifications_text_view_post_text_activity)
+ TextView receivePostReplyNotificationsTextView;
+ @BindView(R.id.receive_post_reply_notifications_switch_material_post_text_activity)
+ SwitchMaterial receivePostReplyNotificationsSwitchMaterial;
@BindView(R.id.divider_3_post_text_activity)
View divider3;
+ @BindView(R.id.post_title_edit_text_post_text_activity)
+ EditText titleEditText;
+ @BindView(R.id.divider_4_post_text_activity)
+ View divider4;
@BindView(R.id.post_text_content_edit_text_post_text_activity)
EditText contentEditText;
@BindView(R.id.markdown_bottom_bar_recycler_view_post_text_activity)
@@ -333,6 +344,10 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
}
});
+ receivePostReplyNotificationsLinearLayout.setOnClickListener(view -> {
+ receivePostReplyNotificationsSwitchMaterial.performClick();
+ });
+
MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter(
mCustomThemeWrapper, new MarkdownBottomBarRecyclerViewAdapter.ItemClickListener() {
@Override
@@ -353,7 +368,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
}
});
- markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManager(this,
+ markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this,
LinearLayoutManager.HORIZONTAL, false));
markdownBottomBarRecyclerView.setAdapter(adapter);
}
@@ -375,12 +390,14 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor();
subredditNameTextView.setTextColor(secondaryTextColor);
rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor());
- rulesButton.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimaryLightTheme()));
+ rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
+ primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ receivePostReplyNotificationsTextView.setTextColor(primaryTextColor);
int dividerColor = mCustomThemeWrapper.getDividerColor();
divider1.setBackgroundColor(dividerColor);
divider2.setBackgroundColor(dividerColor);
divider3.setBackgroundColor(dividerColor);
- primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ divider4.setBackgroundColor(dividerColor);
flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor();
flairTextColor = mCustomThemeWrapper.getFlairTextColor();
spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor();
@@ -423,9 +440,9 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(titleResId)
.setMessage(messageResId)
- .setPositiveButton(R.string.yes, (dialogInterface, i)
+ .setPositiveButton(R.string.discard_dialog_button, (dialogInterface, i)
-> finish())
- .setNegativeButton(R.string.no, null)
+ .setNegativeButton(R.string.cancel, null)
.show();
}
@@ -459,48 +476,55 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
} else if (itemId == R.id.action_preview_post_text_activity) {
Intent intent = new Intent(this, FullMarkdownActivity.class);
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString());
- startActivity(intent);
+ intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true);
+ startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE);
} else if (itemId == R.id.action_send_post_text_activity) {
- if (!subredditSelected) {
- Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
- return true;
- }
+ submitPost(item);
+ return true;
+ }
- if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
- Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
- return true;
- }
+ return false;
+ }
- isPosting = true;
+ private void submitPost(MenuItem item) {
+ if (!subredditSelected) {
+ Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
+ return;
+ }
- item.setEnabled(false);
- item.getIcon().setAlpha(130);
+ if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
+ Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
+ return;
+ }
- mPostingSnackbar.show();
+ isPosting = true;
- String subredditName;
- if (subredditIsUser) {
- subredditName = "u_" + subredditNameTextView.getText().toString();
- } else {
- subredditName = subredditNameTextView.getText().toString();
- }
+ if (item != null) {
+ item.setEnabled(false);
+ item.getIcon().setAlpha(130);
+ }
- Intent intent = new Intent(this, SubmitPostService.class);
- intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
- intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
- intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
- intent.putExtra(SubmitPostService.EXTRA_CONTENT, contentEditText.getText().toString());
- intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_SELF);
- intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
- intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
- intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
- intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
- ContextCompat.startForegroundService(this, intent);
+ mPostingSnackbar.show();
- return true;
+ String subredditName;
+ if (subredditIsUser) {
+ subredditName = "u_" + subredditNameTextView.getText().toString();
+ } else {
+ subredditName = subredditNameTextView.getText().toString();
}
- return false;
+ Intent intent = new Intent(this, SubmitPostService.class);
+ intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
+ intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
+ intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
+ intent.putExtra(SubmitPostService.EXTRA_CONTENT, contentEditText.getText().toString());
+ intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_SELF);
+ intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
+ intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
+ intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
+ intent.putExtra(SubmitPostService.EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, receivePostReplyNotificationsSwitchMaterial.isChecked());
+ intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
+ ContextCompat.startForegroundService(this, intent);
}
@Override
@@ -561,6 +585,8 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
+ } else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
+ submitPost(mMenu.findItem(R.id.action_send_post_text_activity));
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java
index 420477ff..109d10d3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java
@@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit.activities;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
@@ -12,8 +11,8 @@ import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.widget.Button;
import android.widget.EditText;
+import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -35,9 +34,11 @@ import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
+import com.google.android.material.switchmaterial.SwitchMaterial;
import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus;
@@ -95,7 +96,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
@BindView(R.id.subreddit_name_text_view_post_video_activity)
TextView subredditNameTextView;
@BindView(R.id.rules_button_post_video_activity)
- Button rulesButton;
+ MaterialButton rulesButton;
@BindView(R.id.divider_1_post_video_activity)
View divider1;
@BindView(R.id.flair_custom_text_view_post_video_activity)
@@ -106,10 +107,18 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
CustomTextView nsfwTextView;
@BindView(R.id.divider_2_post_video_activity)
View divider2;
- @BindView(R.id.post_title_edit_text_post_video_activity)
- EditText titleEditText;
+ @BindView(R.id.receive_post_reply_notifications_linear_layout_post_video_activity)
+ LinearLayout receivePostReplyNotificationsLinearLayout;
+ @BindView(R.id.receive_post_reply_notifications_text_view_post_video_activity)
+ TextView receivePostReplyNotificationsTextView;
+ @BindView(R.id.receive_post_reply_notifications_switch_material_post_video_activity)
+ SwitchMaterial receivePostReplyNotificationsSwitchMaterial;
@BindView(R.id.divider_3_post_video_activity)
View divider3;
+ @BindView(R.id.post_title_edit_text_post_video_activity)
+ EditText titleEditText;
+ @BindView(R.id.divider_4_post_video_activity)
+ View divider4;
@BindView(R.id.select_video_constraint_layout_post_video_activity)
ConstraintLayout constraintLayout;
@BindView(R.id.capture_fab_post_video_activity)
@@ -345,6 +354,10 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
}
});
+ receivePostReplyNotificationsLinearLayout.setOnClickListener(view -> {
+ receivePostReplyNotificationsSwitchMaterial.performClick();
+ });
+
captureFab.setOnClickListener(view -> {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
@@ -386,12 +399,14 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor();
subredditNameTextView.setTextColor(secondaryTextColor);
rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor());
- rulesButton.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimaryLightTheme()));
+ rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
+ primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ receivePostReplyNotificationsTextView.setTextColor(primaryTextColor);
int dividerColor = mCustomThemeWrapper.getDividerColor();
divider1.setBackgroundColor(dividerColor);
divider2.setBackgroundColor(dividerColor);
divider3.setBackgroundColor(dividerColor);
- primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ divider4.setBackgroundColor(dividerColor);
flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor();
flairTextColor = mCustomThemeWrapper.getFlairTextColor();
spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor();
@@ -444,7 +459,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(titleResId)
.setMessage(messageResId)
- .setPositiveButton(R.string.yes, (dialogInterface, i) -> finish())
+ .setPositiveButton(R.string.discard_dialog_button, (dialogInterface, i) -> finish())
.setNegativeButton(R.string.no, null)
.show();
}
@@ -463,63 +478,64 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- if (isPosting) {
- promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail);
- return true;
- } else {
- if (!titleEditText.getText().toString().equals("") || videoUri != null) {
- promptAlertDialog(R.string.discard, R.string.discard_detail);
- return true;
- }
- }
- finish();
+ int itemId = item.getItemId();
+ if (itemId == android.R.id.home) {
+ if (isPosting) {
+ promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail);
return true;
- case R.id.action_send_post_video_activity:
- if (!subredditSelected) {
- Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
- return true;
- }
-
- if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
- Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
- return true;
- }
-
- if (videoUri == null) {
- Snackbar.make(coordinatorLayout, R.string.select_an_image, Snackbar.LENGTH_SHORT).show();
+ } else {
+ if (!titleEditText.getText().toString().equals("") || videoUri != null) {
+ promptAlertDialog(R.string.discard, R.string.discard_detail);
return true;
}
+ }
+ finish();
+ return true;
+ } else if (itemId == R.id.action_send_post_video_activity) {
+ if (!subredditSelected) {
+ Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
+ return true;
+ }
- isPosting = true;
+ if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
+ Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
+ return true;
+ }
- item.setEnabled(false);
- item.getIcon().setAlpha(130);
+ if (videoUri == null) {
+ Snackbar.make(coordinatorLayout, R.string.select_an_image, Snackbar.LENGTH_SHORT).show();
+ return true;
+ }
- mPostingSnackbar.show();
+ isPosting = true;
- String subredditName;
- if (subredditIsUser) {
- subredditName = "u_" + subredditNameTextView.getText().toString();
- } else {
- subredditName = subredditNameTextView.getText().toString();
- }
+ item.setEnabled(false);
+ item.getIcon().setAlpha(130);
- Intent intent = new Intent(this, SubmitPostService.class);
- intent.setData(videoUri);
- intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
- intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
- intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
- intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
- intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
- intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
- intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_VIDEO);
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ mPostingSnackbar.show();
- ContextCompat.startForegroundService(this, intent);
+ String subredditName;
+ if (subredditIsUser) {
+ subredditName = "u_" + subredditNameTextView.getText().toString();
+ } else {
+ subredditName = subredditNameTextView.getText().toString();
+ }
- return true;
+ Intent intent = new Intent(this, SubmitPostService.class);
+ intent.setData(videoUri);
+ intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
+ intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
+ intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
+ intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
+ intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
+ intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
+ intent.putExtra(SubmitPostService.EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, receivePostReplyNotificationsSwitchMaterial.isChecked());
+ intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_VIDEO);
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+
+ ContextCompat.startForegroundService(this, intent);
+
+ return true;
}
return false;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java
index c22d481f..d99511ac 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RPANActivity.java
@@ -1,5 +1,7 @@
package ml.docilealligator.infinityforreddit.activities;
+import android.content.ActivityNotFoundException;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
@@ -7,6 +9,8 @@ import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Handler;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;
@@ -23,12 +27,15 @@ import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import com.evernote.android.state.State;
+import com.google.android.material.snackbar.Snackbar;
import com.livefront.bridge.Bridge;
+import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.concurrent.Executor;
@@ -44,12 +51,15 @@ import ml.docilealligator.infinityforreddit.RPANBroadcast;
import ml.docilealligator.infinityforreddit.apis.Strapi;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.font.ContentFontFamily;
+import ml.docilealligator.infinityforreddit.font.ContentFontStyle;
import ml.docilealligator.infinityforreddit.font.FontFamily;
+import ml.docilealligator.infinityforreddit.font.FontStyle;
import ml.docilealligator.infinityforreddit.font.TitleFontFamily;
+import ml.docilealligator.infinityforreddit.font.TitleFontStyle;
import ml.docilealligator.infinityforreddit.fragments.ViewRPANBroadcastFragment;
-import ml.docilealligator.infinityforreddit.utils.APIUtils;
import ml.docilealligator.infinityforreddit.utils.JSONUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@@ -57,6 +67,8 @@ import retrofit2.Retrofit;
public class RPANActivity extends AppCompatActivity {
+ public static final String EXTRA_RPAN_BROADCAST_FULLNAME_OR_ID = "ERBFOI";
+
@BindView(R.id.coordinator_layout_rpan_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.view_pager_2_rpan_activity)
@@ -70,14 +82,9 @@ public class RPANActivity extends AppCompatActivity {
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
- @Named("current_account")
- SharedPreferences mCurrentAccountSharedPreferences;
- @Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
- private String mAccessToken;
- private String mAccountName;
@State
ArrayList<RPANBroadcast> rpanBroadcasts;
@State
@@ -92,6 +99,15 @@ public class RPANActivity extends AppCompatActivity {
getTheme().applyStyle(R.style.Theme_Normal, true);
+ getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true);
+
+ getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true);
+
+ getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true);
+
getTheme().applyStyle(FontFamily.valueOf(mSharedPreferences
.getString(SharedPreferencesUtils.FONT_FAMILY_KEY, FontFamily.Default.name())).getResId(), true);
@@ -114,9 +130,6 @@ public class RPANActivity extends AppCompatActivity {
actionBar.setHomeAsUpIndicator(upArrow);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
- mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
- mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
-
if (rpanBroadcasts == null) {
loadRPANVideos();
} else {
@@ -125,25 +138,95 @@ public class RPANActivity extends AppCompatActivity {
}
private void loadRPANVideos() {
- strapiRetrofit.create(Strapi.class).getAllBroadcasts(APIUtils.getOAuthHeader(mAccessToken)).enqueue(new Callback<String>() {
- @Override
- public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
- progressBar.setVisibility(View.GONE);
- if (response.isSuccessful()) {
- parseRPANBroadcasts(response.body());
- } else {
+ String rpanBroadcastFullNameOrId = getIntent().getStringExtra(EXTRA_RPAN_BROADCAST_FULLNAME_OR_ID);
+ if (rpanBroadcastFullNameOrId == null) {
+ strapiRetrofit.create(Strapi.class).getAllBroadcasts().enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ progressBar.setVisibility(View.GONE);
+ if (response.isSuccessful()) {
+ parseRPANBroadcasts(response.body());
+ } else {
+ try {
+ ResponseBody responseBody = response.errorBody();
+ if (responseBody != null) {
+ JSONObject errorObject = new JSONObject(responseBody.string());
+ String errorMessage = errorObject.getString(JSONUtils.DATA_KEY);
+ if (!errorMessage.isEmpty() && !errorMessage.equals("null")) {
+ Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
+ } else {
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
+ } catch (IOException | JSONException e) {
+ e.printStackTrace();
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ progressBar.setVisibility(View.GONE);
Toast.makeText(RPANActivity.this,
R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
}
- }
+ });
+ } else {
+ strapiRetrofit.create(Strapi.class).getRPANBroadcast(rpanBroadcastFullNameOrId).enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ progressBar.setVisibility(View.GONE);
+ if (response.isSuccessful()) {
+ Handler handler = new Handler();
+ mExecutor.execute(() -> {
+ try {
+ rpanBroadcasts = new ArrayList<>();
+ rpanBroadcasts.add(parseSingleRPANBroadcast(new JSONObject(response.body()).getJSONObject(JSONUtils.DATA_KEY)));
+ handler.post(() -> initializeViewPager());
+ } catch (JSONException e) {
+ e.printStackTrace();
+ handler.post(() -> Toast.makeText(RPANActivity.this,
+ R.string.parse_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show());
+ }
+ });
+ } else {
+ try {
+ ResponseBody responseBody = response.errorBody();
+ if (responseBody != null) {
+ JSONObject errorObject = new JSONObject(responseBody.string());
+ String errorMessage = errorObject.getString(JSONUtils.DATA_KEY);
+ if (!errorMessage.isEmpty() && !errorMessage.equals("null")) {
+ Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
+ } else {
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
+ } catch (IOException | JSONException e) {
+ e.printStackTrace();
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
- @Override
- public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
- progressBar.setVisibility(View.GONE);
- Toast.makeText(RPANActivity.this,
- R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
- }
- });
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ progressBar.setVisibility(View.GONE);
+ Toast.makeText(RPANActivity.this,
+ R.string.load_rpan_broadcasts_failed, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
}
private void parseRPANBroadcasts(String response) {
@@ -156,49 +239,12 @@ public class RPANActivity extends AppCompatActivity {
JSONArray dataArray = responseObject.getJSONArray(JSONUtils.DATA_KEY);
for (int i = 0; i < dataArray.length(); i++) {
- JSONObject singleData = dataArray.getJSONObject(i);
- JSONObject rpanPostObject = singleData.getJSONObject(JSONUtils.POST_KEY);
- RPANBroadcast.RPANPost rpanPost = new RPANBroadcast.RPANPost(
- rpanPostObject.getString(JSONUtils.TITLE_KEY),
- rpanPostObject.getJSONObject(JSONUtils.SUBREDDIT_KEY).getString(JSONUtils.NAME_KEY),
- rpanPostObject.getJSONObject(JSONUtils.SUBREDDIT_KEY).getJSONObject(JSONUtils.STYLES_KEY).getString(JSONUtils.ICON_KEY),
- rpanPostObject.getJSONObject(JSONUtils.AUTHOR_INFO_KEY).getString(JSONUtils.NAME_KEY),
- rpanPostObject.getInt(JSONUtils.SCORE_KEY),
- rpanPostObject.getString(JSONUtils.VOTE_STATE_KEY),
- rpanPostObject.getDouble(JSONUtils.UPVOTE_RATIO_CAMEL_CASE_KEY),
- rpanPostObject.getString(JSONUtils.PERMALINK_KEY),
- rpanPostObject.getJSONObject(JSONUtils.OUTBOUND_LINK_KEY).getString(JSONUtils.URL_KEY),
- rpanPostObject.getBoolean(JSONUtils.IS_NSFW_KEY),
- rpanPostObject.getBoolean(JSONUtils.IS_LOCKED_KEY),
- rpanPostObject.getBoolean(JSONUtils.IS_ARCHIVED_KEY),
- rpanPostObject.getBoolean(JSONUtils.IS_SPOILER),
- rpanPostObject.getString(JSONUtils.SUGGESTED_COMMENT_SORT_CAMEL_CASE_KEY),
- rpanPostObject.getString(JSONUtils.LIVE_COMMENTS_WEBSOCKET_KEY)
- );
-
- JSONObject rpanStreamObject = singleData.getJSONObject(JSONUtils.STREAM_KEY);
- RPANBroadcast.RPANStream rpanStream = new RPANBroadcast.RPANStream(
- rpanStreamObject.getString(JSONUtils.STREAM_ID_KEY),
- rpanStreamObject.getString(JSONUtils.HLS_URL_KEY),
- rpanStreamObject.getString(JSONUtils.THUMBNAIL_KEY),
- rpanStreamObject.getInt(JSONUtils.WIDTH_KEY),
- rpanStreamObject.getInt(JSONUtils.HEIGHT_KEY),
- rpanStreamObject.getLong(JSONUtils.PUBLISH_AT_KEY),
- rpanStreamObject.getString(JSONUtils.STATE_KEY)
- );
-
- rpanBroadcasts.add(new RPANBroadcast(
- singleData.getInt(JSONUtils.UPVOTES_KEY),
- singleData.getInt(JSONUtils.DOWNVOTES_KEY),
- singleData.getInt(JSONUtils.UNIQUE_WATCHERS_KEY),
- singleData.getInt(JSONUtils.CONTINUOUS_WATCHERS_KEY),
- singleData.getInt(JSONUtils.TOTAL_CONTINUOUS_WATCHERS_KEY),
- singleData.getBoolean(JSONUtils.CHAT_DISABLED_KEY),
- singleData.getDouble(JSONUtils.BROADCAST_TIME_KEY),
- singleData.getDouble(JSONUtils.ESTIMATED_REMAINING_TIME_KEY),
- rpanPost,
- rpanStream
- ));
+ try {
+ JSONObject singleData = dataArray.getJSONObject(i);
+ rpanBroadcasts.add(parseSingleRPANBroadcast(singleData));
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
}
handler.post(() -> {
@@ -215,6 +261,52 @@ public class RPANActivity extends AppCompatActivity {
});
}
+ private RPANBroadcast parseSingleRPANBroadcast(JSONObject singleData) throws JSONException {
+ JSONObject rpanPostObject = singleData.getJSONObject(JSONUtils.POST_KEY);
+ RPANBroadcast.RPANPost rpanPost = new RPANBroadcast.RPANPost(
+ rpanPostObject.getString(JSONUtils.ID_KEY),
+ rpanPostObject.getString(JSONUtils.TITLE_KEY),
+ rpanPostObject.getJSONObject(JSONUtils.SUBREDDIT_KEY).getString(JSONUtils.NAME_KEY),
+ rpanPostObject.getJSONObject(JSONUtils.SUBREDDIT_KEY).getJSONObject(JSONUtils.STYLES_KEY).getString(JSONUtils.ICON_KEY),
+ rpanPostObject.getJSONObject(JSONUtils.AUTHOR_INFO_KEY).getString(JSONUtils.NAME_KEY),
+ rpanPostObject.getInt(JSONUtils.SCORE_KEY),
+ rpanPostObject.getString(JSONUtils.VOTE_STATE_KEY),
+ rpanPostObject.getDouble(JSONUtils.UPVOTE_RATIO_CAMEL_CASE_KEY),
+ rpanPostObject.getString(JSONUtils.PERMALINK_KEY),
+ rpanPostObject.getJSONObject(JSONUtils.OUTBOUND_LINK_KEY).getString(JSONUtils.URL_KEY),
+ rpanPostObject.getBoolean(JSONUtils.IS_NSFW_KEY),
+ rpanPostObject.getBoolean(JSONUtils.IS_LOCKED_KEY),
+ rpanPostObject.getBoolean(JSONUtils.IS_ARCHIVED_KEY),
+ rpanPostObject.getBoolean(JSONUtils.IS_SPOILER),
+ rpanPostObject.getString(JSONUtils.SUGGESTED_COMMENT_SORT_CAMEL_CASE_KEY),
+ rpanPostObject.getString(JSONUtils.LIVE_COMMENTS_WEBSOCKET_KEY)
+ );
+
+ JSONObject rpanStreamObject = singleData.getJSONObject(JSONUtils.STREAM_KEY);
+ RPANBroadcast.RPANStream rpanStream = new RPANBroadcast.RPANStream(
+ rpanStreamObject.getString(JSONUtils.STREAM_ID_KEY),
+ rpanStreamObject.getString(JSONUtils.HLS_URL_KEY),
+ rpanStreamObject.getString(JSONUtils.THUMBNAIL_KEY),
+ rpanStreamObject.getInt(JSONUtils.WIDTH_KEY),
+ rpanStreamObject.getInt(JSONUtils.HEIGHT_KEY),
+ rpanStreamObject.getLong(JSONUtils.PUBLISH_AT_KEY),
+ rpanStreamObject.getString(JSONUtils.STATE_KEY)
+ );
+
+ return new RPANBroadcast(
+ singleData.getInt(JSONUtils.UPVOTES_KEY),
+ singleData.getInt(JSONUtils.DOWNVOTES_KEY),
+ singleData.getInt(JSONUtils.UNIQUE_WATCHERS_KEY),
+ singleData.getInt(JSONUtils.CONTINUOUS_WATCHERS_KEY),
+ singleData.getInt(JSONUtils.TOTAL_CONTINUOUS_WATCHERS_KEY),
+ singleData.getBoolean(JSONUtils.CHAT_DISABLED_KEY),
+ singleData.getDouble(JSONUtils.BROADCAST_TIME_KEY),
+ singleData.getDouble(JSONUtils.ESTIMATED_REMAINING_TIME_KEY),
+ rpanPost,
+ rpanStream
+ );
+ }
+
private void initializeViewPager() {
sectionsPagerAdapter = new SectionsPagerAdapter(this);
viewPager2.setAdapter(sectionsPagerAdapter);
@@ -240,6 +332,54 @@ public class RPANActivity extends AppCompatActivity {
} catch (NoSuchFieldException | IllegalAccessException ignore) {}
}
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.rpan_activity, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ } else if (item.getItemId() == R.id.action_share_rpan_link_rpan_activity) {
+ if (rpanBroadcasts != null) {
+ int position = viewPager2.getCurrentItem();
+ if (position >= 0 && position < rpanBroadcasts.size()) {
+ shareLink(rpanBroadcasts.get(position).rpanPost.rpanUrl);
+ return true;
+ }
+ }
+ } else if (item.getItemId() == R.id.action_share_post_link_rpan_activity) {
+ if (rpanBroadcasts != null) {
+ int position = viewPager2.getCurrentItem();
+ if (position >= 0 && position < rpanBroadcasts.size()) {
+ shareLink(rpanBroadcasts.get(position).rpanPost.postPermalink);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ EventBus.getDefault().unregister(this);
+ }
+
+ private void shareLink(String link) {
+ try {
+ Intent intent = new Intent(Intent.ACTION_SEND);
+ intent.setType("text/plain");
+ intent.putExtra(Intent.EXTRA_TEXT, link);
+ startActivity(Intent.createChooser(intent, getString(R.string.share)));
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(this, R.string.no_activity_found_for_share, Toast.LENGTH_SHORT).show();
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentStateAdapter {
public SectionsPagerAdapter(FragmentActivity fa) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java
index c13785bf..4b8f9b38 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java
@@ -11,7 +11,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
@@ -117,7 +116,6 @@ public class ReportActivity extends BaseActivity {
} else {
mAdapter = new ReportReasonRecyclerViewAdapter(mCustomThemeWrapper, ReportReason.getGeneralReasons(this));
}
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(mAdapter);
if (rulesReasons == null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java
index dfc8da16..ca687cf1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java
@@ -15,7 +15,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
@@ -119,7 +118,6 @@ public class RulesActivity extends BaseActivity {
mSubredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper);
recyclerView.setAdapter(mAdapter);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
index a4f77b95..66369953 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
@@ -18,7 +18,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.lifecycle.ViewModelProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.ferfalk.simplesearchview.SimpleSearchView;
@@ -183,11 +182,24 @@ public class SearchActivity extends BaseActivity {
subredditAutocompleteRecyclerViewAdapter = new SubredditAutocompleteRecyclerViewAdapter(this,
mCustomThemeWrapper, subredditData -> {
- Intent intent = new Intent(SearchActivity.this, ViewSubredditDetailActivity.class);
- intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditData.getName());
- startActivity(intent);
- finish();
- });
+ if (searchOnlySubreddits) {
+ Intent returnIntent = new Intent();
+ if (getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false)) {
+ ArrayList<String> subredditNameList = new ArrayList<>();
+ subredditNameList.add(subredditData.getName());
+ returnIntent.putStringArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, subredditNameList);
+ } else {
+ returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, subredditData.getName());
+ returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, subredditData.getIconUrl());
+ }
+ setResult(Activity.RESULT_OK, returnIntent);
+ } else {
+ Intent intent = new Intent(SearchActivity.this, ViewSubredditDetailActivity.class);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditData.getName());
+ startActivity(intent);
+ }
+ finish();
+ });
simpleSearchView.setOnQueryTextListener(new SimpleSearchView.OnQueryTextListener() {
@Override
@@ -287,7 +299,6 @@ public class SearchActivity extends BaseActivity {
});
recyclerView.setVisibility(View.VISIBLE);
recyclerView.setNestedScrollingEnabled(false);
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SEARCH_HISTORY, true)) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java
index 7098b86a..f2096b97 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java
@@ -85,7 +85,9 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface,
FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, RandomBottomSheetFragment.RandomOptionSelectionCallback,
PostTypeBottomSheetFragment.PostTypeSelectionCallback, RecyclerViewContentScrollingInterface {
- static final String EXTRA_QUERY = "QK";
+
+ static final String EXTRA_QUERY = "EQ";
+ static final String EXTRA_TRENDING_SOURCE = "ETS";
static final String EXTRA_SUBREDDIT_NAME = "ESN";
private static final String INSERT_SEARCH_QUERY_SUCCESS_STATE = "ISQSS";
@@ -647,7 +649,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
startActivity(subredditIntent);
})
- .setNegativeButton(R.string.cancel, null)
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
+ }
+ })
.setOnDismissListener(dialogInterface -> {
if (imm != null) {
imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
@@ -688,7 +694,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
startActivity(userIntent);
})
- .setNegativeButton(R.string.cancel, null)
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
+ }
+ })
.setOnDismissListener(dialogInterface -> {
if (imm != null) {
imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
@@ -724,6 +734,10 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
case PostTypeBottomSheetFragment.TYPE_VIDEO:
intent = new Intent(this, PostVideoActivity.class);
startActivity(intent);
+ break;
+ case PostTypeBottomSheetFragment.TYPE_GALLERY:
+ intent = new Intent(this, PostGalleryActivity.class);
+ startActivity(intent);
}
}
@@ -760,6 +774,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SEARCH);
bundle.putString(PostFragment.EXTRA_NAME, mSubredditName);
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
+ bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
mFragment.setArguments(bundle);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java
index 84db322c..f9a7460e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java
@@ -13,7 +13,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
@@ -36,6 +35,7 @@ import ml.docilealligator.infinityforreddit.SelectUserFlair;
import ml.docilealligator.infinityforreddit.UserFlair;
import ml.docilealligator.infinityforreddit.adapters.UserFlairRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
@@ -63,7 +63,7 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo
SharedPreferences mCurrentAccountSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
- private LinearLayoutManager mLinearLayoutManager;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
private boolean mNullAccessToken = false;
private String mAccessToken;
private String mAccountName;
@@ -170,7 +170,7 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo
.show();
}
});
- mLinearLayoutManager = new LinearLayoutManager(SelectUserFlairActivity.this);
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(SelectUserFlairActivity.this);
recyclerView.setLayoutManager(mLinearLayoutManager);
recyclerView.setAdapter(mAdapter);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java
index cfc30dcf..38502fd4 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java
@@ -11,7 +11,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
@@ -31,6 +30,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.SelectSubreddit
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class SelectedSubredditsAndUsersActivity extends BaseActivity implements ActivityToolbarInterface {
@@ -56,7 +56,7 @@ public class SelectedSubredditsAndUsersActivity extends BaseActivity implements
SharedPreferences mSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
- private LinearLayoutManager linearLayoutManager;
+ private LinearLayoutManagerBugFixed linearLayoutManager;
private SelectedSubredditsRecyclerViewAdapter adapter;
private ArrayList<String> subreddits;
@@ -88,7 +88,7 @@ public class SelectedSubredditsAndUsersActivity extends BaseActivity implements
}
adapter = new SelectedSubredditsRecyclerViewAdapter(mCustomThemeWrapper, subreddits);
- linearLayoutManager = new LinearLayoutManager(this);
+ linearLayoutManager = new LinearLayoutManagerBugFixed(this);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java
index 7e97c0a6..d6c5e68f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java
@@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit.activities;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
@@ -12,10 +11,10 @@ import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
+import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -32,8 +31,10 @@ import com.bumptech.glide.request.transition.Transition;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
+import com.google.android.material.switchmaterial.SwitchMaterial;
import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus;
@@ -91,7 +92,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
@BindView(R.id.subreddit_name_text_view_submit_crosspost_activity)
TextView subredditNameTextView;
@BindView(R.id.rules_button_submit_crosspost_activity)
- Button rulesButton;
+ MaterialButton rulesButton;
@BindView(R.id.divider_1_submit_crosspost_activity)
View divider1;
@BindView(R.id.flair_custom_text_view_submit_crosspost_activity)
@@ -102,10 +103,18 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
CustomTextView nsfwTextView;
@BindView(R.id.divider_2_submit_crosspost_activity)
View divider2;
- @BindView(R.id.post_title_edit_text_submit_crosspost_activity)
- EditText titleEditText;
+ @BindView(R.id.receive_post_reply_notifications_linear_layout_submit_crosspost_activity)
+ LinearLayout receivePostReplyNotificationsLinearLayout;
+ @BindView(R.id.receive_post_reply_notifications_text_view_submit_crosspost_activity)
+ TextView receivePostReplyNotificationsTextView;
+ @BindView(R.id.receive_post_reply_notifications_switch_material_submit_crosspost_activity)
+ SwitchMaterial receivePostReplyNotificationsSwitchMaterial;
@BindView(R.id.divider_3_submit_crosspost_activity)
View divider3;
+ @BindView(R.id.post_title_edit_text_submit_crosspost_activity)
+ EditText titleEditText;
+ @BindView(R.id.divider_4_submit_crosspost_activity)
+ View divider4;
@BindView(R.id.post_content_text_view_submit_crosspost_activity)
TextView contentTextView;
@BindView(R.id.frame_layout_submit_crosspost_activity)
@@ -360,6 +369,10 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
isNSFW = false;
}
});
+
+ receivePostReplyNotificationsLinearLayout.setOnClickListener(view -> {
+ receivePostReplyNotificationsSwitchMaterial.performClick();
+ });
}
@Nullable
@@ -389,12 +402,14 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor();
subredditNameTextView.setTextColor(secondaryTextColor);
rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor());
- rulesButton.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimaryLightTheme()));
+ rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
+ primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ receivePostReplyNotificationsTextView.setTextColor(primaryTextColor);
int dividerColor = mCustomThemeWrapper.getDividerColor();
divider1.setBackgroundColor(dividerColor);
divider2.setBackgroundColor(dividerColor);
divider3.setBackgroundColor(dividerColor);
- primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ divider4.setBackgroundColor(dividerColor);
flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor();
flairTextColor = mCustomThemeWrapper.getFlairTextColor();
spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor();
@@ -457,61 +472,62 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- if (isPosting) {
- promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail);
- return true;
- } else {
- if (!titleEditText.getText().toString().equals("")) {
- promptAlertDialog(R.string.discard, R.string.discard_detail);
- return true;
- }
- }
- finish();
+ int itemId = item.getItemId();
+ if (itemId == android.R.id.home) {
+ if (isPosting) {
+ promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail);
return true;
- case R.id.action_send_submit_crosspost_activity:
- if (!subredditSelected) {
- Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
- return true;
- }
-
- if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
- Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
+ } else {
+ if (!titleEditText.getText().toString().equals("")) {
+ promptAlertDialog(R.string.discard, R.string.discard_detail);
return true;
}
+ }
+ finish();
+ return true;
+ } else if (itemId == R.id.action_send_submit_crosspost_activity) {
+ if (!subredditSelected) {
+ Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
+ return true;
+ }
- isPosting = true;
+ if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
+ Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
+ return true;
+ }
- item.setEnabled(false);
- item.getIcon().setAlpha(130);
+ isPosting = true;
- mPostingSnackbar.show();
+ item.setEnabled(false);
+ item.getIcon().setAlpha(130);
- String subredditName;
- if (subredditIsUser) {
- subredditName = "u_" + subredditNameTextView.getText().toString();
- } else {
- subredditName = subredditNameTextView.getText().toString();
- }
+ mPostingSnackbar.show();
- Intent intent = new Intent(this, SubmitPostService.class);
- intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
- intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
- intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
- if (post.isCrosspost()) {
- intent.putExtra(SubmitPostService.EXTRA_CONTENT, "t3_" + post.getCrosspostParentId());
- } else {
- intent.putExtra(SubmitPostService.EXTRA_CONTENT, post.getFullName());
- }
- intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_CROSSPOST);
- intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
- intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
- intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
- intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_CROSSPOST);
- ContextCompat.startForegroundService(this, intent);
+ String subredditName;
+ if (subredditIsUser) {
+ subredditName = "u_" + subredditNameTextView.getText().toString();
+ } else {
+ subredditName = subredditNameTextView.getText().toString();
+ }
- return true;
+ Intent intent = new Intent(this, SubmitPostService.class);
+ intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
+ intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
+ intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
+ if (post.isCrosspost()) {
+ intent.putExtra(SubmitPostService.EXTRA_CONTENT, "t3_" + post.getCrosspostParentId());
+ } else {
+ intent.putExtra(SubmitPostService.EXTRA_CONTENT, post.getFullName());
+ }
+ intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_CROSSPOST);
+ intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
+ intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
+ intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
+ intent.putExtra(SubmitPostService.EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, receivePostReplyNotificationsSwitchMaterial.isChecked());
+ intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_CROSSPOST);
+ ContextCompat.startForegroundService(this, intent);
+
+ return true;
}
return false;
@@ -588,7 +604,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
}
@Subscribe
- public void onSubmitTextPostEvent(SubmitCrosspostEvent submitCrosspostEvent) {
+ public void onSubmitCrosspostEvent(SubmitCrosspostEvent submitCrosspostEvent) {
isPosting = false;
mPostingSnackbar.dismiss();
if (submitCrosspostEvent.postSuccess) {
@@ -597,8 +613,8 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
startActivity(intent);
finish();
} else {
- mMenu.findItem(R.id.action_send_post_text_activity).setEnabled(true);
- mMenu.findItem(R.id.action_send_post_text_activity).getIcon().setAlpha(255);
+ mMenu.findItem(R.id.action_send_submit_crosspost_activity).setEnabled(true);
+ mMenu.findItem(R.id.action_send_submit_crosspost_activity).getIcon().setAlpha(255);
if (submitCrosspostEvent.errorMessage == null || submitCrosspostEvent.errorMessage.equals("")) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java
index 69b83579..f2d00212 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java
@@ -19,7 +19,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.lifecycle.ViewModelProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -41,6 +40,7 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.adapters.SubredditMultiselectionRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditViewModel;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
@@ -83,7 +83,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
public SubscribedSubredditViewModel mSubscribedSubredditViewModel;
private String mAccessToken;
private String mAccountName;
- private LinearLayoutManager mLinearLayoutManager;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
private SubredditMultiselectionRecyclerViewAdapter mAdapter;
private RequestManager mGlide;
@@ -142,7 +142,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
}
private void bindView() {
- mLinearLayoutManager = new LinearLayoutManager(this);
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(this);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
mAdapter = new SubredditMultiselectionRecyclerViewAdapter(this, mCustomThemeWrapper);
mRecyclerView.setAdapter(mAdapter);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java
index e5b2e225..0d33b2a8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java
@@ -47,6 +47,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.asynctasks.InsertMultireddit;
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed;
import ml.docilealligator.infinityforreddit.events.GoBackToMainPageEvent;
import ml.docilealligator.infinityforreddit.events.RefreshMultiRedditsEvent;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
@@ -77,7 +78,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
@BindView(R.id.tab_layout_subscribed_thing_listing_activity)
TabLayout tabLayout;
@BindView(R.id.view_pager_subscribed_thing_listing_activity)
- ViewPager viewPager;
+ ViewPagerBugFixed viewPager;
@BindView(R.id.fab_subscribed_thing_listing_activity)
FloatingActionButton fab;
@Inject
@@ -211,7 +212,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
tabLayout.setupWithViewPager(viewPager);
if (showMultiReddits) {
- viewPager.setCurrentItem(2);
+ viewPager.setCurrentItem(2, false);
}
loadSubscriptions(false);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java
new file mode 100644
index 00000000..ca1a5887
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java
@@ -0,0 +1,328 @@
+package ml.docilealligator.infinityforreddit.activities;
+
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Handler;
+import android.util.DisplayMetrics;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.widget.Toolbar;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+
+import com.bumptech.glide.Glide;
+import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.appbar.CollapsingToolbarLayout;
+import com.r0adkll.slidr.Slidr;
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.concurrent.Executor;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.TrendingSearch;
+import ml.docilealligator.infinityforreddit.adapters.TrendingSearchRecyclerViewAdapter;
+import ml.docilealligator.infinityforreddit.apis.RedditAPI;
+import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
+import ml.docilealligator.infinityforreddit.post.ParsePost;
+import ml.docilealligator.infinityforreddit.post.Post;
+import ml.docilealligator.infinityforreddit.utils.APIUtils;
+import ml.docilealligator.infinityforreddit.utils.JSONUtils;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.utils.Utils;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+
+public class TrendingActivity extends BaseActivity {
+
+ private static final String TRENDING_SEARCHES_STATE = "TSS";
+
+ @BindView(R.id.coordinator_layout_trending_activity)
+ CoordinatorLayout coordinatorLayout;
+ @BindView(R.id.collapsing_toolbar_layout_trending_activity)
+ CollapsingToolbarLayout collapsingToolbarLayout;
+ @BindView(R.id.appbar_layout_trending_activity)
+ AppBarLayout appBarLayout;
+ @BindView(R.id.toolbar_trending_activity)
+ Toolbar toolbar;
+ @BindView(R.id.swipe_refresh_layout_trending_activity)
+ SwipeRefreshLayout swipeRefreshLayout;
+ @BindView(R.id.recycler_view_trending_activity)
+ RecyclerView recyclerView;
+ @BindView(R.id.fetch_trending_search_linear_layout_trending_activity)
+ LinearLayout errorLinearLayout;
+ @BindView(R.id.fetch_trending_search_image_view_trending_activity)
+ ImageView errorImageView;
+ @BindView(R.id.fetch_trending_search_text_view_trending_activity)
+ TextView errorTextView;
+ @Inject
+ @Named("oauth")
+ Retrofit mOauthRetrofit;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ @Inject
+ @Named("post_layout")
+ SharedPreferences mPostLayoutSharedPreferences;
+ @Inject
+ @Named("current_account")
+ SharedPreferences mCurrentAccountSharedPreferences;
+ @Inject
+ CustomThemeWrapper mCustomThemeWrapper;
+ @Inject
+ Executor mExecutor;
+ private String mAccessToken;
+ private String mAccountName;
+ private boolean isRefreshing = false;
+ private ArrayList<TrendingSearch> trendingSearches;
+ private TrendingSearchRecyclerViewAdapter adapter;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_trending);
+
+ ButterKnife.bind(this);
+
+ EventBus.getDefault().register(this);
+
+ applyCustomTheme();
+
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) {
+ Slidr.attach(this);
+ }
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ Window window = getWindow();
+
+ if (isChangeStatusBarIconColor()) {
+ addOnOffsetChangedListener(appBarLayout);
+ }
+
+ if (isImmersiveInterface()) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ coordinatorLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
+ View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
+ View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
+ } else {
+ window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
+ }
+ adjustToolbar(toolbar);
+
+ int navBarResourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
+ if (navBarResourceId > 0) {
+ recyclerView.setPadding(0, 0, 0, recyclerView.getPaddingBottom() + getResources().getDimensionPixelSize(navBarResourceId));
+ }
+ }
+ }
+
+ setSupportActionBar(toolbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setToolbarGoToTop(toolbar);
+
+ mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
+ mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
+
+ DisplayMetrics displayMetrics = new DisplayMetrics();
+ getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
+ int windowWidth = displayMetrics.widthPixels;
+
+ String dataSavingModeString = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
+ boolean dataSavingMode = false;
+ if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ALWAYS)) {
+ dataSavingMode = true;
+ } else if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
+ int networkType = Utils.getConnectedNetwork(this);
+ dataSavingMode = networkType == Utils.NETWORK_TYPE_CELLULAR;
+ }
+ boolean disableImagePreview = mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
+ adapter = new TrendingSearchRecyclerViewAdapter(this, mCustomThemeWrapper, windowWidth,
+ dataSavingMode, disableImagePreview, new TrendingSearchRecyclerViewAdapter.ItemClickListener() {
+ @Override
+ public void onClick(TrendingSearch trendingSearch) {
+ Intent intent = new Intent(TrendingActivity.this, SearchResultActivity.class);
+ intent.putExtra(SearchResultActivity.EXTRA_QUERY, trendingSearch.queryString);
+ intent.putExtra(SearchResultActivity.EXTRA_TRENDING_SOURCE, "trending");
+ startActivity(intent);
+ }
+ });
+ recyclerView.setAdapter(adapter);
+
+ swipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true));
+ swipeRefreshLayout.setOnRefreshListener(this::fetchTrendingSearches);
+
+ if (savedInstanceState != null) {
+ trendingSearches = savedInstanceState.getParcelableArrayList(TRENDING_SEARCHES_STATE);
+ }
+ if (trendingSearches != null) {
+ adapter.setTrendingSearches(trendingSearches);
+ } else {
+ fetchTrendingSearches();
+ }
+ }
+
+ private void fetchTrendingSearches() {
+ if (isRefreshing) {
+ return;
+ }
+ isRefreshing = true;
+
+ errorLinearLayout.setVisibility(View.GONE);
+ Glide.with(this).clear(errorImageView);
+ swipeRefreshLayout.setRefreshing(true);
+ trendingSearches = null;
+ adapter.setTrendingSearches(null);
+ Handler handler = new Handler();
+ mOauthRetrofit.create(RedditAPI.class).getTrendingSearches(APIUtils.getOAuthHeader(mAccessToken)).enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if (response.isSuccessful()) {
+ mExecutor.execute(() -> {
+ try {
+ JSONArray trendingSearchesArray = new JSONObject(response.body()).getJSONArray(JSONUtils.TRENDING_SEARCHES_KEY);
+ ArrayList<TrendingSearch> trendingSearchList = new ArrayList<>();
+ for (int i = 0; i < trendingSearchesArray.length(); i++) {
+ try {
+ JSONObject trendingSearchObject = trendingSearchesArray.getJSONObject(i);
+ String queryString = trendingSearchObject.getString(JSONUtils.QUERY_STRING_KEY);
+ String displayString = trendingSearchObject.getString(JSONUtils.DISPLAY_STRING_KEY);
+ JSONArray childrenWithOnlyOneChild = trendingSearchObject
+ .getJSONObject(JSONUtils.RESULTS_KEY)
+ .getJSONObject(JSONUtils.DATA_KEY)
+ .getJSONArray(JSONUtils.CHILDREN_KEY);
+ if (childrenWithOnlyOneChild.length() > 0) {
+ Post post = ParsePost.parseBasicData(childrenWithOnlyOneChild.getJSONObject(0)
+ .getJSONObject(JSONUtils.DATA_KEY));
+
+ trendingSearchList.add(new TrendingSearch(queryString, displayString,
+ post.getTitle(), post.getPreviews()));
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ }
+
+ handler.post(() -> {
+ trendingSearches = trendingSearchList;
+ swipeRefreshLayout.setRefreshing(false);
+ adapter.setTrendingSearches(trendingSearches);
+ isRefreshing = false;
+ });
+ } catch (JSONException e) {
+ e.printStackTrace();
+ handler.post(() -> {
+ swipeRefreshLayout.setRefreshing(false);
+ showErrorView(R.string.error_parse_trending_search);
+ isRefreshing = false;
+ });
+ }
+ });
+ } else {
+ handler.post(() -> {
+ swipeRefreshLayout.setRefreshing(false);
+ showErrorView(R.string.error_fetch_trending_search);
+ isRefreshing = false;
+ });
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ handler.post(() -> {
+ swipeRefreshLayout.setRefreshing(false);
+ showErrorView(R.string.error_fetch_trending_search);
+ isRefreshing = false;
+ });
+ }
+ });
+ }
+
+ private void showErrorView(int stringId) {
+ errorLinearLayout.setVisibility(View.VISIBLE);
+ Glide.with(this).load(R.drawable.error_image).into(errorImageView);
+ errorTextView.setText(stringId);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.trending_activity, menu);
+ applyMenuItemTheme(menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ } else if (item.getItemId() == R.id.action_refresh_trending_activity) {
+ fetchTrendingSearches();
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putParcelableArrayList(TRENDING_SEARCHES_STATE, trendingSearches);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ EventBus.getDefault().unregister(this);
+ }
+
+ @Override
+ protected SharedPreferences getDefaultSharedPreferences() {
+ return mSharedPreferences;
+ }
+
+ @Override
+ protected CustomThemeWrapper getCustomThemeWrapper() {
+ return mCustomThemeWrapper;
+ }
+
+ @Override
+ protected void applyCustomTheme() {
+ coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
+ applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
+ swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground());
+ swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
+ errorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor());
+ }
+
+ @Subscribe
+ public void onAccountSwitchEvent(SwitchAccountEvent event) {
+ finish();
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java
index 3988d3c8..9602da8b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java
@@ -12,11 +12,14 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
+import android.text.Spanned;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -42,6 +45,7 @@ import com.github.piasy.biv.loader.ImageLoader;
import com.github.piasy.biv.loader.glide.GlideImageLoader;
import com.github.piasy.biv.view.BigImageView;
import com.github.piasy.biv.view.GlideImageViewFactory;
+import com.google.android.material.bottomappbar.BottomAppBar;
import com.r0adkll.slidr.Slidr;
import com.r0adkll.slidr.model.SlidrConfig;
import com.r0adkll.slidr.model.SlidrPosition;
@@ -85,6 +89,16 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
BigImageView mImageView;
@BindView(R.id.load_image_error_linear_layout_view_image_or_gif_activity)
LinearLayout mLoadErrorLinearLayout;
+ @BindView(R.id.bottom_navigation_view_image_or_gif_activity)
+ BottomAppBar bottomAppBar;
+ @BindView(R.id.title_text_view_view_image_or_gif_activity)
+ TextView titleTextView;
+ @BindView(R.id.download_image_view_view_image_or_gif_activity)
+ ImageView downloadImageView;
+ @BindView(R.id.share_image_view_view_image_or_gif_activity)
+ ImageView shareImageView;
+ @BindView(R.id.wallpaper_image_view_view_image_or_gif_activity)
+ ImageView wallpaperImageView;
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
@@ -130,11 +144,6 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
ButterKnife.bind(this);
- ActionBar actionBar = getSupportActionBar();
- Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
- actionBar.setHomeAsUpIndicator(upArrow);
- actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
-
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_VERTICALLY_TO_GO_BACK_FROM_MEDIA, true)) {
Slidr.attach(this, new SlidrConfig.Builder().position(SlidrPosition.VERTICAL).distanceThreshold(0.125f).build());
}
@@ -151,10 +160,44 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
String postTitle = intent.getStringExtra(EXTRA_POST_TITLE_KEY);
mSubredditName = intent.getStringExtra(EXTRA_SUBREDDIT_OR_USERNAME_KEY);
+ boolean useBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER, false);
if (postTitle != null) {
- setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
+ Spanned title = Html.fromHtml(String.format("<small>%s</small>", postTitle));
+ if (useBottomAppBar) {
+ titleTextView.setText(title);
+ } else {
+ setTitle(title);
+ }
} else {
- setTitle("");
+ if (!useBottomAppBar) {
+ setTitle("");
+ }
+ }
+
+ if (useBottomAppBar) {
+ getSupportActionBar().hide();
+ bottomAppBar.setVisibility(View.VISIBLE);
+ downloadImageView.setOnClickListener(view -> {
+ if (isDownloading) {
+ return;
+ }
+ isDownloading = true;
+ requestPermissionAndDownload();
+ });
+ shareImageView.setOnClickListener(view -> {
+ if (isGif)
+ shareGif();
+ else
+ shareImage();
+ });
+ wallpaperImageView.setOnClickListener(view -> {
+ setWallpaper();
+ });
+ } else {
+ ActionBar actionBar = getSupportActionBar();
+ Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
+ actionBar.setHomeAsUpIndicator(upArrow);
+ actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
}
mLoadErrorLinearLayout.setOnClickListener(view -> {
@@ -170,6 +213,9 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
isActionBarHidden = false;
+ if (useBottomAppBar) {
+ bottomAppBar.setVisibility(View.VISIBLE);
+ }
} else {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
@@ -179,6 +225,9 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
isActionBarHidden = true;
+ if (useBottomAppBar) {
+ bottomAppBar.setVisibility(View.GONE);
+ }
}
});
@@ -287,26 +336,8 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
if (isDownloading) {
return false;
}
-
isDownloading = true;
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- if (ContextCompat.checkSelfPermission(this,
- Manifest.permission.WRITE_EXTERNAL_STORAGE)
- != PackageManager.PERMISSION_GRANTED) {
-
- // Permission is not granted
- // No explanation needed; request the permission
- ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
- PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
- } else {
- // Permission has already been granted
- download();
- }
- } else {
- download();
- }
-
+ requestPermissionAndDownload();
return true;
} else if (itemId == R.id.action_share_view_image_or_gif_activity) {
if (isGif)
@@ -315,31 +346,32 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
shareImage();
return true;
} else if (itemId == R.id.action_set_wallpaper_view_image_or_gif_activity) {
- if (!isGif) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment();
- setAsWallpaperBottomSheetFragment.show(getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag());
- } else {
- WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.BOTH_SCREENS, this,
- new WallpaperSetter.SetWallpaperListener() {
- @Override
- public void success() {
- Toast.makeText(ViewImageOrGifActivity.this, R.string.wallpaper_set, Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void failed() {
- Toast.makeText(ViewImageOrGifActivity.this, R.string.error_set_wallpaper, Toast.LENGTH_SHORT).show();
- }
- });
- }
- }
+ setWallpaper();
return true;
}
return false;
}
+ private void requestPermissionAndDownload() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
+ if (ContextCompat.checkSelfPermission(this,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ != PackageManager.PERMISSION_GRANTED) {
+
+ // Permission is not granted
+ // No explanation needed; request the permission
+ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
+ PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
+ } else {
+ // Permission has already been granted
+ download();
+ }
+ } else {
+ download();
+ }
+ }
+
private void download() {
isDownloading = false;
@@ -433,6 +465,28 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
}).submit();
}
+ private void setWallpaper() {
+ if (!isGif) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment();
+ setAsWallpaperBottomSheetFragment.show(getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag());
+ } else {
+ WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.BOTH_SCREENS, this,
+ new WallpaperSetter.SetWallpaperListener() {
+ @Override
+ public void success() {
+ Toast.makeText(ViewImageOrGifActivity.this, R.string.wallpaper_set, Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void failed() {
+ Toast.makeText(ViewImageOrGifActivity.this, R.string.error_set_wallpaper, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+ }
+ }
+
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java
index c16cef7d..8aab0011 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java
@@ -36,7 +36,13 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ImgurMedia;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback;
+import ml.docilealligator.infinityforreddit.WallpaperSetter;
import ml.docilealligator.infinityforreddit.apis.ImgurAPI;
+import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed;
import ml.docilealligator.infinityforreddit.font.ContentFontFamily;
import ml.docilealligator.infinityforreddit.font.ContentFontStyle;
import ml.docilealligator.infinityforreddit.font.FontFamily;
@@ -45,14 +51,9 @@ import ml.docilealligator.infinityforreddit.font.TitleFontFamily;
import ml.docilealligator.infinityforreddit.font.TitleFontStyle;
import ml.docilealligator.infinityforreddit.fragments.ViewImgurImageFragment;
import ml.docilealligator.infinityforreddit.fragments.ViewImgurVideoFragment;
-import ml.docilealligator.infinityforreddit.ImgurMedia;
-import ml.docilealligator.infinityforreddit.Infinity;
-import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback;
import ml.docilealligator.infinityforreddit.utils.APIUtils;
import ml.docilealligator.infinityforreddit.utils.JSONUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
-import ml.docilealligator.infinityforreddit.WallpaperSetter;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@@ -72,11 +73,12 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa
@BindView(R.id.progress_bar_view_imgur_media_activity)
ProgressBar progressBar;
@BindView(R.id.view_pager_view_imgur_media_activity)
- ViewPager viewPager;
+ ViewPagerBugFixed viewPager;
@BindView(R.id.load_image_error_linear_layout_view_imgur_media_activity)
LinearLayout errorLinearLayout;
private SectionsPagerAdapter sectionsPagerAdapter;
private ArrayList<ImgurMedia> images;
+ private boolean useBottomAppBar;
@Inject
@Named("imgur")
Retrofit imgurRetrofit;
@@ -116,12 +118,17 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa
ButterKnife.bind(this);
- ActionBar actionBar = getSupportActionBar();
- Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
- actionBar.setHomeAsUpIndicator(upArrow);
- actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
+ useBottomAppBar = sharedPreferences.getBoolean(SharedPreferencesUtils.USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER, false);
- setTitle(" ");
+ if (!useBottomAppBar) {
+ ActionBar actionBar = getSupportActionBar();
+ Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
+ actionBar.setHomeAsUpIndicator(upArrow);
+ actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
+ setTitle(" ");
+ } else {
+ getSupportActionBar().hide();
+ }
String imgurId = getIntent().getStringExtra(EXTRA_IMGUR_ID);
if (imgurId == null) {
@@ -153,6 +160,10 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa
errorLinearLayout.setOnClickListener(view -> fetchImgurMedia(imgurId));
}
+ public boolean isUseBottomAppBar() {
+ return useBottomAppBar;
+ }
+
private void fetchImgurMedia(String imgurId) {
errorLinearLayout.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
@@ -264,15 +275,18 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa
}
private void setupViewPager() {
- setToolbarTitle(0);
+ if (!useBottomAppBar) {
+ setToolbarTitle(0);
+ viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
+ @Override
+ public void onPageSelected(int position) {
+ setToolbarTitle(position);
+ }
+ });
+ }
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
- viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
- @Override
- public void onPageSelected(int position) {
- setToolbarTitle(position);
- }
- });
viewPager.setAdapter(sectionsPagerAdapter);
+ viewPager.setOffscreenPageLimit(3);
}
private void setToolbarTitle(int position) {
@@ -378,12 +392,16 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa
ViewImgurVideoFragment fragment = new ViewImgurVideoFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(ViewImgurVideoFragment.EXTRA_IMGUR_VIDEO, imgurMedia);
+ bundle.putInt(ViewImgurVideoFragment.EXTRA_INDEX, position);
+ bundle.putInt(ViewImgurVideoFragment.EXTRA_MEDIA_COUNT, images.size());
fragment.setArguments(bundle);
return fragment;
} else {
ViewImgurImageFragment fragment = new ViewImgurImageFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(ViewImgurImageFragment.EXTRA_IMGUR_IMAGES, imgurMedia);
+ bundle.putInt(ViewImgurImageFragment.EXTRA_INDEX, position);
+ bundle.putInt(ViewImgurImageFragment.EXTRA_MEDIA_COUNT, images.size());
fragment.setArguments(bundle);
return fragment;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java
index 34fbc55a..ae3538b1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java
@@ -1,8 +1,11 @@
package ml.docilealligator.infinityforreddit.activities;
+import static ml.docilealligator.infinityforreddit.activities.CommentActivity.RETURN_EXTRA_COMMENT_DATA_KEY;
+
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.res.ColorStateList;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -11,6 +14,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
+import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -27,8 +31,11 @@ import com.evernote.android.state.State;
import com.github.piasy.biv.BigImageViewer;
import com.github.piasy.biv.loader.glide.GlideImageLoader;
import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.card.MaterialCardView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
+import com.google.android.material.textfield.TextInputEditText;
+import com.google.android.material.textfield.TextInputLayout;
import com.livefront.bridge.Bridge;
import com.r0adkll.slidr.Slidr;
import com.r0adkll.slidr.model.SlidrInterface;
@@ -62,8 +69,6 @@ import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
-import static ml.docilealligator.infinityforreddit.activities.CommentActivity.RETURN_EXTRA_COMMENT_DATA_KEY;
-
public class ViewPostDetailActivity extends BaseActivity implements SortTypeSelectionCallback, ActivityToolbarInterface {
public static final String EXTRA_POST_DATA = "EPD";
@@ -89,6 +94,18 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
ViewPager2 viewPager2;
@BindView(R.id.fab_view_post_detail_activity)
FloatingActionButton fab;
+ @BindView(R.id.search_panel_material_card_view_view_post_detail_activity)
+ MaterialCardView searchPanelMaterialCardView;
+ @BindView(R.id.search_text_input_layout_view_post_detail_activity)
+ TextInputLayout searchTextInputLayout;
+ @BindView(R.id.search_text_input_edit_text_view_post_detail_activity)
+ TextInputEditText searchTextInputEditText;
+ @BindView(R.id.previous_result_image_view_view_post_detail_activity)
+ ImageView previousResultImageView;
+ @BindView(R.id.next_result_image_view_view_post_detail_activity)
+ ImageView nextResultImageView;
+ @BindView(R.id.close_search_panel_image_view_view_post_detail_activity)
+ ImageView closeSearchPanelImageView;
@Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@@ -160,6 +177,11 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
params.bottomMargin += navBarHeight;
fab.setLayoutParams(params);
+
+ searchPanelMaterialCardView.setContentPadding(searchPanelMaterialCardView.getPaddingStart(),
+ searchPanelMaterialCardView.getPaddingTop(),
+ searchPanelMaterialCardView.getPaddingEnd(),
+ searchPanelMaterialCardView.getPaddingBottom() + navBarHeight);
}
}
}
@@ -256,6 +278,14 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar);
applyFABTheme(fab);
+ searchPanelMaterialCardView.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimary()));
+ int searchPanelTextAndIconColor = mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor();
+ searchTextInputLayout.setBoxStrokeColor(searchPanelTextAndIconColor);
+ searchTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(searchPanelTextAndIconColor));
+ searchTextInputEditText.setTextColor(searchPanelTextAndIconColor);
+ previousResultImageView.setColorFilter(searchPanelTextAndIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ nextResultImageView.setColorFilter(searchPanelTextAndIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ closeSearchPanelImageView.setColorFilter(searchPanelTextAndIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
}
private void checkNewAccountAndBindView(Bundle savedInstanceState) {
@@ -284,6 +314,31 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
if (savedInstanceState == null) {
viewPager2.setCurrentItem(getIntent().getIntExtra(EXTRA_POST_LIST_POSITION, 0), false);
}
+
+ searchPanelMaterialCardView.setOnClickListener(null);
+
+ nextResultImageView.setOnClickListener(view -> {
+ ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment();
+ if (fragment != null) {
+ searchComment(fragment, true);
+ }
+ });
+
+ previousResultImageView.setOnClickListener(view -> {
+ ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment();
+ if (fragment != null) {
+ searchComment(fragment, false);
+ }
+ });
+
+ closeSearchPanelImageView.setOnClickListener(view -> {
+ ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment();
+ if (fragment != null) {
+ fragment.resetSearchCommentIndex();
+ }
+
+ searchPanelMaterialCardView.setVisibility(View.GONE);
+ });
}
public boolean isNsfwSubreddit() {
@@ -372,6 +427,23 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
}
}
+ public boolean toggleSearchPanelVisibility() {
+ if (searchPanelMaterialCardView.getVisibility() == View.GONE) {
+ searchPanelMaterialCardView.setVisibility(View.VISIBLE);
+ return false;
+ } else {
+ searchPanelMaterialCardView.setVisibility(View.GONE);
+ searchTextInputEditText.setText("");
+ return true;
+ }
+ }
+
+ public void searchComment(ViewPostDetailFragment fragment, boolean searchNextComment) {
+ if (!searchTextInputEditText.getText().toString().isEmpty()) {
+ fragment.searchComment(searchTextInputEditText.getText().toString(), searchNextComment);
+ }
+ }
+
@Subscribe
public void onAccountSwitchEvent(SwitchAccountEvent event) {
if (!getClass().getName().equals(event.excludeActivityClassName)) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java
index b7f914b9..ad09e76e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java
@@ -14,7 +14,6 @@ import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.transition.AutoTransition;
import androidx.transition.TransitionManager;
@@ -39,6 +38,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.adapters.PrivateMessagesDetailRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.asynctasks.LoadUserData;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.events.RepliedToPrivateMessageEvent;
import ml.docilealligator.infinityforreddit.message.Message;
import ml.docilealligator.infinityforreddit.message.ReadMessage;
@@ -87,7 +87,7 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
- private LinearLayoutManager mLinearLayoutManager;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
private PrivateMessagesDetailRecyclerViewAdapter mAdapter;
private Message privateMessage;
private String mAccessToken;
@@ -154,7 +154,7 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
}
mAdapter = new PrivateMessagesDetailRecyclerViewAdapter(this, mSharedPreferences,
getResources().getConfiguration().locale, privateMessage, mAccountName, mCustomThemeWrapper);
- mLinearLayoutManager = new LinearLayoutManager(this);
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(this);
mLinearLayoutManager.setStackFromEnd(true);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
mRecyclerView.setAdapter(mAdapter);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java
index 267bd56b..b5047cc6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java
@@ -28,6 +28,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.customviews.ViewPagerBugFixed;
import ml.docilealligator.infinityforreddit.font.ContentFontFamily;
import ml.docilealligator.infinityforreddit.font.ContentFontStyle;
import ml.docilealligator.infinityforreddit.font.FontFamily;
@@ -51,10 +52,11 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
@BindView(R.id.hauler_view_view_reddit_gallery_activity)
HaulerView haulerView;
@BindView(R.id.view_pager_view_reddit_gallery_activity)
- ViewPager viewPager;
+ ViewPagerBugFixed viewPager;
private SectionsPagerAdapter sectionsPagerAdapter;
private ArrayList<Post.Gallery> gallery;
private String subredditName;
+ private boolean useBottomAppBar;
@Inject
@Named("default")
SharedPreferences sharedPreferences;
@@ -91,12 +93,17 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
ButterKnife.bind(this);
- ActionBar actionBar = getSupportActionBar();
- Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
- actionBar.setHomeAsUpIndicator(upArrow);
- actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
+ useBottomAppBar = sharedPreferences.getBoolean(SharedPreferencesUtils.USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER, false);
- setTitle(" ");
+ if (!useBottomAppBar) {
+ ActionBar actionBar = getSupportActionBar();
+ Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
+ actionBar.setHomeAsUpIndicator(upArrow);
+ actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
+ setTitle(" ");
+ } else {
+ getSupportActionBar().hide();
+ }
gallery = getIntent().getParcelableArrayListExtra(EXTRA_REDDIT_GALLERY);
if (gallery == null || gallery.isEmpty()) {
@@ -118,16 +125,23 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
setupViewPager();
}
+ public boolean isUseBottomAppBar() {
+ return useBottomAppBar;
+ }
+
private void setupViewPager() {
- setToolbarTitle(0);
+ if (!useBottomAppBar) {
+ setToolbarTitle(0);
+ viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
+ @Override
+ public void onPageSelected(int position) {
+ setToolbarTitle(position);
+ }
+ });
+ }
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
- viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
- @Override
- public void onPageSelected(int position) {
- setToolbarTitle(position);
- }
- });
viewPager.setAdapter(sectionsPagerAdapter);
+ viewPager.setOffscreenPageLimit(3);
}
private void setToolbarTitle(int position) {
@@ -230,6 +244,8 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
Bundle bundle = new Bundle();
bundle.putParcelable(ViewRedditGalleryVideoFragment.EXTRA_REDDIT_GALLERY_VIDEO, media);
bundle.putString(ViewRedditGalleryVideoFragment.EXTRA_SUBREDDIT_NAME, subredditName);
+ bundle.putInt(ViewRedditGalleryVideoFragment.EXTRA_INDEX, position);
+ bundle.putInt(ViewRedditGalleryVideoFragment.EXTRA_MEDIA_COUNT, gallery.size());
fragment.setArguments(bundle);
return fragment;
} else {
@@ -237,6 +253,8 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
Bundle bundle = new Bundle();
bundle.putParcelable(ViewRedditGalleryImageOrGifFragment.EXTRA_REDDIT_GALLERY_MEDIA, media);
bundle.putString(ViewRedditGalleryImageOrGifFragment.EXTRA_SUBREDDIT_NAME, subredditName);
+ bundle.putInt(ViewRedditGalleryImageOrGifFragment.EXTRA_INDEX, position);
+ bundle.putInt(ViewRedditGalleryImageOrGifFragment.EXTRA_MEDIA_COUNT, gallery.size());
fragment.setArguments(bundle);
return fragment;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
index bed746c4..57620c51 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
@@ -4,11 +4,13 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
+import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
+import android.text.util.Linkify;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
@@ -64,7 +66,14 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import io.noties.markwon.AbstractMarkwonPlugin;
+import io.noties.markwon.Markwon;
+import io.noties.markwon.MarkwonConfiguration;
+import io.noties.markwon.core.MarkwonTheme;
+import io.noties.markwon.linkify.LinkifyPlugin;
+import io.noties.markwon.movement.MovementMethodPlugin;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
+import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
@@ -81,12 +90,14 @@ import ml.docilealligator.infinityforreddit.asynctasks.AddSubredditOrUserToMulti
import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubreddit;
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditData;
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
+import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.RandomBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTimeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTypeBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.events.GoBackToMainPageEvent;
@@ -212,6 +223,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private String mAccessToken;
private String mAccountName;
private String subredditName;
+ private String description;
private boolean mFetchSubredditInfoSuccess = false;
private int mNCurrentOnlineSubscribers = 0;
private boolean isNsfwSubreddit = false;
@@ -373,6 +385,44 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
glide = Glide.with(this);
Locale locale = getResources().getConfiguration().locale;
+ Markwon markwon = Markwon.builder(this)
+ .usePlugin(new AbstractMarkwonPlugin() {
+ @Override
+ public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
+ builder.linkResolver((view, link) -> {
+ Intent intent = new Intent(ViewSubredditDetailActivity.this, LinkResolverActivity.class);
+ Uri uri = Uri.parse(link);
+ intent.setData(uri);
+ startActivity(intent);
+ });
+ }
+
+ @Override
+ public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
+ builder.linkColor(mCustomThemeWrapper.getLinkColor());
+ }
+ })
+ .usePlugin(MovementMethodPlugin.create(BetterLinkMovementMethod.linkify(Linkify.WEB_URLS, this).setOnLinkLongClickListener((textView, url) -> {
+ UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment();
+ Bundle bundle = new Bundle();
+ bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url);
+ urlMenuBottomSheetFragment.setArguments(bundle);
+ urlMenuBottomSheetFragment.show(getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag());
+ return true;
+ })))
+ .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)).build();
+
+ descriptionTextView.setOnLongClickListener(view -> {
+ if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
+ Bundle bundle = new Bundle();
+ bundle.putString(CopyTextBottomSheetFragment.EXTRA_RAW_TEXT, description);
+ CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
+ copyTextBottomSheetFragment.setArguments(bundle);
+ copyTextBottomSheetFragment.show(getSupportFragmentManager(), copyTextBottomSheetFragment.getTag());
+ }
+ return true;
+ });
+
mSubredditViewModel = new ViewModelProvider(this,
new SubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, subredditName))
.get(SubredditViewModel.class);
@@ -424,11 +474,12 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
nSubscribersTextView.setText(nSubscribers);
creationTimeTextView.setText(new SimpleDateFormat("MMM d, yyyy",
locale).format(subredditData.getCreatedUTC()));
- if (hideSubredditDescription || subredditData.getDescription().equals("")) {
+ description = subredditData.getDescription();
+ if (hideSubredditDescription || description.equals("")) {
descriptionTextView.setVisibility(View.GONE);
} else {
descriptionTextView.setVisibility(View.VISIBLE);
- descriptionTextView.setText(subredditData.getDescription());
+ markwon.setMarkdown(descriptionTextView, description);
}
if (subredditData.isNSFW()) {
@@ -1114,6 +1165,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
Intent intent = new Intent(this, MultiredditSelectionActivity.class);
startActivityForResult(intent, ADD_TO_MULTIREDDIT_REQUEST_CODE);
+ } else if (itemId == R.id.action_add_to_post_filter_view_subreddit_detail_activity) {
+ Intent intent = new Intent(this, PostFilterPreferenceActivity.class);
+ intent.putExtra(PostFilterPreferenceActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(intent);
+ return true;
} else if (itemId == R.id.action_share_view_subreddit_detail_activity) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
@@ -1228,6 +1284,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
intent = new Intent(this, PostVideoActivity.class);
intent.putExtra(PostVideoActivity.EXTRA_SUBREDDIT_NAME, subredditName);
startActivity(intent);
+ break;
+ case PostTypeBottomSheetFragment.TYPE_GALLERY:
+ intent = new Intent(this, PostGalleryActivity.class);
+ intent.putExtra(PostVideoActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(intent);
}
}
@@ -1431,7 +1492,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
startActivity(subredditIntent);
})
- .setNegativeButton(R.string.cancel, null)
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
+ }
+ })
.setOnDismissListener(dialogInterface -> {
if (imm != null) {
imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
@@ -1472,7 +1537,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
startActivity(userIntent);
})
- .setNegativeButton(R.string.cancel, null)
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
+ }
+ })
.setOnDismissListener(dialogInterface -> {
if (imm != null) {
imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java
index c1ef9ea2..d6fbb3d4 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java
@@ -981,6 +981,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
}
Intent intent = new Intent(this, MultiredditSelectionActivity.class);
startActivityForResult(intent, ADD_TO_MULTIREDDIT_REQUEST_CODE);
+ } else if (itemId == R.id.action_add_to_post_filter_view_user_detail_activity) {
+ Intent intent = new Intent(this, PostFilterPreferenceActivity.class);
+ intent.putExtra(PostFilterPreferenceActivity.EXTRA_USER_NAME, username);
+ startActivity(intent);
+ return true;
} else if (itemId == R.id.action_report_view_user_detail_activity) {
Intent reportIntent = new Intent(this, LinkResolverActivity.class);
reportIntent.setData(Uri.parse("https://www.reddithelp.com/en/categories/rules-reporting/account-and-community-restrictions/what-should-i-do-if-i-see-something-i"));
@@ -1242,7 +1247,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
startActivity(subredditIntent);
})
- .setNegativeButton(R.string.cancel, null)
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
+ }
+ })
.setOnDismissListener(dialogInterface -> {
if (imm != null) {
imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
@@ -1283,7 +1292,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
startActivity(userIntent);
})
- .setNegativeButton(R.string.cancel, null)
+ .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
+ }
+ })
.setOnDismissListener(dialogInterface -> {
if (imm != null) {
imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
@@ -1386,6 +1399,10 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
case PostTypeBottomSheetFragment.TYPE_VIDEO:
intent = new Intent(this, PostVideoActivity.class);
startActivity(intent);
+ break;
+ case PostTypeBottomSheetFragment.TYPE_GALLERY:
+ intent = new Intent(this, PostGalleryActivity.class);
+ startActivity(intent);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
index 849a3853..7362e892 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
@@ -3,8 +3,10 @@ package ml.docilealligator.infinityforreddit.activities;
import android.Manifest;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
+import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
@@ -12,14 +14,18 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
+import android.provider.Settings;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.OrientationEventListener;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -47,6 +53,7 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.CacheDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.google.android.exoplayer2.util.Util;
+import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.snackbar.Snackbar;
import com.thefuntasty.hauler.DragDirection;
import com.thefuntasty.hauler.HaulerView;
@@ -66,8 +73,11 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.apis.VReddIt;
import ml.docilealligator.infinityforreddit.font.ContentFontFamily;
+import ml.docilealligator.infinityforreddit.font.ContentFontStyle;
import ml.docilealligator.infinityforreddit.font.FontFamily;
+import ml.docilealligator.infinityforreddit.font.FontStyle;
import ml.docilealligator.infinityforreddit.font.TitleFontFamily;
+import ml.docilealligator.infinityforreddit.font.TitleFontStyle;
import ml.docilealligator.infinityforreddit.post.FetchPost;
import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.services.DownloadMediaService;
@@ -116,6 +126,12 @@ public class ViewVideoActivity extends AppCompatActivity {
ImageButton muteButton;
@BindView(R.id.hd_exo_playback_control_view)
ImageButton hdButton;
+ @BindView(R.id.bottom_navigation_exo_playback_control_view)
+ BottomAppBar bottomAppBar;
+ @BindView(R.id.title_text_view_exo_playback_control_view)
+ TextView titleTextView;
+ @BindView(R.id.download_image_view_exo_playback_control_view)
+ ImageView downloadImageView;
private Uri mVideoUri;
private SimpleExoPlayer player;
@@ -135,6 +151,7 @@ public class ViewVideoActivity extends AppCompatActivity {
private int videoType;
private boolean isDataSavingMode;
private boolean isHd;
+ private Integer originalOrientation;
@Inject
@Named("no_oauth")
@@ -170,6 +187,15 @@ public class ViewVideoActivity extends AppCompatActivity {
getTheme().applyStyle(R.style.Theme_Normal, true);
+ getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true);
+
+ getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true);
+
+ getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true);
+
getTheme().applyStyle(FontFamily.valueOf(mSharedPreferences
.getString(SharedPreferencesUtils.FONT_FAMILY_KEY, FontFamily.Default.name())).getResId(), true);
@@ -184,10 +210,31 @@ public class ViewVideoActivity extends AppCompatActivity {
ButterKnife.bind(this);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
- ActionBar actionBar = getSupportActionBar();
- Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
- actionBar.setHomeAsUpIndicator(upArrow);
- actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
+ Resources resources = getResources();
+
+ boolean useBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER, false);
+ if (useBottomAppBar) {
+ getSupportActionBar().hide();
+ bottomAppBar.setVisibility(View.VISIBLE);
+ downloadImageView.setOnClickListener(view -> {
+ if (isDownloading) {
+ return;
+ }
+
+ if (videoDownloadUrl == null) {
+ Toast.makeText(this, R.string.fetching_video_info_please_wait, Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ isDownloading = true;
+ requestPermissionAndDownload();
+ });
+ } else {
+ ActionBar actionBar = getSupportActionBar();
+ Drawable upArrow = resources.getDrawable(R.drawable.ic_arrow_back_white_24dp);
+ actionBar.setHomeAsUpIndicator(upArrow);
+ actionBar.setBackgroundDrawable(new ColorDrawable(resources.getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
+ }
String dataSavingModeString = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
int networkType = Utils.getConnectedNetwork(this);
@@ -199,18 +246,18 @@ public class ViewVideoActivity extends AppCompatActivity {
isHd = !isDataSavingMode;
if (!mSharedPreferences.getBoolean(SharedPreferencesUtils.VIDEO_PLAYER_IGNORE_NAV_BAR, false)) {
- if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || getResources().getBoolean(R.bool.isTablet)) {
+ if (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || resources.getBoolean(R.bool.isTablet)) {
//Set player controller bottom margin in order to display it above the navbar
- int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
+ int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
LinearLayout controllerLinearLayout = findViewById(R.id.linear_layout_exo_playback_control_view);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) controllerLinearLayout.getLayoutParams();
- params.bottomMargin = getResources().getDimensionPixelSize(resourceId);
+ params.bottomMargin = resources.getDimensionPixelSize(resourceId);
} else {
//Set player controller right margin in order to display it above the navbar
- int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
+ int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
LinearLayout controllerLinearLayout = findViewById(R.id.linear_layout_exo_playback_control_view);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) controllerLinearLayout.getLayoutParams();
- params.rightMargin = getResources().getDimensionPixelSize(resourceId);
+ params.rightMargin = resources.getDimensionPixelSize(resourceId);
}
}
@@ -225,13 +272,45 @@ public class ViewVideoActivity extends AppCompatActivity {
isNSFW = intent.getBooleanExtra(EXTRA_IS_NSFW, false);
if (savedInstanceState == null) {
resumePosition = intent.getLongExtra(EXTRA_PROGRESS_SECONDS, -1);
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.VIDEO_PLAYER_AUTOMATIC_LANDSCAPE_ORIENTATION, false)) {
+ originalOrientation = resources.getConfiguration().orientation;
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
+
+ if (android.provider.Settings.System.getInt(getContentResolver(),
+ Settings.System.ACCELEROMETER_ROTATION, 0) == 1) {
+ OrientationEventListener orientationEventListener = new OrientationEventListener(this) {
+ @Override
+ public void onOrientationChanged(int orientation) {
+ int epsilon = 10;
+ int leftLandscape = 90;
+ int rightLandscape = 270;
+ if(epsilonCheck(orientation, leftLandscape, epsilon) ||
+ epsilonCheck(orientation, rightLandscape, epsilon)) {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
+ disable();
+ }
+ }
+
+ private boolean epsilonCheck(int a, int b, int epsilon) {
+ return a > b - epsilon && a < b + epsilon;
+ }
+ };
+ orientationEventListener.enable();
+ }
+ }
}
if (postTitle != null) {
- setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
+ if (useBottomAppBar) {
+ titleTextView.setText(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
+ } else {
+ setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
+ }
} else {
- setTitle("");
+ if (!useBottomAppBar) {
+ setTitle("");
+ }
}
videoPlayerView.setControllerVisibilityListener(visibility -> {
@@ -539,29 +618,33 @@ public class ViewVideoActivity extends AppCompatActivity {
}
isDownloading = true;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- if (ContextCompat.checkSelfPermission(this,
- Manifest.permission.WRITE_EXTERNAL_STORAGE)
- != PackageManager.PERMISSION_GRANTED) {
-
- // Permission is not granted
- // No explanation needed; request the permission
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
- PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
- } else {
- // Permission has already been granted
- download();
- }
- } else {
- download();
- }
+ requestPermissionAndDownload();
return true;
}
return false;
}
+ private void requestPermissionAndDownload() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
+ if (ContextCompat.checkSelfPermission(this,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ != PackageManager.PERMISSION_GRANTED) {
+
+ // Permission is not granted
+ // No explanation needed; request the permission
+ ActivityCompat.requestPermissions(this,
+ new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
+ PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
+ } else {
+ // Permission has already been granted
+ download();
+ }
+ } else {
+ download();
+ }
+ }
+
@Override
protected void onStart() {
super.onStart();
@@ -575,6 +658,9 @@ public class ViewVideoActivity extends AppCompatActivity {
super.onStop();
wasPlaying = player.getPlayWhenReady();
player.setPlayWhenReady(false);
+ if (originalOrientation != null) {
+ setRequestedOrientation(originalOrientation);
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java
new file mode 100644
index 00000000..f4cc17fa
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java
@@ -0,0 +1,370 @@
+package ml.docilealligator.infinityforreddit.activities;
+
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.graphics.Color;
+import android.net.Uri;
+import android.os.Build;
+import android.os.Bundle;
+import android.text.SpannableStringBuilder;
+import android.text.Spanned;
+import android.text.TextPaint;
+import android.text.style.ClickableSpan;
+import android.text.util.Linkify;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.widget.Toolbar;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+
+import com.bumptech.glide.Glide;
+import com.google.android.material.appbar.AppBarLayout;
+import com.r0adkll.slidr.Slidr;
+import com.r0adkll.slidr.model.SlidrInterface;
+
+import org.commonmark.ext.gfm.tables.TableBlock;
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import io.noties.markwon.AbstractMarkwonPlugin;
+import io.noties.markwon.Markwon;
+import io.noties.markwon.MarkwonConfiguration;
+import io.noties.markwon.core.MarkwonTheme;
+import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
+import io.noties.markwon.html.HtmlPlugin;
+import io.noties.markwon.linkify.LinkifyPlugin;
+import io.noties.markwon.recycler.MarkwonAdapter;
+import io.noties.markwon.recycler.table.TableEntry;
+import io.noties.markwon.recycler.table.TableEntryPlugin;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.apis.RedditAPI;
+import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
+import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager;
+import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
+import ml.docilealligator.infinityforreddit.utils.JSONUtils;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+
+public class WikiActivity extends BaseActivity {
+
+ public static final String EXTRA_SUBREDDIT_NAME = "ESN";
+ private static final String WIKI_MARKDOWN_STATE = "WMS";
+
+ @BindView(R.id.coordinator_layout_comment_wiki_activity)
+ CoordinatorLayout coordinatorLayout;
+ @BindView(R.id.appbar_layout_comment_wiki_activity)
+ AppBarLayout appBarLayout;
+ @BindView(R.id.toolbar_comment_wiki_activity)
+ Toolbar toolbar;
+ @BindView(R.id.swipe_refresh_layout_wiki_activity)
+ SwipeRefreshLayout swipeRefreshLayout;
+ @BindView(R.id.content_markdown_view_comment_wiki_activity)
+ RecyclerView markdownRecyclerView;
+ @BindView(R.id.fetch_wiki_linear_layout_wiki_activity)
+ LinearLayout mFetchWikiInfoLinearLayout;
+ @BindView(R.id.fetch_wiki_image_view_wiki_activity)
+ ImageView mFetchWikiInfoImageView;
+ @BindView(R.id.fetch_wiki_text_view_wiki_activity)
+ TextView mFetchWikiInfoTextView;
+
+ @Inject
+ @Named("no_oauth")
+ Retrofit retrofit;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ @Inject
+ CustomThemeWrapper mCustomThemeWrapper;
+ private SlidrInterface mSlidrInterface;
+ private String wikiMarkdown;
+ private Markwon markwon;
+ private MarkwonAdapter markwonAdapter;
+ private boolean isRefreshing = false;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_wiki);
+
+ ButterKnife.bind(this);
+
+ EventBus.getDefault().register(this);
+
+ applyCustomTheme();
+
+ setSupportActionBar(toolbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) {
+ mSlidrInterface = Slidr.attach(this);
+ }
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ Window window = getWindow();
+
+ if (isChangeStatusBarIconColor()) {
+ addOnOffsetChangedListener(appBarLayout);
+ }
+
+ if (isImmersiveInterface()) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ coordinatorLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
+ View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
+ View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
+ } else {
+ window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
+ }
+ adjustToolbar(toolbar);
+ markdownRecyclerView.setPadding(markdownRecyclerView.getPaddingLeft(), 0, markdownRecyclerView.getPaddingRight(), getNavBarHeight());
+ }
+ }
+
+ swipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true));
+ swipeRefreshLayout.setOnRefreshListener(this::loadWiki);
+
+ int markdownColor = mCustomThemeWrapper.getPrimaryTextColor();
+ int spoilerBackgroundColor = markdownColor | 0xFF000000;
+ int linkColor = mCustomThemeWrapper.getLinkColor();
+ markwon = Markwon.builder(this)
+ .usePlugin(HtmlPlugin.create())
+ .usePlugin(new AbstractMarkwonPlugin() {
+ @NonNull
+ @Override
+ public String processMarkdown(@NonNull String markdown) {
+ StringBuilder markdownStringBuilder = new StringBuilder(markdown);
+ Pattern spoilerPattern = Pattern.compile(">![\\S\\s]*?!<");
+ Matcher matcher = spoilerPattern.matcher(markdownStringBuilder);
+ while (matcher.find()) {
+ markdownStringBuilder.replace(matcher.start(), matcher.start() + 1, "&gt;");
+ }
+ return super.processMarkdown(markdownStringBuilder.toString());
+ }
+
+ @Override
+ public void afterSetText(@NonNull TextView textView) {
+ textView.setHighlightColor(Color.TRANSPARENT);
+ SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText().toString());
+ Pattern spoilerPattern = Pattern.compile(">![\\S\\s]*?!<");
+ Matcher matcher = spoilerPattern.matcher(markdownStringBuilder);
+ int start = 0;
+ boolean find = false;
+ while (matcher.find(start)) {
+ if (markdownStringBuilder.length() < 4
+ || matcher.start() < 0
+ || matcher.end() > markdownStringBuilder.length()) {
+ break;
+ }
+ find = true;
+ markdownStringBuilder.delete(matcher.end() - 2, matcher.end());
+ markdownStringBuilder.delete(matcher.start(), matcher.start() + 2);
+ ClickableSpan clickableSpan = new ClickableSpan() {
+ private boolean isShowing = false;
+ @Override
+ public void updateDrawState(@NonNull TextPaint ds) {
+ if (isShowing) {
+ super.updateDrawState(ds);
+ ds.setColor(markdownColor);
+ } else {
+ ds.bgColor = spoilerBackgroundColor;
+ ds.setColor(markdownColor);
+ }
+ ds.setUnderlineText(false);
+ }
+
+ @Override
+ public void onClick(@NonNull View view) {
+ isShowing = !isShowing;
+ view.invalidate();
+ }
+ };
+ markdownStringBuilder.setSpan(clickableSpan, matcher.start(), matcher.end() - 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ start = matcher.end() - 4;
+ }
+ if (find) {
+ textView.setText(markdownStringBuilder);
+ }
+ }
+
+ @Override
+ public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
+ textView.setTextColor(markdownColor);
+ }
+
+ @Override
+ public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
+ builder.linkResolver((view, link) -> {
+ Intent intent = new Intent(WikiActivity.this, LinkResolverActivity.class);
+ Uri uri = Uri.parse(link);
+ intent.setData(uri);
+ startActivity(intent);
+ });
+ }
+
+ @Override
+ public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
+ builder.linkColor(linkColor);
+ }
+ })
+ .usePlugin(StrikethroughPlugin.create())
+ .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
+ .usePlugin(TableEntryPlugin.create(this))
+ .build();
+
+ markwonAdapter = MarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text)
+ .include(TableBlock.class, TableEntry.create(builder -> builder
+ .tableLayout(R.layout.adapter_table_block, R.id.table_layout)
+ .textLayoutIsRoot(R.layout.view_table_entry_cell)))
+ .build();
+ LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(this, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
+ @Override
+ public void onScrolledLeft() {
+ if (mSlidrInterface != null) {
+ mSlidrInterface.lock();
+ }
+ }
+
+ @Override
+ public void onScrolledRight() {
+ if (mSlidrInterface != null) {
+ mSlidrInterface.unlock();
+ }
+ }
+ });
+ markdownRecyclerView.setLayoutManager(linearLayoutManager);
+ markdownRecyclerView.setAdapter(markwonAdapter);
+
+ if (savedInstanceState != null) {
+ wikiMarkdown = savedInstanceState.getString(WIKI_MARKDOWN_STATE);
+ }
+
+ if (wikiMarkdown == null) {
+ loadWiki();
+ } else {
+ markwonAdapter.setMarkdown(markwon, wikiMarkdown);
+ markwonAdapter.notifyDataSetChanged();
+ }
+ }
+
+ private void loadWiki() {
+ if (isRefreshing) {
+ return;
+ }
+ isRefreshing = true;
+
+ swipeRefreshLayout.setRefreshing(true);
+
+ Glide.with(this).clear(mFetchWikiInfoImageView);
+ mFetchWikiInfoLinearLayout.setVisibility(View.GONE);
+
+ retrofit.create(RedditAPI.class).getWiki(getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME)).enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if (response.isSuccessful()) {
+ try {
+ markwonAdapter.setMarkdown(markwon, new JSONObject(response.body())
+ .getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.CONTENT_MD_KEY));
+ markwonAdapter.notifyDataSetChanged();
+ } catch (JSONException e) {
+ e.printStackTrace();
+ showErrorView(R.string.error_loading_wiki);
+ }
+ } else {
+ if (response.code() == 404 || response.code() == 403) {
+ showErrorView(R.string.no_wiki);
+ } else {
+ showErrorView(R.string.error_loading_wiki);
+ }
+ }
+ isRefreshing = false;
+ swipeRefreshLayout.setRefreshing(false);
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ showErrorView(R.string.error_loading_wiki);
+ isRefreshing = false;
+ swipeRefreshLayout.setRefreshing(false);
+ }
+ });
+ }
+
+ private void showErrorView(int stringResId) {
+ swipeRefreshLayout.setRefreshing(false);
+ mFetchWikiInfoLinearLayout.setVisibility(View.VISIBLE);
+ mFetchWikiInfoTextView.setText(stringResId);
+ Glide.with(this).load(R.drawable.error_image).into(mFetchWikiInfoImageView);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putString(WIKI_MARKDOWN_STATE, wikiMarkdown);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ EventBus.getDefault().unregister(this);
+ }
+
+ @Override
+ protected SharedPreferences getDefaultSharedPreferences() {
+ return mSharedPreferences;
+ }
+
+ @Override
+ protected CustomThemeWrapper getCustomThemeWrapper() {
+ return mCustomThemeWrapper;
+ }
+
+ @Override
+ protected void applyCustomTheme() {
+ coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
+ applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
+ swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground());
+ swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
+ mFetchWikiInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor());
+ }
+
+ @Subscribe
+ public void onAccountSwitchEvent(SwitchAccountEvent event) {
+ if (!getClass().getName().equals(event.excludeActivityClassName)) {
+ finish();
+ }
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java
index f3a9c582..15dce401 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java
@@ -16,6 +16,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
+import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
@@ -400,6 +401,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
public class CommentViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.vertical_block_indentation_item_comment)
CommentIndentationView commentIndentationView;
+ @BindView(R.id.linear_layout_item_comment)
+ LinearLayout linearLayout;
@BindView(R.id.author_text_view_item_post_comment)
TextView authorTextView;
@BindView(R.id.author_flair_text_view_item_post_comment)
@@ -455,6 +458,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
constraintSet.applyTo(bottomConstraintLayout);
}
+ linearLayout.getLayoutTransition().setAnimateParentHierarchy(false);
+
commentIndentationView.setVisibility(View.GONE);
if (mShowCommentDivider) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
index f88012b9..14f53a2d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
@@ -139,6 +139,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
private Drawable mCommentIcon;
+ private int mSearchCommentIndex = -1;
+
public CommentsRecyclerViewAdapter(AppCompatActivity activity, ViewPostDetailFragment fragment,
CustomThemeWrapper customThemeWrapper,
Executor executor, Retrofit retrofit, Retrofit oauthRetrofit,
@@ -312,14 +314,12 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
@Override
public int getItemViewType(int position) {
if (mVisibleComments.size() == 0) {
- if (position == 0) {
- if (isInitiallyLoading) {
- return VIEW_TYPE_FIRST_LOADING;
- } else if (isInitiallyLoadingFailed) {
- return VIEW_TYPE_FIRST_LOADING_FAILED;
- } else {
- return VIEW_TYPE_NO_COMMENT_PLACEHOLDER;
- }
+ if (isInitiallyLoading) {
+ return VIEW_TYPE_FIRST_LOADING;
+ } else if (isInitiallyLoadingFailed) {
+ return VIEW_TYPE_FIRST_LOADING_FAILED;
+ } else {
+ return VIEW_TYPE_NO_COMMENT_PLACEHOLDER;
}
}
@@ -514,6 +514,10 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
} else {
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
+
+ if (position == mSearchCommentIndex) {
+ holder.itemView.setBackgroundColor(Color.parseColor("#03A9F4"));
+ }
}
} else if (holder instanceof CommentFullyCollapsedViewHolder) {
Comment comment = getCurrentComment(position);
@@ -692,8 +696,10 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
}
- mVisibleComments.get(placeholderPosition).setLoadingMoreChildren(false);
- mVisibleComments.get(placeholderPosition).setLoadMoreChildrenFailed(true);
+ if (placeholderPosition >= mVisibleComments.size() || placeholderPosition < 0) {
+ mVisibleComments.get(placeholderPosition).setLoadingMoreChildren(false);
+ mVisibleComments.get(placeholderPosition).setLoadMoreChildrenFailed(true);
+ }
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setText(R.string.comment_load_more_comments_failed);
}
@@ -895,25 +901,12 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
public void initiallyLoading() {
- if (mVisibleComments.size() != 0) {
- int previousSize = mVisibleComments.size();
- mVisibleComments.clear();
- if (mIsSingleCommentThreadMode) {
- notifyItemRangeRemoved(0, previousSize + 1);
- } else {
- notifyItemRangeRemoved(0, previousSize);
- }
- }
-
- if (isInitiallyLoading || isInitiallyLoadingFailed) {
- isInitiallyLoading = true;
- isInitiallyLoadingFailed = false;
- notifyItemChanged(0);
- } else {
- isInitiallyLoading = true;
- isInitiallyLoadingFailed = false;
- notifyItemInserted(0);
- }
+ resetCommentSearchIndex();
+ notifyItemRangeRemoved(0, getItemCount());
+ mVisibleComments.clear();
+ isInitiallyLoading = true;
+ isInitiallyLoadingFailed = false;
+ notifyItemInserted(0);
}
public void initiallyLoadCommentsFailed() {
@@ -1036,9 +1029,22 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
}
+ public int getSearchCommentIndex() {
+ return mSearchCommentIndex;
+ }
+
+ public void highlightSearchResult(int searchCommentIndex) {
+ mSearchCommentIndex = searchCommentIndex;
+ }
+
+ public void resetCommentSearchIndex() {
+ mSearchCommentIndex = -1;
+ }
+
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
if (holder instanceof CommentViewHolder) {
+ holder.itemView.setBackgroundColor(mCommentBackgroundColor);
((CommentViewHolder) holder).authorTextView.setTextColor(mUsernameColor);
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
@@ -1050,7 +1056,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).replyButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
- ((CommentViewHolder) holder).itemView.setBackgroundColor(mCommentBackgroundColor);
}
}
@@ -1082,6 +1087,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
public class CommentViewHolder extends RecyclerView.ViewHolder {
+ @BindView(R.id.linear_layout_item_comment)
+ LinearLayout linearLayout;
@BindView(R.id.author_text_view_item_post_comment)
TextView authorTextView;
@BindView(R.id.author_flair_text_view_item_post_comment)
@@ -1140,6 +1147,10 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
constraintSet.applyTo(bottomConstraintLayout);
}
+ if (linearLayout.getLayoutTransition() != null) {
+ linearLayout.getLayoutTransition().setAnimateParentHierarchy(false);
+ }
+
if (mShowCommentDivider) {
commentDivider.setBackgroundColor(mDividerColor);
commentDivider.setVisibility(View.VISIBLE);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java
index fec4d3c2..54f0c090 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java
@@ -31,7 +31,7 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
public static final int CODE_BLOCK = 9;
public static final int UPLOAD_IMAGE = 10;
- private static final int ITEM_COUNT = 11;
+ private static final int ITEM_COUNT = 10;
private CustomThemeWrapper customThemeWrapper;
private ItemClickListener itemClickListener;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java
index 863b2da3..bf9dea5b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/NavigationDrawerRecyclerViewAdapter.java
@@ -56,8 +56,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
private static final int VIEW_TYPE_FAVORITE_SUBSCRIBED_SUBREDDIT = 4;
private static final int VIEW_TYPE_SUBSCRIBED_SUBREDDIT = 5;
private static final int VIEW_TYPE_ACCOUNT = 6;
- private static final int CURRENT_MENU_ITEMS = 17;
+ private static final int CURRENT_MENU_ITEMS = 20;
private static final int ACCOUNT_SECTION_ITEMS = 4;
+ private static final int REDDIT_SECTION_ITEMS = 2;
private static final int POST_SECTION_ITEMS = 5;
private static final int PREFERENCES_SECTION_ITEMS = 3;
@@ -76,6 +77,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
private boolean isLoggedIn;
private boolean isInMainPage = true;
private boolean collapseAccountSection;
+ private boolean collapseRedditSection;
private boolean collapsePostSection;
private boolean collapsePreferencesSection;
private boolean collapseFavoriteSubredditsSection;
@@ -105,6 +107,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
showAvatarOnTheRightInTheNavigationDrawer = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT, false);
isLoggedIn = accountName != null;
collapseAccountSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_ACCOUNT_SECTION, false);
+ collapseRedditSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_REDDIT_SECTION, false);
collapsePostSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_POST_SECTION, false);
collapsePreferencesSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_PREFERENCES_SECTION, false);
collapseFavoriteSubredditsSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_FAVORITE_SUBREDDITS_SECTION, false);
@@ -127,21 +130,25 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
if (isInMainPage) {
if (isLoggedIn) {
if (position == CURRENT_MENU_ITEMS - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) {
return VIEW_TYPE_MENU_GROUP_TITLE;
} else if (!hideFavoriteSubredditsSection && !favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS
- (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)
+ (collapseFavoriteSubredditsSection ? 0 : favoriteSubscribedSubreddits.size()) + 1) {
return VIEW_TYPE_MENU_GROUP_TITLE;
} else if (position > CURRENT_MENU_ITEMS - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) {
if (!favoriteSubscribedSubreddits.isEmpty() && !hideFavoriteSubredditsSection &&
!collapseFavoriteSubredditsSection && position <= CURRENT_MENU_ITEMS
- (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)
+ favoriteSubscribedSubreddits.size()) {
@@ -152,11 +159,17 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
} else if (position == 0) {
return VIEW_TYPE_NAV_HEADER;
} else if (position == 1
- || position == 6 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
- || position == 12 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ || position == (ACCOUNT_SECTION_ITEMS + 2) - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ || position == (ACCOUNT_SECTION_ITEMS + REDDIT_SECTION_ITEMS + 3)
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
+ || position == (ACCOUNT_SECTION_ITEMS + REDDIT_SECTION_ITEMS + POST_SECTION_ITEMS + 4)
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)) {
return VIEW_TYPE_MENU_GROUP_TITLE;
- } else if (position == 16 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ } else if (position == (CURRENT_MENU_ITEMS - 1) - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) {
return VIEW_TYPE_DIVIDER;
@@ -217,15 +230,13 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof NavHeaderViewHolder) {
+ RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ((NavHeaderViewHolder) holder).profileImageView.getLayoutParams();
if (showAvatarOnTheRightInTheNavigationDrawer) {
- RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ((NavHeaderViewHolder) holder).profileImageView.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_END);
- ((NavHeaderViewHolder) holder).profileImageView.setLayoutParams(params);
} else {
- RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ((NavHeaderViewHolder) holder).profileImageView.getLayoutParams();
params.removeRule(RelativeLayout.ALIGN_PARENT_END);
- ((NavHeaderViewHolder) holder).profileImageView.setLayoutParams(params);
}
+ ((NavHeaderViewHolder) holder).profileImageView.setLayoutParams(params);
if (isLoggedIn) {
((NavHeaderViewHolder) holder).karmaTextView.setText(appCompatActivity.getString(R.string.karma_info, karma));
((NavHeaderViewHolder) holder).accountNameTextView.setText(accountName);
@@ -258,7 +269,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
((NavHeaderViewHolder) holder).dropIconImageView.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_arrow_drop_up_24px));
}
- ((NavHeaderViewHolder) holder).itemView.setOnClickListener(view -> {
+ holder.itemView.setOnClickListener(view -> {
if (isInMainPage) {
if (requireAuthToAccountSection) {
BiometricManager biometricManager = BiometricManager.from(appCompatActivity);
@@ -301,15 +312,27 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24px);
}
type = 0;
- } else if (position == 6 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)) {
+ } else if (position == (ACCOUNT_SECTION_ITEMS + 2) - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)) {
+ ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_reddit);
+ if (collapseRedditSection) {
+ ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24px);
+ } else {
+ ((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24px);
+ }
+ type = 1;
+ } else if (position == (ACCOUNT_SECTION_ITEMS + REDDIT_SECTION_ITEMS + 3)
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_post);
if (collapsePostSection) {
((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24px);
} else {
((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24px);
}
- type = 1;
- } else if (position == 12 - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ type = 2;
+ } else if (position == (ACCOUNT_SECTION_ITEMS + REDDIT_SECTION_ITEMS + POST_SECTION_ITEMS + 4)
+ - (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_preferences);
if (collapsePreferencesSection) {
@@ -317,10 +340,11 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
} else {
((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24px);
}
- type = 2;
+ type = 3;
} else {
if (!hideFavoriteSubredditsSection && !favoriteSubscribedSubreddits.isEmpty() && position == CURRENT_MENU_ITEMS
- (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.favorites);
@@ -329,7 +353,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
} else {
((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24px);
}
- type = 3;
+ type = 4;
} else {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.subscriptions);
if (collapseSubscribedSubredditsSection) {
@@ -337,11 +361,11 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
} else {
((MenuGroupTitleViewHolder) holder).collapseIndicatorImageView.setImageResource(R.drawable.ic_baseline_arrow_drop_down_24px);
}
- type = 4;
+ type = 5;
}
}
- ((MenuGroupTitleViewHolder) holder).itemView.setOnClickListener(view -> {
+ holder.itemView.setOnClickListener(view -> {
switch (type) {
case 0:
if (collapseAccountSection) {
@@ -353,6 +377,15 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
}
break;
case 1:
+ if (collapseRedditSection) {
+ collapseRedditSection = !collapseRedditSection;
+ notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, REDDIT_SECTION_ITEMS);
+ } else {
+ collapseRedditSection = !collapseRedditSection;
+ notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, REDDIT_SECTION_ITEMS);
+ }
+ break;
+ case 2:
if (collapsePostSection) {
collapsePostSection = !collapsePostSection;
notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, POST_SECTION_ITEMS);
@@ -361,7 +394,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, POST_SECTION_ITEMS);
}
break;
- case 2:
+ case 3:
if (collapsePreferencesSection) {
collapsePreferencesSection = !collapsePreferencesSection;
notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, PREFERENCES_SECTION_ITEMS);
@@ -370,7 +403,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, PREFERENCES_SECTION_ITEMS);
}
break;
- case 3:
+ case 4:
if (collapseFavoriteSubredditsSection) {
collapseFavoriteSubredditsSection = !collapseFavoriteSubredditsSection;
notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, favoriteSubscribedSubreddits.size());
@@ -379,7 +412,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
notifyItemRangeRemoved(holder.getBindingAdapterPosition() + 1, favoriteSubscribedSubreddits.size());
}
break;
- case 4:
+ case 5:
if (collapseSubscribedSubredditsSection) {
collapseSubscribedSubredditsSection = !collapseSubscribedSubredditsSection;
notifyItemRangeInserted(holder.getBindingAdapterPosition() + 1, subscribedSubreddits.size());
@@ -399,14 +432,28 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
if (isInMainPage) {
if (isLoggedIn) {
int pseudoPosition = position;
- if (collapseAccountSection && collapsePostSection) {
- pseudoPosition += ACCOUNT_SECTION_ITEMS + POST_SECTION_ITEMS;
- } else if (collapseAccountSection && collapsePreferencesSection) {
- pseudoPosition += ACCOUNT_SECTION_ITEMS;
+ if (collapseAccountSection && collapseRedditSection && collapsePostSection) {
+ pseudoPosition += ACCOUNT_SECTION_ITEMS + REDDIT_SECTION_ITEMS + POST_SECTION_ITEMS;
+ } else if (collapseAccountSection && collapseRedditSection) {
+ pseudoPosition += ACCOUNT_SECTION_ITEMS + REDDIT_SECTION_ITEMS;
+ } else if (collapseAccountSection && collapsePostSection) {
+ if (position > REDDIT_SECTION_ITEMS + 2) {
+ pseudoPosition += ACCOUNT_SECTION_ITEMS + POST_SECTION_ITEMS;
+ } else {
+ pseudoPosition += ACCOUNT_SECTION_ITEMS;
+ }
+ } else if (collapseRedditSection && collapsePostSection) {
+ if (position > ACCOUNT_SECTION_ITEMS + 1) {
+ pseudoPosition += REDDIT_SECTION_ITEMS + POST_SECTION_ITEMS;
+ }
} else if (collapseAccountSection) {
pseudoPosition += ACCOUNT_SECTION_ITEMS;
- } else if (collapsePostSection) {
+ } else if (collapseRedditSection) {
if (position > ACCOUNT_SECTION_ITEMS + 1) {
+ pseudoPosition += REDDIT_SECTION_ITEMS;
+ }
+ } else if (collapsePostSection) {
+ if (position > ACCOUNT_SECTION_ITEMS + REDDIT_SECTION_ITEMS + 2) {
pseudoPosition += POST_SECTION_ITEMS;
}
}
@@ -431,32 +478,40 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
((MenuItemViewHolder) holder).menuTextView.setText(R.string.inbox);
}
((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_inbox_24dp));
- ((MenuItemViewHolder) holder).itemView.setOnClickListener(view -> {
+ holder.itemView.setOnClickListener(view -> {
Intent intent = new Intent(appCompatActivity, InboxActivity.class);
appCompatActivity.startActivity(intent);
});
break;
case 7:
+ stringId = R.string.rpan;
+ drawableId = R.drawable.ic_rpan_24dp;
+ break;
+ case 8:
+ stringId = R.string.trending;
+ drawableId = R.drawable.ic_trending_24dp;
+ break;
+ case 10:
stringId = R.string.upvoted;
drawableId = R.drawable.ic_arrow_upward_black_24dp;
break;
- case 8:
+ case 11:
stringId = R.string.downvoted;
drawableId = R.drawable.ic_arrow_downward_black_24dp;
break;
- case 9:
+ case 12:
stringId = R.string.hidden;
drawableId = R.drawable.ic_outline_lock_24dp;
break;
- case 10:
+ case 13:
stringId = R.string.account_saved_thing_activity_label;
drawableId = R.drawable.ic_outline_bookmarks_24dp;
break;
- case 11:
+ case 14:
stringId = R.string.gilded;
drawableId = R.drawable.ic_star_border_24dp;
break;
- case 13:
+ case 16:
if ((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
stringId = R.string.dark_theme;
drawableId = R.drawable.ic_dark_theme_24dp;
@@ -465,7 +520,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
drawableId = R.drawable.ic_light_theme_24dp;
}
break;
- case 14:
+ case 17:
setOnClickListener = false;
if (isNSFWEnabled) {
stringId = R.string.disable_nsfw;
@@ -475,21 +530,21 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
drawableId = R.drawable.ic_nsfw_on_24dp;
}
- ((MenuItemViewHolder) holder).itemView.setOnClickListener(view -> {
+ holder.itemView.setOnClickListener(view -> {
if (isNSFWEnabled) {
isNSFWEnabled = false;
((MenuItemViewHolder) holder).menuTextView.setText(R.string.enable_nsfw);
- ((MenuItemViewHolder) holder).imageView.setImageDrawable(appCompatActivity.getDrawable(R.drawable.ic_nsfw_on_24dp));
+ ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_nsfw_on_24dp));
itemClickListener.onMenuClick(R.string.disable_nsfw);
} else {
isNSFWEnabled = true;
((MenuItemViewHolder) holder).menuTextView.setText(R.string.disable_nsfw);
- ((MenuItemViewHolder) holder).imageView.setImageDrawable(appCompatActivity.getDrawable(R.drawable.ic_nsfw_off_24dp));
+ ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_nsfw_off_24dp));
itemClickListener.onMenuClick(R.string.enable_nsfw);
}
});
break;
- case 15:
+ case 18:
stringId = R.string.settings;
drawableId = R.drawable.ic_settings_24dp;
}
@@ -518,16 +573,16 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
drawableId = R.drawable.ic_nsfw_on_24dp;
}
- ((MenuItemViewHolder) holder).itemView.setOnClickListener(view -> {
+ holder.itemView.setOnClickListener(view -> {
if (isNSFWEnabled) {
isNSFWEnabled = false;
((MenuItemViewHolder) holder).menuTextView.setText(R.string.enable_nsfw);
- ((MenuItemViewHolder) holder).imageView.setImageDrawable(appCompatActivity.getDrawable(R.drawable.ic_nsfw_on_24dp));
+ ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_nsfw_on_24dp));
itemClickListener.onMenuClick(R.string.disable_nsfw);
} else {
isNSFWEnabled = true;
((MenuItemViewHolder) holder).menuTextView.setText(R.string.disable_nsfw);
- ((MenuItemViewHolder) holder).imageView.setImageDrawable(appCompatActivity.getDrawable(R.drawable.ic_nsfw_off_24dp));
+ ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, R.drawable.ic_nsfw_off_24dp));
itemClickListener.onMenuClick(R.string.enable_nsfw);
}
});
@@ -558,15 +613,16 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
if (stringId != 0) {
((MenuItemViewHolder) holder).menuTextView.setText(stringId);
- ((MenuItemViewHolder) holder).imageView.setImageDrawable(appCompatActivity.getDrawable(drawableId));
+ ((MenuItemViewHolder) holder).imageView.setImageDrawable(ContextCompat.getDrawable(appCompatActivity, drawableId));
if (setOnClickListener) {
int finalStringId = stringId;
- ((MenuItemViewHolder) holder).itemView.setOnClickListener(view -> itemClickListener.onMenuClick(finalStringId));
+ holder.itemView.setOnClickListener(view -> itemClickListener.onMenuClick(finalStringId));
}
}
} else if (holder instanceof FavoriteSubscribedThingViewHolder) {
SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.get(position - (CURRENT_MENU_ITEMS
- (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0))
- 1);
@@ -585,17 +641,19 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
.into(((FavoriteSubscribedThingViewHolder) holder).iconGifImageView);
}
- ((FavoriteSubscribedThingViewHolder) holder).itemView.setOnClickListener(view -> {
+ holder.itemView.setOnClickListener(view -> {
itemClickListener.onSubscribedSubredditClick(subredditName);
});
} else if (holder instanceof SubscribedThingViewHolder) {
SubscribedSubredditData subreddit = favoriteSubscribedSubreddits.isEmpty() || hideFavoriteSubredditsSection ? subscribedSubreddits.get(position - (CURRENT_MENU_ITEMS
- (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0))
- 1)
: subscribedSubreddits.get(position - (CURRENT_MENU_ITEMS
- (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0))
- (collapseFavoriteSubredditsSection ? 0 : favoriteSubscribedSubreddits.size())
@@ -615,7 +673,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
.into(((SubscribedThingViewHolder) holder).iconGifImageView);
}
- ((SubscribedThingViewHolder) holder).itemView.setOnClickListener(view -> {
+ holder.itemView.setOnClickListener(view -> {
itemClickListener.onSubscribedSubredditClick(subredditName);
});
} else if (holder instanceof AccountViewHolder) {
@@ -624,7 +682,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(128, 0)))
.into(((AccountViewHolder) holder).profileImageGifImageView);
((AccountViewHolder) holder).usernameTextView.setText(accounts.get(position - 1).getAccountName());
- ((AccountViewHolder) holder).itemView.setOnClickListener(view ->
+ holder.itemView.setOnClickListener(view ->
itemClickListener.onAccountClick(accounts.get(position - 1).getAccountName()));
}
}
@@ -669,18 +727,21 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
if (hideFavoriteSubredditsSection && hideSubscribedSubredditsSection) {
return CURRENT_MENU_ITEMS
- (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0);
} else if (hideFavoriteSubredditsSection) {
return CURRENT_MENU_ITEMS
+ (subscribedSubreddits.isEmpty() ? 0 : subscribedSubreddits.size() + 1)
- (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)
- (collapseSubscribedSubredditsSection ? subscribedSubreddits.size() : 0);
} else if (hideSubscribedSubredditsSection) {
return CURRENT_MENU_ITEMS + (favoriteSubscribedSubreddits.isEmpty() ? 0 : favoriteSubscribedSubreddits.size() + 1)
- (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)
- (collapseFavoriteSubredditsSection ? favoriteSubscribedSubreddits.size() : 0);
@@ -688,6 +749,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
return CURRENT_MENU_ITEMS + (favoriteSubscribedSubreddits.isEmpty() ? 0 : favoriteSubscribedSubreddits.size() + 1)
+ (subscribedSubreddits.isEmpty() ? 0 : subscribedSubreddits.size() + 1)
- (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0)
- (collapseFavoriteSubredditsSection ? favoriteSubscribedSubreddits.size() : 0)
@@ -695,6 +757,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
}
return CURRENT_MENU_ITEMS - 1
- (collapseAccountSection ? ACCOUNT_SECTION_ITEMS : 0)
+ - (collapseRedditSection ? REDDIT_SECTION_ITEMS : 0)
- (collapsePostSection ? POST_SECTION_ITEMS : 0)
- (collapsePreferencesSection ? PREFERENCES_SECTION_ITEMS : 0);
} else {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
index 323e22c6..5529f1fd 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
@@ -1,5 +1,7 @@
package ml.docilealligator.infinityforreddit.adapters;
+import static ml.docilealligator.infinityforreddit.activities.CommentActivity.WRITE_COMMENT_REQUEST_CODE;
+
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
@@ -33,7 +35,6 @@ import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.recyclerview.widget.ItemTouchHelper;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.RequestBuilder;
@@ -103,9 +104,9 @@ import ml.docilealligator.infinityforreddit.asynctasks.LoadUserData;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
-import ml.docilealligator.infinityforreddit.comment.Comment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager;
import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment;
import ml.docilealligator.infinityforreddit.post.Post;
@@ -116,8 +117,6 @@ import ml.docilealligator.infinityforreddit.utils.Utils;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
-import static ml.docilealligator.infinityforreddit.activities.CommentActivity.WRITE_COMMENT_REQUEST_CODE;
-
public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements CacheManager {
private static final int VIEW_TYPE_POST_DETAIL_VIDEO_AUTOPLAY = 1;
private static final int VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW = 2;
@@ -143,38 +142,32 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private String mAccessToken;
private String mAccountName;
private Post mPost;
- private ArrayList<Comment> mVisibleComments;
private String mSubredditNamePrefixed;
private Locale mLocale;
- private String mSingleCommentId;
- private boolean mIsSingleCommentThreadMode;
private boolean mNeedBlurNsfw;
private boolean mDoNotBlurNsfwInNsfwSubreddits;
private boolean mNeedBlurSpoiler;
private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime;
private String mTimeFormatPattern;
- private boolean mExpandChildren;
- private boolean mCommentToolbarHidden;
- private boolean mCommentToolbarHideOnClick;
- private boolean mSwapTapAndLong;
- private boolean mShowCommentDivider;
private boolean mShowAbsoluteNumberOfVotes;
private boolean mAutoplay = false;
private boolean mAutoplayNsfwVideos;
private boolean mMuteAutoplayingVideos;
- private boolean mFullyCollapseComment;
private double mStartAutoplayVisibleAreaOffset;
private boolean mMuteNSFWVideo;
private boolean mAutomaticallyTryRedgifs;
private boolean mDataSavingMode;
private boolean mDisableImagePreview;
private boolean mOnlyDisablePreviewInVideoAndGifPosts;
+ private boolean mHidePostType;
+ private boolean mHidePostFlair;
+ private boolean mHideTheNumberOfAwards;
+ private boolean mHideSubredditAndUserPrefix;
+ private boolean mHideTheNumberOfVotes;
+ private boolean mHideTheNumberOfComments;
+ private boolean mSeparatePostAndComments;
private PostDetailRecyclerViewAdapterCallback mPostDetailRecyclerViewAdapterCallback;
- private boolean isInitiallyLoading;
- private boolean isInitiallyLoadingFailed;
- private boolean mHasMoreComments;
- private boolean loadMoreCommentsFailed;
private int mColorAccent;
private int mCardViewColor;
@@ -202,21 +195,22 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private int mDownvotedColor;
private int mVoteAndReplyUnavailableVoteButtonColor;
private int mPostIconAndInfoColor;
- private int mCommentIconAndInfoColor;
private Drawable mCommentIcon;
private float mScale;
private ExoCreator mExoCreator;
- public PostDetailRecyclerViewAdapter(AppCompatActivity activity, ViewPostDetailFragment fragment, Executor executor, CustomThemeWrapper customThemeWrapper,
+ public PostDetailRecyclerViewAdapter(AppCompatActivity activity, ViewPostDetailFragment fragment,
+ Executor executor, CustomThemeWrapper customThemeWrapper,
Retrofit retrofit, Retrofit oauthRetrofit, Retrofit gfycatRetrofit,
- Retrofit redgifsRetrofit,
- RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
- int imageViewWidth, String accessToken, String accountName,
- Post post, Locale locale, String singleCommentId,
- boolean isSingleCommentThreadMode,
+ Retrofit redgifsRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
+ RequestManager glide, int imageViewWidth,
+ boolean separatePostAndComments, String accessToken,
+ String accountName, Post post, Locale locale,
SharedPreferences sharedPreferences,
- SharedPreferences nsfwAndSpoilerSharedPreferences, ExoCreator exoCreator,
+ SharedPreferences nsfwAndSpoilerSharedPreferences,
+ SharedPreferences postDetailsSharedPreferences,
+ ExoCreator exoCreator,
PostDetailRecyclerViewAdapterCallback postDetailRecyclerViewAdapterCallback) {
mActivity = activity;
mFragment = fragment;
@@ -343,14 +337,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
.textLayoutIsRoot(R.layout.view_table_entry_cell)))
.build();
mImageViewWidth = imageViewWidth;
+ mSeparatePostAndComments = separatePostAndComments;
mAccessToken = accessToken;
mAccountName = accountName;
mPost = post;
- mVisibleComments = new ArrayList<>();
mSubredditNamePrefixed = post.getSubredditNamePrefixed();
mLocale = locale;
- mSingleCommentId = singleCommentId;
- mIsSingleCommentThreadMode = isSingleCommentThreadMode;
mNeedBlurNsfw = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true);
mDoNotBlurNsfwInNsfwSubreddits = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.DO_NOT_BLUR_NSFW_IN_NSFW_SUBREDDITS, false);
@@ -358,11 +350,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE);
- mExpandChildren = !sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
- mCommentToolbarHidden = sharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDDEN, false);
- mCommentToolbarHideOnClick = sharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDE_ON_CLICK, true);
- mSwapTapAndLong = sharedPreferences.getBoolean(SharedPreferencesUtils.SWAP_TAP_AND_LONG_COMMENTS, false);
- mShowCommentDivider = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
mShowAbsoluteNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
String autoplayString = sharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
@@ -374,7 +361,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
}
mAutoplayNsfwVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true);
mMuteAutoplayingVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS, true);
- mFullyCollapseComment = sharedPreferences.getBoolean(SharedPreferencesUtils.FULLY_COLLAPSE_COMMENT, false);
Resources resources = activity.getResources();
mStartAutoplayVisibleAreaOffset = resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ?
@@ -393,11 +379,14 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mDisableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
mOnlyDisablePreviewInVideoAndGifPosts = sharedPreferences.getBoolean(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS, false);
+ mHidePostType = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_TYPE, false);
+ mHidePostFlair = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_FLAIR, false);
+ mHideTheNumberOfAwards = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS, false);
+ mHideSubredditAndUserPrefix = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX, false);
+ mHideTheNumberOfVotes = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES, false);
+ mHideTheNumberOfComments = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS, false);
+
mPostDetailRecyclerViewAdapterCallback = postDetailRecyclerViewAdapterCallback;
- isInitiallyLoading = true;
- isInitiallyLoadingFailed = false;
- mHasMoreComments = false;
- loadMoreCommentsFailed = false;
mScale = resources.getDisplayMetrics().density;
mColorAccent = customThemeWrapper.getColorAccent();
@@ -425,7 +414,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mDownvotedColor = customThemeWrapper.getDownvoted();
mVoteAndReplyUnavailableVoteButtonColor = customThemeWrapper.getVoteAndReplyUnavailableButtonColor();
mPostIconAndInfoColor = customThemeWrapper.getPostIconAndInfoColor();
- mCommentIconAndInfoColor = customThemeWrapper.getCommentIconAndInfoColor();
mCommentIcon = activity.getDrawable(R.drawable.ic_comment_grey_24dp);
if (mCommentIcon != null) {
@@ -439,7 +427,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
public int getItemViewType(int position) {
switch (mPost.getPostType()) {
case Post.VIDEO_TYPE:
- if (mAutoplay) {
+ if (mAutoplay && !mSeparatePostAndComments) {
if (!mAutoplayNsfwVideos && mPost.isNSFW()) {
return VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW;
}
@@ -615,8 +603,13 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailBaseViewHolder) holder).mCrosspostImageView.setVisibility(View.VISIBLE);
}
- ((PostDetailBaseViewHolder) holder).mSubredditTextView.setText(mPost.getSubredditNamePrefixed());
- ((PostDetailBaseViewHolder) holder).mUserTextView.setText(mPost.getAuthorNamePrefixed());
+ if (!mHideSubredditAndUserPrefix) {
+ ((PostDetailBaseViewHolder) holder).mSubredditTextView.setText(mPost.getSubredditNamePrefixed());
+ ((PostDetailBaseViewHolder) holder).mUserTextView.setText(mPost.getAuthorNamePrefixed());
+ } else {
+ ((PostDetailBaseViewHolder) holder).mSubredditTextView.setText(mPost.getSubredditName());
+ ((PostDetailBaseViewHolder) holder).mUserTextView.setText(mPost.getAuthor());
+ }
if (mShowElapsedTime) {
((PostDetailBaseViewHolder) holder).mPostTimeTextView.setText(
@@ -637,12 +630,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailBaseViewHolder) holder).mSpoilerTextView.setVisibility(View.VISIBLE);
}
- if (mPost.getFlair() != null && !mPost.getFlair().equals("")) {
+ if (!mHidePostFlair && mPost.getFlair() != null && !mPost.getFlair().equals("")) {
((PostDetailBaseViewHolder) holder).mFlairTextView.setVisibility(View.VISIBLE);
Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mFlairTextView, mPost.getFlair(), false);
}
- if (mPost.getAwards() != null && !mPost.getAwards().equals("")) {
+ if (!mHideTheNumberOfAwards && mPost.getAwards() != null && !mPost.getAwards().equals("")) {
((PostDetailBaseViewHolder) holder).mAwardsTextView.setVisibility(View.VISIBLE);
Utils.setHTMLWithImageToTextView(((PostDetailBaseViewHolder) holder).mAwardsTextView, mPost.getAwards(), true);
}
@@ -655,7 +648,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailBaseViewHolder) holder).mNSFWTextView.setVisibility(View.GONE);
}
- ((PostDetailBaseViewHolder) holder).mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, mPost.getScore() + mPost.getVoteType()));
+ if (!mHideTheNumberOfVotes) {
+ ((PostDetailBaseViewHolder) holder).mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, mPost.getScore() + mPost.getVoteType()));
+ } else {
+ ((PostDetailBaseViewHolder) holder).mScoreTextView.setText(mActivity.getString(R.string.vote));
+ }
((PostDetailBaseViewHolder) holder).commentsCountTextView.setText(Integer.toString(mPost.getNComments()));
@@ -703,10 +700,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(mPost.getVideoUrl()));
}
} else if (holder instanceof PostDetailVideoAndGifPreviewHolder) {
- if (mPost.getPostType() == Post.GIF_TYPE) {
- ((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.gif));
- } else {
- ((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.video));
+ if (!mHidePostType) {
+ if (mPost.getPostType() == Post.GIF_TYPE) {
+ ((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.gif));
+ } else {
+ ((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.video));
+ }
}
Post.Preview preview = getSuitablePreview(mPost.getPreviews());
if (preview != null) {
@@ -714,10 +713,12 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
loadImage((PostDetailVideoAndGifPreviewHolder) holder, preview);
}
} else if (holder instanceof PostDetailImageAndGifAutoplayViewHolder) {
- if (mPost.getPostType() == Post.IMAGE_TYPE) {
- ((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(R.string.image);
- } else {
- ((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(R.string.gif);
+ if (!mHidePostType) {
+ if (mPost.getPostType() == Post.IMAGE_TYPE) {
+ ((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(R.string.image);
+ } else {
+ ((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(R.string.gif);
+ }
}
Post.Preview preview = getSuitablePreview(mPost.getPreviews());
@@ -744,7 +745,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
} else if (holder instanceof PostDetailNoPreviewViewHolder) {
if (mPost.getPostType() == Post.LINK_TYPE || mPost.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
- ((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.link);
+ if (!mHidePostType) {
+ ((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.link);
+ }
String noPreviewLinkDomain = Uri.parse(mPost.getUrl()).getHost();
((PostDetailNoPreviewViewHolder) holder).mLinkTextView.setVisibility(View.VISIBLE);
((PostDetailNoPreviewViewHolder) holder).mLinkTextView.setText(noPreviewLinkDomain);
@@ -753,27 +756,35 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailNoPreviewViewHolder) holder).mLinkTextView.setVisibility(View.GONE);
switch (mPost.getPostType()) {
case Post.VIDEO_TYPE:
- ((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.video);
+ if (!mHidePostType) {
+ ((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.video);
+ }
((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_outline_video_24dp);
break;
case Post.IMAGE_TYPE:
- ((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.image);
+ if (!mHidePostType) {
+ ((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.image);
+ }
((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_image_24dp);
break;
case Post.GIF_TYPE:
- ((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.gif);
+ if (!mHidePostType) {
+ ((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.gif);
+ }
((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_image_24dp);
break;
case Post.GALLERY_TYPE:
- ((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.gallery);
- ((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_gallery_24dp);
+ if (!mHidePostType) {
+ ((PostDetailNoPreviewViewHolder) holder).mTypeTextView.setText(R.string.gallery);
+ }
+ ((PostDetailNoPreviewViewHolder) holder).mNoPreviewPostTypeImageView.setImageResource(R.drawable.ic_gallery_reverse_color_24dp);
break;
}
}
if (mPost.getSelfText() != null && !mPost.getSelfText().equals("")) {
((PostDetailNoPreviewViewHolder) holder).mContentMarkdownView.setVisibility(View.VISIBLE);
- LinearLayoutManager linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
+ LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
@Override
public void onScrolledLeft() {
((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack();
@@ -803,7 +814,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
} else if (holder instanceof PostDetailTextViewHolder) {
if (mPost.getSelfText() != null && !mPost.getSelfText().equals("")) {
((PostDetailTextViewHolder) holder).mContentMarkdownView.setVisibility(View.VISIBLE);
- LinearLayoutManager linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
+ LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
@Override
public void onScrolledLeft() {
((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack();
@@ -867,7 +878,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private void loadImage(PostDetailBaseViewHolder holder, @NonNull Post.Preview preview) {
if (holder instanceof PostDetailImageAndGifAutoplayViewHolder) {
- String url = mPost.getPostType() == Post.IMAGE_TYPE ? preview.getPreviewUrl() : mPost.getUrl();
+ boolean blurImage = (mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler);
+ String url = mPost.getPostType() == Post.IMAGE_TYPE || blurImage ? preview.getPreviewUrl() : mPost.getUrl();
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url)
.listener(new RequestListener<Drawable>() {
@Override
@@ -889,7 +901,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
}
});
- if ((mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
+ if (blurImage) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
} else {
if (mImageViewWidth > preview.getPreviewWidth()) {
@@ -1196,21 +1208,29 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mActivity.startActivity(crosspostIntent);
});
- mTypeTextView.setOnClickListener(view -> {
- Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
- intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
- intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
- intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, mPost.getPostType());
- mActivity.startActivity(intent);
- });
+ if (!mHidePostType) {
+ mTypeTextView.setOnClickListener(view -> {
+ Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
+ intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
+ intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
+ intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, mPost.getPostType());
+ mActivity.startActivity(intent);
+ });
+ } else {
+ mTypeTextView.setVisibility(View.GONE);
+ }
- mFlairTextView.setOnClickListener(view -> {
- Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
- intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
- intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
- intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, mPost.getFlair());
- mActivity.startActivity(intent);
- });
+ if (!mHidePostFlair) {
+ mFlairTextView.setOnClickListener(view -> {
+ Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
+ intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
+ intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
+ intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, mPost.getFlair());
+ mActivity.startActivity(intent);
+ });
+ } else {
+ mFlairTextView.setVisibility(View.GONE);
+ }
mNSFWTextView.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
@@ -1254,8 +1274,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mScoreTextView.setTextColor(mPostIconAndInfoColor);
}
- mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
- mPost.getScore() + mPost.getVoteType()));
+ if (!mHideTheNumberOfVotes) {
+ mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ mPost.getScore() + mPost.getVoteType()));
+ }
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
@@ -1273,8 +1295,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
}
mDownvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
- mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
- mPost.getScore() + mPost.getVoteType()));
+ if (!mHideTheNumberOfVotes) {
+ mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ mPost.getScore() + mPost.getVoteType()));
+ }
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
}
@@ -1283,8 +1307,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
public void onVoteThingFail() {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
mPost.setVoteType(previousVoteType);
- mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
- mPost.getScore() + previousVoteType));
+ if (!mHideTheNumberOfVotes) {
+ mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ mPost.getScore() + previousVoteType));
+ }
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
mScoreTextView.setTextColor(previousScoreTextViewColor);
@@ -1328,8 +1354,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mScoreTextView.setTextColor(mPostIconAndInfoColor);
}
- mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
- mPost.getScore() + mPost.getVoteType()));
+ if (!mHideTheNumberOfVotes) {
+ mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ mPost.getScore() + mPost.getVoteType()));
+ }
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
@@ -1347,8 +1375,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
}
mUpvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
- mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
- mPost.getScore() + mPost.getVoteType()));
+ if (!mHideTheNumberOfVotes) {
+ mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ mPost.getScore() + mPost.getVoteType()));
+ }
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
}
@@ -1357,8 +1387,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
public void onVoteThingFail() {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
mPost.setVoteType(previousVoteType);
- mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
- mPost.getScore() + previousVoteType));
+ if (!mHideTheNumberOfVotes) {
+ mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ mPost.getScore() + previousVoteType));
+ }
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
mScoreTextView.setTextColor(previousScoreTextViewColor);
@@ -1368,31 +1400,35 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
}, mPost.getFullName(), newVoteType);
});
- commentsCountTextView.setOnClickListener(view -> {
- if (mPost.isArchived()) {
- Toast.makeText(mActivity, R.string.archived_post_comment_unavailable, Toast.LENGTH_SHORT).show();
- return;
- }
+ if (!mHideTheNumberOfComments) {
+ commentsCountTextView.setOnClickListener(view -> {
+ if (mPost.isArchived()) {
+ Toast.makeText(mActivity, R.string.archived_post_comment_unavailable, Toast.LENGTH_SHORT).show();
+ return;
+ }
- if (mPost.isLocked()) {
- Toast.makeText(mActivity, R.string.locked_post_comment_unavailable, Toast.LENGTH_SHORT).show();
- return;
- }
+ if (mPost.isLocked()) {
+ Toast.makeText(mActivity, R.string.locked_post_comment_unavailable, Toast.LENGTH_SHORT).show();
+ return;
+ }
- if (mAccessToken == null) {
- Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
- return;
- }
+ if (mAccessToken == null) {
+ Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
+ return;
+ }
- Intent intent = new Intent(mActivity, CommentActivity.class);
- intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName());
- intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY, mPost.getTitle());
- intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY, mPost.getSelfText());
- intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfTextPlain());
- intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false);
- intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0);
- mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE);
- });
+ Intent intent = new Intent(mActivity, CommentActivity.class);
+ intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mPost.getFullName());
+ intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY, mPost.getTitle());
+ intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY, mPost.getSelfText());
+ intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_BODY_KEY, mPost.getSelfTextPlain());
+ intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false);
+ intent.putExtra(CommentActivity.EXTRA_PARENT_DEPTH_KEY, 0);
+ mActivity.startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE);
+ });
+ } else {
+ commentsCountTextView.setVisibility(View.GONE);
+ }
mSaveButton.setOnClickListener(view -> {
if (mAccessToken == null) {
@@ -1615,11 +1651,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
muteButton.setOnClickListener(view -> {
if (helper != null) {
if (helper.getVolume() != 0) {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_18dp));
+ muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_24dp));
helper.setVolume(0f);
volume = 0f;
} else {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_18dp));
+ muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_24dp));
helper.setVolume(1f);
volume = 1f;
}
@@ -1701,9 +1737,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
helper.setVolume(volume);
muteButton.setVisibility(View.VISIBLE);
if (volume != 0f) {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_18dp));
+ muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_24dp));
} else {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_18dp));
+ muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_24dp));
}
break;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
index c55b7533..12d6c0d1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -29,6 +29,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.Barrier;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
+import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.paging.PagedListAdapter;
import androidx.recyclerview.widget.DiffUtil;
@@ -106,19 +107,15 @@ import retrofit2.Retrofit;
public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHolder> implements CacheManager {
private static final int VIEW_TYPE_POST_CARD_VIDEO_AUTOPLAY_TYPE = 1;
- private static final int VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE = 2;
- private static final int VIEW_TYPE_POST_CARD_IMAGE_AND_GIF_AUTOPLAY_TYPE = 3;
- private static final int VIEW_TYPE_POST_CARD_LINK_TYPE = 4;
- private static final int VIEW_TYPE_POST_CARD_NO_PREVIEW_LINK_TYPE = 5;
- private static final int VIEW_TYPE_POST_CARD_TEXT_TYPE = 6;
- private static final int VIEW_TYPE_POST_CARD_GALLERY_TYPE = 7;
- private static final int VIEW_TYPE_POST_COMPACT = 8;
- private static final int VIEW_TYPE_POST_GALLERY = 9;
- private static final int VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE = 10;
- private static final int VIEW_TYPE_POST_CARD_2_WITH_PREVIEW = 11;
- private static final int VIEW_TYPE_POST_CARD_2_TEXT_TYPE = 12;
- private static final int VIEW_TYPE_ERROR = 13;
- private static final int VIEW_TYPE_LOADING = 14;
+ private static final int VIEW_TYPE_POST_CARD_WITH_PREVIEW_TYPE = 2;
+ private static final int VIEW_TYPE_POST_CARD_TEXT_TYPE = 3;
+ private static final int VIEW_TYPE_POST_COMPACT = 4;
+ private static final int VIEW_TYPE_POST_GALLERY = 5;
+ private static final int VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE = 6;
+ private static final int VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE = 7;
+ private static final int VIEW_TYPE_POST_CARD_2_TEXT_TYPE = 8;
+ private static final int VIEW_TYPE_ERROR = 9;
+ private static final int VIEW_TYPE_LOADING = 10;
private static final DiffUtil.ItemCallback<Post> DIFF_CALLBACK = new DiffUtil.ItemCallback<Post>() {
@Override
@@ -148,6 +145,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private boolean canStartActivity = true;
private int mPostType;
private int mPostLayout;
+ private int mDefaultLinkPostLayout;
private int mColorPrimaryLightTheme;
private int mColorAccent;
private int mCardViewBackgroundColor;
@@ -295,6 +293,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mHideTheNumberOfComments = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS, false);
mPostLayout = postLayout;
+ mDefaultLinkPostLayout = Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.DEFAULT_LINK_POST_LAYOUT_KEY, "-1"));
mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme();
mColorAccent = customThemeWrapper.getColorAccent();
@@ -366,33 +365,45 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
case Post.VIDEO_TYPE:
if (mAutoplay) {
if (!mAutoplayNsfwVideos && post.isNSFW()) {
- return VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE;
+ return VIEW_TYPE_POST_CARD_WITH_PREVIEW_TYPE;
}
return VIEW_TYPE_POST_CARD_VIDEO_AUTOPLAY_TYPE;
}
- return VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE;
+ return VIEW_TYPE_POST_CARD_WITH_PREVIEW_TYPE;
case Post.GIF_TYPE:
- if (mAutoplay) {
- if (!mAutoplayNsfwVideos && post.isNSFW()) {
- return VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE;
- }
- return VIEW_TYPE_POST_CARD_IMAGE_AND_GIF_AUTOPLAY_TYPE;
- }
- return VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE;
case Post.IMAGE_TYPE:
- return VIEW_TYPE_POST_CARD_IMAGE_AND_GIF_AUTOPLAY_TYPE;
+ case Post.GALLERY_TYPE:
+ return VIEW_TYPE_POST_CARD_WITH_PREVIEW_TYPE;
case Post.LINK_TYPE:
- return VIEW_TYPE_POST_CARD_LINK_TYPE;
case Post.NO_PREVIEW_LINK_TYPE:
- return VIEW_TYPE_POST_CARD_NO_PREVIEW_LINK_TYPE;
- case Post.GALLERY_TYPE:
- return VIEW_TYPE_POST_CARD_GALLERY_TYPE;
+ switch (mDefaultLinkPostLayout) {
+ case SharedPreferencesUtils.POST_LAYOUT_CARD_2:
+ return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE;
+ case SharedPreferencesUtils.POST_LAYOUT_GALLERY:
+ return VIEW_TYPE_POST_GALLERY;
+ case SharedPreferencesUtils.POST_LAYOUT_COMPACT:
+ return VIEW_TYPE_POST_COMPACT;
+ }
+ return VIEW_TYPE_POST_CARD_WITH_PREVIEW_TYPE;
default:
return VIEW_TYPE_POST_CARD_TEXT_TYPE;
}
}
return VIEW_TYPE_POST_CARD_TEXT_TYPE;
} else if (mPostLayout == SharedPreferencesUtils.POST_LAYOUT_COMPACT) {
+ Post post = getItem(position);
+ if (post != null) {
+ if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
+ switch (mDefaultLinkPostLayout) {
+ case SharedPreferencesUtils.POST_LAYOUT_CARD:
+ return VIEW_TYPE_POST_CARD_WITH_PREVIEW_TYPE;
+ case SharedPreferencesUtils.POST_LAYOUT_GALLERY:
+ return VIEW_TYPE_POST_GALLERY;
+ case SharedPreferencesUtils.POST_LAYOUT_CARD_2:
+ return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE;
+ }
+ }
+ }
return VIEW_TYPE_POST_COMPACT;
} else if (mPostLayout == SharedPreferencesUtils.POST_LAYOUT_GALLERY) {
return VIEW_TYPE_POST_GALLERY;
@@ -403,17 +414,26 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
case Post.VIDEO_TYPE:
if (mAutoplay) {
if (!mAutoplayNsfwVideos && post.isNSFW()) {
- return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW;
+ return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE;
}
return VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE;
}
- return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW;
+ return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE;
case Post.GIF_TYPE:
case Post.IMAGE_TYPE:
+ case Post.GALLERY_TYPE:
+ return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE;
case Post.LINK_TYPE:
case Post.NO_PREVIEW_LINK_TYPE:
- case Post.GALLERY_TYPE:
- return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW;
+ switch (mDefaultLinkPostLayout) {
+ case SharedPreferencesUtils.POST_LAYOUT_CARD:
+ return VIEW_TYPE_POST_CARD_WITH_PREVIEW_TYPE;
+ case SharedPreferencesUtils.POST_LAYOUT_GALLERY:
+ return VIEW_TYPE_POST_GALLERY;
+ case SharedPreferencesUtils.POST_LAYOUT_COMPACT:
+ return VIEW_TYPE_POST_COMPACT;
+ }
+ return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE;
default:
return VIEW_TYPE_POST_CARD_2_TEXT_TYPE;
}
@@ -431,11 +451,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
return new PostWithPreviewTypeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_with_preview, parent, false));
}
return new PostVideoAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_video_type_autoplay, parent, false));
- } else if (viewType == VIEW_TYPE_POST_CARD_VIDEO_AND_GIF_PREVIEW_TYPE
- || viewType == VIEW_TYPE_POST_CARD_IMAGE_AND_GIF_AUTOPLAY_TYPE
- || viewType == VIEW_TYPE_POST_CARD_LINK_TYPE
- || viewType == VIEW_TYPE_POST_CARD_NO_PREVIEW_LINK_TYPE
- || viewType == VIEW_TYPE_POST_CARD_GALLERY_TYPE) {
+ } else if (viewType == VIEW_TYPE_POST_CARD_WITH_PREVIEW_TYPE) {
return new PostWithPreviewTypeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_with_preview, parent, false));
} else if (viewType == VIEW_TYPE_POST_CARD_TEXT_TYPE) {
return new PostTextTypeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_text, parent, false));
@@ -449,7 +465,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
return new PostGalleryViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_gallery, parent, false));
} else if (viewType == VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE) {
return new PostCard2VideoAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_video_autoplay, parent, false));
- } else if (viewType == VIEW_TYPE_POST_CARD_2_WITH_PREVIEW) {
+ } else if (viewType == VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE) {
return new PostCard2WithPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_with_preview, parent, false));
} else if (viewType == VIEW_TYPE_POST_CARD_2_TEXT_TYPE) {
return new PostCard2TextTypeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_text, parent, false));
@@ -709,7 +725,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else {
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
}
- ((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
+ if (mFragment.getMasterMutingOption() == null) {
+ ((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
+ } else {
+ ((PostVideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f);
+ }
if (post.isGfycat() || post.isRedgifs() && !post.isLoadGfyOrRedgifsVideoSuccess()) {
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks = new FetchGfycatOrRedgifsVideoLinks(new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
@@ -740,10 +760,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else if (holder instanceof PostWithPreviewTypeViewHolder) {
if (post.getPostType() == Post.VIDEO_TYPE) {
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
+ ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.video));
} else if (post.getPostType() == Post.GIF_TYPE) {
if (!mAutoplay) {
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
+ ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
}
((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gif));
} else if (post.getPostType() == Post.IMAGE_TYPE) {
@@ -759,6 +781,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
} else if (post.getPostType() == Post.GALLERY_TYPE) {
((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gallery));
+ ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
+ ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_reverse_color_24dp));
}
if (post.getPostType() != Post.NO_PREVIEW_LINK_TYPE) {
@@ -776,7 +800,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else if (post.getPostType() == Post.LINK_TYPE) {
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_link);
} else if (post.getPostType() == Post.GALLERY_TYPE) {
- ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_gallery_24dp);
+ ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_gallery_reverse_color_24dp);
}
} else if (mDataSavingMode && mOnlyDisablePreviewInVideoAndGifPosts && (post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE)) {
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
@@ -808,7 +832,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else if (post.getPostType() == Post.LINK_TYPE) {
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_link);
} else if (post.getPostType() == Post.GALLERY_TYPE) {
- ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_gallery_24dp);
+ ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setImageResource(R.drawable.ic_gallery_reverse_color_24dp);
}
}
}
@@ -833,7 +857,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else {
((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
}
- ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
+ if (mFragment.getMasterMutingOption() == null) {
+ ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
+ } else {
+ ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f);
+ }
if (post.isGfycat() || post.isRedgifs() && !post.isLoadGfyOrRedgifsVideoSuccess()) {
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks = new FetchGfycatOrRedgifsVideoLinks(new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
@@ -864,10 +892,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else if (holder instanceof PostCard2WithPreviewViewHolder) {
if (post.getPostType() == Post.VIDEO_TYPE) {
((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
+ ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.video));
} else if (post.getPostType() == Post.GIF_TYPE) {
if (!mAutoplay) {
((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
+ ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
}
((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gif));
} else if (post.getPostType() == Post.IMAGE_TYPE) {
@@ -883,6 +913,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
} else if (post.getPostType() == Post.GALLERY_TYPE) {
((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gallery));
+ ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
+ ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_reverse_color_24dp));
}
if (post.getPostType() != Post.NO_PREVIEW_LINK_TYPE) {
@@ -901,7 +933,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else if (post.getPostType() == Post.LINK_TYPE) {
((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link);
} else if (post.getPostType() == Post.GALLERY_TYPE) {
- ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp);
+ ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_reverse_color_24dp);
}
} else if (mDataSavingMode && mOnlyDisablePreviewInVideoAndGifPosts && (post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE)) {
((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE);
@@ -935,7 +967,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else if (post.getPostType() == Post.LINK_TYPE) {
((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link);
} else if (post.getPostType() == Post.GALLERY_TYPE) {
- ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp);
+ ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_reverse_color_24dp);
}
}
}
@@ -1170,7 +1202,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostCompactBaseViewHolder) holder).relativeLayout.setVisibility(View.VISIBLE);
if (post.getPostType() == Post.GALLERY_TYPE && post.getPreviews() != null && post.getPreviews().isEmpty()) {
((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.VISIBLE);
- ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_gallery_24dp);
+ ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_gallery_reverse_color_24dp);
}
ArrayList<Post.Preview> previews = post.getPreviews();
if (previews != null && !previews.isEmpty()) {
@@ -1259,7 +1291,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostCompactBaseViewHolder) holder).typeTextView.setText(R.string.gallery);
if (mDataSavingMode && mDisableImagePreview) {
((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.VISIBLE);
- ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_gallery_24dp);
+ ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_gallery_reverse_color_24dp);
}
break;
case Post.TEXT_TYPE:
@@ -1324,12 +1356,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE);
} else if (post.getPostType() == Post.IMAGE_TYPE || post.getPostType() == Post.GIF_TYPE) {
-
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE);
} else if (post.getPostType() == Post.LINK_TYPE) {
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link);
} else if (post.getPostType() == Post.GALLERY_TYPE) {
- ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp);
+ ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_reverse_color_24dp);
}
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp);
}
@@ -1339,7 +1370,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(mActivity.getDrawable(R.drawable.ic_play_circle_36dp));
+ ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
Post.Preview preview = getSuitablePreview(post.getPreviews());
if (preview != null) {
@@ -1364,7 +1395,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(mActivity.getDrawable(R.drawable.ic_play_circle_36dp));
+ ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
Post.Preview preview = getSuitablePreview(post.getPreviews());
if (preview != null) {
@@ -1389,7 +1420,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(mActivity.getDrawable(R.drawable.ic_link_post_type_indicator));
+ ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_link_post_type_indicator));
Post.Preview preview = getSuitablePreview(post.getPreviews());
if (preview != null) {
@@ -1424,7 +1455,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(mActivity.getDrawable(R.drawable.ic_gallery_24dp));
+ ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_reverse_color_24dp));
Post.Preview preview = getSuitablePreview(post.getPreviews());
if (preview != null) {
@@ -1441,7 +1472,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
loadImage(holder, post, preview);
} else {
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp);
+ ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_reverse_color_24dp);
}
break;
}
@@ -1494,7 +1525,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private void loadImage(final RecyclerView.ViewHolder holder, final Post post, @NonNull Post.Preview preview) {
if (holder instanceof PostWithPreviewTypeViewHolder) {
String url;
- if (post.getPostType() == Post.GIF_TYPE && mAutoplay) {
+ boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler;
+ if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) {
url = post.getUrl();
} else {
url = preview.getPreviewUrl();
@@ -1520,7 +1552,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
});
- if ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) {
+ if (blurImage) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostWithPreviewTypeViewHolder) holder).imageView);
} else {
@@ -1563,7 +1595,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
} else if (holder instanceof PostGalleryViewHolder) {
String url;
- if (post.getPostType() == Post.GIF_TYPE && mAutoplay) {
+ boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler;
+ if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) {
url = post.getUrl();
} else {
url = preview.getPreviewUrl();
@@ -1589,7 +1622,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
});
- if ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) {
+ if (blurImage) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostGalleryViewHolder) holder).imageView);
} else {
@@ -1601,7 +1634,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
} else if (holder instanceof PostCard2WithPreviewViewHolder) {
String url;
- if (post.getPostType() == Post.GIF_TYPE && mAutoplay) {
+ boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler;
+ if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) {
url = post.getUrl();
} else {
url = preview.getPreviewUrl();
@@ -1627,7 +1661,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
});
- if ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) {
+ if (blurImage) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostCard2WithPreviewViewHolder) holder).imageView);
} else {
@@ -1838,6 +1872,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mHideTheNumberOfComments = hideTheNumberOfComments;
}
+ public void setDefaultLinkPostLayout(int defaultLinkPostLayout) {
+ mDefaultLinkPostLayout = defaultLinkPostLayout;
+ }
+
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder);
@@ -1849,15 +1887,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostBaseViewHolder) holder).markPostRead(post, false);
}
}
- ((PostBaseViewHolder) holder).itemView.setVisibility(View.VISIBLE);
+ holder.itemView.setVisibility(View.VISIBLE);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
if (holder instanceof PostCard2VideoAutoplayViewHolder || holder instanceof PostCard2WithPreviewViewHolder) {
int paddingPixel = (int) Utils.convertDpToPixel(16, mActivity);
- ((PostBaseViewHolder) holder).itemView.setPadding(0, paddingPixel, 0, 0);
+ holder.itemView.setPadding(0, paddingPixel, 0, 0);
} else if (holder instanceof PostCard2TextTypeViewHolder) {
int paddingPixel = (int) Utils.convertDpToPixel(12, mActivity);
- ((PostBaseViewHolder) holder).itemView.setPadding(0, paddingPixel, 0, 0);
+ holder.itemView.setPadding(0, paddingPixel, 0, 0);
} else {
int marginPixel = (int) Utils.convertDpToPixel(8, mActivity);
params.topMargin = marginPixel;
@@ -1865,9 +1903,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
holder.itemView.setLayoutParams(params);
if (((PostBaseViewHolder) holder).itemViewIsNotCardView) {
- ((PostBaseViewHolder) holder).itemView.setBackgroundColor(mCardViewBackgroundColor);
+ holder.itemView.setBackgroundColor(mCardViewBackgroundColor);
} else {
- ((PostBaseViewHolder) holder).itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor));
+ holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor));
}
((PostBaseViewHolder) holder).titleTextView.setTextColor(mPostTitleColor);
if (holder instanceof PostVideoAutoplayViewHolder) {
@@ -1892,6 +1930,16 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostTextTypeViewHolder) holder).contentTextView.setText("");
((PostTextTypeViewHolder) holder).contentTextView.setTextColor(mPostContentColor);
((PostTextTypeViewHolder) holder).contentTextView.setVisibility(View.GONE);
+ } else if (holder instanceof PostCard2VideoAutoplayViewHolder) {
+ ((PostCard2VideoAutoplayViewHolder) holder).mediaUri = null;
+ if (((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks != null) {
+ ((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks.cancel();
+ }
+ ((PostCard2VideoAutoplayViewHolder) holder).errorLoadingGfycatImageView.setVisibility(View.GONE);
+ ((PostCard2VideoAutoplayViewHolder) holder).muteButton.setVisibility(View.GONE);
+ ((PostCard2VideoAutoplayViewHolder) holder).resetVolume();
+ mGlide.clear(((PostCard2VideoAutoplayViewHolder) holder).previewImageView);
+ ((PostCard2VideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.GONE);
} else if (holder instanceof PostCard2WithPreviewViewHolder) {
mGlide.clear(((PostCard2WithPreviewViewHolder) holder).imageView);
((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.GONE);
@@ -2761,13 +2809,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
muteButton.setOnClickListener(view -> {
if (helper != null) {
if (helper.getVolume() != 0) {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_18dp));
+ muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_white_rounded_24dp));
helper.setVolume(0f);
volume = 0f;
+ mFragment.videoAutoplayChangeMutingOption(true);
} else {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_18dp));
+ muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_white_rounded_24dp));
helper.setVolume(1f);
volume = 1f;
+ mFragment.videoAutoplayChangeMutingOption(false);
}
}
});
@@ -2851,12 +2901,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
for (int i = 0; i < trackGroups.length; i++) {
String mimeType = trackGroups.get(i).getFormat(0).sampleMimeType;
if (mimeType != null && mimeType.contains("audio")) {
+ if (mFragment.getMasterMutingOption() != null) {
+ volume = mFragment.getMasterMutingOption() ? 0f : 1f;
+ }
helper.setVolume(volume);
muteButton.setVisibility(View.VISIBLE);
if (volume != 0f) {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_18dp));
+ muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_white_rounded_24dp));
} else {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_18dp));
+ muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_white_rounded_24dp));
}
break;
}
@@ -3212,6 +3265,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
constraintSet.applyTo(bottomConstraintLayout);
}
+ if (((ViewGroup) itemView).getLayoutTransition() != null) {
+ ((ViewGroup) itemView).getLayoutTransition().setAnimateParentHierarchy(false);
+ }
+
itemView.setBackgroundColor(mCardViewBackgroundColor);
postTimeTextView.setTextColor(mSecondaryTextColor);
titleTextView.setTextColor(mPostTitleColor);
@@ -3975,13 +4032,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
muteButton.setOnClickListener(view -> {
if (helper != null) {
if (helper.getVolume() != 0) {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_18dp));
+ muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_white_rounded_24dp));
helper.setVolume(0f);
volume = 0f;
+ mFragment.videoAutoplayChangeMutingOption(true);
} else {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_18dp));
+ muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_white_rounded_24dp));
helper.setVolume(1f);
volume = 1f;
+ mFragment.videoAutoplayChangeMutingOption(false);
}
}
});
@@ -4065,12 +4124,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
for (int i = 0; i < trackGroups.length; i++) {
String mimeType = trackGroups.get(i).getFormat(0).sampleMimeType;
if (mimeType != null && mimeType.contains("audio")) {
+ if (mFragment.getMasterMutingOption() != null) {
+ volume = mFragment.getMasterMutingOption() ? 0f : 1f;
+ }
helper.setVolume(volume);
muteButton.setVisibility(View.VISIBLE);
if (volume != 0f) {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_18dp));
+ muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_white_rounded_24dp));
} else {
- muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_18dp));
+ muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_white_rounded_24dp));
}
break;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RPANCommentStreamRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RPANCommentStreamRecyclerViewAdapter.java
index 60f596ab..ba7dcd34 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RPANCommentStreamRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RPANCommentStreamRecyclerViewAdapter.java
@@ -23,12 +23,10 @@ import ml.docilealligator.infinityforreddit.RPANComment;
public class RPANCommentStreamRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private RequestManager glide;
private ArrayList<RPANComment> rpanComments;
- private ItemClickListener itemClickListener;
- public RPANCommentStreamRecyclerViewAdapter(Context context, ItemClickListener itemClickListener) {
+ public RPANCommentStreamRecyclerViewAdapter(Context context) {
glide = Glide.with(context);
rpanComments = new ArrayList<>();
- this.itemClickListener = itemClickListener;
}
@NonNull
@@ -80,14 +78,6 @@ public class RPANCommentStreamRecyclerViewAdapter extends RecyclerView.Adapter<R
iconImageView = itemView.findViewById(R.id.icon_image_view_item_rpan_comment);
authorTextView = itemView.findViewById(R.id.author_text_view_item_rpan_comment);
contentTextView = itemView.findViewById(R.id.content_text_view_item_rpan_comment);
-
- itemView.setOnClickListener(view -> {
- itemClickListener.onClick();
- });
}
}
-
- public interface ItemClickListener {
- void onClick();
- }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java
new file mode 100644
index 00000000..bec2d265
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java
@@ -0,0 +1,231 @@
+package ml.docilealligator.infinityforreddit.adapters;
+
+import android.content.Context;
+import android.content.res.ColorStateList;
+import android.graphics.drawable.Drawable;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
+import android.widget.ImageView;
+import android.widget.ProgressBar;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.RequestManager;
+import com.bumptech.glide.load.DataSource;
+import com.bumptech.glide.load.engine.GlideException;
+import com.bumptech.glide.load.resource.bitmap.CenterCrop;
+import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
+import com.bumptech.glide.request.RequestListener;
+import com.bumptech.glide.request.RequestOptions;
+import com.bumptech.glide.request.target.Target;
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
+
+import java.util.ArrayList;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.RedditGalleryPayload;
+import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView;
+
+public class RedditGallerySubmissionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+
+ private static final int VIEW_TYPE_IMAGE = 1;
+ private static final int VIEW_TYPE_ADD_IMAGE = 2;
+
+ private ArrayList<RedditGalleryImageInfo> redditGalleryImageInfoList;
+ private CustomThemeWrapper customThemeWrapper;
+ private ItemClickListener itemClickListener;
+ private RequestManager glide;
+
+ public RedditGallerySubmissionRecyclerViewAdapter(Context context, CustomThemeWrapper customThemeWrapper,
+ ItemClickListener itemClickListener) {
+ glide = Glide.with(context);
+ this.customThemeWrapper = customThemeWrapper;
+ this.itemClickListener = itemClickListener;
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ if (redditGalleryImageInfoList == null || position >= redditGalleryImageInfoList.size()) {
+ return VIEW_TYPE_ADD_IMAGE;
+ }
+
+ return VIEW_TYPE_IMAGE;
+ }
+
+ @NonNull
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ if (viewType == VIEW_TYPE_ADD_IMAGE) {
+ return new AddImageViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_reddit_gallery_submission_add_image, parent, false));
+ }
+ return new ImageViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_reddit_gallery_submission_image, parent, false));
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
+ if (holder instanceof ImageViewHolder) {
+ glide.load(redditGalleryImageInfoList.get(position).imageUrlString)
+ .apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(48)))
+ .listener(new RequestListener<Drawable>() {
+
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+ ((ImageViewHolder) holder).progressBar.setVisibility(View.GONE);
+ ((ImageViewHolder) holder).closeImageView.setVisibility(View.VISIBLE);
+ return false;
+ }
+
+ @Override
+ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+ return false;
+ }
+ })
+ .into(((ImageViewHolder) holder).imageView);
+
+ if (redditGalleryImageInfoList.get(position).payload != null) {
+ ((ImageViewHolder) holder).progressBar.setVisibility(View.GONE);
+ ((ImageViewHolder) holder).closeImageView.setVisibility(View.VISIBLE);
+ }
+ }
+ }
+
+ @Override
+ public int getItemCount() {
+ return redditGalleryImageInfoList == null ? 1 : (redditGalleryImageInfoList.size() >= 20 ? 20 : redditGalleryImageInfoList.size() + 1);
+ }
+
+ @Override
+ public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
+ super.onViewRecycled(holder);
+ if (holder instanceof ImageViewHolder) {
+ glide.clear(((ImageViewHolder) holder).imageView);
+ ((ImageViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
+ ((ImageViewHolder) holder).closeImageView.setVisibility(View.GONE);
+ }
+ }
+
+ public ArrayList<RedditGalleryImageInfo> getRedditGalleryImageInfoList() {
+ return redditGalleryImageInfoList;
+ }
+
+ public void setRedditGalleryImageInfoList(ArrayList<RedditGalleryImageInfo> redditGalleryImageInfoList) {
+ this.redditGalleryImageInfoList = redditGalleryImageInfoList;
+ notifyDataSetChanged();
+ }
+
+ public void addImage(String imageUrl) {
+ if (redditGalleryImageInfoList == null) {
+ redditGalleryImageInfoList = new ArrayList<>();
+ }
+ redditGalleryImageInfoList.add(new RedditGalleryImageInfo(imageUrl));
+ notifyItemInserted(redditGalleryImageInfoList.size() - 1);
+ }
+
+ public void setImageAsUploaded(String mediaId) {
+ redditGalleryImageInfoList.get(redditGalleryImageInfoList.size() - 1).payload = new RedditGalleryPayload.Item("", "", mediaId);
+ notifyItemChanged(redditGalleryImageInfoList.size() - 1);
+ }
+
+ public void removeFailedToUploadImage() {
+ redditGalleryImageInfoList.remove(redditGalleryImageInfoList.size() - 1);
+ notifyItemRemoved(redditGalleryImageInfoList.size());
+ }
+
+ class ImageViewHolder extends RecyclerView.ViewHolder {
+ @BindView(R.id.aspect_ratio_gif_image_view_item_reddit_gallery_submission_image)
+ AspectRatioGifImageView imageView;
+ @BindView(R.id.progress_bar_item_reddit_gallery_submission_image)
+ ProgressBar progressBar;
+ @BindView(R.id.close_image_view_item_reddit_gallery_submission_image)
+ ImageView closeImageView;
+
+ public ImageViewHolder(@NonNull View itemView) {
+ super(itemView);
+
+ ButterKnife.bind(this, itemView);
+
+ imageView.setRatio(1);
+
+ closeImageView.setOnClickListener(view -> {
+ redditGalleryImageInfoList.remove(getBindingAdapterPosition());
+ notifyItemRemoved(getBindingAdapterPosition());
+ });
+ }
+ }
+
+ class AddImageViewHolder extends RecyclerView.ViewHolder {
+
+ public AddImageViewHolder(@NonNull View itemView) {
+ super(itemView);
+
+ FloatingActionButton fab = itemView.findViewById(R.id.fab_item_gallery_submission_add_image);
+ fab.setBackgroundTintList(ColorStateList.valueOf(customThemeWrapper.getColorPrimaryLightTheme()));
+ fab.setImageTintList(ColorStateList.valueOf(customThemeWrapper.getFABIconColor()));
+
+ itemView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ itemView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ int width = itemView.getMeasuredWidth();
+ ViewGroup.LayoutParams params = itemView.getLayoutParams();
+ params.height = width;
+ itemView.setLayoutParams(params);
+ }
+ });
+
+ fab.setOnClickListener(view -> itemClickListener.onAddImageClicked());
+ itemView.setOnClickListener(view -> fab.performClick());
+ }
+ }
+
+ public static class RedditGalleryImageInfo implements Parcelable {
+ public String imageUrlString;
+ public RedditGalleryPayload.Item payload;
+
+ public RedditGalleryImageInfo(String imageUrlString) {
+ this.imageUrlString = imageUrlString;
+ }
+
+ protected RedditGalleryImageInfo(Parcel in) {
+ imageUrlString = in.readString();
+ payload = in.readParcelable(RedditGalleryPayload.Item.class.getClassLoader());
+ }
+
+ public static final Creator<RedditGalleryImageInfo> CREATOR = new Creator<RedditGalleryImageInfo>() {
+ @Override
+ public RedditGalleryImageInfo createFromParcel(Parcel in) {
+ return new RedditGalleryImageInfo(in);
+ }
+
+ @Override
+ public RedditGalleryImageInfo[] newArray(int size) {
+ return new RedditGalleryImageInfo[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel parcel, int i) {
+ parcel.writeString(imageUrlString);
+ parcel.writeParcelable(payload, i);
+ }
+ }
+
+ public interface ItemClickListener {
+ void onAddImageClicked();
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java
new file mode 100644
index 00000000..8ab40aff
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/TrendingSearchRecyclerViewAdapter.java
@@ -0,0 +1,228 @@
+package ml.docilealligator.infinityforreddit.adapters;
+
+import android.content.Context;
+import android.content.res.ColorStateList;
+import android.graphics.drawable.Drawable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.ProgressBar;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.RequestBuilder;
+import com.bumptech.glide.RequestManager;
+import com.bumptech.glide.load.DataSource;
+import com.bumptech.glide.load.engine.GlideException;
+import com.bumptech.glide.request.RequestListener;
+import com.bumptech.glide.request.target.Target;
+
+import java.util.ArrayList;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.TrendingSearch;
+import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView;
+import ml.docilealligator.infinityforreddit.post.Post;
+
+public class TrendingSearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+ private ArrayList<TrendingSearch> trendingSearches;
+ private CustomThemeWrapper customThemeWrapper;
+ private RequestManager glide;
+ private int imageViewWidth;
+ private boolean dataSavingMode;
+ private boolean disableImagePreview;
+ private float mScale;
+ private ItemClickListener itemClickListener;
+
+ public TrendingSearchRecyclerViewAdapter(Context context, CustomThemeWrapper customThemeWrapper,
+ int imageViewWidth, boolean dataSavingMode, boolean disableImagePreview,
+ ItemClickListener itemClickListener) {
+ this.customThemeWrapper = customThemeWrapper;
+ this.glide = Glide.with(context);
+ this.imageViewWidth = imageViewWidth;
+ this.dataSavingMode = dataSavingMode;
+ this.disableImagePreview = disableImagePreview;
+ mScale = context.getResources().getDisplayMetrics().density;
+ this.itemClickListener = itemClickListener;
+ }
+
+ @NonNull
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ return new TrendingSearchViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_trending_search, parent, false));
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
+ if (holder instanceof TrendingSearchViewHolder) {
+ TrendingSearch trendingSearch = trendingSearches.get(position);
+ if (dataSavingMode && disableImagePreview) {
+ ((TrendingSearchViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
+ } else {
+ Post.Preview preview = getSuitablePreview(trendingSearch.previews);
+ if (preview != null) {
+ ((TrendingSearchViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.VISIBLE);
+ if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) {
+ int height = (int) (400 * mScale);
+ ((TrendingSearchViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
+ ((TrendingSearchViewHolder) holder).imageView.getLayoutParams().height = height;
+ preview.setPreviewWidth(imageViewWidth);
+ preview.setPreviewHeight(height);
+ } else {
+ ((TrendingSearchViewHolder) holder).imageView
+ .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
+ }
+ loadImage((TrendingSearchViewHolder) holder, preview);
+ } else {
+ ((TrendingSearchViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
+ }
+ }
+
+ ((TrendingSearchViewHolder) holder).titleTextView.setText(trendingSearch.displayString);
+ }
+ }
+
+ @Override
+ public int getItemCount() {
+ return trendingSearches == null ? 0 : trendingSearches.size();
+ }
+
+ @Override
+ public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
+ super.onViewRecycled(holder);
+ if (holder instanceof TrendingSearchViewHolder) {
+ glide.clear(((TrendingSearchViewHolder) holder).imageView);
+ ((TrendingSearchViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.GONE);
+ ((TrendingSearchViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
+ ((TrendingSearchViewHolder) holder).noPreviewLinkImageView.setVisibility(View.GONE);
+ ((TrendingSearchViewHolder) holder).progressBar.setVisibility(View.GONE);
+ }
+ }
+
+ @Nullable
+ private Post.Preview getSuitablePreview(ArrayList<Post.Preview> previews) {
+ Post.Preview preview;
+ if (!previews.isEmpty()) {
+ int previewIndex;
+ if (dataSavingMode && previews.size() > 2) {
+ previewIndex = previews.size() / 2;
+ } else {
+ previewIndex = 0;
+ }
+ preview = previews.get(previewIndex);
+ if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) {
+ for (int i = previews.size() - 1; i >= 1; i--) {
+ preview = previews.get(i);
+ if (imageViewWidth >= preview.getPreviewWidth()) {
+ if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 10_000_000) {
+ return preview;
+ }
+ } else {
+ int height = imageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight();
+ if (imageViewWidth * height <= 10_000_000) {
+ return preview;
+ }
+ }
+ }
+ }
+
+ if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) {
+ int divisor = 2;
+ do {
+ preview.setPreviewWidth(preview.getPreviewWidth() / divisor);
+ preview.setPreviewHeight(preview.getPreviewHeight() / divisor);
+ divisor *= 2;
+ } while (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000);
+ }
+ return preview;
+ }
+
+ return null;
+ }
+
+ private void loadImage(final TrendingSearchViewHolder holder, @NonNull Post.Preview preview) {
+ String url = preview.getPreviewUrl();
+ RequestBuilder<Drawable> imageRequestBuilder = glide.load(url).listener(new RequestListener<Drawable>() {
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+ holder.progressBar.setVisibility(View.GONE);
+ holder.errorRelativeLayout.setVisibility(View.VISIBLE);
+ holder.errorRelativeLayout.setOnClickListener(view -> {
+ holder.progressBar.setVisibility(View.VISIBLE);
+ holder.errorRelativeLayout.setVisibility(View.GONE);
+ loadImage(holder, preview);
+ });
+ return false;
+ }
+
+ @Override
+ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+ holder.errorRelativeLayout.setVisibility(View.GONE);
+ holder.progressBar.setVisibility(View.GONE);
+ return false;
+ }
+ });
+
+ if (imageViewWidth > preview.getPreviewWidth()) {
+ imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(holder.imageView);
+ } else {
+ imageRequestBuilder.into(holder.imageView);
+ }
+ }
+
+ public void setTrendingSearches(ArrayList<TrendingSearch> trendingSearches) {
+ if (trendingSearches != null) {
+ this.trendingSearches = trendingSearches;
+ notifyItemRangeInserted(0, trendingSearches.size());
+ } else {
+ int size = this.trendingSearches == null ? 0 : this.trendingSearches.size();
+ this.trendingSearches = null;
+ notifyItemRangeRemoved(0, size);
+ }
+ }
+
+ class TrendingSearchViewHolder extends RecyclerView.ViewHolder {
+
+ @BindView(R.id.image_wrapper_relative_layout_item_trending_search)
+ RelativeLayout imageWrapperRelativeLayout;
+ @BindView(R.id.progress_bar_item_trending_search)
+ ProgressBar progressBar;
+ @BindView(R.id.image_view_item_trending_search)
+ AspectRatioGifImageView imageView;
+ @BindView(R.id.load_image_error_relative_layout_item_trending_search)
+ RelativeLayout errorRelativeLayout;
+ @BindView(R.id.load_image_error_text_view_item_trending_search)
+ TextView errorTextView;
+ @BindView(R.id.image_view_no_preview_gallery_item_trending_search)
+ ImageView noPreviewLinkImageView;
+ @BindView(R.id.title_text_view_item_trending_search)
+ TextView titleTextView;
+
+ public TrendingSearchViewHolder(@NonNull View itemView) {
+ super(itemView);
+ ButterKnife.bind(this, itemView);
+
+ noPreviewLinkImageView.setBackgroundColor(customThemeWrapper.getNoPreviewPostTypeBackgroundColor());
+ noPreviewLinkImageView.setColorFilter(customThemeWrapper.getNoPreviewPostTypeIconTint(), android.graphics.PorterDuff.Mode.SRC_IN);
+ progressBar.setIndeterminateTintList(ColorStateList.valueOf(customThemeWrapper.getColorAccent()));
+ errorTextView.setTextColor(customThemeWrapper.getPrimaryTextColor());
+
+ itemView.setOnClickListener(view -> {
+ itemClickListener.onClick(trendingSearches.get(getBindingAdapterPosition()));
+ });
+ }
+ }
+
+ public interface ItemClickListener {
+ void onClick(TrendingSearch trendingSearch);
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
index 5269da5f..44a65ebb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
@@ -5,6 +5,7 @@ import java.util.Map;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
+import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
@@ -137,21 +138,23 @@ public interface RedditAPI {
@GET("search.json?include_over_18=1&raw_json=1&type=link")
Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after,
- @Query("sort") String sort,
+ @Query("sort") String sort, @Query("source") String source,
@HeaderMap Map<String, String> headers);
@GET("search.json?include_over_18=1&raw_json=1&type=link")
Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after,
@Query("sort") String sort, @Query("t") String sortTime,
+ @Query("source") String source,
@HeaderMap Map<String, String> headers);
@GET("search.json?include_over_18=1&raw_json=1&type=link")
Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
- @Query("sort") String sort);
+ @Query("sort") String sort, @Query("source") String source);
@GET("search.json?include_over_18=1&raw_json=1&type=link")
Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
- @Query("sort") String sort, @Query("t") String sortTime);
+ @Query("sort") String sort, @Query("t") String sortTime,
+ @Query("source") String source);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName,
@@ -345,15 +348,24 @@ public interface RedditAPI {
@FormUrlEncoded
- @PUT("/api/multi{multipath}r/{subredditName}")
+ @PUT("/api/multi{multipath}/r/{subredditName}")
Call<String> addSubredditToMultiReddit(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params,
@Path(value = "multipath", encoded = true) String multipath, @Path("subredditName") String subredditName);
@FormUrlEncoded
- @POST("/api/quarantine_optin?raw_json=1")
+ @POST("/api/quarantine_option?raw_json=1")
Call<String> optInQuarantinedSubreddit(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
@GET("/api/subreddit_autocomplete_v2?typeahead_active=true&include_profiles=false&raw_json=1")
Call<String> subredditAutocomplete(@HeaderMap Map<String ,String> headers, @Query("query") String query,
@Query("include_over_18") boolean nsfw);
+
+ @POST("/api/submit_gallery_post.json?resubmit=true&raw_json=1")
+ Call<String> submitGalleryPost(@HeaderMap Map<String, String> headers, @Body String body);
+
+ @GET("/api/trending_searches_v1.json?withAds=0&raw_json=1&gilding_detail=1")
+ Call<String> getTrendingSearches(@HeaderMap Map<String, String> headers);
+
+ @GET("/r/{subredditName}/wiki/index.json?raw_json=1")
+ Call<String> getWiki(@Path("subredditName") String subredditName);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/Strapi.java b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/Strapi.java
index 02af768f..e68b8850 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/Strapi.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/Strapi.java
@@ -1,58 +1,12 @@
package ml.docilealligator.infinityforreddit.apis;
-import java.util.Map;
-
import retrofit2.Call;
-import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
-import retrofit2.http.HeaderMap;
-import retrofit2.http.POST;
import retrofit2.http.Path;
public interface Strapi {
@GET("/broadcasts")
- Call<String> getAllBroadcasts(@HeaderMap Map<String ,String> headers);
-
- /*
- Response:
- {"status": "success", "status_message": ""}
- */
- @FormUrlEncoded
- @POST("/videos/{rpan_id}/vote/up")
- Call<String> upvote(@HeaderMap Map<String, String> headers, @Path("rpan_id") String rpanId);
-
- @FormUrlEncoded
- @POST("/videos/{rpan_id}/vote/down")
- Call<String> downvote(@HeaderMap Map<String, String> headers, @Path("rpan_id") String rpanId);
-
- @FormUrlEncoded
- @POST("/videos/{rpan_id}/vote/unset")
- Call<String> unsetVote(@HeaderMap Map<String, String> headers, @Path("rpan_id") String rpanId);
-
- /*
- Request payload: {text: "Noice"}
-
- Response:
- {"status": "success", "status_message": "", "data": {"auto_mute_status": {"level": 0, "level_changed": false},
- "r2_comment": {"total_awards_received": 0, "approved_at_utc": null, "comment_type": null, "edited": false,
- "mod_reason_by": null, "banned_by": null, "author_flair_type": "text", "removal_reason": null, "link_id": "t3_of7btc",
- "author_flair_template_id": null, "likes": true, "rtjson": {"document": [{"c": [{"e": "text", "t": "Noice"}], "e": "par"}]},
- "replies": "", "user_reports": [], "saved": false, "id": "h4avk42", "banned_at_utc": null, "mod_reason_title": null,
- "gilded": 0, "archived": false, "no_follow": false, "author": "Hostilenemy", "can_mod_post": false, "send_replies": true,
- "parent_id": "t3_of7btc", "score": 1, "author_fullname": "t2_z40p4", "approved_by": null, "mod_note": null,
- "all_awardings": [], "subreddit_id": "t5_3psukr", "body": "Noice", "awarders": [], "downs": 0, "author_flair_css_class": null,
- "name": "t1_h4avk42", "author_patreon_flair": false, "collapsed": false, "author_flair_richtext": [], "is_submitter": false,
- "body_html": "<div class=\"md\"><p>Noice</p>\n</div>", "gildings": {}, "collapsed_reason": null, "distinguished": null,
- "associated_award": null, "stickied": false, "author_premium": false, "can_gild": false, "top_awarded_type": null,
- "author_flair_text_color": null, "score_hidden": false, "permalink": "/r/RedditSets/comments/of7btc/whistleface_762021_house_music/h4avk42/",
- "num_reports": null, "locked": false, "report_reasons": null, "created": 1625647709.0, "subreddit": "RedditSets", "author_flair_text": null,
- "treatment_tags": [], "rte_mode": "markdown", "created_utc": 1625618909.0, "subreddit_name_prefixed": "r/RedditSets",
- "controversiality": 0, "author_flair_background_color": null, "collapsed_because_crowd_control": null, "mod_reports": [],
- "subreddit_type": "public", "ups": 1}}}
- */
- @FormUrlEncoded
- @POST("/broadcasts/{rpan_id}/comment_v2")
- Call<String> sendComment(@HeaderMap Map<String, String> headers, @Path("rpan_id") String rpanId);
+ Call<String> getAllBroadcasts();
@GET("/videos/{rpan_id_or_fullname}")
Call<String> getRPANBroadcast(@Path("rpan_id_or_fullname") String rpanIdOrFullname);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java
index 6e87c4ee..7b6452ec 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java
@@ -53,23 +53,26 @@ public class CopyTextBottomSheetFragment extends RoundedBottomSheetDialogFragmen
View rootView = inflater.inflate(R.layout.fragment_copy_text_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
- String rawText = getArguments().getString(EXTRA_RAW_TEXT);
- markdownText = getArguments().getString(EXTRA_MARKDOWN);
- if (markdownText != null) {
- markdownText = markdownText.replaceAll("<sup>", "^").replaceAll("</sup>", "");
- }
+ String rawText = getArguments().getString(EXTRA_RAW_TEXT, null);
+ markdownText = getArguments().getString(EXTRA_MARKDOWN, null);
- copyRawTextTextView.setOnClickListener(view -> {
- showCopyDialog(rawText);
- dismiss();
- });
+ if (rawText != null) {
+ copyRawTextTextView.setOnClickListener(view -> {
+ showCopyDialog(rawText);
+ dismiss();
+ });
- copyAllRawTextTextView.setOnClickListener(view -> {
- copyText(rawText);
- dismiss();
- });
+ copyAllRawTextTextView.setOnClickListener(view -> {
+ copyText(rawText);
+ dismiss();
+ });
+ } else {
+ copyRawTextTextView.setVisibility(View.GONE);
+ copyAllRawTextTextView.setVisibility(View.GONE);
+ }
if (markdownText != null) {
+ markdownText = markdownText.replaceAll("<sup>", "^").replaceAll("</sup>", "");
copyMarkdownTextView.setOnClickListener(view -> {
showCopyDialog(markdownText);
dismiss();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java
index d8b39b7e..b7b651a6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java
@@ -12,7 +12,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
@@ -87,7 +86,6 @@ public class FlairBottomSheetFragment extends BottomSheetDialogFragment {
dismiss();
});
- recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(mAdapter);
mAccessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostTypeBottomSheetFragment.java
index 64b604ab..046c512b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostTypeBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostTypeBottomSheetFragment.java
@@ -30,6 +30,7 @@ public class PostTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen
public static final int TYPE_LINK = 1;
public static final int TYPE_IMAGE = 2;
public static final int TYPE_VIDEO = 3;
+ public static final int TYPE_GALLERY = 4;
@BindView(R.id.text_type_linear_layout_post_type_bottom_sheet_fragment)
TextView textTypeTextView;
@BindView(R.id.link_type_linear_layout_post_type_bottom_sheet_fragment)
@@ -38,6 +39,8 @@ public class PostTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen
TextView imageTypeTextView;
@BindView(R.id.video_type_linear_layout_post_type_bottom_sheet_fragment)
TextView videoTypeTextView;
+ @BindView(R.id.gallery_type_linear_layout_post_type_bottom_sheet_fragment)
+ TextView galleryTypeTextView;
private Activity activity;
public PostTypeBottomSheetFragment() {
@@ -75,6 +78,11 @@ public class PostTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen
dismiss();
});
+ galleryTypeTextView.setOnClickListener(view -> {
+ ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_GALLERY);
+ dismiss();
+ });
+
return rootView;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectOrCaptureImageBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectOrCaptureImageBottomSheetFragment.java
new file mode 100644
index 00000000..4be9b51f
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectOrCaptureImageBottomSheetFragment.java
@@ -0,0 +1,52 @@
+package ml.docilealligator.infinityforreddit.bottomsheetfragments;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+
+import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
+
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.activities.PostGalleryActivity;
+
+public class SelectOrCaptureImageBottomSheetFragment extends RoundedBottomSheetDialogFragment {
+
+ private PostGalleryActivity mActivity;
+
+ public SelectOrCaptureImageBottomSheetFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ View rootView = inflater.inflate(R.layout.fragment_select_or_capture_image_bottom_sheet, container, false);
+
+ TextView selectImageTextView = rootView.findViewById(R.id.select_image_text_view_select_or_capture_image_bottom_sheet_fragment);
+ TextView captureImageTextView = rootView.findViewById(R.id.capture_image_text_view_select_or_capture_image_bottom_sheet_fragment);
+
+ selectImageTextView.setOnClickListener(view -> {
+ mActivity.selectImage();
+ dismiss();
+ });
+
+ captureImageTextView.setOnClickListener(view -> {
+ mActivity.captureImage();
+ dismiss();
+ });
+
+ return rootView;
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ mActivity = (PostGalleryActivity) context;
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/WallpaperChangeReceiver.java b/app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/WallpaperChangeReceiver.java
index f994b1a9..5a596308 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/WallpaperChangeReceiver.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/WallpaperChangeReceiver.java
@@ -4,6 +4,8 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import androidx.core.content.ContextCompat;
+
import ml.docilealligator.infinityforreddit.services.MaterialYouService;
public class WallpaperChangeReceiver extends BroadcastReceiver {
@@ -11,6 +13,6 @@ public class WallpaperChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent materialYouIntent = new Intent(context, MaterialYouService.class);
- context.startService(materialYouIntent);
+ ContextCompat.startForegroundService(context, materialYouIntent);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/LinearLayoutManagerBugFixed.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/LinearLayoutManagerBugFixed.java
new file mode 100644
index 00000000..e2264225
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/LinearLayoutManagerBugFixed.java
@@ -0,0 +1,25 @@
+package ml.docilealligator.infinityforreddit.customviews;
+
+import android.content.Context;
+import android.util.AttributeSet;
+
+import androidx.recyclerview.widget.LinearLayoutManager;
+
+public class LinearLayoutManagerBugFixed extends LinearLayoutManager {
+ public LinearLayoutManagerBugFixed(Context context) {
+ super(context);
+ }
+
+ public LinearLayoutManagerBugFixed(Context context, int orientation, boolean reverseLayout) {
+ super(context, orientation, reverseLayout);
+ }
+
+ public LinearLayoutManagerBugFixed(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ @Override
+ public boolean supportsPredictiveItemAnimations() {
+ return false;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MarkwonLinearLayoutManager.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MarkwonLinearLayoutManager.java
index a654b437..35923fa6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MarkwonLinearLayoutManager.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MarkwonLinearLayoutManager.java
@@ -5,9 +5,7 @@ import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.HorizontalScrollView;
-import androidx.recyclerview.widget.LinearLayoutManager;
-
-public class MarkwonLinearLayoutManager extends LinearLayoutManager {
+public class MarkwonLinearLayoutManager extends LinearLayoutManagerBugFixed {
public interface HorizontalScrollViewScrolledListener {
void onScrolledLeft();
void onScrolledRight();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/ViewPagerBugFixed.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/ViewPagerBugFixed.java
new file mode 100644
index 00000000..78e7b88e
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/ViewPagerBugFixed.java
@@ -0,0 +1,37 @@
+package ml.docilealligator.infinityforreddit.customviews;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.viewpager.widget.ViewPager;
+
+public class ViewPagerBugFixed extends ViewPager {
+ public ViewPagerBugFixed(@NonNull Context context) {
+ super(context);
+ }
+
+ public ViewPagerBugFixed(@NonNull Context context, @Nullable AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev) {
+ try {
+ return super.onTouchEvent(ev);
+ } catch (IllegalArgumentException ignore) {}
+
+ return false;
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ try {
+ return super.onInterceptTouchEvent(ev);
+ } catch (IllegalArgumentException ignore) {}
+
+ return false;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeDefaultLinkPostLayoutEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeDefaultLinkPostLayoutEvent.java
new file mode 100644
index 00000000..d7897beb
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeDefaultLinkPostLayoutEvent.java
@@ -0,0 +1,9 @@
+package ml.docilealligator.infinityforreddit.events;
+
+public class ChangeDefaultLinkPostLayoutEvent {
+ public int defaultLinkPostLayout;
+
+ public ChangeDefaultLinkPostLayoutEvent(int defaultLinkPostLayout) {
+ this.defaultLinkPostLayout = defaultLinkPostLayout;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeRememberMutingOptionInPostFeedEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeRememberMutingOptionInPostFeedEvent.java
new file mode 100644
index 00000000..d49d5939
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ChangeRememberMutingOptionInPostFeedEvent.java
@@ -0,0 +1,9 @@
+package ml.docilealligator.infinityforreddit.events;
+
+public class ChangeRememberMutingOptionInPostFeedEvent {
+ public boolean rememberMutingOptionInPostFeedEvent;
+
+ public ChangeRememberMutingOptionInPostFeedEvent(boolean rememberMutingOptionInPostFeedEvent) {
+ this.rememberMutingOptionInPostFeedEvent = rememberMutingOptionInPostFeedEvent;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/SubmitGalleryPostEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/SubmitGalleryPostEvent.java
new file mode 100644
index 00000000..fcab85cd
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/SubmitGalleryPostEvent.java
@@ -0,0 +1,13 @@
+package ml.docilealligator.infinityforreddit.events;
+
+public class SubmitGalleryPostEvent {
+ public boolean postSuccess;
+ public String postUrl;
+ public String errorMessage;
+
+ public SubmitGalleryPostEvent(boolean postSuccess, String postUrl, String errorMessage) {
+ this.postSuccess = postSuccess;
+ this.postUrl = postUrl;
+ this.errorMessage = errorMessage;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ToggleSecureModeEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ToggleSecureModeEvent.java
new file mode 100644
index 00000000..a7c27eb3
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ToggleSecureModeEvent.java
@@ -0,0 +1,9 @@
+package ml.docilealligator.infinityforreddit.events;
+
+public class ToggleSecureModeEvent {
+ public boolean isSecureMode;
+
+ public ToggleSecureModeEvent(boolean isSecureMode) {
+ this.isSecureMode = isSecureMode;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java
index c730b4ba..04cabb7a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java
@@ -25,7 +25,6 @@ import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.ItemTouchHelper;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -50,6 +49,7 @@ import ml.docilealligator.infinityforreddit.activities.BaseActivity;
import ml.docilealligator.infinityforreddit.adapters.CommentsListingRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.comment.CommentViewModel;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
import retrofit2.Retrofit;
@@ -105,7 +105,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private String mAccessToken;
private RequestManager mGlide;
private AppCompatActivity mActivity;
- private LinearLayoutManager mLinearLayoutManager;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
private CommentsListingRecyclerViewAdapter mAdapter;
private SortType sortType;
private ColorDrawable backgroundSwipeRight;
@@ -255,7 +255,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private void bindView(Resources resources) {
if (mActivity != null && !mActivity.isFinishing() && !mActivity.isDestroyed()) {
- mLinearLayoutManager = new LinearLayoutManager(mActivity);
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity);
mCommentRecyclerView.setLayoutManager(mLinearLayoutManager);
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit, customThemeWrapper,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java
index 38726cd8..1fda28d4 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java
@@ -17,7 +17,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -40,6 +39,7 @@ import ml.docilealligator.infinityforreddit.activities.BaseActivity;
import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity;
import ml.docilealligator.infinityforreddit.adapters.FollowedUsersRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserViewModel;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
@@ -78,7 +78,7 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo
SubscribedUserViewModel mSubscribedUserViewModel;
private Activity mActivity;
private RequestManager mGlide;
- private LinearLayoutManager mLinearLayoutManager;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
public FollowedUsersListingFragment() {
// Required empty public constructor
@@ -109,7 +109,7 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo
mGlide = Glide.with(this);
- mLinearLayoutManager = new LinearLayoutManager(mActivity);
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity,
mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java
index b9879c3e..567f3a1b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java
@@ -14,7 +14,6 @@ import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -38,6 +37,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
import ml.docilealligator.infinityforreddit.adapters.MessageRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.events.RepliedToPrivateMessageEvent;
import ml.docilealligator.infinityforreddit.message.FetchMessage;
import ml.docilealligator.infinityforreddit.message.MessageViewModel;
@@ -72,7 +72,7 @@ public class InboxFragment extends Fragment implements FragmentCommunicator {
private String mWhere;
private MessageRecyclerViewAdapter mAdapter;
private RequestManager mGlide;
- private LinearLayoutManager mLinearLayoutManager;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
private BaseActivity mActivity;
public InboxFragment() {
@@ -106,7 +106,7 @@ public class InboxFragment extends Fragment implements FragmentCommunicator {
mWhere = arguments.getString(EXTRA_MESSAGE_WHERE, FetchMessage.WHERE_INBOX);
mAdapter = new MessageRecyclerViewAdapter(mActivity, mOauthRetrofit, mCustomThemeWrapper,
mAccessToken, mWhere, () -> mMessageViewModel.retryLoadingMore());
- mLinearLayoutManager = new LinearLayoutManager(mActivity);
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
mRecyclerView.setAdapter(mAdapter);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mActivity, mLinearLayoutManager.getOrientation());
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java
index fc0723eb..0f80d47a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java
@@ -17,7 +17,6 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -43,6 +42,7 @@ import ml.docilealligator.infinityforreddit.activities.ViewMultiRedditDetailActi
import ml.docilealligator.infinityforreddit.adapters.MultiRedditListingRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.MultiRedditOptionsBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
import ml.docilealligator.infinityforreddit.multireddit.MultiRedditViewModel;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@@ -80,7 +80,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
public MultiRedditViewModel mMultiRedditViewModel;
private AppCompatActivity mActivity;
private RequestManager mGlide;
- private LinearLayoutManager mLinearLayoutManager;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
public MultiRedditListingFragment() {
// Required empty public constructor
@@ -114,7 +114,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
mGlide = Glide.with(this);
- mLinearLayoutManager = new LinearLayoutManager(mActivity);
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(mActivity,
mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
index 4aa058d7..c98f27e6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -1,6 +1,9 @@
package ml.docilealligator.infinityforreddit.fragments;
+import static im.ene.toro.media.PlaybackInfo.INDEX_UNSET;
+import static im.ene.toro.media.PlaybackInfo.TIME_UNSET;
+
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -29,13 +32,13 @@ import android.widget.Toast;
import androidx.annotation.DimenRes;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.paging.PagedList;
import androidx.recyclerview.widget.ItemTouchHelper;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
@@ -78,9 +81,11 @@ import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivi
import ml.docilealligator.infinityforreddit.adapters.PostRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.CustomToroContainer;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.events.ChangeAutoplayNsfwVideosEvent;
import ml.docilealligator.infinityforreddit.events.ChangeCompactLayoutToolbarHiddenByDefaultEvent;
import ml.docilealligator.infinityforreddit.events.ChangeDataSavingModeEvent;
+import ml.docilealligator.infinityforreddit.events.ChangeDefaultLinkPostLayoutEvent;
import ml.docilealligator.infinityforreddit.events.ChangeDefaultPostLayoutEvent;
import ml.docilealligator.infinityforreddit.events.ChangeDisableImagePreviewEvent;
import ml.docilealligator.infinityforreddit.events.ChangeEnableSwipeActionSwitchEvent;
@@ -97,6 +102,7 @@ import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.events.ChangeOnlyDisablePreviewInVideoAndGifPostsEvent;
import ml.docilealligator.infinityforreddit.events.ChangePostLayoutEvent;
+import ml.docilealligator.infinityforreddit.events.ChangeRememberMutingOptionInPostFeedEvent;
import ml.docilealligator.infinityforreddit.events.ChangeSavePostFeedScrolledPositionEvent;
import ml.docilealligator.infinityforreddit.events.ChangeShowAbsoluteNumberOfVotesEvent;
import ml.docilealligator.infinityforreddit.events.ChangeShowElapsedTimeEvent;
@@ -123,9 +129,6 @@ import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
import retrofit2.Retrofit;
-import static im.ene.toro.media.PlaybackInfo.INDEX_UNSET;
-import static im.ene.toro.media.PlaybackInfo.TIME_UNSET;
-
/**
* A simple {@link Fragment} subclass.
@@ -136,6 +139,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
public static final String EXTRA_USER_NAME = "EUN";
public static final String EXTRA_USER_WHERE = "EUW";
public static final String EXTRA_QUERY = "EQ";
+ public static final String EXTRA_TRENDING_SOURCE = "ETS";
public static final String EXTRA_POST_TYPE = "EPT";
public static final String EXTRA_FILTER = "EF";
public static final String EXTRA_ACCESS_TOKEN = "EAT";
@@ -201,7 +205,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
Executor mExecutor;
private RequestManager mGlide;
private AppCompatActivity activity;
- private LinearLayoutManager mLinearLayoutManager;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
private StaggeredGridLayoutManager mStaggeredGridLayoutManager;
private long postFragmentId;
private int postType;
@@ -210,6 +214,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private boolean hasPost = false;
private boolean isShown = false;
private boolean savePostFeedScrolledPosition;
+ private boolean rememberMutingOptionInPostFeed;
+ private Boolean masterMutingOption;
private PostRecyclerViewAdapter mAdapter;
private RecyclerView.SmoothScroller smoothScroller;
private Window window;
@@ -221,6 +227,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private String subredditName;
private String username;
private String query;
+ private String trendingSource;
private String where;
private String multiRedditPath;
private String concatenatedSubredditNames;
@@ -415,6 +422,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, false);
+ rememberMutingOptionInPostFeed = mSharedPreferences.getBoolean(SharedPreferencesUtils.REMEMBER_MUTING_OPTION_IN_POST_FEED, false);
Locale locale = getResources().getConfiguration().locale;
int usage;
@@ -423,6 +431,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (postType == PostDataSource.TYPE_SEARCH) {
subredditName = getArguments().getString(EXTRA_NAME);
query = getArguments().getString(EXTRA_QUERY);
+ trendingSource = getArguments().getString(EXTRA_TRENDING_SOURCE);
if (savedInstanceState == null) {
postFragmentId += query.hashCode();
}
@@ -450,6 +459,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
+ intent.putExtra(FilteredPostsActivity.EXTRA_TRENDING_SOURCE, trendingSource);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter);
startActivity(intent);
@@ -460,6 +470,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
+ intent.putExtra(FilteredPostsActivity.EXTRA_TRENDING_SOURCE, trendingSource);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, flair);
startActivity(intent);
@@ -470,6 +481,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
+ intent.putExtra(FilteredPostsActivity.EXTRA_TRENDING_SOURCE, trendingSource);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE);
startActivity(intent);
@@ -835,7 +847,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
int nColumns = getNColumns(resources);
if (nColumns == 1) {
- mLinearLayoutManager = new LinearLayoutManager(activity);
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(activity);
mPostRecyclerView.setLayoutManager(mLinearLayoutManager);
} else {
mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(nColumns, StaggeredGridLayoutManager.VERTICAL);
@@ -1096,8 +1108,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
new Handler(), accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, mSharedPreferences,
- mPostFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType,
- postFilter, readPosts)).get(PostViewModel.class);
+ mPostFeedScrolledPositionSharedPreferences, subredditName, query, trendingSource,
+ postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
new Handler(), accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
@@ -1132,8 +1144,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
new Handler(), mRetrofit, null,
accountName, mSharedPreferences,
- mPostFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType,
- postFilter, readPosts)).get(PostViewModel.class);
+ mPostFeedScrolledPositionSharedPreferences, subredditName, query, trendingSource,
+ postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mExecutor,
new Handler(), mRetrofit, null,
@@ -1448,9 +1460,16 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
break;
}
+ int previousPosition = -1;
+ if (mLinearLayoutManager != null) {
+ previousPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
+ } else if (mStaggeredGridLayoutManager != null) {
+ int[] into = new int[mStaggeredGridLayoutManager.getSpanCount()];
+ previousPosition = mStaggeredGridLayoutManager.findFirstVisibleItemPositions(into)[0];
+ }
int nColumns = getNColumns(getResources());
if (nColumns == 1) {
- mLinearLayoutManager = new LinearLayoutManager(activity);
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(activity);
if (mPostRecyclerView.getItemDecorationCount() > 0) {
mPostRecyclerView.removeItemDecorationAt(0);
}
@@ -1468,6 +1487,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mLinearLayoutManager = null;
}
+ if (previousPosition > 0) {
+ mPostRecyclerView.scrollToPosition(previousPosition);
+ }
+
if (mAdapter != null) {
mAdapter.setPostLayout(postLayout);
refreshAdapter();
@@ -1509,6 +1532,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
+ intent.putExtra(FilteredPostsActivity.EXTRA_TRENDING_SOURCE, trendingSource);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
startActivity(intent);
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
@@ -1543,6 +1567,17 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
+ @Nullable
+ public Boolean getMasterMutingOption() {
+ return masterMutingOption;
+ }
+
+ public void videoAutoplayChangeMutingOption(boolean isMute) {
+ if (rememberMutingOptionInPostFeed) {
+ masterMutingOption = isMute;
+ }
+ }
+
@Subscribe
public void onPostUpdateEvent(PostUpdateEventToPostList event) {
PagedList<Post> posts = mAdapter.getCurrentList();
@@ -1650,6 +1685,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
@Subscribe
+ public void onChangeDefaultLinkPostLayoutEvent(ChangeDefaultLinkPostLayoutEvent event) {
+ if (mAdapter != null) {
+ mAdapter.setDefaultLinkPostLayout(event.defaultLinkPostLayout);
+ refreshAdapter();
+ }
+ }
+
+ @Subscribe
public void onChangeShowAbsoluteNumberOfVotesEvent(ChangeShowAbsoluteNumberOfVotesEvent changeShowAbsoluteNumberOfVotesEvent) {
if (mAdapter != null) {
mAdapter.setShowAbsoluteNumberOfVotes(changeShowAbsoluteNumberOfVotesEvent.showAbsoluteNumberOfVotes);
@@ -1871,6 +1914,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
+ @Subscribe
+ public void onChangeRememberMutingOptionInPostFeedEvent(ChangeRememberMutingOptionInPostFeedEvent event) {
+ rememberMutingOptionInPostFeed = event.rememberMutingOptionInPostFeedEvent;
+ if (!event.rememberMutingOptionInPostFeedEvent) {
+ masterMutingOption = null;
+ }
+ }
+
private void refreshAdapter() {
int previousPosition = -1;
if (mLinearLayoutManager != null) {
@@ -1885,7 +1936,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostRecyclerView.setLayoutManager(null);
mPostRecyclerView.setAdapter(mAdapter);
mPostRecyclerView.setLayoutManager(layoutManager);
-
if (previousPosition > 0) {
mPostRecyclerView.scrollToPosition(previousPosition);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
index 7297cb54..d7a77b07 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
@@ -17,7 +17,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -48,8 +47,10 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditData;
+import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditViewModel;
@@ -65,7 +66,7 @@ public class SidebarFragment extends Fragment {
private Activity activity;
private String subredditName;
public SubredditViewModel mSubredditViewModel;
- private LinearLayoutManager linearLayoutManager;
+ private LinearLayoutManagerBugFixed linearLayoutManager;
private int markdownColor;
@Inject
@Named("no_oauth")
@@ -76,6 +77,7 @@ public class SidebarFragment extends Fragment {
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
+ private String sidebarDescription;
public SidebarFragment() {
// Required empty public constructor
@@ -99,7 +101,7 @@ public class SidebarFragment extends Fragment {
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground());
swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
- markdownColor = mCustomThemeWrapper.getSecondaryTextColor();
+ markdownColor = mCustomThemeWrapper.getPrimaryTextColor();
Markwon markwon = Markwon.builder(activity)
.usePlugin(HtmlPlugin.create())
@@ -107,6 +109,16 @@ public class SidebarFragment extends Fragment {
@Override
public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
textView.setTextColor(markdownColor);
+ textView.setOnLongClickListener(view -> {
+ if (sidebarDescription != null && !sidebarDescription.equals("") && textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1) {
+ Bundle bundle = new Bundle();
+ bundle.putString(CopyTextBottomSheetFragment.EXTRA_MARKDOWN, sidebarDescription);
+ CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();
+ copyTextBottomSheetFragment.setArguments(bundle);
+ copyTextBottomSheetFragment.show(getChildFragmentManager(), copyTextBottomSheetFragment.getTag());
+ }
+ return true;
+ });
}
@Override
@@ -142,7 +154,7 @@ public class SidebarFragment extends Fragment {
.textLayoutIsRoot(R.layout.view_table_entry_cell)))
.build();
- linearLayoutManager = new LinearLayoutManager(activity);
+ linearLayoutManager = new LinearLayoutManagerBugFixed(activity);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(markwonAdapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@@ -162,8 +174,9 @@ public class SidebarFragment extends Fragment {
.get(SubredditViewModel.class);
mSubredditViewModel.getSubredditLiveData().observe(getViewLifecycleOwner(), subredditData -> {
if (subredditData != null) {
- if (subredditData.getSidebarDescription() != null && !subredditData.getSidebarDescription().equals("")) {
- markwonAdapter.setMarkdown(markwon, subredditData.getSidebarDescription());
+ sidebarDescription = subredditData.getSidebarDescription();
+ if (sidebarDescription != null && !sidebarDescription.equals("")) {
+ markwonAdapter.setMarkdown(markwon, sidebarDescription);
markwonAdapter.notifyDataSetChanged();
}
} else {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java
index e35520bd..46513616 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java
@@ -19,7 +19,6 @@ import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -46,6 +45,7 @@ import ml.docilealligator.infinityforreddit.activities.SearchSubredditsResultAct
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.adapters.SubredditListingRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditListingViewModel;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@@ -97,7 +97,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
- private LinearLayoutManager mLinearLayoutManager;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
private SubredditListingRecyclerViewAdapter mAdapter;
private Activity mActivity;
private SortType sortType;
@@ -131,7 +131,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
}
}
- mLinearLayoutManager = new LinearLayoutManager(getActivity());
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(getActivity());
mSubredditListingRecyclerView.setLayoutManager(mLinearLayoutManager);
String query = getArguments().getString(EXTRA_QUERY);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java
index 7bb69a76..61333955 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java
@@ -17,7 +17,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -41,6 +40,7 @@ import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditViewModel;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
@@ -82,7 +82,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
public SubscribedSubredditViewModel mSubscribedSubredditViewModel;
private Activity mActivity;
private RequestManager mGlide;
- private LinearLayoutManager mLinearLayoutManager;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
public SubscribedSubredditsListingFragment() {
// Required empty public constructor
@@ -115,7 +115,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
mGlide = Glide.with(this);
- mLinearLayoutManager = new LinearLayoutManager(mActivity);
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
SubscribedSubredditsRecyclerViewAdapter adapter;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java
index 5e894706..912176d5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java
@@ -19,7 +19,6 @@ import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -46,6 +45,7 @@ import ml.docilealligator.infinityforreddit.activities.SearchUsersResultActivity
import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.adapters.UserListingRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.user.UserData;
import ml.docilealligator.infinityforreddit.user.UserListingViewModel;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@@ -97,7 +97,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
- private LinearLayoutManager mLinearLayoutManager;
+ private LinearLayoutManagerBugFixed mLinearLayoutManager;
private String mQuery;
private UserListingRecyclerViewAdapter mAdapter;
private Activity mActivity;
@@ -132,7 +132,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
}
}
- mLinearLayoutManager = new LinearLayoutManager(getActivity());
+ mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity);
mUserListingRecyclerView.setLayoutManager(mLinearLayoutManager);
mQuery = getArguments().getString(EXTRA_QUERY);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java
index 0dcf1f01..2b6e9ea9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java
@@ -16,8 +16,10 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -36,6 +38,7 @@ import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
+import com.google.android.material.bottomappbar.BottomAppBar;
import java.io.File;
import java.util.concurrent.Executor;
@@ -57,6 +60,8 @@ import ml.docilealligator.infinityforreddit.services.DownloadMediaService;
public class ViewImgurImageFragment extends Fragment {
public static final String EXTRA_IMGUR_IMAGES = "EII";
+ public static final String EXTRA_INDEX = "EI";
+ public static final String EXTRA_MEDIA_COUNT = "EMC";
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
@BindView(R.id.progress_bar_view_imgur_image_fragment)
@@ -65,6 +70,16 @@ public class ViewImgurImageFragment extends Fragment {
SubsamplingScaleImageView imageView;
@BindView(R.id.load_image_error_linear_layout_view_imgur_image_fragment)
LinearLayout errorLinearLayout;
+ @BindView(R.id.bottom_navigation_view_imgur_image_fragment)
+ BottomAppBar bottomAppBar;
+ @BindView(R.id.title_text_view_view_imgur_image_fragment)
+ TextView titleTextView;
+ @BindView(R.id.download_image_view_view_imgur_image_fragment)
+ ImageView downloadImageView;
+ @BindView(R.id.share_image_view_view_imgur_image_fragment)
+ ImageView shareImageView;
+ @BindView(R.id.wallpaper_image_view_view_imgur_image_fragment)
+ ImageView wallpaperImageView;
@Inject
Executor mExecutor;
@@ -81,7 +96,7 @@ public class ViewImgurImageFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
- View rootView = inflater.inflate(R.layout.fragment_view_imgur_images, container, false);
+ View rootView = inflater.inflate(R.layout.fragment_view_imgur_image, container, false);
((Infinity) activity.getApplication()).getAppComponent().inject(this);
@@ -100,6 +115,9 @@ public class ViewImgurImageFragment extends Fragment {
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
isActionBarHidden = false;
+ if (activity.isUseBottomAppBar()) {
+ bottomAppBar.setVisibility(View.VISIBLE);
+ }
} else {
activity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
@@ -109,6 +127,9 @@ public class ViewImgurImageFragment extends Fragment {
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
isActionBarHidden = true;
+ if (activity.isUseBottomAppBar()) {
+ bottomAppBar.setVisibility(View.GONE);
+ }
}
});
imageView.setMinimumDpi(80);
@@ -121,6 +142,25 @@ public class ViewImgurImageFragment extends Fragment {
loadImage();
});
+ if (activity.isUseBottomAppBar()) {
+ bottomAppBar.setVisibility(View.VISIBLE);
+ titleTextView.setText(getString(R.string.view_imgur_media_activity_image_label,
+ getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
+ downloadImageView.setOnClickListener(view -> {
+ if (isDownloading) {
+ return;
+ }
+ isDownloading = true;
+ requestPermissionAndDownload();
+ });
+ shareImageView.setOnClickListener(view -> {
+ shareImage();
+ });
+ wallpaperImageView.setOnClickListener(view -> {
+ setWallpaper();
+ });
+ }
+
return rootView;
}
@@ -164,83 +204,39 @@ public class ViewImgurImageFragment extends Fragment {
if (isDownloading) {
return false;
}
-
isDownloading = true;
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- if (ContextCompat.checkSelfPermission(activity,
- Manifest.permission.WRITE_EXTERNAL_STORAGE)
- != PackageManager.PERMISSION_GRANTED) {
-
- // Permission is not granted
- // No explanation needed; request the permission
- requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
- PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
- } else {
- // Permission has already been granted
- download();
- }
- } else {
- download();
- }
-
+ requestPermissionAndDownload();
return true;
} else if (itemId == R.id.action_share_view_imgur_image_fragment) {
- glide.asBitmap().load(imgurMedia.getLink()).into(new CustomTarget<Bitmap>() {
-
- @Override
- public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
- if (activity.getExternalCacheDir() != null) {
- Toast.makeText(activity, R.string.save_image_first, Toast.LENGTH_SHORT).show();
- SaveBitmapImageToFile.SaveBitmapImageToFile(mExecutor, new Handler(), resource, activity.getExternalCacheDir().getPath(),
- imgurMedia.getFileName(),
- new SaveBitmapImageToFile.SaveBitmapImageToFileListener() {
- @Override
- public void saveSuccess(File imageFile) {
- Uri uri = FileProvider.getUriForFile(activity,
- BuildConfig.APPLICATION_ID + ".provider", imageFile);
- Intent shareIntent = new Intent();
- shareIntent.setAction(Intent.ACTION_SEND);
- shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
- shareIntent.setType("image/*");
- shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- startActivity(Intent.createChooser(shareIntent, getString(R.string.share)));
- }
-
- @Override
- public void saveFailed() {
- Toast.makeText(activity,
- R.string.cannot_save_image, Toast.LENGTH_SHORT).show();
- }
- });
- } else {
- Toast.makeText(activity,
- R.string.cannot_get_storage, Toast.LENGTH_SHORT).show();
- }
- }
-
- @Override
- public void onLoadCleared(@Nullable Drawable placeholder) {
-
- }
- });
+ shareImage();
return true;
} else if (itemId == R.id.action_set_wallpaper_view_imgur_image_fragment) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment();
- Bundle bundle = new Bundle();
- bundle.putInt(SetAsWallpaperBottomSheetFragment.EXTRA_VIEW_PAGER_POSITION, activity.getCurrentPagePosition());
- setAsWallpaperBottomSheetFragment.setArguments(bundle);
- setAsWallpaperBottomSheetFragment.show(activity.getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag());
- } else {
- ((SetAsWallpaperCallback) activity).setToBoth(activity.getCurrentPagePosition());
- }
+ setWallpaper();
return true;
}
return false;
}
+ private void requestPermissionAndDownload() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
+ if (ContextCompat.checkSelfPermission(activity,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ != PackageManager.PERMISSION_GRANTED) {
+
+ // Permission is not granted
+ // No explanation needed; request the permission
+ requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
+ PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
+ } else {
+ // Permission has already been granted
+ download();
+ }
+ } else {
+ download();
+ }
+ }
+
private void download() {
isDownloading = false;
@@ -252,6 +248,59 @@ public class ViewImgurImageFragment extends Fragment {
Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
}
+ private void shareImage() {
+ glide.asBitmap().load(imgurMedia.getLink()).into(new CustomTarget<Bitmap>() {
+
+ @Override
+ public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
+ if (activity.getExternalCacheDir() != null) {
+ Toast.makeText(activity, R.string.save_image_first, Toast.LENGTH_SHORT).show();
+ SaveBitmapImageToFile.SaveBitmapImageToFile(mExecutor, new Handler(), resource, activity.getExternalCacheDir().getPath(),
+ imgurMedia.getFileName(),
+ new SaveBitmapImageToFile.SaveBitmapImageToFileListener() {
+ @Override
+ public void saveSuccess(File imageFile) {
+ Uri uri = FileProvider.getUriForFile(activity,
+ BuildConfig.APPLICATION_ID + ".provider", imageFile);
+ Intent shareIntent = new Intent();
+ shareIntent.setAction(Intent.ACTION_SEND);
+ shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
+ shareIntent.setType("image/*");
+ shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ startActivity(Intent.createChooser(shareIntent, getString(R.string.share)));
+ }
+
+ @Override
+ public void saveFailed() {
+ Toast.makeText(activity,
+ R.string.cannot_save_image, Toast.LENGTH_SHORT).show();
+ }
+ });
+ } else {
+ Toast.makeText(activity,
+ R.string.cannot_get_storage, Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ @Override
+ public void onLoadCleared(@Nullable Drawable placeholder) {
+
+ }
+ });
+ }
+
+ private void setWallpaper() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment();
+ Bundle bundle = new Bundle();
+ bundle.putInt(SetAsWallpaperBottomSheetFragment.EXTRA_VIEW_PAGER_POSITION, activity.getCurrentPagePosition());
+ setAsWallpaperBottomSheetFragment.setArguments(bundle);
+ setAsWallpaperBottomSheetFragment.show(activity.getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag());
+ } else {
+ ((SetAsWallpaperCallback) activity).setToBoth(activity.getCurrentPagePosition());
+ }
+ }
+
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {
@@ -269,4 +318,10 @@ public class ViewImgurImageFragment extends Fragment {
super.onAttach(context);
activity = (ViewImgurMediaActivity) context;
}
+
+ @Override
+ public void onDestroyView() {
+ super.onDestroyView();
+ glide.clear(imageView);
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java
index 01961e17..65b283e1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java
@@ -1,7 +1,6 @@
package ml.docilealligator.infinityforreddit.fragments;
import android.Manifest;
-import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -18,7 +17,9 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
+import android.widget.ImageView;
import android.widget.LinearLayout;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -39,6 +40,7 @@ import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
+import com.google.android.material.bottomappbar.BottomAppBar;
import javax.inject.Inject;
import javax.inject.Named;
@@ -48,6 +50,7 @@ import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ImgurMedia;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity;
import ml.docilealligator.infinityforreddit.services.DownloadMediaService;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@@ -56,12 +59,20 @@ public class ViewImgurVideoFragment extends Fragment {
public static final String EXTRA_IMGUR_VIDEO = "EIV";
private static final String IS_MUTE_STATE = "IMS";
private static final String POSITION_STATE = "PS";
+ public static final String EXTRA_INDEX = "EI";
+ public static final String EXTRA_MEDIA_COUNT = "EMC";
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
@BindView(R.id.player_view_view_imgur_video_fragment)
PlayerView videoPlayerView;
@BindView(R.id.mute_exo_playback_control_view)
ImageButton muteButton;
- private Activity activity;
+ @BindView(R.id.bottom_navigation_exo_playback_control_view)
+ BottomAppBar bottomAppBar;
+ @BindView(R.id.title_text_view_exo_playback_control_view)
+ TextView titleTextView;
+ @BindView(R.id.download_image_view_exo_playback_control_view)
+ ImageView downloadImageView;
+ private ViewImgurMediaActivity activity;
private ImgurMedia imgurMedia;
private SimpleExoPlayer player;
private DataSource.Factory dataSourceFactory;
@@ -136,6 +147,19 @@ public class ViewImgurVideoFragment extends Fragment {
player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(imgurMedia.getLink())));
preparePlayer(savedInstanceState);
+ if (activity.isUseBottomAppBar()) {
+ bottomAppBar.setVisibility(View.VISIBLE);
+ titleTextView.setText(getString(R.string.view_imgur_media_activity_video_label,
+ getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
+ downloadImageView.setOnClickListener(view -> {
+ if (isDownloading) {
+ return;
+ }
+ isDownloading = true;
+ requestPermissionAndDownload();
+ });
+ }
+
return rootView;
}
@@ -149,25 +173,29 @@ public class ViewImgurVideoFragment extends Fragment {
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.action_download_view_imgur_video_fragment) {
isDownloading = true;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- if (ContextCompat.checkSelfPermission(activity,
- Manifest.permission.WRITE_EXTERNAL_STORAGE)
- != PackageManager.PERMISSION_GRANTED) {
-
- // Permission is not granted
- // No explanation needed; request the permission
- requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
- PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
- } else {
- // Permission has already been granted
- download();
- }
+ requestPermissionAndDownload();
+ return true;
+ }
+ return false;
+ }
+
+ private void requestPermissionAndDownload() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
+ if (ContextCompat.checkSelfPermission(activity,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ != PackageManager.PERMISSION_GRANTED) {
+
+ // Permission is not granted
+ // No explanation needed; request the permission
+ requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
+ PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
} else {
+ // Permission has already been granted
download();
}
- return true;
+ } else {
+ download();
}
- return false;
}
@Override
@@ -282,6 +310,6 @@ public class ViewImgurVideoFragment extends Fragment {
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
- activity = (Activity) context;
+ activity = (ViewImgurMediaActivity) context;
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
index 40d2ff9f..2b79125d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
@@ -1,5 +1,10 @@
package ml.docilealligator.infinityforreddit.fragments;
+import static im.ene.toro.media.PlaybackInfo.INDEX_UNSET;
+import static im.ene.toro.media.PlaybackInfo.TIME_UNSET;
+import static ml.docilealligator.infinityforreddit.activities.CommentActivity.RETURN_EXTRA_COMMENT_DATA_KEY;
+import static ml.docilealligator.infinityforreddit.activities.CommentActivity.WRITE_COMMENT_REQUEST_CODE;
+
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
@@ -33,7 +38,6 @@ import androidx.core.graphics.drawable.DrawableCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.ConcatAdapter;
import androidx.recyclerview.widget.ItemTouchHelper;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -89,6 +93,7 @@ import ml.docilealligator.infinityforreddit.comment.FetchRemovedComment;
import ml.docilealligator.infinityforreddit.comment.ParseComment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.CustomToroContainer;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.events.ChangeSpoilerBlurEvent;
@@ -111,11 +116,6 @@ import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
-import static im.ene.toro.media.PlaybackInfo.INDEX_UNSET;
-import static im.ene.toro.media.PlaybackInfo.TIME_UNSET;
-import static ml.docilealligator.infinityforreddit.activities.CommentActivity.RETURN_EXTRA_COMMENT_DATA_KEY;
-import static ml.docilealligator.infinityforreddit.activities.CommentActivity.WRITE_COMMENT_REQUEST_CODE;
-
public class ViewPostDetailFragment extends Fragment implements FragmentCommunicator {
public static final String EXTRA_POST_DATA = "EPD";
@@ -167,6 +167,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Named("current_account")
SharedPreferences mCurrentAccountSharedPreferences;
@Inject
+ @Named("post_details")
+ SharedPreferences mPostDetailsSharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
ExoCreator mExoCreator;
@@ -215,8 +218,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
private boolean mLockFab;
private boolean mSwipeUpToHideFab;
private boolean mExpandChildren;
+ private boolean mSeparatePostAndComments = false;
private int mWindowWidth;
- private LinearLayoutManager mLinearLayoutManager;
private ConcatAdapter mConcatAdapter;
private PostDetailRecyclerViewAdapter mPostAdapter;
private CommentsRecyclerViewAdapter mCommentsAdapter;
@@ -261,13 +264,17 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mUnsavedIcon = getMenuItemIcon(R.drawable.ic_bookmark_border_toolbar_24dp);
if (getResources().getBoolean(R.bool.isTablet) || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
- mLinearLayoutManager = new LinearLayoutManager(activity);
mCommentsRecyclerView = rootView.findViewById(R.id.comments_recycler_view_view_post_detail_fragment);
- mCommentsRecyclerView.setLayoutManager(mLinearLayoutManager);
- mRecyclerView.setLayoutManager(new LinearLayoutManager(activity));
+ }
+ if (!((mPostDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.SEPARATE_POST_AND_COMMENTS_IN_LANDSCAPE_MODE, true)
+ && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
+ || (mPostDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.SEPARATE_POST_AND_COMMENTS_IN_PORTRAIT_MODE, false)))) {
+ if (mCommentsRecyclerView != null) {
+ mCommentsRecyclerView.setVisibility(View.GONE);
+ mCommentsRecyclerView = null;
+ }
} else {
- mLinearLayoutManager = new LinearLayoutManager(activity);
- mRecyclerView.setLayoutManager(mLinearLayoutManager);
+ mSeparatePostAndComments = true;
}
if (activity != null && activity.isImmersiveInterface()) {
@@ -319,9 +326,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
if (!isLoadingMoreChildren && loadMoreChildrenSuccess) {
- int visibleItemCount = mLinearLayoutManager.getChildCount();
- int totalItemCount = mLinearLayoutManager.getItemCount();
- int firstVisibleItemPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
+ int visibleItemCount = (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().getChildCount();
+ int totalItemCount = (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().getItemCount();
+ int firstVisibleItemPosition = ((LinearLayoutManagerBugFixed) (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager()).findFirstVisibleItemPosition();
if (mCommentsAdapter != null && mCommentsAdapter.getItemCount() >= 1 && (visibleItemCount + firstVisibleItemPosition >= totalItemCount) && firstVisibleItemPosition >= 0) {
fetchMoreComments();
@@ -537,13 +544,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide,
- mWindowWidth, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
- isSingleCommentThreadMode, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mExoCreator, new PostDetailRecyclerViewAdapter.PostDetailRecyclerViewAdapterCallback() {
- @Override
- public void updatePost(Post post) {
- EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
- }
- });
+ mWindowWidth, mSeparatePostAndComments, mAccessToken, mAccountName, mPost, mLocale,
+ mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences,
+ mExoCreator, post -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
mCommentsAdapter = new CommentsRecyclerViewAdapter(activity,
this, mCustomThemeWrapper, mExecutor, mRetrofit, mOauthRetrofit,
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
@@ -755,8 +758,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
public void goToTop() {
- if (mLinearLayoutManager != null) {
- mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ ((LinearLayoutManagerBugFixed) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(0, 0);
+ if (mCommentsRecyclerView != null) {
+ ((LinearLayoutManagerBugFixed) mCommentsRecyclerView.getLayoutManager()).scrollToPositionWithOffset(0, 0);
}
}
@@ -766,6 +770,61 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
}
+ public void searchComment(String query, boolean searchNextComment) {
+ if (mCommentsAdapter != null) {
+ ArrayList<Comment> visibleComments = mCommentsAdapter.getVisibleComments();
+ int currentSearchIndex = mCommentsAdapter.getSearchCommentIndex();
+ if (currentSearchIndex >= 0) {
+ mCommentsAdapter.notifyItemChanged(currentSearchIndex);
+ }
+ if (visibleComments != null) {
+ if (searchNextComment) {
+ for (int i = currentSearchIndex + 1; i < visibleComments.size(); i++) {
+ if (visibleComments.get(i).getCommentRawText() != null &&
+ visibleComments.get(i).getCommentRawText().toLowerCase().contains(query.toLowerCase())) {
+ if (mCommentsAdapter != null) {
+ mCommentsAdapter.highlightSearchResult(i);
+ mCommentsAdapter.notifyItemChanged(i);
+ if (mCommentsRecyclerView == null) {
+ mRecyclerView.scrollToPosition(i + 1);
+ } else {
+ mCommentsRecyclerView.scrollToPosition(i);
+ }
+ }
+ return;
+ }
+ }
+
+ return;
+ } else {
+ for (int i = currentSearchIndex - 1; i >= 0; i--) {
+ if (visibleComments.get(i).getCommentRawText() !=null &&
+ visibleComments.get(i).getCommentRawText().toLowerCase().contains(query.toLowerCase())) {
+ if (mCommentsAdapter != null) {
+ mCommentsAdapter.highlightSearchResult(i);
+ mCommentsAdapter.notifyItemChanged(i);
+ if (mCommentsRecyclerView == null) {
+ mRecyclerView.scrollToPosition(i + 1);
+ } else {
+ mCommentsRecyclerView.scrollToPosition(i);
+ }
+ }
+ return;
+ }
+ }
+
+ return;
+ }
+ }
+ }
+ }
+
+ public void resetSearchCommentIndex() {
+ if (mCommentsAdapter != null) {
+ mCommentsAdapter.resetCommentSearchIndex();
+ }
+ }
+
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.view_post_detail_fragment, menu);
@@ -779,7 +838,11 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int itemId = item.getItemId();
- if (itemId == R.id.action_refresh_view_post_detail_fragment) {
+ if (itemId == R.id.action_search_view_post_detail_fragment) {
+ if (activity.toggleSearchPanelVisibility() && mCommentsAdapter != null) {
+ mCommentsAdapter.resetCommentSearchIndex();
+ }
+ } else if (itemId == R.id.action_refresh_view_post_detail_fragment) {
refresh(true, true);
return true;
} else if (itemId == R.id.action_comment_view_post_detail_fragment) {
@@ -1116,10 +1179,10 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper,
mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit,
- mRedditDataRoomDatabase, mGlide, mWindowWidth, mAccessToken,
- mAccountName, mPost, mLocale, mSingleCommentId,
- isSingleCommentThreadMode, mSharedPreferences,
- mNsfwAndSpoilerSharedPreferences, mExoCreator,
+ mRedditDataRoomDatabase, mGlide, mWindowWidth, mSeparatePostAndComments,
+ mAccessToken, mAccountName, mPost, mLocale, mSharedPreferences,
+ mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences,
+ mExoCreator,
post1 -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
mCommentsAdapter = new CommentsRecyclerViewAdapter(activity,
@@ -1187,9 +1250,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
if (!isLoadingMoreChildren && loadMoreChildrenSuccess) {
- int visibleItemCount = mLinearLayoutManager.getChildCount();
- int totalItemCount = mLinearLayoutManager.getItemCount();
- int firstVisibleItemPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
+ int visibleItemCount = (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().getChildCount();
+ int totalItemCount = (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().getItemCount();
+ int firstVisibleItemPosition = ((LinearLayoutManagerBugFixed) (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager()).findFirstVisibleItemPosition();
if ((visibleItemCount + firstVisibleItemPosition >= totalItemCount) && firstVisibleItemPosition >= 0) {
fetchMoreComments();
@@ -1325,9 +1388,9 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
if (!isLoadingMoreChildren && loadMoreChildrenSuccess) {
- int visibleItemCount = mLinearLayoutManager.getChildCount();
- int totalItemCount = mLinearLayoutManager.getItemCount();
- int firstVisibleItemPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
+ int visibleItemCount = (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().getChildCount();
+ int totalItemCount = (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().getItemCount();
+ int firstVisibleItemPosition = ((LinearLayoutManagerBugFixed) (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager()).findFirstVisibleItemPosition();
if ((visibleItemCount + firstVisibleItemPosition >= totalItemCount) && firstVisibleItemPosition >= 0) {
fetchMoreComments();
@@ -1657,36 +1720,28 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}
public void scrollToNextParentComment() {
- if (mLinearLayoutManager != null) {
- int currentPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
- if (mCommentsAdapter != null) {
- int nextParentPosition = mCommentsAdapter.getNextParentCommentPosition(mCommentsRecyclerView == null ? currentPosition - 1 : currentPosition);
- if (nextParentPosition < 0) {
- return;
- }
- mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null ? nextParentPosition + 1 : nextParentPosition);
- if (mLinearLayoutManager != null) {
- mIsSmoothScrolling = true;
- mLinearLayoutManager.startSmoothScroll(mSmoothScroller);
- }
+ int currentPosition = ((LinearLayoutManagerBugFixed) (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager()).findFirstVisibleItemPosition();
+ if (mCommentsAdapter != null) {
+ int nextParentPosition = mCommentsAdapter.getNextParentCommentPosition(mCommentsRecyclerView == null ? currentPosition - 1 : currentPosition);
+ if (nextParentPosition < 0) {
+ return;
}
+ mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null ? nextParentPosition + 1 : nextParentPosition);
+ mIsSmoothScrolling = true;
+ (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().startSmoothScroll(mSmoothScroller);
}
}
public void scrollToPreviousParentComment() {
- if (mLinearLayoutManager != null) {
- int currentPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
- if (mCommentsAdapter != null) {
- int previousParentPosition = mCommentsAdapter.getPreviousParentCommentPosition(mCommentsRecyclerView == null ? currentPosition - 1 : currentPosition);
- if (previousParentPosition < 0) {
- return;
- }
- mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null ? previousParentPosition + 1 : previousParentPosition);
- if (mLinearLayoutManager != null) {
- mIsSmoothScrolling = true;
- mLinearLayoutManager.startSmoothScroll(mSmoothScroller);
- }
+ int currentPosition = ((LinearLayoutManagerBugFixed) (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager()).findFirstVisibleItemPosition();
+ if (mCommentsAdapter != null) {
+ int previousParentPosition = mCommentsAdapter.getPreviousParentCommentPosition(mCommentsRecyclerView == null ? currentPosition - 1 : currentPosition);
+ if (previousParentPosition < 0) {
+ return;
}
+ mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null ? previousParentPosition + 1 : previousParentPosition);
+ mIsSmoothScrolling = true;
+ (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().startSmoothScroll(mSmoothScroller);
}
}
@@ -1767,7 +1822,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
private void refreshAdapter(RecyclerView recyclerView, RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {
int previousPosition = -1;
if (recyclerView.getLayoutManager() != null) {
- previousPosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
+ previousPosition = ((LinearLayoutManagerBugFixed) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
}
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java
index 219a55de..8c0c2f57 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java
@@ -6,20 +6,22 @@ import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.request.RequestOptions;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.Player;
@@ -47,18 +49,21 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RPANBroadcast;
import ml.docilealligator.infinityforreddit.RPANComment;
import ml.docilealligator.infinityforreddit.adapters.RPANCommentStreamRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.utils.JSONUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
+import retrofit2.Retrofit;
public class ViewRPANBroadcastFragment extends Fragment {
@@ -69,6 +74,14 @@ public class ViewRPANBroadcastFragment extends Fragment {
ConstraintLayout constraintLayout;
@BindView(R.id.player_view_view_rpan_broadcast_fragment)
PlayerView playerView;
+ @BindView(R.id.subreddit_icon_image_view_exo_rpan_broadcast_playback_control_view)
+ ImageView subredditIconImageView;
+ @BindView(R.id.subreddit_name_text_view_exo_rpan_broadcast_playback_control_view)
+ TextView subredditNameTextView;
+ @BindView(R.id.username_text_view_exo_rpan_broadcast_playback_control_view)
+ TextView usernameTextView;
+ @BindView(R.id.title_text_view_exo_rpan_broadcast_playback_control_view)
+ TextView titleTextView;
@BindView(R.id.recycler_view_exo_rpan_broadcast_playback_control_view)
RecyclerView recyclerView;
@BindView(R.id.mute_exo_rpan_broadcast_playback_control_view)
@@ -76,6 +89,9 @@ public class ViewRPANBroadcastFragment extends Fragment {
@BindView(R.id.hd_exo_rpan_broadcast_playback_control_view)
ImageButton hdButton;
@Inject
+ @Named("strapi")
+ Retrofit mStrapiRetrofit;
+ @Inject
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
@@ -142,6 +158,7 @@ public class ViewRPANBroadcastFragment extends Fragment {
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
+ playerView.setControllerShowTimeoutMs(0);
break;
case View.VISIBLE:
mActivity.getWindow().getDecorView().setSystemUiVisibility(
@@ -221,6 +238,15 @@ public class ViewRPANBroadcastFragment extends Fragment {
}
});
+ Glide.with(mActivity).load(rpanBroadcast.rpanPost.subredditIconUrl)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .error(Glide.with(mActivity).load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
+ .into(subredditIconImageView);
+ subredditNameTextView.setText(rpanBroadcast.rpanPost.subredditName);
+ usernameTextView.setText(rpanBroadcast.rpanPost.username);
+ titleTextView.setText(rpanBroadcast.rpanPost.title);
+
recyclerView.setOnTouchListener(new View.OnTouchListener() {
float x1;
float x2;
@@ -248,12 +274,7 @@ public class ViewRPANBroadcastFragment extends Fragment {
return false;
}
});
- adapter = new RPANCommentStreamRecyclerViewAdapter(mActivity, new RPANCommentStreamRecyclerViewAdapter.ItemClickListener() {
- @Override
- public void onClick() {
-
- }
- });
+ adapter = new RPANCommentStreamRecyclerViewAdapter(mActivity);
recyclerView.setAdapter(adapter);
handler = new Handler();
@@ -288,7 +309,7 @@ public class ViewRPANBroadcastFragment extends Fragment {
payload.getLong(JSONUtils.CREATED_UTC_KEY));
handler.post(() -> {
- LinearLayoutManager manager = ((LinearLayoutManager) recyclerView.getLayoutManager());
+ LinearLayoutManagerBugFixed manager = ((LinearLayoutManagerBugFixed) recyclerView.getLayoutManager());
boolean shouldScrollToBottom = false;
if (manager != null) {
int lastPosition = manager.findLastCompletelyVisibleItemPosition();
@@ -373,7 +394,6 @@ public class ViewRPANBroadcastFragment extends Fragment {
@Override
public void onMessage(@NonNull WebSocket webSocket, @NonNull String text) {
- Log.i("asfasdf", "s " + text);
messageReceivedListener.onMessage(text);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java
index 75e3b2c6..cee6d404 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java
@@ -16,8 +16,10 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -41,6 +43,7 @@ import com.github.piasy.biv.loader.ImageLoader;
import com.github.piasy.biv.loader.glide.GlideImageLoader;
import com.github.piasy.biv.view.BigImageView;
import com.github.piasy.biv.view.GlideImageViewFactory;
+import com.google.android.material.bottomappbar.BottomAppBar;
import java.io.File;
import java.util.concurrent.Executor;
@@ -64,6 +67,8 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
public static final String EXTRA_REDDIT_GALLERY_MEDIA = "ERGM";
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
+ public static final String EXTRA_INDEX = "EI";
+ public static final String EXTRA_MEDIA_COUNT = "EMC";
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
@BindView(R.id.progress_bar_view_reddit_gallery_image_or_gif_fragment)
@@ -72,6 +77,16 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
BigImageView imageView;
@BindView(R.id.load_image_error_linear_layout_view_reddit_gallery_image_or_gif_fragment)
LinearLayout errorLinearLayout;
+ @BindView(R.id.bottom_navigation_view_reddit_gallery_image_or_gif_fragment)
+ BottomAppBar bottomAppBar;
+ @BindView(R.id.title_text_view_view_reddit_gallery_image_or_gif_fragment)
+ TextView titleTextView;
+ @BindView(R.id.download_image_view_view_reddit_gallery_image_or_gif_fragment)
+ ImageView downloadImageView;
+ @BindView(R.id.share_image_view_view_reddit_gallery_image_or_gif_fragment)
+ ImageView shareImageView;
+ @BindView(R.id.wallpaper_image_view_view_reddit_gallery_image_or_gif_fragment)
+ ImageView wallpaperImageView;
@Inject
Executor mExecutor;
@@ -192,6 +207,9 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
isActionBarHidden = false;
+ if (activity.isUseBottomAppBar()) {
+ bottomAppBar.setVisibility(View.VISIBLE);
+ }
} else {
activity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
@@ -201,6 +219,9 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
isActionBarHidden = true;
+ if (activity.isUseBottomAppBar()) {
+ bottomAppBar.setVisibility(View.GONE);
+ }
}
});
@@ -210,6 +231,34 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
loadImage();
});
+ if (activity.isUseBottomAppBar()) {
+ bottomAppBar.setVisibility(View.VISIBLE);
+ if (media.mediaType == Post.Gallery.TYPE_GIF) {
+ titleTextView.setText(getString(R.string.view_reddit_gallery_activity_gif_label,
+ getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
+ } else {
+ titleTextView.setText(getString(R.string.view_reddit_gallery_activity_image_label,
+ getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
+ }
+ downloadImageView.setOnClickListener(view -> {
+ if (isDownloading) {
+ return;
+ }
+ isDownloading = true;
+ requestPermissionAndDownload();
+ });
+ shareImageView.setOnClickListener(view -> {
+ if (media.mediaType == Post.Gallery.TYPE_GIF) {
+ shareGif();
+ } else {
+ shareImage();
+ }
+ });
+ wallpaperImageView.setOnClickListener(view -> {
+ setWallpaper();
+ });
+ }
+
return rootView;
}
@@ -225,53 +274,46 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
- switch (item.getItemId()) {
- case R.id.action_download_view_reddit_gallery_image_or_gif_fragment:
- if (isDownloading) {
- return false;
- }
+ int itemId = item.getItemId();
+ if (itemId == R.id.action_download_view_reddit_gallery_image_or_gif_fragment) {
+ if (isDownloading) {
+ return false;
+ }
+ isDownloading = true;
+ requestPermissionAndDownload();
+ return true;
+ } else if (itemId == R.id.action_share_view_reddit_gallery_image_or_gif_fragment) {
+ if (media.mediaType == Post.Gallery.TYPE_GIF) {
+ shareGif();
+ } else {
+ shareImage();
+ }
+ return true;
+ } else if (itemId == R.id.action_set_wallpaper_view_reddit_gallery_image_or_gif_fragment) {
+ setWallpaper();
+ return true;
+ }
- isDownloading = true;
+ return false;
+ }
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- if (ContextCompat.checkSelfPermission(activity,
- Manifest.permission.WRITE_EXTERNAL_STORAGE)
- != PackageManager.PERMISSION_GRANTED) {
-
- // Permission is not granted
- // No explanation needed; request the permission
- requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
- PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
- } else {
- // Permission has already been granted
- download();
- }
- } else {
- download();
- }
+ private void requestPermissionAndDownload() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
+ if (ContextCompat.checkSelfPermission(activity,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ != PackageManager.PERMISSION_GRANTED) {
- return true;
- case R.id.action_share_view_reddit_gallery_image_or_gif_fragment:
- if (media.mediaType == Post.Gallery.TYPE_GIF) {
- shareGif();
- } else {
- shareImage();
- }
- return true;
- case R.id.action_set_wallpaper_view_reddit_gallery_image_or_gif_fragment:
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment();
- Bundle bundle = new Bundle();
- bundle.putInt(SetAsWallpaperBottomSheetFragment.EXTRA_VIEW_PAGER_POSITION, activity.getCurrentPagePosition());
- setAsWallpaperBottomSheetFragment.setArguments(bundle);
- setAsWallpaperBottomSheetFragment.show(activity.getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag());
- } else {
- ((SetAsWallpaperCallback) activity).setToBoth(activity.getCurrentPagePosition());
- }
- return true;
+ // Permission is not granted
+ // No explanation needed; request the permission
+ requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
+ PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
+ } else {
+ // Permission has already been granted
+ download();
+ }
+ } else {
+ download();
}
-
- return false;
}
private void download() {
@@ -366,6 +408,20 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
}).submit();
}
+ private void setWallpaper() {
+ if (media.mediaType != Post.Gallery.TYPE_GIF) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment();
+ Bundle bundle = new Bundle();
+ bundle.putInt(SetAsWallpaperBottomSheetFragment.EXTRA_VIEW_PAGER_POSITION, activity.getCurrentPagePosition());
+ setAsWallpaperBottomSheetFragment.setArguments(bundle);
+ setAsWallpaperBottomSheetFragment.show(activity.getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag());
+ } else {
+ ((SetAsWallpaperCallback) activity).setToBoth(activity.getCurrentPagePosition());
+ }
+ }
+ }
+
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {
@@ -385,8 +441,21 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
}
@Override
- public void onDestroy() {
- super.onDestroy();
+ public void onResume() {
+ super.onResume();
+ SubsamplingScaleImageView ssiv = imageView.getSSIV();
+ if (ssiv == null || !ssiv.hasImage()) {
+ imageView.showImage(Uri.parse(media.url));
+ }
+ }
+
+ @Override
+ public void onDestroyView() {
+ super.onDestroyView();
BigImageViewer.imageLoader().cancelAll();
+ SubsamplingScaleImageView subsamplingScaleImageView = imageView.getSSIV();
+ if (subsamplingScaleImageView != null) {
+ subsamplingScaleImageView.recycle();
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java
index a1258ce2..de1e5566 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java
@@ -1,7 +1,6 @@
package ml.docilealligator.infinityforreddit.fragments;
import android.Manifest;
-import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -18,7 +17,9 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
+import android.widget.ImageView;
import android.widget.LinearLayout;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -39,6 +40,7 @@ import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
+import com.google.android.material.bottomappbar.BottomAppBar;
import javax.inject.Inject;
import javax.inject.Named;
@@ -46,8 +48,9 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Infinity;
-import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity;
+import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.services.DownloadMediaService;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@@ -57,12 +60,20 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
private static final String IS_MUTE_STATE = "IMS";
private static final String POSITION_STATE = "PS";
+ public static final String EXTRA_INDEX = "EI";
+ public static final String EXTRA_MEDIA_COUNT = "EMC";
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
@BindView(R.id.player_view_view_reddit_gallery_video_fragment)
PlayerView videoPlayerView;
@BindView(R.id.mute_exo_playback_control_view)
ImageButton muteButton;
- private Activity activity;
+ @BindView(R.id.bottom_navigation_exo_playback_control_view)
+ BottomAppBar bottomAppBar;
+ @BindView(R.id.title_text_view_exo_playback_control_view)
+ TextView titleTextView;
+ @BindView(R.id.download_image_view_exo_playback_control_view)
+ ImageView downloadImageView;
+ private ViewRedditGalleryActivity activity;
private Post.Gallery galleryVideo;
private String subredditName;
private SimpleExoPlayer player;
@@ -139,6 +150,19 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(galleryVideo.url)));
preparePlayer(savedInstanceState);
+ if (activity.isUseBottomAppBar()) {
+ bottomAppBar.setVisibility(View.VISIBLE);
+ titleTextView.setText(getString(R.string.view_reddit_gallery_activity_video_label,
+ getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
+ downloadImageView.setOnClickListener(view -> {
+ if (isDownloading) {
+ return;
+ }
+ isDownloading = true;
+ requestPermissionAndDownload();
+ });
+ }
+
return rootView;
}
@@ -152,25 +176,29 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.action_download_view_reddit_gallery_video_fragment) {
isDownloading = true;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- if (ContextCompat.checkSelfPermission(activity,
- Manifest.permission.WRITE_EXTERNAL_STORAGE)
- != PackageManager.PERMISSION_GRANTED) {
-
- // Permission is not granted
- // No explanation needed; request the permission
- requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
- PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
- } else {
- // Permission has already been granted
- download();
- }
+ requestPermissionAndDownload();
+ return true;
+ }
+ return false;
+ }
+
+ private void requestPermissionAndDownload() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
+ if (ContextCompat.checkSelfPermission(activity,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ != PackageManager.PERMISSION_GRANTED) {
+
+ // Permission is not granted
+ // No explanation needed; request the permission
+ requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
+ PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
} else {
+ // Permission has already been granted
download();
}
- return true;
+ } else {
+ download();
}
- return false;
}
@Override
@@ -286,6 +314,6 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
- activity = (Activity) context;
+ activity = (ViewRedditGalleryActivity) context;
}
} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
index 53b5aa39..881fb4d8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
@@ -119,7 +119,7 @@ public class ParsePost {
});
}
- private static Post parseBasicData(JSONObject data) throws JSONException {
+ public static Post parseBasicData(JSONObject data) throws JSONException {
String id = data.getString(JSONUtils.ID_KEY);
String fullName = data.getString(JSONUtils.NAME_KEY);
String subredditName = data.getString(JSONUtils.SUBREDDIT_KEY);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java
index 9c8490ef..57a6b5e3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java
@@ -48,6 +48,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
private SharedPreferences postFeedScrolledPositionSharedPreferences;
private String subredditOrUserName;
private String query;
+ private String trendingSource;
private int postType;
private SortType sortType;
private PostFilter postFilter;
@@ -151,8 +152,8 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
PostDataSource(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String subredditOrUserName, String query, int postType, SortType sortType, PostFilter postFilter,
- List<ReadPost> readPostList) {
+ String subredditOrUserName, String query, String trendingSource, int postType,
+ SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
this.executor = executor;
this.handler = handler;
this.retrofit = retrofit;
@@ -162,6 +163,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
this.subredditOrUserName = subredditOrUserName;
this.query = query;
+ this.trendingSource = trendingSource;
paginationNetworkStateLiveData = new MutableLiveData<>();
initialLoadStateLiveData = new MutableLiveData<>();
hasPostLiveData = new MutableLiveData<>();
@@ -639,16 +641,17 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
if (subredditOrUserName == null) {
if (accessToken == null) {
if (sortType.getTime() != null) {
- getPost = api.searchPosts(query, lastItem, sortType.getType().value, sortType.getTime().value);
+ getPost = api.searchPosts(query, lastItem, sortType.getType().value, sortType.getTime().value,
+ trendingSource);
} else {
- getPost = api.searchPosts(query, lastItem, sortType.getType().value);
+ getPost = api.searchPosts(query, lastItem, sortType.getType().value, trendingSource);
}
} else {
if(sortType.getTime() != null) {
getPost = api.searchPostsOauth(query, lastItem, sortType.getType().value,
- sortType.getTime().value, APIUtils.getOAuthHeader(accessToken));
+ sortType.getTime().value, trendingSource, APIUtils.getOAuthHeader(accessToken));
} else {
- getPost = api.searchPostsOauth(query, lastItem, sortType.getType().value,
+ getPost = api.searchPostsOauth(query, lastItem, sortType.getType().value, trendingSource,
APIUtils.getOAuthHeader(accessToken));
}
}
@@ -732,16 +735,18 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
if (subredditOrUserName == null) {
if (accessToken == null) {
if (sortType.getTime() != null) {
- getPost = api.searchPosts(query, after, sortType.getType().value, sortType.getTime().value);
+ getPost = api.searchPosts(query, after, sortType.getType().value, sortType.getTime().value,
+ trendingSource);
} else {
- getPost = api.searchPosts(query, after, sortType.getType().value);
+ getPost = api.searchPosts(query, after, sortType.getType().value, trendingSource);
}
} else {
if (sortType.getTime() != null) {
getPost = api.searchPostsOauth(query, after, sortType.getType().value,
- sortType.getTime().value, APIUtils.getOAuthHeader(accessToken));
+ sortType.getTime().value, trendingSource, APIUtils.getOAuthHeader(accessToken));
} else {
- getPost = api.searchPostsOauth(query, after, sortType.getType().value, APIUtils.getOAuthHeader(accessToken));
+ getPost = api.searchPostsOauth(query, after, sortType.getType().value, trendingSource,
+ APIUtils.getOAuthHeader(accessToken));
}
}
} else {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java
index ff4088b7..dd8312b7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java
@@ -26,6 +26,7 @@ class PostDataSourceFactory extends DataSource.Factory {
private SharedPreferences postFeedScrolledPositionSharedPreferences;
private String name;
private String query;
+ private String trendingSource;
private int postType;
private SortType sortType;
private PostFilter postFilter;
@@ -94,8 +95,8 @@ class PostDataSourceFactory extends DataSource.Factory {
PostDataSourceFactory(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String name, String query, int postType, SortType sortType, PostFilter postFilter,
- List<ReadPost> readPostList) {
+ String name, String query, String trendingSource, int postType, SortType sortType,
+ PostFilter postFilter, List<ReadPost> readPostList) {
this.executor = executor;
this.handler = handler;
this.retrofit = retrofit;
@@ -105,6 +106,7 @@ class PostDataSourceFactory extends DataSource.Factory {
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
this.name = name;
this.query = query;
+ this.trendingSource = trendingSource;
postDataSourceLiveData = new MutableLiveData<>();
this.postType = postType;
this.sortType = sortType;
@@ -121,7 +123,7 @@ class PostDataSourceFactory extends DataSource.Factory {
postFilter, readPostList);
} else if (postType == PostDataSource.TYPE_SEARCH) {
postDataSource = new PostDataSource(executor, handler, retrofit, accessToken, accountName,
- sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query,
+ sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, trendingSource,
postType, sortType, postFilter, readPostList);
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
Log.i("asdasfd", "s5 " + (postFilter == null));
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java
index 3649f430..ea56f54e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java
@@ -137,9 +137,10 @@ public class PostViewModel extends ViewModel {
public PostViewModel(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName,
- String query, int postType, SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
+ String query, String trendingSource, int postType, SortType sortType,
+ PostFilter postFilter, List<ReadPost> readPostList) {
postDataSourceFactory = new PostDataSourceFactory(executor, handler, retrofit, accessToken, accountName,
- sharedPreferences, cache, subredditName, query, postType, sortType, postFilter,
+ sharedPreferences, cache, subredditName, query, trendingSource, postType, sortType, postFilter,
readPostList);
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
@@ -211,6 +212,7 @@ public class PostViewModel extends ViewModel {
private SharedPreferences postFeedScrolledPositionSharedPreferences;
private String name;
private String query;
+ private String trendingSource;
private int postType;
private SortType sortType;
private PostFilter postFilter;
@@ -272,8 +274,8 @@ public class PostViewModel extends ViewModel {
public Factory(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String name, String query, int postType, SortType sortType, PostFilter postFilter,
- List<ReadPost> readPostList) {
+ String name, String query, String trendingSource, int postType, SortType sortType,
+ PostFilter postFilter, List<ReadPost> readPostList) {
this.executor = executor;
this.handler = handler;
this.retrofit = retrofit;
@@ -283,6 +285,7 @@ public class PostViewModel extends ViewModel {
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
this.name = name;
this.query = query;
+ this.trendingSource = trendingSource;
this.postType = postType;
this.sortType = sortType;
this.postFilter = postFilter;
@@ -310,7 +313,7 @@ public class PostViewModel extends ViewModel {
postFeedScrolledPositionSharedPreferences, postType, sortType, postFilter, readPostList);
} else if (postType == PostDataSource.TYPE_SEARCH) {
return (T) new PostViewModel(executor, handler, retrofit, accessToken, accountName, sharedPreferences,
- postFeedScrolledPositionSharedPreferences, name, query, postType, sortType,
+ postFeedScrolledPositionSharedPreferences, name, query, trendingSource, postType, sortType,
postFilter, readPostList);
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
return (T) new PostViewModel(executor, handler, retrofit, accessToken, accountName, sharedPreferences,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/SubmitPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/SubmitPost.java
index b7dd5f59..bf6fdbda 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/SubmitPost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/SubmitPost.java
@@ -13,7 +13,6 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
-import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Executor;
@@ -31,22 +30,24 @@ import retrofit2.Retrofit;
public class SubmitPost {
public static void submitTextOrLinkPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
- Locale locale, String subredditName, String title, String content,
- Flair flair, boolean isSpoiler, boolean isNSFW, String kind,
+ String subredditName, String title, String content,
+ Flair flair, boolean isSpoiler, boolean isNSFW,
+ boolean receivePostReplyNotifications, String kind,
SubmitPostListener submitPostListener) {
submitPost(executor, handler, oauthRetrofit, accessToken, subredditName, title, content,
- flair, isSpoiler, isNSFW, kind, null, submitPostListener);
+ flair, isSpoiler, isNSFW, receivePostReplyNotifications, kind, null, submitPostListener);
}
public static void submitImagePost(Executor executor, Handler handler, Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit,
String accessToken, String subredditName, String title, Bitmap image,
- Flair flair, boolean isSpoiler, boolean isNSFW, SubmitPostListener submitPostListener) {
+ Flair flair, boolean isSpoiler, boolean isNSFW,
+ boolean receivePostReplyNotifications, SubmitPostListener submitPostListener) {
try {
String imageUrlOrError = UploadImageUtils.uploadImage(oauthRetrofit, uploadMediaRetrofit, accessToken, image);
if (imageUrlOrError != null && !imageUrlOrError.startsWith("Error: ")) {
submitPost(executor, handler, oauthRetrofit, accessToken,
subredditName, title, imageUrlOrError, flair, isSpoiler, isNSFW,
- APIUtils.KIND_IMAGE, null, submitPostListener);
+ receivePostReplyNotifications, APIUtils.KIND_IMAGE, null, submitPostListener);
} else {
submitPostListener.submitFailed(imageUrlOrError);
}
@@ -60,7 +61,7 @@ public class SubmitPost {
Retrofit uploadVideoRetrofit, String accessToken,
String subredditName, String title, File buffer, String mimeType,
Bitmap posterBitmap, Flair flair, boolean isSpoiler, boolean isNSFW,
- SubmitPostListener submitPostListener) {
+ boolean receivePostReplyNotifications, SubmitPostListener submitPostListener) {
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
String fileType = mimeType.substring(mimeType.indexOf("/") + 1);
@@ -97,11 +98,13 @@ public class SubmitPost {
if (fileType.equals("gif")) {
submitPost(executor, handler, oauthRetrofit, accessToken,
subredditName, title, url, flair, isSpoiler, isNSFW,
- APIUtils.KIND_VIDEOGIF, imageUrlOrError, submitPostListener);
+ receivePostReplyNotifications, APIUtils.KIND_VIDEOGIF, imageUrlOrError,
+ submitPostListener);
} else {
submitPost(executor, handler, oauthRetrofit, accessToken,
subredditName, title, url, flair, isSpoiler, isNSFW,
- APIUtils.KIND_VIDEO, imageUrlOrError, submitPostListener);
+ receivePostReplyNotifications, APIUtils.KIND_VIDEO, imageUrlOrError,
+ submitPostListener);
}
} else {
submitPostListener.submitFailed(imageUrlOrError);
@@ -119,16 +122,18 @@ public class SubmitPost {
}
public static void submitCrosspost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
- String subredditName, String title, String crosspostFullname,
- Flair flair, boolean isSpoiler, boolean isNSFW, String kind,
- SubmitPostListener submitPostListener) {
+ String subredditName, String title, String crosspostFullname,
+ Flair flair, boolean isSpoiler, boolean isNSFW,
+ boolean receivePostReplyNotifications, String kind,
+ SubmitPostListener submitPostListener) {
submitPost(executor, handler, oauthRetrofit, accessToken, subredditName, title, crosspostFullname,
- flair, isSpoiler, isNSFW, kind, null, submitPostListener);
+ flair, isSpoiler, isNSFW, receivePostReplyNotifications, kind, null, submitPostListener);
}
private static void submitPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
String subredditName, String title, String content,
- Flair flair, boolean isSpoiler, boolean isNSFW, String kind,
+ Flair flair, boolean isSpoiler, boolean isNSFW,
+ boolean receivePostReplyNotifications, String kind,
@Nullable String posterUrl, SubmitPostListener submitPostListener) {
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
@@ -165,6 +170,7 @@ public class SubmitPost {
}
params.put(APIUtils.SPOILER_KEY, Boolean.toString(isSpoiler));
params.put(APIUtils.NSFW_KEY, Boolean.toString(isNSFW));
+ params.put(APIUtils.SEND_REPLIES_KEY, Boolean.toString(receivePostReplyNotifications));
Call<String> submitPostCall = api.submit(APIUtils.getOAuthHeader(accessToken), params);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java
index a326d81f..e5534ef9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java
@@ -263,7 +263,7 @@ public class DownloadMediaService extends Service {
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, destinationFileUriString);
contentValues.put(mediaType == EXTRA_MEDIA_TYPE_VIDEO ? MediaStore.Video.Media.IS_PENDING : MediaStore.Images.Media.IS_PENDING, 1);
- final Uri contentUri = mediaType == EXTRA_MEDIA_TYPE_VIDEO ? MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL) : MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
+ final Uri contentUri = mediaType == EXTRA_MEDIA_TYPE_VIDEO ? MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY) : MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
Uri uri = contentResolver.insert(contentUri, contentValues);
if (uri == null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
index f1b9633e..a398871e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
@@ -25,7 +25,6 @@ import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.provider.MediaStore;
-import android.util.Log;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
@@ -417,7 +416,7 @@ public class DownloadRedditVideoService extends Service {
Uri uri = null;
try {
- final Uri contentUri = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
+ final Uri contentUri = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
uri = contentResolver.insert(contentUri, contentValues);
if (uri == null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/MaterialYouService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/MaterialYouService.java
index 7fc764f8..66bd4e0b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/MaterialYouService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/MaterialYouService.java
@@ -1,9 +1,18 @@
package ml.docilealligator.infinityforreddit.services;
-import android.app.IntentService;
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.os.Build;
import android.os.Handler;
+import android.os.IBinder;
+
+import androidx.annotation.Nullable;
+import androidx.core.app.NotificationCompat;
+import androidx.core.app.NotificationManagerCompat;
import java.util.concurrent.Executor;
@@ -11,12 +20,14 @@ import javax.inject.Inject;
import javax.inject.Named;
import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.utils.MaterialYouUtils;
+import ml.docilealligator.infinityforreddit.utils.NotificationUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
-public class MaterialYouService extends IntentService {
+public class MaterialYouService extends Service {
@Inject
@Named("default")
@@ -38,16 +49,50 @@ public class MaterialYouService extends IntentService {
Executor executor;
public MaterialYouService() {
- super("MaterialYouService");
}
+ @Nullable
@Override
- protected void onHandleIntent(Intent intent) {
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
((Infinity) getApplication()).getAppComponent().inject(this);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ NotificationChannel serviceChannel = new NotificationChannel(
+ NotificationUtils.CHANNEL_ID_MATERIAL_YOU,
+ NotificationUtils.CHANNEL_MATERIAL_YOU,
+ NotificationManager.IMPORTANCE_LOW
+ );
+
+ NotificationManagerCompat manager = NotificationManagerCompat.from(this);
+ manager.createNotificationChannel(serviceChannel);
+ }
+ Notification notification = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_MATERIAL_YOU)
+ .setContentTitle(getString(R.string.material_you_notification_title))
+ .setContentText(getString(R.string.please_wait))
+ .setSmallIcon(R.drawable.ic_notification)
+ .setColor(customThemeWrapper.getColorPrimaryLightTheme())
+ .build();
+ startForeground(NotificationUtils.MATERIAL_YOU_NOTIFICATION_ID, notification);
+
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_MATERIAL_YOU, false)) {
MaterialYouUtils.changeTheme(this, executor, new Handler(), redditDataRoomDatabase,
customThemeWrapper, lightThemeSharedPreferences, darkThemeSharedPreferences,
- amoledThemeSharedPreferences);
+ amoledThemeSharedPreferences, () -> {
+ stopService();
+ });
+ } else {
+ stopService();
}
+
+ return START_NOT_STICKY;
+ }
+
+ private void stopService() {
+ stopForeground(true);
+ stopSelf();
}
} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java
index 12b4e1a5..e22bc541 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java
@@ -25,6 +25,9 @@ import androidx.core.app.NotificationManagerCompat;
import com.bumptech.glide.Glide;
import org.greenrobot.eventbus.EventBus;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
import java.io.File;
import java.io.FileOutputStream;
@@ -41,15 +44,19 @@ import javax.inject.Named;
import ml.docilealligator.infinityforreddit.Flair;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.events.SubmitCrosspostEvent;
+import ml.docilealligator.infinityforreddit.events.SubmitGalleryPostEvent;
import ml.docilealligator.infinityforreddit.events.SubmitImagePostEvent;
import ml.docilealligator.infinityforreddit.events.SubmitTextOrLinkPostEvent;
import ml.docilealligator.infinityforreddit.events.SubmitVideoOrGifPostEvent;
import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.post.SubmitPost;
import ml.docilealligator.infinityforreddit.utils.APIUtils;
+import ml.docilealligator.infinityforreddit.utils.JSONUtils;
import ml.docilealligator.infinityforreddit.utils.NotificationUtils;
+import retrofit2.Response;
import retrofit2.Retrofit;
public class SubmitPostService extends Service {
@@ -57,15 +64,19 @@ public class SubmitPostService extends Service {
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
public static final String EXTRA_TITLE = "ET";
public static final String EXTRA_CONTENT = "EC";
+ public static final String EXTRA_REDDIT_GALLERY_PAYLOAD = "ERGP";
public static final String EXTRA_KIND = "EK";
public static final String EXTRA_FLAIR = "EF";
public static final String EXTRA_IS_SPOILER = "EIS";
public static final String EXTRA_IS_NSFW = "EIN";
+ public static final String EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS = "ERPRN";
public static final String EXTRA_POST_TYPE = "EPT";
public static final int EXTRA_POST_TEXT_OR_LINK = 0;
public static final int EXTRA_POST_TYPE_IMAGE = 1;
public static final int EXTRA_POST_TYPE_VIDEO = 2;
- public static final int EXTRA_POST_TYPE_CROSSPOST = 3;
+ public static final int EXTRA_POST_TYPE_GALLERY = 3;
+ public static final int EXTRA_POST_TYPE_CROSSPOST = 4;
+
private static final String EXTRA_MEDIA_URI = "EU";
@Inject
@Named("oauth")
@@ -107,22 +118,28 @@ public class SubmitPostService extends Service {
Flair flair = bundle.getParcelable(EXTRA_FLAIR);
boolean isSpoiler = bundle.getBoolean(EXTRA_IS_SPOILER, false);
boolean isNSFW = bundle.getBoolean(EXTRA_IS_NSFW, false);
+ boolean receivePostReplyNotifications = bundle.getBoolean(EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, true);
int postType = bundle.getInt(EXTRA_POST_TYPE, EXTRA_POST_TEXT_OR_LINK);
if (postType == EXTRA_POST_TEXT_OR_LINK) {
String content = bundle.getString(EXTRA_CONTENT);
String kind = bundle.getString(EXTRA_KIND);
- submitTextOrLinkPost(accessToken, subredditName, title, content, flair, isSpoiler, isNSFW, kind);
+ submitTextOrLinkPost(accessToken, subredditName, title, content, flair, isSpoiler, isNSFW,
+ receivePostReplyNotifications, kind);
} else if (postType == EXTRA_POST_TYPE_CROSSPOST) {
String content = bundle.getString(EXTRA_CONTENT);
submitCrosspost(mExecutor, handler, accessToken, subredditName, title, content,
- flair, isSpoiler, isNSFW);
+ flair, isSpoiler, isNSFW, receivePostReplyNotifications);
} else if (postType == EXTRA_POST_TYPE_IMAGE) {
Uri mediaUri = Uri.parse(bundle.getString(EXTRA_MEDIA_URI));
- submitImagePost(accessToken, mediaUri, subredditName, title, flair, isSpoiler, isNSFW);
- } else {
+ submitImagePost(accessToken, mediaUri, subredditName, title, flair, isSpoiler, isNSFW,
+ receivePostReplyNotifications);
+ } else if (postType == EXTRA_POST_TYPE_VIDEO) {
Uri mediaUri = Uri.parse(bundle.getString(EXTRA_MEDIA_URI));
- submitVideoPost(accessToken, mediaUri, subredditName, title, flair, isSpoiler, isNSFW);
+ submitVideoPost(accessToken, mediaUri, subredditName, title, flair, isSpoiler, isNSFW,
+ receivePostReplyNotifications);
+ } else {
+ submitGalleryPost(accessToken, bundle.getString(EXTRA_REDDIT_GALLERY_PAYLOAD));
}
}
}
@@ -169,9 +186,11 @@ public class SubmitPostService extends Service {
} else if (postType == EXTRA_POST_TYPE_IMAGE) {
bundle.putString(EXTRA_MEDIA_URI, intent.getData().toString());
startForeground(NotificationUtils.SUBMIT_POST_SERVICE_NOTIFICATION_ID + randomNotificationIdOffset, createNotification(R.string.posting_image));
- } else {
+ } else if (postType == EXTRA_POST_TYPE_VIDEO) {
bundle.putString(EXTRA_MEDIA_URI, intent.getData().toString());
startForeground(NotificationUtils.SUBMIT_POST_SERVICE_NOTIFICATION_ID + randomNotificationIdOffset, createNotification(R.string.posting_video));
+ } else {
+ startForeground(NotificationUtils.SUBMIT_POST_SERVICE_NOTIFICATION_ID + randomNotificationIdOffset, createNotification(R.string.posting_gallery));
}
Message msg = serviceHandler.obtainMessage();
@@ -190,10 +209,12 @@ public class SubmitPostService extends Service {
.build();
}
- private void submitTextOrLinkPost(String accessToken, String subredditName, String title, String content, Flair flair, boolean isSpoiler, boolean isNSFW, String kind) {
+ private void submitTextOrLinkPost(String accessToken, String subredditName, String title, String content,
+ Flair flair, boolean isSpoiler, boolean isNSFW, boolean receivePostReplyNotifications,
+ String kind) {
SubmitPost.submitTextOrLinkPost(mExecutor, handler, mOauthRetrofit, accessToken,
- getResources().getConfiguration().locale, subredditName, title, content, flair, isSpoiler,
- isNSFW, kind, new SubmitPost.SubmitPostListener() {
+ subredditName, title, content, flair, isSpoiler,
+ isNSFW, receivePostReplyNotifications, kind, new SubmitPost.SubmitPostListener() {
@Override
public void submitSuccessful(Post post) {
handler.post(() -> EventBus.getDefault().post(new SubmitTextOrLinkPostEvent(true, post, null)));
@@ -211,9 +232,11 @@ public class SubmitPostService extends Service {
}
private void submitCrosspost(Executor executor, Handler handler, String accessToken, String subredditName,
- String title, String content, Flair flair, boolean isSpoiler, boolean isNSFW) {
+ String title, String content, Flair flair, boolean isSpoiler, boolean isNSFW,
+ boolean receivePostReplyNotifications) {
SubmitPost.submitCrosspost(executor, handler, mOauthRetrofit, accessToken, subredditName, title,
- content, flair, isSpoiler, isNSFW, APIUtils.KIND_CROSSPOST, new SubmitPost.SubmitPostListener() {
+ content, flair, isSpoiler, isNSFW, receivePostReplyNotifications, APIUtils.KIND_CROSSPOST,
+ new SubmitPost.SubmitPostListener() {
@Override
public void submitSuccessful(Post post) {
handler.post(() -> EventBus.getDefault().post(new SubmitCrosspostEvent(true, post, null)));
@@ -230,11 +253,12 @@ public class SubmitPostService extends Service {
});
}
- private void submitImagePost(String accessToken, Uri mediaUri, String subredditName, String title, Flair flair, boolean isSpoiler, boolean isNSFW) {
+ private void submitImagePost(String accessToken, Uri mediaUri, String subredditName, String title,
+ Flair flair, boolean isSpoiler, boolean isNSFW, boolean receivePostReplyNotifications) {
try {
Bitmap resource = Glide.with(this).asBitmap().load(mediaUri).submit().get();
SubmitPost.submitImagePost(mExecutor, handler, mOauthRetrofit, mUploadMediaRetrofit,
- accessToken, subredditName, title, resource, flair, isSpoiler, isNSFW,
+ accessToken, subredditName, title, resource, flair, isSpoiler, isNSFW, receivePostReplyNotifications,
new SubmitPost.SubmitPostListener() {
@Override
public void submitSuccessful(Post post) {
@@ -261,7 +285,7 @@ public class SubmitPostService extends Service {
}
private void submitVideoPost(String accessToken, Uri mediaUri, String subredditName, String title,
- Flair flair, boolean isSpoiler, boolean isNSFW) {
+ Flair flair, boolean isSpoiler, boolean isNSFW, boolean receivePostReplyNotifications) {
try {
InputStream in = getContentResolver().openInputStream(mediaUri);
String type = getContentResolver().getType(mediaUri);
@@ -279,7 +303,8 @@ public class SubmitPostService extends Service {
if (type != null) {
SubmitPost.submitVideoPost(mExecutor, handler, mOauthRetrofit, mUploadMediaRetrofit,
mUploadVideoRetrofit, accessToken, subredditName, title, new File(cacheFilePath),
- type, resource, flair, isSpoiler, isNSFW, new SubmitPost.SubmitPostListener() {
+ type, resource, flair, isSpoiler, isNSFW, receivePostReplyNotifications,
+ new SubmitPost.SubmitPostListener() {
@Override
public void submitSuccessful(Post post) {
handler.post(() -> {
@@ -315,6 +340,42 @@ public class SubmitPostService extends Service {
}
}
+ private void submitGalleryPost(String accessToken, String payload) {
+ try {
+ Response<String> response = mOauthRetrofit.create(RedditAPI.class).submitGalleryPost(APIUtils.getOAuthHeader(accessToken), payload).execute();
+ if (response.isSuccessful()) {
+ JSONObject responseObject = new JSONObject(response.body()).getJSONObject(JSONUtils.JSON_KEY);
+ if (responseObject.getJSONArray(JSONUtils.ERRORS_KEY).length() != 0) {
+ JSONArray error = responseObject.getJSONArray(JSONUtils.ERRORS_KEY)
+ .getJSONArray(responseObject.getJSONArray(JSONUtils.ERRORS_KEY).length() - 1);
+ if (error.length() != 0) {
+ String errorMessage;
+ if (error.length() >= 2) {
+ errorMessage = error.getString(1);
+ } else {
+ errorMessage = error.getString(0);
+ }
+ handler.post(() -> EventBus.getDefault().post(new SubmitGalleryPostEvent(false, null, errorMessage)));
+ } else {
+ handler.post(() -> EventBus.getDefault().post(new SubmitGalleryPostEvent(false, null, null)));
+ }
+ } else {
+ String postUrl = responseObject.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.URL_KEY);
+ handler.post(() -> {
+ EventBus.getDefault().post(new SubmitGalleryPostEvent(true, postUrl, null));
+ });
+ }
+ } else {
+ handler.post(() -> EventBus.getDefault().post(new SubmitGalleryPostEvent(false, null, response.message())));
+ }
+ } catch (IOException | JSONException e) {
+ e.printStackTrace();
+ handler.post(() -> EventBus.getDefault().post(new SubmitGalleryPostEvent(false, null, e.getMessage())));
+ } finally {
+ stopService();
+ }
+ }
+
private static void copyFileToCache(InputStream fileInputStream, String destinationFilePath) throws IOException {
OutputStream out = new FileOutputStream(destinationFilePath);
byte[] buf = new byte[2048];
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AcknowledgementFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AcknowledgementFragment.java
index 59adcf9d..2f2aa91e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AcknowledgementFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AcknowledgementFragment.java
@@ -11,7 +11,6 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
@@ -20,6 +19,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.adapters.AcknowledgementRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
/**
* A simple {@link Fragment} subclass.
@@ -127,7 +127,7 @@ public class AcknowledgementFragment extends Fragment {
Uri.parse("https://github.com/saket/Better-Link-Movement-Method")));
AcknowledgementRecyclerViewAdapter adapter = new AcknowledgementRecyclerViewAdapter(activity, acknowledgements);
- recyclerView.setLayoutManager(new LinearLayoutManager(activity));
+ recyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(activity));
recyclerView.setAdapter(adapter);
return rootView;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java
index 350addf8..6cb67a5f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CrashReportsFragment.java
@@ -17,7 +17,6 @@ import androidx.annotation.NonNull;
import androidx.appcompat.view.menu.MenuItemImpl;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.fragment.app.Fragment;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.crazylegend.crashyreporter.CrashyReporter;
@@ -49,7 +48,6 @@ public class CrashReportsFragment extends Fragment {
setHasOptionsMenu(true);
- recyclerView.setLayoutManager(new LinearLayoutManager(activity));
recyclerView.setAdapter(new CrashReportsRecyclerViewAdapter(CrashyReporter.INSTANCE.getLogsAsStrings()));
return recyclerView;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostDetailsPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostDetailsPreferenceFragment.java
new file mode 100644
index 00000000..2e0db830
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostDetailsPreferenceFragment.java
@@ -0,0 +1,18 @@
+package ml.docilealligator.infinityforreddit.settings;
+
+import android.os.Bundle;
+
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.PreferenceManager;
+
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+
+public class PostDetailsPreferenceFragment extends PreferenceFragmentCompat {
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ PreferenceManager preferenceManager = getPreferenceManager();
+ preferenceManager.setSharedPreferencesName(SharedPreferencesUtils.POST_DETAILS_SHARED_PREFERENCES_FILE);
+ setPreferencesFromResource(R.xml.post_details_preferences, rootKey);
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java
index f3a4f30c..5b508a96 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostPreferenceFragment.java
@@ -11,6 +11,7 @@ import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.events.ChangeCompactLayoutToolbarHiddenByDefaultEvent;
+import ml.docilealligator.infinityforreddit.events.ChangeDefaultLinkPostLayoutEvent;
import ml.docilealligator.infinityforreddit.events.ChangeDefaultPostLayoutEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHidePostFlairEvent;
import ml.docilealligator.infinityforreddit.events.ChangeHidePostTypeEvent;
@@ -31,6 +32,7 @@ public class PostPreferenceFragment extends PreferenceFragmentCompat {
setPreferencesFromResource(R.xml.post_preferences, rootKey);
ListPreference defaultPostLayoutList = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY);
+ ListPreference defaultLinkPostLayoutList = findPreference(SharedPreferencesUtils.DEFAULT_LINK_POST_LAYOUT_KEY);
SwitchPreference showDividerInCompactLayoutSwitch = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT);
SwitchPreference showThumbnailOnTheRightInCompactLayoutSwitch = findPreference(SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_LEFT_IN_COMPACT_LAYOUT);
SwitchPreference showAbsoluteNumberOfVotesSwitch = findPreference(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES);
@@ -50,6 +52,13 @@ public class PostPreferenceFragment extends PreferenceFragmentCompat {
});
}
+ if (defaultLinkPostLayoutList != null) {
+ defaultLinkPostLayoutList.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new ChangeDefaultLinkPostLayoutEvent(Integer.parseInt((String) newValue)));
+ return true;
+ });
+ }
+
if (showDividerInCompactLayoutSwitch != null) {
showDividerInCompactLayoutSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ShowDividerInCompactLayoutPreferenceEvent((Boolean) newValue));
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java
index cb6917c8..c4dd2b16 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/SecurityPreferenceFragment.java
@@ -1,5 +1,8 @@
package ml.docilealligator.infinityforreddit.settings;
+import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
+import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
+
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
@@ -18,14 +21,12 @@ import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
-import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.events.ChangeRequireAuthToAccountSectionEvent;
+import ml.docilealligator.infinityforreddit.events.ToggleSecureModeEvent;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
-import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
-import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
-
public class SecurityPreferenceFragment extends PreferenceFragmentCompat {
private AppCompatActivity activity;
@@ -40,6 +41,7 @@ public class SecurityPreferenceFragment extends PreferenceFragmentCompat {
((Infinity) activity.getApplication()).getAppComponent().inject(this);
SwitchPreference requireAuthToAccountSectionSwitch = findPreference(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER);
+ SwitchPreference secureModeSwitch = findPreference(SharedPreferencesUtils.SECURE_MODE);
if (requireAuthToAccountSectionSwitch != null) {
requireAuthToAccountSectionSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
@@ -47,6 +49,13 @@ public class SecurityPreferenceFragment extends PreferenceFragmentCompat {
return true;
});
}
+
+ if (secureModeSwitch != null) {
+ secureModeSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new ToggleSecureModeEvent((Boolean) newValue));
+ return true;
+ });
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java
index 9dafc175..0e0a8c7d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/ThemePreferenceFragment.java
@@ -1,5 +1,10 @@
package ml.docilealligator.infinityforreddit.settings;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
+
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -38,11 +43,6 @@ import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUt
import ml.docilealligator.infinityforreddit.utils.MaterialYouUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
-
/**
* A simple {@link Fragment} subclass.
*/
@@ -182,7 +182,7 @@ public class ThemePreferenceFragment extends PreferenceFragmentCompat {
MaterialYouUtils.changeTheme(activity, executor, new Handler(),
redditDataRoomDatabase, customThemeWrapper,
lightThemeSharedPreferences, darkThemeSharedPreferences,
- amoledThemeSharedPreferences);
+ amoledThemeSharedPreferences, null);
applyMaterialYouPreference.setVisible(true);
} else {
applyMaterialYouPreference.setVisible(false);
@@ -194,7 +194,7 @@ public class ThemePreferenceFragment extends PreferenceFragmentCompat {
MaterialYouUtils.changeTheme(activity, executor, new Handler(),
redditDataRoomDatabase, customThemeWrapper,
lightThemeSharedPreferences, darkThemeSharedPreferences,
- amoledThemeSharedPreferences);
+ amoledThemeSharedPreferences, null);
return true;
});
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/TranslationFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/TranslationFragment.java
index a0f9cd1e..62f5c50a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/TranslationFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/TranslationFragment.java
@@ -9,7 +9,6 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
-import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import javax.inject.Inject;
@@ -44,7 +43,6 @@ public class TranslationFragment extends Fragment {
ButterKnife.bind(this, rootView);
TranslationFragmentRecyclerViewAdapter adapter = new TranslationFragmentRecyclerViewAdapter(activity, customThemeWrapper);
- recyclerView.setLayoutManager(new LinearLayoutManager(activity));
recyclerView.setAdapter(adapter);
return rootView;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java
index f7941534..6a89dcd6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/VideoPreferenceFragment.java
@@ -22,6 +22,7 @@ import javax.inject.Named;
import ml.docilealligator.infinityforreddit.events.ChangeAutoplayNsfwVideosEvent;
import ml.docilealligator.infinityforreddit.events.ChangeMuteAutoplayingVideosEvent;
import ml.docilealligator.infinityforreddit.events.ChangeMuteNSFWVideoEvent;
+import ml.docilealligator.infinityforreddit.events.ChangeRememberMutingOptionInPostFeedEvent;
import ml.docilealligator.infinityforreddit.events.ChangeStartAutoplayVisibleAreaOffsetEvent;
import ml.docilealligator.infinityforreddit.events.ChangeVideoAutoplayEvent;
import ml.docilealligator.infinityforreddit.Infinity;
@@ -43,6 +44,7 @@ public class VideoPreferenceFragment extends PreferenceFragmentCompat {
ListPreference videoAutoplayListPreference = findPreference(SharedPreferencesUtils.VIDEO_AUTOPLAY);
SwitchPreference muteAutoplayingVideosSwitchPreference = findPreference(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS);
+ SwitchPreference rememberMutingOptionInPostFeedSwitchPreference = findPreference(SharedPreferencesUtils.REMEMBER_MUTING_OPTION_IN_POST_FEED);
SwitchPreference muteNSFWVideosSwitchPreference = findPreference(SharedPreferencesUtils.MUTE_NSFW_VIDEO);
SwitchPreference autoplayNsfwVideosSwitchPreference = findPreference(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS);
SeekBarPreference startAutoplayVisibleAreaOffsetPortrait = findPreference(SharedPreferencesUtils.START_AUTOPLAY_VISIBLE_AREA_OFFSET_PORTRAIT);
@@ -74,6 +76,13 @@ public class VideoPreferenceFragment extends PreferenceFragmentCompat {
});
}
+ if (rememberMutingOptionInPostFeedSwitchPreference != null) {
+ rememberMutingOptionInPostFeedSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new ChangeRememberMutingOptionInPostFeedEvent((Boolean) newValue));
+ return true;
+ });
+ }
+
int orientation = getResources().getConfiguration().orientation;
if (startAutoplayVisibleAreaOffsetPortrait != null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java
index 5ad14398..465a31eb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java
@@ -73,6 +73,7 @@ public class APIUtils {
public static final String SPOILER_KEY = "spoiler";
public static final String NSFW_KEY = "nsfw";
public static final String CROSSPOST_FULLNAME_KEY = "crosspost_fullname";
+ public static final String SEND_REPLIES_KEY = "sendreplies";
public static final String KIND_KEY = "kind";
public static final String KIND_SELF = "self";
public static final String KIND_LINK = "link";
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java
index 027d69dd..b76f198e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java
@@ -164,4 +164,11 @@ public class JSONUtils {
public static final String ESTIMATED_REMAINING_TIME_KEY = "estimated_remaining_time";
public static final String PAYLOAD_KEY = "payload";
public static final String AUTHOR_ICON_IMAGE = "author_icon_img";
+ public static final String ASSET_KEY = "asset";
+ public static final String ASSET_ID_KEY = "asset_id";
+ public static final String TRENDING_SEARCHES_KEY = "trending_searches";
+ public static final String QUERY_STRING_KEY = "query_string";
+ public static final String DISPLAY_STRING_KEY = "display_string";
+ public static final String RESULTS_KEY = "results";
+ public static final String CONTENT_MD_KEY = "content_md";
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java
index 37e92aa1..d470e1d0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java
@@ -9,6 +9,7 @@ import android.os.Build;
import android.os.Handler;
import androidx.annotation.ColorInt;
+import androidx.annotation.Nullable;
import org.greenrobot.eventbus.EventBus;
@@ -44,27 +45,28 @@ public class MaterialYouUtils {
CustomThemeWrapper customThemeWrapper,
SharedPreferences lightThemeSharedPreferences,
SharedPreferences darkThemeSharedPreferences,
- SharedPreferences amoledThemeSharedPreferences) {
+ SharedPreferences amoledThemeSharedPreferences,
+ @Nullable MaterialYouListener materialYouListener) {
executor.execute(() -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
WallpaperColors wallpaperColors = wallpaperManager.getWallpaperColors(WallpaperManager.FLAG_SYSTEM);
if (wallpaperColors != null) {
- CustomTheme lightTheme = CustomThemeWrapper.getIndigo(context);
- CustomTheme darkTheme = CustomThemeWrapper.getIndigoDark(context);
- CustomTheme amoledTheme = CustomThemeWrapper.getIndigoAmoled(context);
-
- int colorPrimaryInt = shiftColorTo255(wallpaperColors.getPrimaryColor().toArgb(), 0.4);
- int colorPrimaryDarkInt = shiftColorTo0(colorPrimaryInt, 0.3);
- int backgroundColor = shiftColorTo255(colorPrimaryInt, 0.6);
- int cardViewBackgroundColor = shiftColorTo255(colorPrimaryInt, 0.9);
+ int colorPrimaryInt = lightenColor(wallpaperColors.getPrimaryColor().toArgb(), 0.4);
+ int colorPrimaryDarkInt = darkenColor(colorPrimaryInt, 0.3);
+ int backgroundColor = lightenColor(colorPrimaryInt, 0.2);
+ int cardViewBackgroundColor = lightenColor(colorPrimaryInt, 0.6);
Color colorAccent = wallpaperColors.getSecondaryColor();
- int colorAccentInt = shiftColorTo255(colorAccent == null ? customThemeWrapper.getColorAccent() : colorAccent.toArgb(), 0.4);
+ int colorAccentInt = lightenColor(colorAccent == null ? customThemeWrapper.getColorAccent() : colorAccent.toArgb(), 0.4);
int colorPrimaryAppropriateTextColor = getAppropriateTextColor(colorPrimaryInt);
int backgroundColorAppropriateTextColor = getAppropriateTextColor(backgroundColor);
+ CustomTheme lightTheme = CustomThemeWrapper.getIndigo(context);
+ CustomTheme darkTheme = CustomThemeWrapper.getIndigoDark(context);
+ CustomTheme amoledTheme = CustomThemeWrapper.getIndigoAmoled(context);
+
lightTheme.colorPrimary = colorPrimaryInt;
lightTheme.colorPrimaryDark = colorPrimaryDarkInt;
lightTheme.colorAccent = colorAccentInt;
@@ -76,6 +78,7 @@ public class MaterialYouUtils {
lightTheme.bottomAppBarBackgroundColor = colorPrimaryInt;
lightTheme.navBarColor = colorPrimaryInt;
lightTheme.primaryTextColor = backgroundColorAppropriateTextColor;
+ lightTheme.secondaryTextColor = backgroundColorAppropriateTextColor == Color.BLACK ? Color.parseColor("#8A000000") : Color.parseColor("#B3FFFFFF");
lightTheme.bottomAppBarIconColor = colorPrimaryAppropriateTextColor;
lightTheme.primaryIconColor = backgroundColorAppropriateTextColor;
lightTheme.fabIconColor = colorPrimaryAppropriateTextColor;
@@ -88,7 +91,11 @@ public class MaterialYouUtils {
lightTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = colorPrimaryAppropriateTextColor;
lightTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = colorPrimaryAppropriateTextColor;
lightTheme.circularProgressBarBackground = colorPrimaryInt;
- lightTheme.isLightStatusBar = getAppropriateTextColor(colorPrimaryInt) == Color.toArgb(Color.BLACK);
+ lightTheme.dividerColor = backgroundColorAppropriateTextColor == Color.BLACK ? Color.parseColor("#E0E0E0") : Color.parseColor("69666C");
+ lightTheme.isLightStatusBar = colorPrimaryAppropriateTextColor == Color.BLACK;
+ lightTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface =
+ (lightTheme.isLightStatusBar && getAppropriateTextColor(cardViewBackgroundColor) == Color.WHITE)
+ || (!lightTheme.isLightStatusBar && getAppropriateTextColor(cardViewBackgroundColor) == Color.BLACK);
lightTheme.name = "Material You";
darkTheme.colorAccent = colorPrimaryInt;
@@ -111,24 +118,27 @@ public class MaterialYouUtils {
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(darkTheme, darkThemeSharedPreferences);
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(amoledTheme, amoledThemeSharedPreferences);
- handler.post(() -> EventBus.getDefault().post(new RecreateActivityEvent()));
+ handler.post(() -> {
+ if (materialYouListener != null) {
+ materialYouListener.applied();
+ }
+ EventBus.getDefault().post(new RecreateActivityEvent());
+ });
}
}
});
}
- private static int shiftColorTo255(int color, double ratio) {
- int offset = (int) (Math.min(Math.min(255 - Color.red(color), 255 - Color.green(color)), 255 - Color.blue(color)) * ratio);
- return Color.argb(Color.alpha(color), Color.red(color) + offset,
- Color.green(color) + offset,
- Color.blue(color) + offset);
+ private static int lightenColor(int color, double ratio) {
+ return Color.argb(Color.alpha(color), (int) (Color.red(color) + (255 - Color.red(color)) * ratio),
+ (int) (Color.green(color) + (255 - Color.green(color)) * ratio),
+ (int) (Color.blue(color) + (255 - Color.blue(color)) * ratio));
}
- private static int shiftColorTo0(int color, double ratio) {
- int offset = (int) (Math.min(Math.min(Color.red(color), Color.green(color)), Color.blue(color)) * ratio);
- return Color.argb(Color.alpha(color), Color.red(color) - offset,
- Color.green(color) - offset,
- Color.blue(color) - offset);
+ private static int darkenColor(int color, double ratio) {
+ return Color.argb(Color.alpha(color), (int) (Color.red(color) * (1 - ratio)),
+ (int) (Color.green(color) * (1 - ratio)),
+ (int) (Color.blue(color) * (1 - ratio)));
}
@@ -138,4 +148,8 @@ public class MaterialYouUtils {
double luminance = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
return luminance < 0.5 ? Color.BLACK : Color.WHITE;
}
+
+ public interface MaterialYouListener {
+ void applied();
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/NotificationUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/NotificationUtils.java
index 3c3255de..5552271f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/NotificationUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/NotificationUtils.java
@@ -22,11 +22,14 @@ public class NotificationUtils {
public static final String CHANNEL_DOWNLOAD_IMAGE = "Download Image";
public static final String CHANNEL_ID_DOWNLOAD_GIF = "download_gif";
public static final String CHANNEL_DOWNLOAD_GIF = "Download Gif";
+ public static final String CHANNEL_ID_MATERIAL_YOU = "material_you";
+ public static final String CHANNEL_MATERIAL_YOU = "Material You";
public static final int SUBMIT_POST_SERVICE_NOTIFICATION_ID = 10000;
public static final int DOWNLOAD_REDDIT_VIDEO_NOTIFICATION_ID = 20000;
public static final int DOWNLOAD_VIDEO_NOTIFICATION_ID = 30000;
public static final int DOWNLOAD_IMAGE_NOTIFICATION_ID = 40000;
public static final int DOWNLOAD_GIF_NOTIFICATION_ID = 50000;
+ public static final int MATERIAL_YOU_NOTIFICATION_ID = 60000;
private static final int SUMMARY_BASE_ID_UNREAD_MESSAGE = 0;
private static final int NOTIFICATION_BASE_ID_UNREAD_MESSAGE = 1;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
index 82343e4f..f3247d99 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
@@ -182,6 +182,11 @@ public class SharedPreferencesUtils {
public static final String SHOW_ONLY_ONE_COMMENT_LEVEL_INDICATOR = "show_only_one_comment_level_indicator";
public static final String ENABLE_MATERIAL_YOU = "enable_material_you";
public static final String APPLY_MATERIAL_YOU = "apply_material_you";
+ public static final String VIDEO_PLAYER_AUTOMATIC_LANDSCAPE_ORIENTATION = "video_player_automatic_landscape_orientation";
+ public static final String REMEMBER_MUTING_OPTION_IN_POST_FEED = "remember_muting_option_in_post_feed";
+ public static final String DEFAULT_LINK_POST_LAYOUT_KEY = "default_link_post_layout";
+ public static final String USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER = "use_bottom_toolbar_in_media_viewer";
+ public static final String SECURE_MODE = "secure_mode";
public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences";
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
@@ -308,6 +313,7 @@ public class SharedPreferencesUtils {
public static final String NAVIGATION_DRAWER_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.navigation_drawer";
public static final String COLLAPSE_ACCOUNT_SECTION = "collapse_account_section";
+ public static final String COLLAPSE_REDDIT_SECTION = "collapse_reddit_section";
public static final String COLLAPSE_POST_SECTION = "collapse_post_section";
public static final String COLLAPSE_PREFERENCES_SECTION = "collapse_preferences_section";
public static final String COLLAPSE_FAVORITE_SUBREDDITS_SECTION = "collapse_favorite_subreddits_section";
@@ -315,6 +321,10 @@ public class SharedPreferencesUtils {
public static final String HIDE_FAVORITE_SUBREDDITS_SECTION = "hide_favorite_subreddits_sections";
public static final String HIDE_SUBSCRIBED_SUBREDDITS_SECTIONS = "hide_subscribed_subreddits_sections";
+ public static final String POST_DETAILS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.post_details";
+ public static final String SEPARATE_POST_AND_COMMENTS_IN_PORTRAIT_MODE = "separate_post_and_comments_in_portrait_mode";
+ public static final String SEPARATE_POST_AND_COMMENTS_IN_LANDSCAPE_MODE = "separate_post_and_comments_in_landscape_mode";
+
//Legacy Settings
public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title";
public static final String MAIN_PAGE_TAB_2_TITLE_LEGACY = "main_page_tab_2_title";
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/UploadImageUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/UploadImageUtils.java
index 4eff065d..c7b5f728 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/UploadImageUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/UploadImageUtils.java
@@ -28,7 +28,13 @@ import retrofit2.Retrofit;
public class UploadImageUtils {
@Nullable
public static String uploadImage(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit,
- String accessToken, Bitmap image) throws IOException, JSONException, XmlPullParserException {
+ String accessToken, Bitmap image) throws IOException, JSONException, XmlPullParserException {
+ return uploadImage(oauthRetrofit, uploadMediaRetrofit, accessToken, image, false);
+ }
+
+ @Nullable
+ public static String uploadImage(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit,
+ String accessToken, Bitmap image, boolean returnResponseForGallerySubmission) throws IOException, JSONException, XmlPullParserException {
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
Map<String, String> uploadImageParams = new HashMap<>();
@@ -51,6 +57,9 @@ public class UploadImageUtils {
Call<String> uploadMediaToAWS = uploadMediaToAWSApi.uploadMediaToAWS(nameValuePairsMap, fileToUpload);
Response<String> uploadMediaToAWSResponse = uploadMediaToAWS.execute();
if (uploadMediaToAWSResponse.isSuccessful()) {
+ if (returnResponseForGallerySubmission) {
+ return uploadImageResponse.body();
+ }
return parseXMLResponseFromAWS(uploadMediaToAWSResponse.body());
} else {
return "Error: " + uploadMediaToAWSResponse.code();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
index e01f41cd..ad2b7405 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
@@ -220,15 +220,17 @@ public class Utils {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Network nw = connMgr.getActiveNetwork();
if (nw == null) return NETWORK_TYPE_OTHER;
- NetworkCapabilities actNw = connMgr.getNetworkCapabilities(nw);
- if (actNw != null) {
- if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
- return NETWORK_TYPE_WIFI;
- }
- if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
- return NETWORK_TYPE_CELLULAR;
+ try {
+ NetworkCapabilities actNw = connMgr.getNetworkCapabilities(nw);
+ if (actNw != null) {
+ if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
+ return NETWORK_TYPE_WIFI;
+ }
+ if (actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
+ return NETWORK_TYPE_CELLULAR;
+ }
}
- }
+ } catch (SecurityException ignore) {}
return NETWORK_TYPE_OTHER;
} else {
boolean isWifi = false;
@@ -311,6 +313,13 @@ public class Utils {
}
public static void hideKeyboard(Activity activity) {
+ /*if (activity.getCurrentFocus() == null || !(activity.getCurrentFocus() instanceof EditText)) {
+ editText.requestFocus();
+ }
+ InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
+ activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);*/
+
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
if (inputMethodManager != null && activity.getCurrentFocus() != null) {
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);