From b2fb513cc48f7d704e0e557f076d9047b06e66cd Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sun, 15 Sep 2024 19:36:17 -0400 Subject: Rearrange files and packages. --- .../AccessTokenAuthenticator.java | 103 -------------- .../ActivityToolbarInterface.java | 6 - .../AnyAccountAccessTokenAuthenticator.java | 106 -------------- .../AppBarStateChangeListener.java | 48 ------- .../CustomThemeWrapperReceiver.java | 7 - .../infinityforreddit/DeleteThing.java | 41 ------ .../infinityforreddit/FavoriteThing.java | 153 -------------------- .../infinityforreddit/FetchFlairs.java | 103 -------------- .../infinityforreddit/FetchMyInfo.java | 97 ------------- .../infinityforreddit/FetchRedgifsVideoLinks.java | 76 ---------- .../infinityforreddit/FetchRules.java | 86 ------------ .../infinityforreddit/FetchStreamableVideo.java | 98 ------------- .../infinityforreddit/FetchSubscribedThing.java | 74 ---------- .../infinityforreddit/FetchUserFlairs.java | 122 ---------------- .../docilealligator/infinityforreddit/Flair.java | 80 ----------- .../infinityforreddit/FragmentCommunicator.java | 54 -------- .../infinityforreddit/ImgurMedia.java | 84 ----------- .../infinityforreddit/LoadingMorePostsStatus.java | 16 --- .../infinityforreddit/MarkPostAsReadInterface.java | 7 - .../infinityforreddit/MediaMetadata.java | 122 ---------------- .../infinityforreddit/NetworkModule.java | 2 + .../infinityforreddit/ParseSubscribedThing.java | 138 ------------------ .../infinityforreddit/PollPayload.java | 71 ---------- .../infinityforreddit/RedditGalleryPayload.java | 115 --------------- .../RedgifsAccessTokenAuthenticator.java | 89 ------------ .../ReplyNotificationsToggle.java | 45 ------ .../infinityforreddit/ReportReason.java | 90 ------------ .../infinityforreddit/ReportThing.java | 55 -------- .../ml/docilealligator/infinityforreddit/Rule.java | 19 --- .../infinityforreddit/SaveThing.java | 63 --------- .../infinityforreddit/SelectThingReturnKey.java | 21 --- .../infinityforreddit/SelectUserFlair.java | 103 -------------- .../infinityforreddit/SortType.java | 73 ---------- .../SortTypeSelectionCallback.java | 9 -- .../infinityforreddit/StreamableVideo.java | 29 ---- .../infinityforreddit/TrendingSearch.java | 54 -------- .../UploadImageEnabledActivity.java | 7 - .../infinityforreddit/UploadedImage.java | 68 --------- .../infinityforreddit/UserFlair.java | 78 ----------- .../infinityforreddit/VoteThing.java | 94 ------------- .../infinityforreddit/account/FetchMyInfo.java | 98 +++++++++++++ .../activities/AccountPostsActivity.java | 7 +- .../activities/AccountSavedThingActivity.java | 3 +- .../activities/ActivityToolbarInterface.java | 6 + .../activities/AppBarStateChangeListener.java | 48 +++++++ .../infinityforreddit/activities/BaseActivity.java | 2 - .../activities/CommentActivity.java | 5 +- .../activities/CustomThemePreviewActivity.java | 1 - .../activities/EditCommentActivity.java | 5 +- .../activities/EditPostActivity.java | 3 +- .../activities/FilteredPostsActivity.java | 9 +- .../activities/HistoryActivity.java | 1 - .../activities/InboxActivity.java | 3 +- .../activities/LoginActivity.java | 2 +- .../activities/LoginChromeCustomTabActivity.java | 2 +- .../infinityforreddit/activities/MainActivity.java | 9 +- .../activities/PostGalleryActivity.java | 7 +- .../activities/PostImageActivity.java | 4 +- .../activities/PostLinkActivity.java | 4 +- .../activities/PostPollActivity.java | 10 +- .../activities/PostTextActivity.java | 7 +- .../activities/PostVideoActivity.java | 4 +- .../activities/ReportActivity.java | 8 +- .../activities/RulesActivity.java | 4 +- .../activities/SearchActivity.java | 2 +- .../activities/SearchResultActivity.java | 9 +- .../activities/SearchSubredditsResultActivity.java | 1 - .../activities/SearchUsersResultActivity.java | 1 - .../activities/SelectUserFlairActivity.java | 7 +- .../SelectedSubredditsAndUsersActivity.java | 3 +- .../activities/SubmitCrosspostActivity.java | 4 +- .../SubredditMultiselectionActivity.java | 1 - .../activities/SubscribedThingListingActivity.java | 7 +- .../activities/UploadImageEnabledActivity.java | 9 ++ .../activities/ViewImgurMediaActivity.java | 2 +- .../activities/ViewMultiRedditDetailActivity.java | 11 +- .../activities/ViewPostDetailActivity.java | 9 +- .../activities/ViewPrivateMessagesActivity.java | 1 - .../activities/ViewSubredditDetailActivity.java | 10 +- .../activities/ViewUserDetailActivity.java | 12 +- .../activities/ViewVideoActivity.java | 6 +- .../CommentsListingRecyclerViewAdapter.java | 4 +- .../adapters/CommentsRecyclerViewAdapter.java | 6 +- .../FlairBottomSheetRecyclerViewAdapter.java | 2 +- .../adapters/FollowedUsersRecyclerViewAdapter.java | 2 +- .../adapters/HistoryPostRecyclerViewAdapter.java | 10 +- .../adapters/PostDetailRecyclerViewAdapter.java | 10 +- .../adapters/PostRecyclerViewAdapter.java | 12 +- ...RedditGallerySubmissionRecyclerViewAdapter.java | 2 +- .../adapters/ReportReasonRecyclerViewAdapter.java | 2 +- .../adapters/RulesRecyclerViewAdapter.java | 2 +- .../SearchActivityRecyclerViewAdapter.java | 2 +- .../SubscribedSubredditsRecyclerViewAdapter.java | 2 +- .../UploadedImagesRecyclerViewAdapter.java | 2 +- .../adapters/UserFlairRecyclerViewAdapter.java | 2 +- .../infinityforreddit/apis/RedditAPI.java | 2 +- .../CommentMoreBottomSheetFragment.java | 2 +- .../FlairBottomSheetFragment.java | 4 +- .../PostCommentSortTypeBottomSheetFragment.java | 4 +- .../SearchPostSortTypeBottomSheetFragment.java | 4 +- ...serAndSubredditSortTypeBottomSheetFragment.java | 4 +- .../SortTimeBottomSheetFragment.java | 4 +- .../SortTypeBottomSheetFragment.java | 4 +- .../UploadedImagesBottomSheetFragment.java | 2 +- .../UserThingSortTypeBottomSheetFragment.java | 4 +- .../infinityforreddit/comment/Comment.java | 2 +- .../comment/CommentDataSource.java | 2 +- .../comment/CommentDataSourceFactory.java | 2 +- .../comment/CommentViewModel.java | 2 +- .../infinityforreddit/comment/FetchComment.java | 2 +- .../infinityforreddit/comment/ParseComment.java | 2 +- .../infinityforreddit/comment/SendComment.java | 2 +- .../customtheme/CustomThemeWrapperReceiver.java | 5 + .../customviews/CustomFontEditTextPreference.java | 2 +- .../customviews/CustomFontListPreference.java | 2 +- .../customviews/CustomFontPreference.java | 2 +- .../customviews/CustomFontPreferenceCategory.java | 2 +- .../CustomFontPreferenceFragmentCompat.java | 2 +- .../customviews/CustomFontSeekBarPreference.java | 2 +- .../customviews/CustomFontSwitchPreference.java | 2 +- .../events/FlairSelectedEvent.java | 2 +- ...ovidePostListToViewPostDetailActivityEvent.java | 2 +- .../fragments/CommentsListingFragment.java | 5 +- .../fragments/FollowedUsersListingFragment.java | 3 +- .../fragments/FragmentCommunicator.java | 54 ++++++++ .../fragments/HistoryPostFragment.java | 1 - .../infinityforreddit/fragments/InboxFragment.java | 1 - .../fragments/MorePostsInfoFragment.java | 2 +- .../fragments/MultiRedditListingFragment.java | 3 +- .../infinityforreddit/fragments/PostFragment.java | 5 +- .../fragments/SubredditListingFragment.java | 5 +- .../SubscribedSubredditsListingFragment.java | 3 +- .../fragments/UserListingFragment.java | 5 +- .../fragments/ViewImgurImageFragment.java | 2 +- .../fragments/ViewImgurVideoFragment.java | 2 +- .../fragments/ViewPostDetailFragment.java | 11 +- .../infinityforreddit/markdown/Emote.java | 2 +- .../markdown/EmoteCloseBracketInlineProcessor.java | 2 +- .../infinityforreddit/markdown/EmotePlugin.java | 2 +- .../markdown/ImageAndGifBlock.java | 2 +- .../markdown/ImageAndGifBlockParser.java | 2 +- .../markdown/ImageAndGifEntry.java | 2 +- .../markdown/ImageAndGifPlugin.java | 2 +- .../markdown/RichTextJSONConverter.java | 2 +- .../markdown/UploadedImageBlock.java | 2 +- .../markdown/UploadedImageBlockParser.java | 2 +- .../markdown/UploadedImagePlugin.java | 2 +- .../network/AccessTokenAuthenticator.java | 104 ++++++++++++++ .../AnyAccountAccessTokenAuthenticator.java | 107 ++++++++++++++ .../network/RedgifsAccessTokenAuthenticator.java | 89 ++++++++++++ .../network/SortTypeConverter.java | 2 +- .../network/SortTypeConverterFactory.java | 2 +- .../infinityforreddit/post/FetchRules.java | 87 ++++++++++++ .../post/FetchStreamableVideo.java | 99 +++++++++++++ .../infinityforreddit/post/ImgurMedia.java | 84 +++++++++++ .../post/LoadingMorePostsStatus.java | 16 +++ .../post/MarkPostAsReadInterface.java | 5 + .../infinityforreddit/post/ParsePost.java | 2 +- .../infinityforreddit/post/PollPayload.java | 73 ++++++++++ .../infinityforreddit/post/Post.java | 2 +- .../infinityforreddit/post/PostPagingSource.java | 2 +- .../infinityforreddit/post/PostViewModel.java | 2 +- .../post/RedditGalleryPayload.java | 117 ++++++++++++++++ .../infinityforreddit/post/SubmitPost.java | 2 +- .../recentsearchquery/RecentSearchQuery.java | 2 +- .../services/SubmitPostService.java | 6 +- .../settings/CustomizeMainPageTabsFragment.java | 2 +- .../infinityforreddit/subreddit/FetchFlairs.java | 103 ++++++++++++++ .../subreddit/FetchSubredditData.java | 2 +- .../infinityforreddit/subreddit/Flair.java | 80 +++++++++++ .../infinityforreddit/subreddit/Rule.java | 19 +++ .../subreddit/SubredditListingDataSource.java | 2 +- .../SubredditListingDataSourceFactory.java | 2 +- .../subreddit/SubredditListingViewModel.java | 2 +- .../infinityforreddit/thing/DeleteThing.java | 41 ++++++ .../infinityforreddit/thing/FavoriteThing.java | 154 +++++++++++++++++++++ .../thing/FetchRedgifsVideoLinks.java | 76 ++++++++++ .../thing/FetchSubscribedThing.java | 74 ++++++++++ .../infinityforreddit/thing/MediaMetadata.java | 122 ++++++++++++++++ .../thing/ParseSubscribedThing.java | 138 ++++++++++++++++++ .../thing/ReplyNotificationsToggle.java | 45 ++++++ .../infinityforreddit/thing/ReportReason.java | 93 +++++++++++++ .../infinityforreddit/thing/ReportThing.java | 55 ++++++++ .../infinityforreddit/thing/SaveThing.java | 63 +++++++++ .../thing/SelectThingReturnKey.java | 21 +++ .../infinityforreddit/thing/SortType.java | 73 ++++++++++ .../thing/SortTypeSelectionCallback.java | 9 ++ .../infinityforreddit/thing/StreamableVideo.java | 29 ++++ .../infinityforreddit/thing/TrendingSearch.java | 54 ++++++++ .../infinityforreddit/thing/UploadedImage.java | 68 +++++++++ .../infinityforreddit/thing/VoteThing.java | 94 +++++++++++++ .../infinityforreddit/user/FetchUserData.java | 2 +- .../infinityforreddit/user/FetchUserFlairs.java | 122 ++++++++++++++++ .../infinityforreddit/user/SelectUserFlair.java | 103 ++++++++++++++ .../infinityforreddit/user/UserFlair.java | 78 +++++++++++ .../user/UserListingDataSource.java | 2 +- .../user/UserListingDataSourceFactory.java | 2 +- .../user/UserListingViewModel.java | 2 +- .../infinityforreddit/utils/JSONUtils.java | 2 +- .../infinityforreddit/utils/Utils.java | 6 +- 200 files changed, 2912 insertions(+), 2939 deletions(-) delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/AnyAccountAccessTokenAuthenticator.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/AppBarStateChangeListener.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/CustomThemeWrapperReceiver.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/DeleteThing.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FetchFlairs.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FetchMyInfo.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FetchRedgifsVideoLinks.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FetchStreamableVideo.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FetchUserFlairs.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Flair.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/ImgurMedia.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/LoadingMorePostsStatus.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/MarkPostAsReadInterface.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/MediaMetadata.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/PollPayload.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/RedditGalleryPayload.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/RedgifsAccessTokenAuthenticator.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/ReplyNotificationsToggle.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/ReportReason.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/ReportThing.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Rule.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SaveThing.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SelectThingReturnKey.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SelectUserFlair.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeSelectionCallback.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/StreamableVideo.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/TrendingSearch.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/UploadImageEnabledActivity.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/UploadedImage.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/UserFlair.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/account/FetchMyInfo.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/activities/ActivityToolbarInterface.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/activities/AppBarStateChangeListener.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/activities/UploadImageEnabledActivity.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomThemeWrapperReceiver.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FragmentCommunicator.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/network/AccessTokenAuthenticator.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/network/AnyAccountAccessTokenAuthenticator.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/network/RedgifsAccessTokenAuthenticator.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRules.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchStreamableVideo.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/post/ImgurMedia.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/post/LoadingMorePostsStatus.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/post/MarkPostAsReadInterface.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/post/PollPayload.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/post/RedditGalleryPayload.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchFlairs.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/Flair.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/Rule.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/DeleteThing.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/FavoriteThing.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/FetchRedgifsVideoLinks.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/FetchSubscribedThing.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/MediaMetadata.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/ParseSubscribedThing.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/ReplyNotificationsToggle.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/ReportReason.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/ReportThing.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/SaveThing.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/SelectThingReturnKey.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/SortType.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/SortTypeSelectionCallback.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/StreamableVideo.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/TrendingSearch.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/UploadedImage.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/thing/VoteThing.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/user/FetchUserFlairs.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/user/SelectUserFlair.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/user/UserFlair.java diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java deleted file mode 100644 index 43003d36..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccessTokenAuthenticator.java +++ /dev/null @@ -1,103 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.content.SharedPreferences; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import ml.docilealligator.infinityforreddit.account.Account; -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import okhttp3.Authenticator; -import okhttp3.Headers; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.Route; -import retrofit2.Call; -import retrofit2.Retrofit; - -class AccessTokenAuthenticator implements Authenticator { - private final Retrofit mRetrofit; - private final RedditDataRoomDatabase mRedditDataRoomDatabase; - private final SharedPreferences mCurrentAccountSharedPreferences; - - AccessTokenAuthenticator(Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase, SharedPreferences currentAccountSharedPreferences) { - mRetrofit = retrofit; - mRedditDataRoomDatabase = accountRoomDatabase; - mCurrentAccountSharedPreferences = currentAccountSharedPreferences; - } - - @Nullable - @Override - public Request authenticate(Route route, @NonNull Response response) { - if (response.code() == 401) { - String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY); - if (accessTokenHeader == null) { - return null; - } - - String accessToken = accessTokenHeader.substring(APIUtils.AUTHORIZATION_BASE.length()); - synchronized (this) { - Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); - if (account == null) { - return null; - } - String accessTokenFromDatabase = account.getAccessToken(); - if (accessToken.equals(accessTokenFromDatabase)) { - String newAccessToken = refreshAccessToken(account); - if (!newAccessToken.equals("")) { - return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(newAccessToken))).build(); - } else { - return null; - } - } else { - return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(accessTokenFromDatabase))).build(); - } - } - } - return null; - } - - private String refreshAccessToken(Account account) { - String refreshToken = mRedditDataRoomDatabase.accountDao().getCurrentAccount().getRefreshToken(); - - RedditAPI api = mRetrofit.create(RedditAPI.class); - - Map params = new HashMap<>(); - params.put(APIUtils.GRANT_TYPE_KEY, APIUtils.GRANT_TYPE_REFRESH_TOKEN); - params.put(APIUtils.REFRESH_TOKEN_KEY, refreshToken); - - Call accessTokenCall = api.getAccessToken(APIUtils.getHttpBasicAuthHeader(), params); - try { - retrofit2.Response response = accessTokenCall.execute(); - if (response.isSuccessful() && response.body() != null) { - JSONObject jsonObject = new JSONObject(response.body()); - String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY); - String newRefreshToken = jsonObject.has(APIUtils.REFRESH_TOKEN_KEY) ? jsonObject.getString(APIUtils.REFRESH_TOKEN_KEY) : null; - if (newRefreshToken == null) { - mRedditDataRoomDatabase.accountDao().updateAccessToken(account.getAccountName(), newAccessToken); - } else { - mRedditDataRoomDatabase.accountDao().updateAccessTokenAndRefreshToken(account.getAccountName(), newAccessToken, newRefreshToken); - } - if (mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT).equals(account.getAccountName())) { - mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, newAccessToken).apply(); - } - - return newAccessToken; - } - return ""; - } catch (IOException | JSONException e) { - e.printStackTrace(); - } - - return ""; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java deleted file mode 100644 index 65280f92..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java +++ /dev/null @@ -1,6 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -public interface ActivityToolbarInterface { - void onLongPress(); - default void displaySortType() {} -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AnyAccountAccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AnyAccountAccessTokenAuthenticator.java deleted file mode 100644 index 178ca1c3..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AnyAccountAccessTokenAuthenticator.java +++ /dev/null @@ -1,106 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.content.SharedPreferences; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import ml.docilealligator.infinityforreddit.account.Account; -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import okhttp3.Authenticator; -import okhttp3.Headers; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.Route; -import retrofit2.Call; -import retrofit2.Retrofit; - -public class AnyAccountAccessTokenAuthenticator implements Authenticator { - private final Retrofit mRetrofit; - private final RedditDataRoomDatabase mRedditDataRoomDatabase; - private final Account mAccount; - private final SharedPreferences mCurrentAccountSharedPreferences; - - public AnyAccountAccessTokenAuthenticator(Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase, Account account, - SharedPreferences currentAccountSharedPreferences) { - mRetrofit = retrofit; - mRedditDataRoomDatabase = accountRoomDatabase; - mAccount = account; - mCurrentAccountSharedPreferences = currentAccountSharedPreferences; - } - - @Nullable - @Override - public Request authenticate(Route route, @NonNull Response response) { - if (response.code() == 401) { - String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY); - if (accessTokenHeader == null) { - return null; - } - - String accessToken = accessTokenHeader.substring(APIUtils.AUTHORIZATION_BASE.length()); - synchronized (this) { - if (mAccount == null) { - return null; - } - String accessTokenFromDatabase = mAccount.getAccessToken(); - if (accessToken.equals(accessTokenFromDatabase)) { - String newAccessToken = refreshAccessToken(mAccount); - if (!newAccessToken.equals("")) { - return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(newAccessToken))).build(); - } else { - return null; - } - } else { - return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(accessTokenFromDatabase))).build(); - } - } - } - return null; - } - - private String refreshAccessToken(Account account) { - String refreshToken = account.getRefreshToken(); - - RedditAPI api = mRetrofit.create(RedditAPI.class); - - Map params = new HashMap<>(); - params.put(APIUtils.GRANT_TYPE_KEY, APIUtils.GRANT_TYPE_REFRESH_TOKEN); - params.put(APIUtils.REFRESH_TOKEN_KEY, refreshToken); - - Call accessTokenCall = api.getAccessToken(APIUtils.getHttpBasicAuthHeader(), params); - try { - retrofit2.Response response = accessTokenCall.execute(); - if (response.isSuccessful() && response.body() != null) { - JSONObject jsonObject = new JSONObject(response.body()); - String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY); - String newRefreshToken = jsonObject.has(APIUtils.REFRESH_TOKEN_KEY) ? jsonObject.getString(APIUtils.REFRESH_TOKEN_KEY) : null; - if (newRefreshToken == null) { - mRedditDataRoomDatabase.accountDao().updateAccessToken(account.getAccountName(), newAccessToken); - } else { - mRedditDataRoomDatabase.accountDao().updateAccessTokenAndRefreshToken(account.getAccountName(), newAccessToken, newRefreshToken); - } - Account currentAccount = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); - if (currentAccount != null && mAccount.getAccountName().equals(currentAccount.getAccountName()) && mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT).equals(account.getAccountName())) { - mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, newAccessToken).apply(); - } - - return newAccessToken; - } - return ""; - } catch (IOException | JSONException e) { - e.printStackTrace(); - } - - return ""; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppBarStateChangeListener.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppBarStateChangeListener.java deleted file mode 100644 index 43e11941..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppBarStateChangeListener.java +++ /dev/null @@ -1,48 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import com.google.android.material.appbar.AppBarLayout; - -public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener { - private AppBarStateChangeListener.State mCurrentState = AppBarStateChangeListener.State.IDLE; - private int lastOffset = -1; - - @Override - public final void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { - if (lastOffset == verticalOffset) { - return; - } - lastOffset = verticalOffset; - - if (verticalOffset == 0) { - if (mCurrentState != AppBarStateChangeListener.State.EXPANDED) { - onStateChanged(appBarLayout, AppBarStateChangeListener.State.EXPANDED); - } - mCurrentState = AppBarStateChangeListener.State.EXPANDED; - } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) { - if (mCurrentState != AppBarStateChangeListener.State.COLLAPSED) { - onStateChanged(appBarLayout, AppBarStateChangeListener.State.COLLAPSED); - } - mCurrentState = AppBarStateChangeListener.State.COLLAPSED; - } else { - if (mCurrentState != AppBarStateChangeListener.State.IDLE) { - onStateChanged(appBarLayout, AppBarStateChangeListener.State.IDLE); - } - mCurrentState = AppBarStateChangeListener.State.IDLE; - } - } - - /** - * Notifies on state change - * - * @param appBarLayout Layout - * @param state Collapse state - */ - public abstract void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.State state); - - // State - public enum State { - EXPANDED, - COLLAPSED, - IDLE - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomThemeWrapperReceiver.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomThemeWrapperReceiver.java deleted file mode 100644 index 58ac1bd1..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomThemeWrapperReceiver.java +++ /dev/null @@ -1,7 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; - -public interface CustomThemeWrapperReceiver { - void setCustomThemeWrapper(CustomThemeWrapper customThemeWrapper); -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/DeleteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/DeleteThing.java deleted file mode 100644 index 0d0d0b0e..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/DeleteThing.java +++ /dev/null @@ -1,41 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import androidx.annotation.NonNull; - -import java.util.HashMap; -import java.util.Map; - -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class DeleteThing { - public static void delete(Retrofit oauthRetrofit, String fullname, String accessToken, DeleteThingListener deleteThingListener) { - Map params = new HashMap<>(); - params.put(APIUtils.ID_KEY, fullname); - oauthRetrofit.create(RedditAPI.class).delete(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - deleteThingListener.deleteSuccess(); - } else { - deleteThingListener.deleteFailed(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - deleteThingListener.deleteFailed(); - } - }); - } - - public interface DeleteThingListener { - void deleteSuccess(); - - void deleteFailed(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java deleted file mode 100644 index c01eba2f..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java +++ /dev/null @@ -1,153 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.Handler; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Executor; - -import ml.docilealligator.infinityforreddit.account.Account; -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings; -import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; -import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class FavoriteThing { - public static void favoriteSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit, - RedditDataRoomDatabase redditDataRoomDatabase, - @Nullable String accessToken, @NonNull String accountName, - SubscribedSubredditData subscribedSubredditData, - FavoriteThingListener favoriteThingListener) { - if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { - InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedSubredditData, - favoriteThingListener::success); - } else { - Map params = new HashMap<>(); - params.put(APIUtils.SR_NAME_KEY, subscribedSubredditData.getName()); - params.put(APIUtils.MAKE_FAVORITE_KEY, "true"); - oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedSubredditData, - favoriteThingListener::success); - } else { - favoriteThingListener.failed(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - favoriteThingListener.failed(); - } - }); - } - } - - public static void unfavoriteSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit, - RedditDataRoomDatabase redditDataRoomDatabase, - @Nullable String accessToken, @NonNull String accountName, - SubscribedSubredditData subscribedSubredditData, - FavoriteThingListener favoriteThingListener) { - if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { - InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, - subscribedSubredditData, favoriteThingListener::success); - } else { - Map params = new HashMap<>(); - params.put(APIUtils.SR_NAME_KEY, subscribedSubredditData.getName()); - params.put(APIUtils.MAKE_FAVORITE_KEY, "false"); - oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, - subscribedSubredditData, favoriteThingListener::success); - } else { - favoriteThingListener.failed(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - favoriteThingListener.failed(); - } - }); - } - } - - public static void favoriteUser(Executor executor, Handler handler, Retrofit oauthRetrofit, - RedditDataRoomDatabase redditDataRoomDatabase, - @Nullable String accessToken, @NonNull String accountName, - SubscribedUserData subscribedUserData, - FavoriteThingListener favoriteThingListener) { - if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { - InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, - subscribedUserData, favoriteThingListener::success); - } else { - Map params = new HashMap<>(); - params.put(APIUtils.SR_NAME_KEY, "u_" + subscribedUserData.getName()); - params.put(APIUtils.MAKE_FAVORITE_KEY, "true"); - oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, - subscribedUserData, favoriteThingListener::success); - } else { - favoriteThingListener.failed(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - favoriteThingListener.failed(); - } - }); - } - } - - public static void unfavoriteUser(Executor executor, Handler handler, Retrofit oauthRetrofit, - RedditDataRoomDatabase redditDataRoomDatabase, - @Nullable String accessToken, @NonNull String accountName, - SubscribedUserData subscribedUserData, - FavoriteThingListener favoriteThingListener) { - if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { - InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedUserData, - favoriteThingListener::success); - } else { - Map params = new HashMap<>(); - params.put(APIUtils.SR_NAME_KEY, "u_" + subscribedUserData.getName()); - params.put(APIUtils.MAKE_FAVORITE_KEY, "false"); - oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, - subscribedUserData, favoriteThingListener::success); - } else { - favoriteThingListener.failed(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - favoriteThingListener.failed(); - } - }); - } - } - - public interface FavoriteThingListener { - void success(); - - void failed(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchFlairs.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchFlairs.java deleted file mode 100644 index a3f75501..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchFlairs.java +++ /dev/null @@ -1,103 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.AsyncTask; - -import androidx.annotation.NonNull; - -import org.json.JSONArray; -import org.json.JSONException; - -import java.util.ArrayList; - -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.JSONUtils; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class FetchFlairs { - public static void fetchFlairsInSubreddit(Retrofit oauthRetrofit, String accessToken, String subredditName, FetchFlairsInSubredditListener fetchFlairsInSubredditListener) { - RedditAPI api = oauthRetrofit.create(RedditAPI.class); - - Call flairsCall = api.getFlairs(APIUtils.getOAuthHeader(accessToken), subredditName); - flairsCall.enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - new ParseFlairsAsyncTask(response.body(), new ParseFlairsAsyncTask.ParseFlairsAsyncTaskListener() { - @Override - public void parseSuccessful(ArrayList flairs) { - fetchFlairsInSubredditListener.fetchSuccessful(flairs); - } - - @Override - public void parseFailed() { - fetchFlairsInSubredditListener.fetchFailed(); - } - }).execute(); - } else if (response.code() == 403) { - //No flairs - fetchFlairsInSubredditListener.fetchSuccessful(null); - } else { - fetchFlairsInSubredditListener.fetchFailed(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - fetchFlairsInSubredditListener.fetchFailed(); - } - }); - } - - public interface FetchFlairsInSubredditListener { - void fetchSuccessful(ArrayList flairs); - - void fetchFailed(); - } - - private static class ParseFlairsAsyncTask extends AsyncTask, ArrayList> { - private final String response; - private final ParseFlairsAsyncTaskListener parseFlairsAsyncTaskListener; - ParseFlairsAsyncTask(String response, ParseFlairsAsyncTaskListener parseFlairsAsyncTaskListener) { - this.response = response; - this.parseFlairsAsyncTaskListener = parseFlairsAsyncTaskListener; - } - - @Override - protected ArrayList doInBackground(Void... voids) { - try { - JSONArray jsonArray = new JSONArray(response); - ArrayList flairs = new ArrayList<>(); - for (int i = 0; i < jsonArray.length(); i++) { - String id = jsonArray.getJSONObject(i).getString(JSONUtils.ID_KEY); - String text = jsonArray.getJSONObject(i).getString(JSONUtils.TEXT_KEY); - boolean editable = jsonArray.getJSONObject(i).getBoolean(JSONUtils.TEXT_EDITABLE_KEY); - - flairs.add(new Flair(id, text, editable)); - } - return flairs; - } catch (JSONException e) { - e.printStackTrace(); - } - return null; - } - - @Override - protected void onPostExecute(ArrayList strings) { - if (strings != null) { - parseFlairsAsyncTaskListener.parseSuccessful(strings); - } else { - parseFlairsAsyncTaskListener.parseFailed(); - } - } - - interface ParseFlairsAsyncTaskListener { - void parseSuccessful(ArrayList flairs); - - void parseFailed(); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchMyInfo.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchMyInfo.java deleted file mode 100644 index b1ac07eb..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchMyInfo.java +++ /dev/null @@ -1,97 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.AsyncTask; -import android.text.Html; - -import androidx.annotation.NonNull; - -import org.json.JSONException; -import org.json.JSONObject; - -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.JSONUtils; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Retrofit; - -public class FetchMyInfo { - - public static void fetchAccountInfo(final Retrofit retrofit, RedditDataRoomDatabase redditDataRoomDatabase, - String accessToken, final FetchMyInfoListener fetchMyInfoListener) { - RedditAPI api = retrofit.create(RedditAPI.class); - - Call userInfo = api.getMyInfo(APIUtils.getOAuthHeader(accessToken)); - userInfo.enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { - if (response.isSuccessful()) { - new ParseAndSaveAccountInfoAsyncTask(response.body(), redditDataRoomDatabase, fetchMyInfoListener).execute(); - } else { - fetchMyInfoListener.onFetchMyInfoFailed(false); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - fetchMyInfoListener.onFetchMyInfoFailed(false); - } - }); - } - - public interface FetchMyInfoListener { - void onFetchMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma); - - void onFetchMyInfoFailed(boolean parseFailed); - } - - private static class ParseAndSaveAccountInfoAsyncTask extends AsyncTask { - private JSONObject jsonResponse; - private RedditDataRoomDatabase redditDataRoomDatabase; - private FetchMyInfoListener fetchMyInfoListener; - private boolean parseFailed; - - private String name; - private String profileImageUrl; - private String bannerImageUrl; - private int karma; - - ParseAndSaveAccountInfoAsyncTask(String response, RedditDataRoomDatabase redditDataRoomDatabase, - FetchMyInfoListener fetchMyInfoListener) { - try { - jsonResponse = new JSONObject(response); - this.redditDataRoomDatabase = redditDataRoomDatabase; - this.fetchMyInfoListener = fetchMyInfoListener; - parseFailed = false; - } catch (JSONException e) { - fetchMyInfoListener.onFetchMyInfoFailed(true); - } - } - - @Override - protected Void doInBackground(Void... voids) { - try { - name = jsonResponse.getString(JSONUtils.NAME_KEY); - profileImageUrl = Html.fromHtml(jsonResponse.getString(JSONUtils.ICON_IMG_KEY)).toString(); - if (!jsonResponse.isNull(JSONUtils.SUBREDDIT_KEY)) { - bannerImageUrl = Html.fromHtml(jsonResponse.getJSONObject(JSONUtils.SUBREDDIT_KEY).getString(JSONUtils.BANNER_IMG_KEY)).toString(); - } - karma = jsonResponse.getInt(JSONUtils.TOTAL_KARMA_KEY); - - redditDataRoomDatabase.accountDao().updateAccountInfo(name, profileImageUrl, bannerImageUrl, karma); - } catch (JSONException e) { - parseFailed = true; - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - if (!parseFailed) { - fetchMyInfoListener.onFetchMyInfoSuccess(name, profileImageUrl, bannerImageUrl, karma); - } else { - fetchMyInfoListener.onFetchMyInfoFailed(true); - } - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRedgifsVideoLinks.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRedgifsVideoLinks.java deleted file mode 100644 index 8435f3ea..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRedgifsVideoLinks.java +++ /dev/null @@ -1,76 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.content.SharedPreferences; -import android.os.Handler; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.IOException; -import java.util.concurrent.Executor; - -import ml.docilealligator.infinityforreddit.apis.RedgifsAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.JSONUtils; -import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import retrofit2.Call; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class FetchRedgifsVideoLinks { - - public interface FetchRedgifsVideoLinksListener { - void success(String webm, String mp4); - void failed(int errorCode); - } - - public static void fetchRedgifsVideoLinks(Executor executor, Handler handler, Retrofit redgifsRetrofit, - SharedPreferences currentAccountSharedPreferences, - String redgifsId, - FetchRedgifsVideoLinksListener fetchRedgifsVideoLinksListener) { - executor.execute(() -> { - try { - Response response = redgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(currentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), - redgifsId, APIUtils.USER_AGENT).execute(); - if (response.isSuccessful()) { - parseRedgifsVideoLinks(handler, response.body(), fetchRedgifsVideoLinksListener); - } else { - handler.post(() -> fetchRedgifsVideoLinksListener.failed(response.code())); - } - } catch (IOException e) { - e.printStackTrace(); - handler.post(() -> fetchRedgifsVideoLinksListener.failed(-1)); - } - }); - } - - public static void fetchRedgifsVideoLinksInRecyclerViewAdapter(Executor executor, Handler handler, - Call redgifsCall, - FetchRedgifsVideoLinksListener fetchRedgifsVideoLinksListener) { - executor.execute(() -> { - try { - Response response = redgifsCall.execute(); - if (response.isSuccessful()) { - parseRedgifsVideoLinks(handler, response.body(), fetchRedgifsVideoLinksListener); - } else { - handler.post(() -> fetchRedgifsVideoLinksListener.failed(response.code())); - } - } catch (IOException e) { - e.printStackTrace(); - handler.post(() -> fetchRedgifsVideoLinksListener.failed(-1)); - } - }); - } - - private static void parseRedgifsVideoLinks(Handler handler, String response, - FetchRedgifsVideoLinksListener fetchRedgifsVideoLinksListener) { - try { - String mp4 = new JSONObject(response).getJSONObject(JSONUtils.GIF_KEY).getJSONObject(JSONUtils.URLS_KEY) - .getString(JSONUtils.HD_KEY); - handler.post(() -> fetchRedgifsVideoLinksListener.success(mp4, mp4)); - } catch (JSONException e) { - e.printStackTrace(); - handler.post(() -> fetchRedgifsVideoLinksListener.failed(-1)); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java deleted file mode 100644 index a914bb19..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchRules.java +++ /dev/null @@ -1,86 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.Handler; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.concurrent.Executor; - -import ml.docilealligator.infinityforreddit.account.Account; -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -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 FetchRules { - public interface FetchRulesListener { - void success(ArrayList rules); - void failed(); - } - - public static void fetchRules(Executor executor, Handler handler, Retrofit retrofit, @Nullable String accessToken, - @NonNull String accountName, String subredditName, - FetchRulesListener fetchRulesListener) { - RedditAPI api = retrofit.create(RedditAPI.class); - Call rulesCall = accountName.equals(Account.ANONYMOUS_ACCOUNT) - ? api.getRules(subredditName) - : api.getRulesOauth(APIUtils.getOAuthHeader(accessToken), subredditName); - rulesCall.enqueue(new Callback<>() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - parseRules(executor, handler, response.body(), new FetchRulesListener() { - @Override - public void success(ArrayList rules) { - fetchRulesListener.success(rules); - } - - @Override - public void failed() { - fetchRulesListener.failed(); - } - }); - } else { - fetchRulesListener.failed(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - fetchRulesListener.failed(); - } - }); - } - - private static void parseRules(Executor executor, Handler handler, String response, - FetchRulesListener fetchRulesListener) { - executor.execute(() -> { - try { - JSONArray rulesArray = new JSONObject(response).getJSONArray(JSONUtils.RULES_KEY); - ArrayList rules = new ArrayList<>(); - for (int i = 0; i < rulesArray.length(); i++) { - String shortName = rulesArray.getJSONObject(i).getString(JSONUtils.SHORT_NAME_KEY); - String description = null; - if (rulesArray.getJSONObject(i).has(JSONUtils.DESCRIPTION_KEY)) { - description = Utils.modifyMarkdown(rulesArray.getJSONObject(i).getString(JSONUtils.DESCRIPTION_KEY)); - } - rules.add(new Rule(shortName, description)); - } - handler.post(() -> fetchRulesListener.success(rules)); - } catch (JSONException e) { - e.printStackTrace(); - handler.post(fetchRulesListener::failed); - } - }); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchStreamableVideo.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchStreamableVideo.java deleted file mode 100644 index f0b03e1b..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchStreamableVideo.java +++ /dev/null @@ -1,98 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.Handler; - -import androidx.annotation.Nullable; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.IOException; -import java.util.concurrent.Executor; - -import javax.inject.Provider; - -import ml.docilealligator.infinityforreddit.apis.StreamableAPI; -import ml.docilealligator.infinityforreddit.utils.JSONUtils; -import retrofit2.Call; -import retrofit2.Response; - -public class FetchStreamableVideo { - public interface FetchStreamableVideoListener { - void success(StreamableVideo streamableVideo); - void failed(); - } - - public static void fetchStreamableVideo(Executor executor, Handler handler, Provider streamableApiProvider, - String videoUrl, FetchStreamableVideoListener fetchStreamableVideoListener) { - executor.execute(() -> { - try { - Response response = streamableApiProvider.get().getStreamableData(videoUrl).execute(); - if (response.isSuccessful()) { - JSONObject jsonObject = new JSONObject(response.body()); - String title = jsonObject.getString(JSONUtils.TITLE_KEY); - JSONObject filesObject = jsonObject.getJSONObject(JSONUtils.FILES_KEY); - StreamableVideo.Media mp4 = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_KEY)); - StreamableVideo.Media mp4MobileTemp = null; - if (filesObject.has(JSONUtils.MP4_MOBILE_KEY)) { - mp4MobileTemp = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_MOBILE_KEY)); - } - if (mp4 == null && mp4MobileTemp == null) { - handler.post(fetchStreamableVideoListener::failed); - return; - } - StreamableVideo.Media mp4Mobile = mp4MobileTemp; - handler.post(() -> fetchStreamableVideoListener.success(new StreamableVideo(title, mp4, mp4Mobile))); - } else { - handler.post(fetchStreamableVideoListener::failed); - } - } catch (IOException | JSONException e) { - e.printStackTrace(); - handler.post(fetchStreamableVideoListener::failed); - } - }); - } - - public static void fetchStreamableVideoInRecyclerViewAdapter(Executor executor, Handler handler, Call streamableCall, - FetchStreamableVideoListener fetchStreamableVideoListener) { - executor.execute(() -> { - try { - Response response = streamableCall.execute(); - if (response.isSuccessful()) { - JSONObject jsonObject = new JSONObject(response.body()); - String title = jsonObject.getString(JSONUtils.TITLE_KEY); - JSONObject filesObject = jsonObject.getJSONObject(JSONUtils.FILES_KEY); - StreamableVideo.Media mp4 = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_KEY)); - StreamableVideo.Media mp4MobileTemp = null; - if (filesObject.has(JSONUtils.MP4_MOBILE_KEY)) { - mp4MobileTemp = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_MOBILE_KEY)); - } - if (mp4 == null && mp4MobileTemp == null) { - handler.post(fetchStreamableVideoListener::failed); - return; - } - StreamableVideo.Media mp4Mobile = mp4MobileTemp; - handler.post(() -> fetchStreamableVideoListener.success(new StreamableVideo(title, mp4, mp4Mobile))); - } else { - handler.post(fetchStreamableVideoListener::failed); - } - } catch (IOException | JSONException e) { - e.printStackTrace(); - handler.post(fetchStreamableVideoListener::failed); - } - }); - } - - @Nullable - private static StreamableVideo.Media parseMedia(JSONObject jsonObject) { - try { - return new StreamableVideo.Media( - jsonObject.getString(JSONUtils.URL_KEY), - jsonObject.getInt(JSONUtils.WIDTH_KEY), - jsonObject.getInt(JSONUtils.HEIGHT_KEY)); - } catch (JSONException e) { - e.printStackTrace(); - return null; - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java deleted file mode 100644 index 9a8f08f2..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java +++ /dev/null @@ -1,74 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import java.util.ArrayList; - -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.subreddit.SubredditData; -import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; -import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class FetchSubscribedThing { - public static void fetchSubscribedThing(final Retrofit oauthRetrofit, @Nullable String accessToken, @NonNull String accountName, - final String lastItem, final ArrayList subscribedSubredditData, - final ArrayList subscribedUserData, - final ArrayList subredditData, - final FetchSubscribedThingListener fetchSubscribedThingListener) { - RedditAPI api = oauthRetrofit.create(RedditAPI.class); - - Call subredditDataCall = api.getSubscribedThing(lastItem, APIUtils.getOAuthHeader(accessToken)); - subredditDataCall.enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - ParseSubscribedThing.parseSubscribedSubreddits(response.body(), accountName, - subscribedSubredditData, subscribedUserData, subredditData, - new ParseSubscribedThing.ParseSubscribedSubredditsListener() { - - @Override - public void onParseSubscribedSubredditsSuccess(ArrayList subscribedSubredditData, - ArrayList subscribedUserData, - ArrayList subredditData, - String lastItem) { - if (lastItem.equals("null")) { - fetchSubscribedThingListener.onFetchSubscribedThingSuccess( - subscribedSubredditData, subscribedUserData, subredditData); - } else { - fetchSubscribedThing(oauthRetrofit, accessToken, accountName, lastItem, - subscribedSubredditData, subscribedUserData, subredditData, - fetchSubscribedThingListener); - } - } - - @Override - public void onParseSubscribedSubredditsFail() { - fetchSubscribedThingListener.onFetchSubscribedThingFail(); - } - }); - } else { - fetchSubscribedThingListener.onFetchSubscribedThingFail(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - fetchSubscribedThingListener.onFetchSubscribedThingFail(); - } - }); - } - - public interface FetchSubscribedThingListener { - void onFetchSubscribedThingSuccess(ArrayList subscribedSubredditData, - ArrayList subscribedUserData, - ArrayList subredditData); - - void onFetchSubscribedThingFail(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchUserFlairs.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchUserFlairs.java deleted file mode 100644 index 2d80e0a0..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchUserFlairs.java +++ /dev/null @@ -1,122 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.AsyncTask; -import android.text.Html; - -import androidx.annotation.NonNull; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; - -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.JSONUtils; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class FetchUserFlairs { - public static void fetchUserFlairsInSubreddit(Retrofit oauthRetrofit, String accessToken, String subredditName, FetchUserFlairsInSubredditListener fetchUserFlairsInSubredditListener) { - RedditAPI api = oauthRetrofit.create(RedditAPI.class); - - Call flairsCall = api.getUserFlairs(APIUtils.getOAuthHeader(accessToken), subredditName); - flairsCall.enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - new ParseUserFlairsAsyncTask(response.body(), new ParseUserFlairsAsyncTask.ParseUserFlairsAsyncTaskListener() { - @Override - public void parseSuccessful(ArrayList userFlairs) { - fetchUserFlairsInSubredditListener.fetchSuccessful(userFlairs); - } - - @Override - public void parseFailed() { - fetchUserFlairsInSubredditListener.fetchFailed(); - } - }).execute(); - } else if (response.code() == 403) { - //No flairs - fetchUserFlairsInSubredditListener.fetchSuccessful(null); - } else { - fetchUserFlairsInSubredditListener.fetchFailed(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - fetchUserFlairsInSubredditListener.fetchFailed(); - } - }); - } - - public interface FetchUserFlairsInSubredditListener { - void fetchSuccessful(ArrayList userFlairs); - - void fetchFailed(); - } - - private static class ParseUserFlairsAsyncTask extends AsyncTask, ArrayList> { - private final String response; - private final ParseUserFlairsAsyncTaskListener parseFlairsAsyncTaskListener; - - ParseUserFlairsAsyncTask(String response, ParseUserFlairsAsyncTaskListener parseFlairsAsyncTaskListener) { - this.response = response; - this.parseFlairsAsyncTaskListener = parseFlairsAsyncTaskListener; - } - - @Override - protected ArrayList doInBackground(Void... voids) { - try { - JSONArray jsonArray = new JSONArray(response); - ArrayList userFlairs = new ArrayList<>(); - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject userFlairObject = jsonArray.getJSONObject(i); - String id = userFlairObject.getString(JSONUtils.ID_KEY); - String text = userFlairObject.getString(JSONUtils.TEXT_KEY); - boolean editable = userFlairObject.getBoolean(JSONUtils.TEXT_EDITABLE_KEY); - int maxEmojis = userFlairObject.getInt(JSONUtils.MAX_EMOJIS_KEY); - - StringBuilder authorFlairHTMLBuilder = new StringBuilder(); - if (userFlairObject.has(JSONUtils.RICHTEXT_KEY)) { - JSONArray flairArray = userFlairObject.getJSONArray(JSONUtils.RICHTEXT_KEY); - for (int j = 0; j < flairArray.length(); j++) { - JSONObject flairObject = flairArray.getJSONObject(j); - String e = flairObject.getString(JSONUtils.E_KEY); - if (e.equals("text")) { - authorFlairHTMLBuilder.append(Html.escapeHtml(flairObject.getString(JSONUtils.T_KEY))); - } else if (e.equals("emoji")) { - authorFlairHTMLBuilder.append(""); - } - } - } - - userFlairs.add(new UserFlair(id, text, authorFlairHTMLBuilder.toString(), editable, maxEmojis)); - } - return userFlairs; - } catch (JSONException e) { - e.printStackTrace(); - } - return null; - } - - @Override - protected void onPostExecute(ArrayList userFlairs) { - if (userFlairs != null) { - parseFlairsAsyncTaskListener.parseSuccessful(userFlairs); - } else { - parseFlairsAsyncTaskListener.parseFailed(); - } - } - - interface ParseUserFlairsAsyncTaskListener { - void parseSuccessful(ArrayList userFlairs); - - void parseFailed(); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Flair.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Flair.java deleted file mode 100644 index 28eb33ba..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Flair.java +++ /dev/null @@ -1,80 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.Parcel; -import android.os.Parcelable; - -import com.google.gson.Gson; -import com.google.gson.JsonParseException; - -public class Flair implements Parcelable { - public static final Creator CREATOR = new Creator() { - @Override - public Flair createFromParcel(Parcel in) { - return new Flair(in); - } - - @Override - public Flair[] newArray(int size) { - return new Flair[size]; - } - }; - private String id; - private String text; - private boolean editable; - - Flair(String id, String text, boolean editable) { - this.id = id; - this.text = text; - this.editable = editable; - } - - protected Flair(Parcel in) { - id = in.readString(); - text = in.readString(); - editable = in.readByte() != 0; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - public boolean isEditable() { - return editable; - } - - public void setEditable(boolean editable) { - this.editable = editable; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(id); - parcel.writeString(text); - parcel.writeByte((byte) (editable ? 1 : 0)); - } - - public String getJSONModel() { - return new Gson().toJson(this); - } - - public static Flair fromJson(String json) throws JsonParseException { - return new Gson().fromJson(json, Flair.class); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java deleted file mode 100644 index 3ee75984..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java +++ /dev/null @@ -1,54 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import ml.docilealligator.infinityforreddit.postfilter.PostFilter; - -public interface FragmentCommunicator { - default void refresh() { - } - - default boolean handleKeyDown(int keyCode) { - return false; - } - - default void changeNSFW(boolean nsfw) { - } - - default boolean startLazyMode() { - return false; - } - - default void stopLazyMode() { - } - - default void resumeLazyMode(boolean resumeNow) { - } - - default void pauseLazyMode(boolean startTimer) { - } - - default boolean isInLazyMode() { - return false; - } - - default void changePostLayout(int postLayout) { - } - - default void stopRefreshProgressbar() { - } - - void applyTheme(); - - default void hideReadPosts() { - } - - default void changePostFilter(PostFilter postFilter) { - } - - default PostFilter getPostFilter() { - return null; - } - - default void filterPosts() { - - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ImgurMedia.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ImgurMedia.java deleted file mode 100644 index 356d48d5..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ImgurMedia.java +++ /dev/null @@ -1,84 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.Parcel; -import android.os.Parcelable; - -public class ImgurMedia implements Parcelable { - public static final int TYPE_IMAGE = 0; - public static final int TYPE_VIDEO = 1; - private String id; - private final String title; - private final String description; - private final String link; - private int type; - - public ImgurMedia(String id, String title, String description, String type, String link) { - this.id = id; - this.title = title; - this.description = description; - if (type.contains("mp4")) { - this.type = TYPE_VIDEO; - } else { - this.type = TYPE_IMAGE; - } - this.link = link; - } - - protected ImgurMedia(Parcel in) { - title = in.readString(); - description = in.readString(); - link = in.readString(); - } - - public static final Creator CREATOR = new Creator() { - @Override - public ImgurMedia createFromParcel(Parcel in) { - return new ImgurMedia(in); - } - - @Override - public ImgurMedia[] newArray(int size) { - return new ImgurMedia[size]; - } - }; - - public String getId() { - return id; - } - - public String getTitle() { - return title; - } - - public String getDescription() { - return description; - } - - public int getType() { - return type; - } - - public String getLink() { - return link; - } - - public String getFileName() { - if (type == TYPE_VIDEO) { - return "imgur-" + id + ".mp4"; - } - - return "imgur-" + id + ".jpg"; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(title); - parcel.writeString(description); - parcel.writeString(link); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/LoadingMorePostsStatus.java b/app/src/main/java/ml/docilealligator/infinityforreddit/LoadingMorePostsStatus.java deleted file mode 100644 index 8df6016b..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/LoadingMorePostsStatus.java +++ /dev/null @@ -1,16 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import androidx.annotation.IntDef; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@IntDef({LoadingMorePostsStatus.LOADING, LoadingMorePostsStatus.FAILED, LoadingMorePostsStatus.NO_MORE_POSTS, - LoadingMorePostsStatus.NOT_LOADING}) -@Retention(RetentionPolicy.SOURCE) -public @interface LoadingMorePostsStatus { - int LOADING = 0; - int FAILED = 1; - int NO_MORE_POSTS = 2; - int NOT_LOADING = 3; -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MarkPostAsReadInterface.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MarkPostAsReadInterface.java deleted file mode 100644 index d14c1c09..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MarkPostAsReadInterface.java +++ /dev/null @@ -1,7 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import ml.docilealligator.infinityforreddit.post.Post; - -public interface MarkPostAsReadInterface { - void markPostAsRead(Post post); -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MediaMetadata.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MediaMetadata.java deleted file mode 100644 index db41399c..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MediaMetadata.java +++ /dev/null @@ -1,122 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.net.Uri; -import android.os.Parcel; -import android.os.Parcelable; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -public class MediaMetadata implements Parcelable { - public String id; - //E.g. Image - public String e; - public String fileName; - public String caption; - public boolean isGIF; - public MediaItem original; - public MediaItem downscaled; - - public MediaMetadata(String id, String e, MediaItem original, MediaItem downscaled) { - this.id = id; - this.e = e; - isGIF = !e.equalsIgnoreCase("image"); - String path = Uri.parse(original.url).getPath(); - this.fileName = path == null ? (isGIF ? "Animated.gif" : "Image.jpg") : path.substring(path.lastIndexOf('/') + 1); - this.original = original; - this.downscaled = downscaled; - } - - protected MediaMetadata(Parcel in) { - id = in.readString(); - e = in.readString(); - fileName = in.readString(); - caption = in.readString(); - isGIF = in.readByte() != 0; - original = in.readParcelable(MediaItem.class.getClassLoader()); - downscaled = in.readParcelable(MediaItem.class.getClassLoader()); - } - - public static final Creator CREATOR = new Creator() { - @Override - public MediaMetadata createFromParcel(Parcel in) { - return new MediaMetadata(in); - } - - @Override - public MediaMetadata[] newArray(int size) { - return new MediaMetadata[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeString(id); - dest.writeString(e); - dest.writeString(fileName); - dest.writeString(caption); - dest.writeByte((byte) (isGIF ? 1 : 0)); - dest.writeParcelable(original, flags); - dest.writeParcelable(downscaled, flags); - } - - public static class MediaItem implements Parcelable { - public int x; - public int y; - //Image or gif - public String url; - //Only for gifs - @Nullable - public String mp4Url; - - public MediaItem(int x, int y, String url) { - this.x = x; - this.y = y; - this.url = url; - } - - public MediaItem(int x, int y, String url, String mp4Url) { - this.x = x; - this.y = y; - this.url = url; - this.mp4Url = mp4Url; - } - - protected MediaItem(Parcel in) { - x = in.readInt(); - y = in.readInt(); - url = in.readString(); - mp4Url = in.readString(); - } - - public static final Creator CREATOR = new Creator() { - @Override - public MediaItem createFromParcel(Parcel in) { - return new MediaItem(in); - } - - @Override - public MediaItem[] newArray(int size) { - return new MediaItem[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeInt(x); - dest.writeInt(y); - dest.writeString(url); - dest.writeString(mp4Url); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java index 7bbc2443..aa3b46ae 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/NetworkModule.java @@ -10,6 +10,8 @@ import javax.inject.Singleton; import dagger.Module; import dagger.Provides; import ml.docilealligator.infinityforreddit.apis.StreamableAPI; +import ml.docilealligator.infinityforreddit.network.AccessTokenAuthenticator; +import ml.docilealligator.infinityforreddit.network.RedgifsAccessTokenAuthenticator; import ml.docilealligator.infinityforreddit.network.SortTypeConverterFactory; import ml.docilealligator.infinityforreddit.utils.APIUtils; import okhttp3.ConnectionPool; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java deleted file mode 100644 index 7b6d6067..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java +++ /dev/null @@ -1,138 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.AsyncTask; - -import androidx.annotation.NonNull; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; - -import ml.docilealligator.infinityforreddit.subreddit.SubredditData; -import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; -import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; -import ml.docilealligator.infinityforreddit.utils.JSONUtils; -import ml.docilealligator.infinityforreddit.utils.Utils; - -class ParseSubscribedThing { - static void parseSubscribedSubreddits(String response, @NonNull String accountName, - ArrayList subscribedSubredditData, - ArrayList subscribedUserData, - ArrayList subredditData, - ParseSubscribedSubredditsListener parseSubscribedSubredditsListener) { - new ParseSubscribedSubredditsAsyncTask(response, accountName, subscribedSubredditData, subscribedUserData, subredditData, - parseSubscribedSubredditsListener).execute(); - } - - interface ParseSubscribedSubredditsListener { - void onParseSubscribedSubredditsSuccess(ArrayList subscribedSubredditData, - ArrayList subscribedUserData, - ArrayList subredditData, - String lastItem); - - void onParseSubscribedSubredditsFail(); - } - - private static class ParseSubscribedSubredditsAsyncTask extends AsyncTask { - private JSONObject jsonResponse; - private String accountName; - private boolean parseFailed; - private String lastItem; - private ArrayList subscribedSubredditData; - private ArrayList subscribedUserData; - private ArrayList subredditData; - private ArrayList newSubscribedSubredditData; - private ArrayList newSubscribedUserData; - private ArrayList newSubredditData; - private final ParseSubscribedSubredditsListener parseSubscribedSubredditsListener; - - ParseSubscribedSubredditsAsyncTask(String response, @NonNull String accountName, ArrayList subscribedSubredditData, - ArrayList subscribedUserData, - ArrayList subredditData, - ParseSubscribedSubredditsListener parseSubscribedSubredditsListener) { - this.parseSubscribedSubredditsListener = parseSubscribedSubredditsListener; - try { - jsonResponse = new JSONObject(response); - this.accountName = accountName; - parseFailed = false; - this.subscribedSubredditData = subscribedSubredditData; - this.subscribedUserData = subscribedUserData; - this.subredditData = subredditData; - newSubscribedSubredditData = new ArrayList<>(); - newSubscribedUserData = new ArrayList<>(); - newSubredditData = new ArrayList<>(); - } catch (JSONException e) { - e.printStackTrace(); - } - } - - @Override - protected Void doInBackground(Void... voids) { - try { - if (jsonResponse == null) { - parseFailed = true; - return null; - } - JSONArray children = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY); - for (int i = 0; i < children.length(); i++) { - JSONObject data = children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); - String name = data.getString(JSONUtils.DISPLAY_NAME_KEY); - String bannerImageUrl = data.getString(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY); - if (bannerImageUrl.equals("") || bannerImageUrl.equals("null")) { - bannerImageUrl = data.getString(JSONUtils.BANNER_IMG_KEY); - if (bannerImageUrl.equals("null")) { - bannerImageUrl = ""; - } - } - String iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY); - if (iconUrl.equals("") || iconUrl.equals("null")) { - iconUrl = data.getString(JSONUtils.ICON_IMG_KEY); - if (iconUrl.equals("null")) { - iconUrl = ""; - } - } - String id = data.getString(JSONUtils.NAME_KEY); - boolean isFavorite = data.getBoolean(JSONUtils.USER_HAS_FAVORITED_KEY); - - if (data.getString(JSONUtils.SUBREDDIT_TYPE_KEY) - .equals(JSONUtils.SUBREDDIT_TYPE_VALUE_USER)) { - //It's a user - newSubscribedUserData.add(new SubscribedUserData(name.substring(2), iconUrl, accountName, isFavorite)); - } else { - String subredditFullName = data.getString(JSONUtils.DISPLAY_NAME_KEY); - String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim(); - String sidebarDescription = Utils.modifyMarkdown(data.getString(JSONUtils.DESCRIPTION_KEY).trim()); - int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY); - long createdUTC = data.getLong(JSONUtils.CREATED_UTC_KEY) * 1000; - String suggestedCommentSort = data.getString(JSONUtils.SUGGESTED_COMMENT_SORT_KEY); - boolean isNSFW = data.getBoolean(JSONUtils.OVER18_KEY); - newSubscribedSubredditData.add(new SubscribedSubredditData(id, name, iconUrl, accountName, isFavorite)); - newSubredditData.add(new SubredditData(id, subredditFullName, iconUrl, - bannerImageUrl, description, sidebarDescription, nSubscribers, createdUTC, - suggestedCommentSort, isNSFW)); - } - } - lastItem = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY); - } catch (JSONException e) { - parseFailed = true; - e.printStackTrace(); - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - if (!parseFailed) { - subscribedSubredditData.addAll(newSubscribedSubredditData); - subscribedUserData.addAll(newSubscribedUserData); - subredditData.addAll(newSubredditData); - parseSubscribedSubredditsListener.onParseSubscribedSubredditsSuccess(subscribedSubredditData, - subscribedUserData, subredditData, lastItem); - } else { - parseSubscribedSubredditsListener.onParseSubscribedSubredditsFail(); - } - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PollPayload.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PollPayload.java deleted file mode 100644 index 1383ddf9..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PollPayload.java +++ /dev/null @@ -1,71 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import com.google.gson.annotations.SerializedName; - -public class PollPayload { - @SerializedName("api_type") - public String apiType = "json"; - @SerializedName("duration") - public int duration; - @SerializedName("nsfw") - public boolean isNsfw; - public String[] options; - @SerializedName("flair_id") - public String flairId; - @SerializedName("flair_text") - public String flairText; - @SerializedName("raw_rtjson") - public String richTextJSON; - @SerializedName("post_to_twitter") - public boolean postToTwitter = false; - @SerializedName("sendreplies") - public boolean sendReplies; - @SerializedName("show_error_list") - public boolean showErrorList = true; - @SerializedName("spoiler") - public boolean isSpoiler; - @SerializedName("sr") - public String subredditName; - @SerializedName("submit_type") - public String submitType; - public String text; - public String title; - @SerializedName("validate_on_submit") - public boolean validateOnSubmit = true; - - public PollPayload(String subredditName, String title, String[] options, int duration, boolean isNsfw, - boolean isSpoiler, Flair flair, boolean sendReplies, - String submitType) { - this.subredditName = subredditName; - this.title = title; - this.options = options; - this.duration = duration; - this.isNsfw = isNsfw; - this.isSpoiler = isSpoiler; - if (flair != null) { - flairId = flair.getId(); - flairText = flair.getText(); - } - this.sendReplies = sendReplies; - this.submitType = submitType; - } - - public PollPayload(String subredditName, String title, String[] options, int duration, boolean isNsfw, - boolean isSpoiler, Flair flair, String richTextJSON, String text, boolean sendReplies, - String submitType) { - this.subredditName = subredditName; - this.title = title; - this.options = options; - this.duration = duration; - this.isNsfw = isNsfw; - this.isSpoiler = isSpoiler; - if (flair != null) { - flairId = flair.getId(); - flairText = flair.getText(); - } - this.richTextJSON = richTextJSON; - this.text = text; - this.sendReplies = sendReplies; - this.submitType = submitType; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditGalleryPayload.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditGalleryPayload.java deleted file mode 100644 index 6106d09f..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditGalleryPayload.java +++ /dev/null @@ -1,115 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.Parcel; -import android.os.Parcelable; - -import com.google.gson.annotations.SerializedName; - -import java.util.ArrayList; - -public class RedditGalleryPayload { - @SerializedName("sr") - public String subredditName; - @SerializedName("submit_type") - public String submitType; - @SerializedName("api_type") - public String apiType = "json"; - @SerializedName("show_error_list") - public boolean showErrorList = true; - public String title; - public String text; - @SerializedName("spoiler") - public boolean isSpoiler; - @SerializedName("nsfw") - public boolean isNSFW; - public String kind = "self"; - @SerializedName("original_content") - public boolean originalContent = false; - @SerializedName("post_to_twitter") - public boolean postToTwitter = false; - @SerializedName("sendreplies") - public boolean sendReplies; - @SerializedName("validate_on_submit") - public boolean validateOnSubmit = true; - @SerializedName("flair_id") - public String flairId; - @SerializedName("flair_text") - public String flairText; - public ArrayList items; - - public RedditGalleryPayload(String subredditName, String submitType, String title, String text, - boolean isSpoiler, boolean isNSFW, boolean sendReplies, Flair flair, ArrayList items) { - this.subredditName = subredditName; - this.submitType = submitType; - this.title = title; - this.text = text; - this.isSpoiler = isSpoiler; - this.isNSFW = isNSFW; - this.sendReplies = sendReplies; - if (flair != null) { - flairId = flair.getId(); - flairText = flair.getText(); - } - this.items = items; - } - - public static class Item implements Parcelable { - public String caption; - @SerializedName("outbound_url") - public String outboundUrl; - @SerializedName("media_id") - public String mediaId; - - public Item(String caption, String outboundUrl, String mediaId) { - this.caption = caption; - this.outboundUrl = outboundUrl; - this.mediaId = mediaId; - } - - protected Item(Parcel in) { - caption = in.readString(); - outboundUrl = in.readString(); - mediaId = in.readString(); - } - - public static final Creator CREATOR = new Creator() { - @Override - public Item createFromParcel(Parcel in) { - return new Item(in); - } - - @Override - public Item[] newArray(int size) { - return new Item[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(caption); - parcel.writeString(outboundUrl); - parcel.writeString(mediaId); - } - - public String getCaption() { - return caption; - } - - public void setCaption(String caption) { - this.caption = caption == null ? "" : caption; - } - - public String getOutboundUrl() { - return outboundUrl; - } - - public void setOutboundUrl(String outboundUrl) { - this.outboundUrl = outboundUrl; - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedgifsAccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedgifsAccessTokenAuthenticator.java deleted file mode 100644 index 07bd37a6..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedgifsAccessTokenAuthenticator.java +++ /dev/null @@ -1,89 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.content.SharedPreferences; - -import androidx.annotation.NonNull; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import ml.docilealligator.infinityforreddit.apis.RedgifsAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import okhttp3.Headers; -import okhttp3.Interceptor; -import okhttp3.Response; -import retrofit2.Call; -import retrofit2.Retrofit; -import retrofit2.converter.scalars.ScalarsConverterFactory; - -public class RedgifsAccessTokenAuthenticator implements Interceptor { - private final SharedPreferences mCurrentAccountSharedPreferences; - - public RedgifsAccessTokenAuthenticator(SharedPreferences currentAccountSharedPreferences) { - this.mCurrentAccountSharedPreferences = currentAccountSharedPreferences; - } - - private String refreshAccessToken() { - Retrofit retrofit = new Retrofit.Builder() - .baseUrl(APIUtils.REDGIFS_API_BASE_URI) - .addConverterFactory(ScalarsConverterFactory.create()) - .build(); - RedgifsAPI api = retrofit.create(RedgifsAPI.class); - - Map params = new HashMap<>(); - params.put(APIUtils.GRANT_TYPE_KEY, APIUtils.GRANT_TYPE_CLIENT_CREDENTIALS); - params.put(APIUtils.CLIENT_ID_KEY, APIUtils.REDGIFS_CLIENT_ID); - params.put(APIUtils.CLIENT_SECRET_KEY, APIUtils.REDGIFS_CLIENT_SECRET); - - Call accessTokenCall = api.getRedgifsAccessToken(params); - try { - retrofit2.Response response = accessTokenCall.execute(); - if (response.isSuccessful() && response.body() != null) { - String newAccessToken = new JSONObject(response.body()).getString(APIUtils.ACCESS_TOKEN_KEY); - mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, newAccessToken).apply(); - - return newAccessToken; - } - return ""; - } catch (IOException | JSONException e) { - e.printStackTrace(); - } - - return ""; - } - - @NonNull - @Override - public Response intercept(@NonNull Chain chain) throws IOException { - Response response = chain.proceed(chain.request()); - if (response.code() == 401 || response.code() == 400) { - String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY); - if (accessTokenHeader == null) { - return response; - } - - String accessToken = accessTokenHeader.substring(APIUtils.AUTHORIZATION_BASE.length() - 1).trim(); - synchronized (this) { - String accessTokenFromSharedPreferences = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, ""); - if (accessToken.equals(accessTokenFromSharedPreferences)) { - String newAccessToken = refreshAccessToken(); - if (!newAccessToken.equals("")) { - response.close(); - return chain.proceed(response.request().newBuilder().headers(Headers.of(APIUtils.getRedgifsOAuthHeader(newAccessToken))).build()); - } else { - return response; - } - } else { - response.close(); - return chain.proceed(response.request().newBuilder().headers(Headers.of(APIUtils.getRedgifsOAuthHeader(accessTokenFromSharedPreferences))).build()); - } - } - } - return response; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ReplyNotificationsToggle.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ReplyNotificationsToggle.java deleted file mode 100644 index c5c29dec..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ReplyNotificationsToggle.java +++ /dev/null @@ -1,45 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.Handler; - -import androidx.annotation.NonNull; - -import java.util.HashMap; -import java.util.Map; - -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.comment.Comment; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class ReplyNotificationsToggle { - public static void toggleEnableNotification(Handler handler, Retrofit oauthRetrofit, String accessToken, - Comment comment, SendNotificationListener sendNotificationListener) { - Map params = new HashMap<>(); - params.put(APIUtils.ID_KEY, comment.getFullName()); - params.put(APIUtils.STATE_KEY, String.valueOf(!comment.isSendReplies())); - oauthRetrofit.create(RedditAPI.class).toggleRepliesNotification(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - handler.post(sendNotificationListener::onSuccess); - } else { - handler.post(sendNotificationListener::onError); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { - handler.post(sendNotificationListener::onError); - } - }); - } - - public interface SendNotificationListener { - void onSuccess(); - void onError(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ReportReason.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ReportReason.java deleted file mode 100644 index 04f139ef..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ReportReason.java +++ /dev/null @@ -1,90 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.content.Context; -import android.os.Parcel; -import android.os.Parcelable; - -import java.util.ArrayList; - -public class ReportReason implements Parcelable { - public static final String REASON_TYPE_SITE_REASON = "site_reason"; - public static final String REASON_TYPE_RULE_REASON = "rule_reason"; - public static final String REASON_TYPE_OTHER_REASON = "other_reason"; - public static final String REASON_SITE_REASON_SELECTED = "site_reason_selected"; - public static final String REASON_RULE_REASON_SELECTED = "rule_reason_selected"; - public static final String REASON_OTHER = "other"; - - private final String reportReason; - private final String reasonType; - private boolean isSelected; - - public ReportReason(String reportReason, String reasonType) { - this.reportReason = reportReason; - this.reasonType = reasonType; - this.isSelected = false; - } - - protected ReportReason(Parcel in) { - reportReason = in.readString(); - reasonType = in.readString(); - isSelected = in.readByte() != 0; - } - - public static final Creator CREATOR = new Creator() { - @Override - public ReportReason createFromParcel(Parcel in) { - return new ReportReason(in); - } - - @Override - public ReportReason[] newArray(int size) { - return new ReportReason[size]; - } - }; - - public String getReportReason() { - return reportReason; - } - - public String getReasonType() { - return reasonType; - } - - public boolean isSelected() { - return isSelected; - } - - public void setSelected(boolean selected) { - isSelected = selected; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(reportReason); - parcel.writeString(reasonType); - parcel.writeByte((byte) (isSelected ? 1 : 0)); - } - - public static ArrayList getGeneralReasons(Context context) { - ArrayList reportReasons = new ArrayList<>(); - reportReasons.add(new ReportReason(context.getString(R.string.report_reason_general_spam), REASON_TYPE_SITE_REASON)); - reportReasons.add(new ReportReason(context.getString(R.string.report_reason_general_copyright_issue), REASON_TYPE_SITE_REASON)); - reportReasons.add(new ReportReason(context.getString(R.string.report_reason_general_child_pornography), REASON_TYPE_SITE_REASON)); - reportReasons.add(new ReportReason(context.getString(R.string.report_reason_general_abusive_content), REASON_TYPE_SITE_REASON)); - return reportReasons; - } - - public static ArrayList convertRulesToReasons(ArrayList rules) { - ArrayList reportReasons = new ArrayList<>(); - for (Rule r : rules) { - reportReasons.add(new ReportReason(r.getShortName(), REASON_TYPE_RULE_REASON)); - } - - return reportReasons; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ReportThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ReportThing.java deleted file mode 100644 index dc69a541..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ReportThing.java +++ /dev/null @@ -1,55 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import androidx.annotation.NonNull; - -import java.util.HashMap; -import java.util.Map; - -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class ReportThing { - - public interface ReportThingListener { - void success(); - void failed(); - } - - public static void reportThing(Retrofit oauthRetrofit, String accessToken, String thingFullname, - String subredditName, String reasonType, String reason, - ReportThingListener reportThingListener) { - Map header = APIUtils.getOAuthHeader(accessToken); - Map params = new HashMap<>(); - params.put(APIUtils.THING_ID_KEY, thingFullname); - params.put(APIUtils.SR_NAME_KEY, subredditName); - params.put(reasonType, reason); - if (reasonType.equals(ReportReason.REASON_TYPE_SITE_REASON)) { - params.put(APIUtils.REASON_KEY, ReportReason.REASON_SITE_REASON_SELECTED); - } else if (reasonType.equals(ReportReason.REASON_TYPE_RULE_REASON)) { - params.put(APIUtils.REASON_KEY, ReportReason.REASON_RULE_REASON_SELECTED); - } else { - params.put(APIUtils.REASON_KEY, ReportReason.REASON_OTHER); - } - params.put(APIUtils.API_TYPE_KEY, APIUtils.API_TYPE_JSON); - - oauthRetrofit.create(RedditAPI.class).report(header, params).enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - reportThingListener.success(); - } else { - reportThingListener.failed(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - reportThingListener.failed(); - } - }); - } -} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Rule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Rule.java deleted file mode 100644 index 95fa064a..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Rule.java +++ /dev/null @@ -1,19 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -public class Rule { - private final String shortName; - private final String descriptionHtml; - - public Rule(String shortName, String descriptionHtml) { - this.shortName = shortName; - this.descriptionHtml = descriptionHtml; - } - - public String getShortName() { - return shortName; - } - - public String getDescriptionHtml() { - return descriptionHtml; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SaveThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SaveThing.java deleted file mode 100644 index 262a22d4..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SaveThing.java +++ /dev/null @@ -1,63 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import androidx.annotation.NonNull; - -import java.util.HashMap; -import java.util.Map; - -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class SaveThing { - public static void saveThing(Retrofit oauthRetrofit, String accessToken, String fullname, - SaveThingListener saveThingListener) { - Map params = new HashMap<>(); - params.put(APIUtils.ID_KEY, fullname); - oauthRetrofit.create(RedditAPI.class).save(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - saveThingListener.success(); - } else { - saveThingListener.failed(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - saveThingListener.failed(); - } - }); - } - - public static void unsaveThing(Retrofit oauthRetrofit, String accessToken, String fullname, - SaveThingListener saveThingListener) { - Map params = new HashMap<>(); - params.put(APIUtils.ID_KEY, fullname); - oauthRetrofit.create(RedditAPI.class).unsave(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - saveThingListener.success(); - } else { - saveThingListener.failed(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - saveThingListener.failed(); - } - }); - } - - public interface SaveThingListener { - void success(); - - void failed(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SelectThingReturnKey.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SelectThingReturnKey.java deleted file mode 100644 index d2b72696..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SelectThingReturnKey.java +++ /dev/null @@ -1,21 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import androidx.annotation.IntDef; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -public class SelectThingReturnKey { - public static final String RETURN_EXTRA_SUBREDDIT_OR_USER_NAME = "RESOUN"; - public static final String RETURN_EXTRA_SUBREDDIT_OR_USER_ICON = "RESOUI"; - public static final String RETRUN_EXTRA_MULTIREDDIT = "REM"; - public static final String RETURN_EXTRA_THING_TYPE = "RETT"; - - @IntDef({THING_TYPE.SUBREDDIT, THING_TYPE.USER, THING_TYPE.MULTIREDDIT}) - @Retention(RetentionPolicy.SOURCE) - public @interface THING_TYPE { - int SUBREDDIT = 0; - int USER = 1; - int MULTIREDDIT = 2; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SelectUserFlair.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SelectUserFlair.java deleted file mode 100644 index 85b40bdc..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SelectUserFlair.java +++ /dev/null @@ -1,103 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.AsyncTask; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.HashMap; -import java.util.Map; - -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.JSONUtils; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; -import retrofit2.Retrofit; - -public class SelectUserFlair { - public interface SelectUserFlairListener { - void success(); - void failed(String errorMessage); - } - - public static void selectUserFlair(Retrofit oauthRetrofit, String accessToken, @Nullable UserFlair userFlair, - String subredditName, @NonNull String accountName, SelectUserFlairListener selectUserFlairListener) { - Map params = new HashMap<>(); - params.put(APIUtils.API_TYPE_KEY, APIUtils.API_TYPE_JSON); - if (userFlair != null) { - params.put(APIUtils.FLAIR_TEMPLATE_ID_KEY, userFlair.getId()); - params.put(APIUtils.TEXT_KEY, userFlair.getText()); - } - params.put(APIUtils.NAME_KEY, accountName); - oauthRetrofit.create(RedditAPI.class).selectUserFlair(APIUtils.getOAuthHeader(accessToken), params, subredditName) - .enqueue(new Callback<>() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - new ParseErrorAsyncTask(response.body(), selectUserFlairListener).execute(); - } else { - selectUserFlairListener.failed(response.message()); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - selectUserFlairListener.failed(t.getMessage()); - } - }); - } - - private static class ParseErrorAsyncTask extends AsyncTask { - - private final String response; - @Nullable - private String errorMessage; - private final SelectUserFlairListener selectUserFlairListener; - - ParseErrorAsyncTask(String response, SelectUserFlairListener selectUserFlairListener) { - this.response = response; - this.selectUserFlairListener = selectUserFlairListener; - } - - @Override - protected Void doInBackground(Void... voids) { - try { - JSONObject responseObject = new JSONObject(response).getJSONObject(JSONUtils.JSON_KEY); - - if (responseObject.getJSONArray(JSONUtils.ERRORS_KEY).length() != 0) { - JSONArray error = responseObject.getJSONArray(JSONUtils.ERRORS_KEY) - .getJSONArray(responseObject.getJSONArray(JSONUtils.ERRORS_KEY).length() - 1); - if (error.length() != 0) { - String errorString; - if (error.length() >= 2) { - errorString = error.getString(1); - } else { - errorString = error.getString(0); - } - errorMessage = errorString.substring(0, 1).toUpperCase() + errorString.substring(1); - } - } - } catch (JSONException e) { - e.printStackTrace(); - } - - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - if (errorMessage == null) { - selectUserFlairListener.success(); - } else { - selectUserFlairListener.failed(errorMessage); - } - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java deleted file mode 100644 index 537a5292..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SortType.java +++ /dev/null @@ -1,73 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -public class SortType { - - @NonNull - private final Type type; - @Nullable - private final Time time; - - public SortType(@NonNull Type type) { - this(type, null); - } - - public SortType(@NonNull Type type, @Nullable Time time) { - this.type = type; - this.time = time; - } - - @NonNull - public Type getType() { - return type; - } - - @Nullable - public Time getTime() { - return time; - } - - public enum Type { - BEST("best", "Best"), - HOT("hot", "Hot"), - NEW("new", "New"), - RANDOM("random", "Random"), - RISING("rising", "Rising"), - TOP("top", "Top"), - CONTROVERSIAL("controversial", "Controversial"), - RELEVANCE("relevance", "Relevance"), - COMMENTS("comments", "Comments"), - ACTIVITY("activity", "Activity"), - CONFIDENCE("confidence", "Best"), - OLD("old", "Old"), - QA("qa", "QA"), - LIVE("live", "Live"); - - public final String value; - public final String fullName; - - Type(String value, String fullName) { - this.value = value; - this.fullName = fullName; - } - } - - public enum Time { - HOUR("hour", "Hour"), - DAY("day", "Day"), - WEEK("week", "Week"), - MONTH("month", "Month"), - YEAR("year", "Year"), - ALL("all", "All Time"); - - public final String value; - public final String fullName; - - Time(String value, String fullName) { - this.value = value; - this.fullName = fullName; - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeSelectionCallback.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeSelectionCallback.java deleted file mode 100644 index 6585c3a4..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeSelectionCallback.java +++ /dev/null @@ -1,9 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -public interface SortTypeSelectionCallback { - default void sortTypeSelected(SortType sortType){} - - default void sortTypeSelected(String sortType){} - - default void searchUserAndSubredditSortTypeSelected(SortType sortType, int fragmentPosition){} -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/StreamableVideo.java b/app/src/main/java/ml/docilealligator/infinityforreddit/StreamableVideo.java deleted file mode 100644 index 909e890c..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/StreamableVideo.java +++ /dev/null @@ -1,29 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import androidx.annotation.Nullable; - -public class StreamableVideo { - public String title; - @Nullable - public Media mp4; - @Nullable - public Media mp4Mobile; - - public StreamableVideo(String title, @Nullable Media mp4, @Nullable Media mp4Mobile) { - this.title = title; - this.mp4 = mp4; - this.mp4Mobile = mp4Mobile; - } - - public static class Media { - public String url; - public int width; - public int height; - - public Media(String url, int width, int height) { - this.url = url; - this.width = width; - this.height = height; - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/TrendingSearch.java b/app/src/main/java/ml/docilealligator/infinityforreddit/TrendingSearch.java deleted file mode 100644 index f0afc541..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/TrendingSearch.java +++ /dev/null @@ -1,54 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.Parcel; -import android.os.Parcelable; - -import java.util.ArrayList; - -import ml.docilealligator.infinityforreddit.post.Post; - -public class TrendingSearch implements Parcelable { - public String queryString; - public String displayString; - public String title; - public ArrayList previews; - - public TrendingSearch(String queryString, String displayString, String title, ArrayList previews) { - this.queryString = queryString; - this.displayString = displayString; - this.title = title; - this.previews = previews; - } - - protected TrendingSearch(Parcel in) { - queryString = in.readString(); - displayString = in.readString(); - title = in.readString(); - previews = in.createTypedArrayList(Post.Preview.CREATOR); - } - - public static final Creator CREATOR = new Creator() { - @Override - public TrendingSearch createFromParcel(Parcel in) { - return new TrendingSearch(in); - } - - @Override - public TrendingSearch[] newArray(int size) { - return new TrendingSearch[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(queryString); - parcel.writeString(displayString); - parcel.writeString(title); - parcel.writeTypedList(previews); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UploadImageEnabledActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UploadImageEnabledActivity.java deleted file mode 100644 index aecde88f..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/UploadImageEnabledActivity.java +++ /dev/null @@ -1,7 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -public interface UploadImageEnabledActivity { - void uploadImage(); - void captureImage(); - void insertImageUrl(UploadedImage uploadedImage); -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UploadedImage.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UploadedImage.java deleted file mode 100644 index 093b7843..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/UploadedImage.java +++ /dev/null @@ -1,68 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.Parcel; -import android.os.Parcelable; - -import com.google.gson.Gson; -import com.google.gson.JsonParseException; -import com.google.gson.reflect.TypeToken; - -import java.util.ArrayList; -import java.util.List; - -public class UploadedImage implements Parcelable { - public String imageName; - public String imageUrlOrKey; - private String caption = ""; - - public UploadedImage(String imageName, String imageUrlOrKey) { - this.imageName = imageName; - this.imageUrlOrKey = imageUrlOrKey; - } - - protected UploadedImage(Parcel in) { - imageName = in.readString(); - imageUrlOrKey = in.readString(); - caption = in.readString(); - } - - public String getCaption() { - return caption == null ? "" : caption; - } - - public void setCaption(String caption) { - this.caption = caption == null ? "" : caption; - } - - public static final Creator CREATOR = new Creator() { - @Override - public UploadedImage createFromParcel(Parcel in) { - return new UploadedImage(in); - } - - @Override - public UploadedImage[] newArray(int size) { - return new UploadedImage[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(imageName); - parcel.writeString(imageUrlOrKey); - parcel.writeString(caption); - } - - public static String getArrayListJSONModel(ArrayList uploadedImages) { - return new Gson().toJson(uploadedImages, new TypeToken>(){}.getType()); - } - - public static List fromListJson(String json) throws JsonParseException { - return new Gson().fromJson(json, new TypeToken>(){}.getType()); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserFlair.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserFlair.java deleted file mode 100644 index fdb8966e..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/UserFlair.java +++ /dev/null @@ -1,78 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.os.Parcel; -import android.os.Parcelable; - -public class UserFlair implements Parcelable { - private final String id; - private String text; - private final String htmlText; - private final boolean editable; - private final int maxEmojis; - - public UserFlair(String id, String text, String htmlText, boolean editable, int maxEmojis) { - this.id = id; - this.text = text; - this.htmlText = htmlText; - this.editable = editable; - this.maxEmojis = maxEmojis; - } - - protected UserFlair(Parcel in) { - id = in.readString(); - text = in.readString(); - htmlText = in.readString(); - editable = in.readByte() != 0; - maxEmojis = in.readInt(); - } - - public static final Creator CREATOR = new Creator() { - @Override - public UserFlair createFromParcel(Parcel in) { - return new UserFlair(in); - } - - @Override - public UserFlair[] newArray(int size) { - return new UserFlair[size]; - } - }; - - public String getId() { - return id; - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - public String getHtmlText() { - return htmlText; - } - - public boolean isEditable() { - return editable; - } - - public int getMaxEmojis() { - return maxEmojis; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeString(id); - parcel.writeString(text); - parcel.writeString(htmlText); - parcel.writeByte((byte) (editable ? 1 : 0)); - parcel.writeInt(maxEmojis); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java deleted file mode 100644 index 9fb23c86..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java +++ /dev/null @@ -1,94 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.content.Context; -import android.widget.Toast; - -import androidx.annotation.NonNull; - -import java.util.HashMap; -import java.util.Map; - -import ml.docilealligator.infinityforreddit.apis.RedditAPI; -import ml.docilealligator.infinityforreddit.utils.APIUtils; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Retrofit; - -/** - * Created by alex on 3/14/18. - */ - -public class VoteThing { - - public static void voteThing(Context context, final Retrofit retrofit, String accessToken, - final VoteThingListener voteThingListener, final String fullName, - final String point, final int position) { - RedditAPI api = retrofit.create(RedditAPI.class); - - Map params = new HashMap<>(); - params.put(APIUtils.DIR_KEY, point); - params.put(APIUtils.ID_KEY, fullName); - params.put(APIUtils.RANK_KEY, APIUtils.RANK); - - Call voteThingCall = api.voteThing(APIUtils.getOAuthHeader(accessToken), params); - voteThingCall.enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { - if (response.isSuccessful()) { - voteThingListener.onVoteThingSuccess(position); - } else { - voteThingListener.onVoteThingFail(position); - Toast.makeText(context, "Code " + response.code() + " Body: " + response.body(), Toast.LENGTH_LONG).show(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - voteThingListener.onVoteThingFail(position); - Toast.makeText(context, "Network error " + "Body: " + t.getMessage(), Toast.LENGTH_LONG).show(); - } - }); - } - - public static void voteThing(Context context, final Retrofit retrofit, String accessToken, - final VoteThingWithoutPositionListener voteThingWithoutPositionListener, - final String fullName, final String point) { - RedditAPI api = retrofit.create(RedditAPI.class); - - Map params = new HashMap<>(); - params.put(APIUtils.DIR_KEY, point); - params.put(APIUtils.ID_KEY, fullName); - params.put(APIUtils.RANK_KEY, APIUtils.RANK); - - Call voteThingCall = api.voteThing(APIUtils.getOAuthHeader(accessToken), params); - voteThingCall.enqueue(new Callback() { - @Override - public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { - if (response.isSuccessful()) { - voteThingWithoutPositionListener.onVoteThingSuccess(); - } else { - voteThingWithoutPositionListener.onVoteThingFail(); - Toast.makeText(context, "Code " + response.code() + " Body: " + response.body(), Toast.LENGTH_LONG).show(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable t) { - voteThingWithoutPositionListener.onVoteThingFail(); - Toast.makeText(context, "Network error " + "Body: " + t.getMessage(), Toast.LENGTH_LONG).show(); - } - }); - } - - public interface VoteThingListener { - void onVoteThingSuccess(int position); - - void onVoteThingFail(int position); - } - - public interface VoteThingWithoutPositionListener { - void onVoteThingSuccess(); - - void onVoteThingFail(); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/account/FetchMyInfo.java b/app/src/main/java/ml/docilealligator/infinityforreddit/account/FetchMyInfo.java new file mode 100644 index 00000000..e2685a7b --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/account/FetchMyInfo.java @@ -0,0 +1,98 @@ +package ml.docilealligator.infinityforreddit.account; + +import android.os.AsyncTask; +import android.text.Html; + +import androidx.annotation.NonNull; + +import org.json.JSONException; +import org.json.JSONObject; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import ml.docilealligator.infinityforreddit.utils.JSONUtils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Retrofit; + +public class FetchMyInfo { + + public static void fetchAccountInfo(final Retrofit retrofit, RedditDataRoomDatabase redditDataRoomDatabase, + String accessToken, final FetchMyInfoListener fetchMyInfoListener) { + RedditAPI api = retrofit.create(RedditAPI.class); + + Call userInfo = api.getMyInfo(APIUtils.getOAuthHeader(accessToken)); + userInfo.enqueue(new Callback<>() { + @Override + public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { + if (response.isSuccessful()) { + new ParseAndSaveAccountInfoAsyncTask(response.body(), redditDataRoomDatabase, fetchMyInfoListener).execute(); + } else { + fetchMyInfoListener.onFetchMyInfoFailed(false); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + fetchMyInfoListener.onFetchMyInfoFailed(false); + } + }); + } + + public interface FetchMyInfoListener { + void onFetchMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma); + + void onFetchMyInfoFailed(boolean parseFailed); + } + + private static class ParseAndSaveAccountInfoAsyncTask extends AsyncTask { + private JSONObject jsonResponse; + private RedditDataRoomDatabase redditDataRoomDatabase; + private FetchMyInfoListener fetchMyInfoListener; + private boolean parseFailed; + + private String name; + private String profileImageUrl; + private String bannerImageUrl; + private int karma; + + ParseAndSaveAccountInfoAsyncTask(String response, RedditDataRoomDatabase redditDataRoomDatabase, + FetchMyInfoListener fetchMyInfoListener) { + try { + jsonResponse = new JSONObject(response); + this.redditDataRoomDatabase = redditDataRoomDatabase; + this.fetchMyInfoListener = fetchMyInfoListener; + parseFailed = false; + } catch (JSONException e) { + fetchMyInfoListener.onFetchMyInfoFailed(true); + } + } + + @Override + protected Void doInBackground(Void... voids) { + try { + name = jsonResponse.getString(JSONUtils.NAME_KEY); + profileImageUrl = Html.fromHtml(jsonResponse.getString(JSONUtils.ICON_IMG_KEY)).toString(); + if (!jsonResponse.isNull(JSONUtils.SUBREDDIT_KEY)) { + bannerImageUrl = Html.fromHtml(jsonResponse.getJSONObject(JSONUtils.SUBREDDIT_KEY).getString(JSONUtils.BANNER_IMG_KEY)).toString(); + } + karma = jsonResponse.getInt(JSONUtils.TOTAL_KARMA_KEY); + + redditDataRoomDatabase.accountDao().updateAccountInfo(name, profileImageUrl, bannerImageUrl, karma); + } catch (JSONException e) { + parseFailed = true; + } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + if (!parseFailed) { + fetchMyInfoListener.onFetchMyInfoSuccess(name, profileImageUrl, bannerImageUrl, karma); + } else { + fetchMyInfoListener.onFetchMyInfoFailed(true); + } + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java index 21288314..a54f0c61 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java @@ -18,12 +18,11 @@ import org.greenrobot.eventbus.Subscribe; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.fragments.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java index c38641c1..1c0c77b1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java @@ -27,9 +27,8 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.post.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ActivityToolbarInterface.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ActivityToolbarInterface.java new file mode 100644 index 00000000..f24c7043 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ActivityToolbarInterface.java @@ -0,0 +1,6 @@ +package ml.docilealligator.infinityforreddit.activities; + +public interface ActivityToolbarInterface { + void onLongPress(); + default void displaySortType() {} +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AppBarStateChangeListener.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AppBarStateChangeListener.java new file mode 100644 index 00000000..2ce7b062 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AppBarStateChangeListener.java @@ -0,0 +1,48 @@ +package ml.docilealligator.infinityforreddit.activities; + +import com.google.android.material.appbar.AppBarLayout; + +public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener { + private AppBarStateChangeListener.State mCurrentState = AppBarStateChangeListener.State.IDLE; + private int lastOffset = -1; + + @Override + public final void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { + if (lastOffset == verticalOffset) { + return; + } + lastOffset = verticalOffset; + + if (verticalOffset == 0) { + if (mCurrentState != AppBarStateChangeListener.State.EXPANDED) { + onStateChanged(appBarLayout, AppBarStateChangeListener.State.EXPANDED); + } + mCurrentState = AppBarStateChangeListener.State.EXPANDED; + } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) { + if (mCurrentState != AppBarStateChangeListener.State.COLLAPSED) { + onStateChanged(appBarLayout, AppBarStateChangeListener.State.COLLAPSED); + } + mCurrentState = AppBarStateChangeListener.State.COLLAPSED; + } else { + if (mCurrentState != AppBarStateChangeListener.State.IDLE) { + onStateChanged(appBarLayout, AppBarStateChangeListener.State.IDLE); + } + mCurrentState = AppBarStateChangeListener.State.IDLE; + } + } + + /** + * Notifies on state change + * + * @param appBarLayout Layout + * @param state Collapse state + */ + public abstract void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.State state); + + // State + public enum State { + EXPANDED, + COLLAPSED, + IDLE + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java index d0c873d0..4e3889f9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java @@ -44,8 +44,6 @@ import com.google.android.material.tabs.TabLayout; import java.lang.reflect.Field; import java.util.Locale; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.CustomFontReceiver; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.account.Account; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java index bfa5dc1d..ff0d3519 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -46,12 +46,11 @@ import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.AnyAccountAccessTokenAuthenticator; +import ml.docilealligator.infinityforreddit.network.AnyAccountAccessTokenAuthenticator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.UploadImageEnabledActivity; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.bottomsheetfragments.AccountChooserBottomSheetFragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java index e66fb00f..161d0f05 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemePreviewActivity.java @@ -40,7 +40,6 @@ import java.util.ArrayList; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.CustomFontReceiver; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java index b23d9797..629daf3f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java @@ -36,10 +36,9 @@ import javax.inject.Inject; import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.UploadImageEnabledActivity; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesBottomSheetFragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java index 151a8596..fb3caa73 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java @@ -35,8 +35,7 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.UploadImageEnabledActivity; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesBottomSheetFragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java index 07b66e49..13b2c3aa 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java @@ -23,15 +23,14 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.fragments.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.post.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FilteredThingFABMoreOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/HistoryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/HistoryActivity.java index a9b141bb..74959297 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/HistoryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/HistoryActivity.java @@ -24,7 +24,6 @@ import org.greenrobot.eventbus.Subscribe; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java index ffb1b44a..31d64b6a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java @@ -34,12 +34,11 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.asynctasks.AccountManagement; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java index 3d20da35..facb9a07 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java @@ -34,7 +34,7 @@ import javax.inject.Inject; import javax.inject.Named; import me.saket.bettermovementmethod.BetterLinkMovementMethod; -import ml.docilealligator.infinityforreddit.FetchMyInfo; +import ml.docilealligator.infinityforreddit.account.FetchMyInfo; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginChromeCustomTabActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginChromeCustomTabActivity.java index 58db6f7b..54e4582b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginChromeCustomTabActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginChromeCustomTabActivity.java @@ -31,7 +31,7 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.FetchMyInfo; +import ml.docilealligator.infinityforreddit.account.FetchMyInfo; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 64f28a26..045394ce 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -64,16 +64,15 @@ import java.util.concurrent.TimeUnit; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.FetchSubscribedThing; +import ml.docilealligator.infinityforreddit.thing.FetchSubscribedThing; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.post.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.PullNotificationWorker; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.account.AccountViewModel; import ml.docilealligator.infinityforreddit.adapters.SubredditAutocompleteRecyclerViewAdapter; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java index ec6dfb82..68e05f1b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java @@ -23,7 +23,6 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; @@ -52,12 +51,12 @@ import javax.inject.Inject; import javax.inject.Named; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.Flair; +import ml.docilealligator.infinityforreddit.subreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.RedditGalleryPayload; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.post.RedditGalleryPayload; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.adapters.RedditGallerySubmissionRecyclerViewAdapter; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java index f781e07f..69f81f82 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java @@ -40,11 +40,11 @@ import javax.inject.Inject; import javax.inject.Named; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.Flair; +import ml.docilealligator.infinityforreddit.subreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java index de85c123..2669f5b6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java @@ -35,11 +35,11 @@ import javax.inject.Inject; import javax.inject.Named; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.Flair; +import ml.docilealligator.infinityforreddit.subreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.apis.TitleSuggestion; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java index 89c4cfc2..7bd24b47 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java @@ -26,7 +26,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; import androidx.recyclerview.widget.LinearLayoutManager; @@ -51,14 +50,13 @@ import javax.inject.Inject; import javax.inject.Named; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.Flair; +import ml.docilealligator.infinityforreddit.subreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.PollPayload; +import ml.docilealligator.infinityforreddit.post.PollPayload; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; -import ml.docilealligator.infinityforreddit.UploadImageEnabledActivity; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java index 8521c97b..728c97c8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java @@ -42,13 +42,12 @@ import javax.inject.Inject; import javax.inject.Named; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.Flair; +import ml.docilealligator.infinityforreddit.subreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; -import ml.docilealligator.infinityforreddit.UploadImageEnabledActivity; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java index 97e865a3..72057b42 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java @@ -46,11 +46,11 @@ import javax.inject.Inject; import javax.inject.Named; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.Flair; +import ml.docilealligator.infinityforreddit.subreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java index 8528a3ce..77eabada 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java @@ -18,13 +18,13 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.FetchRules; +import ml.docilealligator.infinityforreddit.post.FetchRules; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.ReportReason; -import ml.docilealligator.infinityforreddit.ReportThing; -import ml.docilealligator.infinityforreddit.Rule; +import ml.docilealligator.infinityforreddit.thing.ReportReason; +import ml.docilealligator.infinityforreddit.thing.ReportThing; +import ml.docilealligator.infinityforreddit.subreddit.Rule; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.ReportReasonRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java index 0f46e512..29284219 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java @@ -21,10 +21,10 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.FetchRules; +import ml.docilealligator.infinityforreddit.post.FetchRules; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.Rule; +import ml.docilealligator.infinityforreddit.subreddit.Rule; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.RulesRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java index abc09091..5637c3b0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -41,7 +41,7 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.SearchActivityRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.adapters.SubredditAutocompleteRecyclerViewAdapter; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index 9685630f..11dc6021 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -38,15 +38,14 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.fragments.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.SubredditAutocompleteRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.apis.RedditAPI; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java index c96de881..cc292190 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java index a24acc0f..dbf3939d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java index 4bd78511..4f8a8d80 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java @@ -20,12 +20,11 @@ import java.util.ArrayList; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.FetchUserFlairs; +import ml.docilealligator.infinityforreddit.user.FetchUserFlairs; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SelectUserFlair; -import ml.docilealligator.infinityforreddit.UserFlair; +import ml.docilealligator.infinityforreddit.user.SelectUserFlair; +import ml.docilealligator.infinityforreddit.user.UserFlair; import ml.docilealligator.infinityforreddit.adapters.UserFlairRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java index 65cfa242..730a80b2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java @@ -17,10 +17,9 @@ import java.util.Collections; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.adapters.SelectedSubredditsRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SelectSubredditsOrUsersOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java index df885e2c..59c45e1c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java @@ -41,11 +41,11 @@ import javax.inject.Inject; import javax.inject.Named; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.Flair; +import ml.docilealligator.infinityforreddit.subreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; import ml.docilealligator.infinityforreddit.bottomsheetfragments.AccountChooserBottomSheetFragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java index d4421cf1..5289afa3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java index fc92dcda..061481a1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java @@ -41,10 +41,9 @@ import java.util.concurrent.TimeUnit; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.AnyAccountAccessTokenAuthenticator; -import ml.docilealligator.infinityforreddit.FetchSubscribedThing; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.network.AnyAccountAccessTokenAuthenticator; +import ml.docilealligator.infinityforreddit.thing.FetchSubscribedThing; +import ml.docilealligator.infinityforreddit.fragments.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/UploadImageEnabledActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/UploadImageEnabledActivity.java new file mode 100644 index 00000000..10c8f2b2 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/UploadImageEnabledActivity.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.activities; + +import ml.docilealligator.infinityforreddit.thing.UploadedImage; + +public interface UploadImageEnabledActivity { + void uploadImage(); + void captureImage(); + void insertImageUrl(UploadedImage uploadedImage); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java index 5981115e..8cf05256 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImgurMediaActivity.java @@ -33,7 +33,7 @@ import javax.inject.Named; import app.futured.hauler.DragDirection; import ml.docilealligator.infinityforreddit.CustomFontReceiver; -import ml.docilealligator.infinityforreddit.ImgurMedia; +import ml.docilealligator.infinityforreddit.post.ImgurMedia; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java index 436b1184..b865414c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java @@ -34,16 +34,15 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.fragments.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.post.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.SubredditAutocompleteRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.apis.RedditAPI; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index 0271d3a7..7072fff6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -50,14 +50,13 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.LoadingMorePostsStatus; +import ml.docilealligator.infinityforreddit.post.LoadingMorePostsStatus; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SaveThing; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SaveThing; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.asynctasks.AccountManagement; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java index 331141be..074c90fd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java @@ -24,7 +24,6 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index a13b6e3e..9b20c311 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -65,16 +65,14 @@ import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.post.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.SubredditAutocompleteRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.apis.RedditAPI; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index c170a56e..009b80d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -61,17 +61,15 @@ import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; -import ml.docilealligator.infinityforreddit.DeleteThing; +import ml.docilealligator.infinityforreddit.thing.DeleteThing; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.post.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.SubredditAutocompleteRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.apis.RedditAPI; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index 07d166f3..3486018c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -90,11 +90,11 @@ import javax.inject.Provider; import app.futured.hauler.DragDirection; import ml.docilealligator.infinityforreddit.CustomFontReceiver; -import ml.docilealligator.infinityforreddit.FetchRedgifsVideoLinks; -import ml.docilealligator.infinityforreddit.FetchStreamableVideo; +import ml.docilealligator.infinityforreddit.thing.FetchRedgifsVideoLinks; +import ml.docilealligator.infinityforreddit.post.FetchStreamableVideo; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.StreamableVideo; +import ml.docilealligator.infinityforreddit.thing.StreamableVideo; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.StreamableAPI; import ml.docilealligator.infinityforreddit.apis.VReddIt; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index 0397ff4d..184249b1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -34,8 +34,8 @@ import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SaveThing; -import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.thing.SaveThing; +import ml.docilealligator.infinityforreddit.thing.VoteThing; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 7db33144..3a9db964 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -40,9 +40,9 @@ import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SaveThing; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.thing.SaveThing; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.VoteThing; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FlairBottomSheetRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FlairBottomSheetRecyclerViewAdapter.java index 70b0f258..14a3d34c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FlairBottomSheetRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FlairBottomSheetRecyclerViewAdapter.java @@ -13,7 +13,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import java.util.ArrayList; -import ml.docilealligator.infinityforreddit.Flair; +import ml.docilealligator.infinityforreddit.subreddit.Flair; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java index 61e237d1..888c9f20 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java @@ -19,7 +19,7 @@ import java.util.concurrent.Executor; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import me.zhanghai.android.fastscroll.PopupTextProvider; -import ml.docilealligator.infinityforreddit.FavoriteThing; +import ml.docilealligator.infinityforreddit.thing.FavoriteThing; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.activities.BaseActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java index bab066b1..2308cf3d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java @@ -68,13 +68,13 @@ import javax.inject.Provider; import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.FetchRedgifsVideoLinks; -import ml.docilealligator.infinityforreddit.FetchStreamableVideo; +import ml.docilealligator.infinityforreddit.thing.FetchRedgifsVideoLinks; +import ml.docilealligator.infinityforreddit.post.FetchStreamableVideo; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy; -import ml.docilealligator.infinityforreddit.SaveThing; -import ml.docilealligator.infinityforreddit.StreamableVideo; -import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.thing.SaveThing; +import ml.docilealligator.infinityforreddit.thing.StreamableVideo; +import ml.docilealligator.infinityforreddit.thing.VoteThing; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 35d18ee2..1dcde814 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -66,14 +66,14 @@ import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.FetchRedgifsVideoLinks; -import ml.docilealligator.infinityforreddit.FetchStreamableVideo; +import ml.docilealligator.infinityforreddit.thing.FetchRedgifsVideoLinks; +import ml.docilealligator.infinityforreddit.post.FetchStreamableVideo; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy; -import ml.docilealligator.infinityforreddit.SaveThing; -import ml.docilealligator.infinityforreddit.StreamableVideo; -import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.thing.SaveThing; +import ml.docilealligator.infinityforreddit.thing.StreamableVideo; +import ml.docilealligator.infinityforreddit.thing.VoteThing; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 995b9de2..435b7720 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -68,14 +68,14 @@ import javax.inject.Provider; import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -import ml.docilealligator.infinityforreddit.FetchRedgifsVideoLinks; -import ml.docilealligator.infinityforreddit.FetchStreamableVideo; -import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.thing.FetchRedgifsVideoLinks; +import ml.docilealligator.infinityforreddit.post.FetchStreamableVideo; +import ml.docilealligator.infinityforreddit.post.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy; -import ml.docilealligator.infinityforreddit.SaveThing; -import ml.docilealligator.infinityforreddit.StreamableVideo; -import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.thing.SaveThing; +import ml.docilealligator.infinityforreddit.thing.StreamableVideo; +import ml.docilealligator.infinityforreddit.thing.VoteThing; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java index 5c709796..9c97d69b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RedditGallerySubmissionRecyclerViewAdapter.java @@ -28,7 +28,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.util.ArrayList; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.RedditGalleryPayload; +import ml.docilealligator.infinityforreddit.post.RedditGalleryPayload; import ml.docilealligator.infinityforreddit.activities.PostGalleryActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetRedditGalleryItemCaptionAndUrlBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/ReportReasonRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/ReportReasonRecyclerViewAdapter.java index 4ac81100..f0800927 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/ReportReasonRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/ReportReasonRecyclerViewAdapter.java @@ -9,7 +9,7 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; -import ml.docilealligator.infinityforreddit.ReportReason; +import ml.docilealligator.infinityforreddit.thing.ReportReason; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.databinding.ItemReportReasonBinding; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java index 3aefb319..66b7c31a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -22,7 +22,7 @@ import io.noties.markwon.MarkwonConfiguration; import io.noties.markwon.MarkwonPlugin; import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.recycler.MarkwonAdapter; -import ml.docilealligator.infinityforreddit.Rule; +import ml.docilealligator.infinityforreddit.subreddit.Rule; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewImageOrGifActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java index f4b97116..e7bf496e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java @@ -10,7 +10,7 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.List; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.databinding.ItemRecentSearchQueryBinding; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java index 93ad1ca5..67448104 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SubscribedSubredditsRecyclerViewAdapter.java @@ -20,7 +20,7 @@ import java.util.concurrent.Executor; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import me.zhanghai.android.fastscroll.PopupTextProvider; -import ml.docilealligator.infinityforreddit.FavoriteThing; +import ml.docilealligator.infinityforreddit.thing.FavoriteThing; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.activities.BaseActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UploadedImagesRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UploadedImagesRecyclerViewAdapter.java index 744813bb..f2c0364b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UploadedImagesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UploadedImagesRecyclerViewAdapter.java @@ -12,7 +12,7 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; import ml.docilealligator.infinityforreddit.activities.BaseActivity; public class UploadedImagesRecyclerViewAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java index be72915f..edf24c89 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/UserFlairRecyclerViewAdapter.java @@ -10,7 +10,7 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.UserFlair; +import ml.docilealligator.infinityforreddit.user.UserFlair; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.databinding.ItemUserFlairBinding; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java index 838b714b..9c2f2f07 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java @@ -4,7 +4,7 @@ import com.google.common.util.concurrent.ListenableFuture; import java.util.Map; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.utils.APIUtils; import okhttp3.MultipartBody; import okhttp3.RequestBody; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java index 889de962..f1e2e198 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CommentMoreBottomSheetFragment.java @@ -18,7 +18,7 @@ import androidx.fragment.app.Fragment; import java.util.ArrayList; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java index 75f88bbc..9479ce72 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FlairBottomSheetFragment.java @@ -19,8 +19,8 @@ import java.util.ArrayList; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.FetchFlairs; -import ml.docilealligator.infinityforreddit.Flair; +import ml.docilealligator.infinityforreddit.subreddit.FetchFlairs; +import ml.docilealligator.infinityforreddit.subreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.BaseActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostCommentSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostCommentSortTypeBottomSheetFragment.java index ff8102b8..9c216b9f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostCommentSortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PostCommentSortTypeBottomSheetFragment.java @@ -14,8 +14,8 @@ import androidx.appcompat.content.res.AppCompatResources; import androidx.fragment.app.Fragment; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.databinding.FragmentPostCommentSortTypeBottomSheetBinding; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchPostSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchPostSortTypeBottomSheetFragment.java index 85d49273..c8d8cbe9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchPostSortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchPostSortTypeBottomSheetFragment.java @@ -14,8 +14,8 @@ import androidx.appcompat.content.res.AppCompatResources; import androidx.fragment.app.Fragment; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.databinding.FragmentSearchPostSortTypeBottomSheetBinding; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchUserAndSubredditSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchUserAndSubredditSortTypeBottomSheetFragment.java index 9cc38685..a9d499a7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchUserAndSubredditSortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SearchUserAndSubredditSortTypeBottomSheetFragment.java @@ -14,8 +14,8 @@ import androidx.appcompat.content.res.AppCompatResources; import androidx.fragment.app.Fragment; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.databinding.FragmentSearchUserAndSubredditSortTypeBottomSheetBinding; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTimeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTimeBottomSheetFragment.java index 71768040..7ef4af33 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTimeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTimeBottomSheetFragment.java @@ -12,8 +12,8 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.databinding.FragmentSortTimeBottomSheetBinding; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTypeBottomSheetFragment.java index 9a5a7454..3db35fad 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SortTypeBottomSheetFragment.java @@ -14,8 +14,8 @@ import androidx.appcompat.content.res.AppCompatResources; import androidx.fragment.app.Fragment; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.databinding.FragmentSortTypeBottomSheetBinding; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UploadedImagesBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UploadedImagesBottomSheetFragment.java index 2ff9fb31..db73ad23 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UploadedImagesBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UploadedImagesBottomSheetFragment.java @@ -9,7 +9,7 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; -import ml.docilealligator.infinityforreddit.UploadImageEnabledActivity; +import ml.docilealligator.infinityforreddit.activities.UploadImageEnabledActivity; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.adapters.UploadedImagesRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UserThingSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UserThingSortTypeBottomSheetFragment.java index e27334cc..a1c280a6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UserThingSortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/UserThingSortTypeBottomSheetFragment.java @@ -14,8 +14,8 @@ import androidx.appcompat.content.res.AppCompatResources; import androidx.fragment.app.Fragment; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.databinding.FragmentUserThingSortTypeBottomSheetBinding; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java index cd56a03b..140e0332 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java @@ -7,7 +7,7 @@ import java.util.ArrayList; import java.util.Map; import ml.docilealligator.infinityforreddit.BuildConfig; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; import ml.docilealligator.infinityforreddit.utils.APIUtils; public class Comment implements Parcelable { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSource.java index abd5e266..7f4bf776 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSource.java @@ -14,7 +14,7 @@ import org.json.JSONObject; import java.util.ArrayList; import ml.docilealligator.infinityforreddit.NetworkState; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.post.PostPagingSource; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSourceFactory.java index 5ae58264..c1931f8f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSourceFactory.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentDataSourceFactory.java @@ -5,7 +5,7 @@ import androidx.annotation.Nullable; import androidx.lifecycle.MutableLiveData; import androidx.paging.DataSource; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import retrofit2.Retrofit; class CommentDataSourceFactory extends DataSource.Factory { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java index df291cc6..faa2d6e4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java @@ -11,7 +11,7 @@ import androidx.paging.LivePagedListBuilder; import androidx.paging.PagedList; import ml.docilealligator.infinityforreddit.NetworkState; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import retrofit2.Retrofit; public class CommentViewModel extends ViewModel { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchComment.java index 0c6fce12..1045dd8f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/FetchComment.java @@ -8,7 +8,7 @@ import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.concurrent.Executor; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java index 29d8ad70..82dc1fca 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java @@ -19,7 +19,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.Executor; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter; import ml.docilealligator.infinityforreddit.utils.JSONUtils; import ml.docilealligator.infinityforreddit.utils.Utils; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/SendComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/SendComment.java index 18d6c0a0..0d7e5922 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/SendComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/SendComment.java @@ -14,7 +14,7 @@ import java.util.Map; import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.markdown.RichTextJSONConverter; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomThemeWrapperReceiver.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomThemeWrapperReceiver.java new file mode 100644 index 00000000..422f52ff --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomThemeWrapperReceiver.java @@ -0,0 +1,5 @@ +package ml.docilealligator.infinityforreddit.customtheme; + +public interface CustomThemeWrapperReceiver { + void setCustomThemeWrapper(CustomThemeWrapper customThemeWrapper); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontEditTextPreference.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontEditTextPreference.java index 49e8e438..57a07271 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontEditTextPreference.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontEditTextPreference.java @@ -11,7 +11,7 @@ import androidx.preference.EditTextPreference; import androidx.preference.PreferenceViewHolder; import ml.docilealligator.infinityforreddit.CustomFontReceiver; -import ml.docilealligator.infinityforreddit.CustomThemeWrapperReceiver; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapperReceiver; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; public class CustomFontEditTextPreference extends EditTextPreference implements CustomFontReceiver, CustomThemeWrapperReceiver { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontListPreference.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontListPreference.java index f7159828..3d9ad387 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontListPreference.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontListPreference.java @@ -11,7 +11,7 @@ import androidx.preference.ListPreference; import androidx.preference.PreferenceViewHolder; import ml.docilealligator.infinityforreddit.CustomFontReceiver; -import ml.docilealligator.infinityforreddit.CustomThemeWrapperReceiver; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapperReceiver; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; public class CustomFontListPreference extends ListPreference implements CustomFontReceiver, CustomThemeWrapperReceiver { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreference.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreference.java index f08a157f..d2eba5b3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreference.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreference.java @@ -11,7 +11,7 @@ import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; import ml.docilealligator.infinityforreddit.CustomFontReceiver; -import ml.docilealligator.infinityforreddit.CustomThemeWrapperReceiver; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapperReceiver; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; public class CustomFontPreference extends Preference implements CustomFontReceiver, CustomThemeWrapperReceiver { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceCategory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceCategory.java index 8514796d..d7fb3b8a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceCategory.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceCategory.java @@ -10,7 +10,7 @@ import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceViewHolder; import ml.docilealligator.infinityforreddit.CustomFontReceiver; -import ml.docilealligator.infinityforreddit.CustomThemeWrapperReceiver; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapperReceiver; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; public class CustomFontPreferenceCategory extends PreferenceCategory implements CustomFontReceiver, CustomThemeWrapperReceiver { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceFragmentCompat.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceFragmentCompat.java index 3357918a..46bc7ec8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceFragmentCompat.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontPreferenceFragmentCompat.java @@ -11,7 +11,7 @@ import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceScreen; import ml.docilealligator.infinityforreddit.CustomFontReceiver; -import ml.docilealligator.infinityforreddit.CustomThemeWrapperReceiver; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapperReceiver; import ml.docilealligator.infinityforreddit.activities.SettingsActivity; public abstract class CustomFontPreferenceFragmentCompat extends PreferenceFragmentCompat { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSeekBarPreference.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSeekBarPreference.java index 08a0477b..434cf84d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSeekBarPreference.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSeekBarPreference.java @@ -11,7 +11,7 @@ import androidx.preference.PreferenceViewHolder; import androidx.preference.SeekBarPreference; import ml.docilealligator.infinityforreddit.CustomFontReceiver; -import ml.docilealligator.infinityforreddit.CustomThemeWrapperReceiver; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapperReceiver; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; public class CustomFontSeekBarPreference extends SeekBarPreference implements CustomFontReceiver, CustomThemeWrapperReceiver { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSwitchPreference.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSwitchPreference.java index 347d8b29..a497488a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSwitchPreference.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CustomFontSwitchPreference.java @@ -14,7 +14,7 @@ import androidx.preference.SwitchPreference; import com.google.android.material.materialswitch.MaterialSwitch; import ml.docilealligator.infinityforreddit.CustomFontReceiver; -import ml.docilealligator.infinityforreddit.CustomThemeWrapperReceiver; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapperReceiver; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/FlairSelectedEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/FlairSelectedEvent.java index 4ff85a89..43a22963 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/events/FlairSelectedEvent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/FlairSelectedEvent.java @@ -1,6 +1,6 @@ package ml.docilealligator.infinityforreddit.events; -import ml.docilealligator.infinityforreddit.Flair; +import ml.docilealligator.infinityforreddit.subreddit.Flair; public class FlairSelectedEvent { public long viewPostDetailFragmentId; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ProvidePostListToViewPostDetailActivityEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ProvidePostListToViewPostDetailActivityEvent.java index ffe27c0d..e387c27d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/events/ProvidePostListToViewPostDetailActivityEvent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/events/ProvidePostListToViewPostDetailActivityEvent.java @@ -2,7 +2,7 @@ package ml.docilealligator.infinityforreddit.events; import java.util.ArrayList; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java index 98fb14ea..e4a3adbe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java @@ -35,14 +35,13 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.ReplyNotificationsToggle; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.ReplyNotificationsToggle; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.adapters.CommentsListingRecyclerViewAdapter; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java index 8fe7ea2e..2f3a2bcf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FollowedUsersListingFragment.java @@ -25,11 +25,10 @@ import javax.inject.Inject; import javax.inject.Named; import me.zhanghai.android.fastscroll.FastScrollerBuilder; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FragmentCommunicator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FragmentCommunicator.java new file mode 100644 index 00000000..73165e2f --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/FragmentCommunicator.java @@ -0,0 +1,54 @@ +package ml.docilealligator.infinityforreddit.fragments; + +import ml.docilealligator.infinityforreddit.postfilter.PostFilter; + +public interface FragmentCommunicator { + default void refresh() { + } + + default boolean handleKeyDown(int keyCode) { + return false; + } + + default void changeNSFW(boolean nsfw) { + } + + default boolean startLazyMode() { + return false; + } + + default void stopLazyMode() { + } + + default void resumeLazyMode(boolean resumeNow) { + } + + default void pauseLazyMode(boolean startTimer) { + } + + default boolean isInLazyMode() { + return false; + } + + default void changePostLayout(int postLayout) { + } + + default void stopRefreshProgressbar() { + } + + void applyTheme(); + + default void hideReadPosts() { + } + + default void changePostFilter(PostFilter postFilter) { + } + + default PostFilter getPostFilter() { + return null; + } + + default void filterPosts() { + + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java index eb47e9ba..05667f8e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/HistoryPostFragment.java @@ -58,7 +58,6 @@ import javax.inject.Named; import javax.inject.Provider; import ml.docilealligator.infinityforreddit.FetchPostFilterReadPostsAndConcatenatedSubredditNames; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java index db4076cc..51af2bfb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/InboxFragment.java @@ -23,7 +23,6 @@ import org.greenrobot.eventbus.Subscribe; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MorePostsInfoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MorePostsInfoFragment.java index f38527dd..661c0a08 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MorePostsInfoFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MorePostsInfoFragment.java @@ -12,7 +12,7 @@ import androidx.fragment.app.Fragment; import javax.inject.Inject; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.LoadingMorePostsStatus; +import ml.docilealligator.infinityforreddit.post.LoadingMorePostsStatus; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java index c603d222..87450086 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java @@ -25,11 +25,10 @@ import javax.inject.Inject; import javax.inject.Named; import me.zhanghai.android.fastscroll.FastScrollerBuilder; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 68131e45..31e80ced 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -60,14 +60,13 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Provider; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; +import ml.docilealligator.infinityforreddit.activities.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.FetchPostFilterReadPostsAndConcatenatedSubredditNames; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.AccountPostsActivity; import ml.docilealligator.infinityforreddit.activities.AccountSavedThingActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java index f168cd3d..72951c40 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubredditListingFragment.java @@ -27,14 +27,13 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java index 459e3d91..696411e2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SubscribedSubredditsListingFragment.java @@ -25,11 +25,10 @@ import javax.inject.Inject; import javax.inject.Named; import me.zhanghai.android.fastscroll.FastScrollerBuilder; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java index 7fb40b34..ba149282 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/UserListingFragment.java @@ -26,14 +26,13 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RecyclerViewContentScrollingInterface; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java index 5b67f459..074459ca 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java @@ -43,7 +43,7 @@ import java.util.concurrent.Executor; import javax.inject.Inject; import ml.docilealligator.infinityforreddit.BuildConfig; -import ml.docilealligator.infinityforreddit.ImgurMedia; +import ml.docilealligator.infinityforreddit.post.ImgurMedia; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java index 47d04de7..71391948 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java @@ -49,7 +49,7 @@ import com.google.common.collect.ImmutableList; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.ImgurMedia; +import ml.docilealligator.infinityforreddit.post.ImgurMedia; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 84a566b4..a2e43d08 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -61,15 +61,14 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Provider; -import ml.docilealligator.infinityforreddit.DeleteThing; -import ml.docilealligator.infinityforreddit.Flair; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.thing.DeleteThing; +import ml.docilealligator.infinityforreddit.subreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SaveThing; -import ml.docilealligator.infinityforreddit.ReplyNotificationsToggle; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SaveThing; +import ml.docilealligator.infinityforreddit.thing.ReplyNotificationsToggle; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.EditPostActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/Emote.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/Emote.java index 90517682..24631807 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/Emote.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/Emote.java @@ -3,7 +3,7 @@ package ml.docilealligator.infinityforreddit.markdown; import org.commonmark.node.CustomNode; import org.commonmark.node.Visitor; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; public class Emote extends CustomNode { private final MediaMetadata mediaMetadata; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmoteCloseBracketInlineProcessor.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmoteCloseBracketInlineProcessor.java index b24dc484..ffb51d80 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmoteCloseBracketInlineProcessor.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmoteCloseBracketInlineProcessor.java @@ -14,7 +14,7 @@ import java.util.Map; import java.util.regex.Pattern; import io.noties.markwon.inlineparser.InlineProcessor; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; public class EmoteCloseBracketInlineProcessor extends InlineProcessor { private static final Pattern WHITESPACE = Pattern.compile("\\s+"); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java index 1fbc68d4..dd263565 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java @@ -35,7 +35,7 @@ import io.noties.markwon.image.AsyncDrawableLoader; import io.noties.markwon.image.AsyncDrawableScheduler; import io.noties.markwon.image.DrawableUtils; import io.noties.markwon.image.ImageProps; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifBlock.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifBlock.java index d336c5b4..74570db3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifBlock.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifBlock.java @@ -2,7 +2,7 @@ package ml.docilealligator.infinityforreddit.markdown; import org.commonmark.node.CustomBlock; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; public class ImageAndGifBlock extends CustomBlock { public MediaMetadata mediaMetadata; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifBlockParser.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifBlockParser.java index ec982d30..b58094f4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifBlockParser.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifBlockParser.java @@ -14,7 +14,7 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; public class ImageAndGifBlockParser extends AbstractBlockParser { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java index 5f56faca..cb09c22b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java @@ -32,7 +32,7 @@ import io.noties.markwon.recycler.MarkwonAdapter; import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import me.saket.bettermovementmethod.BetterLinkMovementMethod; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifPlugin.java index d1db5a3d..8484779e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifPlugin.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifPlugin.java @@ -7,7 +7,7 @@ import org.commonmark.parser.Parser; import java.util.Map; import io.noties.markwon.AbstractMarkwonPlugin; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; public class ImageAndGifPlugin extends AbstractMarkwonPlugin { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java index f021e3fe..3ea511be 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java @@ -47,7 +47,7 @@ import java.util.Stack; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonReducer; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; public class RichTextJSONConverter implements Visitor { private static final int BOLD = 1; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/UploadedImageBlock.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/UploadedImageBlock.java index e6e3371c..3561ffbe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/UploadedImageBlock.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/UploadedImageBlock.java @@ -2,7 +2,7 @@ package ml.docilealligator.infinityforreddit.markdown; import org.commonmark.node.CustomBlock; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; public class UploadedImageBlock extends CustomBlock { public UploadedImage uploadeImage; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/UploadedImageBlockParser.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/UploadedImageBlockParser.java index ca9c0904..392e2a82 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/UploadedImageBlockParser.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/UploadedImageBlockParser.java @@ -16,7 +16,7 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; public class UploadedImageBlockParser extends AbstractBlockParser { private final UploadedImageBlock uploadedImageBlock; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/UploadedImagePlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/UploadedImagePlugin.java index 64645a84..adf5d283 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/UploadedImagePlugin.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/UploadedImagePlugin.java @@ -7,7 +7,7 @@ import org.commonmark.parser.Parser; import java.util.List; import io.noties.markwon.AbstractMarkwonPlugin; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; public class UploadedImagePlugin extends AbstractMarkwonPlugin { private final UploadedImageBlockParser.Factory factory; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/network/AccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/network/AccessTokenAuthenticator.java new file mode 100644 index 00000000..e47141c1 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/network/AccessTokenAuthenticator.java @@ -0,0 +1,104 @@ +package ml.docilealligator.infinityforreddit.network; + +import android.content.SharedPreferences; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import okhttp3.Authenticator; +import okhttp3.Headers; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.Route; +import retrofit2.Call; +import retrofit2.Retrofit; + +public class AccessTokenAuthenticator implements Authenticator { + private final Retrofit mRetrofit; + private final RedditDataRoomDatabase mRedditDataRoomDatabase; + private final SharedPreferences mCurrentAccountSharedPreferences; + + public AccessTokenAuthenticator(Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase, SharedPreferences currentAccountSharedPreferences) { + mRetrofit = retrofit; + mRedditDataRoomDatabase = accountRoomDatabase; + mCurrentAccountSharedPreferences = currentAccountSharedPreferences; + } + + @Nullable + @Override + public Request authenticate(Route route, @NonNull Response response) { + if (response.code() == 401) { + String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY); + if (accessTokenHeader == null) { + return null; + } + + String accessToken = accessTokenHeader.substring(APIUtils.AUTHORIZATION_BASE.length()); + synchronized (this) { + Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); + if (account == null) { + return null; + } + String accessTokenFromDatabase = account.getAccessToken(); + if (accessToken.equals(accessTokenFromDatabase)) { + String newAccessToken = refreshAccessToken(account); + if (!newAccessToken.equals("")) { + return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(newAccessToken))).build(); + } else { + return null; + } + } else { + return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(accessTokenFromDatabase))).build(); + } + } + } + return null; + } + + private String refreshAccessToken(Account account) { + String refreshToken = mRedditDataRoomDatabase.accountDao().getCurrentAccount().getRefreshToken(); + + RedditAPI api = mRetrofit.create(RedditAPI.class); + + Map params = new HashMap<>(); + params.put(APIUtils.GRANT_TYPE_KEY, APIUtils.GRANT_TYPE_REFRESH_TOKEN); + params.put(APIUtils.REFRESH_TOKEN_KEY, refreshToken); + + Call accessTokenCall = api.getAccessToken(APIUtils.getHttpBasicAuthHeader(), params); + try { + retrofit2.Response response = accessTokenCall.execute(); + if (response.isSuccessful() && response.body() != null) { + JSONObject jsonObject = new JSONObject(response.body()); + String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY); + String newRefreshToken = jsonObject.has(APIUtils.REFRESH_TOKEN_KEY) ? jsonObject.getString(APIUtils.REFRESH_TOKEN_KEY) : null; + if (newRefreshToken == null) { + mRedditDataRoomDatabase.accountDao().updateAccessToken(account.getAccountName(), newAccessToken); + } else { + mRedditDataRoomDatabase.accountDao().updateAccessTokenAndRefreshToken(account.getAccountName(), newAccessToken, newRefreshToken); + } + if (mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT).equals(account.getAccountName())) { + mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, newAccessToken).apply(); + } + + return newAccessToken; + } + return ""; + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + + return ""; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/network/AnyAccountAccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/network/AnyAccountAccessTokenAuthenticator.java new file mode 100644 index 00000000..d31c4d6c --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/network/AnyAccountAccessTokenAuthenticator.java @@ -0,0 +1,107 @@ +package ml.docilealligator.infinityforreddit.network; + +import android.content.SharedPreferences; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import okhttp3.Authenticator; +import okhttp3.Headers; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.Route; +import retrofit2.Call; +import retrofit2.Retrofit; + +public class AnyAccountAccessTokenAuthenticator implements Authenticator { + private final Retrofit mRetrofit; + private final RedditDataRoomDatabase mRedditDataRoomDatabase; + private final Account mAccount; + private final SharedPreferences mCurrentAccountSharedPreferences; + + public AnyAccountAccessTokenAuthenticator(Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase, Account account, + SharedPreferences currentAccountSharedPreferences) { + mRetrofit = retrofit; + mRedditDataRoomDatabase = accountRoomDatabase; + mAccount = account; + mCurrentAccountSharedPreferences = currentAccountSharedPreferences; + } + + @Nullable + @Override + public Request authenticate(Route route, @NonNull Response response) { + if (response.code() == 401) { + String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY); + if (accessTokenHeader == null) { + return null; + } + + String accessToken = accessTokenHeader.substring(APIUtils.AUTHORIZATION_BASE.length()); + synchronized (this) { + if (mAccount == null) { + return null; + } + String accessTokenFromDatabase = mAccount.getAccessToken(); + if (accessToken.equals(accessTokenFromDatabase)) { + String newAccessToken = refreshAccessToken(mAccount); + if (!newAccessToken.equals("")) { + return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(newAccessToken))).build(); + } else { + return null; + } + } else { + return response.request().newBuilder().headers(Headers.of(APIUtils.getOAuthHeader(accessTokenFromDatabase))).build(); + } + } + } + return null; + } + + private String refreshAccessToken(Account account) { + String refreshToken = account.getRefreshToken(); + + RedditAPI api = mRetrofit.create(RedditAPI.class); + + Map params = new HashMap<>(); + params.put(APIUtils.GRANT_TYPE_KEY, APIUtils.GRANT_TYPE_REFRESH_TOKEN); + params.put(APIUtils.REFRESH_TOKEN_KEY, refreshToken); + + Call accessTokenCall = api.getAccessToken(APIUtils.getHttpBasicAuthHeader(), params); + try { + retrofit2.Response response = accessTokenCall.execute(); + if (response.isSuccessful() && response.body() != null) { + JSONObject jsonObject = new JSONObject(response.body()); + String newAccessToken = jsonObject.getString(APIUtils.ACCESS_TOKEN_KEY); + String newRefreshToken = jsonObject.has(APIUtils.REFRESH_TOKEN_KEY) ? jsonObject.getString(APIUtils.REFRESH_TOKEN_KEY) : null; + if (newRefreshToken == null) { + mRedditDataRoomDatabase.accountDao().updateAccessToken(account.getAccountName(), newAccessToken); + } else { + mRedditDataRoomDatabase.accountDao().updateAccessTokenAndRefreshToken(account.getAccountName(), newAccessToken, newRefreshToken); + } + Account currentAccount = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); + if (currentAccount != null && mAccount.getAccountName().equals(currentAccount.getAccountName()) && mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, Account.ANONYMOUS_ACCOUNT).equals(account.getAccountName())) { + mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, newAccessToken).apply(); + } + + return newAccessToken; + } + return ""; + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + + return ""; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/network/RedgifsAccessTokenAuthenticator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/network/RedgifsAccessTokenAuthenticator.java new file mode 100644 index 00000000..b6d9e5e9 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/network/RedgifsAccessTokenAuthenticator.java @@ -0,0 +1,89 @@ +package ml.docilealligator.infinityforreddit.network; + +import android.content.SharedPreferences; + +import androidx.annotation.NonNull; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import ml.docilealligator.infinityforreddit.apis.RedgifsAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import okhttp3.Headers; +import okhttp3.Interceptor; +import okhttp3.Response; +import retrofit2.Call; +import retrofit2.Retrofit; +import retrofit2.converter.scalars.ScalarsConverterFactory; + +public class RedgifsAccessTokenAuthenticator implements Interceptor { + private final SharedPreferences mCurrentAccountSharedPreferences; + + public RedgifsAccessTokenAuthenticator(SharedPreferences currentAccountSharedPreferences) { + this.mCurrentAccountSharedPreferences = currentAccountSharedPreferences; + } + + private String refreshAccessToken() { + Retrofit retrofit = new Retrofit.Builder() + .baseUrl(APIUtils.REDGIFS_API_BASE_URI) + .addConverterFactory(ScalarsConverterFactory.create()) + .build(); + RedgifsAPI api = retrofit.create(RedgifsAPI.class); + + Map params = new HashMap<>(); + params.put(APIUtils.GRANT_TYPE_KEY, APIUtils.GRANT_TYPE_CLIENT_CREDENTIALS); + params.put(APIUtils.CLIENT_ID_KEY, APIUtils.REDGIFS_CLIENT_ID); + params.put(APIUtils.CLIENT_SECRET_KEY, APIUtils.REDGIFS_CLIENT_SECRET); + + Call accessTokenCall = api.getRedgifsAccessToken(params); + try { + retrofit2.Response response = accessTokenCall.execute(); + if (response.isSuccessful() && response.body() != null) { + String newAccessToken = new JSONObject(response.body()).getString(APIUtils.ACCESS_TOKEN_KEY); + mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, newAccessToken).apply(); + + return newAccessToken; + } + return ""; + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + + return ""; + } + + @NonNull + @Override + public Response intercept(@NonNull Chain chain) throws IOException { + Response response = chain.proceed(chain.request()); + if (response.code() == 401 || response.code() == 400) { + String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY); + if (accessTokenHeader == null) { + return response; + } + + String accessToken = accessTokenHeader.substring(APIUtils.AUTHORIZATION_BASE.length() - 1).trim(); + synchronized (this) { + String accessTokenFromSharedPreferences = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, ""); + if (accessToken.equals(accessTokenFromSharedPreferences)) { + String newAccessToken = refreshAccessToken(); + if (!newAccessToken.equals("")) { + response.close(); + return chain.proceed(response.request().newBuilder().headers(Headers.of(APIUtils.getRedgifsOAuthHeader(newAccessToken))).build()); + } else { + return response; + } + } else { + response.close(); + return chain.proceed(response.request().newBuilder().headers(Headers.of(APIUtils.getRedgifsOAuthHeader(accessTokenFromSharedPreferences))).build()); + } + } + } + return response; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/network/SortTypeConverter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/network/SortTypeConverter.java index b69f9da6..d8fd2751 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/network/SortTypeConverter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/network/SortTypeConverter.java @@ -5,7 +5,7 @@ import androidx.annotation.Nullable; import java.io.IOException; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import retrofit2.Converter; /** diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/network/SortTypeConverterFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/network/SortTypeConverterFactory.java index 84a1ed6c..281a0a90 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/network/SortTypeConverterFactory.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/network/SortTypeConverterFactory.java @@ -6,7 +6,7 @@ import androidx.annotation.Nullable; import java.lang.annotation.Annotation; import java.lang.reflect.Type; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import retrofit2.Converter; import retrofit2.Retrofit; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRules.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRules.java new file mode 100644 index 00000000..6a1efca3 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRules.java @@ -0,0 +1,87 @@ +package ml.docilealligator.infinityforreddit.post; + +import android.os.Handler; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.account.Account; +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.subreddit.Rule; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +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 FetchRules { + public interface FetchRulesListener { + void success(ArrayList rules); + void failed(); + } + + public static void fetchRules(Executor executor, Handler handler, Retrofit retrofit, @Nullable String accessToken, + @NonNull String accountName, String subredditName, + FetchRulesListener fetchRulesListener) { + RedditAPI api = retrofit.create(RedditAPI.class); + Call rulesCall = accountName.equals(Account.ANONYMOUS_ACCOUNT) + ? api.getRules(subredditName) + : api.getRulesOauth(APIUtils.getOAuthHeader(accessToken), subredditName); + rulesCall.enqueue(new Callback<>() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + parseRules(executor, handler, response.body(), new FetchRulesListener() { + @Override + public void success(ArrayList rules) { + fetchRulesListener.success(rules); + } + + @Override + public void failed() { + fetchRulesListener.failed(); + } + }); + } else { + fetchRulesListener.failed(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + fetchRulesListener.failed(); + } + }); + } + + private static void parseRules(Executor executor, Handler handler, String response, + FetchRulesListener fetchRulesListener) { + executor.execute(() -> { + try { + JSONArray rulesArray = new JSONObject(response).getJSONArray(JSONUtils.RULES_KEY); + ArrayList rules = new ArrayList<>(); + for (int i = 0; i < rulesArray.length(); i++) { + String shortName = rulesArray.getJSONObject(i).getString(JSONUtils.SHORT_NAME_KEY); + String description = null; + if (rulesArray.getJSONObject(i).has(JSONUtils.DESCRIPTION_KEY)) { + description = Utils.modifyMarkdown(rulesArray.getJSONObject(i).getString(JSONUtils.DESCRIPTION_KEY)); + } + rules.add(new Rule(shortName, description)); + } + handler.post(() -> fetchRulesListener.success(rules)); + } catch (JSONException e) { + e.printStackTrace(); + handler.post(fetchRulesListener::failed); + } + }); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchStreamableVideo.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchStreamableVideo.java new file mode 100644 index 00000000..044baf1f --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchStreamableVideo.java @@ -0,0 +1,99 @@ +package ml.docilealligator.infinityforreddit.post; + +import android.os.Handler; + +import androidx.annotation.Nullable; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.util.concurrent.Executor; + +import javax.inject.Provider; + +import ml.docilealligator.infinityforreddit.thing.StreamableVideo; +import ml.docilealligator.infinityforreddit.apis.StreamableAPI; +import ml.docilealligator.infinityforreddit.utils.JSONUtils; +import retrofit2.Call; +import retrofit2.Response; + +public class FetchStreamableVideo { + public interface FetchStreamableVideoListener { + void success(StreamableVideo streamableVideo); + void failed(); + } + + public static void fetchStreamableVideo(Executor executor, Handler handler, Provider streamableApiProvider, + String videoUrl, FetchStreamableVideoListener fetchStreamableVideoListener) { + executor.execute(() -> { + try { + Response response = streamableApiProvider.get().getStreamableData(videoUrl).execute(); + if (response.isSuccessful()) { + JSONObject jsonObject = new JSONObject(response.body()); + String title = jsonObject.getString(JSONUtils.TITLE_KEY); + JSONObject filesObject = jsonObject.getJSONObject(JSONUtils.FILES_KEY); + StreamableVideo.Media mp4 = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_KEY)); + StreamableVideo.Media mp4MobileTemp = null; + if (filesObject.has(JSONUtils.MP4_MOBILE_KEY)) { + mp4MobileTemp = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_MOBILE_KEY)); + } + if (mp4 == null && mp4MobileTemp == null) { + handler.post(fetchStreamableVideoListener::failed); + return; + } + StreamableVideo.Media mp4Mobile = mp4MobileTemp; + handler.post(() -> fetchStreamableVideoListener.success(new StreamableVideo(title, mp4, mp4Mobile))); + } else { + handler.post(fetchStreamableVideoListener::failed); + } + } catch (IOException | JSONException e) { + e.printStackTrace(); + handler.post(fetchStreamableVideoListener::failed); + } + }); + } + + public static void fetchStreamableVideoInRecyclerViewAdapter(Executor executor, Handler handler, Call streamableCall, + FetchStreamableVideoListener fetchStreamableVideoListener) { + executor.execute(() -> { + try { + Response response = streamableCall.execute(); + if (response.isSuccessful()) { + JSONObject jsonObject = new JSONObject(response.body()); + String title = jsonObject.getString(JSONUtils.TITLE_KEY); + JSONObject filesObject = jsonObject.getJSONObject(JSONUtils.FILES_KEY); + StreamableVideo.Media mp4 = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_KEY)); + StreamableVideo.Media mp4MobileTemp = null; + if (filesObject.has(JSONUtils.MP4_MOBILE_KEY)) { + mp4MobileTemp = parseMedia(filesObject.getJSONObject(JSONUtils.MP4_MOBILE_KEY)); + } + if (mp4 == null && mp4MobileTemp == null) { + handler.post(fetchStreamableVideoListener::failed); + return; + } + StreamableVideo.Media mp4Mobile = mp4MobileTemp; + handler.post(() -> fetchStreamableVideoListener.success(new StreamableVideo(title, mp4, mp4Mobile))); + } else { + handler.post(fetchStreamableVideoListener::failed); + } + } catch (IOException | JSONException e) { + e.printStackTrace(); + handler.post(fetchStreamableVideoListener::failed); + } + }); + } + + @Nullable + private static StreamableVideo.Media parseMedia(JSONObject jsonObject) { + try { + return new StreamableVideo.Media( + jsonObject.getString(JSONUtils.URL_KEY), + jsonObject.getInt(JSONUtils.WIDTH_KEY), + jsonObject.getInt(JSONUtils.HEIGHT_KEY)); + } catch (JSONException e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ImgurMedia.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ImgurMedia.java new file mode 100644 index 00000000..a9a09a50 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ImgurMedia.java @@ -0,0 +1,84 @@ +package ml.docilealligator.infinityforreddit.post; + +import android.os.Parcel; +import android.os.Parcelable; + +public class ImgurMedia implements Parcelable { + public static final int TYPE_IMAGE = 0; + public static final int TYPE_VIDEO = 1; + private String id; + private final String title; + private final String description; + private final String link; + private int type; + + public ImgurMedia(String id, String title, String description, String type, String link) { + this.id = id; + this.title = title; + this.description = description; + if (type.contains("mp4")) { + this.type = TYPE_VIDEO; + } else { + this.type = TYPE_IMAGE; + } + this.link = link; + } + + protected ImgurMedia(Parcel in) { + title = in.readString(); + description = in.readString(); + link = in.readString(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public ImgurMedia createFromParcel(Parcel in) { + return new ImgurMedia(in); + } + + @Override + public ImgurMedia[] newArray(int size) { + return new ImgurMedia[size]; + } + }; + + public String getId() { + return id; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public int getType() { + return type; + } + + public String getLink() { + return link; + } + + public String getFileName() { + if (type == TYPE_VIDEO) { + return "imgur-" + id + ".mp4"; + } + + return "imgur-" + id + ".jpg"; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(title); + parcel.writeString(description); + parcel.writeString(link); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/LoadingMorePostsStatus.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/LoadingMorePostsStatus.java new file mode 100644 index 00000000..d3a95e0c --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/LoadingMorePostsStatus.java @@ -0,0 +1,16 @@ +package ml.docilealligator.infinityforreddit.post; + +import androidx.annotation.IntDef; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@IntDef({LoadingMorePostsStatus.LOADING, LoadingMorePostsStatus.FAILED, LoadingMorePostsStatus.NO_MORE_POSTS, + LoadingMorePostsStatus.NOT_LOADING}) +@Retention(RetentionPolicy.SOURCE) +public @interface LoadingMorePostsStatus { + int LOADING = 0; + int FAILED = 1; + int NO_MORE_POSTS = 2; + int NOT_LOADING = 3; +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/MarkPostAsReadInterface.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/MarkPostAsReadInterface.java new file mode 100644 index 00000000..495fdb2f --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/MarkPostAsReadInterface.java @@ -0,0 +1,5 @@ +package ml.docilealligator.infinityforreddit.post; + +public interface MarkPostAsReadInterface { + void markPostAsRead(Post post); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java index f0dc2138..e7dc35ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -18,7 +18,7 @@ import java.util.concurrent.Executor; import java.util.regex.Matcher; import java.util.regex.Pattern; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; import ml.docilealligator.infinityforreddit.utils.JSONUtils; import ml.docilealligator.infinityforreddit.utils.Utils; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PollPayload.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PollPayload.java new file mode 100644 index 00000000..c113a106 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PollPayload.java @@ -0,0 +1,73 @@ +package ml.docilealligator.infinityforreddit.post; + +import com.google.gson.annotations.SerializedName; + +import ml.docilealligator.infinityforreddit.subreddit.Flair; + +public class PollPayload { + @SerializedName("api_type") + public String apiType = "json"; + @SerializedName("duration") + public int duration; + @SerializedName("nsfw") + public boolean isNsfw; + public String[] options; + @SerializedName("flair_id") + public String flairId; + @SerializedName("flair_text") + public String flairText; + @SerializedName("raw_rtjson") + public String richTextJSON; + @SerializedName("post_to_twitter") + public boolean postToTwitter = false; + @SerializedName("sendreplies") + public boolean sendReplies; + @SerializedName("show_error_list") + public boolean showErrorList = true; + @SerializedName("spoiler") + public boolean isSpoiler; + @SerializedName("sr") + public String subredditName; + @SerializedName("submit_type") + public String submitType; + public String text; + public String title; + @SerializedName("validate_on_submit") + public boolean validateOnSubmit = true; + + public PollPayload(String subredditName, String title, String[] options, int duration, boolean isNsfw, + boolean isSpoiler, Flair flair, boolean sendReplies, + String submitType) { + this.subredditName = subredditName; + this.title = title; + this.options = options; + this.duration = duration; + this.isNsfw = isNsfw; + this.isSpoiler = isSpoiler; + if (flair != null) { + flairId = flair.getId(); + flairText = flair.getText(); + } + this.sendReplies = sendReplies; + this.submitType = submitType; + } + + public PollPayload(String subredditName, String title, String[] options, int duration, boolean isNsfw, + boolean isSpoiler, Flair flair, String richTextJSON, String text, boolean sendReplies, + String submitType) { + this.subredditName = subredditName; + this.title = title; + this.options = options; + this.duration = duration; + this.isNsfw = isNsfw; + this.isSpoiler = isSpoiler; + if (flair != null) { + flairId = flair.getId(); + flairText = flair.getText(); + } + this.richTextJSON = richTextJSON; + this.text = text; + this.sendReplies = sendReplies; + this.submitType = submitType; + } +} 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 b204c97d..c6490942 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java @@ -9,7 +9,7 @@ import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.Map; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; import ml.docilealligator.infinityforreddit.utils.APIUtils; /** diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java index 1611dd99..0e5926b8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java @@ -16,7 +16,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.concurrent.Executor; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java index c3ea8734..47ec89e2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java @@ -21,7 +21,7 @@ import androidx.paging.PagingLiveData; import java.util.List; import java.util.concurrent.Executor; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/RedditGalleryPayload.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/RedditGalleryPayload.java new file mode 100644 index 00000000..bbebd3fa --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/RedditGalleryPayload.java @@ -0,0 +1,117 @@ +package ml.docilealligator.infinityforreddit.post; + +import android.os.Parcel; +import android.os.Parcelable; + +import com.google.gson.annotations.SerializedName; + +import java.util.ArrayList; + +import ml.docilealligator.infinityforreddit.subreddit.Flair; + +public class RedditGalleryPayload { + @SerializedName("sr") + public String subredditName; + @SerializedName("submit_type") + public String submitType; + @SerializedName("api_type") + public String apiType = "json"; + @SerializedName("show_error_list") + public boolean showErrorList = true; + public String title; + public String text; + @SerializedName("spoiler") + public boolean isSpoiler; + @SerializedName("nsfw") + public boolean isNSFW; + public String kind = "self"; + @SerializedName("original_content") + public boolean originalContent = false; + @SerializedName("post_to_twitter") + public boolean postToTwitter = false; + @SerializedName("sendreplies") + public boolean sendReplies; + @SerializedName("validate_on_submit") + public boolean validateOnSubmit = true; + @SerializedName("flair_id") + public String flairId; + @SerializedName("flair_text") + public String flairText; + public ArrayList items; + + public RedditGalleryPayload(String subredditName, String submitType, String title, String text, + boolean isSpoiler, boolean isNSFW, boolean sendReplies, Flair flair, ArrayList items) { + this.subredditName = subredditName; + this.submitType = submitType; + this.title = title; + this.text = text; + this.isSpoiler = isSpoiler; + this.isNSFW = isNSFW; + this.sendReplies = sendReplies; + if (flair != null) { + flairId = flair.getId(); + flairText = flair.getText(); + } + this.items = items; + } + + public static class Item implements Parcelable { + public String caption; + @SerializedName("outbound_url") + public String outboundUrl; + @SerializedName("media_id") + public String mediaId; + + public Item(String caption, String outboundUrl, String mediaId) { + this.caption = caption; + this.outboundUrl = outboundUrl; + this.mediaId = mediaId; + } + + protected Item(Parcel in) { + caption = in.readString(); + outboundUrl = in.readString(); + mediaId = in.readString(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public Item createFromParcel(Parcel in) { + return new Item(in); + } + + @Override + public Item[] newArray(int size) { + return new Item[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(caption); + parcel.writeString(outboundUrl); + parcel.writeString(mediaId); + } + + public String getCaption() { + return caption; + } + + public void setCaption(String caption) { + this.caption = caption == null ? "" : caption; + } + + public String getOutboundUrl() { + return outboundUrl; + } + + public void setOutboundUrl(String outboundUrl) { + this.outboundUrl = outboundUrl; + } + } +} 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 fbb15bc8..e1b0e719 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/SubmitPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/SubmitPost.java @@ -17,7 +17,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.Executor; -import ml.docilealligator.infinityforreddit.Flair; +import ml.docilealligator.infinityforreddit.subreddit.Flair; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.JSONUtils; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQuery.java b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQuery.java index 6bc5f4ee..e554b1ba 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQuery.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQuery.java @@ -6,7 +6,7 @@ import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.ForeignKey; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.account.Account; @Entity(tableName = "recent_search_queries", primaryKeys = {"username", "search_query"}, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java index d70881d0..30edab3e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java @@ -41,12 +41,12 @@ import java.util.concurrent.TimeUnit; import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.AnyAccountAccessTokenAuthenticator; -import ml.docilealligator.infinityforreddit.Flair; +import ml.docilealligator.infinityforreddit.network.AnyAccountAccessTokenAuthenticator; +import ml.docilealligator.infinityforreddit.subreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; 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 525defaf..3bb68f5c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java @@ -25,7 +25,7 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SelectThingReturnKey; +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.activities.SearchActivity; import ml.docilealligator.infinityforreddit.activities.SettingsActivity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchFlairs.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchFlairs.java new file mode 100644 index 00000000..842eec94 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchFlairs.java @@ -0,0 +1,103 @@ +package ml.docilealligator.infinityforreddit.subreddit; + +import android.os.AsyncTask; + +import androidx.annotation.NonNull; + +import org.json.JSONArray; +import org.json.JSONException; + +import java.util.ArrayList; + +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import ml.docilealligator.infinityforreddit.utils.JSONUtils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class FetchFlairs { + public static void fetchFlairsInSubreddit(Retrofit oauthRetrofit, String accessToken, String subredditName, FetchFlairsInSubredditListener fetchFlairsInSubredditListener) { + RedditAPI api = oauthRetrofit.create(RedditAPI.class); + + Call flairsCall = api.getFlairs(APIUtils.getOAuthHeader(accessToken), subredditName); + flairsCall.enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + new ParseFlairsAsyncTask(response.body(), new ParseFlairsAsyncTask.ParseFlairsAsyncTaskListener() { + @Override + public void parseSuccessful(ArrayList flairs) { + fetchFlairsInSubredditListener.fetchSuccessful(flairs); + } + + @Override + public void parseFailed() { + fetchFlairsInSubredditListener.fetchFailed(); + } + }).execute(); + } else if (response.code() == 403) { + //No flairs + fetchFlairsInSubredditListener.fetchSuccessful(null); + } else { + fetchFlairsInSubredditListener.fetchFailed(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + fetchFlairsInSubredditListener.fetchFailed(); + } + }); + } + + public interface FetchFlairsInSubredditListener { + void fetchSuccessful(ArrayList flairs); + + void fetchFailed(); + } + + private static class ParseFlairsAsyncTask extends AsyncTask, ArrayList> { + private final String response; + private final ParseFlairsAsyncTaskListener parseFlairsAsyncTaskListener; + ParseFlairsAsyncTask(String response, ParseFlairsAsyncTaskListener parseFlairsAsyncTaskListener) { + this.response = response; + this.parseFlairsAsyncTaskListener = parseFlairsAsyncTaskListener; + } + + @Override + protected ArrayList doInBackground(Void... voids) { + try { + JSONArray jsonArray = new JSONArray(response); + ArrayList flairs = new ArrayList<>(); + for (int i = 0; i < jsonArray.length(); i++) { + String id = jsonArray.getJSONObject(i).getString(JSONUtils.ID_KEY); + String text = jsonArray.getJSONObject(i).getString(JSONUtils.TEXT_KEY); + boolean editable = jsonArray.getJSONObject(i).getBoolean(JSONUtils.TEXT_EDITABLE_KEY); + + flairs.add(new Flair(id, text, editable)); + } + return flairs; + } catch (JSONException e) { + e.printStackTrace(); + } + return null; + } + + @Override + protected void onPostExecute(ArrayList strings) { + if (strings != null) { + parseFlairsAsyncTaskListener.parseSuccessful(strings); + } else { + parseFlairsAsyncTaskListener.parseFailed(); + } + } + + interface ParseFlairsAsyncTaskListener { + void parseSuccessful(ArrayList flairs); + + void parseFailed(); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java index 45806447..a1740f4d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/FetchSubredditData.java @@ -11,7 +11,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.Executor; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.utils.APIUtils; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/Flair.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/Flair.java new file mode 100644 index 00000000..f713d5ac --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/Flair.java @@ -0,0 +1,80 @@ +package ml.docilealligator.infinityforreddit.subreddit; + +import android.os.Parcel; +import android.os.Parcelable; + +import com.google.gson.Gson; +import com.google.gson.JsonParseException; + +public class Flair implements Parcelable { + public static final Creator CREATOR = new Creator() { + @Override + public Flair createFromParcel(Parcel in) { + return new Flair(in); + } + + @Override + public Flair[] newArray(int size) { + return new Flair[size]; + } + }; + private String id; + private String text; + private boolean editable; + + Flair(String id, String text, boolean editable) { + this.id = id; + this.text = text; + this.editable = editable; + } + + protected Flair(Parcel in) { + id = in.readString(); + text = in.readString(); + editable = in.readByte() != 0; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public boolean isEditable() { + return editable; + } + + public void setEditable(boolean editable) { + this.editable = editable; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(id); + parcel.writeString(text); + parcel.writeByte((byte) (editable ? 1 : 0)); + } + + public String getJSONModel() { + return new Gson().toJson(this); + } + + public static Flair fromJson(String json) throws JsonParseException { + return new Gson().fromJson(json, Flair.class); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/Rule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/Rule.java new file mode 100644 index 00000000..ec57bc94 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/Rule.java @@ -0,0 +1,19 @@ +package ml.docilealligator.infinityforreddit.subreddit; + +public class Rule { + private final String shortName; + private final String descriptionHtml; + + public Rule(String shortName, String descriptionHtml) { + this.shortName = shortName; + this.descriptionHtml = descriptionHtml; + } + + public String getShortName() { + return shortName; + } + + public String getDescriptionHtml() { + return descriptionHtml; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java index 0ba14106..9ce93863 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSource.java @@ -11,7 +11,7 @@ import java.util.ArrayList; import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.NetworkState; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import retrofit2.Retrofit; public class SubredditListingDataSource extends PageKeyedDataSource { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSourceFactory.java index 5f7ecc94..a0716047 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSourceFactory.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingDataSourceFactory.java @@ -9,7 +9,7 @@ import androidx.paging.DataSource; import java.util.concurrent.Executor; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import retrofit2.Retrofit; public class SubredditListingDataSourceFactory extends DataSource.Factory { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingViewModel.java index 491de480..fc55b19c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/subreddit/SubredditListingViewModel.java @@ -15,7 +15,7 @@ import androidx.paging.PagedList; import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.NetworkState; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import retrofit2.Retrofit; public class SubredditListingViewModel extends ViewModel { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/DeleteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/DeleteThing.java new file mode 100644 index 00000000..0d758a7c --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/DeleteThing.java @@ -0,0 +1,41 @@ +package ml.docilealligator.infinityforreddit.thing; + +import androidx.annotation.NonNull; + +import java.util.HashMap; +import java.util.Map; + +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class DeleteThing { + public static void delete(Retrofit oauthRetrofit, String fullname, String accessToken, DeleteThingListener deleteThingListener) { + Map params = new HashMap<>(); + params.put(APIUtils.ID_KEY, fullname); + oauthRetrofit.create(RedditAPI.class).delete(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + deleteThingListener.deleteSuccess(); + } else { + deleteThingListener.deleteFailed(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + deleteThingListener.deleteFailed(); + } + }); + } + + public interface DeleteThingListener { + void deleteSuccess(); + + void deleteFailed(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/FavoriteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/FavoriteThing.java new file mode 100644 index 00000000..1ee9b1e1 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/FavoriteThing.java @@ -0,0 +1,154 @@ +package ml.docilealligator.infinityforreddit.thing; + +import android.os.Handler; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings; +import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; +import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class FavoriteThing { + public static void favoriteSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit, + RedditDataRoomDatabase redditDataRoomDatabase, + @Nullable String accessToken, @NonNull String accountName, + SubscribedSubredditData subscribedSubredditData, + FavoriteThingListener favoriteThingListener) { + if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedSubredditData, + favoriteThingListener::success); + } else { + Map params = new HashMap<>(); + params.put(APIUtils.SR_NAME_KEY, subscribedSubredditData.getName()); + params.put(APIUtils.MAKE_FAVORITE_KEY, "true"); + oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedSubredditData, + favoriteThingListener::success); + } else { + favoriteThingListener.failed(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + favoriteThingListener.failed(); + } + }); + } + } + + public static void unfavoriteSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit, + RedditDataRoomDatabase redditDataRoomDatabase, + @Nullable String accessToken, @NonNull String accountName, + SubscribedSubredditData subscribedSubredditData, + FavoriteThingListener favoriteThingListener) { + if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, + subscribedSubredditData, favoriteThingListener::success); + } else { + Map params = new HashMap<>(); + params.put(APIUtils.SR_NAME_KEY, subscribedSubredditData.getName()); + params.put(APIUtils.MAKE_FAVORITE_KEY, "false"); + oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, + subscribedSubredditData, favoriteThingListener::success); + } else { + favoriteThingListener.failed(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + favoriteThingListener.failed(); + } + }); + } + } + + public static void favoriteUser(Executor executor, Handler handler, Retrofit oauthRetrofit, + RedditDataRoomDatabase redditDataRoomDatabase, + @Nullable String accessToken, @NonNull String accountName, + SubscribedUserData subscribedUserData, + FavoriteThingListener favoriteThingListener) { + if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, + subscribedUserData, favoriteThingListener::success); + } else { + Map params = new HashMap<>(); + params.put(APIUtils.SR_NAME_KEY, "u_" + subscribedUserData.getName()); + params.put(APIUtils.MAKE_FAVORITE_KEY, "true"); + oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, + subscribedUserData, favoriteThingListener::success); + } else { + favoriteThingListener.failed(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + favoriteThingListener.failed(); + } + }); + } + } + + public static void unfavoriteUser(Executor executor, Handler handler, Retrofit oauthRetrofit, + RedditDataRoomDatabase redditDataRoomDatabase, + @Nullable String accessToken, @NonNull String accountName, + SubscribedUserData subscribedUserData, + FavoriteThingListener favoriteThingListener) { + if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) { + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedUserData, + favoriteThingListener::success); + } else { + Map params = new HashMap<>(); + params.put(APIUtils.SR_NAME_KEY, "u_" + subscribedUserData.getName()); + params.put(APIUtils.MAKE_FAVORITE_KEY, "false"); + oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, + subscribedUserData, favoriteThingListener::success); + } else { + favoriteThingListener.failed(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + favoriteThingListener.failed(); + } + }); + } + } + + public interface FavoriteThingListener { + void success(); + + void failed(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/FetchRedgifsVideoLinks.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/FetchRedgifsVideoLinks.java new file mode 100644 index 00000000..60fd028b --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/FetchRedgifsVideoLinks.java @@ -0,0 +1,76 @@ +package ml.docilealligator.infinityforreddit.thing; + +import android.content.SharedPreferences; +import android.os.Handler; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.util.concurrent.Executor; + +import ml.docilealligator.infinityforreddit.apis.RedgifsAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import ml.docilealligator.infinityforreddit.utils.JSONUtils; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import retrofit2.Call; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class FetchRedgifsVideoLinks { + + public interface FetchRedgifsVideoLinksListener { + void success(String webm, String mp4); + void failed(int errorCode); + } + + public static void fetchRedgifsVideoLinks(Executor executor, Handler handler, Retrofit redgifsRetrofit, + SharedPreferences currentAccountSharedPreferences, + String redgifsId, + FetchRedgifsVideoLinksListener fetchRedgifsVideoLinksListener) { + executor.execute(() -> { + try { + Response response = redgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(currentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), + redgifsId, APIUtils.USER_AGENT).execute(); + if (response.isSuccessful()) { + parseRedgifsVideoLinks(handler, response.body(), fetchRedgifsVideoLinksListener); + } else { + handler.post(() -> fetchRedgifsVideoLinksListener.failed(response.code())); + } + } catch (IOException e) { + e.printStackTrace(); + handler.post(() -> fetchRedgifsVideoLinksListener.failed(-1)); + } + }); + } + + public static void fetchRedgifsVideoLinksInRecyclerViewAdapter(Executor executor, Handler handler, + Call redgifsCall, + FetchRedgifsVideoLinksListener fetchRedgifsVideoLinksListener) { + executor.execute(() -> { + try { + Response response = redgifsCall.execute(); + if (response.isSuccessful()) { + parseRedgifsVideoLinks(handler, response.body(), fetchRedgifsVideoLinksListener); + } else { + handler.post(() -> fetchRedgifsVideoLinksListener.failed(response.code())); + } + } catch (IOException e) { + e.printStackTrace(); + handler.post(() -> fetchRedgifsVideoLinksListener.failed(-1)); + } + }); + } + + private static void parseRedgifsVideoLinks(Handler handler, String response, + FetchRedgifsVideoLinksListener fetchRedgifsVideoLinksListener) { + try { + String mp4 = new JSONObject(response).getJSONObject(JSONUtils.GIF_KEY).getJSONObject(JSONUtils.URLS_KEY) + .getString(JSONUtils.HD_KEY); + handler.post(() -> fetchRedgifsVideoLinksListener.success(mp4, mp4)); + } catch (JSONException e) { + e.printStackTrace(); + handler.post(() -> fetchRedgifsVideoLinksListener.failed(-1)); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/FetchSubscribedThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/FetchSubscribedThing.java new file mode 100644 index 00000000..579f7905 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/FetchSubscribedThing.java @@ -0,0 +1,74 @@ +package ml.docilealligator.infinityforreddit.thing; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.util.ArrayList; + +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.subreddit.SubredditData; +import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; +import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class FetchSubscribedThing { + public static void fetchSubscribedThing(final Retrofit oauthRetrofit, @Nullable String accessToken, @NonNull String accountName, + final String lastItem, final ArrayList subscribedSubredditData, + final ArrayList subscribedUserData, + final ArrayList subredditData, + final FetchSubscribedThingListener fetchSubscribedThingListener) { + RedditAPI api = oauthRetrofit.create(RedditAPI.class); + + Call subredditDataCall = api.getSubscribedThing(lastItem, APIUtils.getOAuthHeader(accessToken)); + subredditDataCall.enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + ParseSubscribedThing.parseSubscribedSubreddits(response.body(), accountName, + subscribedSubredditData, subscribedUserData, subredditData, + new ParseSubscribedThing.ParseSubscribedSubredditsListener() { + + @Override + public void onParseSubscribedSubredditsSuccess(ArrayList subscribedSubredditData, + ArrayList subscribedUserData, + ArrayList subredditData, + String lastItem) { + if (lastItem.equals("null")) { + fetchSubscribedThingListener.onFetchSubscribedThingSuccess( + subscribedSubredditData, subscribedUserData, subredditData); + } else { + fetchSubscribedThing(oauthRetrofit, accessToken, accountName, lastItem, + subscribedSubredditData, subscribedUserData, subredditData, + fetchSubscribedThingListener); + } + } + + @Override + public void onParseSubscribedSubredditsFail() { + fetchSubscribedThingListener.onFetchSubscribedThingFail(); + } + }); + } else { + fetchSubscribedThingListener.onFetchSubscribedThingFail(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + fetchSubscribedThingListener.onFetchSubscribedThingFail(); + } + }); + } + + public interface FetchSubscribedThingListener { + void onFetchSubscribedThingSuccess(ArrayList subscribedSubredditData, + ArrayList subscribedUserData, + ArrayList subredditData); + + void onFetchSubscribedThingFail(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/MediaMetadata.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/MediaMetadata.java new file mode 100644 index 00000000..b3c4ce7e --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/MediaMetadata.java @@ -0,0 +1,122 @@ +package ml.docilealligator.infinityforreddit.thing; + +import android.net.Uri; +import android.os.Parcel; +import android.os.Parcelable; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public class MediaMetadata implements Parcelable { + public String id; + //E.g. Image + public String e; + public String fileName; + public String caption; + public boolean isGIF; + public MediaItem original; + public MediaItem downscaled; + + public MediaMetadata(String id, String e, MediaItem original, MediaItem downscaled) { + this.id = id; + this.e = e; + isGIF = !e.equalsIgnoreCase("image"); + String path = Uri.parse(original.url).getPath(); + this.fileName = path == null ? (isGIF ? "Animated.gif" : "Image.jpg") : path.substring(path.lastIndexOf('/') + 1); + this.original = original; + this.downscaled = downscaled; + } + + protected MediaMetadata(Parcel in) { + id = in.readString(); + e = in.readString(); + fileName = in.readString(); + caption = in.readString(); + isGIF = in.readByte() != 0; + original = in.readParcelable(MediaItem.class.getClassLoader()); + downscaled = in.readParcelable(MediaItem.class.getClassLoader()); + } + + public static final Creator CREATOR = new Creator() { + @Override + public MediaMetadata createFromParcel(Parcel in) { + return new MediaMetadata(in); + } + + @Override + public MediaMetadata[] newArray(int size) { + return new MediaMetadata[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeString(id); + dest.writeString(e); + dest.writeString(fileName); + dest.writeString(caption); + dest.writeByte((byte) (isGIF ? 1 : 0)); + dest.writeParcelable(original, flags); + dest.writeParcelable(downscaled, flags); + } + + public static class MediaItem implements Parcelable { + public int x; + public int y; + //Image or gif + public String url; + //Only for gifs + @Nullable + public String mp4Url; + + public MediaItem(int x, int y, String url) { + this.x = x; + this.y = y; + this.url = url; + } + + public MediaItem(int x, int y, String url, String mp4Url) { + this.x = x; + this.y = y; + this.url = url; + this.mp4Url = mp4Url; + } + + protected MediaItem(Parcel in) { + x = in.readInt(); + y = in.readInt(); + url = in.readString(); + mp4Url = in.readString(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public MediaItem createFromParcel(Parcel in) { + return new MediaItem(in); + } + + @Override + public MediaItem[] newArray(int size) { + return new MediaItem[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeInt(x); + dest.writeInt(y); + dest.writeString(url); + dest.writeString(mp4Url); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/ParseSubscribedThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/ParseSubscribedThing.java new file mode 100644 index 00000000..ef803aff --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/ParseSubscribedThing.java @@ -0,0 +1,138 @@ +package ml.docilealligator.infinityforreddit.thing; + +import android.os.AsyncTask; + +import androidx.annotation.NonNull; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; + +import ml.docilealligator.infinityforreddit.subreddit.SubredditData; +import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData; +import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData; +import ml.docilealligator.infinityforreddit.utils.JSONUtils; +import ml.docilealligator.infinityforreddit.utils.Utils; + +class ParseSubscribedThing { + static void parseSubscribedSubreddits(String response, @NonNull String accountName, + ArrayList subscribedSubredditData, + ArrayList subscribedUserData, + ArrayList subredditData, + ParseSubscribedSubredditsListener parseSubscribedSubredditsListener) { + new ParseSubscribedSubredditsAsyncTask(response, accountName, subscribedSubredditData, subscribedUserData, subredditData, + parseSubscribedSubredditsListener).execute(); + } + + interface ParseSubscribedSubredditsListener { + void onParseSubscribedSubredditsSuccess(ArrayList subscribedSubredditData, + ArrayList subscribedUserData, + ArrayList subredditData, + String lastItem); + + void onParseSubscribedSubredditsFail(); + } + + private static class ParseSubscribedSubredditsAsyncTask extends AsyncTask { + private JSONObject jsonResponse; + private String accountName; + private boolean parseFailed; + private String lastItem; + private ArrayList subscribedSubredditData; + private ArrayList subscribedUserData; + private ArrayList subredditData; + private ArrayList newSubscribedSubredditData; + private ArrayList newSubscribedUserData; + private ArrayList newSubredditData; + private final ParseSubscribedSubredditsListener parseSubscribedSubredditsListener; + + ParseSubscribedSubredditsAsyncTask(String response, @NonNull String accountName, ArrayList subscribedSubredditData, + ArrayList subscribedUserData, + ArrayList subredditData, + ParseSubscribedSubredditsListener parseSubscribedSubredditsListener) { + this.parseSubscribedSubredditsListener = parseSubscribedSubredditsListener; + try { + jsonResponse = new JSONObject(response); + this.accountName = accountName; + parseFailed = false; + this.subscribedSubredditData = subscribedSubredditData; + this.subscribedUserData = subscribedUserData; + this.subredditData = subredditData; + newSubscribedSubredditData = new ArrayList<>(); + newSubscribedUserData = new ArrayList<>(); + newSubredditData = new ArrayList<>(); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + @Override + protected Void doInBackground(Void... voids) { + try { + if (jsonResponse == null) { + parseFailed = true; + return null; + } + JSONArray children = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY); + for (int i = 0; i < children.length(); i++) { + JSONObject data = children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); + String name = data.getString(JSONUtils.DISPLAY_NAME_KEY); + String bannerImageUrl = data.getString(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY); + if (bannerImageUrl.equals("") || bannerImageUrl.equals("null")) { + bannerImageUrl = data.getString(JSONUtils.BANNER_IMG_KEY); + if (bannerImageUrl.equals("null")) { + bannerImageUrl = ""; + } + } + String iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY); + if (iconUrl.equals("") || iconUrl.equals("null")) { + iconUrl = data.getString(JSONUtils.ICON_IMG_KEY); + if (iconUrl.equals("null")) { + iconUrl = ""; + } + } + String id = data.getString(JSONUtils.NAME_KEY); + boolean isFavorite = data.getBoolean(JSONUtils.USER_HAS_FAVORITED_KEY); + + if (data.getString(JSONUtils.SUBREDDIT_TYPE_KEY) + .equals(JSONUtils.SUBREDDIT_TYPE_VALUE_USER)) { + //It's a user + newSubscribedUserData.add(new SubscribedUserData(name.substring(2), iconUrl, accountName, isFavorite)); + } else { + String subredditFullName = data.getString(JSONUtils.DISPLAY_NAME_KEY); + String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim(); + String sidebarDescription = Utils.modifyMarkdown(data.getString(JSONUtils.DESCRIPTION_KEY).trim()); + int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY); + long createdUTC = data.getLong(JSONUtils.CREATED_UTC_KEY) * 1000; + String suggestedCommentSort = data.getString(JSONUtils.SUGGESTED_COMMENT_SORT_KEY); + boolean isNSFW = data.getBoolean(JSONUtils.OVER18_KEY); + newSubscribedSubredditData.add(new SubscribedSubredditData(id, name, iconUrl, accountName, isFavorite)); + newSubredditData.add(new SubredditData(id, subredditFullName, iconUrl, + bannerImageUrl, description, sidebarDescription, nSubscribers, createdUTC, + suggestedCommentSort, isNSFW)); + } + } + lastItem = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY); + } catch (JSONException e) { + parseFailed = true; + e.printStackTrace(); + } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + if (!parseFailed) { + subscribedSubredditData.addAll(newSubscribedSubredditData); + subscribedUserData.addAll(newSubscribedUserData); + subredditData.addAll(newSubredditData); + parseSubscribedSubredditsListener.onParseSubscribedSubredditsSuccess(subscribedSubredditData, + subscribedUserData, subredditData, lastItem); + } else { + parseSubscribedSubredditsListener.onParseSubscribedSubredditsFail(); + } + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/ReplyNotificationsToggle.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/ReplyNotificationsToggle.java new file mode 100644 index 00000000..50aaf397 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/ReplyNotificationsToggle.java @@ -0,0 +1,45 @@ +package ml.docilealligator.infinityforreddit.thing; + +import android.os.Handler; + +import androidx.annotation.NonNull; + +import java.util.HashMap; +import java.util.Map; + +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.comment.Comment; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class ReplyNotificationsToggle { + public static void toggleEnableNotification(Handler handler, Retrofit oauthRetrofit, String accessToken, + Comment comment, SendNotificationListener sendNotificationListener) { + Map params = new HashMap<>(); + params.put(APIUtils.ID_KEY, comment.getFullName()); + params.put(APIUtils.STATE_KEY, String.valueOf(!comment.isSendReplies())); + oauthRetrofit.create(RedditAPI.class).toggleRepliesNotification(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + handler.post(sendNotificationListener::onSuccess); + } else { + handler.post(sendNotificationListener::onError); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { + handler.post(sendNotificationListener::onError); + } + }); + } + + public interface SendNotificationListener { + void onSuccess(); + void onError(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/ReportReason.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/ReportReason.java new file mode 100644 index 00000000..9b130804 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/ReportReason.java @@ -0,0 +1,93 @@ +package ml.docilealligator.infinityforreddit.thing; + +import android.content.Context; +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.ArrayList; + +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.subreddit.Rule; + +public class ReportReason implements Parcelable { + public static final String REASON_TYPE_SITE_REASON = "site_reason"; + public static final String REASON_TYPE_RULE_REASON = "rule_reason"; + public static final String REASON_TYPE_OTHER_REASON = "other_reason"; + public static final String REASON_SITE_REASON_SELECTED = "site_reason_selected"; + public static final String REASON_RULE_REASON_SELECTED = "rule_reason_selected"; + public static final String REASON_OTHER = "other"; + + private final String reportReason; + private final String reasonType; + private boolean isSelected; + + public ReportReason(String reportReason, String reasonType) { + this.reportReason = reportReason; + this.reasonType = reasonType; + this.isSelected = false; + } + + protected ReportReason(Parcel in) { + reportReason = in.readString(); + reasonType = in.readString(); + isSelected = in.readByte() != 0; + } + + public static final Creator CREATOR = new Creator() { + @Override + public ReportReason createFromParcel(Parcel in) { + return new ReportReason(in); + } + + @Override + public ReportReason[] newArray(int size) { + return new ReportReason[size]; + } + }; + + public String getReportReason() { + return reportReason; + } + + public String getReasonType() { + return reasonType; + } + + public boolean isSelected() { + return isSelected; + } + + public void setSelected(boolean selected) { + isSelected = selected; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(reportReason); + parcel.writeString(reasonType); + parcel.writeByte((byte) (isSelected ? 1 : 0)); + } + + public static ArrayList getGeneralReasons(Context context) { + ArrayList reportReasons = new ArrayList<>(); + reportReasons.add(new ReportReason(context.getString(R.string.report_reason_general_spam), REASON_TYPE_SITE_REASON)); + reportReasons.add(new ReportReason(context.getString(R.string.report_reason_general_copyright_issue), REASON_TYPE_SITE_REASON)); + reportReasons.add(new ReportReason(context.getString(R.string.report_reason_general_child_pornography), REASON_TYPE_SITE_REASON)); + reportReasons.add(new ReportReason(context.getString(R.string.report_reason_general_abusive_content), REASON_TYPE_SITE_REASON)); + return reportReasons; + } + + public static ArrayList convertRulesToReasons(ArrayList rules) { + ArrayList reportReasons = new ArrayList<>(); + for (Rule r : rules) { + reportReasons.add(new ReportReason(r.getShortName(), REASON_TYPE_RULE_REASON)); + } + + return reportReasons; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/ReportThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/ReportThing.java new file mode 100644 index 00000000..927a7cbf --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/ReportThing.java @@ -0,0 +1,55 @@ +package ml.docilealligator.infinityforreddit.thing; + +import androidx.annotation.NonNull; + +import java.util.HashMap; +import java.util.Map; + +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class ReportThing { + + public interface ReportThingListener { + void success(); + void failed(); + } + + public static void reportThing(Retrofit oauthRetrofit, String accessToken, String thingFullname, + String subredditName, String reasonType, String reason, + ReportThingListener reportThingListener) { + Map header = APIUtils.getOAuthHeader(accessToken); + Map params = new HashMap<>(); + params.put(APIUtils.THING_ID_KEY, thingFullname); + params.put(APIUtils.SR_NAME_KEY, subredditName); + params.put(reasonType, reason); + if (reasonType.equals(ReportReason.REASON_TYPE_SITE_REASON)) { + params.put(APIUtils.REASON_KEY, ReportReason.REASON_SITE_REASON_SELECTED); + } else if (reasonType.equals(ReportReason.REASON_TYPE_RULE_REASON)) { + params.put(APIUtils.REASON_KEY, ReportReason.REASON_RULE_REASON_SELECTED); + } else { + params.put(APIUtils.REASON_KEY, ReportReason.REASON_OTHER); + } + params.put(APIUtils.API_TYPE_KEY, APIUtils.API_TYPE_JSON); + + oauthRetrofit.create(RedditAPI.class).report(header, params).enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + reportThingListener.success(); + } else { + reportThingListener.failed(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + reportThingListener.failed(); + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/SaveThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/SaveThing.java new file mode 100644 index 00000000..974b7858 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/SaveThing.java @@ -0,0 +1,63 @@ +package ml.docilealligator.infinityforreddit.thing; + +import androidx.annotation.NonNull; + +import java.util.HashMap; +import java.util.Map; + +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class SaveThing { + public static void saveThing(Retrofit oauthRetrofit, String accessToken, String fullname, + SaveThingListener saveThingListener) { + Map params = new HashMap<>(); + params.put(APIUtils.ID_KEY, fullname); + oauthRetrofit.create(RedditAPI.class).save(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + saveThingListener.success(); + } else { + saveThingListener.failed(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + saveThingListener.failed(); + } + }); + } + + public static void unsaveThing(Retrofit oauthRetrofit, String accessToken, String fullname, + SaveThingListener saveThingListener) { + Map params = new HashMap<>(); + params.put(APIUtils.ID_KEY, fullname); + oauthRetrofit.create(RedditAPI.class).unsave(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + saveThingListener.success(); + } else { + saveThingListener.failed(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + saveThingListener.failed(); + } + }); + } + + public interface SaveThingListener { + void success(); + + void failed(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/SelectThingReturnKey.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/SelectThingReturnKey.java new file mode 100644 index 00000000..f5e7401e --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/SelectThingReturnKey.java @@ -0,0 +1,21 @@ +package ml.docilealligator.infinityforreddit.thing; + +import androidx.annotation.IntDef; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class SelectThingReturnKey { + public static final String RETURN_EXTRA_SUBREDDIT_OR_USER_NAME = "RESOUN"; + public static final String RETURN_EXTRA_SUBREDDIT_OR_USER_ICON = "RESOUI"; + public static final String RETRUN_EXTRA_MULTIREDDIT = "REM"; + public static final String RETURN_EXTRA_THING_TYPE = "RETT"; + + @IntDef({THING_TYPE.SUBREDDIT, THING_TYPE.USER, THING_TYPE.MULTIREDDIT}) + @Retention(RetentionPolicy.SOURCE) + public @interface THING_TYPE { + int SUBREDDIT = 0; + int USER = 1; + int MULTIREDDIT = 2; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/SortType.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/SortType.java new file mode 100644 index 00000000..bb6f8555 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/SortType.java @@ -0,0 +1,73 @@ +package ml.docilealligator.infinityforreddit.thing; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public class SortType { + + @NonNull + private final Type type; + @Nullable + private final Time time; + + public SortType(@NonNull Type type) { + this(type, null); + } + + public SortType(@NonNull Type type, @Nullable Time time) { + this.type = type; + this.time = time; + } + + @NonNull + public Type getType() { + return type; + } + + @Nullable + public Time getTime() { + return time; + } + + public enum Type { + BEST("best", "Best"), + HOT("hot", "Hot"), + NEW("new", "New"), + RANDOM("random", "Random"), + RISING("rising", "Rising"), + TOP("top", "Top"), + CONTROVERSIAL("controversial", "Controversial"), + RELEVANCE("relevance", "Relevance"), + COMMENTS("comments", "Comments"), + ACTIVITY("activity", "Activity"), + CONFIDENCE("confidence", "Best"), + OLD("old", "Old"), + QA("qa", "QA"), + LIVE("live", "Live"); + + public final String value; + public final String fullName; + + Type(String value, String fullName) { + this.value = value; + this.fullName = fullName; + } + } + + public enum Time { + HOUR("hour", "Hour"), + DAY("day", "Day"), + WEEK("week", "Week"), + MONTH("month", "Month"), + YEAR("year", "Year"), + ALL("all", "All Time"); + + public final String value; + public final String fullName; + + Time(String value, String fullName) { + this.value = value; + this.fullName = fullName; + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/SortTypeSelectionCallback.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/SortTypeSelectionCallback.java new file mode 100644 index 00000000..8e9e6d43 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/SortTypeSelectionCallback.java @@ -0,0 +1,9 @@ +package ml.docilealligator.infinityforreddit.thing; + +public interface SortTypeSelectionCallback { + default void sortTypeSelected(SortType sortType){} + + default void sortTypeSelected(String sortType){} + + default void searchUserAndSubredditSortTypeSelected(SortType sortType, int fragmentPosition){} +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/StreamableVideo.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/StreamableVideo.java new file mode 100644 index 00000000..64caa013 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/StreamableVideo.java @@ -0,0 +1,29 @@ +package ml.docilealligator.infinityforreddit.thing; + +import androidx.annotation.Nullable; + +public class StreamableVideo { + public String title; + @Nullable + public Media mp4; + @Nullable + public Media mp4Mobile; + + public StreamableVideo(String title, @Nullable Media mp4, @Nullable Media mp4Mobile) { + this.title = title; + this.mp4 = mp4; + this.mp4Mobile = mp4Mobile; + } + + public static class Media { + public String url; + public int width; + public int height; + + public Media(String url, int width, int height) { + this.url = url; + this.width = width; + this.height = height; + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/TrendingSearch.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/TrendingSearch.java new file mode 100644 index 00000000..dec280fa --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/TrendingSearch.java @@ -0,0 +1,54 @@ +package ml.docilealligator.infinityforreddit.thing; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.ArrayList; + +import ml.docilealligator.infinityforreddit.post.Post; + +public class TrendingSearch implements Parcelable { + public String queryString; + public String displayString; + public String title; + public ArrayList previews; + + public TrendingSearch(String queryString, String displayString, String title, ArrayList previews) { + this.queryString = queryString; + this.displayString = displayString; + this.title = title; + this.previews = previews; + } + + protected TrendingSearch(Parcel in) { + queryString = in.readString(); + displayString = in.readString(); + title = in.readString(); + previews = in.createTypedArrayList(Post.Preview.CREATOR); + } + + public static final Creator CREATOR = new Creator() { + @Override + public TrendingSearch createFromParcel(Parcel in) { + return new TrendingSearch(in); + } + + @Override + public TrendingSearch[] newArray(int size) { + return new TrendingSearch[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(queryString); + parcel.writeString(displayString); + parcel.writeString(title); + parcel.writeTypedList(previews); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/UploadedImage.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/UploadedImage.java new file mode 100644 index 00000000..ed00d880 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/UploadedImage.java @@ -0,0 +1,68 @@ +package ml.docilealligator.infinityforreddit.thing; + +import android.os.Parcel; +import android.os.Parcelable; + +import com.google.gson.Gson; +import com.google.gson.JsonParseException; +import com.google.gson.reflect.TypeToken; + +import java.util.ArrayList; +import java.util.List; + +public class UploadedImage implements Parcelable { + public String imageName; + public String imageUrlOrKey; + private String caption = ""; + + public UploadedImage(String imageName, String imageUrlOrKey) { + this.imageName = imageName; + this.imageUrlOrKey = imageUrlOrKey; + } + + protected UploadedImage(Parcel in) { + imageName = in.readString(); + imageUrlOrKey = in.readString(); + caption = in.readString(); + } + + public String getCaption() { + return caption == null ? "" : caption; + } + + public void setCaption(String caption) { + this.caption = caption == null ? "" : caption; + } + + public static final Creator CREATOR = new Creator() { + @Override + public UploadedImage createFromParcel(Parcel in) { + return new UploadedImage(in); + } + + @Override + public UploadedImage[] newArray(int size) { + return new UploadedImage[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(imageName); + parcel.writeString(imageUrlOrKey); + parcel.writeString(caption); + } + + public static String getArrayListJSONModel(ArrayList uploadedImages) { + return new Gson().toJson(uploadedImages, new TypeToken>(){}.getType()); + } + + public static List fromListJson(String json) throws JsonParseException { + return new Gson().fromJson(json, new TypeToken>(){}.getType()); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/thing/VoteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/VoteThing.java new file mode 100644 index 00000000..91ff631e --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/thing/VoteThing.java @@ -0,0 +1,94 @@ +package ml.docilealligator.infinityforreddit.thing; + +import android.content.Context; +import android.widget.Toast; + +import androidx.annotation.NonNull; + +import java.util.HashMap; +import java.util.Map; + +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Retrofit; + +/** + * Created by alex on 3/14/18. + */ + +public class VoteThing { + + public static void voteThing(Context context, final Retrofit retrofit, String accessToken, + final VoteThingListener voteThingListener, final String fullName, + final String point, final int position) { + RedditAPI api = retrofit.create(RedditAPI.class); + + Map params = new HashMap<>(); + params.put(APIUtils.DIR_KEY, point); + params.put(APIUtils.ID_KEY, fullName); + params.put(APIUtils.RANK_KEY, APIUtils.RANK); + + Call voteThingCall = api.voteThing(APIUtils.getOAuthHeader(accessToken), params); + voteThingCall.enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { + if (response.isSuccessful()) { + voteThingListener.onVoteThingSuccess(position); + } else { + voteThingListener.onVoteThingFail(position); + Toast.makeText(context, "Code " + response.code() + " Body: " + response.body(), Toast.LENGTH_LONG).show(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + voteThingListener.onVoteThingFail(position); + Toast.makeText(context, "Network error " + "Body: " + t.getMessage(), Toast.LENGTH_LONG).show(); + } + }); + } + + public static void voteThing(Context context, final Retrofit retrofit, String accessToken, + final VoteThingWithoutPositionListener voteThingWithoutPositionListener, + final String fullName, final String point) { + RedditAPI api = retrofit.create(RedditAPI.class); + + Map params = new HashMap<>(); + params.put(APIUtils.DIR_KEY, point); + params.put(APIUtils.ID_KEY, fullName); + params.put(APIUtils.RANK_KEY, APIUtils.RANK); + + Call voteThingCall = api.voteThing(APIUtils.getOAuthHeader(accessToken), params); + voteThingCall.enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { + if (response.isSuccessful()) { + voteThingWithoutPositionListener.onVoteThingSuccess(); + } else { + voteThingWithoutPositionListener.onVoteThingFail(); + Toast.makeText(context, "Code " + response.code() + " Body: " + response.body(), Toast.LENGTH_LONG).show(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + voteThingWithoutPositionListener.onVoteThingFail(); + Toast.makeText(context, "Network error " + "Body: " + t.getMessage(), Toast.LENGTH_LONG).show(); + } + }); + } + + public interface VoteThingListener { + void onVoteThingSuccess(int position); + + void onVoteThingFail(int position); + } + + public interface VoteThingWithoutPositionListener { + void onVoteThingSuccess(); + + void onVoteThingFail(); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/FetchUserData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/FetchUserData.java index b2a69826..2be140cd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/user/FetchUserData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/FetchUserData.java @@ -5,7 +5,7 @@ import androidx.annotation.NonNull; import java.util.ArrayList; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.utils.APIUtils; import retrofit2.Call; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/FetchUserFlairs.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/FetchUserFlairs.java new file mode 100644 index 00000000..d1bf7242 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/FetchUserFlairs.java @@ -0,0 +1,122 @@ +package ml.docilealligator.infinityforreddit.user; + +import android.os.AsyncTask; +import android.text.Html; + +import androidx.annotation.NonNull; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; + +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import ml.docilealligator.infinityforreddit.utils.JSONUtils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class FetchUserFlairs { + public static void fetchUserFlairsInSubreddit(Retrofit oauthRetrofit, String accessToken, String subredditName, FetchUserFlairsInSubredditListener fetchUserFlairsInSubredditListener) { + RedditAPI api = oauthRetrofit.create(RedditAPI.class); + + Call flairsCall = api.getUserFlairs(APIUtils.getOAuthHeader(accessToken), subredditName); + flairsCall.enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + new ParseUserFlairsAsyncTask(response.body(), new ParseUserFlairsAsyncTask.ParseUserFlairsAsyncTaskListener() { + @Override + public void parseSuccessful(ArrayList userFlairs) { + fetchUserFlairsInSubredditListener.fetchSuccessful(userFlairs); + } + + @Override + public void parseFailed() { + fetchUserFlairsInSubredditListener.fetchFailed(); + } + }).execute(); + } else if (response.code() == 403) { + //No flairs + fetchUserFlairsInSubredditListener.fetchSuccessful(null); + } else { + fetchUserFlairsInSubredditListener.fetchFailed(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + fetchUserFlairsInSubredditListener.fetchFailed(); + } + }); + } + + public interface FetchUserFlairsInSubredditListener { + void fetchSuccessful(ArrayList userFlairs); + + void fetchFailed(); + } + + private static class ParseUserFlairsAsyncTask extends AsyncTask, ArrayList> { + private final String response; + private final ParseUserFlairsAsyncTaskListener parseFlairsAsyncTaskListener; + + ParseUserFlairsAsyncTask(String response, ParseUserFlairsAsyncTaskListener parseFlairsAsyncTaskListener) { + this.response = response; + this.parseFlairsAsyncTaskListener = parseFlairsAsyncTaskListener; + } + + @Override + protected ArrayList doInBackground(Void... voids) { + try { + JSONArray jsonArray = new JSONArray(response); + ArrayList userFlairs = new ArrayList<>(); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject userFlairObject = jsonArray.getJSONObject(i); + String id = userFlairObject.getString(JSONUtils.ID_KEY); + String text = userFlairObject.getString(JSONUtils.TEXT_KEY); + boolean editable = userFlairObject.getBoolean(JSONUtils.TEXT_EDITABLE_KEY); + int maxEmojis = userFlairObject.getInt(JSONUtils.MAX_EMOJIS_KEY); + + StringBuilder authorFlairHTMLBuilder = new StringBuilder(); + if (userFlairObject.has(JSONUtils.RICHTEXT_KEY)) { + JSONArray flairArray = userFlairObject.getJSONArray(JSONUtils.RICHTEXT_KEY); + for (int j = 0; j < flairArray.length(); j++) { + JSONObject flairObject = flairArray.getJSONObject(j); + String e = flairObject.getString(JSONUtils.E_KEY); + if (e.equals("text")) { + authorFlairHTMLBuilder.append(Html.escapeHtml(flairObject.getString(JSONUtils.T_KEY))); + } else if (e.equals("emoji")) { + authorFlairHTMLBuilder.append(""); + } + } + } + + userFlairs.add(new UserFlair(id, text, authorFlairHTMLBuilder.toString(), editable, maxEmojis)); + } + return userFlairs; + } catch (JSONException e) { + e.printStackTrace(); + } + return null; + } + + @Override + protected void onPostExecute(ArrayList userFlairs) { + if (userFlairs != null) { + parseFlairsAsyncTaskListener.parseSuccessful(userFlairs); + } else { + parseFlairsAsyncTaskListener.parseFailed(); + } + } + + interface ParseUserFlairsAsyncTaskListener { + void parseSuccessful(ArrayList userFlairs); + + void parseFailed(); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/SelectUserFlair.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/SelectUserFlair.java new file mode 100644 index 00000000..01b4add6 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/SelectUserFlair.java @@ -0,0 +1,103 @@ +package ml.docilealligator.infinityforreddit.user; + +import android.os.AsyncTask; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.HashMap; +import java.util.Map; + +import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.utils.APIUtils; +import ml.docilealligator.infinityforreddit.utils.JSONUtils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class SelectUserFlair { + public interface SelectUserFlairListener { + void success(); + void failed(String errorMessage); + } + + public static void selectUserFlair(Retrofit oauthRetrofit, String accessToken, @Nullable UserFlair userFlair, + String subredditName, @NonNull String accountName, SelectUserFlairListener selectUserFlairListener) { + Map params = new HashMap<>(); + params.put(APIUtils.API_TYPE_KEY, APIUtils.API_TYPE_JSON); + if (userFlair != null) { + params.put(APIUtils.FLAIR_TEMPLATE_ID_KEY, userFlair.getId()); + params.put(APIUtils.TEXT_KEY, userFlair.getText()); + } + params.put(APIUtils.NAME_KEY, accountName); + oauthRetrofit.create(RedditAPI.class).selectUserFlair(APIUtils.getOAuthHeader(accessToken), params, subredditName) + .enqueue(new Callback<>() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + new ParseErrorAsyncTask(response.body(), selectUserFlairListener).execute(); + } else { + selectUserFlairListener.failed(response.message()); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + selectUserFlairListener.failed(t.getMessage()); + } + }); + } + + private static class ParseErrorAsyncTask extends AsyncTask { + + private final String response; + @Nullable + private String errorMessage; + private final SelectUserFlairListener selectUserFlairListener; + + ParseErrorAsyncTask(String response, SelectUserFlairListener selectUserFlairListener) { + this.response = response; + this.selectUserFlairListener = selectUserFlairListener; + } + + @Override + protected Void doInBackground(Void... voids) { + try { + JSONObject responseObject = new JSONObject(response).getJSONObject(JSONUtils.JSON_KEY); + + if (responseObject.getJSONArray(JSONUtils.ERRORS_KEY).length() != 0) { + JSONArray error = responseObject.getJSONArray(JSONUtils.ERRORS_KEY) + .getJSONArray(responseObject.getJSONArray(JSONUtils.ERRORS_KEY).length() - 1); + if (error.length() != 0) { + String errorString; + if (error.length() >= 2) { + errorString = error.getString(1); + } else { + errorString = error.getString(0); + } + errorMessage = errorString.substring(0, 1).toUpperCase() + errorString.substring(1); + } + } + } catch (JSONException e) { + e.printStackTrace(); + } + + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + if (errorMessage == null) { + selectUserFlairListener.success(); + } else { + selectUserFlairListener.failed(errorMessage); + } + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserFlair.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserFlair.java new file mode 100644 index 00000000..874fff19 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserFlair.java @@ -0,0 +1,78 @@ +package ml.docilealligator.infinityforreddit.user; + +import android.os.Parcel; +import android.os.Parcelable; + +public class UserFlair implements Parcelable { + private final String id; + private String text; + private final String htmlText; + private final boolean editable; + private final int maxEmojis; + + public UserFlair(String id, String text, String htmlText, boolean editable, int maxEmojis) { + this.id = id; + this.text = text; + this.htmlText = htmlText; + this.editable = editable; + this.maxEmojis = maxEmojis; + } + + protected UserFlair(Parcel in) { + id = in.readString(); + text = in.readString(); + htmlText = in.readString(); + editable = in.readByte() != 0; + maxEmojis = in.readInt(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public UserFlair createFromParcel(Parcel in) { + return new UserFlair(in); + } + + @Override + public UserFlair[] newArray(int size) { + return new UserFlair[size]; + } + }; + + public String getId() { + return id; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String getHtmlText() { + return htmlText; + } + + public boolean isEditable() { + return editable; + } + + public int getMaxEmojis() { + return maxEmojis; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(id); + parcel.writeString(text); + parcel.writeString(htmlText); + parcel.writeByte((byte) (editable ? 1 : 0)); + parcel.writeInt(maxEmojis); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSource.java index c3d922a7..89831334 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSource.java @@ -7,7 +7,7 @@ import androidx.paging.PageKeyedDataSource; import java.util.ArrayList; import ml.docilealligator.infinityforreddit.NetworkState; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import retrofit2.Retrofit; public class UserListingDataSource extends PageKeyedDataSource { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSourceFactory.java index 9d52d087..56d91b1a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSourceFactory.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingDataSourceFactory.java @@ -4,7 +4,7 @@ import androidx.annotation.NonNull; import androidx.lifecycle.MutableLiveData; import androidx.paging.DataSource; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import retrofit2.Retrofit; public class UserListingDataSourceFactory extends DataSource.Factory { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingViewModel.java index daffdf1e..aebeba63 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/user/UserListingViewModel.java @@ -10,7 +10,7 @@ import androidx.paging.LivePagedListBuilder; import androidx.paging.PagedList; import ml.docilealligator.infinityforreddit.NetworkState; -import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.thing.SortType; import retrofit2.Retrofit; public class UserListingViewModel extends ViewModel { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java index 54a6c731..ee18f9ba 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java @@ -10,7 +10,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; /** * Created by alex on 2/25/18. 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 37db8124..94386ed1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -53,10 +53,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import io.noties.markwon.core.spans.CustomTypefaceSpan; -import ml.docilealligator.infinityforreddit.MediaMetadata; +import ml.docilealligator.infinityforreddit.thing.MediaMetadata; import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.UploadedImage; +import ml.docilealligator.infinityforreddit.thing.SortType; +import ml.docilealligator.infinityforreddit.thing.UploadedImage; import retrofit2.Retrofit; public final class Utils { -- cgit v1.2.3