aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/API/PushshiftAPI.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java36
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditMultiRedditActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java39
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ReportActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java34
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java62
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java25
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java307
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java308
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java416
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java121
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java319
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java251
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java107
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java48
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java148
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java61
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java148
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SetAsWallpaperAsyncTask.java95
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/MultiRedditOptionsBottomSheetFragment.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/SetAsWallpaperBottomSheetFragment.java79
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeMuteAutoplayingVideosEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Event/ShowThumbnailOnTheRightInCompactLayoutEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java (renamed from app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatVideoLinks.java)26
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchMessages.java24
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java97
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java141
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Font/ContentFontFamily.java31
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Font/ContentFontStyle.java (renamed from app/src/main/java/ml/docilealligator/infinityforreddit/ContentFontStyle.java)4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Font/FontFamily.java31
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Font/FontStyle.java (renamed from app/src/main/java/ml/docilealligator/infinityforreddit/FontStyle.java)4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Font/TitleFontFamily.java31
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Font/TitleFontStyle.java (renamed from app/src/main/java/ml/docilealligator/infinityforreddit/TitleFontStyle.java)4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewPostsFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java81
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurVideoFragment.java51
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewMessagesFragment.java128
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MediaDownloader.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MediaDownloaderImpl.java58
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/FavoriteMultiReddit.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Post/SubmitPost.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadRedditVideoService.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Service/SubmitPostService.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SetAsWallpaperCallback.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AboutPreferenceFragment.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CreditsPreferenceFragment.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontPreferenceFragment.java (renamed from app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontSizePreferenceFragment.java)29
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontPreviewFragment.java29
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ImmersiveInterfacePreferenceFragment.java53
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java45
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/VideoPreferenceFragment.java (renamed from app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AutoplayPreferenceFragment.java)13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/WallpaperSetter.java46
98 files changed, 2446 insertions, 1594 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/API/PushshiftAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/API/PushshiftAPI.java
new file mode 100644
index 00000000..1dc7b411
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/API/PushshiftAPI.java
@@ -0,0 +1,13 @@
+package ml.docilealligator.infinityforreddit.API;
+
+import retrofit2.Call;
+import retrofit2.http.GET;
+import retrofit2.http.Query;
+
+public interface PushshiftAPI {
+ @GET("reddit/comment/search/")
+ Call<String> getRemovedComment(@Query("ids") String commentId);
+
+ @GET("reddit/submission/search/")
+ Call<String> getRemovedPost(@Query("ids") String postId);
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
index 1e6ef259..97cc5967 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
@@ -16,6 +16,7 @@ import androidx.fragment.app.Fragment;
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;
@@ -94,6 +95,10 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java
index d3c3caf9..42e89abc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java
@@ -21,6 +21,8 @@ import androidx.viewpager.widget.ViewPager;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.tabs.TabLayout;
+import com.r0adkll.slidr.Slidr;
+import com.r0adkll.slidr.model.SlidrInterface;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -42,6 +44,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class AccountSavedThingActivity extends BaseActivity implements ActivityToolbarInterface {
@@ -74,6 +77,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
@Inject
CustomThemeWrapper mCustomThemeWrapper;
private SectionsPagerAdapter sectionsPagerAdapter;
+ private SlidrInterface mSlidrInterface;
private Menu mMenu;
private AppBarLayout.LayoutParams params;
private boolean mNullAccessToken = false;
@@ -95,6 +99,10 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ mSlidrInterface = Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
@@ -173,12 +181,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
viewPager.setOffscreenPageLimit(2);
tabLayout.setupWithViewPager(viewPager);
- viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
-
- }
-
+ viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
if (isInLazyMode) {
@@ -188,11 +191,12 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
sectionsPagerAdapter.pauseLazyMode();
}
}
- }
-
- @Override
- public void onPageScrollStateChanged(int state) {
+ if (position == 0) {
+ unlockSwipeRightToGoBack();
+ } else {
+ lockSwipeRightToGoBack();
+ }
}
});
}
@@ -284,6 +288,18 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
}
}
+ private void lockSwipeRightToGoBack() {
+ if (mSlidrInterface != null) {
+ mSlidrInterface.lock();
+ }
+ }
+
+ private void unlockSwipeRightToGoBack() {
+ if (mSlidrInterface != null) {
+ mSlidrInterface.unlock();
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment;
private CommentsListingFragment commentsListingFragment;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java
index 1eb8aa0a..883d0ce8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java
@@ -27,11 +27,14 @@ import com.google.android.material.tabs.TabLayout;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
-import ml.docilealligator.infinityforreddit.ContentFontStyle;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
-import ml.docilealligator.infinityforreddit.FontStyle;
+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.R;
-import ml.docilealligator.infinityforreddit.TitleFontStyle;
import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
@@ -113,6 +116,15 @@ public abstract class BaseActivity extends AppCompatActivity {
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);
+
+ getTheme().applyStyle(TitleFontFamily.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.TITLE_FONT_FAMILY_KEY, TitleFontFamily.Default.name())).getResId(), true);
+
+ getTheme().applyStyle(ContentFontFamily.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true);
+
Window window = getWindow();
View decorView = window.getDecorView();
if (!hasDrawerLayout) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java
index d9c07e88..95804f88 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java
@@ -27,6 +27,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
+import com.r0adkll.slidr.Slidr;
import org.commonmark.ext.gfm.tables.TableBlock;
import org.greenrobot.eventbus.EventBus;
@@ -56,6 +57,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SendComment;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Retrofit;
@@ -122,6 +124,10 @@ public class CommentActivity extends BaseActivity {
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java
index b564a3a3..86669de9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java
@@ -20,6 +20,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.snackbar.Snackbar;
+import com.r0adkll.slidr.Slidr;
import java.util.ArrayList;
@@ -35,6 +36,7 @@ import ml.docilealligator.infinityforreddit.MultiReddit.CreateMultiReddit;
import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditJSONModel;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class CreateMultiRedditActivity extends BaseActivity {
@@ -91,6 +93,10 @@ public class CreateMultiRedditActivity extends BaseActivity {
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java
index 42ee73c0..4e937cf6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java
@@ -38,12 +38,12 @@ import ml.docilealligator.infinityforreddit.AsyncTask.ChangeThemeNameAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.DeleteThemeAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCustomThemeAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertCustomThemeAsyncTask;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.CreateThemeBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.CustomThemeOptionsBottomSheetFragment;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeViewModel;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.CreateThemeBottomSheetFragment;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.CustomThemeOptionsBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
@@ -260,7 +260,7 @@ public class CustomThemeListingActivity extends BaseActivity implements
!clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) {
// since the clipboard has data but it is not plain text
Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show();
- } else if (clipboard.getPrimaryClip() != null){
+ } else if (clipboard.getPrimaryClip() != null) {
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
String json = item.getText().toString();
try {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java
index 307f5e13..1d807d13 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java
@@ -18,6 +18,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
+import com.r0adkll.slidr.Slidr;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -36,6 +37,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Call;
import retrofit2.Callback;
@@ -87,6 +89,10 @@ public class EditCommentActivity extends BaseActivity {
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditMultiRedditActivity.java
index de8c71a9..1eb815b6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditMultiRedditActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditMultiRedditActivity.java
@@ -22,6 +22,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.snackbar.Snackbar;
+import com.r0adkll.slidr.Slidr;
import javax.inject.Inject;
import javax.inject.Named;
@@ -37,6 +38,7 @@ import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditJSONModel;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class EditMultiRedditActivity extends BaseActivity {
@@ -100,6 +102,10 @@ public class EditMultiRedditActivity extends BaseActivity {
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java
index aaf5d2f5..d886f91f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java
@@ -20,6 +20,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
+import com.r0adkll.slidr.Slidr;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -38,6 +39,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@@ -89,6 +91,10 @@ public class EditPostActivity extends BaseActivity {
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
index c850f2d3..1ed02b61 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
@@ -16,6 +16,7 @@ import androidx.fragment.app.Fragment;
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;
@@ -109,6 +110,10 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java
index 0b7cf47f..45c310c0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java
@@ -79,20 +79,20 @@ public class LinkResolverActivity extends AppCompatActivity {
}
if (path.endsWith("jpg") || path.endsWith("png")) {
- Intent intent = new Intent(this, ViewImageActivity.class);
+ Intent intent = new Intent(this, ViewImageOrGifActivity.class);
String url = uri.toString();
String fileName = url.substring(url.lastIndexOf('/') + 1);
- intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, url);
- intent.putExtra(ViewImageActivity.FILE_NAME_KEY, fileName);
- intent.putExtra(ViewImageActivity.POST_TITLE_KEY, fileName);
+ intent.putExtra(ViewImageOrGifActivity.IMAGE_URL_KEY, url);
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, fileName);
+ intent.putExtra(ViewImageOrGifActivity.POST_TITLE_KEY, fileName);
startActivity(intent);
} else if (path.endsWith("gif")) {
- Intent intent = new Intent(this, ViewGIFActivity.class);
+ Intent intent = new Intent(this, ViewImageOrGifActivity.class);
String url = uri.toString();
String fileName = url.substring(url.lastIndexOf('/') + 1);
- intent.putExtra(ViewGIFActivity.GIF_URL_KEY, url);
- intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, fileName);
- intent.putExtra(ViewGIFActivity.POST_TITLE_KEY, fileName);
+ intent.putExtra(ViewImageOrGifActivity.GIF_URL_KEY, url);
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, fileName);
+ intent.putExtra(ViewImageOrGifActivity.POST_TITLE_KEY, fileName);
startActivity(intent);
} else if (path.endsWith("mp4")) {
Intent intent = new Intent(this, ViewVideoActivity.class);
@@ -159,8 +159,9 @@ public class LinkResolverActivity extends AppCompatActivity {
intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
} else if (path.matches(SIDEBAR_PATTERN)) {
- Intent intent = new Intent(this, ViewSidebarActivity.class);
- intent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, path.substring(3, path.length() - 14));
+ Intent intent = new Intent(this, ViewSubredditDetailActivity.class);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3, path.length() - 14));
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_VIEW_SIDEBAR, true);
startActivity(intent);
} else if (path.matches(MULTIREDDIT_PATTERN)) {
Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java
index 7f03f302..0fa06f4f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java
@@ -6,6 +6,8 @@ import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
+import android.util.Log;
+import android.view.InflateException;
import android.view.MenuItem;
import android.webkit.CookieManager;
import android.webkit.WebView;
@@ -16,6 +18,7 @@ import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import com.google.android.material.appbar.AppBarLayout;
+import com.r0adkll.slidr.Slidr;
import org.json.JSONException;
import org.json.JSONObject;
@@ -37,6 +40,7 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@@ -70,12 +74,23 @@ public class LoginActivity extends BaseActivity {
((Infinity) getApplication()).getAppComponent().inject(this);
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
+ try {
+ setContentView(R.layout.activity_login);
+ } catch (InflateException ie) {
+ Log.e("LoginActivity", "Failed to inflate LoginActivity: " + ie.getMessage());
+ Toast.makeText(LoginActivity.this, R.string.no_system_webview_error, Toast.LENGTH_SHORT).show();
+ finish();
+ return;
+ }
ButterKnife.bind(this);
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
index 14c12d2e..d1e9af09 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
@@ -64,6 +64,10 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchToAnonymousAccountAsyncTask;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostLayoutBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostTypeBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTimeBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.ChangeConfirmToExitEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeLockBottomAppBarEvent;
@@ -73,10 +77,6 @@ import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.FetchMyInfo;
import ml.docilealligator.infinityforreddit.FetchSubscribedThing;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostLayoutBottomSheetFragment;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostTypeBottomSheetFragment;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTimeBottomSheetFragment;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.ParseAndSaveAccountInfo;
import ml.docilealligator.infinityforreddit.Post.PostDataSource;
@@ -321,7 +321,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private void getCurrentAccountAndBindView() {
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
boolean enableNotification = mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_NOTIFICATION_KEY, true);
- String notificationInterval = mSharedPreferences.getString(SharedPreferencesUtils.NOTIFICATION_INTERVAL_KEY, "1");
+ long notificationInterval = Long.parseLong(mSharedPreferences.getString(SharedPreferencesUtils.NOTIFICATION_INTERVAL_KEY, "1"));
+ TimeUnit timeUnit = notificationInterval == 15 || notificationInterval == 30 ? TimeUnit.MINUTES : TimeUnit.HOURS;
WorkManager workManager = WorkManager.getInstance(this);
@@ -349,7 +350,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
PeriodicWorkRequest pullNotificationRequest =
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
- Long.parseLong(notificationInterval), TimeUnit.HOURS)
+ notificationInterval, timeUnit)
.setConstraints(constraints)
.build();
@@ -375,7 +376,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
PeriodicWorkRequest pullNotificationRequest =
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
- Long.parseLong(notificationInterval), TimeUnit.HOURS)
+ notificationInterval, timeUnit)
.setConstraints(constraints)
.build();
@@ -405,7 +406,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
PeriodicWorkRequest pullNotificationRequest =
new PeriodicWorkRequest.Builder(PullNotificationWorker.class,
- Long.parseLong(notificationInterval), TimeUnit.HOURS)
+ notificationInterval, timeUnit)
.setConstraints(constraints)
.build();
@@ -583,11 +584,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
viewPager.setOffscreenPageLimit(3);
tabLayout.setupWithViewPager(viewPager);
- viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- }
-
+ viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
if (mAccessToken != null) {
@@ -605,10 +602,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
sectionsPagerAdapter.displaySortTypeInToolbar();
}
-
- @Override
- public void onPageScrollStateChanged(int state) {
- }
});
loadSubscriptions();
@@ -1366,9 +1359,17 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
void goBackToTop() {
if (viewPager.getCurrentItem() == 0) {
- tab1.goBackToTop();
+ if (mAccessToken != null && tab1 != null) {
+ tab1.goBackToTop();
+ } else if (tab2 != null) {
+ tab2.goBackToTop();
+ }
} else if (viewPager.getCurrentItem() == 1) {
- tab2.goBackToTop();
+ if (mAccessToken != null && tab2 != null) {
+ tab2.goBackToTop();
+ } else if (tab3 != null) {
+ tab3.goBackToTop();
+ }
} else {
tab3.goBackToTop();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java
index 2ef1d14f..e636572d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java
@@ -26,8 +26,7 @@ import com.bumptech.glide.RequestManager;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
-
-import org.greenrobot.eventbus.Subscribe;
+import com.r0adkll.slidr.Slidr;
import java.util.ArrayList;
@@ -41,7 +40,6 @@ import ml.docilealligator.infinityforreddit.Adapter.MultiRedditListingRecyclerVi
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertMultiRedditAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
-import ml.docilealligator.infinityforreddit.Event.RefreshMultiRedditsEvent;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.MultiReddit.DeleteMultiReddit;
import ml.docilealligator.infinityforreddit.MultiReddit.FetchMyMultiReddits;
@@ -49,6 +47,7 @@ import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditViewModel;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class MultiRedditListingActivity extends BaseActivity {
@@ -105,6 +104,10 @@ public class MultiRedditListingActivity extends BaseActivity {
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
@@ -292,8 +295,8 @@ public class MultiRedditListingActivity extends BaseActivity {
.show();
}
- @Subscribe
+ /*@Subscribe
public void onRefreshMultiRedditsEvent(RefreshMultiRedditsEvent event) {
loadMultiReddits();
- }
+ }*/
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java
index 0bfbc20e..07952f79 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java
@@ -32,6 +32,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.libRG.CustomTextView;
+import com.r0adkll.slidr.Slidr;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -56,6 +57,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Service.SubmitPostService;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
@@ -175,6 +177,10 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java
index 5edb7c8f..c041f64e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java
@@ -25,6 +25,7 @@ import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import com.libRG.CustomTextView;
+import com.r0adkll.slidr.Slidr;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -47,6 +48,7 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Service.SubmitPostService;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
@@ -150,6 +152,10 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
@@ -541,7 +547,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
} else {
mMemu.findItem(R.id.action_send_post_link_activity).setEnabled(true);
mMemu.findItem(R.id.action_send_post_link_activity).getIcon().setAlpha(255);
- if (submitTextOrLinkPostEvent.errorMessage == null) {
+ if (submitTextOrLinkPostEvent.errorMessage == null || submitTextOrLinkPostEvent.errorMessage.equals("")) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(coordinatorLayout, submitTextOrLinkPostEvent.errorMessage.substring(0, 1).toUpperCase()
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java
index 29b0256f..a3e3accc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java
@@ -25,6 +25,7 @@ import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import com.libRG.CustomTextView;
+import com.r0adkll.slidr.Slidr;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -47,6 +48,7 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Service.SubmitPostService;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
@@ -150,6 +152,10 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
@@ -541,7 +547,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
} else {
mMemu.findItem(R.id.action_send_post_text_activity).setEnabled(true);
mMemu.findItem(R.id.action_send_post_text_activity).getIcon().setAlpha(255);
- if (submitTextOrLinkPostEvent.errorMessage == null) {
+ if (submitTextOrLinkPostEvent.errorMessage == null || submitTextOrLinkPostEvent.errorMessage.equals("")) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(coordinatorLayout, submitTextOrLinkPostEvent.errorMessage.substring(0, 1).toUpperCase()
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java
index 386032a7..68068775 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java
@@ -37,6 +37,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.libRG.CustomTextView;
+import com.r0adkll.slidr.Slidr;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -58,6 +59,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Service.SubmitPostService;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
@@ -183,6 +185,10 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ReportActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ReportActivity.java
index 4e3a0738..b816b505 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ReportActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ReportActivity.java
@@ -15,6 +15,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.snackbar.Snackbar;
+import com.r0adkll.slidr.Slidr;
import java.util.ArrayList;
@@ -33,6 +34,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.ReportReason;
import ml.docilealligator.infinityforreddit.ReportThing;
import ml.docilealligator.infinityforreddit.Rule;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class ReportActivity extends BaseActivity {
@@ -86,6 +88,10 @@ public class ReportActivity extends BaseActivity {
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java
index 2c5cb05c..f90dedf3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java
@@ -18,6 +18,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
+import com.r0adkll.slidr.Slidr;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -36,6 +37,7 @@ import ml.docilealligator.infinityforreddit.FetchRules;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Rule;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class RulesActivity extends BaseActivity {
@@ -79,6 +81,10 @@ public class RulesActivity extends BaseActivity {
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java
index 0160401a..8b603451 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java
@@ -20,6 +20,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.ferfalk.simplesearchview.SimpleSearchView;
import com.google.android.material.appbar.AppBarLayout;
+import com.r0adkll.slidr.Slidr;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -33,6 +34,7 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
public class SearchActivity extends BaseActivity {
@@ -86,6 +88,10 @@ public class SearchActivity extends BaseActivity {
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
setSupportActionBar(toolbar);
boolean searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
index 764c065c..5ea80f8f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
@@ -21,6 +21,8 @@ import androidx.viewpager.widget.ViewPager;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.tabs.TabLayout;
+import com.r0adkll.slidr.Slidr;
+import com.r0adkll.slidr.model.SlidrInterface;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -93,6 +95,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
+ private SlidrInterface mSlidrInterface;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -108,6 +111,10 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ mSlidrInterface = Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
@@ -201,18 +208,15 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOffscreenPageLimit(2);
- viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- }
-
+ viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
sectionsPagerAdapter.displaySortTypeInToolbar();
- }
-
- @Override
- public void onPageScrollStateChanged(int state) {
+ if (position == 0) {
+ unlockSwipeRightToGoBack();
+ } else {
+ lockSwipeRightToGoBack();
+ }
}
});
tabLayout.setupWithViewPager(viewPager);
@@ -497,4 +501,16 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
}
}
}
+
+ private void lockSwipeRightToGoBack() {
+ if (mSlidrInterface != null) {
+ mSlidrInterface.lock();
+ }
+ }
+
+ private void unlockSwipeRightToGoBack() {
+ if (mSlidrInterface != null) {
+ mSlidrInterface.unlock();
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java
index 092cd5d8..b7b2730d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java
@@ -15,6 +15,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import com.google.android.material.appbar.AppBarLayout;
+import com.r0adkll.slidr.Slidr;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -32,6 +33,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
public class SearchSubredditsResultActivity extends BaseActivity implements ActivityToolbarInterface {
@@ -76,6 +78,10 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java
index 96bbabdb..3d17ecbf 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java
@@ -16,6 +16,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import com.r0adkll.slidr.Slidr;
import java.util.ArrayList;
@@ -29,6 +30,7 @@ import ml.docilealligator.infinityforreddit.Adapter.SelectedSubredditsRecyclerVi
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
public class SelectedSubredditsActivity extends BaseActivity implements ActivityToolbarInterface {
@@ -63,8 +65,13 @@ public class SelectedSubredditsActivity extends BaseActivity implements Activity
setContentView(R.layout.activity_selected_subreddits);
ButterKnife.bind(this);
+
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java
index ef91f34a..3c50caf8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java
@@ -26,6 +26,7 @@ import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Settings.AboutPreferenceFragment;
+import ml.docilealligator.infinityforreddit.Settings.FontPreferenceFragment;
import ml.docilealligator.infinityforreddit.Settings.InterfacePreferenceFragment;
import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment;
@@ -83,6 +84,8 @@ public class SettingsActivity extends BaseActivity implements
setTitle(R.string.settings_about_master_title);
} else if (getSupportFragmentManager().findFragmentById(R.id.frame_layout_settings_activity) instanceof InterfacePreferenceFragment) {
setTitle(R.string.settings_interface_title);
+ } else if (getSupportFragmentManager().findFragmentById(R.id.frame_layout_settings_activity) instanceof FontPreferenceFragment) {
+ setTitle(R.string.settings_font_title);
}
});
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java
index d464ecec..88825dc5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java
@@ -26,6 +26,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.google.android.material.appbar.AppBarLayout;
+import com.r0adkll.slidr.Slidr;
import java.util.ArrayList;
@@ -42,6 +43,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class SubredditMultiselectionActivity extends BaseActivity implements ActivityToolbarInterface {
@@ -86,6 +88,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
private LinearLayoutManager mLinearLayoutManager;
private SubredditMultiselectionRecyclerViewAdapter mAdapter;
private RequestManager mGlide;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this);
@@ -96,6 +99,10 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java
index f48cb952..b6aa045d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java
@@ -17,6 +17,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import com.google.android.material.appbar.AppBarLayout;
+import com.r0adkll.slidr.Slidr;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -41,6 +42,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class SubredditSelectionActivity extends BaseActivity implements ActivityToolbarInterface {
@@ -95,6 +97,10 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java
index c1919782..994d19e7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java
@@ -18,7 +18,10 @@ import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.tabs.TabLayout;
+import com.r0adkll.slidr.Slidr;
+import com.r0adkll.slidr.model.SlidrInterface;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -36,6 +39,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.InsertMultiRedditAsyncTask
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.GoBackToMainPageEvent;
+import ml.docilealligator.infinityforreddit.Event.RefreshMultiRedditsEvent;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.FetchSubscribedThing;
import ml.docilealligator.infinityforreddit.Fragment.FollowedUsersListingFragment;
@@ -43,6 +47,7 @@ import ml.docilealligator.infinityforreddit.Fragment.MultiRedditListingFragment;
import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListingFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.MultiReddit.DeleteMultiReddit;
import ml.docilealligator.infinityforreddit.MultiReddit.FetchMyMultiReddits;
import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
import ml.docilealligator.infinityforreddit.R;
@@ -50,6 +55,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class SubscribedThingListingActivity extends BaseActivity implements ActivityToolbarInterface {
@@ -81,6 +87,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
SharedPreferences mSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
+ private SlidrInterface mSlidrInterface;
private boolean mNullAccessToken = false;
private String mAccessToken;
private String mAccountName;
@@ -103,6 +110,10 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ mSlidrInterface = Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
@@ -170,6 +181,16 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOffscreenPageLimit(3);
+ viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
+ @Override
+ public void onPageSelected(int position) {
+ if (position == 0) {
+ unlockSwipeRightToGoBack();
+ } else {
+ lockSwipeRightToGoBack();
+ }
+ }
+ });
tabLayout.setupWithViewPager(viewPager);
if (showMultiReddits) {
@@ -261,6 +282,30 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
});
}
+ public void deleteMultiReddit(MultiReddit multiReddit) {
+ new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.delete)
+ .setMessage(R.string.delete_multi_reddit_dialog_message)
+ .setPositiveButton(R.string.delete, (dialogInterface, i)
+ -> DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
+ mAccessToken, mAccountName, multiReddit.getPath(), new DeleteMultiReddit.DeleteMultiRedditListener() {
+ @Override
+ public void success() {
+ Toast.makeText(SubscribedThingListingActivity.this,
+ R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show();
+ loadMultiReddits();
+ }
+
+ @Override
+ public void failed() {
+ Toast.makeText(SubscribedThingListingActivity.this,
+ R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show();
+ }
+ }))
+ .setNegativeButton(R.string.cancel, null)
+ .show();
+ }
+
@Subscribe
public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish();
@@ -271,6 +316,11 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
finish();
}
+ @Subscribe
+ public void onRefreshMultiRedditsEvent(RefreshMultiRedditsEvent event) {
+ loadMultiReddits();
+ }
+
@Override
public void onLongPress() {
if (sectionsPagerAdapter != null) {
@@ -278,6 +328,18 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
}
}
+ private void lockSwipeRightToGoBack() {
+ if (mSlidrInterface != null) {
+ mSlidrInterface.lock();
+ }
+ }
+
+ private void unlockSwipeRightToGoBack() {
+ if (mSlidrInterface != null) {
+ mSlidrInterface.unlock();
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentPagerAdapter {
private SubscribedSubredditsListingFragment subscribedSubredditsListingFragment;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java
index c9a08f48..ed20127b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java
@@ -32,6 +32,7 @@ import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.chip.Chip;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
+import com.r0adkll.slidr.Slidr;
import java.util.ArrayList;
@@ -41,15 +42,15 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
-import ml.docilealligator.infinityforreddit.ContentFontStyle;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeSettingsItem;
-import ml.docilealligator.infinityforreddit.FontStyle;
+import ml.docilealligator.infinityforreddit.Font.ContentFontStyle;
+import ml.docilealligator.infinityforreddit.Font.FontStyle;
+import ml.docilealligator.infinityforreddit.Font.TitleFontStyle;
import ml.docilealligator.infinityforreddit.Fragment.ThemePreviewCommentsFragment;
import ml.docilealligator.infinityforreddit.Fragment.ThemePreviewPostsFragment;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.TitleFontStyle;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
@@ -133,7 +134,7 @@ public class ThemePreviewActivity extends AppCompatActivity {
break;
case 1:
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
- if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) {
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) {
getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true);
} else {
getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true);
@@ -145,10 +146,10 @@ public class ThemePreviewActivity extends AppCompatActivity {
} else {
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY);
}
- if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) {
+ if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) {
getTheme().applyStyle(R.style.Theme_Normal, true);
} else {
- if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) {
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) {
getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true);
} else {
getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true);
@@ -215,8 +216,13 @@ public class ThemePreviewActivity extends AppCompatActivity {
setContentView(R.layout.activity_theme_preview);
ButterKnife.bind(this);
+
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (immersiveInterface) {
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
@@ -354,10 +360,9 @@ public class ThemePreviewActivity extends AppCompatActivity {
params.topMargin = statusBarHeight;
toolbar.setLayoutParams(params);
TypedValue tv = new TypedValue();
- if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
- {
- ((ViewGroup.MarginLayoutParams)linearLayout.getLayoutParams()).setMargins(0,
- TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics()) + statusBarHeight, 0, 0);
+ if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
+ ((ViewGroup.MarginLayoutParams) linearLayout.getLayoutParams()).setMargins(0,
+ TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()) + statusBarHeight, 0, 0);
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java
deleted file mode 100644
index 8bdc82fe..00000000
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java
+++ /dev/null
@@ -1,307 +0,0 @@
-package ml.docilealligator.infinityforreddit.Activity;
-
-import android.Manifest;
-import android.app.DownloadManager;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
-import android.graphics.drawable.ColorDrawable;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Environment;
-import android.text.Html;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.LinearLayout;
-import android.widget.ProgressBar;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.core.app.ActivityCompat;
-import androidx.core.content.ContextCompat;
-import androidx.core.content.FileProvider;
-
-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.gif.GifDrawable;
-import com.bumptech.glide.request.RequestListener;
-import com.bumptech.glide.request.RequestOptions;
-import com.bumptech.glide.request.target.Target;
-import com.thefuntasty.hauler.HaulerView;
-
-import java.io.File;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import butterknife.BindView;
-import butterknife.ButterKnife;
-import ml.docilealligator.infinityforreddit.AsyncTask.SaveGIFToFileAsyncTask;
-import ml.docilealligator.infinityforreddit.BuildConfig;
-import ml.docilealligator.infinityforreddit.ContentFontStyle;
-import ml.docilealligator.infinityforreddit.FontStyle;
-import ml.docilealligator.infinityforreddit.Infinity;
-import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.TitleFontStyle;
-import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
-import pl.droidsonroids.gif.GifImageView;
-
-public class ViewGIFActivity extends AppCompatActivity {
-
- public static final String GIF_URL_KEY = "GUK";
- public static final String FILE_NAME_KEY = "FNK";
- public static final String POST_TITLE_KEY = "PTK";
- private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
- @BindView(R.id.hauler_view_view_gif_activity)
- HaulerView mHaulerView;
- @BindView(R.id.progress_bar_view_gif_activity)
- ProgressBar mProgressBar;
- @BindView(R.id.image_view_view_gif_activity)
- GifImageView mImageView;
- @BindView(R.id.load_image_error_linear_layout_view_gif_activity)
- LinearLayout mLoadErrorLinearLayout;
- @Inject
- @Named("default")
- SharedPreferences mSharedPreferences;
- private boolean isActionBarHidden = false;
- private boolean isDownloading = false;
- private RequestManager glide;
- private String mImageUrl;
- private String mImageFileName;
- private boolean isSwiping = false;
- private String postTitle;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- ((Infinity) getApplication()).getAppComponent().inject(this);
-
- 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);
-
- setContentView(R.layout.activity_view_gif);
-
- 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)));
-
- mHaulerView.setOnDragDismissedListener(dragDirection -> finish());
-
- glide = Glide.with(this);
-
- Intent intent = getIntent();
- mImageUrl = intent.getStringExtra(GIF_URL_KEY);
- mImageFileName = intent.getStringExtra(FILE_NAME_KEY);
- postTitle = intent.getStringExtra(POST_TITLE_KEY);
-
- if (postTitle != null) {
- setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
- } else {
- setTitle("");
- }
-
- mLoadErrorLinearLayout.setOnClickListener(view -> {
- if (!isSwiping) {
- mProgressBar.setVisibility(View.VISIBLE);
- mLoadErrorLinearLayout.setVisibility(View.GONE);
- loadImage();
- }
- });
-
- loadImage();
-
- mImageView.setOnClickListener(view -> {
- if (isActionBarHidden) {
- getWindow().getDecorView().setSystemUiVisibility(
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE
- | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
- isActionBarHidden = false;
- } else {
- getWindow().getDecorView().setSystemUiVisibility(
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE
- | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
- | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_FULLSCREEN
- | View.SYSTEM_UI_FLAG_IMMERSIVE);
- isActionBarHidden = true;
- }
- });
- }
-
- private void loadImage() {
- glide.load(mImageUrl).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- mProgressBar.setVisibility(View.GONE);
- mLoadErrorLinearLayout.setVisibility(View.VISIBLE);
- return false;
- }
-
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- mProgressBar.setVisibility(View.GONE);
- return false;
- }
- }).apply(new RequestOptions().fitCenter()).into(mImageView);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.view_gif_activity, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- finish();
- return true;
- case R.id.action_download_view_gif_activity:
- if (isDownloading) {
- return false;
- }
-
- isDownloading = true;
-
- if (Build.VERSION.SDK_INT >= 23) {
- 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();
- }
-
- return true;
- case R.id.action_share_view_gif_activity:
- Toast.makeText(ViewGIFActivity.this, R.string.save_gif_before_sharing, Toast.LENGTH_SHORT).show();
- glide.asGif().load(mImageUrl).listener(new RequestListener<GifDrawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
- return false;
- }
-
- @Override
- public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
- if (getExternalCacheDir() != null) {
- new SaveGIFToFileAsyncTask(resource, getExternalCacheDir().getPath(), mImageFileName,
- new SaveGIFToFileAsyncTask.SaveGIFToFileAsyncTaskListener() {
- @Override
- public void saveSuccess(File imageFile) {
- Uri uri = FileProvider.getUriForFile(ViewGIFActivity.this,
- 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(ViewGIFActivity.this,
- R.string.cannot_save_gif, Toast.LENGTH_SHORT).show();
- }
- }).execute();
- } else {
- Toast.makeText(ViewGIFActivity.this,
- R.string.cannot_get_storage, Toast.LENGTH_SHORT).show();
- }
- return false;
- }
- }).submit();
- return true;
- }
-
- return false;
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {
- if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
- Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
- } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED && isDownloading) {
- download();
- }
- isDownloading = false;
- }
- }
-
- private void download() {
- DownloadManager.Request request = new DownloadManager.Request(Uri.parse(mImageUrl));
- request.setTitle(mImageFileName);
-
- request.allowScanningByMediaScanner();
- request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
-
- //Android Q support
- if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, mImageFileName);
- } else {
- String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
- File directory = new File(path + "/Infinity/");
- boolean saveToInfinityFolder = true;
- if (!directory.exists()) {
- if (!directory.mkdir()) {
- saveToInfinityFolder = false;
- }
- } else {
- if (directory.isFile()) {
- if (!(directory.delete() && directory.mkdir())) {
- saveToInfinityFolder = false;
- }
- }
- }
-
- if (saveToInfinityFolder) {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + "/Infinity/", mImageFileName);
- } else {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, mImageFileName);
- }
- }
-
- DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
-
- if (manager == null) {
- Toast.makeText(this, R.string.download_failed, Toast.LENGTH_SHORT).show();
- return;
- }
-
- manager.enqueue(request);
- Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
- }
-}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java
deleted file mode 100644
index 779d7fe7..00000000
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java
+++ /dev/null
@@ -1,308 +0,0 @@
-package ml.docilealligator.infinityforreddit.Activity;
-
-import android.Manifest;
-import android.app.DownloadManager;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
-import android.graphics.Bitmap;
-import android.graphics.drawable.ColorDrawable;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Environment;
-import android.text.Html;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.LinearLayout;
-import android.widget.ProgressBar;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.core.app.ActivityCompat;
-import androidx.core.content.ContextCompat;
-import androidx.core.content.FileProvider;
-
-import com.alexvasilkov.gestures.views.GestureImageView;
-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.request.RequestListener;
-import com.bumptech.glide.request.target.CustomTarget;
-import com.bumptech.glide.request.target.Target;
-import com.bumptech.glide.request.transition.Transition;
-import com.thefuntasty.hauler.HaulerView;
-
-import java.io.File;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import butterknife.BindView;
-import butterknife.ButterKnife;
-import ml.docilealligator.infinityforreddit.AsyncTask.SaveImageToFileAsyncTask;
-import ml.docilealligator.infinityforreddit.BuildConfig;
-import ml.docilealligator.infinityforreddit.ContentFontStyle;
-import ml.docilealligator.infinityforreddit.FontStyle;
-import ml.docilealligator.infinityforreddit.Infinity;
-import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.TitleFontStyle;
-import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
-
-public class ViewImageActivity extends AppCompatActivity {
-
- public static final String IMAGE_URL_KEY = "IUK";
- public static final String FILE_NAME_KEY = "FNK";
- public static final String POST_TITLE_KEY = "PTK";
- private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
- @BindView(R.id.hauler_view_view_image_activity)
- HaulerView mHaulerView;
- @BindView(R.id.progress_bar_view_image_activity)
- ProgressBar mProgressBar;
- @BindView(R.id.image_view_view_image_activity)
- GestureImageView mImageView;
- @BindView(R.id.load_image_error_linear_layout_view_image_activity)
- LinearLayout mLoadErrorLinearLayout;
- @Inject
- @Named("default")
- SharedPreferences mSharedPreferences;
- private boolean isActionBarHidden = false;
- private boolean isDownloading = false;
- private String mImageUrl;
- private String mImageFileName;
- private RequestManager glide;
- private String postTitle;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- ((Infinity) getApplication()).getAppComponent().inject(this);
-
- 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);
-
- setContentView(R.layout.activity_view_image);
-
- 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)));
-
- glide = Glide.with(this);
-
- Intent intent = getIntent();
- mImageUrl = intent.getStringExtra(IMAGE_URL_KEY);
- mImageFileName = intent.getStringExtra(FILE_NAME_KEY);
- postTitle = intent.getStringExtra(POST_TITLE_KEY);
-
- if (postTitle != null) {
- setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
- } else {
- setTitle("");
- }
-
- mHaulerView.setOnDragDismissedListener(dragDirection -> finish());
-
- mLoadErrorLinearLayout.setOnClickListener(view -> {
- mProgressBar.setVisibility(View.VISIBLE);
- mLoadErrorLinearLayout.setVisibility(View.GONE);
- loadImage();
- });
-
- loadImage();
-
- mImageView.getController().getSettings().setMaxZoom(10f).setDoubleTapZoom(2f).setPanEnabled(true);
-
- mImageView.setOnClickListener(view -> {
- if (isActionBarHidden) {
- getWindow().getDecorView().setSystemUiVisibility(
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE
- | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
- isActionBarHidden = false;
- } else {
- getWindow().getDecorView().setSystemUiVisibility(
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE
- | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
- | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_FULLSCREEN
- | View.SYSTEM_UI_FLAG_IMMERSIVE);
- isActionBarHidden = true;
- }
- });
- }
-
- private void loadImage() {
- glide.load(mImageUrl).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- mProgressBar.setVisibility(View.GONE);
- mLoadErrorLinearLayout.setVisibility(View.VISIBLE);
- return false;
- }
-
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- mProgressBar.setVisibility(View.GONE);
- return false;
- }
- }).into(mImageView);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.view_image_activity, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- finish();
- return true;
- case R.id.action_download_view_image_activity:
- if (isDownloading) {
- return false;
- }
-
- isDownloading = true;
-
- if (Build.VERSION.SDK_INT >= 23) {
- 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();
- }
-
- return true;
- case R.id.action_share_view_image_activity:
- glide.asBitmap().load(mImageUrl).into(new CustomTarget<Bitmap>() {
-
- @Override
- public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
- if (getExternalCacheDir() != null) {
- Toast.makeText(ViewImageActivity.this, R.string.save_image_before_sharing, Toast.LENGTH_SHORT).show();
- new SaveImageToFileAsyncTask(resource, getExternalCacheDir().getPath(), mImageFileName,
- new SaveImageToFileAsyncTask.SaveImageToFileAsyncTaskListener() {
- @Override
- public void saveSuccess(File imageFile) {
- Uri uri = FileProvider.getUriForFile(ViewImageActivity.this,
- 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(ViewImageActivity.this,
- R.string.cannot_save_image, Toast.LENGTH_SHORT).show();
- }
- }).execute();
- } else {
- Toast.makeText(ViewImageActivity.this,
- R.string.cannot_get_storage, Toast.LENGTH_SHORT).show();
- }
- }
-
- @Override
- public void onLoadCleared(@Nullable Drawable placeholder) {
-
- }
- });
- return true;
- }
-
- return false;
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {
- if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
- Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
- } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED && isDownloading) {
- download();
- }
- isDownloading = false;
- }
- }
-
- private void download() {
- DownloadManager.Request request = new DownloadManager.Request(Uri.parse(mImageUrl));
- request.setTitle(mImageFileName);
-
- request.allowScanningByMediaScanner();
- request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
-
- //Android Q support
- if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, mImageFileName);
- } else {
- String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
- File directory = new File(path + "/Infinity/");
- boolean saveToInfinityFolder = true;
- if (!directory.exists()) {
- if (!directory.mkdir()) {
- saveToInfinityFolder = false;
- }
- } else {
- if (directory.isFile()) {
- if (!(directory.delete() && directory.mkdir())) {
- saveToInfinityFolder = false;
- }
- }
- }
-
- if (saveToInfinityFolder) {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + "/Infinity/", mImageFileName);
- } else {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, mImageFileName);
- }
- }
-
- DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
-
- if (manager == null) {
- Toast.makeText(this, R.string.download_failed, Toast.LENGTH_SHORT).show();
- return;
- }
-
- manager.enqueue(request);
- Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
- }
-}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java
new file mode 100644
index 00000000..68631472
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java
@@ -0,0 +1,416 @@
+package ml.docilealligator.infinityforreddit.Activity;
+
+import android.Manifest;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.graphics.Bitmap;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+import android.net.Uri;
+import android.os.Build;
+import android.os.Bundle;
+import android.text.Html;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
+import androidx.core.content.FileProvider;
+
+import com.alexvasilkov.gestures.views.GestureFrameLayout;
+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.gif.GifDrawable;
+import com.bumptech.glide.request.RequestListener;
+import com.bumptech.glide.request.target.CustomTarget;
+import com.bumptech.glide.request.target.Target;
+import com.bumptech.glide.request.transition.Transition;
+import com.thefuntasty.hauler.DragDirection;
+import com.thefuntasty.hauler.HaulerView;
+
+import java.io.File;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.AsyncTask.SaveGIFToFileAsyncTask;
+import ml.docilealligator.infinityforreddit.AsyncTask.SaveImageToFileAsyncTask;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.SetAsWallpaperBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.BuildConfig;
+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.Infinity;
+import ml.docilealligator.infinityforreddit.MediaDownloader;
+import ml.docilealligator.infinityforreddit.MediaDownloaderImpl;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.WallpaperSetter;
+import pl.droidsonroids.gif.GifImageView;
+
+public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWallpaperCallback {
+
+ public static final String IMAGE_URL_KEY = "IUK";
+ public static final String GIF_URL_KEY = "GUK";
+ public static final String FILE_NAME_KEY = "FNK";
+ public static final String POST_TITLE_KEY = "PTK";
+ private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
+ @BindView(R.id.hauler_view_view_image_or_gif_activity)
+ HaulerView mHaulerView;
+ @BindView(R.id.progress_bar_view_image_or_gif_activity)
+ ProgressBar mProgressBar;
+ @BindView(R.id.image_view_view_image_or_gif_activity)
+ GifImageView mImageView;
+ @BindView(R.id.gesture_layout_view_image_or_gif_activity)
+ GestureFrameLayout gestureLayout;
+ @BindView(R.id.load_image_error_linear_layout_view_image_or_gif_activity)
+ LinearLayout mLoadErrorLinearLayout;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ private MediaDownloader mediaDownloader;
+ private boolean isActionBarHidden = false;
+ private boolean isDownloading = false;
+ private RequestManager glide;
+ private String mImageUrl;
+ private String mImageFileName;
+ private boolean isGif = true;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
+ 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);
+
+ getTheme().applyStyle(TitleFontFamily.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.TITLE_FONT_FAMILY_KEY, TitleFontFamily.Default.name())).getResId(), true);
+
+ getTheme().applyStyle(ContentFontFamily.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true);
+
+ setContentView(R.layout.activity_view_image_or_gif);
+
+ 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)));
+
+ mHaulerView.setOnDragDismissedListener(dragDirection -> finish());
+
+ mediaDownloader = new MediaDownloaderImpl();
+
+ glide = Glide.with(this);
+
+ Intent intent = getIntent();
+ mImageUrl = intent.getStringExtra(GIF_URL_KEY);
+ if (mImageUrl == null) {
+ isGif = false;
+ mImageUrl = intent.getStringExtra(IMAGE_URL_KEY);
+ }
+ mImageFileName = intent.getStringExtra(FILE_NAME_KEY);
+ String postTitle = intent.getStringExtra(POST_TITLE_KEY);
+
+ if (postTitle != null) {
+ setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
+ } else {
+ setTitle("");
+ }
+
+ mHaulerView.setOnDragDismissedListener(dragDirection -> {
+ int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down;
+ finish();
+ overridePendingTransition(0, slide);
+ });
+
+ mLoadErrorLinearLayout.setOnClickListener(view -> {
+ mProgressBar.setVisibility(View.VISIBLE);
+ mLoadErrorLinearLayout.setVisibility(View.GONE);
+ loadImage();
+ });
+
+ loadImage();
+
+ gestureLayout.getController().getSettings().setMaxZoom(10f).setDoubleTapZoom(2f).setPanEnabled(true);
+
+ mImageView.setOnClickListener(view -> {
+ if (isActionBarHidden) {
+ getWindow().getDecorView().setSystemUiVisibility(
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
+ isActionBarHidden = false;
+ } else {
+ getWindow().getDecorView().setSystemUiVisibility(
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_IMMERSIVE);
+ isActionBarHidden = true;
+ }
+ });
+ }
+
+ private void loadImage() {
+ glide.load(mImageUrl).listener(new RequestListener<Drawable>() {
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+ mProgressBar.setVisibility(View.GONE);
+ mLoadErrorLinearLayout.setVisibility(View.VISIBLE);
+ return false;
+ }
+
+ @Override
+ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+ mProgressBar.setVisibility(View.GONE);
+ return false;
+ }
+ }).override(Target.SIZE_ORIGINAL).into(mImageView);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.view_image_or_gif_activity, menu);
+ if (!isGif)
+ menu.findItem(R.id.action_set_wallpaper_view_image_or_gif_activity).setVisible(true);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ case R.id.action_download_view_image_or_gif_activity:
+ if (isDownloading) {
+ return false;
+ }
+
+ isDownloading = true;
+
+ if (Build.VERSION.SDK_INT >= 23) {
+ 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
+ mediaDownloader.download(mImageUrl, mImageFileName, this);
+ }
+ } else {
+ mediaDownloader.download(mImageUrl, mImageFileName, this);
+ }
+
+ return true;
+ case R.id.action_share_view_image_or_gif_activity:
+ if (isGif)
+ shareGif();
+ else
+ shareImage();
+ return true;
+ case 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(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();
+ }
+ });
+ }
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ private void shareImage() {
+ glide.asBitmap().load(mImageUrl).into(new CustomTarget<Bitmap>() {
+
+ @Override
+ public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
+ if (getExternalCacheDir() != null) {
+ Toast.makeText(ViewImageOrGifActivity.this, R.string.save_image_first, Toast.LENGTH_SHORT).show();
+ new SaveImageToFileAsyncTask(resource, getExternalCacheDir().getPath(), mImageFileName,
+ new SaveImageToFileAsyncTask.SaveImageToFileAsyncTaskListener() {
+ @Override
+ public void saveSuccess(File imageFile) {
+ Uri uri = FileProvider.getUriForFile(ViewImageOrGifActivity.this,
+ 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(ViewImageOrGifActivity.this,
+ R.string.cannot_save_image, Toast.LENGTH_SHORT).show();
+ }
+ }).execute();
+ } else {
+ Toast.makeText(ViewImageOrGifActivity.this,
+ R.string.cannot_get_storage, Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ @Override
+ public void onLoadCleared(@Nullable Drawable placeholder) {
+
+ }
+ });
+ }
+
+ private void shareGif() {
+ Toast.makeText(ViewImageOrGifActivity.this, R.string.save_gif_first, Toast.LENGTH_SHORT).show();
+ glide.asGif().load(mImageUrl).listener(new RequestListener<GifDrawable>() {
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
+ return false;
+ }
+
+ @Override
+ public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
+ if (getExternalCacheDir() != null) {
+ new SaveGIFToFileAsyncTask(resource, getExternalCacheDir().getPath(), mImageFileName,
+ new SaveGIFToFileAsyncTask.SaveGIFToFileAsyncTaskListener() {
+ @Override
+ public void saveSuccess(File imageFile) {
+ Uri uri = FileProvider.getUriForFile(ViewImageOrGifActivity.this,
+ 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(ViewImageOrGifActivity.this,
+ R.string.cannot_save_gif, Toast.LENGTH_SHORT).show();
+ }
+ }).execute();
+ } else {
+ Toast.makeText(ViewImageOrGifActivity.this,
+ R.string.cannot_get_storage, Toast.LENGTH_SHORT).show();
+ }
+ return false;
+ }
+ }).submit();
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {
+ if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
+ Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
+ } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED && isDownloading) {
+ mediaDownloader.download(mImageUrl, mImageFileName, this);
+ }
+ isDownloading = false;
+ }
+ }
+
+ @Override
+ public void setToHomeScreen(int viewPagerPosition) {
+ WallpaperSetter.set(mImageUrl, WallpaperSetter.HOME_SCREEN, 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 setToLockScreen(int viewPagerPosition) {
+ WallpaperSetter.set(mImageUrl, WallpaperSetter.LOCK_SCREEN, 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 setToBoth(int viewPagerPosition) {
+ WallpaperSetter.set(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();
+ }
+ });
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java
index 9e0b95e7..0e073b70 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java
@@ -10,6 +10,7 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
+import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
@@ -19,6 +20,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
+import com.thefuntasty.hauler.DragDirection;
import com.thefuntasty.hauler.HaulerView;
import org.json.JSONArray;
@@ -33,23 +35,28 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.API.ImgurAPI;
-import ml.docilealligator.infinityforreddit.ContentFontStyle;
-import ml.docilealligator.infinityforreddit.FontStyle;
+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.Fragment.ViewImgurImageFragment;
import ml.docilealligator.infinityforreddit.Fragment.ViewImgurVideoFragment;
import ml.docilealligator.infinityforreddit.ImgurMedia;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.TitleFontStyle;
+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;
import retrofit2.Retrofit;
-public class ViewImgurMediaActivity extends AppCompatActivity {
+public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWallpaperCallback {
public static final String EXTRA_IMGUR_TYPE = "EIT";
public static final String EXTRA_IMGUR_ID = "EII";
@@ -74,6 +81,7 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
@Inject
@Named("default")
SharedPreferences sharedPreferences;
+ private WallpaperSetter wallpaperSetter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -92,6 +100,15 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
getTheme().applyStyle(ContentFontStyle.valueOf(sharedPreferences
.getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true);
+ getTheme().applyStyle(FontFamily.valueOf(sharedPreferences
+ .getString(SharedPreferencesUtils.FONT_FAMILY_KEY, FontFamily.Default.name())).getResId(), true);
+
+ getTheme().applyStyle(TitleFontFamily.valueOf(sharedPreferences
+ .getString(SharedPreferencesUtils.TITLE_FONT_FAMILY_KEY, TitleFontFamily.Default.name())).getResId(), true);
+
+ getTheme().applyStyle(ContentFontFamily.valueOf(sharedPreferences
+ .getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true);
+
setContentView(R.layout.activity_view_imgur_media);
ButterKnife.bind(this);
@@ -101,6 +118,8 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
actionBar.setHomeAsUpIndicator(upArrow);
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
+ wallpaperSetter = new WallpaperSetter();
+
setTitle(" ");
String imgurId = getIntent().getStringExtra(EXTRA_IMGUR_ID);
@@ -113,7 +132,11 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
images = savedInstanceState.getParcelableArrayList(IMGUR_IMAGES_STATE);
}
- haulerView.setOnDragDismissedListener(dragDirection -> finish());
+ haulerView.setOnDragDismissedListener(dragDirection -> {
+ int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down;
+ finish();
+ overridePendingTransition(0, slide);
+ });
if (images == null) {
fetchImgurMedia(imgurId);
@@ -122,9 +145,7 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
setupViewPager();
}
- errorLinearLayout.setOnClickListener(view -> {
- fetchImgurMedia(imgurId);
- });
+ errorLinearLayout.setOnClickListener(view -> fetchImgurMedia(imgurId));
}
private void fetchImgurMedia(String imgurId) {
@@ -240,30 +261,22 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
private void setupViewPager() {
setToolbarTitle(0);
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
- viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
-
- }
-
+ viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
setToolbarTitle(position);
}
-
- @Override
- public void onPageScrollStateChanged(int state) {
-
- }
});
viewPager.setAdapter(sectionsPagerAdapter);
}
private void setToolbarTitle(int position) {
- if (images.get(position).getType() == ImgurMedia.TYPE_VIDEO) {
- setTitle(getString(R.string.view_imgur_media_activity_video_label, position + 1, images.size()));
- } else {
- setTitle(getString(R.string.view_imgur_media_activity_image_label, position + 1, images.size()));
+ if (images != null && position >= 0 && position < images.size()) {
+ if (images.get(position).getType() == ImgurMedia.TYPE_VIDEO) {
+ setTitle(getString(R.string.view_imgur_media_activity_video_label, position + 1, images.size()));
+ } else {
+ setTitle(getString(R.string.view_imgur_media_activity_image_label, position + 1, images.size()));
+ }
}
}
@@ -288,6 +301,64 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
outState.putParcelableArrayList(IMGUR_IMAGES_STATE, images);
}
+ @Override
+ public void setToHomeScreen(int viewPagerPosition) {
+ if (images != null && viewPagerPosition >= 0 && viewPagerPosition < images.size()) {
+ WallpaperSetter.set(images.get(viewPagerPosition).getLink(), WallpaperSetter.HOME_SCREEN, this,
+ new WallpaperSetter.SetWallpaperListener() {
+ @Override
+ public void success() {
+ Toast.makeText(ViewImgurMediaActivity.this, R.string.wallpaper_set, Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void failed() {
+ Toast.makeText(ViewImgurMediaActivity.this, R.string.error_set_wallpaper, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+ }
+
+ @Override
+ public void setToLockScreen(int viewPagerPosition) {
+ if (images != null && viewPagerPosition >= 0 && viewPagerPosition < images.size()) {
+ WallpaperSetter.set(images.get(viewPagerPosition).getLink(), WallpaperSetter.LOCK_SCREEN, this,
+ new WallpaperSetter.SetWallpaperListener() {
+ @Override
+ public void success() {
+ Toast.makeText(ViewImgurMediaActivity.this, R.string.wallpaper_set, Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void failed() {
+ Toast.makeText(ViewImgurMediaActivity.this, R.string.error_set_wallpaper, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+ }
+
+ @Override
+ public void setToBoth(int viewPagerPosition) {
+ if (images != null && viewPagerPosition >= 0 && viewPagerPosition < images.size()) {
+ WallpaperSetter.set(images.get(viewPagerPosition).getLink(), WallpaperSetter.BOTH_SCREENS, this,
+ new WallpaperSetter.SetWallpaperListener() {
+ @Override
+ public void success() {
+ Toast.makeText(ViewImgurMediaActivity.this, R.string.wallpaper_set, Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void failed() {
+ Toast.makeText(ViewImgurMediaActivity.this, R.string.error_set_wallpaper, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+ }
+
+ public int getCurrentPagePosition() {
+ return viewPager.getCurrentItem();
+ }
+
private class SectionsPagerAdapter extends FragmentStatePagerAdapter {
SectionsPagerAdapter(@NonNull FragmentManager fm) {
@@ -328,6 +399,7 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
interface ParseImgurImagesAsyncTaskListener {
void success(ArrayList<ImgurMedia> images);
+
void failed();
}
@@ -382,6 +454,7 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
interface ParseImgurImageAsyncTaskListener {
void success(ImgurMedia image);
+
void failed();
}
@@ -422,4 +495,4 @@ public class ViewImgurMediaActivity extends AppCompatActivity {
}
}
}
-} \ No newline at end of file
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java
index a71cf47b..5e7446bc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java
@@ -26,6 +26,7 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
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;
@@ -47,6 +48,7 @@ import ml.docilealligator.infinityforreddit.MessageViewModel;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class ViewMessageActivity extends BaseActivity implements ActivityToolbarInterface {
@@ -107,6 +109,10 @@ public class ViewMessageActivity extends BaseActivity implements ActivityToolbar
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
mGlide = Glide.with(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
index a87a200a..1317e133 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
@@ -18,6 +18,7 @@ import androidx.fragment.app.Fragment;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
+import com.r0adkll.slidr.Slidr;
import org.greenrobot.eventbus.EventBus;
@@ -28,12 +29,12 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
-import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
-import ml.docilealligator.infinityforreddit.Event.RefreshMultiRedditsEvent;
-import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostLayoutBottomSheetFragment;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTimeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTypeBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.Event.RefreshMultiRedditsEvent;
+import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.MultiReddit.DeleteMultiReddit;
@@ -108,6 +109,10 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
@@ -301,8 +306,8 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
public void sortTypeSelected(SortType sortType) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiPath,
sortType.getType().name()).apply();
- if(sortType.getTime() != null) {
- mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE+ multiPath,
+ if (sortType.getTime() != null) {
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiPath,
sortType.getTime().name()).apply();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
index 51a5beaa..81e1ba8a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
@@ -60,6 +60,8 @@ import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.CommentAndPostRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.FlairBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostCommentSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.CommentData;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer;
@@ -71,9 +73,9 @@ import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivit
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.FetchComment;
+import ml.docilealligator.infinityforreddit.FetchRemovedComment;
+import ml.docilealligator.infinityforreddit.FetchRemovedPost;
import ml.docilealligator.infinityforreddit.Flair;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.FlairBottomSheetFragment;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostCommentSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.ParseComment;
import ml.docilealligator.infinityforreddit.Post.FetchPost;
@@ -161,6 +163,9 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
@Named("no_oauth")
Retrofit mRetrofit;
@Inject
+ @Named("pushshift")
+ Retrofit pushshiftRetrofit;
+ @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
@@ -449,63 +454,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
if (mPost == null) {
fetchPostAndCommentsById(getIntent().getStringExtra(EXTRA_POST_ID));
} else {
- if (mMenu != null) {
- MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity);
- MenuItem hideItem = mMenu.findItem(R.id.action_hide_view_post_detail_activity);
-
- mMenu.findItem(R.id.action_comment_view_post_detail_activity).setVisible(true);
- mMenu.findItem(R.id.action_sort_view_post_detail_activity).setVisible(true);
-
- if (mAccessToken != null) {
- if (mPost.isSaved()) {
- saveItem.setVisible(true);
- saveItem.setIcon(mSavedIcon);
- } else {
- saveItem.setVisible(true);
- saveItem.setIcon(mUnsavedIcon);
- }
-
- if (mPost.isHidden()) {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_unhide_post);
- } else {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_hide_post);
- }
-
- mMenu.findItem(R.id.action_report_view_post_detail_activity).setVisible(true);
- } else {
- saveItem.setVisible(false);
- hideItem.setVisible(false);
- }
-
- if (mPost.getAuthor().equals(mAccountName)) {
- if (mPost.getPostType() == Post.TEXT_TYPE) {
- mMenu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true);
- }
- mMenu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true);
-
- MenuItem nsfwItem = mMenu.findItem(R.id.action_nsfw_view_post_detail_activity);
- nsfwItem.setVisible(true);
- if (mPost.isNSFW()) {
- nsfwItem.setTitle(R.string.action_unmark_nsfw);
- } else {
- nsfwItem.setTitle(R.string.action_mark_nsfw);
- }
-
- MenuItem spoilerItem = mMenu.findItem(R.id.action_spoiler_view_post_detail_activity);
- spoilerItem.setVisible(true);
- if (mPost.isSpoiler()) {
- spoilerItem.setTitle(R.string.action_unmark_spoiler);
- } else {
- spoilerItem.setTitle(R.string.action_mark_spoiler);
- }
-
- mMenu.findItem(R.id.action_edit_flair_view_post_detail_activity).setVisible(true);
- }
-
- mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null);
- }
+ setupMenu();
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this,
mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide,
@@ -559,6 +508,73 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
fab.setOnClickListener(view -> scrollToNextParentComment());
}
+ private void setupMenu() {
+ if (mMenu != null) {
+ MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity);
+ MenuItem hideItem = mMenu.findItem(R.id.action_hide_view_post_detail_activity);
+
+ mMenu.findItem(R.id.action_comment_view_post_detail_activity).setVisible(true);
+ mMenu.findItem(R.id.action_sort_view_post_detail_activity).setVisible(true);
+
+ if (mAccessToken != null) {
+ if (mPost.isSaved()) {
+ saveItem.setVisible(true);
+ saveItem.setIcon(mSavedIcon);
+ } else {
+ saveItem.setVisible(true);
+ saveItem.setIcon(mUnsavedIcon);
+ }
+
+ if (mPost.isHidden()) {
+ hideItem.setVisible(true);
+ hideItem.setTitle(R.string.action_unhide_post);
+ } else {
+ hideItem.setVisible(true);
+ hideItem.setTitle(R.string.action_hide_post);
+ }
+
+ mMenu.findItem(R.id.action_report_view_post_detail_activity).setVisible(true);
+ } else {
+ saveItem.setVisible(false);
+ hideItem.setVisible(false);
+ }
+
+ if (mPost.getAuthor().equals(mAccountName)) {
+ if (mPost.getPostType() == Post.TEXT_TYPE) {
+ mMenu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true);
+ }
+ mMenu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true);
+
+ MenuItem nsfwItem = mMenu.findItem(R.id.action_nsfw_view_post_detail_activity);
+ nsfwItem.setVisible(true);
+ if (mPost.isNSFW()) {
+ nsfwItem.setTitle(R.string.action_unmark_nsfw);
+ } else {
+ nsfwItem.setTitle(R.string.action_mark_nsfw);
+ }
+
+ MenuItem spoilerItem = mMenu.findItem(R.id.action_spoiler_view_post_detail_activity);
+ spoilerItem.setVisible(true);
+ if (mPost.isSpoiler()) {
+ spoilerItem.setTitle(R.string.action_unmark_spoiler);
+ } else {
+ spoilerItem.setTitle(R.string.action_mark_spoiler);
+ }
+
+ mMenu.findItem(R.id.action_edit_flair_view_post_detail_activity).setVisible(true);
+ }
+
+ mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null);
+
+ if ("[deleted]".equals(mPost.getAuthor()) ||
+ "[deleted]".equals(mPost.getSelfText()) ||
+ "[removed]".equals(mPost.getSelfText())
+ ) {
+ mMenu.findItem(R.id.action_see_removed_view_post_detail_activity).setVisible(true);
+ }
+ }
+ }
+
private Drawable getMenuItemIcon(int drawableId) {
Drawable icon = getDrawable(drawableId);
if (icon != null) {
@@ -602,45 +618,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
public void onParsePostSuccess(Post post) {
mPost = post;
- if (mMenu != null) {
- MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity);
- MenuItem hideItem = mMenu.findItem(R.id.action_hide_view_post_detail_activity);
-
- mMenu.findItem(R.id.action_comment_view_post_detail_activity).setVisible(true);
- mMenu.findItem(R.id.action_sort_view_post_detail_activity).setVisible(true);
-
- if (mAccessToken != null) {
- if (post.isSaved()) {
- saveItem.setVisible(true);
- saveItem.setIcon(mSavedIcon);
- } else {
- saveItem.setVisible(true);
- saveItem.setIcon(mUnsavedIcon);
- }
-
- if (post.isHidden()) {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_unhide_post);
- } else {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_hide_post);
- }
-
- mMenu.findItem(R.id.action_report_view_post_detail_activity).setVisible(true);
- } else {
- saveItem.setVisible(false);
- hideItem.setVisible(false);
- }
-
- if (mPost.getAuthor().equals(mAccountName)) {
- if (mPost.getPostType() == Post.TEXT_TYPE) {
- mMenu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true);
- }
- mMenu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true);
- }
-
- mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null);
- }
+ setupMenu();
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this,
mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide,
@@ -910,38 +888,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mAdapter.updatePost(mPost);
EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition));
isRefreshing = false;
- if (mMenu != null) {
- MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity);
- MenuItem hideItem = mMenu.findItem(R.id.action_hide_view_post_detail_activity);
-
- mMenu.findItem(R.id.action_comment_view_post_detail_activity).setVisible(true);
- mMenu.findItem(R.id.action_sort_view_post_detail_activity).setVisible(true);
-
- if (mAccessToken != null) {
- if (post.isSaved()) {
- saveItem.setVisible(true);
- saveItem.setIcon(mSavedIcon);
- } else {
- saveItem.setVisible(true);
- saveItem.setIcon(mUnsavedIcon);
- }
-
- if (post.isHidden()) {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_unhide_post);
- } else {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_hide_post);
- }
-
- mMenu.findItem(R.id.action_report_view_post_detail_activity).setVisible(true);
- } else {
- saveItem.setVisible(false);
- hideItem.setVisible(false);
- }
-
- mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null);
- }
+ setupMenu();
mSwipeRefreshLayout.setRefreshing(false);
}
@@ -1144,6 +1091,24 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
.show();
}
+ public void showRemovedComment(CommentData comment, int position) {
+ Toast.makeText(ViewPostDetailActivity.this, R.string.fetching_removed_comment, Toast.LENGTH_SHORT).show();
+ FetchRemovedComment.fetchRemovedComment(
+ pushshiftRetrofit,
+ comment,
+ new FetchRemovedComment.FetchRemovedCommentListener() {
+ @Override
+ public void fetchSuccess(CommentData comment) {
+ mAdapter.editComment(comment.getAuthor(), comment.getCommentMarkdown(), position);
+ }
+
+ @Override
+ public void fetchFailed() {
+ Toast.makeText(ViewPostDetailActivity.this, R.string.show_removed_comment_failed, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
public void changeToSingleThreadMode() {
isSingleCommentThreadMode = false;
mSingleCommentId = null;
@@ -1257,65 +1222,30 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
applyMenuItemTheme(menu);
mMenu = menu;
if (mPost != null) {
- MenuItem saveItem = mMenu.findItem(R.id.action_save_view_post_detail_activity);
- MenuItem hideItem = mMenu.findItem(R.id.action_hide_view_post_detail_activity);
-
- mMenu.findItem(R.id.action_comment_view_post_detail_activity).setVisible(true);
- mMenu.findItem(R.id.action_sort_view_post_detail_activity).setVisible(true);
-
- if (mAccessToken != null) {
- if (mPost.isSaved()) {
- saveItem.setVisible(true);
- saveItem.setIcon(mSavedIcon);
- } else {
- saveItem.setVisible(true);
- saveItem.setIcon(mUnsavedIcon);
- }
-
- if (mPost.isHidden()) {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_unhide_post);
- } else {
- hideItem.setVisible(true);
- hideItem.setTitle(R.string.action_hide_post);
- }
-
- mMenu.findItem(R.id.action_report_view_post_detail_activity).setVisible(true);
- } else {
- saveItem.setVisible(false);
- hideItem.setVisible(false);
- }
-
- if (mPost.getAuthor().equals(mAccountName)) {
- if (mPost.getPostType() == Post.TEXT_TYPE) {
- menu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true);
- }
- menu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true);
-
- MenuItem nsfwItem = menu.findItem(R.id.action_nsfw_view_post_detail_activity);
- nsfwItem.setVisible(true);
- if (mPost.isNSFW()) {
- nsfwItem.setTitle(R.string.action_unmark_nsfw);
- } else {
- nsfwItem.setTitle(R.string.action_mark_nsfw);
- }
-
- MenuItem spoilerItem = menu.findItem(R.id.action_spoiler_view_post_detail_activity);
- spoilerItem.setVisible(true);
- if (mPost.isSpoiler()) {
- spoilerItem.setTitle(R.string.action_unmark_spoiler);
- } else {
- spoilerItem.setTitle(R.string.action_mark_spoiler);
- }
-
- menu.findItem(R.id.action_edit_flair_view_post_detail_activity).setVisible(true);
- }
-
- menu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null);
+ setupMenu();
}
return true;
}
+ public void showRemovedPost() {
+ Toast.makeText(ViewPostDetailActivity.this, R.string.fetching_removed_post, Toast.LENGTH_SHORT).show();
+ FetchRemovedPost.fetchRemovedPost(
+ pushshiftRetrofit,
+ mPost,
+ new FetchRemovedPost.FetchRemovedPostListener() {
+ @Override
+ public void fetchSuccess(Post post) {
+ mPost = post;
+ mAdapter.updatePost(post);
+ }
+
+ @Override
+ public void fetchFailed() {
+ Toast.makeText(ViewPostDetailActivity.this, R.string.show_removed_post_failed, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
@@ -1450,12 +1380,12 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
return true;
case R.id.action_edit_view_post_detail_activity:
- Intent editPostItent = new Intent(this, EditPostActivity.class);
- editPostItent.putExtra(EditPostActivity.EXTRA_ACCESS_TOKEN, mAccessToken);
- editPostItent.putExtra(EditPostActivity.EXTRA_FULLNAME, mPost.getFullName());
- editPostItent.putExtra(EditPostActivity.EXTRA_TITLE, mPost.getTitle());
- editPostItent.putExtra(EditPostActivity.EXTRA_CONTENT, mPost.getSelfText());
- startActivityForResult(editPostItent, EDIT_POST_REQUEST_CODE);
+ Intent editPostIntent = new Intent(this, EditPostActivity.class);
+ editPostIntent.putExtra(EditPostActivity.EXTRA_ACCESS_TOKEN, mAccessToken);
+ editPostIntent.putExtra(EditPostActivity.EXTRA_FULLNAME, mPost.getFullName());
+ editPostIntent.putExtra(EditPostActivity.EXTRA_TITLE, mPost.getTitle());
+ editPostIntent.putExtra(EditPostActivity.EXTRA_CONTENT, mPost.getSelfText());
+ startActivityForResult(editPostIntent, EDIT_POST_REQUEST_CODE);
return true;
case R.id.action_delete_view_post_detail_activity:
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
@@ -1504,6 +1434,10 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
intent.putExtra(ReportActivity.EXTRA_SUBREDDIT_NAME, mPost.getSubredditName());
intent.putExtra(ReportActivity.EXTRA_THING_FULLNAME, mPost.getFullName());
startActivity(intent);
+ return true;
+ case R.id.action_see_removed_view_post_detail_activity:
+ showRemovedPost();
+ return true;
case android.R.id.home:
onBackPressed();
return true;
@@ -1537,7 +1471,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
} else if (requestCode == EDIT_COMMENT_REQUEST_CODE) {
if (data != null && resultCode == RESULT_OK) {
- mAdapter.editComment(data.getStringExtra(EditCommentActivity.EXTRA_EDITED_COMMENT_CONTENT),
+ mAdapter.editComment(null,
+ data.getStringExtra(EditCommentActivity.EXTRA_EDITED_COMMENT_CONTENT),
data.getExtras().getInt(EditCommentActivity.EXTRA_EDITED_COMMENT_POSITION));
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java
deleted file mode 100644
index 826ba33d..00000000
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java
+++ /dev/null
@@ -1,251 +0,0 @@
-package ml.docilealligator.infinityforreddit.Activity;
-
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.text.Spanned;
-import android.text.style.SuperscriptSpan;
-import android.text.util.Linkify;
-import android.util.TypedValue;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.Window;
-import android.view.WindowManager;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-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;
-
-import com.google.android.material.appbar.AppBarLayout;
-
-import org.commonmark.ext.gfm.tables.TableBlock;
-
-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.ext.strikethrough.StrikethroughPlugin;
-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 io.noties.markwon.simple.ext.SimpleExtPlugin;
-import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
-import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
-import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTask;
-import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
-import ml.docilealligator.infinityforreddit.FetchSubredditData;
-import ml.docilealligator.infinityforreddit.Infinity;
-import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
-import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
-import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
-import retrofit2.Retrofit;
-
-public class ViewSidebarActivity extends BaseActivity implements ActivityToolbarInterface {
-
- public static final String EXTRA_SUBREDDIT_NAME = "ESN";
- @BindView(R.id.coordinator_layout_view_sidebar_activity)
- CoordinatorLayout coordinatorLayout;
- @BindView(R.id.appbar_layout_view_sidebar_activity)
- AppBarLayout appBarLayout;
- @BindView(R.id.toolbar_view_sidebar_activity)
- Toolbar toolbar;
- @BindView(R.id.swipe_refresh_layout_view_sidebar_activity)
- SwipeRefreshLayout swipeRefreshLayout;
- @BindView(R.id.markdown_recycler_view_view_sidebar_activity)
- RecyclerView markdownRecyclerView;
- @Inject
- @Named("no_oauth")
- Retrofit mRetrofit;
- @Inject
- RedditDataRoomDatabase mRedditDataRoomDatabase;
- @Inject
- @Named("default")
- SharedPreferences mSharedPreferences;
- @Inject
- CustomThemeWrapper mCustomThemeWrapper;
- public SubredditViewModel mSubredditViewModel;
- private LinearLayoutManager mLinearLayoutManager;
- private String subredditName;
- private int markdownColor;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- ((Infinity) getApplication()).getAppComponent().inject(this);
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_view_sidebar);
-
- ButterKnife.bind(this);
-
- applyCustomTheme();
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- Window window = getWindow();
-
- if (isChangeStatusBarIconColor()) {
- addOnOffsetChangedListener(appBarLayout);
- }
-
- if (isImmersiveInterface()) {
- window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
- adjustToolbar(toolbar);
-
- int navBarHeight = getNavBarHeight();
- if (navBarHeight > 0) {
- int px = (int) TypedValue.applyDimension(
- TypedValue.COMPLEX_UNIT_DIP,
- 16,
- getResources().getDisplayMetrics()
- );
- markdownRecyclerView.setPadding(px, px, px, navBarHeight);
- }
- }
- }
-
- subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
- if (subredditName == null) {
- Toast.makeText(this, R.string.error_getting_subreddit_name, Toast.LENGTH_SHORT).show();
- finish();
- return;
- }
-
- toolbar.setTitle("r/" + subredditName);
- setSupportActionBar(toolbar);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- setToolbarGoToTop(toolbar);
-
- Markwon markwon = Markwon.builder(this)
- .usePlugin(new AbstractMarkwonPlugin() {
- @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(ViewSidebarActivity.this, LinkResolverActivity.class);
- Uri uri = Uri.parse(link);
- if (uri.getScheme() == null && uri.getHost() == null) {
- intent.setData(LinkResolverActivity.getRedditUriByPath(link));
- } else {
- intent.setData(uri);
- }
- ViewSidebarActivity.this.startActivity(intent);
- }).urlProcessor(new UrlProcessorRelativeToAbsolute("https://www.reddit.com"));
- }
- })
- .usePlugin(StrikethroughPlugin.create())
- .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
- .usePlugin(SimpleExtPlugin.create(plugin ->
- plugin.addExtension(1, '^', (configuration, props) -> {
- return new SuperscriptSpan();
- })
- )
- )
- .usePlugin(TableEntryPlugin.create(this))
- .build();
- MarkwonAdapter 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();
-
- mLinearLayoutManager = new LinearLayoutManager(this);
- markdownRecyclerView.setLayoutManager(mLinearLayoutManager);
- markdownRecyclerView.setAdapter(markwonAdapter);
-
- mSubredditViewModel = new ViewModelProvider(this,
- new SubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, subredditName))
- .get(SubredditViewModel.class);
- mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> {
- if (subredditData != null) {
- if (subredditData.getSidebarDescription() != null && !subredditData.getSidebarDescription().equals("")) {
- markwonAdapter.setMarkdown(markwon, subredditData.getSidebarDescription());
- markwonAdapter.notifyDataSetChanged();
- }
- } else {
- fetchSubredditData();
- }
- });
-
- swipeRefreshLayout.setOnRefreshListener(this::fetchSubredditData);
- }
-
- private void fetchSubredditData() {
- swipeRefreshLayout.setRefreshing(true);
- FetchSubredditData.fetchSubredditData(mRetrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() {
- @Override
- public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
- swipeRefreshLayout.setRefreshing(false);
- new InsertSubredditDataAsyncTask(mRedditDataRoomDatabase, subredditData, () -> swipeRefreshLayout.setRefreshing(false)).execute();
- }
-
- @Override
- public void onFetchSubredditDataFail() {
- swipeRefreshLayout.setRefreshing(false);
- Toast.makeText(ViewSidebarActivity.this, R.string.cannot_fetch_sidebar, Toast.LENGTH_SHORT).show();
- }
- });
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.view_sidebar_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_view_sidebar_activity) {
- if (!swipeRefreshLayout.isRefreshing()) {
- fetchSubredditData();
- }
- return true;
- }
- return false;
- }
-
- @Override
- public SharedPreferences getSharedPreferences() {
- 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());
- markdownColor = mCustomThemeWrapper.getSecondaryTextColor();
- }
-
- @Override
- public void onLongPress() {
- if (mLinearLayoutManager != null) {
- mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
- }
- }
-}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
index 0ec10e46..6f122bee 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
@@ -37,6 +37,8 @@ import com.google.android.material.chip.Chip;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;
+import com.r0adkll.slidr.Slidr;
+import com.r0adkll.slidr.model.SlidrInterface;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -56,17 +58,17 @@ import ml.docilealligator.infinityforreddit.AsyncTask.CheckIsSubscribedToSubredd
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostLayoutBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostTypeBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTimeBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.Event.GoBackToMainPageEvent;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostLayoutBottomSheetFragment;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SidebarFragment;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTimeBottomSheetFragment;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.Post.PostDataSource;
@@ -90,6 +92,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
public static final String EXTRA_SUBREDDIT_NAME_KEY = "ESN";
public static final String EXTRA_MESSAGE_FULLNAME = "ENF";
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
+ public static final String EXTRA_VIEW_SIDEBAR = "EVSB";
private static final String FETCH_SUBREDDIT_INFO_STATE = "FSIS";
private static final String CURRENT_ONLINE_SUBSCRIBERS_STATE = "COSS";
@@ -195,6 +198,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private int collapsedTabIndicatorColor;
private int unsubscribedColor;
private int subscribedColor;
+ private SlidrInterface mSlidrInterface;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -211,6 +215,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ mSlidrInterface = Slidr.attach(this);
+ }
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
if (isImmersiveInterface()) {
@@ -348,9 +356,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
} else {
glide.load(subredditData.getBannerUrl()).into(bannerImageView);
bannerImageView.setOnClickListener(view -> {
- Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageActivity.class);
- intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, subredditData.getBannerUrl());
- intent.putExtra(ViewImageActivity.FILE_NAME_KEY, subredditName + "-banner.jpg");
+ Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.IMAGE_URL_KEY, subredditData.getBannerUrl());
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, subredditName + "-banner.jpg");
startActivity(intent);
});
}
@@ -369,9 +377,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0))))
.into(iconGifImageView);
iconGifImageView.setOnClickListener(view -> {
- Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageActivity.class);
- intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, subredditData.getIconUrl());
- intent.putExtra(ViewImageActivity.FILE_NAME_KEY, subredditName + "-icon.jpg");
+ Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.IMAGE_URL_KEY, subredditData.getIconUrl());
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, subredditName + "-icon.jpg");
startActivity(intent);
});
}
@@ -623,16 +631,27 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}).execute();
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
+ viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
+ @Override
+ public void onPageSelected(int position) {
+ if (position == 0) {
+ unlockSwipeRightToGoBack();
+ } else {
+ lockSwipeRightToGoBack();
+ }
+ }
+ });
viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOffscreenPageLimit(2);
tabLayout.setupWithViewPager(viewPager);
- viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- }
+ boolean viewSidebar = getIntent().getBooleanExtra(EXTRA_VIEW_SIDEBAR, false);
+ if (viewSidebar) {
+ viewPager.setCurrentItem(1, false);
+ }
+ viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
if (mAccessToken != null) {
@@ -651,11 +670,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
sectionsPagerAdapter.displaySortTypeInToolbar();
}
-
- @Override
- public void onPageScrollStateChanged(int state) {
-
- }
});
}
@@ -701,34 +715,31 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
fetchSubredditData();
return true;
case R.id.action_lazy_mode_view_subreddit_detail_activity:
- MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity);
- if (isInLazyMode) {
- isInLazyMode = false;
- sectionsPagerAdapter.stopLazyMode();
- lazyModeItem.setTitle(R.string.action_start_lazy_mode);
- params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS |
- AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED);
- collapsingToolbarLayout.setLayoutParams(params);
- } else {
- isInLazyMode = true;
- if (sectionsPagerAdapter.startLazyMode()) {
- lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
- appBarLayout.setExpanded(false);
- params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
+ if (sectionsPagerAdapter != null) {
+ MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity);
+ if (isInLazyMode) {
+ isInLazyMode = false;
+ sectionsPagerAdapter.stopLazyMode();
+ lazyModeItem.setTitle(R.string.action_start_lazy_mode);
+ params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS |
+ AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED);
collapsingToolbarLayout.setLayoutParams(params);
} else {
- isInLazyMode = false;
+ isInLazyMode = true;
+ if (sectionsPagerAdapter.startLazyMode()) {
+ lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
+ appBarLayout.setExpanded(false);
+ params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
+ collapsingToolbarLayout.setLayoutParams(params);
+ } else {
+ isInLazyMode = false;
+ }
}
}
return true;
case R.id.action_change_post_layout_view_subreddit_detail_activity:
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
- case R.id.action_view_side_bar_view_subreddit_detail_activity:
- Intent sidebarIntent = new Intent(this, ViewSidebarActivity.class);
- sidebarIntent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, subredditName);
- startActivity(sidebarIntent);
- return true;
case R.id.action_share_view_subreddit_detail_activity:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
@@ -777,7 +788,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
@Override
public void sortTypeSelected(SortType sortType) {
- sectionsPagerAdapter.changeSortType(sortType);
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.changeSortType(sortType);
+ }
}
@Override
@@ -976,7 +989,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
public void changeSortType(SortType sortType) {
if (postFragment != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().name()).apply();
- if(sortType.getTime() != null) {
+ if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply();
}
@@ -1019,4 +1032,16 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
}
}
+
+ private void lockSwipeRightToGoBack() {
+ if (mSlidrInterface != null) {
+ mSlidrInterface.lock();
+ }
+ }
+
+ private void unlockSwipeRightToGoBack() {
+ if (mSlidrInterface != null) {
+ mSlidrInterface.unlock();
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
index a72c7389..c3d4c345 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
@@ -36,6 +36,8 @@ import com.google.android.material.chip.Chip;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;
+import com.r0adkll.slidr.Slidr;
+import com.r0adkll.slidr.model.SlidrInterface;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -171,6 +173,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
private boolean showToast = false;
private String mMessageFullname;
private String mNewAccountName;
+ private SlidrInterface mSlidrInterface;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -187,6 +190,10 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
applyCustomTheme();
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ mSlidrInterface = Slidr.attach(this);
+ }
+
username = getIntent().getStringExtra(EXTRA_USER_NAME_KEY);
if (savedInstanceState == null) {
@@ -295,9 +302,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
} else {
glide.load(userData.getBanner()).into(bannerImageView);
bannerImageView.setOnClickListener(view -> {
- Intent intent = new Intent(this, ViewImageActivity.class);
- intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, userData.getBanner());
- intent.putExtra(ViewImageActivity.FILE_NAME_KEY, username + "-banner.jpg");
+ Intent intent = new Intent(this, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.IMAGE_URL_KEY, userData.getBanner());
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, username + "-banner.jpg");
startActivity(intent);
});
}
@@ -315,9 +322,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
.into(iconGifImageView);
iconGifImageView.setOnClickListener(view -> {
- Intent intent = new Intent(this, ViewImageActivity.class);
- intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, userData.getIconUrl());
- intent.putExtra(ViewImageActivity.FILE_NAME_KEY, username + "-icon.jpg");
+ Intent intent = new Intent(this, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.IMAGE_URL_KEY, userData.getIconUrl());
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, username + "-icon.jpg");
startActivity(intent);
});
}
@@ -496,12 +503,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
viewPager.setOffscreenPageLimit(2);
tabLayout.setupWithViewPager(viewPager);
- viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
-
- }
-
+ viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
if (isInLazyMode) {
@@ -511,13 +513,13 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
sectionsPagerAdapter.pauseLazyMode();
}
}
+ if (position == 0) {
+ unlockSwipeRightToGoBack();
+ } else {
+ lockSwipeRightToGoBack();
+ }
sectionsPagerAdapter.displaySortTypeInToolbar();
}
-
- @Override
- public void onPageScrollStateChanged(int state) {
-
- }
});
if (mAccessToken != null && mMessageFullname != null) {
@@ -926,4 +928,16 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
}
}
}
+
+ private void lockSwipeRightToGoBack() {
+ if (mSlidrInterface != null) {
+ mSlidrInterface.lock();
+ }
+ }
+
+ private void unlockSwipeRightToGoBack() {
+ if (mSlidrInterface != null) {
+ mSlidrInterface.unlock();
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
index 0bd5f7fc..3db53108 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
@@ -1,8 +1,6 @@
package ml.docilealligator.infinityforreddit.Activity;
import android.Manifest;
-import android.app.DownloadManager;
-import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
@@ -13,7 +11,6 @@ import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
-import android.os.Environment;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
@@ -27,6 +24,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@@ -47,17 +45,22 @@ import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
+import com.google.android.material.snackbar.Snackbar;
+import com.thefuntasty.hauler.DragDirection;
import com.thefuntasty.hauler.HaulerView;
-import java.io.File;
-
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
-import ml.docilealligator.infinityforreddit.FetchGfycatVideoLinks;
+import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks;
+import ml.docilealligator.infinityforreddit.Font.ContentFontFamily;
+import ml.docilealligator.infinityforreddit.Font.FontFamily;
+import ml.docilealligator.infinityforreddit.Font.TitleFontFamily;
import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.MediaDownloader;
+import ml.docilealligator.infinityforreddit.MediaDownloaderImpl;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Service.DownloadRedditVideoService;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
@@ -82,6 +85,8 @@ public class ViewVideoActivity extends AppCompatActivity {
private static final String VIDEO_URI_STATE = "VUS";
@BindView(R.id.hauler_view_view_video_activity)
HaulerView haulerView;
+ @BindView(R.id.coordinator_layout_view_video_activity)
+ CoordinatorLayout coordinatorLayout;
@BindView(R.id.progress_bar_view_video_activity)
ProgressBar progressBar;
@BindView(R.id.player_view_view_video_activity)
@@ -92,6 +97,7 @@ public class ViewVideoActivity extends AppCompatActivity {
private Uri mVideoUri;
private SimpleExoPlayer player;
private DataSource.Factory dataSourceFactory;
+ private MediaDownloader mediaDownloader;
private String videoDownloadUrl;
private String videoFileName;
@@ -119,11 +125,21 @@ public class ViewVideoActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
getTheme().applyStyle(R.style.Theme_Normal, true);
- setContentView(R.layout.activity_view_video);
+ getTheme().applyStyle(FontFamily.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.FONT_FAMILY_KEY, FontFamily.Default.name())).getResId(), true);
- ((Infinity) getApplication()).getAppComponent().inject(this);
+ getTheme().applyStyle(TitleFontFamily.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.TITLE_FONT_FAMILY_KEY, TitleFontFamily.Default.name())).getResId(), true);
+
+ getTheme().applyStyle(ContentFontFamily.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true);
+
+ setContentView(R.layout.activity_view_video);
ButterKnife.bind(this);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
@@ -147,7 +163,13 @@ public class ViewVideoActivity extends AppCompatActivity {
params.rightMargin = getResources().getDimensionPixelSize(resourceId);
}
- haulerView.setOnDragDismissedListener(dragDirection -> finish());
+ haulerView.setOnDragDismissedListener(dragDirection -> {
+ int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down;
+ finish();
+ overridePendingTransition(0, slide);
+ });
+
+ mediaDownloader = new MediaDownloaderImpl();
Intent intent = getIntent();
mVideoUri = intent.getData();
@@ -196,42 +218,17 @@ public class ViewVideoActivity extends AppCompatActivity {
}
if (mVideoUri == null) {
- progressBar.setVisibility(View.VISIBLE);
String gfycatId = intent.getStringExtra(EXTRA_GFYCAT_ID);
if (gfycatId != null && gfycatId.contains("-")) {
gfycatId = gfycatId.substring(0, gfycatId.indexOf('-'));
}
- Retrofit retrofit;
if (videoType == VIDEO_TYPE_GFYCAT) {
- retrofit = gfycatRetrofit;
videoFileName = "Gfycat-" + gfycatId + ".mp4";
+ loadGfycatOrRedgifsVideo(gfycatRetrofit, gfycatId, savedInstanceState, true);
} else {
- retrofit = redgifsRetrofit;
videoFileName = "Redgifs-" + gfycatId + ".mp4";
+ loadGfycatOrRedgifsVideo(redgifsRetrofit, gfycatId, savedInstanceState, false);
}
- FetchGfycatVideoLinks.fetchGfycatVideoLinks(retrofit, gfycatId,
- new FetchGfycatVideoLinks.FetchGfycatVideoLinksListener() {
- @Override
- public void success(String webm, String mp4) {
- progressBar.setVisibility(View.GONE);
- mVideoUri = Uri.parse(webm);
- videoDownloadUrl = mp4;
- dataSourceFactory = new DefaultDataSourceFactory(ViewVideoActivity.this,
- Util.getUserAgent(ViewVideoActivity.this, "Infinity"));
- player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri));
- preparePlayer(savedInstanceState);
- }
-
- @Override
- public void failed() {
- progressBar.setVisibility(View.GONE);
- if (videoType == VIDEO_TYPE_GFYCAT) {
- Toast.makeText(ViewVideoActivity.this, R.string.fetch_gfycat_video_failed, Toast.LENGTH_SHORT).show();
- } else {
- Toast.makeText(ViewVideoActivity.this, R.string.fetch_redgifs_video_failed, Toast.LENGTH_SHORT).show();
- }
- }
- });
} else {
dataSourceFactory = new DefaultDataSourceFactory(ViewVideoActivity.this,
Util.getUserAgent(ViewVideoActivity.this, "Infinity"));
@@ -315,6 +312,42 @@ public class ViewVideoActivity extends AppCompatActivity {
});
}
+ private void loadGfycatOrRedgifsVideo(Retrofit retrofit, String gfycatId, Bundle savedInstanceState, boolean needErrorHandling) {
+ progressBar.setVisibility(View.VISIBLE);
+ FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinks(retrofit, gfycatId,
+ new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
+ @Override
+ public void success(String webm, String mp4) {
+ progressBar.setVisibility(View.GONE);
+ mVideoUri = Uri.parse(webm);
+ videoDownloadUrl = mp4;
+ dataSourceFactory = new DefaultDataSourceFactory(ViewVideoActivity.this,
+ Util.getUserAgent(ViewVideoActivity.this, "Infinity"));
+ player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri));
+ preparePlayer(savedInstanceState);
+ }
+
+ @Override
+ public void failed(int errorCode) {
+ progressBar.setVisibility(View.GONE);
+ if (videoType == VIDEO_TYPE_GFYCAT) {
+ if (errorCode == 404 && needErrorHandling) {
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.AUTOMATICALLY_TRY_REDGIFS, true)) {
+ loadGfycatOrRedgifsVideo(redgifsRetrofit, gfycatId, savedInstanceState, false);
+ } else {
+ Snackbar.make(coordinatorLayout, R.string.load_video_in_redgifs, Snackbar.LENGTH_INDEFINITE).setAction(R.string.yes,
+ view -> loadGfycatOrRedgifsVideo(redgifsRetrofit, gfycatId, savedInstanceState, false)).show();
+ }
+ } else {
+ Toast.makeText(ViewVideoActivity.this, R.string.fetch_gfycat_video_failed, Toast.LENGTH_SHORT).show();
+ }
+ } else {
+ Toast.makeText(ViewVideoActivity.this, R.string.fetch_redgifs_video_failed, Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.view_video, menu);
@@ -394,46 +427,7 @@ public class ViewVideoActivity extends AppCompatActivity {
isDownloading = false;
if (videoType != VIDEO_TYPE_NORMAL) {
- DownloadManager.Request request = new DownloadManager.Request(Uri.parse(videoDownloadUrl));
- request.setTitle(videoFileName);
-
- request.allowScanningByMediaScanner();
- request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
-
- //Android Q support
- if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, videoFileName);
- } else {
- String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
- File directory = new File(path + "/Infinity/");
- boolean saveToInfinityFolder = true;
- if (!directory.exists()) {
- if (!directory.mkdir()) {
- saveToInfinityFolder = false;
- }
- } else {
- if (directory.isFile()) {
- if (!(directory.delete() && directory.mkdir())) {
- saveToInfinityFolder = false;
- }
- }
- }
-
- if (saveToInfinityFolder) {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + "/Infinity/", videoFileName);
- } else {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, videoFileName);
- }
- }
-
- DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
-
- if (manager == null) {
- Toast.makeText(this, R.string.download_failed, Toast.LENGTH_SHORT).show();
- return;
- }
-
- manager.enqueue(request);
+ mediaDownloader.download(videoDownloadUrl, videoFileName, this);
} else {
Intent intent = new Intent(this, DownloadRedditVideoService.class);
intent.putExtra(DownloadRedditVideoService.EXTRA_VIDEO_URL, videoDownloadUrl);
@@ -445,8 +439,8 @@ public class ViewVideoActivity extends AppCompatActivity {
} else {
startService(intent);
}
+ Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
}
- Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
index c4d65766..3689f9a8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -36,6 +36,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.DataSource;
+import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
@@ -81,8 +82,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.Activity.CommentActivity;
import ml.docilealligator.infinityforreddit.Activity.FilteredThingActivity;
import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity;
-import ml.docilealligator.infinityforreddit.Activity.ViewGIFActivity;
-import ml.docilealligator.infinityforreddit.Activity.ViewImageActivity;
+import ml.docilealligator.infinityforreddit.Activity.ViewImageOrGifActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity;
@@ -155,6 +155,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private boolean mShowAbsoluteNumberOfVotes;
private boolean mAutoplay = false;
private boolean mAutoplayNsfwVideos;
+ private boolean mMuteAutoplayingVideos;
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
private boolean isInitiallyLoading;
private boolean isInitiallyLoadingFailed;
@@ -307,7 +308,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
mCommentToolbarHidden = mSharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDDEN, false);
- mCommentToolbarHideOnClick= mSharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDE_ON_CLICK, true);
+ mCommentToolbarHideOnClick = mSharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDE_ON_CLICK, true);
mSwapTapAndLong = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWAP_TAP_AND_LONG_COMMENTS, false);
mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
mShowAbsoluteNumberOfVotes = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
@@ -319,6 +320,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mAutoplay = Utils.isConnectedToWifi(activity);
}
mAutoplayNsfwVideos = mSharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true);
+ mMuteAutoplayingVideos = mSharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS, true);
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
isInitiallyLoading = true;
@@ -934,7 +936,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((LoadMoreChildCommentsViewHolder) holder).placeholderTextView.setOnClickListener(view -> {
int commentPosition = mIsSingleCommentThreadMode ? holder.getAdapterPosition() - 2 : holder.getAdapterPosition() - 1;
int parentPosition = getParentPosition(commentPosition);
- if(parentPosition >= 0) {
+ if (parentPosition >= 0) {
CommentData parentComment = mVisibleComments.get(parentPosition);
mVisibleComments.get(commentPosition).setLoadingMoreChildren(true);
@@ -1117,7 +1119,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private void loadImage(PostDetailBaseViewHolder holder) {
if (holder instanceof PostDetailImageAndGifAutoplayViewHolder) {
String url = mAutoplay && mPost.getPostType() == Post.GIF_TYPE ? mPost.getUrl() : mPost.getPreviewUrl();
- RequestBuilder imageRequestBuilder = mGlide.load(url)
+ RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
@@ -1142,10 +1144,10 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
} else {
- imageRequestBuilder.into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
+ imageRequestBuilder.apply(RequestOptions.noTransformation()).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
}
} else if (holder instanceof PostDetailVideoAndGifPreviewHolder) {
- RequestBuilder imageRequestBuilder = mGlide.load(mPost.getPreviewUrl())
+ RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(mPost.getPreviewUrl())
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
@@ -1170,10 +1172,10 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
} else {
- imageRequestBuilder.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
+ imageRequestBuilder.apply(RequestOptions.noTransformation()).into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
}
- } else if(holder instanceof PostDetailLinkViewHolder) {
- RequestBuilder imageRequestBuilder = mGlide.load(mPost.getPreviewUrl())
+ } else if (holder instanceof PostDetailLinkViewHolder) {
+ RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(mPost.getPreviewUrl())
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
@@ -1198,7 +1200,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostDetailLinkViewHolder) holder).mImageView);
} else {
- imageRequestBuilder.into(((PostDetailLinkViewHolder) holder).mImageView);
+ imageRequestBuilder.apply(RequestOptions.noTransformation()).into(((PostDetailLinkViewHolder) holder).mImageView);
}
}
}
@@ -1385,8 +1387,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
}
- public void editComment(String commentContent, int position) {
- mVisibleComments.get(position).setCommentMarkdown(commentContent);
+ public void editComment(String commentAuthor, String commentContentMarkdown, int position) {
+ if (commentAuthor != null)
+ mVisibleComments.get(position).setAuthor(commentAuthor);
+
+ mVisibleComments.get(position).setCommentMarkdown(commentContentMarkdown);
if (mIsSingleCommentThreadMode) {
notifyItemChanged(position + 2);
} else {
@@ -2016,7 +2021,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
@Nullable
ExoPlayerViewHelper helper;
private Uri mediaUri;
- private float volume = 0f;
+ private float volume;
public PostDetailVideoAutoplayViewHolder(@NonNull View itemView) {
super(itemView);
@@ -2045,6 +2050,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
aspectRatioFrameLayout.setOnClickListener(null);
+ volume = mMuteAutoplayingVideos ? 0f : 1f;
+
muteButton.setOnClickListener(view -> {
if (helper != null) {
if (helper.getVolume() != 0) {
@@ -2255,11 +2262,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle());
mActivity.startActivity(intent);
} else if (mPost.getPostType() == Post.GIF_TYPE) {
- Intent intent = new Intent(mActivity, ViewGIFActivity.class);
- intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, mPost.getSubredditName()
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, mPost.getSubredditName()
+ "-" + mPost.getId() + ".gif");
- intent.putExtra(ViewGIFActivity.GIF_URL_KEY, mPost.getVideoUrl());
- intent.putExtra(ViewImageActivity.POST_TITLE_KEY, mPost.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.GIF_URL_KEY, mPost.getVideoUrl());
+ intent.putExtra(ViewImageOrGifActivity.POST_TITLE_KEY, mPost.getTitle());
mActivity.startActivity(intent);
}
});
@@ -2350,18 +2357,18 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mImageView.setOnClickListener(view -> {
if (mPost.getPostType() == Post.IMAGE_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageActivity.class);
- intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, mPost.getUrl());
- intent.putExtra(ViewImageActivity.FILE_NAME_KEY, mPost.getSubredditNamePrefixed().substring(2)
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.IMAGE_URL_KEY, mPost.getUrl());
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, mPost.getSubredditNamePrefixed().substring(2)
+ "-" + mPost.getId().substring(3) + ".jpg");
- intent.putExtra(ViewImageActivity.POST_TITLE_KEY, mPost.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.POST_TITLE_KEY, mPost.getTitle());
mActivity.startActivity(intent);
} else if (mPost.getPostType() == Post.GIF_TYPE) {
- Intent intent = new Intent(mActivity, ViewGIFActivity.class);
- intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, mPost.getSubredditName()
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, mPost.getSubredditName()
+ "-" + mPost.getId() + ".gif");
- intent.putExtra(ViewGIFActivity.GIF_URL_KEY, mPost.getVideoUrl());
- intent.putExtra(ViewImageActivity.POST_TITLE_KEY, mPost.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.GIF_URL_KEY, mPost.getVideoUrl());
+ intent.putExtra(ViewImageOrGifActivity.POST_TITLE_KEY, mPost.getTitle());
mActivity.startActivity(intent);
}
});
@@ -2934,7 +2941,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
expandButton.setOnClickListener(view -> {
if (expandButton.getVisibility() == View.VISIBLE) {
int commentPosition = mIsSingleCommentThreadMode ? getAdapterPosition() - 2 : getAdapterPosition() - 1;
- if(commentPosition >= 0 && commentPosition < mVisibleComments.size()) {
+ if (commentPosition >= 0 && commentPosition < mVisibleComments.size()) {
CommentData comment = getCurrentComment();
if (mVisibleComments.get(commentPosition).isExpanded()) {
collapseChildren(commentPosition);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java
index a60cf1e1..5e2cf2da 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/FollowedUsersRecyclerViewAdapter.java
@@ -294,7 +294,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
@Override
public String getPopupText(int position) {
switch (getItemViewType(position)) {
- case VIEW_TYPE_USER_DIVIDER:
+ case VIEW_TYPE_USER:
int offset = (mFavoriteSubscribedUserData != null && mFavoriteSubscribedUserData.size() > 0) ?
mFavoriteSubscribedUserData.size() + 2 : 0;
return mSubscribedUserData.get(position - offset).getName().substring(0, 1).toUpperCase();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java
index 4be79e91..51939d7f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/MultiRedditListingRecyclerViewAdapter.java
@@ -125,7 +125,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
multiReddit.setFavorite(false);
FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
- mAccessToken, mAccountName, false, multiReddit,
+ mAccessToken, false, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@Override
public void success() {
@@ -151,7 +151,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
multiReddit.setFavorite(true);
FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
- mAccessToken, mAccountName, true, multiReddit,
+ mAccessToken, true, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@Override
public void success() {
@@ -213,7 +213,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
multiReddit.setFavorite(false);
FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
- mAccessToken, mAccountName, false, multiReddit,
+ mAccessToken, false, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@Override
public void success() {
@@ -239,7 +239,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
multiReddit.setFavorite(true);
FavoriteMultiReddit.favoriteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
- mAccessToken, mAccountName, true, multiReddit,
+ mAccessToken, true, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@Override
public void success() {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java
index 0491c1ed..7d038fa0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java
@@ -42,7 +42,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
private static final int VIEW_TYPE_DIVIDER = 3;
private static final int VIEW_TYPE_SUBSCRIBED_SUBREDDIT = 4;
private static final int VIEW_TYPE_ACCOUNT = 5;
- private static final int CURRENT_MENU_ITEMS = 16;
+ private static final int CURRENT_MENU_ITEMS = 17;
private Context context;
private Resources resources;
@@ -90,9 +90,9 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
return VIEW_TYPE_SUBSCRIBED_SUBREDDIT;
} else if (position == 0) {
return VIEW_TYPE_NAV_HEADER;
- } else if (position == 1 || position == 6) {
+ } else if (position == 1 || position == 6 || position == 12) {
return VIEW_TYPE_MENU_GROUP_TITLE;
- } else if (position == 12) {
+ } else if (position == 16) {
return VIEW_TYPE_DIVIDER;
} else {
return VIEW_TYPE_MENU_ITEM;
@@ -214,6 +214,8 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_account);
} else if (position == 6) {
((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_post);
+ } else if (position == 12) {
+ ((MenuGroupTitleViewHolder) holder).titleTextView.setText(R.string.label_preferences);
}
} else if (holder instanceof MenuItemViewHolder) {
int stringId = 0;
@@ -401,7 +403,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
if (subscribedSubreddits != null) {
return CURRENT_MENU_ITEMS + subscribedSubreddits.size();
}
- return CURRENT_MENU_ITEMS;
+ return CURRENT_MENU_ITEMS - 1;
} else {
return 4;
}
@@ -448,7 +450,7 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
this.isNSFWEnabled = isNSFWEnabled;
if (isInMainPage) {
if (isLoggedIn) {
- notifyItemChanged(CURRENT_MENU_ITEMS - 2);
+ notifyItemChanged(CURRENT_MENU_ITEMS - 3);
} else {
notifyItemChanged(2);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
index 7aaaa391..86101979 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
@@ -22,6 +22,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.constraintlayout.widget.Barrier;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.core.graphics.drawable.DrawableCompat;
@@ -33,6 +34,7 @@ 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.DecodeFormat;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
@@ -64,18 +66,17 @@ import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.Activity.FilteredThingActivity;
import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity;
-import ml.docilealligator.infinityforreddit.Activity.ViewGIFActivity;
-import ml.docilealligator.infinityforreddit.Activity.ViewImageActivity;
+import ml.docilealligator.infinityforreddit.Activity.ViewImageOrGifActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewVideoActivity;
import ml.docilealligator.infinityforreddit.AsyncTask.LoadSubredditIconAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.LoadUserDataAsyncTask;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.ShareLinkBottomSheetFragment;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView;
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivity;
-import ml.docilealligator.infinityforreddit.BottomSheetFragment.ShareLinkBottomSheetFragment;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.Post.PostDataSource;
@@ -153,6 +154,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private int mVoteAndReplyUnavailableVoteButtonColor;
private int mButtonTextColor;
private int mPostIconAndInfoColor;
+ private int mDividerColor;
private float mScale;
private boolean mDisplaySubredditName;
private boolean mVoteButtonsOnTheRight;
@@ -163,6 +165,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private boolean mShowAbsoluteNumberOfVotes;
private boolean mAutoplay = false;
private boolean mAutoplayNsfwVideos;
+ private boolean mMuteAutoplayingVideos;
+ private boolean mShowThumbnailOnTheRightInCompactLayout;
private Drawable mCommentIcon;
private NetworkState networkState;
private ExoCreator mExoCreator;
@@ -196,6 +200,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mAutoplay = Utils.isConnectedToWifi(activity);
}
mAutoplayNsfwVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true);
+ mMuteAutoplayingVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS, true);
+ mShowThumbnailOnTheRightInCompactLayout = sharedPreferences.getBoolean(
+ SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_RIGHT_IN_COMPACT_LAYOUT, false);
mPostLayout = postLayout;
mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme();
@@ -227,6 +234,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mVoteAndReplyUnavailableVoteButtonColor = customThemeWrapper.getVoteAndReplyUnavailableButtonColor();
mButtonTextColor = customThemeWrapper.getButtonTextColor();
mPostIconAndInfoColor = customThemeWrapper.getPostIconAndInfoColor();
+ mDividerColor = customThemeWrapper.getDividerColor();
mCommentIcon = activity.getDrawable(R.drawable.ic_comment_grey_24dp);
if (mCommentIcon != null) {
@@ -830,9 +838,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
final String imageUrl = post.getUrl();
((PostCompactViewHolder) holder).imageView.setOnClickListener(view -> {
- Intent intent = new Intent(mActivity, ViewImageActivity.class);
- intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, imageUrl);
- intent.putExtra(ViewImageActivity.FILE_NAME_KEY, subredditName
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.IMAGE_URL_KEY, imageUrl);
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, subredditName
+ "-" + id + ".jpg");
mActivity.startActivity(intent);
});
@@ -860,11 +868,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
final Uri gifVideoUri = Uri.parse(post.getVideoUrl());
((PostCompactViewHolder) holder).imageView.setOnClickListener(view -> {
- Intent intent = new Intent(mActivity, ViewGIFActivity.class);
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
intent.setData(gifVideoUri);
- intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, subredditName
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, subredditName
+ "-" + id + ".gif");
- intent.putExtra(ViewGIFActivity.GIF_URL_KEY, post.getVideoUrl());
+ intent.putExtra(ViewImageOrGifActivity.GIF_URL_KEY, post.getVideoUrl());
mActivity.startActivity(intent);
});
@@ -892,8 +900,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostCompactViewHolder) holder).linkTextView.setVisibility(View.VISIBLE);
String noPreviewLinkDomain = Uri.parse(noPreviewLinkUrl).getHost();
((PostCompactViewHolder) holder).linkTextView.setText(noPreviewLinkDomain);
- ((PostCompactViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
- ((PostCompactViewHolder) holder).noPreviewLinkImageView.setOnClickListener(view -> {
+ ((PostCompactViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE);
+ ((PostCompactViewHolder) holder).noPreviewLinkImageFrameLayout.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
Uri uri = Uri.parse(post.getUrl());
if (uri.getScheme() == null && uri.getHost() == null) {
@@ -1141,7 +1149,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostImageAndGifAutoplayViewHolder) holder).imageView);
} else {
- imageRequestBuilder.into(((PostImageAndGifAutoplayViewHolder) holder).imageView);
+ imageRequestBuilder.apply(RequestOptions.noTransformation()).into(((PostImageAndGifAutoplayViewHolder) holder).imageView);
}
} else if (holder instanceof PostVideoAndGifPreviewViewHolder) {
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(post.getPreviewUrl()).listener(new RequestListener<Drawable>() {
@@ -1169,7 +1177,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
} else {
- imageRequestBuilder.into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
+ imageRequestBuilder.apply(RequestOptions.noTransformation()).into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
}
} else if (holder instanceof PostLinkTypeViewHolder) {
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(post.getPreviewUrl()).listener(new RequestListener<Drawable>() {
@@ -1197,28 +1205,27 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostLinkTypeViewHolder) holder).imageView);
} else {
- imageRequestBuilder.into(((PostLinkTypeViewHolder) holder).imageView);
+ imageRequestBuilder.apply(RequestOptions.noTransformation()).into(((PostLinkTypeViewHolder) holder).imageView);
}
} else if (holder instanceof PostCompactViewHolder) {
String previewUrl = post.getThumbnailPreviewUrl().equals("") ? post.getPreviewUrl() : post.getThumbnailPreviewUrl();
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(previewUrl)
.error(R.drawable.ic_error_outline_black_24dp).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- ((PostCompactViewHolder) holder).progressBar.setVisibility(View.GONE);
- return false;
- }
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+ ((PostCompactViewHolder) holder).progressBar.setVisibility(View.GONE);
+ return false;
+ }
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- ((PostCompactViewHolder) holder).progressBar.setVisibility(View.GONE);
- return false;
- }
- });
+ @Override
+ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+ ((PostCompactViewHolder) holder).progressBar.setVisibility(View.GONE);
+ return false;
+ }
+ });
if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) {
imageRequestBuilder
- .transform(new BlurTransformation(50, 2))
- .into(((PostCompactViewHolder) holder).imageView);
+ .transform(new BlurTransformation(50, 2)).into(((PostCompactViewHolder) holder).imageView);
} else {
imageRequestBuilder.into(((PostCompactViewHolder) holder).imageView);
}
@@ -1304,7 +1311,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
public void removeFooter() {
if (hasExtraRow()) {
- notifyItemRemoved(getItemCount() - 1);
+ notifyItemRemoved(getItemCount() - 1);
}
networkState = null;
@@ -1322,6 +1329,14 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mAutoplayNsfwVideos = autoplayNsfwVideos;
}
+ public void setMuteAutoplayingVideos(boolean muteAutoplayingVideos) {
+ mMuteAutoplayingVideos = muteAutoplayingVideos;
+ }
+
+ public void setShowThumbnailOnTheRightInCompactLayout(boolean showThumbnailOnTheRightInCompactLayout) {
+ mShowThumbnailOnTheRightInCompactLayout = showThumbnailOnTheRightInCompactLayout;
+ }
+
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder);
@@ -1375,7 +1390,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostCompactViewHolder) holder).progressBar.setVisibility(View.GONE);
((PostCompactViewHolder) holder).imageView.setVisibility(View.GONE);
((PostCompactViewHolder) holder).playButtonImageView.setVisibility(View.GONE);
- ((PostCompactViewHolder) holder).noPreviewLinkImageView.setVisibility(View.GONE);
+ ((PostCompactViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.GONE);
((PostCompactViewHolder) holder).upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
((PostCompactViewHolder) holder).scoreTextView.setTextColor(mPostIconAndInfoColor);
((PostCompactViewHolder) holder).downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
@@ -1886,7 +1901,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@Nullable
ExoPlayerViewHelper helper;
private Uri mediaUri;
- private float volume = 0f;
+ private float volume;
PostVideoAutoplayViewHolder(View itemView) {
super(itemView);
@@ -1916,6 +1931,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
aspectRatioFrameLayout.setOnClickListener(null);
+ volume = mMuteAutoplayingVideos ? 0f : 1f;
+
muteButton.setOnClickListener(view -> {
if (helper != null) {
if (helper.getVolume() != 0) {
@@ -2134,11 +2151,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle());
mActivity.startActivity(intent);
} else if (post.getPostType() == Post.GIF_TYPE) {
- Intent intent = new Intent(mActivity, ViewGIFActivity.class);
- intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, post.getSubredditName()
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, post.getSubredditName()
+ "-" + post.getId() + ".gif");
- intent.putExtra(ViewGIFActivity.GIF_URL_KEY, post.getVideoUrl());
- intent.putExtra(ViewGIFActivity.POST_TITLE_KEY, post.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.GIF_URL_KEY, post.getVideoUrl());
+ intent.putExtra(ViewImageOrGifActivity.POST_TITLE_KEY, post.getTitle());
mActivity.startActivity(intent);
}
}
@@ -2233,18 +2250,18 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
Post post = getItem(getAdapterPosition());
if (post != null) {
if (post.getPostType() == Post.IMAGE_TYPE) {
- Intent intent = new Intent(mActivity, ViewImageActivity.class);
- intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, post.getUrl());
- intent.putExtra(ViewImageActivity.FILE_NAME_KEY, post.getSubredditName()
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.IMAGE_URL_KEY, post.getUrl());
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, post.getSubredditName()
+ "-" + post.getId() + ".jpg");
- intent.putExtra(ViewImageActivity.POST_TITLE_KEY, post.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.POST_TITLE_KEY, post.getTitle());
mActivity.startActivity(intent);
} else if (post.getPostType() == Post.GIF_TYPE) {
- Intent intent = new Intent(mActivity, ViewGIFActivity.class);
- intent.putExtra(ViewGIFActivity.FILE_NAME_KEY, post.getSubredditName()
+ Intent intent = new Intent(mActivity, ViewImageOrGifActivity.class);
+ intent.putExtra(ViewImageOrGifActivity.FILE_NAME_KEY, post.getSubredditName()
+ "-" + post.getId() + ".gif");
- intent.putExtra(ViewGIFActivity.GIF_URL_KEY, post.getVideoUrl());
- intent.putExtra(ViewGIFActivity.POST_TITLE_KEY, post.getTitle());
+ intent.putExtra(ViewImageOrGifActivity.GIF_URL_KEY, post.getVideoUrl());
+ intent.putExtra(ViewImageOrGifActivity.POST_TITLE_KEY, post.getTitle());
mActivity.startActivity(intent);
}
}
@@ -2497,7 +2514,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@BindView(R.id.share_button_item_post_text_type)
ImageView shareButton;
- PostTextTypeViewHolder (View itemView) {
+ PostTextTypeViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
setBaseView(cardView,
@@ -2536,6 +2553,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
ImageView stickiedPostImageView;
@BindView(R.id.post_time_text_view_item_post_compact)
TextView postTimeTextView;
+ @BindView(R.id.title_and_image_constraint_layout)
+ ConstraintLayout titleAndImageConstraintLayout;
@BindView(R.id.title_text_view_item_post_compact)
TextView titleTextView;
@BindView(R.id.type_text_view_item_post_compact)
@@ -2564,8 +2583,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
ImageView imageView;
@BindView(R.id.play_button_image_view_item_post_compact)
ImageView playButtonImageView;
+ @BindView(R.id.frame_layout_image_view_no_preview_link_item_post_compact)
+ FrameLayout noPreviewLinkImageFrameLayout;
@BindView(R.id.image_view_no_preview_link_item_post_compact)
ImageView noPreviewLinkImageView;
+ @BindView(R.id.barrier2)
+ Barrier imageBarrier;
@BindView(R.id.bottom_constraint_layout_item_post_compact)
ConstraintLayout bottomConstraintLayout;
@BindView(R.id.plus_button_item_post_compact)
@@ -2609,6 +2632,40 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
constraintSet.applyTo(bottomConstraintLayout);
}
+ if (mShowThumbnailOnTheRightInCompactLayout) {
+ ConstraintSet constraintSet = new ConstraintSet();
+ constraintSet.clone(titleAndImageConstraintLayout);
+ constraintSet.clear(titleTextView.getId(), ConstraintSet.START);
+ constraintSet.clear(titleTextView.getId(), ConstraintSet.END);
+ constraintSet.clear(R.id.flow_layout_item_post_compact, ConstraintSet.START);
+ constraintSet.clear(R.id.flow_layout_item_post_compact, ConstraintSet.END);
+ constraintSet.clear(linkTextView.getId(), ConstraintSet.START);
+ constraintSet.clear(linkTextView.getId(), ConstraintSet.END);
+ constraintSet.clear(relativeLayout.getId(), ConstraintSet.START);
+ constraintSet.clear(relativeLayout.getId(), ConstraintSet.END);
+ constraintSet.clear(noPreviewLinkImageFrameLayout.getId(), ConstraintSet.START);
+ constraintSet.clear(noPreviewLinkImageFrameLayout.getId(), ConstraintSet.END);
+ int barrierId = 1234;
+ constraintSet.createBarrier(barrierId, Barrier.END, R.id.image_view_wrapper_item_post_compact,
+ R.id.frame_layout_image_view_no_preview_link_item_post_compact);
+ constraintSet.connect(titleTextView.getId(), ConstraintSet.START, barrierId, ConstraintSet.END);
+ constraintSet.connect(titleTextView.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END);
+ constraintSet.connect(R.id.flow_layout_item_post_compact, ConstraintSet.START, barrierId, ConstraintSet.END);
+ constraintSet.connect(R.id.flow_layout_item_post_compact, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END);
+ constraintSet.connect(R.id.flow_layout_item_post_compact, ConstraintSet.BOTTOM, linkTextView.getId(), ConstraintSet.TOP);
+ constraintSet.connect(linkTextView.getId(), ConstraintSet.START, barrierId, ConstraintSet.END);
+ constraintSet.connect(linkTextView.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END);
+ constraintSet.connect(relativeLayout.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START);
+ constraintSet.connect(relativeLayout.getId(), ConstraintSet.END, barrierId, ConstraintSet.START);
+ constraintSet.connect(noPreviewLinkImageFrameLayout.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START);
+ constraintSet.connect(noPreviewLinkImageFrameLayout.getId(), ConstraintSet.END, barrierId, ConstraintSet.START);
+ constraintSet.applyTo(titleAndImageConstraintLayout);
+
+ int leftMargin = (int) Utils.convertDpToPixel(16, mActivity);
+ ((ConstraintLayout.LayoutParams) relativeLayout.getLayoutParams()).leftMargin = leftMargin;
+ ((ConstraintLayout.LayoutParams) noPreviewLinkImageFrameLayout.getLayoutParams()).leftMargin = leftMargin;
+ }
+
itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor));
postTimeTextView.setTextColor(mSecondaryTextColor);
titleTextView.setTextColor(mPostTitleColor);
@@ -2641,6 +2698,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
commentsCountTextView.setCompoundDrawablesWithIntrinsicBounds(mCommentIcon, null, null, null);
saveButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
shareButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ divider.setBackgroundColor(mDividerColor);
+
+ imageView.setClipToOutline(true);
+ noPreviewLinkImageFrameLayout.setClipToOutline(true);
+
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index 651b09b7..9e763433 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -32,13 +32,11 @@ import ml.docilealligator.infinityforreddit.Activity.SubredditMultiselectionActi
import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity;
import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity;
import ml.docilealligator.infinityforreddit.Activity.ThemePreviewActivity;
-import ml.docilealligator.infinityforreddit.Activity.ViewGIFActivity;
-import ml.docilealligator.infinityforreddit.Activity.ViewImageActivity;
+import ml.docilealligator.infinityforreddit.Activity.ViewImageOrGifActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewImgurMediaActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewMessageActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewMultiRedditDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity;
-import ml.docilealligator.infinityforreddit.Activity.ViewSidebarActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewVideoActivity;
@@ -134,16 +132,12 @@ public interface AppComponent {
void inject(AccountSavedThingActivity accountSavedThingActivity);
- void inject(ViewImageActivity viewImageActivity);
-
- void inject(ViewGIFActivity viewGIFActivity);
+ void inject(ViewImageOrGifActivity viewGIFActivity);
void inject(MultiRedditListingActivity multiRedditListingActivity);
void inject(ViewMultiRedditDetailActivity viewMultiRedditDetailActivity);
- void inject(ViewSidebarActivity viewSidebarActivity);
-
void inject(ViewVideoActivity viewVideoActivity);
void inject(GesturesAndButtonsPreferenceFragment gesturesAndButtonsPreferenceFragment);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
index f4f32b20..d70a167d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
@@ -131,6 +131,16 @@ class AppModule {
}
@Provides
+ @Named("pushshift")
+ @Singleton
+ Retrofit providePushshiftRetrofit() {
+ return new Retrofit.Builder()
+ .baseUrl(APIUtils.PUSHSHIFT_API_BASE_URI)
+ .addConverterFactory(ScalarsConverterFactory.create())
+ .build();
+ }
+
+ @Provides
@Singleton
OkHttpClient provideOkHttpClient(@Named("no_oauth") Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase) {
OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java
index 2c15fa33..2c49eccb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertMultiRedditAsyncTask.java
@@ -1,7 +1,6 @@
package ml.docilealligator.infinityforreddit.AsyncTask;
import android.os.AsyncTask;
-import android.util.Log;
import java.util.ArrayList;
import java.util.Collections;
@@ -14,6 +13,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
public class InsertMultiRedditAsyncTask extends AsyncTask<Void, Void, Void> {
private MultiRedditDao multiRedditDao;
private ArrayList<MultiReddit> multiReddits;
+ private MultiReddit multiReddit;
private String accountName;
private InsertMultiRedditAsyncTaskListener insertMultiRedditAsyncTaskListener;
@@ -26,15 +26,27 @@ public class InsertMultiRedditAsyncTask extends AsyncTask<Void, Void, Void> {
this.insertMultiRedditAsyncTaskListener = insertMultiRedditAsyncTaskListener;
}
+ public InsertMultiRedditAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
+ MultiReddit multiReddit,
+ InsertMultiRedditAsyncTaskListener insertMultiRedditAsyncTaskListener) {
+ multiRedditDao = redditDataRoomDatabase.multiRedditDao();
+ this.multiReddit = multiReddit;
+ this.insertMultiRedditAsyncTaskListener = insertMultiRedditAsyncTaskListener;
+ }
+
@Override
protected Void doInBackground(Void... voids) {
+ if (multiReddit != null) {
+ multiRedditDao.insert(multiReddit);
+ return null;
+ }
+
List<MultiReddit> existingMultiReddits = multiRedditDao.getAllMultiRedditsList(accountName);
Collections.sort(multiReddits, (multiReddit, t1) -> multiReddit.getName().compareToIgnoreCase(t1.getName()));
List<String> deletedMultiredditNames = new ArrayList<>();
compareTwoMultiRedditList(multiReddits, existingMultiReddits, deletedMultiredditNames);
for (String deleted : deletedMultiredditNames) {
- Log.i("asdfasdfs", "s " + deleted + accountName);
multiRedditDao.deleteMultiReddit(deleted, accountName);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SetAsWallpaperAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SetAsWallpaperAsyncTask.java
new file mode 100644
index 00000000..b868e5d6
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SetAsWallpaperAsyncTask.java
@@ -0,0 +1,95 @@
+package ml.docilealligator.infinityforreddit.AsyncTask;
+
+import android.app.WallpaperManager;
+import android.graphics.Bitmap;
+import android.graphics.Rect;
+import android.media.ThumbnailUtils;
+import android.os.AsyncTask;
+import android.os.Build;
+import android.util.DisplayMetrics;
+import android.view.WindowManager;
+
+import java.io.IOException;
+
+import ml.docilealligator.infinityforreddit.WallpaperSetter;
+
+public class SetAsWallpaperAsyncTask extends AsyncTask<Void, Void, Void> {
+
+ private Bitmap bitmap;
+ private int setTo;
+ private WallpaperManager manager;
+ private WindowManager windowManager;
+ private WallpaperSetter.SetWallpaperListener setWallpaperListener;
+ private boolean success = true;
+
+ public SetAsWallpaperAsyncTask(Bitmap bitmap, int setTo, WallpaperManager manager, WindowManager windowManager,
+ WallpaperSetter.SetWallpaperListener setWallpaperListener) {
+ this.bitmap = bitmap;
+ this.setTo = setTo;
+ this.manager = manager;
+ this.windowManager = windowManager;
+ this.setWallpaperListener = setWallpaperListener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ DisplayMetrics metrics = new DisplayMetrics();
+ Rect rect = null;
+
+ if (windowManager != null) {
+ windowManager.getDefaultDisplay().getMetrics(metrics);
+ int height = metrics.heightPixels;
+ int width = metrics.widthPixels;
+
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
+ bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height);
+ }
+
+ float imageAR = (float) bitmap.getWidth() / (float) bitmap.getHeight();
+ float screenAR = (float) width / (float) height;
+
+ if (imageAR > screenAR) {
+ int desiredWidth = (int) (bitmap.getHeight() * screenAR);
+ rect = new Rect((bitmap.getWidth() - desiredWidth) / 2, 0, bitmap.getWidth(), bitmap.getHeight());
+ } else {
+ int desiredHeight = (int) (bitmap.getWidth() / screenAR);
+ rect = new Rect(0, (bitmap.getHeight() - desiredHeight) / 2, bitmap.getWidth(), (bitmap.getHeight() + desiredHeight) / 2);
+ }
+ }
+ try {
+ switch (setTo) {
+ case WallpaperSetter.HOME_SCREEN:
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ manager.setBitmap(bitmap, rect, true, WallpaperManager.FLAG_SYSTEM);
+ }
+ break;
+ case WallpaperSetter.LOCK_SCREEN:
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ manager.setBitmap(bitmap, rect, true, WallpaperManager.FLAG_LOCK);
+ }
+ break;
+ case WallpaperSetter.BOTH_SCREENS:
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ manager.setBitmap(bitmap, rect, true, WallpaperManager.FLAG_SYSTEM | WallpaperManager.FLAG_LOCK);
+ } else {
+ manager.setBitmap(bitmap);
+ }
+ break;
+ }
+ } catch (IOException e) {
+ success = false;
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ if (success) {
+ setWallpaperListener.success();
+ } else {
+ setWallpaperListener.failed();
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java
index 364096e6..de4f5778 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/CommentMoreBottomSheetFragment.java
@@ -47,7 +47,10 @@ public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFrag
TextView copyTextView;
@BindView(R.id.report_view_comment_more_bottom_sheet_fragment)
TextView reportTextView;
+ @BindView(R.id.see_removed_view_comment_more_bottom_sheet_fragment)
+ TextView seeRemovedTextView;
private AppCompatActivity activity;
+
public CommentMoreBottomSheetFragment() {
// Required empty public constructor
}
@@ -131,6 +134,20 @@ public class CommentMoreBottomSheetFragment extends RoundedBottomSheetDialogFrag
dismiss();
});
+ if ("[deleted]".equals(commentData.getAuthor()) ||
+ "[deleted]".equals(commentData.getCommentRawText()) ||
+ "[removed]".equals(commentData.getCommentRawText())
+ ) {
+ seeRemovedTextView.setVisibility(View.VISIBLE);
+
+ seeRemovedTextView.setOnClickListener(view -> {
+ dismiss();
+ if (activity instanceof ViewPostDetailActivity) {
+ ((ViewPostDetailActivity) activity).showRemovedComment(commentData, bundle.getInt(EXTRA_POSITION));
+ }
+ });
+ }
+
return rootView;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/MultiRedditOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/MultiRedditOptionsBottomSheetFragment.java
index 60b065ba..27a9ccdc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/MultiRedditOptionsBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/MultiRedditOptionsBottomSheetFragment.java
@@ -16,7 +16,7 @@ import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Activity.EditMultiRedditActivity;
-import ml.docilealligator.infinityforreddit.Activity.MultiRedditListingActivity;
+import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity;
import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
import ml.docilealligator.infinityforreddit.R;
@@ -31,7 +31,7 @@ public class MultiRedditOptionsBottomSheetFragment extends RoundedBottomSheetDia
TextView editMultiRedditTextView;
@BindView(R.id.delete_multi_reddit_text_view_multi_reddit_options_bottom_sheet_fragment)
TextView deleteMultiRedditTextView;
- private MultiRedditListingActivity multiRedditListingActivity;
+ private SubscribedThingListingActivity subscribedThingListingActivity;
public MultiRedditOptionsBottomSheetFragment() {
// Required empty public constructor
@@ -48,14 +48,14 @@ public class MultiRedditOptionsBottomSheetFragment extends RoundedBottomSheetDia
MultiReddit multiReddit = getArguments().getParcelable(EXTRA_MULTI_REDDIT);
editMultiRedditTextView.setOnClickListener(view -> {
- Intent editIntent = new Intent(multiRedditListingActivity, EditMultiRedditActivity.class);
+ Intent editIntent = new Intent(subscribedThingListingActivity, EditMultiRedditActivity.class);
editIntent.putExtra(EditMultiRedditActivity.EXTRA_MULTI_REDDIT, multiReddit);
startActivity(editIntent);
dismiss();
});
deleteMultiRedditTextView.setOnClickListener(view -> {
- multiRedditListingActivity.deleteMultiReddit(multiReddit);
+ subscribedThingListingActivity.deleteMultiReddit(multiReddit);
dismiss();
});
@@ -65,6 +65,6 @@ public class MultiRedditOptionsBottomSheetFragment extends RoundedBottomSheetDia
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
- multiRedditListingActivity = (MultiRedditListingActivity) context;
+ subscribedThingListingActivity = (SubscribedThingListingActivity) context;
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/SetAsWallpaperBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/SetAsWallpaperBottomSheetFragment.java
new file mode 100644
index 00000000..db6e80e9
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/SetAsWallpaperBottomSheetFragment.java
@@ -0,0 +1,79 @@
+package ml.docilealligator.infinityforreddit.BottomSheetFragment;
+
+import android.app.Activity;
+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 butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback;
+
+public class SetAsWallpaperBottomSheetFragment extends RoundedBottomSheetDialogFragment {
+
+ public static final String EXTRA_VIEW_PAGER_POSITION = "EVPP";
+
+ @BindView(R.id.home_screen_text_view_set_as_wallpaper_bottom_sheet_fragment)
+ TextView homeScreenTextvView;
+ @BindView(R.id.lock_screen_text_view_set_as_wallpaper_bottom_sheet_fragment)
+ TextView lockScreenTextView;
+ @BindView(R.id.both_text_view_set_as_wallpaper_bottom_sheet_fragment)
+ TextView bothTextView;
+ private Activity mActivity;
+
+ public SetAsWallpaperBottomSheetFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_set_as_wallpaper_bottom_sheet, container, false);
+ ButterKnife.bind(this, rootView);
+
+ Bundle bundle = getArguments();
+ int viewPagerPosition = bundle == null ? -1 : bundle.getInt(EXTRA_VIEW_PAGER_POSITION);
+
+ bothTextView.setOnClickListener(view -> {
+ if (mActivity instanceof SetAsWallpaperCallback) {
+ ((SetAsWallpaperCallback) mActivity).setToBoth(viewPagerPosition);
+ }
+ dismiss();
+ });
+
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
+ homeScreenTextvView.setVisibility(View.VISIBLE);
+ lockScreenTextView.setVisibility(View.VISIBLE);
+
+ homeScreenTextvView.setOnClickListener(view -> {
+ if (mActivity instanceof SetAsWallpaperCallback) {
+ ((SetAsWallpaperCallback) mActivity).setToHomeScreen(viewPagerPosition);
+ }
+ dismiss();
+ });
+
+ lockScreenTextView.setOnClickListener(view -> {
+ if (mActivity instanceof SetAsWallpaperCallback) {
+ ((SetAsWallpaperCallback) mActivity).setToLockScreen(viewPagerPosition);
+ }
+ dismiss();
+ });
+ }
+
+ return rootView;
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ this.mActivity = (Activity) context;
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
index 5c01f3fe..e38ecd11 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
@@ -279,7 +279,7 @@ public class CommentData implements Parcelable {
if (children == null || children.size() == 0) {
setChildren(moreChildren);
} else {
- if (children.get(children.size() - 1).isPlaceHolder) {
+ if (children.size() > 1 && children.get(children.size() - 1).isPlaceHolder) {
children.addAll(children.size() - 2, moreChildren);
} else {
children.addAll(moreChildren);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeMuteAutoplayingVideosEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeMuteAutoplayingVideosEvent.java
new file mode 100644
index 00000000..421be2a1
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeMuteAutoplayingVideosEvent.java
@@ -0,0 +1,9 @@
+package ml.docilealligator.infinityforreddit.Event;
+
+public class ChangeMuteAutoplayingVideosEvent {
+ public boolean muteAutoplayingVideos;
+
+ public ChangeMuteAutoplayingVideosEvent(boolean muteAutoplayingVideos) {
+ this.muteAutoplayingVideos = muteAutoplayingVideos;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ShowThumbnailOnTheRightInCompactLayoutEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ShowThumbnailOnTheRightInCompactLayoutEvent.java
new file mode 100644
index 00000000..f1010773
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ShowThumbnailOnTheRightInCompactLayoutEvent.java
@@ -0,0 +1,9 @@
+package ml.docilealligator.infinityforreddit.Event;
+
+public class ShowThumbnailOnTheRightInCompactLayoutEvent {
+ public boolean showThumbnailOnTheRightInCompactLayout;
+
+ public ShowThumbnailOnTheRightInCompactLayoutEvent(boolean showThumbnailOnTheRightInCompactLayout) {
+ this.showThumbnailOnTheRightInCompactLayout = showThumbnailOnTheRightInCompactLayout;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatVideoLinks.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java
index b9799484..9d51cb1e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatVideoLinks.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java
@@ -14,27 +14,27 @@ import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
-public class FetchGfycatVideoLinks {
- public interface FetchGfycatVideoLinksListener {
+public class FetchGfycatOrRedgifsVideoLinks {
+ public interface FetchGfycatOrRedgifsVideoLinksListener {
void success(String webm, String mp4);
- void failed();
+ void failed(int errorCode);
}
- public static void fetchGfycatVideoLinks(Retrofit gfycatRetrofit, String gfycatId,
- FetchGfycatVideoLinksListener fetchGfycatVideoLinksListener) {
+ public static void fetchGfycatOrRedgifsVideoLinks(Retrofit gfycatRetrofit, String gfycatId,
+ FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
gfycatRetrofit.create(GfycatAPI.class).getGfycatData(gfycatId).enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {
- new ParseGfycatVideoLinksAsyncTask(response.body(), fetchGfycatVideoLinksListener).execute();
+ new ParseGfycatVideoLinksAsyncTask(response.body(), fetchGfycatOrRedgifsVideoLinksListener).execute();
} else {
- fetchGfycatVideoLinksListener.failed();
+ fetchGfycatOrRedgifsVideoLinksListener.failed(response.code());
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
- fetchGfycatVideoLinksListener.failed();
+ fetchGfycatOrRedgifsVideoLinksListener.failed(-1);
}
});
}
@@ -45,11 +45,11 @@ public class FetchGfycatVideoLinks {
private String webm;
private String mp4;
private boolean parseFailed = false;
- private FetchGfycatVideoLinksListener fetchGfycatVideoLinksListener;
+ private FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener;
- ParseGfycatVideoLinksAsyncTask(String response, FetchGfycatVideoLinksListener fetchGfycatVideoLinksListener) {
+ ParseGfycatVideoLinksAsyncTask(String response, FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
this.response = response;
- this.fetchGfycatVideoLinksListener = fetchGfycatVideoLinksListener;
+ this.fetchGfycatOrRedgifsVideoLinksListener = fetchGfycatOrRedgifsVideoLinksListener;
}
@Override
@@ -70,9 +70,9 @@ public class FetchGfycatVideoLinks {
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if (parseFailed) {
- fetchGfycatVideoLinksListener.failed();
+ fetchGfycatOrRedgifsVideoLinksListener.failed(-1);
} else {
- fetchGfycatVideoLinksListener.success(webm, mp4);
+ fetchGfycatOrRedgifsVideoLinksListener.success(webm, mp4);
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchMessages.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchMessages.java
index e49e21ec..942d7f7a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchMessages.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchMessages.java
@@ -29,15 +29,19 @@ public class FetchMessages {
public static final String WHERE_UNREAD = "unread";
public static final String WHERE_SENT = "sent";
public static final String WHERE_COMMENTS = "comments";
+ public static final String WHERE_MESSAGES = "messages";
+ public static final int MESSAGE_TYPE_NOTIFICATION = 0;
+ public static final int MESSAGE_TYPE_PRIVATE_MESSAGE = 1;
- static void fetchMessagesAsync(Retrofit oauthRetrofit, Locale locale, String accessToken, String where,
- String after, FetchMessagesListener fetchMessagesListener) {
+ static void fetchInbox(Retrofit oauthRetrofit, Locale locale, String accessToken, String where,
+ String after, int messageType, FetchMessagesListener fetchMessagesListener) {
oauthRetrofit.create(RedditAPI.class).getMessages(APIUtils.getOAuthHeader(accessToken), where, after)
.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {
- new ParseMessageAsnycTask(response.body(), locale, fetchMessagesListener::fetchSuccess).execute();
+ new ParseMessageAsnycTask(response.body(), locale, messageType,
+ fetchMessagesListener::fetchSuccess).execute();
} else {
fetchMessagesListener.fetchFailed();
}
@@ -50,8 +54,7 @@ public class FetchMessages {
});
}
- @Nullable
- static ArrayList<Message> parseMessage(String response, Locale locale) {
+ static ArrayList<Message> parseMessage(String response, Locale locale, int messageType) {
JSONArray messageArray;
try {
messageArray = new JSONObject(response).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
@@ -65,6 +68,10 @@ public class FetchMessages {
try {
JSONObject messageJSON = messageArray.getJSONObject(i);
String kind = messageJSON.getString(JSONUtils.KIND_KEY);
+ if ((messageType == MESSAGE_TYPE_NOTIFICATION && kind.equals("t4")) ||
+ (messageType == MESSAGE_TYPE_PRIVATE_MESSAGE && !kind.equals("t4"))) {
+ continue;
+ }
JSONObject rawMessageJSON = messageJSON.getJSONObject(JSONUtils.DATA_KEY);
String subredditName = rawMessageJSON.getString(JSONUtils.SUBREDDIT_KEY);
@@ -111,17 +118,20 @@ public class FetchMessages {
private Locale locale;
private ArrayList<Message> messages;
private String after;
+ private int messageType;
private ParseMessageAsyncTaskListener parseMessageAsyncTaskListener;
- ParseMessageAsnycTask(String response, Locale locale, ParseMessageAsyncTaskListener parseMessageAsnycTaskListener) {
+ ParseMessageAsnycTask(String response, Locale locale, int messageType,
+ ParseMessageAsyncTaskListener parseMessageAsnycTaskListener) {
this.response = response;
this.locale = locale;
+ this.messageType = messageType;
messages = new ArrayList<>();
this.parseMessageAsyncTaskListener = parseMessageAsnycTaskListener;
}
@Override
protected Void doInBackground(Void... voids) {
- messages = parseMessage(response, locale);
+ messages = parseMessage(response, locale, messageType);
try {
after = new JSONObject(response).getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
} catch (JSONException e) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java
new file mode 100644
index 00000000..d012342e
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedComment.java
@@ -0,0 +1,97 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.os.AsyncTask;
+
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import ml.docilealligator.infinityforreddit.API.PushshiftAPI;
+import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+
+public class FetchRemovedComment {
+
+ public static void fetchRemovedComment(Retrofit retrofit, CommentData comment, FetchRemovedCommentListener listener) {
+ retrofit.create(PushshiftAPI.class).getRemovedComment(comment.getId())
+ .enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if (response.isSuccessful()) {
+ new ParseCommentAsyncTask(response.body(), comment, listener).execute();
+ } else {
+ listener.fetchFailed();
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ t.printStackTrace();
+ listener.fetchFailed();
+ }
+ });
+ }
+
+ private static CommentData parseRemovedComment(JSONObject result, CommentData comment) throws JSONException {
+ String id = result.getString(JSONUtils.ID_KEY);
+ String author = result.getString(JSONUtils.AUTHOR_KEY);
+ String body = Utils.modifyMarkdown(result.optString(JSONUtils.BODY_KEY).trim());
+
+ if ( id.equals(comment.getId()) &&
+ (!author.equals(comment.getAuthor()) ||
+ !body.equals(comment.getCommentRawText()))
+ ) {
+ comment.setAuthor(author);
+ comment.setCommentMarkdown(body);
+ comment.setCommentRawText(body);
+ return comment;
+ } else {
+ return null;
+ }
+ }
+
+ public interface FetchRemovedCommentListener {
+ void fetchSuccess(CommentData comment);
+
+ void fetchFailed();
+ }
+
+ private static class ParseCommentAsyncTask extends AsyncTask<Void, Void, Void> {
+
+ private String responseBody;
+ private FetchRemovedCommentListener listener;
+ CommentData comment;
+
+ public ParseCommentAsyncTask(String responseBody, CommentData comment, FetchRemovedCommentListener listener) {
+ this.responseBody = responseBody;
+ this.comment = comment;
+ this.listener = listener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ try {
+ JSONObject commentJSON = new JSONObject(responseBody).getJSONArray(JSONUtils.DATA_KEY).getJSONObject(0);
+ comment = parseRemovedComment(commentJSON, comment);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ comment = null;
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ if (comment != null)
+ listener.fetchSuccess(comment);
+ else
+ listener.fetchFailed();
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java
new file mode 100644
index 00000000..646dfe19
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRemovedPost.java
@@ -0,0 +1,141 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.text.Html;
+
+import androidx.annotation.NonNull;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import ml.docilealligator.infinityforreddit.API.PushshiftAPI;
+import ml.docilealligator.infinityforreddit.Post.Post;
+import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+
+public class FetchRemovedPost {
+
+ public static void fetchRemovedPost(Retrofit retrofit, Post post, FetchRemovedPostListener listener) {
+ retrofit.create(PushshiftAPI.class).getRemovedPost(post.getId())
+ .enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if (response.isSuccessful()) {
+ new ParsePostAsyncTask(response.body(), post, listener).execute();
+ } else {
+ listener.fetchFailed();
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ t.printStackTrace();
+ listener.fetchFailed();
+ }
+ });
+ }
+
+ private static Post parseRemovedPost(JSONObject result, Post post) throws JSONException {
+ String id = result.getString(JSONUtils.ID_KEY);
+ String author = result.getString(JSONUtils.AUTHOR_KEY);
+ String title = result.getString(JSONUtils.TITLE_KEY);
+ String body = Utils.modifyMarkdown(result.getString(JSONUtils.SELFTEXT_KEY).trim());
+
+ if ( id.equals(post.getId()) &&
+ (!author.equals(post.getAuthor()) ||
+ foundSelfText(post.getSelfText(), body))
+ ) {
+ post.setAuthor(author);
+ post.setTitle(title);
+ post.setSelfText(body);
+ post.setSelfTextPlain("");
+ post.setSelfTextPlainTrimmed("");
+
+ String url = result.optString(JSONUtils.URL_KEY);
+
+ if (url.endsWith("gif") || url.endsWith("mp4")) {
+ post.setVideoUrl(url);
+ post.setVideoDownloadUrl(url);
+ } else if (post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE) {
+ JSONObject redditVideoObject = result.getJSONObject("secure_media").getJSONObject(JSONUtils.REDDIT_VIDEO_KEY);
+ String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.HLS_URL_KEY)).toString();
+ String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY);
+
+ post.setVideoUrl(videoUrl);
+ post.setVideoDownloadUrl(videoDownloadUrl);
+ } else if (post.getPostType() == Post.LINK_TYPE) {
+ post.setUrl(url);
+ }
+
+ if (post.getPostType() == Post.VIDEO_TYPE) {
+ try {
+ Uri uri = Uri.parse(url);
+ String authority = uri.getAuthority();
+ if (authority != null && (authority.contains("gfycat.com") || authority.contains("redgifs.com"))) {
+ post.setPostType(Post.LINK_TYPE);
+ post.setUrl(url);
+ }
+ } catch (IllegalArgumentException ignore) {
+ }
+ }
+
+ if (!result.isNull("thumbnail")) {
+ post.setThumbnailPreviewUrl(result.getString("thumbnail"));
+ }
+
+ return post;
+ } else {
+ return null;
+ }
+ }
+
+ private static boolean foundSelfText(String oldText, String newText) {
+ return !(newText.equals("[deleted]") || newText.equals("[removed]")) &&
+ !newText.equals(oldText);
+ }
+
+ public interface FetchRemovedPostListener {
+ void fetchSuccess(Post post);
+
+ void fetchFailed();
+ }
+
+ private static class ParsePostAsyncTask extends AsyncTask<Void, Void, Void> {
+
+ private String responseBody;
+ private FetchRemovedPostListener listener;
+ Post post;
+
+ public ParsePostAsyncTask(String responseBody, Post post, FetchRemovedPostListener listener) {
+ this.responseBody = responseBody;
+ this.post = post;
+ this.listener = listener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ try {
+ JSONObject postJson = new JSONObject(responseBody).getJSONArray(JSONUtils.DATA_KEY).getJSONObject(0);
+ post = parseRemovedPost(postJson, post);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ post = null;
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ if (post != null)
+ listener.fetchSuccess(post);
+ else
+ listener.fetchFailed();
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Font/ContentFontFamily.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/ContentFontFamily.java
new file mode 100644
index 00000000..6a00aec9
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/ContentFontFamily.java
@@ -0,0 +1,31 @@
+package ml.docilealligator.infinityforreddit.Font;
+
+import ml.docilealligator.infinityforreddit.R;
+
+public enum ContentFontFamily {
+ Default(R.style.ContentFontFamily, "Default"),
+ BalsamiqSans(R.style.ContentFontFamily_BalsamiqSans, "BalsamiqSans"),
+ NotoSans(R.style.ContentFontFamily_NotoSans, "NotoSans"),
+ RobotoCondensed(R.style.ContentFontFamily_RobotoCondensed, "RobotoCondensed"),
+ HarmoniaSans(R.style.ContentFontFamily_HarmoniaSans, "HarmoniaSans"),
+ Inter(R.style.ContentFontFamily_Inter, "Inter"),
+ Manrope(R.style.ContentFontFamily_Manrope, "Manrope"),
+ BadScript(R.style.ContentFontFamily_BadScript, "BadScript"),
+ Sriracha(R.style.ContentFontFamily_Sriracha, "Sriracha");
+
+ private int resId;
+ private String title;
+
+ ContentFontFamily(int resId, String title) {
+ this.resId = resId;
+ this.title = title;
+ }
+
+ public int getResId() {
+ return resId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ContentFontStyle.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/ContentFontStyle.java
index 4eee6b53..654cff07 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ContentFontStyle.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/ContentFontStyle.java
@@ -1,4 +1,6 @@
-package ml.docilealligator.infinityforreddit;
+package ml.docilealligator.infinityforreddit.Font;
+
+import ml.docilealligator.infinityforreddit.R;
public enum ContentFontStyle {
Small(R.style.ContentFontStyle_Small, "Small"),
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Font/FontFamily.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/FontFamily.java
new file mode 100644
index 00000000..8a04a50e
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/FontFamily.java
@@ -0,0 +1,31 @@
+package ml.docilealligator.infinityforreddit.Font;
+
+import ml.docilealligator.infinityforreddit.R;
+
+public enum FontFamily {
+ Default(R.style.FontFamily, "Default"),
+ BalsamiqSans(R.style.FontFamily_BalsamiqSans, "BalsamiqSans"),
+ NotoSans(R.style.FontFamily_NotoSans, "NotoSans"),
+ RobotoCondensed(R.style.FontFamily_RobotoCondensed, "RobotoCondensed"),
+ HarmoniaSans(R.style.FontFamily_HarmoniaSans, "HarmoniaSans"),
+ Inter(R.style.FontFamily_Inter, "Inter"),
+ Manrope(R.style.FontFamily_Manrope, "Manrope"),
+ BadScript(R.style.FontFamily_BadScript, "BadScript"),
+ Sriracha(R.style.FontFamily_Sriracha, "Sriracha");
+
+ private int resId;
+ private String title;
+
+ FontFamily(int resId, String title) {
+ this.resId = resId;
+ this.title = title;
+ }
+
+ public int getResId() {
+ return resId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FontStyle.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/FontStyle.java
index 61d4cfb8..101b17b4 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FontStyle.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/FontStyle.java
@@ -1,4 +1,6 @@
-package ml.docilealligator.infinityforreddit;
+package ml.docilealligator.infinityforreddit.Font;
+
+import ml.docilealligator.infinityforreddit.R;
public enum FontStyle {
Small(R.style.FontStyle_Small, "Small"),
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Font/TitleFontFamily.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/TitleFontFamily.java
new file mode 100644
index 00000000..ffe319c4
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/TitleFontFamily.java
@@ -0,0 +1,31 @@
+package ml.docilealligator.infinityforreddit.Font;
+
+import ml.docilealligator.infinityforreddit.R;
+
+public enum TitleFontFamily {
+ Default(R.style.TitleFontFamily, "Default"),
+ BalsamiqSans(R.style.TitleFontFamily_BalsamiqSans, "BalsamiqSans"),
+ NotoSans(R.style.TitleFontFamily_NotoSans, "NotoSans"),
+ RobotoCondensed(R.style.TitleFontFamily_RobotoCondensed, "RobotoCondensed"),
+ HarmoniaSans(R.style.TitleFontFamily_HarmoniaSans, "HarmoniaSans"),
+ Inter(R.style.TitleFontFamily_Inter, "Inter"),
+ Manrope(R.style.TitleFontFamily_Manrope, "Manrope"),
+ BadScript(R.style.TitleFontFamily_BadScript, "BadScript"),
+ Sriracha(R.style.TitleFontFamily_Sriracha, "Sriracha");
+
+ private int resId;
+ private String title;
+
+ TitleFontFamily(int resId, String title) {
+ this.resId = resId;
+ this.title = title;
+ }
+
+ public int getResId() {
+ return resId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/TitleFontStyle.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/TitleFontStyle.java
index 5dc32c9d..9ac48525 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/TitleFontStyle.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Font/TitleFontStyle.java
@@ -1,4 +1,6 @@
-package ml.docilealligator.infinityforreddit;
+package ml.docilealligator.infinityforreddit.Font;
+
+import ml.docilealligator.infinityforreddit.R;
public enum TitleFontStyle {
Small(R.style.TitleFontStyle_Small, "Small"),
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java
index 89311f15..1a58e526 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/MultiRedditListingFragment.java
@@ -49,7 +49,6 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
public static final String EXTRA_ACCOUNT_NAME = "EAN";
public static final String EXTRA_ACCESS_TOKEN = "EAT";
- private static final String INSERT_MULTI_REDDIT_STATE = "ISSS";
@BindView(R.id.swipe_refresh_layout_multi_reddit_listing_fragment)
SwipeRefreshLayout mSwipeRefreshLayout;
@@ -78,7 +77,6 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
private AppCompatActivity mActivity;
private RequestManager mGlide;
private LinearLayoutManager mLinearLayoutManager;
- private boolean mInsertSuccess = false;
public MultiRedditListingFragment() {
// Required empty public constructor
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
index 37888f9a..3aa0f16c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
@@ -59,6 +59,7 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.CustomView.CustomToroContainer;
import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
+import ml.docilealligator.infinityforreddit.Event.ChangeMuteAutoplayingVideosEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVotesEvent;
@@ -69,6 +70,7 @@ import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent
import ml.docilealligator.infinityforreddit.Event.ChangeWifiStatusEvent;
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList;
import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPreferenceEvent;
+import ml.docilealligator.infinityforreddit.Event.ShowThumbnailOnTheRightInCompactLayoutEvent;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.NetworkState;
@@ -890,7 +892,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
public void onChangeAutoplayNsfwVideosEvent(ChangeAutoplayNsfwVideosEvent changeAutoplayNsfwVideosEvent) {
if (mAdapter != null) {
mAdapter.setAutoplayNsfwVideos(changeAutoplayNsfwVideosEvent.autoplayNsfwVideos);
- refresh();
+ refreshAdapter();
+ }
+ }
+
+ @Subscribe
+ public void onChangeMuteAutoplayingVideosEvent(ChangeMuteAutoplayingVideosEvent changeMuteAutoplayingVideosEvent) {
+ if (mAdapter != null) {
+ mAdapter.setMuteAutoplayingVideos(changeMuteAutoplayingVideosEvent.muteAutoplayingVideos);
+ refreshAdapter();
}
}
@@ -905,6 +915,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
+ @Subscribe
+ public void onShowThumbnailOnTheRightInCompactLayoutEvent(ShowThumbnailOnTheRightInCompactLayoutEvent showThumbnailOnTheRightInCompactLayoutEvent) {
+ if (mAdapter != null) {
+ mAdapter.setShowThumbnailOnTheRightInCompactLayout(showThumbnailOnTheRightInCompactLayoutEvent.showThumbnailOnTheRightInCompactLayout);
+ refreshAdapter();
+ }
+ }
+
private void refreshAdapter() {
int previousPosition = -1;
if (mLinearLayoutManager != null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java
index dbafed2d..9d9aa9b7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java
@@ -50,9 +50,6 @@ import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
import retrofit2.Retrofit;
-/**
- * A simple {@link Fragment} subclass.
- */
public class SidebarFragment extends Fragment {
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
@@ -152,7 +149,7 @@ public class SidebarFragment extends Fragment {
mSubredditViewModel = new ViewModelProvider(this,
new SubredditViewModel.Factory(activity.getApplication(), mRedditDataRoomDatabase, subredditName))
.get(SubredditViewModel.class);
- mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> {
+ mSubredditViewModel.getSubredditLiveData().observe(getViewLifecycleOwner(), subredditData -> {
if (subredditData != null) {
if (subredditData.getSidebarDescription() != null && !subredditData.getSidebarDescription().equals("")) {
markwonAdapter.setMarkdown(markwon, subredditData.getSidebarDescription());
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewPostsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewPostsFragment.java
index e8963f92..eeefeaa0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewPostsFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewPostsFragment.java
@@ -15,7 +15,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.core.graphics.drawable.DrawableCompat;
-import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
@@ -59,6 +58,8 @@ public class ThemePreviewPostsFragment extends Fragment {
CustomTextView nsfwTextView;
@BindView(R.id.flair_custom_text_view_theme_preview_posts_fragment)
CustomTextView flairTextView;
+ @BindView(R.id.awards_text_view_theme_preview_posts_fragment)
+ CustomTextView awardsTextView;
@BindView(R.id.archived_image_view_theme_preview_posts_fragment)
ImageView archivedImageView;
@BindView(R.id.locked_image_view_theme_preview_posts_fragment)
@@ -120,6 +121,9 @@ public class ThemePreviewPostsFragment extends Fragment {
flairTextView.setBackgroundColor(customTheme.flairBackgroundColor);
flairTextView.setBorderColor(customTheme.flairBackgroundColor);
flairTextView.setTextColor(customTheme.flairTextColor);
+ awardsTextView.setBackgroundColor(customTheme.awardsBackgroundColor);
+ awardsTextView.setBorderColor(customTheme.awardsBackgroundColor);
+ awardsTextView.setTextColor(customTheme.awardsTextColor);
archivedImageView.setColorFilter(customTheme.archivedTint, PorterDuff.Mode.SRC_IN);
lockedImageView.setColorFilter(customTheme.lockedIconTint, PorterDuff.Mode.SRC_IN);
crosspostImageView.setColorFilter(customTheme.crosspostIconTint, PorterDuff.Mode.SRC_IN);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java
index ae047287..8d761757 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurImageFragment.java
@@ -1,8 +1,6 @@
package ml.docilealligator.infinityforreddit.Fragment;
import android.Manifest;
-import android.app.Activity;
-import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -11,7 +9,6 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
-import android.os.Environment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -43,10 +40,15 @@ import java.io.File;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.Activity.ViewImgurMediaActivity;
import ml.docilealligator.infinityforreddit.AsyncTask.SaveImageToFileAsyncTask;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.SetAsWallpaperBottomSheetFragment;
import ml.docilealligator.infinityforreddit.BuildConfig;
import ml.docilealligator.infinityforreddit.ImgurMedia;
+import ml.docilealligator.infinityforreddit.MediaDownloader;
+import ml.docilealligator.infinityforreddit.MediaDownloaderImpl;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback;
public class ViewImgurImageFragment extends Fragment {
@@ -60,8 +62,9 @@ public class ViewImgurImageFragment extends Fragment {
@BindView(R.id.load_image_error_linear_layout_view_imgur_image_fragment)
LinearLayout errorLinearLayout;
- private Activity activity;
+ private ViewImgurMediaActivity activity;
private RequestManager glide;
+ private MediaDownloader mediaDownloader;
private ImgurMedia imgurMedia;
private boolean isDownloading = false;
@@ -80,6 +83,7 @@ public class ViewImgurImageFragment extends Fragment {
imgurMedia = getArguments().getParcelable(EXTRA_IMGUR_IMAGES);
glide = Glide.with(activity);
+ mediaDownloader = new MediaDownloaderImpl();
loadImage();
return rootView;
@@ -99,7 +103,7 @@ public class ViewImgurImageFragment extends Fragment {
progressBar.setVisibility(View.GONE);
return false;
}
- }).into(imageView);
+ }).override(Target.SIZE_ORIGINAL).into(imageView);
}
@Override
@@ -130,10 +134,10 @@ public class ViewImgurImageFragment extends Fragment {
PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
} else {
// Permission has already been granted
- download();
+ mediaDownloader.download(imgurMedia.getLink(), imgurMedia.getFileName(), getContext());
}
} else {
- download();
+ mediaDownloader.download(imgurMedia.getLink(), imgurMedia.getFileName(), getContext());
}
return true;
@@ -143,14 +147,14 @@ public class ViewImgurImageFragment extends Fragment {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
if (activity.getExternalCacheDir() != null) {
- Toast.makeText(activity, R.string.save_image_before_sharing, Toast.LENGTH_SHORT).show();
+ Toast.makeText(activity, R.string.save_image_first, Toast.LENGTH_SHORT).show();
new SaveImageToFileAsyncTask(resource, activity.getExternalCacheDir().getPath(),
imgurMedia.getFileName(),
new SaveImageToFileAsyncTask.SaveImageToFileAsyncTaskListener() {
@Override
public void saveSuccess(File imageFile) {
Uri uri = FileProvider.getUriForFile(activity,
- BuildConfig.APPLICATION_ID + ".provider",imageFile);
+ BuildConfig.APPLICATION_ID + ".provider", imageFile);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
@@ -177,6 +181,17 @@ public class ViewImgurImageFragment extends Fragment {
}
});
return true;
+ case R.id.action_set_wallpaper_view_imgur_image_fragments:
+ 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;
}
return false;
@@ -188,59 +203,15 @@ public class ViewImgurImageFragment extends Fragment {
if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
Toast.makeText(activity, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
} else if (grantResults[0] == PackageManager.PERMISSION_GRANTED && isDownloading) {
- download();
+ mediaDownloader.download(imgurMedia.getLink(), imgurMedia.getFileName(), getContext());
}
isDownloading = false;
}
}
- private void download() {
- DownloadManager.Request request = new DownloadManager.Request(Uri.parse(imgurMedia.getLink()));
- request.setTitle(imgurMedia.getFileName());
-
- request.allowScanningByMediaScanner();
- request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
-
- //Android Q support
- if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, imgurMedia.getFileName());
- } else {
- String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
- File directory = new File(path + "/Infinity/");
- boolean saveToInfinityFolder = true;
- if (!directory.exists()) {
- if (!directory.mkdir()) {
- saveToInfinityFolder = false;
- }
- } else {
- if (directory.isFile()) {
- if (!(directory.delete() && directory.mkdir())) {
- saveToInfinityFolder = false;
- }
- }
- }
-
- if (saveToInfinityFolder) {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + "/Infinity/", imgurMedia.getFileName());
- } else {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, imgurMedia.getFileName());
- }
- }
-
- DownloadManager manager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
-
- if (manager == null) {
- Toast.makeText(activity, R.string.download_failed, Toast.LENGTH_SHORT).show();
- return;
- }
-
- manager.enqueue(request);
- Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
- }
-
@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/Fragment/ViewImgurVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurVideoFragment.java
index 3ec6eb39..dd3853d0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurVideoFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewImgurVideoFragment.java
@@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit.Fragment;
import android.Manifest;
import android.app.Activity;
-import android.app.DownloadManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
@@ -11,7 +10,6 @@ import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
-import android.os.Environment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -42,8 +40,6 @@ import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
-import java.io.File;
-
import javax.inject.Inject;
import javax.inject.Named;
@@ -51,6 +47,8 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ImgurMedia;
import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.MediaDownloader;
+import ml.docilealligator.infinityforreddit.MediaDownloaderImpl;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
@@ -71,6 +69,7 @@ public class ViewImgurVideoFragment extends Fragment {
private ImgurMedia imgurMedia;
private SimpleExoPlayer player;
private DataSource.Factory dataSourceFactory;
+ private MediaDownloader mediaDownloader;
private boolean wasPlaying = false;
private boolean isMute = false;
private boolean isDownloading = false;
@@ -131,6 +130,8 @@ public class ViewImgurVideoFragment extends Fragment {
}
});
+ mediaDownloader = new MediaDownloaderImpl();
+
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(activity, trackSelector);
@@ -190,47 +191,7 @@ public class ViewImgurVideoFragment extends Fragment {
private void download() {
isDownloading = false;
- DownloadManager.Request request = new DownloadManager.Request(Uri.parse(imgurMedia.getLink()));
- request.setTitle(imgurMedia.getFileName());
-
- request.allowScanningByMediaScanner();
- request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
-
- //Android Q support
- if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, imgurMedia.getFileName());
- } else {
- String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
- File directory = new File(path + "/Infinity/");
- boolean saveToInfinityFolder = true;
- if (!directory.exists()) {
- if (!directory.mkdir()) {
- saveToInfinityFolder = false;
- }
- } else {
- if (directory.isFile()) {
- if (!(directory.delete() && directory.mkdir())) {
- saveToInfinityFolder = false;
- }
- }
- }
-
- if (saveToInfinityFolder) {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + "/Infinity/", imgurMedia.getFileName());
- } else {
- request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, imgurMedia.getFileName());
- }
- }
-
- DownloadManager manager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
-
- if (manager == null) {
- Toast.makeText(activity, R.string.download_failed, Toast.LENGTH_SHORT).show();
- return;
- }
-
- manager.enqueue(request);
- Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
+ mediaDownloader.download(imgurMedia.getLink(), imgurMedia.getFileName(), getContext());
}
private void preparePlayer(Bundle savedInstanceState) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewMessagesFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewMessagesFragment.java
new file mode 100644
index 00000000..6d2d7061
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ViewMessagesFragment.java
@@ -0,0 +1,128 @@
+package ml.docilealligator.infinityforreddit.Fragment;
+
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.fragment.app.Fragment;
+import androidx.lifecycle.ViewModelProvider;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+
+import com.bumptech.glide.RequestManager;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import ml.docilealligator.infinityforreddit.Adapter.MessageRecyclerViewAdapter;
+import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.FetchMessages;
+import ml.docilealligator.infinityforreddit.FragmentCommunicator;
+import ml.docilealligator.infinityforreddit.MessageViewModel;
+import ml.docilealligator.infinityforreddit.NetworkState;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import retrofit2.Retrofit;
+
+public class ViewMessagesFragment extends Fragment implements FragmentCommunicator {
+
+ @BindView(R.id.swipe_refresh_layout_view_messages_fragment)
+ SwipeRefreshLayout mSwipeRefreshLayout;
+ @BindView(R.id.recycler_view_view_messages_fragment)
+ RecyclerView mRecyclerView;
+ @BindView(R.id.fetch_messages_info_linear_layout_view_messages_fragment)
+ LinearLayout mFetchMessageInfoLinearLayout;
+ @BindView(R.id.fetch_messages_info_image_view_view_messages_fragment)
+ ImageView mFetchMessageInfoImageView;
+ @BindView(R.id.fetch_messages_info_text_view_view_messages_fragment)
+ TextView mFetchMessageInfoTextView;
+ MessageViewModel mMessageViewModel;
+ @Inject
+ @Named("oauth")
+ Retrofit mOauthRetrofit;
+ @Inject
+ RedditDataRoomDatabase mRedditDataRoomDatabase;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ @Inject
+ CustomThemeWrapper mCustomThemeWrapper;
+ private String mAccessToken;
+ private MessageRecyclerViewAdapter mAdapter;
+ private RequestManager mGlide;
+ private LinearLayoutManager mLinearLayoutManager;
+
+ public ViewMessagesFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_view_messages, container, false);
+
+ MessageViewModel.Factory factory = new MessageViewModel.Factory(mOauthRetrofit,
+ getResources().getConfiguration().locale, mAccessToken, FetchMessages.WHERE_INBOX);
+ mMessageViewModel = new ViewModelProvider(this, factory).get(MessageViewModel.class);
+ mMessageViewModel.getMessages().observe(getViewLifecycleOwner(), messages -> mAdapter.submitList(messages));
+
+ mMessageViewModel.hasMessage().observe(getViewLifecycleOwner(), hasMessage -> {
+ mSwipeRefreshLayout.setRefreshing(false);
+ if (hasMessage) {
+ mFetchMessageInfoLinearLayout.setVisibility(View.GONE);
+ } else {
+ mFetchMessageInfoLinearLayout.setOnClickListener(view -> {
+ //Do nothing
+ });
+ showErrorView(R.string.no_messages);
+ }
+ });
+
+ mMessageViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> {
+ if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
+ mSwipeRefreshLayout.setRefreshing(false);
+ } else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) {
+ mSwipeRefreshLayout.setRefreshing(false);
+ mFetchMessageInfoLinearLayout.setOnClickListener(view -> {
+ mFetchMessageInfoLinearLayout.setVisibility(View.GONE);
+ mMessageViewModel.refresh();
+ mAdapter.setNetworkState(null);
+ });
+ showErrorView(R.string.load_messages_failed);
+ } else {
+ mSwipeRefreshLayout.setRefreshing(true);
+ }
+ });
+
+ mMessageViewModel.getPaginationNetworkState().observe(getViewLifecycleOwner(), networkState -> {
+ mAdapter.setNetworkState(networkState);
+ });
+
+ mSwipeRefreshLayout.setOnRefreshListener(this::onRefresh);
+
+ return rootView;
+ }
+
+ private void showErrorView(int stringResId) {
+ mSwipeRefreshLayout.setRefreshing(false);
+ mFetchMessageInfoLinearLayout.setVisibility(View.VISIBLE);
+ mFetchMessageInfoTextView.setText(stringResId);
+ mGlide.load(R.drawable.error_image).into(mFetchMessageInfoImageView);
+ }
+
+ @Override
+ public void applyTheme() {
+
+ }
+
+ private void onRefresh() {
+ mMessageViewModel.refresh();
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
index 90478a08..04edd825 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
@@ -17,6 +17,7 @@ import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.BroadcastReceiver.NetworkWifiStatusReceiver;
import ml.docilealligator.infinityforreddit.Event.ChangeWifiStatusEvent;
import ml.docilealligator.infinityforreddit.Utils.Utils;
+import ml.docilealligator.inifinityforreddit.EventBusIndex;
public class Infinity extends Application {
private AppComponent mAppComponent;
@@ -42,6 +43,8 @@ public class Infinity extends Application {
}
});
+ EventBus.builder().addIndex(new EventBusIndex()).installDefaultEventBus();
+
mNetworkWifiStatusReceiver =
new NetworkWifiStatusReceiver(() -> EventBus.getDefault().post(new ChangeWifiStatusEvent(Utils.isConnectedToWifi(getApplicationContext()))));
registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MediaDownloader.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MediaDownloader.java
new file mode 100644
index 00000000..9967a6a4
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MediaDownloader.java
@@ -0,0 +1,7 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.content.Context;
+
+public interface MediaDownloader {
+ void download(String url, String fileName, Context ctx);
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MediaDownloaderImpl.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MediaDownloaderImpl.java
new file mode 100644
index 00000000..638bdf93
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MediaDownloaderImpl.java
@@ -0,0 +1,58 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.app.DownloadManager;
+import android.content.Context;
+import android.net.Uri;
+import android.os.Build;
+import android.os.Environment;
+import android.widget.Toast;
+
+import java.io.File;
+
+public class MediaDownloaderImpl implements MediaDownloader {
+
+ @Override
+ public void download(String url, String fileName, Context ctx) {
+ DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
+ request.setTitle(fileName);
+
+ request.allowScanningByMediaScanner();
+ request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
+
+ //Android Q support
+ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
+ request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, fileName);
+ } else {
+ String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
+ File directory = new File(path + "/Infinity/");
+ boolean saveToInfinityFolder = true;
+ if (!directory.exists()) {
+ if (!directory.mkdir()) {
+ saveToInfinityFolder = false;
+ }
+ } else {
+ if (directory.isFile()) {
+ if (!(directory.delete() && directory.mkdir())) {
+ saveToInfinityFolder = false;
+ }
+ }
+ }
+
+ if (saveToInfinityFolder) {
+ request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES + "/Infinity/", fileName);
+ } else {
+ request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, fileName);
+ }
+ }
+
+ DownloadManager manager = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE);
+
+ if (manager == null) {
+ Toast.makeText(ctx, R.string.download_failed, Toast.LENGTH_SHORT).show();
+ return;
+ }
+
+ manager.enqueue(request);
+ Toast.makeText(ctx, R.string.download_started, Toast.LENGTH_SHORT).show();
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java
index 7d74afce..66fd7647 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MessageDataSource.java
@@ -15,6 +15,7 @@ class MessageDataSource extends PageKeyedDataSource<String, Message> {
private Locale locale;
private String accessToken;
private String where;
+ private int messageType;
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
private MutableLiveData<NetworkState> initialLoadStateLiveData;
@@ -28,6 +29,11 @@ class MessageDataSource extends PageKeyedDataSource<String, Message> {
this.locale = locale;
this.accessToken = accessToken;
this.where = where;
+ if (where.equals(FetchMessages.WHERE_MESSAGES)) {
+ messageType = FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE;
+ } else {
+ messageType = FetchMessages.MESSAGE_TYPE_NOTIFICATION;
+ }
paginationNetworkStateLiveData = new MutableLiveData<>();
initialLoadStateLiveData = new MutableLiveData<>();
hasPostLiveData = new MutableLiveData<>();
@@ -53,7 +59,8 @@ class MessageDataSource extends PageKeyedDataSource<String, Message> {
public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull LoadInitialCallback<String, Message> callback) {
initialLoadStateLiveData.postValue(NetworkState.LOADING);
- FetchMessages.fetchMessagesAsync(oauthRetrofit, locale, accessToken, where, null, new FetchMessages.FetchMessagesListener() {
+ FetchMessages.fetchInbox(oauthRetrofit, locale, accessToken, where, null, messageType,
+ new FetchMessages.FetchMessagesListener() {
@Override
public void fetchSuccess(ArrayList<Message> messages, @Nullable String after) {
if (messages.size() == 0) {
@@ -89,7 +96,8 @@ class MessageDataSource extends PageKeyedDataSource<String, Message> {
paginationNetworkStateLiveData.postValue(NetworkState.LOADING);
- FetchMessages.fetchMessagesAsync(oauthRetrofit, locale, accessToken, where, params.key, new FetchMessages.FetchMessagesListener() {
+ FetchMessages.fetchInbox(oauthRetrofit, locale, accessToken, where, params.key, messageType,
+ new FetchMessages.FetchMessagesListener() {
@Override
public void fetchSuccess(ArrayList<Message> messages, @Nullable String after) {
if (after == null || after.equals("") || after.equals("null")) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/FavoriteMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/FavoriteMultiReddit.java
index 54142d08..8c976245 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/FavoriteMultiReddit.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/FavoriteMultiReddit.java
@@ -2,12 +2,11 @@ package ml.docilealligator.infinityforreddit.MultiReddit;
import androidx.annotation.NonNull;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
-import ml.docilealligator.infinityforreddit.AsyncTask.InsertMultiRedditAsyncTask;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
+import ml.docilealligator.infinityforreddit.AsyncTask.InsertMultiRedditAsyncTask;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
import retrofit2.Call;
@@ -22,7 +21,7 @@ public class FavoriteMultiReddit {
}
public static void favoriteMultiReddit(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
- String accessToken, String accountName, boolean makeFavorite,
+ String accessToken, boolean makeFavorite,
MultiReddit multiReddit, FavoriteMultiRedditListener favoriteMultiRedditListener) {
Map<String, String> params = new HashMap<>();
params.put(APIUtils.MULTIPATH_KEY, multiReddit.getPath());
@@ -33,10 +32,8 @@ public class FavoriteMultiReddit {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {
- multiReddit.setFavorite(true);
- ArrayList<MultiReddit> singleMultiRedditList = new ArrayList<>();
- singleMultiRedditList.add(multiReddit);
- new InsertMultiRedditAsyncTask(redditDataRoomDatabase, singleMultiRedditList, accountName,
+ multiReddit.setFavorite(makeFavorite);
+ new InsertMultiRedditAsyncTask(redditDataRoomDatabase, multiReddit,
favoriteMultiRedditListener::success).execute();
} else {
favoriteMultiRedditListener.failed();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java
index 73854808..23bd9910 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java
@@ -10,6 +10,7 @@ import java.util.ArrayList;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
class ParseSubredditData {
static void parseSubredditData(String response, ParseSubredditDataListener parseSubredditDataListener) {
@@ -24,7 +25,7 @@ class ParseSubredditData {
String id = subredditDataJsonObject.getString(JSONUtils.NAME_KEY);
String subredditFullName = subredditDataJsonObject.getString(JSONUtils.DISPLAY_NAME_KEY);
String description = subredditDataJsonObject.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
- String sidebarDescription = subredditDataJsonObject.getString(JSONUtils.DESCRIPTION_KEY).trim();
+ String sidebarDescription = Utils.modifyMarkdown(subredditDataJsonObject.getString(JSONUtils.DESCRIPTION_KEY).trim());
long createdUTC = subredditDataJsonObject.getLong(JSONUtils.CREATED_UTC_KEY) * 1000;
String bannerImageUrl;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java
index a05a97f2..3a345572 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java
@@ -252,6 +252,11 @@ public class Post implements Parcelable {
return author;
}
+ public void setAuthor(String author) {
+ this.author = author;
+ this.authorNamePrefixed = "u/" + author;
+ }
+
public String getAuthorNamePrefixed() {
return authorNamePrefixed;
}
@@ -320,6 +325,10 @@ public class Post implements Parcelable {
return thumbnailPreviewUrl;
}
+ public void setThumbnailPreviewUrl(String thumbnailPreviewUrl) {
+ this.thumbnailPreviewUrl = thumbnailPreviewUrl;
+ }
+
public String getUrl() {
return url;
}
@@ -524,4 +533,9 @@ public class Post implements Parcelable {
}
return ((Post) obj).id.equals(id);
}
-} \ No newline at end of file
+
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+}
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 9e27bce1..7b4762a6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/SubmitPost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/SubmitPost.java
@@ -21,6 +21,7 @@ import java.util.Locale;
import java.util.Map;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
+import ml.docilealligator.infinityforreddit.Flair;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
import okhttp3.MediaType;
@@ -34,7 +35,7 @@ import retrofit2.Retrofit;
public class SubmitPost {
public static void submitTextOrLinkPost(Retrofit oauthRetrofit, String accessToken,
Locale locale, String subredditName, String title, String content,
- String flair, boolean isSpoiler, boolean isNSFW, String kind,
+ Flair flair, boolean isSpoiler, boolean isNSFW, String kind,
SubmitPostListener submitPostListener) {
submitPost(oauthRetrofit, accessToken, locale, subredditName, title, content,
flair, isSpoiler, isNSFW, kind, null, submitPostListener);
@@ -42,7 +43,7 @@ public class SubmitPost {
public static void submitImagePost(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit,
String accessToken, Locale locale,
- String subredditName, String title, Bitmap image, String flair,
+ String subredditName, String title, Bitmap image, Flair flair,
boolean isSpoiler, boolean isNSFW, SubmitPostListener submitPostListener) {
uploadImage(oauthRetrofit, uploadMediaRetrofit, accessToken, image,
new UploadImageListener() {
@@ -63,7 +64,7 @@ public class SubmitPost {
public static void submitVideoPost(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit,
Retrofit uploadVideoRetrofit, String accessToken,
Locale locale, String subredditName, String title, byte[] buffer, String mimeType,
- Bitmap posterBitmap, String flair, boolean isSpoiler, boolean isNSFW,
+ Bitmap posterBitmap, Flair flair, boolean isSpoiler, boolean isNSFW,
SubmitPostListener submitPostListener) {
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
@@ -157,7 +158,7 @@ public class SubmitPost {
private static void submitPost(Retrofit oauthRetrofit, String accessToken,
Locale locale, String subredditName, String title, String content,
- String flair, boolean isSpoiler, boolean isNSFW, String kind,
+ Flair flair, boolean isSpoiler, boolean isNSFW, String kind,
@Nullable String posterUrl, SubmitPostListener submitPostListener) {
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
@@ -186,7 +187,8 @@ public class SubmitPost {
}
if (flair != null) {
- params.put(APIUtils.FLAIR_TEXT_KEY, flair);
+ params.put(APIUtils.FLAIR_TEXT_KEY, flair.getText());
+ params.put(APIUtils.FLAIR_ID_KEY, flair.getId());
}
params.put(APIUtils.SPOILER_KEY, Boolean.toString(isSpoiler));
params.put(APIUtils.NSFW_KEY, Boolean.toString(isNSFW));
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
index 214a9736..2473d074 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java
@@ -74,7 +74,8 @@ public class PullNotificationWorker extends Worker {
if (response != null && response.isSuccessful()) {
String responseBody = response.body();
- ArrayList<Message> messages = FetchMessages.parseMessage(responseBody, context.getResources().getConfiguration().locale);
+ ArrayList<Message> messages = FetchMessages.parseMessage(responseBody,
+ context.getResources().getConfiguration().locale, FetchMessages.MESSAGE_TYPE_NOTIFICATION);
if (messages != null && !messages.isEmpty()) {
NotificationManagerCompat notificationManager = NotificationUtils.getNotificationManager(context);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadRedditVideoService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadRedditVideoService.java
index 3da24433..b958eba2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadRedditVideoService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/DownloadRedditVideoService.java
@@ -397,7 +397,7 @@ public class DownloadRedditVideoService extends Service {
int audioTrack = muxer.addTrack(audioFormat);
boolean sawEOS = false;
int offset = 100;
- int sampleSize = 256 * 1024;
+ int sampleSize = 2048 * 1024;
ByteBuffer videoBuf = ByteBuffer.allocate(sampleSize);
ByteBuffer audioBuf = ByteBuffer.allocate(sampleSize);
MediaCodec.BufferInfo videoBufferInfo = new MediaCodec.BufferInfo();
@@ -412,7 +412,6 @@ public class DownloadRedditVideoService extends Service {
videoBufferInfo.offset = offset;
videoBufferInfo.size = videoExtractor.readSampleData(videoBuf, offset);
-
if (videoBufferInfo.size < 0 || audioBufferInfo.size < 0) {
sawEOS = true;
videoBufferInfo.size = 0;
@@ -441,8 +440,10 @@ public class DownloadRedditVideoService extends Service {
}
}
- muxer.stop();
- muxer.release();
+ try {
+ muxer.stop();
+ muxer.release();
+ } catch (IllegalStateException ignore) {}
} catch (IOException e) {
e.printStackTrace();
return false;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Service/SubmitPostService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/SubmitPostService.java
index 5177e415..eb8ffd3c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Service/SubmitPostService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/SubmitPostService.java
@@ -34,11 +34,12 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.SubmitImagePostEvent;
import ml.docilealligator.infinityforreddit.Event.SubmitTextOrLinkPostEvent;
import ml.docilealligator.infinityforreddit.Event.SubmitVideoPostEvent;
+import ml.docilealligator.infinityforreddit.Flair;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.NotificationUtils;
import ml.docilealligator.infinityforreddit.Post.Post;
-import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Post.SubmitPost;
+import ml.docilealligator.infinityforreddit.R;
import retrofit2.Retrofit;
public class SubmitPostService extends Service {
@@ -68,7 +69,7 @@ public class SubmitPostService extends Service {
private String mAccessToken;
private String subredditName;
private String title;
- private String flair;
+ private Flair flair;
private boolean isSpoiler;
private boolean isNSFW;
private String content;
@@ -90,7 +91,7 @@ public class SubmitPostService extends Service {
mAccessToken = intent.getStringExtra(EXTRA_ACCESS_TOKEN);
subredditName = intent.getStringExtra(EXTRA_SUBREDDIT_NAME);
title = intent.getStringExtra(EXTRA_TITLE);
- flair = intent.getStringExtra(EXTRA_FLAIR);
+ flair = intent.getParcelableExtra(EXTRA_FLAIR);
isSpoiler = intent.getBooleanExtra(EXTRA_IS_SPOILER, false);
isNSFW = intent.getBooleanExtra(EXTRA_IS_NSFW, false);
int postType = intent.getIntExtra(EXTRA_POST_TYPE, EXTRA_POST_TEXT_OR_LINK);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SetAsWallpaperCallback.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SetAsWallpaperCallback.java
new file mode 100644
index 00000000..7fb6e324
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SetAsWallpaperCallback.java
@@ -0,0 +1,7 @@
+package ml.docilealligator.infinityforreddit;
+
+public interface SetAsWallpaperCallback {
+ void setToHomeScreen(int viewPagerPosition);
+ void setToLockScreen(int viewPagerPosition);
+ void setToBoth(int viewPagerPosition);
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AboutPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AboutPreferenceFragment.java
index 3d81bb30..71e9dbc6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AboutPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AboutPreferenceFragment.java
@@ -13,6 +13,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity;
+import ml.docilealligator.infinityforreddit.BuildConfig;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
@@ -34,6 +35,7 @@ public class AboutPreferenceFragment extends PreferenceFragmentCompat {
Preference redditAccountPreference = findPreference(SharedPreferencesUtils.REDDIT_ACCOUNT_KEY);
Preference subredditPreference = findPreference(SharedPreferencesUtils.SUBREDDIT_KEY);
Preference sharePreference = findPreference(SharedPreferencesUtils.SHARE_KEY);
+ Preference versionPreference = findPreference(SharedPreferencesUtils.VERSION_KEY);
if (openSourcePreference != null) {
openSourcePreference.setOnPreferenceClickListener(preference -> {
@@ -112,6 +114,24 @@ public class AboutPreferenceFragment extends PreferenceFragmentCompat {
return true;
});
}
+
+ if (versionPreference != null) {
+ versionPreference.setSummary(getString(R.string.settings_version_summary, BuildConfig.VERSION_NAME));
+
+ versionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ int clickedTimes = 0;
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ clickedTimes++;
+ if (clickedTimes > 6) {
+ Toast.makeText(activity, R.string.no_developer_easter_egg, Toast.LENGTH_SHORT).show();
+ clickedTimes = 0;
+ }
+ return true;
+ }
+ });
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CreditsPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CreditsPreferenceFragment.java
index 8607b486..3bb14843 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CreditsPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CreditsPreferenceFragment.java
@@ -32,6 +32,7 @@ public class CreditsPreferenceFragment extends PreferenceFragmentCompat {
Preference gildedIconPreference = findPreference(SharedPreferencesUtils.GILDED_ICON_KEY);
Preference crosspostIconPreference = findPreference(SharedPreferencesUtils.CROSSPOST_ICON_KEY);
Preference thumbtackIconPreference = findPreference(SharedPreferencesUtils.THUMBTACK_ICON_KEY);
+ Preference bestRocketIconPreference = findPreference(SharedPreferencesUtils.BEST_ROCKET_ICON_KEY);
Preference materialIconsPreference = findPreference(SharedPreferencesUtils.MATERIAL_ICONS_KEY);
if (iconForegroundPreference != null) {
@@ -88,6 +89,15 @@ public class CreditsPreferenceFragment extends PreferenceFragmentCompat {
});
}
+ if (bestRocketIconPreference != null) {
+ bestRocketIconPreference.setOnPreferenceClickListener(preference -> {
+ Intent intent = new Intent(activity, LinkResolverActivity.class);
+ intent.setData(Uri.parse("https://www.flaticon.com/free-icon/spring-swing-rocket_2929322?term=space%20ship&page=1&position=18"));
+ startActivity(intent);
+ return true;
+ });
+ }
+
if (materialIconsPreference != null) {
materialIconsPreference.setOnPreferenceClickListener(preference -> {
Intent intent = new Intent(activity, LinkResolverActivity.class);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java
index 01e2c28e..33ad2ea9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/CustomizeMainPageTabsFragment.java
@@ -5,7 +5,6 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
@@ -33,12 +32,6 @@ public class CustomizeMainPageTabsFragment extends PreferenceFragmentCompat {
private SettingsActivity activity;
@Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- }
-
- @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.customize_main_page_tabs_preferences, rootKey);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontSizePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontPreferenceFragment.java
index 5d4a0a5a..78ae7d82 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontSizePreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontPreferenceFragment.java
@@ -14,16 +14,41 @@ import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
-public class FontSizePreferenceFragment extends PreferenceFragmentCompat {
+public class FontPreferenceFragment extends PreferenceFragmentCompat {
private Activity activity;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- setPreferencesFromResource(R.xml.font_size_preferences, rootKey);
+ setPreferencesFromResource(R.xml.font_preferences, rootKey);
+ ListPreference fontFamilyPreference = findPreference(SharedPreferencesUtils.FONT_FAMILY_KEY);
+ ListPreference titleFontFamilyPreference = findPreference(SharedPreferencesUtils.TITLE_FONT_FAMILY_KEY);
+ ListPreference contentFontFamilyPreference = findPreference(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY);
ListPreference fontSizePreference = findPreference(SharedPreferencesUtils.FONT_SIZE_KEY);
ListPreference titleFontSizePreference = findPreference(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY);
ListPreference contentFontSizePreference = findPreference(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY);
+ if (fontFamilyPreference != null) {
+ fontFamilyPreference.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new RecreateActivityEvent());
+ activity.recreate();
+ return true;
+ });
+ }
+
+ if (titleFontFamilyPreference != null) {
+ titleFontFamilyPreference.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new RecreateActivityEvent());
+ return true;
+ });
+ }
+
+ if (contentFontFamilyPreference != null) {
+ contentFontFamilyPreference.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new RecreateActivityEvent());
+ return true;
+ });
+ }
+
if (fontSizePreference != null) {
fontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new RecreateActivityEvent());
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontPreviewFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontPreviewFragment.java
new file mode 100644
index 00000000..9cd93e01
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/FontPreviewFragment.java
@@ -0,0 +1,29 @@
+package ml.docilealligator.infinityforreddit.Settings;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.fragment.app.Fragment;
+
+import ml.docilealligator.infinityforreddit.R;
+
+/**
+ * A simple {@link Fragment} subclass.
+ * Use the {@link FontPreviewFragment#newInstance} factory method to
+ * create an instance of this fragment.
+ */
+public class FontPreviewFragment extends Fragment {
+
+ public FontPreviewFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_font_preview, container, false);
+ return rootView;
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ImmersiveInterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ImmersiveInterfacePreferenceFragment.java
new file mode 100644
index 00000000..c9f95e98
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ImmersiveInterfacePreferenceFragment.java
@@ -0,0 +1,53 @@
+package ml.docilealligator.infinityforreddit.Settings;
+
+import android.os.Build;
+import android.os.Bundle;
+
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.SwitchPreference;
+
+import org.greenrobot.eventbus.EventBus;
+
+import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+
+public class ImmersiveInterfacePreferenceFragment extends PreferenceFragmentCompat {
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ setPreferencesFromResource(R.xml.immersive_interface_preferences, rootKey);
+
+ SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY);
+ SwitchPreference immersiveInterfaceIgnoreNavBarSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY);
+
+ if (immersiveInterfaceSwitch != null && immersiveInterfaceIgnoreNavBarSwitch != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ immersiveInterfaceSwitch.setVisible(true);
+ immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
+ if ((Boolean) newValue) {
+ immersiveInterfaceIgnoreNavBarSwitch.setVisible(true);
+ } else {
+ immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
+ }
+ EventBus.getDefault().post(new RecreateActivityEvent());
+ return true;
+ });
+
+ if (immersiveInterfaceSwitch.isChecked()) {
+ immersiveInterfaceIgnoreNavBarSwitch.setVisible(true);
+ } else {
+ immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
+ }
+
+ immersiveInterfaceIgnoreNavBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new RecreateActivityEvent());
+ return true;
+ });
+ } else {
+ immersiveInterfaceSwitch.setVisible(false);
+ immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java
index c3c21c1c..85ba2a5e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java
@@ -1,10 +1,8 @@
package ml.docilealligator.infinityforreddit.Settings;
-import android.os.Build;
import android.os.Bundle;
-import androidx.fragment.app.Fragment;
import androidx.preference.ListPreference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
@@ -17,56 +15,24 @@ import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPreferenceEvent;
+import ml.docilealligator.infinityforreddit.Event.ShowThumbnailOnTheRightInCompactLayoutEvent;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
-/**
- * A simple {@link Fragment} subclass.
- */
public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.interface_preference, rootKey);
- SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY);
- SwitchPreference immersiveInterfaceIgnoreNavBarSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY);
SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY);
SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY);
SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY);
ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY);
SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT);
+ SwitchPreference showThumbnailOnTheRightInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_RIGHT_IN_COMPACT_LAYOUT);
SwitchPreference showAbsoluteNumberOfVotes = findPreference(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES);
- if (immersiveInterfaceSwitch != null && immersiveInterfaceIgnoreNavBarSwitch != null) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- immersiveInterfaceSwitch.setVisible(true);
- immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
- if ((Boolean) newValue) {
- immersiveInterfaceIgnoreNavBarSwitch.setVisible(true);
- } else {
- immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
- }
- EventBus.getDefault().post(new RecreateActivityEvent());
- return true;
- });
-
- if (immersiveInterfaceSwitch.isChecked()) {
- immersiveInterfaceIgnoreNavBarSwitch.setVisible(true);
- } else {
- immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
- }
-
- immersiveInterfaceIgnoreNavBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
- EventBus.getDefault().post(new RecreateActivityEvent());
- return true;
- });
- } else {
- immersiveInterfaceSwitch.setVisible(false);
- immersiveInterfaceIgnoreNavBarSwitch.setVisible(false);
- }
- }
-
if (bottomAppBarSwitch != null) {
bottomAppBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new RecreateActivityEvent());
@@ -102,6 +68,13 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
});
}
+ if (showThumbnailOnTheRightInCompactLayout != null) {
+ showThumbnailOnTheRightInCompactLayout.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new ShowThumbnailOnTheRightInCompactLayoutEvent((Boolean) newValue));
+ return true;
+ });
+ }
+
if (showAbsoluteNumberOfVotes != null) {
showAbsoluteNumberOfVotes.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeShowAbsoluteNumberOfVotesEvent((Boolean) newValue));
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AutoplayPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/VideoPreferenceFragment.java
index 91bd52d7..e7cd2432 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AutoplayPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/VideoPreferenceFragment.java
@@ -9,17 +9,19 @@ import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.Event.ChangeAutoplayNsfwVideosEvent;
+import ml.docilealligator.infinityforreddit.Event.ChangeMuteAutoplayingVideosEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
-public class AutoplayPreferenceFragment extends PreferenceFragmentCompat {
+public class VideoPreferenceFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- setPreferencesFromResource(R.xml.autoplay_preferences, rootKey);
+ setPreferencesFromResource(R.xml.video_preferences, rootKey);
ListPreference videoAutoplayListPreference = findPreference(SharedPreferencesUtils.VIDEO_AUTOPLAY);
+ SwitchPreference muteAutoplayingVideosSwitchPreference = findPreference(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS);
SwitchPreference autoplayNsfwVideosSwitchPreference = findPreference(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS);
if (videoAutoplayListPreference != null && autoplayNsfwVideosSwitchPreference != null) {
@@ -33,5 +35,12 @@ public class AutoplayPreferenceFragment extends PreferenceFragmentCompat {
return true;
});
}
+
+ if (muteAutoplayingVideosSwitchPreference != null) {
+ muteAutoplayingVideosSwitchPreference.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new ChangeMuteAutoplayingVideosEvent((Boolean) newValue));
+ return true;
+ });
+ }
}
} \ No newline at end of file
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 a42c1660..89b85bbe 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java
@@ -21,6 +21,7 @@ public class APIUtils {
public static final String GFYCAT_API_BASE_URI = "https://api.gfycat.com/v1/gfycats/";
public static final String REDGIFS_API_BASE_URI = "https://api.redgifs.com/v1/gfycats/";
public static final String IMGUR_API_BASE_URI = "https://api.imgur.com/3/";
+ public static final String PUSHSHIFT_API_BASE_URI = "https://api.pushshift.io/";
public static final String CLIENT_ID_KEY = "client_id";
public static final String CLIENT_ID = "NOe2iKrPPzwscA";
@@ -82,6 +83,7 @@ public class APIUtils {
public static final String LINK_KEY = "link";
public static final String FLAIR_TEMPLATE_ID_KEY = "flair_template_id";
+ public static final String FLAIR_ID_KEY = "flair_id";
public static final String MAKE_FAVORITE_KEY = "make_favorite";
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java
index 04c16284..fc8cfcf9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java
@@ -56,7 +56,7 @@ public class GlideImageGetter implements Html.ImageGetter {
BitmapDrawablePlaceholder drawable = new BitmapDrawablePlaceholder(textSize);
Context context = container.get().getContext();
- if (!(context instanceof Activity && ((Activity) context).isFinishing())) {
+ if (!(context instanceof Activity && ((Activity) context).isDestroyed())) {
container.get().post(() -> Glide.with(context)
.asBitmap()
.load(source)
@@ -118,7 +118,9 @@ public class GlideImageGetter implements Html.ImageGetter {
@Override
public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap> transition) {
- setDrawable(new BitmapDrawable(container.get().getResources(), bitmap));
+ if (container != null) {
+ setDrawable(new BitmapDrawable(container.get().getResources(), bitmap));
+ }
}
@Override
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 a51c9e0b..ee25195d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -18,6 +18,7 @@ public class SharedPreferencesUtils {
public static final String GILDED_ICON_KEY = "gilded_icon";
public static final String CROSSPOST_ICON_KEY = "crosspost_icon";
public static final String THUMBTACK_ICON_KEY = "thumbtack_icon";
+ public static final String BEST_ROCKET_ICON_KEY = "best_rocket_icon";
public static final String MATERIAL_ICONS_KEY = "material_icons";
public static final String OPEN_SOURCE_KEY = "open_source";
public static final String RATE_KEY = "rate";
@@ -26,9 +27,13 @@ public class SharedPreferencesUtils {
public static final String REDDIT_ACCOUNT_KEY = "reddit_account";
public static final String SUBREDDIT_KEY = "subreddit";
public static final String SHARE_KEY = "share";
+ public static final String VERSION_KEY = "version";
public static final String FONT_SIZE_KEY = "font_size";
public static final String TITLE_FONT_SIZE_KEY = "title_font_size";
public static final String CONTENT_FONT_SIZE_KEY = "content_font_size";
+ public static final String FONT_FAMILY_KEY = "font_family";
+ public static final String TITLE_FONT_FAMILY_KEY = "title_font_family";
+ public static final String CONTENT_FONT_FAMILY_KEY = "content_font_family";
public static final String AMOLED_DARK_KEY = "amoled_dark";
public static final String IMMERSIVE_INTERFACE_KEY = "immersive_interface";
public static final String IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY = "immersive_interface_ignore_nav_bar";
@@ -71,6 +76,7 @@ public class SharedPreferencesUtils {
public static final String SHOW_ELAPSED_TIME_KEY = "show_elapsed_time";
public static final String DEFAULT_POST_LAYOUT_KEY = "default_post_layout";
public static final String SHOW_DIVIDER_IN_COMPACT_LAYOUT = "show_divider_in_compact_layout";
+ public static final String SHOW_THUMBNAIL_ON_THE_RIGHT_IN_COMPACT_LAYOUT = "show_thumbnail_on_the_right_in_compact_layout";
public static final String SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL = "swipe_to_go_back_from_post_detail";
public static final String VOLUME_KEYS_NAVIGATE_COMMENTS = "volume_keys_navigate_comments";
public static final String VOLUME_KEYS_NAVIGATE_POSTS = "volume_keys_navigate_posts";
@@ -80,7 +86,9 @@ public class SharedPreferencesUtils {
public static final String VIDEO_AUTOPLAY_VALUE_ALWAYS_ON = "2";
public static final String VIDEO_AUTOPLAY_VALUE_ON_WIFI = "1";
public static final String VIDEO_AUTOPLAY_VALUE_NEVER = "0";
+ public static final String MUTE_AUTOPLAYING_VIDEOS = "mute_autoplaying_videos";
public static final String AUTOPLAY_NSFW_VIDEOS = "autoplay_nsfw_videos";
+ public static final String AUTOMATICALLY_TRY_REDGIFS = "automatically_try_redgifs";
public static final String LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON = "lock_jump_to_next_top_level_comment_button";
public static final String SWAP_TAP_AND_LONG_COMMENTS = "swap_tap_and_long_in_comments";
public static final String SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON = "swipe_up_to_hide_jump_to_next_top_level_comments_button";
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 329371dc..52a1972a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
@@ -7,6 +7,7 @@ import android.net.Network;
import android.net.NetworkInfo;
import android.text.Html;
import android.text.Spannable;
+import android.util.DisplayMetrics;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
@@ -126,4 +127,8 @@ public class Utils {
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
}
+
+ public static float convertDpToPixel(float dp, Context context){
+ return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/WallpaperSetter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/WallpaperSetter.java
new file mode 100644
index 00000000..f1407bab
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/WallpaperSetter.java
@@ -0,0 +1,46 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.app.WallpaperManager;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.drawable.Drawable;
+import android.view.WindowManager;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.request.target.CustomTarget;
+import com.bumptech.glide.request.transition.Transition;
+
+import ml.docilealligator.infinityforreddit.AsyncTask.SetAsWallpaperAsyncTask;
+
+public class WallpaperSetter {
+ public static final int HOME_SCREEN = 0;
+ public static final int LOCK_SCREEN = 1;
+ public static final int BOTH_SCREENS = 2;
+
+ public static void set(String url, int setTo, Context context, SetWallpaperListener setWallpaperListener) {
+ Toast.makeText(context, R.string.save_image_first, Toast.LENGTH_SHORT).show();
+ WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
+ WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+
+ Glide.with(context).asBitmap().load(url).into(new CustomTarget<Bitmap>() {
+ @Override
+ public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
+ new SetAsWallpaperAsyncTask(resource, setTo, wallpaperManager, windowManager, setWallpaperListener).execute();
+ }
+
+ @Override
+ public void onLoadCleared(@Nullable Drawable placeholder) {
+
+ }
+ });
+ }
+
+ public interface SetWallpaperListener {
+ void success();
+ void failed();
+ }
+}