303 Commits

Author SHA1 Message Date
Bazsalanszky
1d9854cb0e Test build1 2024-08-12 09:46:48 +02:00
Bazsalanszky
336223cc36 Bump version 2024-08-09 09:44:32 +02:00
Bazsalanszky
7da428e9b2 Removed unused translations 2024-08-09 09:35:09 +02:00
Bazsalanszky
2a08a26a36 Remove CustomTextView dependency and reimplement it from scratch
The dependency caused some errors. It is old and unmaintained anyway.
2024-08-09 08:52:47 +02:00
Bazsalanszky
c60d88b2fe Add ThreadStackSize to gradle.properties
For real now
2024-08-08 14:43:59 +02:00
Bazsalanszky
b66742dd37 Revert "Add ThreadStackSize to gradle.properties"
This reverts commit b3623e6f7b.
2024-08-08 14:40:41 +02:00
Bazsalanszky
b3623e6f7b Add ThreadStackSize to gradle.properties 2024-08-08 14:38:42 +02:00
Bazsalanszky
2a2e7c0e87 Removed many unused strings
Closes #263
2024-08-08 14:27:31 +02:00
Balazs Toldi
1395eee2df Fix typo in woodpecker pipeline 2024-08-06 08:30:25 +02:00
Balazs Toldi
a0e2bb06a1 Update SDK in woodpecker pipeline 2024-08-06 08:23:29 +02:00
Balazs Toldi
ce08191d01 Bump versionCode in build.gradle 2024-08-06 08:23:29 +02:00
Lefteris T
75f65691fd Translated using Weblate (Greek)
Currently translated at 99.5% (1319 of 1325 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/el/
2024-08-05 16:18:23 +00:00
Balazs Toldi
b70db40a03 Fix crash when trying to Commnet
Previously, if a post did not have any markdown in it, the app would not initialize Glide on the CommentActivity, causing a crash while loading the user icon. Now it will be initialized either way.

Closes #272
2024-08-04 14:31:39 +02:00
30p87
5f345113f1 Translated using Weblate (Bavarian)
Currently translated at 0.9% (12 of 1325 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/bar/
2024-08-03 21:18:23 +00:00
30p87
ba1c320e47 Translated using Weblate (German)
Currently translated at 100.0% (1325 of 1325 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2024-08-03 21:18:23 +00:00
Fjuro
be6c137e03 Translated using Weblate (Czech)
Currently translated at 100.0% (1325 of 1325 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/cs/
2024-08-03 21:18:23 +00:00
30p87
07a556b76e Added translation using Weblate (Bavarian) 2024-08-03 08:02:33 +00:00
SomeTr
5aba7cd938 Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1325 of 1325 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-08-02 13:18:23 +00:00
lucasew
40b63522d0 Translated using Weblate (Portuguese)
Currently translated at 94.5% (1253 of 1325 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/pt/
2024-08-02 13:18:23 +00:00
Balazs Toldi
934d0e5c81 Change error image in a few more places 2024-08-01 18:33:58 +02:00
Balazs Toldi
6457a4db2f Proper Admin/Moderator indication
This commit adds proper indicators if a post or comment is made by a moderator or an admin. If a user is both an admin and a moderator, both indicators will be shown.

Closes #267
2024-07-30 09:32:16 +02:00
Balazs Toldi
4ccb1a38bf Fix crash when opening links
This commit fixes the issue where opening links while browsing would trigger an account switch with a null name.
2024-07-29 21:47:54 +02:00
SomeTr
de92e0edd3 Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1325 of 1325 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-07-29 09:18:23 +00:00
Anonymous
e87426d591 Translated using Weblate (French)
Currently translated at 93.5% (1240 of 1325 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/fr/
2024-07-28 08:27:52 +00:00
Bazsalanszky
3a9638e236 Fix typos 2024-07-28 10:00:46 +02:00
Bazsalanszky
f5b8206959 Fix token checking (again)
Failure to call the API (e.g. network error) with the token caused incorrect relogin requests.
2024-07-28 10:00:45 +02:00
Lefteris T
ae74eeba0f Translated using Weblate (Greek)
Currently translated at 99.5% (1318 of 1324 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/el/
2024-07-27 13:18:23 +00:00
artnay
f6e5942e86 Translated using Weblate (Finnish)
Currently translated at 56.0% (742 of 1324 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/fi/
2024-07-24 17:22:40 +00:00
SomeTr
b67b62f952 Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1324 of 1324 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-07-23 10:18:23 +00:00
Fjuro
f01e53953b Translated using Weblate (Czech)
Currently translated at 100.0% (1324 of 1324 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/cs/
2024-07-23 10:18:23 +00:00
Bazsalanszky
241f082806 Translated using Weblate (Hungarian)
Currently translated at 82.7% (1094 of 1322 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/hu/
2024-07-22 10:07:25 +00:00
Bazsalanszky
56e05a2e84 Add indication for removed/deleted comments
It is now visible, if a comment is deleted by the creator or if it was removed by a moderator or admin.

Closes #249
2024-07-22 12:07:13 +02:00
Bazsalanszky
2c16a05a95 Bump version code 2024-07-21 20:46:15 +02:00
Bazsalanszky
23c5ac9127 Fix issues with notifications
This commit fixes the issue where the app incorrectly switches accounts when opening a notification (see changes in the InboxActivity). It also fixes the issue where the posts/comments would not show up after clicking on a notification that would require an account switch (see changes in the LinkResolverActivity).
2024-07-21 20:44:39 +02:00
Bazsalanszky
1303106a7b Mark message as read fix
This commit fixes the issue where messages aren't marked as read when you click on them from the InboxActivity.
2024-07-21 13:47:07 +02:00
Bazsalanszky
f9a0e0e70d Fix CRASH on starting a foreground service
Starting from android target 34, we need to set a foreground service type. In my opinion, the dataSync one fits best for us.
2024-07-21 11:49:17 +02:00
Bazsalanszky
3d3285d1ee Fix CRASH on CommentActivity 2024-07-21 11:49:17 +02:00
Lefteris T
c2017dd17c Translated using Weblate (Greek)
Currently translated at 99.5% (1316 of 1322 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/el/
2024-07-20 20:18:24 +00:00
SomeTr
fb6d9ed0bc Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1322 of 1322 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-07-20 20:18:24 +00:00
Fjuro
257dc4d0a7 Translated using Weblate (Czech)
Currently translated at 100.0% (1322 of 1322 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/cs/
2024-07-20 20:18:24 +00:00
Balazs Toldi
5fdf1208a7 Better image loading in Markdown
This commit potentially solves issues with slow scrolling on posts and some crashes due to too large files
2024-07-19 20:55:08 +02:00
Balazs Toldi
6708b72fd8 Removed commit log file 2024-07-19 19:15:05 +02:00
Balazs Toldi
327b874fd6 Update strings
Removed anonymous_homepage_not_implemented string from every language file
2024-07-19 19:12:46 +02:00
Balazs Toldi
cafd3c6025 Add option to disable automatic post hide
This commit adds two new options:
- Do not hide saved posts automatically: When enabled, read posts will also be visible on the saved posts page
- Do not hide your own posts: When enabled, your own posts will be visible, even if it's read

Closes #219
Closes #125
2024-07-19 17:02:58 +02:00
Balazs Toldi
9ecbaba3d4 Minor change to distinguish moderators/admins 2024-07-19 17:02:58 +02:00
Balazs Toldi
4741198c78 Show new icon as error image as well
Closes #223
2024-07-19 17:02:58 +02:00
Balazs Toldi
577d5b8e6f Removed Anonymous page not implemented error
No longer needed as it's there now.
2024-07-19 17:02:58 +02:00
SomeTr
307036bca0 Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1321 of 1321 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-07-19 13:18:24 +00:00
Fjuro
ec4c79eb69 Translated using Weblate (Czech)
Currently translated at 100.0% (1321 of 1321 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/cs/
2024-07-19 13:18:24 +00:00
Balazs Toldi
0affa4a90d Update build.gradle
Bump version, version code and target sdk
2024-07-19 13:11:49 +02:00
Balazs Toldi
8ef3867610 Transparent branding images
This works better on light themes
2024-07-19 13:10:58 +02:00
Balazs Toldi
b9e61518a4 Improve video preview loading time
This commit improves the loading time of posts with videos on the feed.

Closes #242
2024-07-18 21:32:53 +02:00
SomeTr
706f51c4f5 Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1316 of 1316 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-07-18 12:07:58 +00:00
Bazsalanszky
30a2c1a9b9 Instance Blocking
This commit adds the ability to block/unblock instances from the instance view page.

Closes #231
2024-07-18 14:07:34 +02:00
Bazsalanszky
06315c55ad Add option to view instance of users/communities
This Commit adds an option to view the details of a users/communities instance, just like the instance info accessible from the navigation bar. #204
2024-07-18 11:09:22 +02:00
Bazsalanszky
42af7ee315 Fix user icons for the instance info page
The avatars were parsed incorrectly.
2024-07-18 10:46:36 +02:00
Bazsalanszky
f0d6abee5d Search to open link
This commit adds the ability to open posts from a URL by inserting it to the search menu.
2024-07-12 08:28:10 +02:00
Bazsalanszky
21861a5884 Added Comments to search results
This commit adds the ability to search for comments. It adds a new tab to the SearchResultActivity with a CommentsListingFragment. #241

This commit also fixes an issue where you can't upvote comments on when in a listing (e.g. on a profile, or now search)
2024-07-12 08:22:29 +02:00
Bazsalanszky
0fb834fb38 Minor pipeline change 2024-07-09 16:22:25 +02:00
Bazsalanszky
60155c4c6b Fix search sorting
Added all sorting options to the SearchResultActivity
2024-07-09 16:20:33 +02:00
Bazsalanszky
1ab8f31cbd Do not show display name when disabled
There was an issue where the display name of the user was
2024-07-09 15:54:51 +02:00
Bazsalanszky
ae5b3836e7 Fix unread message highlight in inbox
Previously, the mentions where incorrectly highlighted as unread in the Inbox activity (the read/unread messages were inverted). This commit fixes this issue.
2024-07-09 12:13:27 +02:00
Bazsalanszky
1cdd490789 Fix crash when adding a community to multi-communties
This commit fixes the issue where the app previously crashed when adding a community to a multi-community from search.
2024-07-09 12:13:27 +02:00
30p87
e96a89d430 Translated using Weblate (German)
Currently translated at 100.0% (1315 of 1315 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2024-07-07 14:18:24 +00:00
Bazsalanszky
c606a29e79 Added Lemmy badge to README 2024-07-04 18:18:06 +00:00
trlef19
afd8223eb4 Translated using Weblate (Greek)
Currently translated at 99.5% (1309 of 1315 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/el/
2024-07-03 10:18:29 +00:00
SomeTr
a39ee994ff Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1315 of 1315 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-07-03 10:18:26 +00:00
SomeTr
e25e258d48 Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1315 of 1315 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-07-01 10:18:26 +00:00
0ko
1e8a60aeb9 Translated using Weblate (Russian)
Currently translated at 98.4% (1295 of 1315 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2024-07-01 10:18:25 +00:00
Fjuro
27f3807a69 Translated using Weblate (Czech)
Currently translated at 100.0% (1315 of 1315 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/cs/
2024-07-01 10:18:25 +00:00
Balazs Toldi
49961c215a Remove FAB from blocked instances page 2024-06-30 20:19:11 +02:00
Balazs Toldi
b0cbecbdc5 Remove score from user pages
This has been removed from lemmy. No longer needed.
2024-06-30 11:32:33 +02:00
Balazs Toldi
1276435494 View blocked instances
This commit adds the instances page to the blocks activity to display the instances blocked by the user.
2024-06-30 10:53:45 +02:00
Balazs Toldi
b68bf50359 Added handling for unauthorized responses when validating an auth token.
Previously, any unsuccessful response would trigger the onValidateAuthTokenFailed callback. Now, if the response is 401 Unauthorized (indicating an invalid token), the onValidateAuthTokenFailed callback will be called. Other errors are still ignored.
2024-06-28 09:21:04 +02:00
Balazs Toldi
ae125feae0 Adjust markPostAsRead to Lemmy 0.19.4 2024-06-23 14:32:18 +02:00
Balazs Toldi
03c1792262 Don't hide read posts on saved page
This commit fixes the issue where if the option to hide read posts from the feed is activated, no posts show up in the saved section.

Fixes #219.
2024-06-23 14:18:17 +02:00
Balazs Toldi
6c3d26fe5a Fix comment loading from inbox
There was an issue where if you load comments from a post, it will not display them initially. They would only appear after a refresh. Now it has been fixed, and comments are loaded immediately.
2024-06-21 22:36:00 +02:00
Balazs Toldi
1373b4cb40 Fix crash 2024-06-21 22:19:57 +02:00
Balazs Toldi
ae389527b6 Removed "Community Recommended Sort type" option
Caused some issues, described in #151. Also, this is not a feature in Lemmy, should have been removed anyway.
2024-06-21 21:19:45 +02:00
C1ff0
1390460438 Translated using Weblate (Italian)
Currently translated at 89.1% (1171 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/it/
2024-05-25 13:18:24 +00:00
SomeTr
0674934366 Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1313 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-05-24 09:18:23 +00:00
SomeTr
dbc0effe61 Translated using Weblate (Ukrainian)
Currently translated at 99.9% (1312 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-03-18 17:53:35 +00:00
mochichi
f0cf65a5a4 Translated using Weblate (Japanese)
Currently translated at 75.7% (995 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ja/
2024-03-12 18:53:34 +00:00
v1s7
5696c9e7a8 Translated using Weblate (Russian)
Currently translated at 98.4% (1293 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2024-03-11 04:46:30 +00:00
Integral
3c871e2678 Translated using Weblate (Chinese (Simplified))
Currently translated at 98.0% (1288 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/zh_Hans/
2024-02-27 09:56:33 +00:00
SomeTr
f4d61ee8dc Translated using Weblate (Ukrainian)
Currently translated at 99.9% (1312 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-02-26 08:56:33 +00:00
dogasert01
e7d434458d Translated using Weblate (Turkish)
Currently translated at 85.8% (1127 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/tr/
2024-02-26 08:56:33 +00:00
jaahas
00568cfd37 Translated using Weblate (Finnish)
Currently translated at 51.2% (673 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/fi/
2024-02-24 14:56:33 +00:00
Application-Maker
237894892d Translated using Weblate (Russian)
Currently translated at 98.4% (1293 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2024-02-22 12:56:33 +00:00
Dirk
62bf37e9c3 Translated using Weblate (German)
Currently translated at 100.0% (1313 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2024-02-22 12:56:32 +00:00
Integral
4be9a409ec Translated using Weblate (Chinese (Simplified))
Currently translated at 97.7% (1283 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/zh_Hans/
2024-02-21 10:56:33 +00:00
Dirk
85d94d91c0 Translated using Weblate (German)
Currently translated at 100.0% (1313 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2024-02-21 10:56:33 +00:00
Integral
af4b0cc65e Translated using Weblate (Chinese (Simplified))
Currently translated at 96.1% (1263 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/zh_Hans/
2024-02-20 09:56:33 +00:00
0que
1f8f44af57 Translated using Weblate (Russian)
Currently translated at 98.4% (1292 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2024-02-03 17:56:34 +00:00
gallegonovato
f3db563550 Translated using Weblate (Spanish)
Currently translated at 87.9% (1155 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/es/
2024-01-31 17:56:33 +00:00
Application-Maker
0aeaa8fb93 Translated using Weblate (Russian)
Currently translated at 98.3% (1291 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2024-01-29 00:56:32 +00:00
coper
213856a1eb Translated using Weblate (Spanish)
Currently translated at 87.8% (1154 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/es/
2024-01-29 00:56:32 +00:00
Application-Maker
bc1cd27dd4 Translated using Weblate (Russian)
Currently translated at 98.6% (1295 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2024-01-26 20:56:33 +00:00
Hiajen
2f9d45bed3 Translated using Weblate (German)
Currently translated at 95.0% (1248 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2024-01-24 20:56:34 +00:00
Application-Maker
bf5937da63 Translated using Weblate (Russian)
Currently translated at 98.6% (1295 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2024-01-22 08:01:41 +00:00
0que
d04f0c296c Translated using Weblate (Russian)
Currently translated at 98.5% (1294 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2024-01-20 16:56:33 +00:00
onemorebug
ad2a1f5bf5 Translated using Weblate (German)
Currently translated at 94.8% (1245 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2024-01-17 16:56:33 +00:00
SomeTr
72a8f88738 Translated using Weblate (Ukrainian)
Currently translated at 99.8% (1311 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-01-07 12:49:12 +00:00
Bazsalanszky
3668466ee6 Translated using Weblate (Hungarian)
Currently translated at 82.7% (1087 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/hu/
2024-01-07 12:49:12 +00:00
Fjuro
cecb218278 Translated using Weblate (Czech)
Currently translated at 100.0% (1313 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/cs/
2024-01-07 12:49:12 +00:00
Balazs Toldi
8cf911685a Merge remote-tracking branch 'origin/master'
# Conflicts:
#	app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java
2024-01-06 21:53:14 +01:00
Balazs Toldi
07fbb103e7 Fix loading block page
Closes #228
2024-01-06 21:52:13 +01:00
Balazs Toldi
3195f05e56 Only check token for logged in users 2024-01-06 21:42:57 +01:00
SomeTr
67da6b1c53 Translated using Weblate (Ukrainian)
Currently translated at 99.8% (1311 of 1313 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-01-06 20:18:37 +00:00
tinsukE
0662173045 Allow login with email (#239)
While the call to obtain a JWT (`api/v3/user/login`) works for username or email, the app was then following that with a call to ` api/v3/user`, which only works with username (https://lemmy.readme.io/reference/get_user). This would cause the login attempt to fail with the error reported on #235.

These changes skip the call to `api/v3/user`, and instead retrieves the user information from the call to `api/v3/site`, that was already being performed.

Fixes #235.

Question: should the label of the username field be updated to "Username / Email" or "Username or Email"? (screenshot)

Reviewed-on: https://codeberg.org/Bazsalanszky/Eternity/pulls/239
Reviewed-by: Bazsalanszky <bazsalanszky@noreply.codeberg.org>
Co-authored-by: tinsukE <tinsuke@noreply.codeberg.org>
Co-committed-by: tinsukE <tinsuke@noreply.codeberg.org>
2024-01-06 20:18:32 +00:00
0que
3d5c936fa3 Translated using Weblate (Russian)
Currently translated at 98.5% (1292 of 1311 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2024-01-06 10:40:09 +00:00
Balazs Toldi
e7f84b8aed Better realization of a Lemmy upgrade 2024-01-06 11:40:00 +01:00
Balazs Toldi
ba5b533cb9 Added "Most comments" and "new comments" sort type 2024-01-06 11:39:33 +01:00
Balazs Toldi
133dc4a69c Fix "Old" sort type for multi communities 2024-01-06 11:20:30 +01:00
Balazs Toldi
0fd7203fa3 Multi communities (#209)
Reviewed-on: https://codeberg.org/Bazsalanszky/Eternity/pulls/209
Co-authored-by: Balazs Toldi <balazs@toldi.eu>
Co-committed-by: Balazs Toldi <balazs@toldi.eu>
2024-01-06 10:18:16 +00:00
SomeTr
1a1b92bb72 Translated using Weblate (Ukrainian)
Currently translated at 99.9% (1310 of 1311 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2024-01-05 10:43:51 +00:00
Bazsalanszky
715f371440 Translated using Weblate (Hungarian)
Currently translated at 82.9% (1087 of 1311 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/hu/
2024-01-05 10:43:51 +00:00
Fjuro
b1164921a0 Translated using Weblate (Czech)
Currently translated at 100.0% (1311 of 1311 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/cs/
2024-01-05 10:43:51 +00:00
Balazs Toldi
b69245aedc Fix shortcut login issues
Fix issues with home screen shortcuts not logging the user in properly
2024-01-04 19:12:18 +01:00
Balazs Toldi
3dc94a05c7 Remove report option from User pages
This was a reddit feature that is unavailable on Lemmy. Closes #211
2024-01-04 15:02:27 +01:00
Balazs Toldi
d0849e9f27 Fix pull down refresh on Post detail pages
The refresh function was incorrectly called, making the loading progress not stopping at all (actually it didn't even start properly)
2024-01-04 14:51:54 +01:00
Balazs Toldi
2ea47cf7fd Changed intent filter from www.hexbear.net to hexbear.net
Fixes #237
2024-01-04 11:06:55 +01:00
Balazs Toldi
6d23f4e13d Merge remote-tracking branch 'origin/master' 2024-01-04 11:04:26 +01:00
Balazs Toldi
8a9102bc8a Check the user token when opening the app 2024-01-04 11:03:29 +01:00
Bazsalanszky
02bed2eb3b Merge pull request 'Remove Gfycat support (the service is dead), simplifying the code' (#226) from tinsukE/Eternity:remove_gfycat into master
Reviewed-on: https://codeberg.org/Bazsalanszky/Eternity/pulls/226
Reviewed-by: Bazsalanszky <bazsalanszky@noreply.codeberg.org>
2024-01-03 13:39:39 +00:00
Bazsalanszky
84653d7677 Merge pull request 'Add previews to video (MP4, WEBM) posts' (#225) from tinsukE/Eternity:video-preview into master
Reviewed-on: https://codeberg.org/Bazsalanszky/Eternity/pulls/225
Reviewed-by: Bazsalanszky <bazsalanszky@noreply.codeberg.org>
2024-01-03 13:39:25 +00:00
Balazs Toldi
40a9091b7d Scaled and Controversial sort types 2024-01-03 14:28:28 +01:00
tinsukE
103ab039b3 Remove Gfycat support (the service is dead), simplifying the code 2024-01-03 09:39:53 +01:00
Balazs Toldi
af7148ce58 Removed IzzyOnDroid badge 2024-01-02 18:38:26 +01:00
Balazs Toldi
ff0bacff1d Fix "share on local instance" option for post pages 2024-01-02 18:37:24 +01:00
Sergio Varela
b684542e42 Translated using Weblate (Spanish)
Currently translated at 87.9% (1153 of 1311 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/es/
2023-11-28 16:38:27 +00:00
Sergio Varela
a1d78271fa Translated using Weblate (Spanish)
Currently translated at 85.9% (1127 of 1311 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/es/
2023-11-23 16:13:37 +00:00
tinsukE
1c75710424 Add previews to video (MP4, WEBM) posts 2023-11-22 08:02:21 +00:00
alextecplayz
89583cfe29 Translated using Weblate (Romanian)
Currently translated at 100.0% (1311 of 1311 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ro/
2023-11-20 11:13:38 +00:00
0que
8e0b599b09 Translated using Weblate (Russian)
Currently translated at 98.6% (1293 of 1311 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2023-11-17 16:13:37 +00:00
SomeTr
b8eda72d7b Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1311 of 1311 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-11-13 17:13:38 +00:00
0que
c0f483e570 Translated using Weblate (Russian)
Currently translated at 97.2% (1275 of 1311 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2023-11-13 17:13:37 +00:00
Balazs Toldi
083bde8149 Merge remote-tracking branch 'origin/master' 2023-11-10 22:16:14 +01:00
Balazs Toldi
ff3ccca3eb Minor fix to comment filters 2023-11-10 11:01:35 +01:00
Fjuro
b4569d56e6 Translated using Weblate (Czech)
Currently translated at 100.0% (1311 of 1311 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/cs/
2023-11-10 09:42:39 +00:00
Balazs Toldi
0b1171c5b2 Fix reddit link handling
This Eternity should not attempt to open Reddit links as it's for Lemmy, not Reddit. Instead, they should be handled as regular links. If a reddit app is installed (e.g. Infinity) it should use that app instead.

Closes #213
2023-11-10 10:31:48 +01:00
Balazs Toldi
48776d28bb Show a bin icon on deleted posts 2023-11-10 10:19:48 +01:00
SomeTr
88f932ad5a Translated using Weblate (Ukrainian)
Currently translated at 99.5% (1305 of 1311 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-11-10 06:50:09 +00:00
SomeTr
8bb8bf3b31 Translated using Weblate (Ukrainian)
Currently translated at 99.5% (1304 of 1310 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-11-10 06:50:09 +00:00
Fjuro
23a40f27c7 Translated using Weblate (Czech)
Currently translated at 100.0% (1310 of 1310 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/cs/
2023-11-10 06:50:09 +00:00
SomeTr
0a30fdfb27 Translated using Weblate (Ukrainian)
Currently translated at 99.5% (1302 of 1308 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-11-10 06:50:09 +00:00
SomeTr
f6c95b27b4 Translated using Weblate (Ukrainian)
Currently translated at 99.1% (1297 of 1308 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-11-10 06:50:08 +00:00
Bazsalanszky
384543824d Translated using Weblate (English)
Currently translated at 100.0% (1308 of 1308 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/en/
2023-11-10 06:50:08 +00:00
Codeberg Translate
de2a6351c7 Update translation files
Updated by "Remove blank strings" hook in Weblate.

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/
2023-11-10 06:50:08 +00:00
Balazs Toldi
25495b737a Merge remote-tracking branch 'origin/master' 2023-11-10 07:50:01 +01:00
Balazs Toldi
e5ffaf3d97 Fix cross posting
Closes #222
2023-11-10 07:49:52 +01:00
Bazsalanszky
48d41103b6 Update .gitea/issue_template/feature_request.md 2023-11-10 06:43:40 +00:00
Bazsalanszky
04a60211c6 Add .gitea/issue_template/feature_request.md 2023-11-10 06:39:47 +00:00
Balazs Toldi
55f4689984 Auto-complete feature for the login page
This commit adds an auto-complete feature to select the users instance. It fetches all the instances from lemmyverse.net so everyone can find their instance :)

Closes #38
2023-11-09 20:17:55 +01:00
Balazs Toldi
9f02969dd2 Add u/HostileEnemy to credits page
Seriously? Why wasn't this there in the first release?!
2023-11-09 19:19:31 +01:00
Balazs Toldi
fd833a65c5 Fix text issues on post detail activity post without preview page 2023-11-09 19:10:12 +01:00
Balazs Toldi
16dfc65c64 Fixing issues with reading info for kbin magazines
This commit fixes the issue where the information for Kbin/Mbin magazines weren't displayed properly on community pages. The problem was related to magazines having a different actor id (/m/ instead of /c/)

Closes #182
2023-11-08 13:19:28 +01:00
Balazs Toldi
67115e0dd6 Fixing weblate 2023-11-07 16:48:37 +01:00
Balazs Toldi
5f6b966160 Merge remote-tracking branch 'weblate/master'
# Conflicts:
#	app/src/main/res/values-de/strings.xml
#	app/src/main/res/values-tr-rTR/strings.xml
2023-11-07 16:41:44 +01:00
Sergio Varela
4a200d7343 Translated using Weblate (Spanish)
Currently translated at 89.7% (1128 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/es/
2023-11-07 13:20:17 +00:00
Balazs Toldi
aa75fb5592 Fix crash when opening a comment from a user tab
This seems more of a workaround than a fix.
2023-11-07 14:20:09 +01:00
Embark9962
5618e2e88b Translated using Weblate (German)
Currently translated at 100.0% (1257 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-11-06 15:13:38 +00:00
Balazs Toldi
03ee3899d7 Do not load inline images in data-saving mode 2023-11-05 16:49:11 +01:00
Balazs Toldi
6b09f0379c Fix crash related to the "swipe between posts" options
There was a null pointer execution because it did not check for a null value.
2023-11-05 16:19:51 +01:00
Bazsalanszky
fe565d2ef3 Merge pull request 'Updates from upstream' (#218) from infinity-update into master
Reviewed-on: https://codeberg.org/Bazsalanszky/Eternity/pulls/218
2023-11-05 14:19:56 +00:00
Balazs Toldi
14e568e642 Fix translation related compilation errors 2023-11-05 15:09:09 +01:00
Balazs Toldi
ec3b89a056 Fix crashes originating form merging updates from upstream 2023-11-05 14:38:05 +01:00
Balazs Toldi
343484aff2 Eternity (placeholder?) "branding" on splash screen 2023-11-05 12:22:54 +01:00
artnay
ec7ef689c9 Translated using Weblate (Finnish)
Currently translated at 50.7% (638 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/fi/
2023-11-02 17:13:38 +00:00
SomeTr
312a768351 Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1257 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-11-02 17:13:38 +00:00
SomeTr
c4992aac74 Translated using Weblate (Portuguese)
Currently translated at 98.8% (1242 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/pt/
2023-11-02 17:13:38 +00:00
SomeTr
df37db5fed Translated using Weblate (Hindi)
Currently translated at 70.1% (882 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/hi/
2023-11-02 17:13:37 +00:00
SomeTr
d699e3a434 Translated using Weblate (Romanian)
Currently translated at 99.7% (1254 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ro/
2023-10-31 18:10:35 +00:00
Bazsalanszky
c111ee35b4 Translated using Weblate (Hungarian)
Currently translated at 85.4% (1074 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/hu/
2023-10-31 18:10:35 +00:00
SomeTr
766c2dc2c5 Translated using Weblate (Spanish)
Currently translated at 89.6% (1127 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/es/
2023-10-31 18:10:35 +00:00
SomeTr
ec484cd51d Translated using Weblate (Vietnamese)
Currently translated at 88.0% (1107 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/vi/
2023-10-31 18:10:35 +00:00
0que
494545500f Translated using Weblate (Russian)
Currently translated at 99.5% (1251 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2023-10-31 18:10:35 +00:00
SomeTr
db9c7a77e5 Translated using Weblate (Italian)
Currently translated at 91.2% (1147 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/it/
2023-10-31 18:10:35 +00:00
SomeTr
5a2954b432 Translated using Weblate (Hungarian)
Currently translated at 81.3% (1023 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/hu/
2023-10-31 18:10:34 +00:00
SomeTr
751c2bd421 Translated using Weblate (Chinese (Simplified))
Currently translated at 88.7% (1115 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/zh_Hans/
2023-10-31 18:10:34 +00:00
SomeTr
3940f9b402 Translated using Weblate (Vietnamese)
Currently translated at 88.0% (1107 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/vi/
2023-10-31 18:10:34 +00:00
SomeTr
dd72afc115 Translated using Weblate (Turkish)
Currently translated at 89.8% (1130 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/tr/
2023-10-31 18:10:34 +00:00
SomeTr
7c87bf19d2 Translated using Weblate (Romanian)
Currently translated at 99.7% (1254 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ro/
2023-10-31 18:10:34 +00:00
SomeTr
3d5d26f6ec Translated using Weblate (Portuguese (Brazil))
Currently translated at 98.1% (1234 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/pt_BR/
2023-10-31 18:10:34 +00:00
SomeTr
12eec8cc6b Translated using Weblate (Polish)
Currently translated at 88.3% (1110 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/pl/
2023-10-31 18:10:34 +00:00
SomeTr
1d17b4be9e Translated using Weblate (Dutch)
Currently translated at 81.6% (1026 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/nl/
2023-10-31 18:10:34 +00:00
SomeTr
4896aad901 Translated using Weblate (Japanese)
Currently translated at 78.3% (985 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ja/
2023-10-31 18:10:34 +00:00
SomeTr
46b6ab82d5 Translated using Weblate (Italian)
Currently translated at 91.3% (1148 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/it/
2023-10-31 18:10:34 +00:00
SomeTr
523db3c659 Translated using Weblate (Hungarian)
Currently translated at 81.4% (1024 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/hu/
2023-10-31 18:10:34 +00:00
SomeTr
4614ee0ae2 Translated using Weblate (Croatian)
Currently translated at 71.7% (902 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/hr/
2023-10-31 18:10:34 +00:00
SomeTr
a874b9b455 Translated using Weblate (Hindi)
Currently translated at 70.0% (880 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/hi/
2023-10-31 18:10:34 +00:00
SomeTr
998e4dd802 Translated using Weblate (Spanish)
Currently translated at 89.5% (1126 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/es/
2023-10-31 18:10:34 +00:00
SomeTr
cca17e0e81 Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1257 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-10-31 18:10:34 +00:00
artnay
f9deaccb5a Translated using Weblate (Finnish)
Currently translated at 50.6% (637 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/fi/
2023-10-31 18:10:34 +00:00
Fjuro
04a9679429 Translated using Weblate (Czech)
Currently translated at 100.0% (1257 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/cs/
2023-10-31 18:10:34 +00:00
SomeTr
caffec6b2a Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1257 of 1257 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-10-31 18:10:34 +00:00
SomeTr
17c98e85ac Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1255 of 1255 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-10-31 18:10:34 +00:00
SomeTr
2c46ac079c Translated using Weblate (Croatian)
Currently translated at 71.9% (903 of 1255 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/hr/
2023-10-31 18:10:34 +00:00
SomeTr
95b4325f3e Translated using Weblate (Hindi)
Currently translated at 70.1% (881 of 1255 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/hi/
2023-10-31 18:10:34 +00:00
SomeTr
673d717ef1 Translated using Weblate (Spanish)
Currently translated at 89.8% (1127 of 1255 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/es/
2023-10-31 18:10:34 +00:00
Fjuro
8c9460c6c0 Translated using Weblate (Czech)
Currently translated at 100.0% (1255 of 1255 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/cs/
2023-10-31 18:10:34 +00:00
scharnkn
b1d1f7ec72 Translated using Weblate (German)
Currently translated at 100.0% (1254 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-10-31 18:10:34 +00:00
dieserniko
7d394d5a13 Translated using Weblate (German)
Currently translated at 100.0% (1254 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-10-31 18:10:34 +00:00
SomeTr
e07ffc69ed Translated using Weblate (Turkish)
Currently translated at 90.2% (1132 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/tr/
2023-10-31 18:10:34 +00:00
SomeTr
80f7d1e331 Translated using Weblate (Polish)
Currently translated at 88.5% (1110 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/pl/
2023-10-31 18:10:34 +00:00
SomeTr
f06775de4b Translated using Weblate (Japanese)
Currently translated at 78.7% (987 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ja/
2023-10-31 18:10:34 +00:00
SomeTr
2184d73e3e Translated using Weblate (Spanish)
Currently translated at 89.8% (1127 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/es/
2023-10-31 18:10:34 +00:00
SomeTr
0ff2e70867 Translated using Weblate (Ukrainian)
Currently translated at 100.0% (1254 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-10-31 18:10:34 +00:00
alextecplayz
e7e83946eb Translated using Weblate (Romanian)
Currently translated at 100.0% (1254 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ro/
2023-10-31 18:10:34 +00:00
Frederik Zorn
2de2614d6f Translated using Weblate (German)
Currently translated at 100.0% (1254 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-10-31 18:10:34 +00:00
Eryk Michalak
67349a134d Translated using Weblate (Polish)
Currently translated at 88.5% (1111 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/pl/
2023-10-31 18:10:34 +00:00
artnay
25caea0b72 Translated using Weblate (Finnish)
Currently translated at 50.3% (632 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/fi/
2023-10-31 18:10:34 +00:00
scharnkn
5522884bb2 Translated using Weblate (German)
Currently translated at 99.8% (1252 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-10-31 18:10:34 +00:00
functional-tim
9de9ba19e7 Translated using Weblate (German)
Currently translated at 99.8% (1252 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-10-31 18:10:34 +00:00
Hartmut Goebel
05f1f929e1 Translated using Weblate (German)
Currently translated at 99.8% (1252 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-10-31 18:10:34 +00:00
scharnkn
ab6573b3cf Translated using Weblate (German)
Currently translated at 99.3% (1246 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-10-31 18:10:33 +00:00
Hartmut Goebel
7ba12262ca Translated using Weblate (German)
Currently translated at 99.3% (1246 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-10-31 18:10:33 +00:00
artnay
82f5be2568 Translated using Weblate (Finnish)
Currently translated at 48.5% (609 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/fi/
2023-10-31 18:10:33 +00:00
artnay
e33b4a3ec6 Added translation using Weblate (Finnish) 2023-10-31 18:10:33 +00:00
edxkl
40f28071d6 Translated using Weblate (Portuguese (Brazil))
Currently translated at 98.4% (1234 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/pt_BR/
2023-10-31 18:10:33 +00:00
tubbadu
2783bcd1e4 Translated using Weblate (Italian)
Currently translated at 91.5% (1148 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/it/
2023-10-31 18:10:33 +00:00
evmexa-prog
3e9db084b0 Translated using Weblate (Russian)
Currently translated at 99.5% (1248 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2023-10-31 18:10:33 +00:00
alextecplayz
a648993f78 Translated using Weblate (Romanian)
Currently translated at 91.8% (1152 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ro/
2023-10-31 18:10:33 +00:00
edxkl
75416b8b1b Translated using Weblate (Portuguese (Brazil))
Currently translated at 98.3% (1233 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/pt_BR/
2023-10-31 18:10:33 +00:00
JnkLtt
6f273d5e58 Translated using Weblate (German)
Currently translated at 98.6% (1237 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-10-31 18:10:33 +00:00
functional-tim
8654512584 Translated using Weblate (German)
Currently translated at 98.6% (1237 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-10-31 18:10:33 +00:00
scharnkn
46b2e0b816 Translated using Weblate (German)
Currently translated at 98.6% (1237 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-10-31 18:10:33 +00:00
genoxidedev1
d708ef5300 Translated using Weblate (German)
Currently translated at 98.6% (1237 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-10-31 18:10:33 +00:00
botorfj
9c8c667c41 Translated using Weblate (Turkish)
Currently translated at 90.3% (1133 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/tr/
2023-10-31 18:10:33 +00:00
SomeTr
ff270e6895 Translated using Weblate (Ukrainian)
Currently translated at 99.9% (1253 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-10-31 18:10:33 +00:00
0que
7869bd3b2b Translated using Weblate (Russian)
Currently translated at 99.4% (1247 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/ru/
2023-10-31 18:10:33 +00:00
American_Jesus
36d932e9fe Translated using Weblate (Portuguese)
Currently translated at 99.0% (1242 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/pt/
2023-10-31 18:10:33 +00:00
edxkl
5b2f3eb9b4 Translated using Weblate (Portuguese (Brazil))
Currently translated at 98.1% (1231 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/pt_BR/
2023-10-31 18:10:33 +00:00
julroy67
ddb1d6746b Translated using Weblate (French)
Currently translated at 100.0% (1254 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/fr/
2023-10-31 18:10:33 +00:00
Fjuro
f2440e0e2e Translated using Weblate (Czech)
Currently translated at 100.0% (1254 of 1254 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/cs/
2023-10-31 18:10:33 +00:00
Balazs Toldi
af6245eed7 Added a 'Get it on Fdroid' badge to the readme
Hurray! Eternity is on F-droid now!!

Signed-off-by: Balazs Toldi <balazs@toldi.eu>
2023-10-31 19:10:20 +01:00
Balazs Toldi
4397e09016 Merge changes from Infinity
This commit merges the changes that were made in the upstream infinity repo
2023-10-27 15:10:00 +02:00
Bazsalanszky
262d9f02ba Merge pull request 'Reproducible build fix' (#208) from reproducible-build-tests into master
Reviewed-on: https://codeberg.org/Bazsalanszky/Eternity/pulls/208
2023-10-26 06:12:17 +00:00
Bazsalanszky
45b0399766 Merge branch 'master' into reproducible-build-tests 2023-10-26 06:11:47 +00:00
Balazs Toldi
3bee0deb11 Reproducible build fix 2023-10-26 08:05:23 +02:00
Bazsalanszky
27a7b96ffb Merge pull request 'Fix typo in translation section' (#207) from inovvia/Eternity:FixReadMeTypo into master
Reviewed-on: https://codeberg.org/Bazsalanszky/Eternity/pulls/207
Reviewed-by: Bazsalanszky <bazsalanszky@noreply.codeberg.org>
2023-10-25 07:02:41 +00:00
John Matthew Marquez
11a845e21c Fix typo in translation section 2023-10-25 14:59:41 +08:00
Balazs Toldi
6d6a79bcb6 Fix python script in the build process 2023-10-24 21:23:23 +02:00
Balazs Toldi
6ff46f928a Bump version 2023-10-24 20:37:17 +02:00
Balazs Toldi
81e1c73c65 Fix the updating part of the community saving
In a previous commit, I've added a code snippet that made an update query for each fetched summary that is already in the internal database. However, it did not take in to account that the same community can be related to different accounts. This commit fixes this issue by adding an additional filter to the update db query.
2023-10-24 18:58:41 +02:00
Balazs Toldi
554dfff4ad Always add the access token to the retrofit holder
This hopefully eliminates any login related issues on Lemmy 0.19
2023-10-24 18:51:32 +02:00
Balazs Toldi
741ec08386 Minor fix to updating subscribed communities
Previously, the app did not update any changes to a community after subscribing to it. Now the internal db is updated each time the list of subscribers is refreshed.
2023-10-22 18:40:01 +02:00
Balazs Toldi
f8a21fa3ba Add credits to the new icon 2023-10-22 18:26:46 +02:00
Balazs Toldi
fd6bc82214 Make icon toggleable
This commit adds an option to choose between the original and the new icon
2023-10-22 09:51:30 +02:00
Balazs Toldi
0ae8826732 Add the new icon 2023-10-22 09:03:44 +02:00
Balazs Toldi
5311edc404 Add new icon to README and fastlane 2023-10-20 11:38:20 +02:00
Balazs Toldi
d8dc8c39b2 Update README and fastlane description 2023-10-20 11:35:05 +02:00
Balazs Toldi
c43ced8b00 Merge Reproducible Builds
This commit makes release builds reproducible. This will help folks update the app from F-Droid when it's released there.
2023-10-20 09:31:53 +02:00
Balazs Toldi
908f294130 Fix issue with marking as read when swiping
This commit fixes the issue where the 'swiping between posts' and 'mark post as read' options are enable. Previously, it only marked the first post as read, and not the ones that were swiped to. Now, all posts are marked read in these scenarios.
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
2023-10-19 08:18:14 +02:00
Balazs Toldi
95408f8125 Fix link for translation
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
2023-10-16 18:58:49 +02:00
Balazs Toldi
6d5ba059f8 Fixing issue with swiping to see new posts.
This commit fixes the issue with Fetching new posts when swiping on the post detail page.
2023-10-13 18:21:37 +02:00
Balazs Toldi
ecdd9da9c8 Fix issue where display name makes impossible to load saved things
This commit fixes an issue where the display name of a user makes it
impossible to load saved things. The problem is that the display name
was used in the url to load the saved things instead of the username.

Closes #179

Signed-off-by: Balazs Toldi <balazs@toldi.eu>
2023-10-12 09:16:56 +02:00
Balazs Toldi
1c17e6b7d2 Fix some issues with the "goto User" and "goto Community" options
This commit allows the user to input the communities with their "!" prefix. Similarly, it also allows the "@" prefix for users when trying to navigate to them with their corresponding "go to" options.

Also fixes issues with these options in the Community and User pages.
2023-10-12 08:26:50 +02:00
Balazs Toldi
9f60eca225 Fix crash when trying to open the community lists in some cases.
In some cases the app crashed when trying to select a community. This commit attempts to fix this issue
2023-10-12 08:08:02 +02:00
Balazs Toldi
9deba8b10e Fixing some sort type issues
This commit fixes issues where the sort type/time isn't loaded properly and the app resets back to NEW on the frontpage and Hot on Community pages.

Heads up: You might need to change the sort type in your settings if you see any issues.
2023-10-12 08:06:06 +02:00
Balazs Toldi
05948d74f4 Fix authentication when opening the app 2023-10-11 14:00:07 +02:00
Balazs Toldi
1007be50f8 Fix autherntiction on first logging in to Lemmy 0.19 2023-10-11 13:56:14 +02:00
Balazs Toldi
28617cf9a8 Compatibility for Lemmy 0.19
Closes #197
2023-10-06 12:56:33 +02:00
Bazsalanszky
5d2d43eebc Merge pull request 'Add preview to RedGIFs posts' (#187) from tinsukE/Eternity:regifs-preview into master
Reviewed-on: https://codeberg.org/Bazsalanszky/Eternity/pulls/187
Reviewed-by: Bazsalanszky <bazsalanszky@noreply.codeberg.org>
2023-10-06 06:15:34 +00:00
Bazsalanszky
f2b2525823 Merge pull request 'Fix parsing posts and userdata: admin flag removed in recent versions of Lemmy' (#190) from otaconix/Eternity:fix-for-missing-admin-flag into master
Reviewed-on: https://codeberg.org/Bazsalanszky/Eternity/pulls/190
Reviewed-by: Bazsalanszky <bazsalanszky@noreply.codeberg.org>
2023-10-06 06:01:11 +00:00
Balazs Toldi
29547f4750 Show instance for user listings
Closes #166
2023-09-12 09:02:27 +02:00
Balazs Toldi
af63bba54a Show instance for community listings 2023-09-12 08:43:56 +02:00
Stefan Zwanenburg
caf4f177d2 Fix parsing posts and userdata: admin flag removed in recent versions of Lemmy
See: https://github.com/LemmyNet/lemmy/pull/3403

For now, I guess we can try parsing the flag if it's present, and fall
back on assuming the associated user is *not* an admin.
2023-09-11 11:46:08 +02:00
Angelo Suzuki
1e67b34440 Add previews to RedGIFs posts
- Setup Glide with OkHttp in the custom application
- Add PostEnricher framework, that allows to add more data to fetched Posts. This was used to fetch the RedGIFs preview from their API.
2023-09-07 13:03:08 +02:00
Angelo Suzuki
67afcd7e88 Cleanup RedGIFs API usage
- Add User-Agent and authentication transparently
- Provide RedgifsAPI instance
2023-09-07 13:02:59 +02:00
Bazsalanszky
9406f29562 Merge pull request 'Use an OkHttpClient with User-Agent when initializing BigImageViewer' (#185) from tinsukE/Eternity:glide_user_agent into master
Reviewed-on: https://codeberg.org/Bazsalanszky/Eternity/pulls/185
Reviewed-by: Bazsalanszky <bazsalanszky@noreply.codeberg.org>
2023-09-07 08:48:52 +00:00
Angelo Suzuki
b626c5fb73 Use an OkHttpClient with User-Agent when initializing BigImageViewer.
If not passed, BigImageViewer overrides the Glide OkHttp downloader upon initialization with an empty one:
https://github.com/Piasy/BigImageViewer/blob/067f8eb/GlideImageLoader/src/main/java/com/github/piasy/biv/loader/glide/GlideProgressSupport.java#L76

In that case, Glide creates a default User-Agent:
cbdc1e78b4/library/src/main/java/com/bumptech/glide/load/model/LazyHeaders.java (L103-L106)

Example User-Agent: Dalvik/2.1.0 (Linux; U; Android 11; sdk_gphone_x86 Build/RSR1.201013.001)

https://files.catbox.moe is filtering out that User-Agent. Using the App one fixes it.
2023-09-05 11:42:38 +02:00
Balazs Toldi
0393ff6e77 Fix link text colour on the InstanceInfoActivity 2023-09-03 10:31:07 +02:00
Balazs Toldi
30ecc17d55 Fixing crash on opening community selector on post creation page 2023-09-03 10:21:43 +02:00
Bazsalanszky
7c5f184cc8 Updated Readme.md 2023-08-30 10:13:23 +02:00
Balazs Toldi
d5fff14cb0 Fix flashing screen on the MainActivity when changing the anonymous instance 2023-08-25 22:23:20 +02:00
Balazs Toldi
5cdda037b2 Change artifact name on tagged builds 2023-08-25 17:41:24 +02:00
Balazs Toldi
0942f7c5ec Bump version 2023-08-25 17:34:14 +02:00
Balazs Toldi
efe90d0030 Changed default media download location to the "Eternity" folder 2023-08-25 17:23:56 +02:00
Balazs Toldi
2d45f337d7 Somewhat better phone images 2023-08-25 17:15:50 +02:00
Balazs Toldi
70cf6f3340 Fix bug with unsubscribing from communities 2023-08-25 17:14:23 +02:00
Balazs Toldi
6542859892 Fix IndexOutOfBoundsException in CommentsRecyclerViewAdapter 2023-08-25 09:36:37 +02:00
Balazs Toldi
143bc5e1b6 Fix issues with resolving Links
This commit changes how resolving links work. It will not use the resolve object function now for local instance links, as they would fail almost every time.

It also opens toasts in the application context instead of the activity context. This might prevent some crashes
2023-08-25 09:02:39 +02:00
Balazs Toldi
6e51ea6ee7 Fix crashes and issues with searching in communities 2023-08-25 08:35:05 +02:00
Balazs Toldi
d7c4e3d5bc Truncate long names in the navigation header 2023-08-24 23:11:34 +02:00
Balazs Toldi
1ed86c138e Removed automatically added dependency 2023-08-24 23:10:46 +02:00
Balazs Toldi
2d83545865 Fix theming on multiple elements
Fixed theming on:
- Post content on PostImage and PostLink activities
- Report content forms

Closes #163
2023-08-24 20:09:52 +02:00
Balazs Toldi
3594f10fdd Fix issues with subscription listing after marking communities as favorite
Previously, when marking a community as favorite made some communities disappear on the subscription list
2023-08-24 19:53:48 +02:00
Balazs Toldi
a903ac9dbd Attempt to fix crash when deleted comment add necessary placeholder 2023-08-23 23:23:10 +02:00
Balazs Toldi
ed90a278a6 Fix crashes related to sort types
Closes #153 and #113
2023-08-23 22:53:41 +02:00
Balazs Toldi
6221b33a3d Fix user name on collapsed comments
Closes #161
2023-08-23 22:35:51 +02:00
Balazs Toldi
2561ba8bd0 Fix post layouts 2023-08-23 21:39:08 +02:00
Balazs Toldi
9859608764 Merge remote-tracking branch 'weblate/master'
# Conflicts:
#	app/src/main/res/values/strings.xml
2023-08-23 21:24:20 +02:00
SomeTr
b40077f83f Translated using Weblate (Ukrainian)
Currently translated at 99.7% (1249 of 1252 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-08-23 19:19:38 +00:00
Bazsalanszky
76dc0ff083 Translated using Weblate (Hungarian)
Currently translated at 81.7% (1024 of 1252 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/hu/
2023-08-23 19:19:38 +00:00
Bazsalanszky
6a2d59ed48 Translated using Weblate (English)
Currently translated at 100.0% (1252 of 1252 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/en/
2023-08-23 19:19:38 +00:00
Balazs Toldi
a09d6f85f8 Add option to share links on local instance 2023-08-23 21:14:53 +02:00
SomeTr
2f3d39ed31 Translated using Weblate (Ukrainian)
Currently translated at 99.6% (1248 of 1252 strings)

Translation: Eternity/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/uk/
2023-08-23 09:21:45 +00:00
American_Jesus
83e0fc039f Translated using Weblate (Portuguese)
Currently translated at 99.1% (1235 of 1245 strings)

Translation: Infinity for Lemmy/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/pt/
2023-08-23 09:21:45 +00:00
julroy67
d4ca682882 Translated using Weblate (French)
Currently translated at 94.5% (1177 of 1245 strings)

Translation: Infinity for Lemmy/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/fr/
2023-08-23 09:21:45 +00:00
dieserniko
e2b75a3928 Translated using Weblate (German)
Currently translated at 98.2% (1223 of 1245 strings)

Translation: Infinity for Lemmy/App
Translate-URL: https://translate.codeberg.org/projects/infinity-for-lemmy/app/de/
2023-08-23 09:21:45 +00:00
Balazs Toldi
d9f9fb51db Fix instance info activity card background colours 2023-08-23 11:21:19 +02:00
Balazs Toldi
a8b2091e69 Bump version 2023-08-22 22:18:03 +02:00
417 changed files with 20818 additions and 16401 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

BIN
.assets/fdroid-badge.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@@ -0,0 +1,28 @@
---
name: "Feature request"
about: "Request a feature!"
title: "[Feature] "
ref: "master"
labels:
- Kind/Feature
---
### Description
<!-- A clear and concise description of what the feature is and what problem it solves. -->
### Background
<!-- Any background information or context that would be helpful. -->
### Proposed Solution
<!--
- Describe the solution you'd like.
- A clear and concise description of what you want to happen.
- Include any alternative solutions or features you've considered.
- Add any technical details, mockups, or examples if available.
-->
### Additional Context
<!-- Add any other context, screenshots, or links to existing issues/discussions about the feature here. -->

2
.gitignore vendored
View File

@@ -56,6 +56,8 @@ gen-external-apklibs
# NDK
obj/
**/ndkHelperBin
**/.cxx
# IntelliJ IDEA
*.iml

View File

@@ -1,14 +1,15 @@
steps:
build:
image: alvrme/alpine-android:android-33-jdk11
image: alvrme/alpine-android:android-34-jdk17
commands:
- apk add --no-cache python3
- ./gradlew :app:assembleRelease
when:
path: [ app/**, build.gradle ]
sign:
image: alvrme/alpine-android:android-33-jdk11
image: alvrme/alpine-android:android-34-jdk17
commands:
- ./scripts/apk-sign.sh LemmInfinity-signed.apk app/build/outputs/apk/release/app-release-unsigned.apk
- ./scripts/apk-sign.sh Eternity-signed.apk app/build/outputs/apk/release/app-release-unsigned.apk
secrets: [ APK_KS_PASS, APK_KS, APK_KS_ALIAS ]
when:
event: [ tag ]
@@ -17,12 +18,12 @@ steps:
settings:
base_url: https://codeberg.org
files:
- LemmInfinity-signed.apk
- Eternity-signed.apk
api_key:
from_secret: GITEA_ACCESS_TOKEN
target: main
prerelease: true
note: "This is an alpha release. Expect many bugs and unfinished features!"
note: "Pending release notes..."
when:
event: [ tag ]
when:

View File

@@ -6,11 +6,12 @@ clone:
steps:
build:
image: alvrme/alpine-android:android-33-jdk11
image: alvrme/alpine-android:android-34-jdk11
commands:
- apk add --no-cache python3
- ./gradlew :app:assembleNightly
sign:
image: alvrme/alpine-android:android-33-jdk11
image: alvrme/alpine-android:android-34-jdk11
commands:
- ./scripts/apk-sign.sh eu.toldi.infinityforlemmy.nightly.apk app/build/outputs/apk/nightly/eu.toldi.infinityforlemmy.nightly.apk
secrets: [ APK_KS_PASS, APK_KS, APK_KS_ALIAS ]

View File

@@ -1,5 +1,5 @@
<h1 align="center">
Eternity (formerly Infinity for Lemmy)
Eternity for Lemmy
</h1>
<div align="center">
@@ -10,44 +10,90 @@ A Lemmy client for Android written in Java. It's a fork of the [Infinity for Red
<br>
<div align="center">
<img src="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/raw/branch/master/fastlane/metadata/android/en-US/images/icon.png" width=256>
<img src="https://codeberg.org/Bazsalanszky/Eternity/raw/branch/master/fastlane/metadata/android/en-US/images/icon.png" width=256>
[![status-badge](https://ci.codeberg.org/api/badges/12474/status.svg)](https://ci.codeberg.org/repos/12474)
[![Liberapay patrons](https://img.shields.io/liberapay/patrons/bazsalanszky)](https://liberapay.com/Bazsalanszky)
[![Lemmy Community](https://img.shields.io/lemmy/eternityapp@lemdro.id?style=flat-square&logo=lemmy&label=lemmy)](https://lemdro.id/c/eternityapp)
<a href="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/issues">Report a Bug</a>
<a href="https://codeberg.org/Bazsalanszky/Eternity/issues">Report a Bug</a>
</div>
<div align="center">
<a href="https://apt.izzysoft.de/fdroid/index/apk/eu.toldi.infinityforlemmy">
<img src="./.assets/IzzyOnDroid.png" height="80">
<a href="https://f-droid.org/packages/eu.toldi.infinityforlemmy/">
<img src="./.assets/fdroid-badge.png" height="80">
</a>
<a href="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/releases/">
<a href="https://play.google.com/store/apps/details?id=eu.toldi.infinityforlemmy">
<img src="./.assets/google-play-badge.png" height="80">
</a>
<a href="https://codeberg.org/Bazsalanszky/Eternity/releases/">
<img src="./.assets/codeberg.png" height="80">
</a>
</div>
---
## Action Items for Eternity
## Features
Eternity is currently in the early stages of development. Expect many unfinished features and bugs!
- [x] Implementation of basic post browsing feature
- [x] Support for multiple account handling
- [x] Functionality for post upvotes/downvotes
- [x] Functionality to browse comments
- [x] Capability for creating a new post
- [x] Ability to create comments
- [x] Edit/Delete posts and comments
- [x] Basic inbox
- [ ] Elimination of code/string references specific to Reddit
- [x] Incorporation of private messaging feature
- [x] Feature for saving posts/comments
- [x] Resolving links
- [ ] Account editing function
- [ ] Multi community view?
### Browsing Lemmy
- Explore various feeds (Subscribed/Local/All) and communities
- Subscribe or unsubscribe from specific communities, with the option to block
- Discover communities federated with the current instance
- Favorite a community for quick access
- Manage your subscriptions and blocked communities
### Content Engagement
- Engage with content by voting, saving, sharing, and creating posts or comments
- Enjoy endless scrolling through feeds and posts
- Tailor the view settings for posts (card,compact, gallery)
- Set default preferences for post and comment sorting
- Stay updated with notifications for replies
### Account Management
- Sign in to multiple accounts or instances, and effortlessly switch between them
- Use the inbox features to view replies, mentions, and private messages
- Access your profile to view your posts, comments, and saved content
### Customization
- Choose between various theme options including Light, Dark, OLED
- Support Material You theming
- Explore user-created themes
- Customize font settings
- Optional bottom navigation bar
- Discover a plethora of other customization features
<img
src="https://codeberg.org/Bazsalanszky/Eternity/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/1.png"
alt="Screenshot 1"
height="200" >
<img
src="https://codeberg.org/Bazsalanszky/Eternity/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/2.png"
alt="Screenshot 2"
height="200" >
<img
src="https://codeberg.org/Bazsalanszky/Eternity/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/3.png"
alt="Screenshot 3"
height="200" >
<img
src="https://codeberg.org/Bazsalanszky/Eternity/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/4.png"
alt="Screenshot 4"
height="200" >
<img
src="https://codeberg.org/Bazsalanszky/Eternity/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/5.png"
alt="Screenshot 5"
height="200" >
## Contributing
@@ -66,19 +112,19 @@ Don't forget to give the project a star! Thanks again!
### Translation
You can alos help Eternity by translating it to your native langugage! Translations are done via [Weblate](https://translate.codeberg.org/projects/infinity-for-lemmy/app/)!
You can also help Eternity by translating it to your native langugage! Translations are done via [Weblate](https://translate.codeberg.org/projects/infinity-for-lemmy/app/)!
[![Translation](https://translate.codeberg.org/widgets/infinity-for-lemmy/-/app/multi-auto.svg)](https://translate.codeberg.org/engage/infinity-for-lemmy/)
[![Translation](https://translate.codeberg.org/widgets/infinity-for-lemmy/-/app/multi-auto.svg)](https://translate.codeberg.org/engage/Eternity/)
### Reporting bugs
You can also contribute by [reporting bugs](https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/issues)
You can also contribute by [reporting bugs](https://codeberg.org/Bazsalanszky/Eternity/issues)
<p align="right">(<a href="#top">back to top</a>)</p>
## License
Distributed under the AGPL-3.0 License. See <a href="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/src/branch/master/LICENSE">LICENSE</a> for more information.
Distributed under the AGPL-3.0 License. See <a href="https://codeberg.org/Bazsalanszky/Eternity/src/branch/master/LICENSE">LICENSE</a> for more information.
<p align="right">(<a href="#top">back to top</a>)</p>
@@ -86,6 +132,6 @@ Distributed under the AGPL-3.0 License. See <a href="https://codeberg.org/Bazsal
[@bazsalanszky@lemmy.toldi.eu](https://lemmy.toldi.eu/u/bazsalanszky) - (Owner)
Project Link: [https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy](https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy)
Project Link: [https://codeberg.org/Bazsalanszky/Eternity](https://codeberg.org/Bazsalanszky/Eternity)
<p align="right">(<a href="#top">back to top</a>)</p>

View File

@@ -16,13 +16,13 @@ def getCommitVersionCode = { ->
}
android {
compileSdk 33
compileSdk 34
defaultConfig {
applicationId "eu.toldi.infinityforlemmy"
minSdk 21
targetSdk 33
versionCode 128
versionName "0.0.8"
targetSdk 34
versionCode 136
versionName "0.2.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
@@ -33,7 +33,8 @@ android {
buildTypes {
release {
minifyEnabled false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
@@ -97,7 +98,37 @@ android {
packagingOptions {
doNotStrip '**/*.so'
}
// Kotlin jvm target
kotlinOptions {
jvmTarget = '11'
}
namespace 'eu.toldi.infinityforlemmy'
task rearrangeClass(type: Exec) {
commandLine 'python3', '../scripts/fixEventBus.py'
}
applicationVariants.all { variant ->
if (variant.name == 'release') {
task("compileSingleFile${variant.name.capitalize()}", type: JavaCompile, dependsOn: rearrangeClass) {
def filePath = project.rootDir.absolutePath + '/app/build/generated/ap_generated_sources/release/out/eu/toldi/infinityforlemmy/'
source = files(filePath)
includes = ["**/EventBusIndex.java"]
classpath = variant.getCompileClasspath() + files(project.rootDir.absolutePath + '/app/build/intermediates/javac/release/classes')
destinationDir = file("$buildDir/intermediates/javac/release/classes")
}
tasks.withType(JavaCompile).all { task ->
if (task.name == 'compileReleaseJavaWithJavac') {
task.finalizedBy "compileSingleFile${variant.name.capitalize()}"
}
}
}
}
}
dependencies {
@@ -108,7 +139,7 @@ dependencies {
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.0"
def lifecycleVersion = "2.5.1"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycleVersion"
@@ -196,11 +227,12 @@ dependencies {
def glideVersion = "4.12.0"
implementation "com.github.bumptech.glide:glide:$glideVersion"
annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
implementation "com.github.bumptech.glide:okhttp-integration:$glideVersion"
implementation 'jp.wasabeef:glide-transformations:4.3.0'
implementation 'com.github.santalu:aspect-ratio-imageview:1.0.9'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.23'
def bivVersion = "1.8.1"
implementation "com.github.piasy:BigImageViewer:bivVersion"
implementation "com.github.piasy:BigImageViewer:$bivVersion"
implementation "com.github.piasy:GlideImageLoader:$bivVersion"
implementation "com.github.piasy:GlideImageViewFactory:$bivVersion"
@@ -222,8 +254,6 @@ dependencies {
// Loading ProgressBar
implementation 'com.lsjwzh:materialloadingprogressbar:0.5.8-RELEASE'
// Customizable TextView
implementation 'com.libRG:customtextview:2.4'
// Dismiss gesturing
implementation 'app.futured.hauler:hauler:5.0.0'
@@ -239,9 +269,42 @@ dependencies {
implementation 'com.otaliastudios:zoomlayout:1.9.0'
implementation 'androidx.core:core-splashscreen:1.0.1'
/**** Builds and flavors ****/
// debugImplementation because LeakCanary should only run in debug builds.
//debugImplementation 'com.squareup.leakcanary:leakcanary-android:x.y'
}
// NB: Android Studio can't find the imports; this does not affect the
// actual build since Gradle can find them just fine.
import com.android.tools.profgen.ArtProfileKt
import com.android.tools.profgen.ArtProfileSerializer
import com.android.tools.profgen.DexFile
project.afterEvaluate {
tasks.each { task ->
if (task.name.startsWith("compile") && task.name.endsWith("ReleaseArtProfile")) {
task.doLast {
outputs.files.each { file ->
if (file.name.endsWith(".profm")) {
println("Sorting ${file} ...")
def version = ArtProfileSerializer.valueOf("METADATA_0_0_2")
def profile = ArtProfileKt.ArtProfile(file)
def keys = new ArrayList(profile.profileData.keySet())
def sortedData = new LinkedHashMap()
Collections.sort keys, new DexFile.Companion()
keys.each { key -> sortedData[key] = profile.profileData[key] }
new FileOutputStream(file).with {
write(version.magicBytes$profgen)
write(version.versionBytes$profgen)
version.write$profgen(it, sortedData, "")
}
}
}
}
}
}
}

View File

@@ -5,6 +5,8 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-dontobfuscate
-keepattributes SourceFile,LineNumberTable
## Preferences reflection
-keep class * extends androidx.preference.PreferenceFragmentCompat

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
package="eu.toldi.infinityforlemmy">
<queries>
<intent>
@@ -16,12 +17,14 @@
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
<uses-permission-sdk-23
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application
@@ -41,9 +44,26 @@
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<activity
android:name=".activities.HistoryActivity"
android:exported="false"
android:label="@string/history_activity_label"
android:name=".activities.CommentFilterUsageListingActivity"
android:parentActivityName=".activities.SettingsActivity"
android:theme="@style/AppTheme.NoActionBar"
android:exported="false" />
<activity
android:name=".activities.CustomizeCommentFilterActivity"
android:label="@string/customize_comment_filter_activity_label"
android:parentActivityName=".activities.SettingsActivity"
android:theme="@style/AppTheme.NoActionBar"
android:exported="false" />
<activity
android:name=".activities.CommentFilterPreferenceActivity"
android:label="@string/comment_filter_preference_activity_label"
android:parentActivityName=".activities.SettingsActivity"
android:theme="@style/AppTheme.NoActionBar"
android:exported="false" />
<activity
android:name=".activities.BlockedThingListingActivity"
android:label="@string/blocks"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<activity
@@ -116,11 +136,7 @@
android:name=".activities.FetchRandomSubredditOrPostActivity"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.GiveAwardActivity"
android:label="@string/give_award_activity_label"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<activity
android:name=".activities.SelectUserFlairActivity"
android:parentActivityName=".activities.MainActivity"
@@ -139,6 +155,7 @@
<service
android:name=".services.DownloadMediaService"
android:enabled="true"
android:foregroundServiceType="dataSync"
android:exported="false" />
<activity
@@ -156,6 +173,7 @@
<service
android:name=".services.DownloadRedditVideoService"
android:enabled="true"
android:foregroundServiceType="dataSync"
android:exported="false" />
<activity
@@ -304,7 +322,7 @@
<data android:host="feddit.de" />
<data android:host="lemmy.fmhy.ml" />
<data android:host="lemmy.ca" />
<data android:host="www.hexbear.net" />
<data android:host="hexbear.net" />
<data android:host="programming.dev" />
<data android:host="lemmy.dbzer0.com" />
<data android:host="lemmy.blahaj.zone" />
@@ -407,11 +425,6 @@
android:label="@string/subscriptions"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<activity
android:name=".activities.BlockedThingListingActivity"
android:label="@string/blocks"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<activity
android:name=".activities.SubredditSelectionActivity"
android:label="@string/community_selection_activity_label"
@@ -440,12 +453,38 @@
android:label="@string/application_name"
android:theme="@style/AppTheme.Launcher"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias
android:name=".DefaultIcon"
android:targetActivity=".activities.MainActivity"
android:label="@string/application_name"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</activity-alias>
<activity-alias
android:name=".OriginalIcon"
android:targetActivity=".activities.MainActivity"
android:label="@string/application_name"
android:enabled="false"
android:icon="@mipmap/original_ic_launcher"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity
android:name=".activities.LoginActivity"
android:configChanges="orientation|screenLayout|screenSize|layoutDirection"
@@ -474,6 +513,7 @@
android:name=".activities.ViewUserDetailActivity"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
@@ -496,10 +536,12 @@
<service
android:name=".services.SubmitPostService"
android:enabled="true"
android:foregroundServiceType="dataSync"
android:exported="false" />
<service
android:name=".services.EditProfileService"
android:enabled="true"
android:foregroundServiceType="dataSync"
android:exported="false" />
<receiver android:name=".broadcastreceivers.DownloadedMediaDeleteActionBroadcastReceiver" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -12,9 +12,12 @@ import eu.toldi.infinityforlemmy.activities.AccountPostsActivity;
import eu.toldi.infinityforlemmy.activities.AccountSavedThingActivity;
import eu.toldi.infinityforlemmy.activities.BlockedThingListingActivity;
import eu.toldi.infinityforlemmy.activities.CommentActivity;
import eu.toldi.infinityforlemmy.activities.CommentFilterPreferenceActivity;
import eu.toldi.infinityforlemmy.activities.CommentFilterUsageListingActivity;
import eu.toldi.infinityforlemmy.activities.CreateMultiRedditActivity;
import eu.toldi.infinityforlemmy.activities.CustomThemeListingActivity;
import eu.toldi.infinityforlemmy.activities.CustomThemePreviewActivity;
import eu.toldi.infinityforlemmy.activities.CustomizeCommentFilterActivity;
import eu.toldi.infinityforlemmy.activities.CustomizePostFilterActivity;
import eu.toldi.infinityforlemmy.activities.CustomizeThemeActivity;
import eu.toldi.infinityforlemmy.activities.EditCommentActivity;
@@ -25,7 +28,6 @@ import eu.toldi.infinityforlemmy.activities.FetchRandomSubredditOrPostActivity;
import eu.toldi.infinityforlemmy.activities.FilteredPostsActivity;
import eu.toldi.infinityforlemmy.activities.FullMarkdownActivity;
import eu.toldi.infinityforlemmy.activities.GiveAwardActivity;
import eu.toldi.infinityforlemmy.activities.HistoryActivity;
import eu.toldi.infinityforlemmy.activities.InboxActivity;
import eu.toldi.infinityforlemmy.activities.InstanceInfoActivity;
import eu.toldi.infinityforlemmy.activities.LinkResolverActivity;
@@ -72,10 +74,10 @@ import eu.toldi.infinityforlemmy.bottomsheetfragments.AccountChooserBottomSheetF
import eu.toldi.infinityforlemmy.bottomsheetfragments.CommentMoreBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.FlairBottomSheetFragment;
import eu.toldi.infinityforlemmy.fragments.BlockedCommunitiesListingFragment;
import eu.toldi.infinityforlemmy.fragments.BlockedInstancesListingFragment;
import eu.toldi.infinityforlemmy.fragments.BlockedUsersListingFragment;
import eu.toldi.infinityforlemmy.fragments.CommentsListingFragment;
import eu.toldi.infinityforlemmy.fragments.FollowedUsersListingFragment;
import eu.toldi.infinityforlemmy.fragments.HistoryPostFragment;
import eu.toldi.infinityforlemmy.fragments.InboxFragment;
import eu.toldi.infinityforlemmy.fragments.MorePostsInfoFragment;
import eu.toldi.infinityforlemmy.fragments.MultiRedditListingFragment;
@@ -113,7 +115,7 @@ import eu.toldi.infinityforlemmy.settings.TranslationFragment;
import eu.toldi.infinityforlemmy.settings.VideoPreferenceFragment;
@Singleton
@Component(modules = {AppModule.class, NetworkModule.class})
@Component(modules = {AppModule.class, NetworkModule.class, PostEnricherModule.class})
public interface AppComponent {
void inject(MainActivity mainActivity);
@@ -309,10 +311,6 @@ public interface AppComponent {
void inject(MaterialYouWorker materialYouWorker);
void inject(HistoryPostFragment historyPostFragment);
void inject(HistoryActivity historyActivity);
void inject(MorePostsInfoFragment morePostsInfoFragment);
void inject(BlockedThingListingActivity blockedThingListingActivity);
@@ -321,12 +319,20 @@ public interface AppComponent {
void inject(BlockedUsersListingFragment blockedUsersListingFragment);
void inject(BlockedInstancesListingFragment blockedInstancesListingFragment);
void inject(CommentMoreBottomSheetFragment commentMoreBottomSheetFragment);
void inject(PrivateMessageFragment privateMessageFragment);
void inject(@NotNull InstanceInfoActivity instanceInfoActivity);
void inject(CommentFilterPreferenceActivity commentFilterPreferenceActivity);
void inject(CustomizeCommentFilterActivity customizeCommentFilterActivity);
void inject(CommentFilterUsageListingActivity commentFilterUsageListingActivity);
@Component.Factory
interface Factory {
AppComponent create(@BindsInstance Application application);

View File

@@ -0,0 +1,85 @@
package eu.toldi.infinityforlemmy;
import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.util.AttributeSet;
import androidx.appcompat.widget.AppCompatTextView;
import android.content.res.TypedArray;
public class CustomTextView extends AppCompatTextView {
private float radius = 6f;
private boolean roundedView = true;
private int shape = 0;
public CustomTextView(Context context) {
super(context);
init(null);
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
public CustomTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
}
private void init(AttributeSet attrs) {
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomTextView);
radius = a.getDimension(R.styleable.CustomTextView_lib_setRadius, radius);
roundedView = a.getBoolean(R.styleable.CustomTextView_lib_setRoundedView, roundedView);
shape = a.getInt(R.styleable.CustomTextView_lib_setShape, shape);
a.recycle();
}
updateBackground();
}
private void updateBackground() {
GradientDrawable drawable = new GradientDrawable();
if (shape == 0) { // Rectangle
drawable.setShape(GradientDrawable.RECTANGLE);
} else if (shape == 1) { // Oval
drawable.setShape(GradientDrawable.OVAL);
}
if (roundedView) {
drawable.setCornerRadius(radius);
} else {
drawable.setCornerRadius(0);
}
this.setBackground(drawable);
}
public void setBackgroundColor(int color) {
GradientDrawable background = (GradientDrawable) this.getBackground();
background.setColor(color);
this.setBackground(background);
}
public void setBorderColor(int borderColor, int borderWidthDp) {
GradientDrawable background = (GradientDrawable) this.getBackground();
background.setStroke(dpToPx(borderWidthDp), borderColor);
this.setBackground(background);
}
public void setBorderColor(int borderColor) {
this.setBorderColor(borderColor, 1);
}
private int dpToPx(int dp) {
float density = getContext().getResources().getDisplayMetrics().density;
return Math.round(dp * density);
}
}

View File

@@ -0,0 +1,78 @@
package eu.toldi.infinityforlemmy;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import androidx.annotation.Nullable;
public class DualBadgeDrawable extends Drawable {
private Drawable leftBadge;
private Drawable rightBadge;
public DualBadgeDrawable(Drawable leftBadge, Drawable rightBadge) {
this.leftBadge = leftBadge;
this.rightBadge = rightBadge;
}
@Override
public void draw(Canvas canvas) {
if (leftBadge == null || rightBadge == null) {
return;
}
int width = getBounds().width();
int height = getBounds().height();
// Draw the left badge on the left half of the canvas
Rect leftRect = new Rect(0, 0, width / 2, height);
leftBadge.setBounds(leftRect);
leftBadge.draw(canvas);
// Draw the right badge on the right half of the canvas
Rect rightRect = new Rect(width / 2, 0, width, height);
rightBadge.setBounds(rightRect);
rightBadge.draw(canvas);
}
@Override
public void setAlpha(int alpha) {
if (leftBadge != null) {
leftBadge.setAlpha(alpha);
}
if (rightBadge != null) {
rightBadge.setAlpha(alpha);
}
}
@Override
public void setColorFilter(@Nullable ColorFilter colorFilter) {
if (leftBadge != null) {
leftBadge.setColorFilter(colorFilter);
}
if (rightBadge != null) {
rightBadge.setColorFilter(colorFilter);
}
}
@Override
public int getOpacity() {
return leftBadge != null ? leftBadge.getOpacity() : rightBadge.getOpacity();
}
@Override
public int getIntrinsicWidth() {
int leftWidth = leftBadge != null ? leftBadge.getIntrinsicWidth() : 0;
int rightWidth = rightBadge != null ? rightBadge.getIntrinsicWidth() : 0;
return leftWidth + rightWidth;
}
@Override
public int getIntrinsicHeight() {
int leftHeight = leftBadge != null ? leftBadge.getIntrinsicHeight() : 0;
int rightHeight = rightBadge != null ? rightBadge.getIntrinsicHeight() : 0;
return Math.max(leftHeight, rightHeight);
}
}

View File

@@ -1,135 +0,0 @@
package eu.toldi.infinityforlemmy;
import android.content.Context;
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 eu.toldi.infinityforlemmy.apis.GfycatAPI;
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import eu.toldi.infinityforlemmy.utils.JSONUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
public class FetchGfycatOrRedgifsVideoLinks {
public interface FetchGfycatOrRedgifsVideoLinksListener {
void success(String webm, String mp4);
void failed(int errorCode);
}
public static void fetchGfycatVideoLinks(Executor executor, Handler handler, Retrofit gfycatRetrofit,
String gfycatId,
FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
executor.execute(() -> {
try {
Response<String> response = gfycatRetrofit.create(GfycatAPI.class).getGfycatData(gfycatId).execute();
if (response.isSuccessful()) {
parseGfycatVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
} else {
handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.failed(response.code()));
}
} catch (IOException e) {
e.printStackTrace();
handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.failed(-1));
}
});
}
public static void fetchRedgifsVideoLinks(Context context, Executor executor, Handler handler, Retrofit redgifsRetrofit,
SharedPreferences currentAccountSharedPreferences,
String gfycatId,
FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
executor.execute(() -> {
try {
Response<String> response = redgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(currentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")),
gfycatId, APIUtils.USER_AGENT).execute();
if (response.isSuccessful()) {
parseRedgifsVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
} else {
handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.failed(response.code()));
}
} catch (IOException e) {
e.printStackTrace();
handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.failed(-1));
}
});
}
public static void fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(Executor executor, Handler handler,
Call<String> gfycatCall,
boolean isGfycatVideo,
boolean automaticallyTryRedgifs,
FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
executor.execute(() -> {
try {
Response<String> response = gfycatCall.execute();
if (response.isSuccessful()) {
if (isGfycatVideo) {
parseGfycatVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
} else {
parseRedgifsVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
}
} else {
if (response.code() == 404 && isGfycatVideo && automaticallyTryRedgifs) {
fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(executor, handler, gfycatCall.clone(),
false, false, fetchGfycatOrRedgifsVideoLinksListener);
} else {
handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.failed(response.code()));
}
}
} catch (IOException e) {
e.printStackTrace();
handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.failed(-1));
}
});
}
private static void parseGfycatVideoLinks(Handler handler, String response,
FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
try {
JSONObject jsonObject = new JSONObject(response);
String mp4 = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).has(JSONUtils.MP4_URL_KEY) ?
jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getString(JSONUtils.MP4_URL_KEY)
: jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY)
.getJSONObject(JSONUtils.CONTENT_URLS_KEY)
.getJSONObject(JSONUtils.MP4_KEY)
.getString(JSONUtils.URL_KEY);
String webm;
if (jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).has(JSONUtils.WEBM_URL_KEY)) {
webm = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getString(JSONUtils.WEBM_URL_KEY);
} else if (jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getJSONObject(JSONUtils.CONTENT_URLS_KEY).has(JSONUtils.WEBM_KEY)) {
webm = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY)
.getJSONObject(JSONUtils.CONTENT_URLS_KEY)
.getJSONObject(JSONUtils.WEBM_KEY)
.getString(JSONUtils.URL_KEY);
} else {
webm = mp4;
}
handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.success(webm, mp4));
} catch (JSONException e) {
e.printStackTrace();
handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.failed(-1));
}
}
private static void parseRedgifsVideoLinks(Handler handler, String response,
FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
try {
String mp4 = new JSONObject(response).getJSONObject(JSONUtils.GIF_KEY).getJSONObject(JSONUtils.URLS_KEY)
.getString(JSONUtils.HD_KEY);
handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.success(mp4, mp4));
} catch (JSONException e) {
e.printStackTrace();
handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.failed(-1));
}
}
}

View File

@@ -1,99 +0,0 @@
package eu.toldi.infinityforlemmy;
import android.os.AsyncTask;
import androidx.annotation.NonNull;
import org.json.JSONException;
import org.json.JSONObject;
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
public class FetchMyInfo {
public static void fetchAccountInfo(final Retrofit retrofit, RedditDataRoomDatabase redditDataRoomDatabase,
String username,String accessToken, final FetchMyInfoListener fetchMyInfoListener) {
LemmyAPI api = retrofit.create(LemmyAPI.class);
Call<String> userInfo = api.userInfo(username,accessToken);
userInfo.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
new ParseAndSaveAccountInfoAsyncTask(response.body(), redditDataRoomDatabase, fetchMyInfoListener).execute();
} else {
fetchMyInfoListener.onFetchMyInfoFailed(false);
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
fetchMyInfoListener.onFetchMyInfoFailed(false);
}
});
}
public interface FetchMyInfoListener {
void onFetchMyInfoSuccess(String name, String display_name,String profileImageUrl, String bannerImageUrl);
void onFetchMyInfoFailed(boolean parseFailed);
}
private static class ParseAndSaveAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
private JSONObject jsonResponse;
private RedditDataRoomDatabase redditDataRoomDatabase;
private FetchMyInfoListener fetchMyInfoListener;
private boolean parseFailed;
private String name;
private String profileImageUrl;
private String bannerImageUrl;
private String display_name;
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 {
JSONObject person = jsonResponse.getJSONObject("person_view").getJSONObject("person");
name = LemmyUtils.actorID2FullName(person.getString("actor_id"));
if (!person.isNull("avatar")) {
profileImageUrl = person.getString("avatar");
}
if (!person.isNull("banner")) {
bannerImageUrl = person.getString("banner");
}
display_name = (person.has("display_name")) ? person.getString("display_name") : person.getString("name");
redditDataRoomDatabase.accountDao().updateAccountInfo(name, profileImageUrl, bannerImageUrl);
} catch (JSONException e) {
parseFailed = true;
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (!parseFailed) {
fetchMyInfoListener.onFetchMyInfoSuccess(name,display_name, profileImageUrl, bannerImageUrl);
} else {
fetchMyInfoListener.onFetchMyInfoFailed(true);
}
}
}
}

View File

@@ -49,7 +49,7 @@ public class FetchPostFilterReadPostsAndConcatenatedSubredditNames {
if (anonymousSubscribedSubreddits != null && !anonymousSubscribedSubreddits.isEmpty()) {
StringBuilder stringBuilder = new StringBuilder();
for (SubscribedSubredditData s : anonymousSubscribedSubreddits) {
stringBuilder.append(s.getName()).append("+");
stringBuilder.append(s.getQualified_name()).append(",");
}
if (stringBuilder.length() > 0) {
stringBuilder.deleteCharAt(stringBuilder.length() - 1);

View File

@@ -0,0 +1,71 @@
package eu.toldi.infinityforlemmy;
import android.os.Handler;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
import eu.toldi.infinityforlemmy.utils.JSONUtils;
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,
String redgifsId,
FetchRedgifsVideoLinksListener fetchRedgifsVideoLinksListener) {
executor.execute(() -> {
try {
Response<String> response = redgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(redgifsId).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<String> redgifsCall,
FetchRedgifsVideoLinksListener fetchRedgifsVideoLinksListener) {
executor.execute(() -> {
try {
Response<String> 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));
}
}
}

View File

@@ -11,6 +11,16 @@ import android.os.Bundle;
import android.view.WindowManager;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.lifecycle.ProcessLifecycleOwner;
import com.bumptech.glide.Glide;
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader;
import com.bumptech.glide.load.model.GlideUrl;
import com.evernote.android.state.StateSaver;
import com.livefront.bridge.Bridge;
import com.livefront.bridge.SavedStateHandler;
@@ -18,15 +28,11 @@ import com.livefront.bridge.SavedStateHandler;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.io.InputStream;
import javax.inject.Inject;
import javax.inject.Named;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.lifecycle.ProcessLifecycleOwner;
import eu.toldi.infinityforlemmy.activities.LockScreenActivity;
import eu.toldi.infinityforlemmy.broadcastreceivers.NetworkWifiStatusReceiver;
import eu.toldi.infinityforlemmy.broadcastreceivers.WallpaperChangeReceiver;
@@ -38,6 +44,8 @@ import eu.toldi.infinityforlemmy.font.FontFamily;
import eu.toldi.infinityforlemmy.font.TitleFontFamily;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import okhttp3.Call;
import okhttp3.OkHttpClient;
public class Infinity extends Application implements LifecycleObserver {
public Typeface typeface;
@@ -55,6 +63,9 @@ public class Infinity extends Application implements LifecycleObserver {
@Inject
@Named("security")
SharedPreferences mSecuritySharedPreferences;
@Inject
@Named("glide")
OkHttpClient glideOkHttpClient;
@Override
public void onCreate() {
@@ -159,6 +170,9 @@ public class Infinity extends Application implements LifecycleObserver {
registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
registerReceiver(new WallpaperChangeReceiver(mSharedPreferences), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory((Call.Factory) glideOkHttpClient);
Glide.get(this).getRegistry().replace(GlideUrl.class, InputStream.class, factory);
}
@OnLifecycleEvent(Lifecycle.Event.ON_START)

View File

@@ -9,10 +9,11 @@ import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
import eu.toldi.infinityforlemmy.apis.StreamableAPI;
import eu.toldi.infinityforlemmy.privatemessage.LemmyPrivateMessageAPI;
import eu.toldi.infinityforlemmy.comment.LemmyCommentAPI;
import eu.toldi.infinityforlemmy.post.LemmyPostAPI;
import eu.toldi.infinityforlemmy.privatemessage.LemmyPrivateMessageAPI;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import okhttp3.ConnectionPool;
import okhttp3.Interceptor;
@@ -34,6 +35,21 @@ abstract class NetworkModule {
.build();
}
@Provides
@Named("glide")
@Singleton
static OkHttpClient provideGlideOkHttp(@Named("base") OkHttpClient baseOkHttp,
@Named("RedgifsAccessTokenAuthenticator") Interceptor redGifsAuthenticator) {
return baseOkHttp.newBuilder()
.addInterceptor(chain -> chain.proceed(
chain.request()
.newBuilder()
.header("User-Agent", APIUtils.USER_AGENT)
.build()
))
.addInterceptor(redGifsAuthenticator)
.build();
}
@Provides
@Named("base")
@@ -127,15 +143,6 @@ abstract class NetworkModule {
.build();
}
@Provides
@Named("gfycat")
@Singleton
static Retrofit provideGfycatRetrofit(@Named("base") RetrofitHolder retrofit) {
return retrofit.getRetrofit().newBuilder()
.baseUrl(APIUtils.GFYCAT_API_BASE_URI)
.build();
}
@Provides
@Named("RedgifsAccessTokenAuthenticator")
static Interceptor redgifsAccessTokenAuthenticator(@Named("current_account") SharedPreferences currentAccountSharedPreferences) {
@@ -165,6 +172,12 @@ abstract class NetworkModule {
.build();
}
@Provides
@Singleton
static RedgifsAPI provideRedgifsAPI(@Named("redgifs") Retrofit redgifsRetrofit) {
return redgifsRetrofit.create(RedgifsAPI.class);
}
@Provides
@Named("imgur")
@Singleton
@@ -233,4 +246,13 @@ abstract class NetworkModule {
static LemmyPrivateMessageAPI provideLemmyPrivateMessageAPI(@Named("base") RetrofitHolder retrofit) {
return new LemmyPrivateMessageAPI(retrofit);
}
@Provides
@Named("lemmyVerse")
@Singleton
static Retrofit provideLemmyVerseRetrofit(@Named("base") RetrofitHolder retrofit) {
return retrofit.getRetrofit().newBuilder()
.baseUrl(APIUtils.LEMMYVERSE_API_BASE_URI)
.build();
}
}

View File

@@ -0,0 +1,27 @@
package eu.toldi.infinityforlemmy;
import java.util.Set;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.IntoSet;
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
import eu.toldi.infinityforlemmy.post.enrich.CompositePostEnricher;
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
import eu.toldi.infinityforlemmy.post.enrich.RedGifsPostEnricher;
@Module
abstract class PostEnricherModule {
@Provides
@IntoSet
static PostEnricher provideRedGifsPostEnricher(RedgifsAPI redgifsAPI) {
return new RedGifsPostEnricher(redgifsAPI);
}
@Provides
static PostEnricher providePostEnricher(Set<PostEnricher> postEnrichers) {
return new CompositePostEnricher(postEnrichers);
}
}

View File

@@ -15,8 +15,14 @@ import eu.toldi.infinityforlemmy.account.Account;
import eu.toldi.infinityforlemmy.account.AccountDao;
import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityDao;
import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityData;
import eu.toldi.infinityforlemmy.blockedinstances.BlockedInstanceDao;
import eu.toldi.infinityforlemmy.blockedinstances.BlockedInstanceData;
import eu.toldi.infinityforlemmy.blockeduser.BlockedUserDao;
import eu.toldi.infinityforlemmy.blockeduser.BlockedUserData;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterDao;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsage;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsageDao;
import eu.toldi.infinityforlemmy.customtheme.CustomTheme;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeDao;
import eu.toldi.infinityforlemmy.multireddit.AnonymousMultiredditSubreddit;
@@ -42,7 +48,8 @@ import eu.toldi.infinityforlemmy.user.UserData;
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class,
SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class,
ReadPost.class, PostFilter.class, PostFilterUsage.class, AnonymousMultiredditSubreddit.class, BlockedUserData.class, BlockedCommunityData.class}, version = 27)
ReadPost.class, PostFilter.class, PostFilterUsage.class, AnonymousMultiredditSubreddit.class,
BlockedUserData.class, BlockedCommunityData.class, BlockedInstanceData.class, CommentFilter.class, CommentFilterUsage.class}, version = 30)
public abstract class RedditDataRoomDatabase extends RoomDatabase {
public static RedditDataRoomDatabase create(final Context context) {
@@ -53,7 +60,9 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13,
MIGRATION_13_14, MIGRATION_14_15, MIGRATION_15_16, MIGRATION_16_17,
MIGRATION_17_18, MIGRATION_18_19, MIGRATION_19_20, MIGRATION_20_21,
MIGRATION_21_22, MIGRATION_22_23, MIGRATION_23_24, MIGRATION_24_25, MIGRATION_25_26, MIGRATION_26_27)
MIGRATION_21_22, MIGRATION_22_23, MIGRATION_23_24, MIGRATION_24_25,
MIGRATION_25_26, MIGRATION_26_27, MIGRATION_27_28, MIGRATION_28_29,
MIGRATION_29_30)
.build();
}
@@ -67,6 +76,8 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
public abstract BlockedCommunityDao blockedCommunityDao();
public abstract BlockedInstanceDao blockedInstanceDao();
public abstract UserDao userDao();
public abstract SubscribedUserDao subscribedUserDao();
@@ -85,6 +96,10 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
public abstract AnonymousMultiredditSubredditDao anonymousMultiredditSubredditDao();
public abstract CommentFilterDao commentFilterDao();
public abstract CommentFilterUsageDao commentFilterUsageDao();
private static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase database) {
@@ -424,4 +439,35 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
+ " ADD COLUMN is_favorite INTEGER DEFAULT 0 NOT NULL");
}
};
private static final Migration MIGRATION_27_28 = new Migration(27, 28) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE custom_themes ADD COLUMN filled_card_view_background_color INTEGER DEFAULT " + Color.parseColor("#E6F4FF") + " NOT NULL");
database.execSQL("ALTER TABLE custom_themes ADD COLUMN read_post_filled_card_view_background_color INTEGER DEFAULT " + Color.parseColor("#F5F5F5") + " NOT NULL");
database.execSQL("CREATE TABLE comment_filter " +
"(name TEXT NOT NULL PRIMARY KEY, max_vote INTEGER NOT NULL, min_vote INTEGER NOT NULL, exclude_strings TEXT, exclude_users TEXT)");
database.execSQL("CREATE TABLE comment_filter_usage (name TEXT NOT NULL, usage INTEGER NOT NULL, " +
"name_of_usage TEXT NOT NULL, PRIMARY KEY(name, usage, name_of_usage), FOREIGN KEY(name) REFERENCES comment_filter(name) ON DELETE CASCADE)");
}
};
private static final Migration MIGRATION_28_29 = new Migration(28, 29) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE blocked_instances" +
"(domain TEXT, id INTEGER NOT NULL, account_name TEXT NOT NULL, PRIMARY KEY( id, account_name))");
}
};
private static final Migration MIGRATION_29_30 = new Migration(29, 30) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
// Alter table "blocked_instances" to add new columns "instance_name" and "icon"
database.execSQL("ALTER TABLE blocked_instances ADD COLUMN instance_name TEXT");
database.execSQL("ALTER TABLE blocked_instances ADD COLUMN icon TEXT");
}
};
}

View File

@@ -14,7 +14,6 @@ import java.util.Map;
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.Response;
import retrofit2.Call;
@@ -22,6 +21,8 @@ import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;
public class RedgifsAccessTokenAuthenticator implements Interceptor {
private static final String REDGIFS_HOST = "redgifs.com";
private SharedPreferences mCurrentAccountSharedPreferences;
public RedgifsAccessTokenAuthenticator(SharedPreferences currentAccountSharedPreferences) {
@@ -60,7 +61,17 @@ public class RedgifsAccessTokenAuthenticator implements Interceptor {
@NonNull
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
Response response = chain.proceed(chain.request());
if (!chain.request().url().host().endsWith(REDGIFS_HOST)) {
return chain.proceed(chain.request());
}
String currentAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "");
Response response = chain.proceed(
chain.request().newBuilder()
.addHeader(APIUtils.AUTHORIZATION_KEY, APIUtils.AUTHORIZATION_BASE + currentAccessToken)
.build()
);
if (response.code() == 401 || response.code() == 400) {
String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY);
if (accessTokenHeader == null) {
@@ -74,13 +85,21 @@ public class RedgifsAccessTokenAuthenticator implements Interceptor {
String newAccessToken = refreshAccessToken();
if (!newAccessToken.equals("")) {
response.close();
return chain.proceed(response.request().newBuilder().headers(Headers.of(APIUtils.getRedgifsOAuthHeader(newAccessToken))).build());
return chain.proceed(
chain.request().newBuilder()
.addHeader(APIUtils.AUTHORIZATION_KEY, APIUtils.AUTHORIZATION_BASE + newAccessToken)
.build()
);
} else {
return response;
}
} else {
response.close();
return chain.proceed(response.request().newBuilder().headers(Headers.of(APIUtils.getRedgifsOAuthHeader(accessTokenFromSharedPreferences))).build());
return chain.proceed(
chain.request().newBuilder()
.addHeader(APIUtils.AUTHORIZATION_KEY, APIUtils.AUTHORIZATION_BASE + accessTokenFromSharedPreferences)
.build()
);
}
}
}

View File

@@ -1,7 +1,10 @@
package eu.toldi.infinityforlemmy;
import android.util.Log;
import eu.toldi.infinityforlemmy.network.SortTypeConverterFactory;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.guava.GuavaCallAdapterFactory;
@@ -12,8 +15,14 @@ public class RetrofitHolder {
private Retrofit retrofit;
private OkHttpClient okHttpClient;
private OkHttpClient okHttpClientBase;
private String baseURL = APIUtils.API_BASE_URI;
private String accessToken = null;
private Interceptor oAuthInterceptor;
public Retrofit getRetrofit() {
return retrofit;
}
@@ -33,6 +42,7 @@ public class RetrofitHolder {
public RetrofitHolder(OkHttpClient okHttpClient) {
this.okHttpClient = okHttpClient;
this.okHttpClientBase = okHttpClient;
this.retrofit = createRetrofit(okHttpClient, APIUtils.API_BASE_URI);
}
@@ -46,4 +56,18 @@ public class RetrofitHolder {
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
OkHttpClient.Builder builder = okHttpClientBase.newBuilder();
Log.d("RetrofitHolder", "Access token changed");
if (accessToken != null && !accessToken.equals("")) {
Log.i("RetrofitHolder", "Setting access token interceptor");
oAuthInterceptor = APIUtils.getOAuthInterceptor(accessToken);
builder.addInterceptor(oAuthInterceptor);
}
okHttpClient = builder.build();
retrofit = createRetrofit(okHttpClient, baseURL);
}
}

View File

@@ -35,8 +35,8 @@ public class SortType {
NEW("New", "New"),
OLD("Old", "Old"),
TOP("Top", "Top"),
MOST_COMMENTS("MostCommentes", "Most Commentes"),
NEW_COMMENTS("NewCommentes", "New Commentes"),
MOST_COMMENTS("MostComments", "Most Comments"),
NEW_COMMENTS("NewComments", "New Comments"),
TOP_HOUR("TopHour", "Top"),
TOP_SIX_HOURS("TopSixHour", "Top"),
@@ -48,7 +48,10 @@ public class SortType {
TOP_SIX_MONTHS("TopSixMonths", "Top"),
TOP_NINE_MONTHS("TopNineMonths", "Top"),
TOP_YEAR("TopYear", "Top"),
TOP_ALL("TopAll", "Top");
TOP_ALL("TopAll", "Top"),
SCALED("Scaled", "Scaled"),
CONTROVERSIAL("Controversial", "Controversial");
public final String value;
public final String fullName;
@@ -69,15 +72,15 @@ public class SortType {
}
public enum Time {
HOUR("TopHour", "Top Hour"),
SIX_HOURS("TopSixHour", "Top Six Hours"),
TWELVE_HOURS("TopTwelveHour", "Top Twelve Hours"),
HOUR("hour", "Hour"),
SIX_HOURS("SixHour", "Six Hours"),
TWELVE_HOURS("TwelveHour", "Twelve Hours"),
DAY("day", "Day"),
WEEK("week", "Week"),
MONTH("month", "Month"),
THREE_MONTHS("TopThreeMonth", "Top Three Months"),
SIX_MONTHS("TopSixMonth", "Top Six Months"),
NINE_MONTHS("TopNineMonth", "Top Nine Months"),
THREE_MONTHS("ThreeMonths", "Three Months"),
SIX_MONTHS("SixMonths", "Six Months"),
NINE_MONTHS("NineMonths", "Nine Months"),
YEAR("year", "Year"),
ALL("all", "All Time");
@@ -88,5 +91,14 @@ public class SortType {
this.value = value;
this.fullName = fullName;
}
public static Time fromValue(String value) {
for (Time time : values()) {
if (time.value.equalsIgnoreCase(value)) {
return time;
}
}
return null;
}
}
}

View File

@@ -9,6 +9,7 @@ import java.util.List;
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityData;
import eu.toldi.infinityforlemmy.blockedinstances.BlockedInstanceData;
import eu.toldi.infinityforlemmy.blockeduser.BlockedUserData;
import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData;
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
@@ -31,10 +32,13 @@ public class FetchBlockedThings {
if (siteInfo != null) {
List<BlockedUserData> blockedUsers = new ArrayList<>();
List<BlockedCommunityData> blockedCommunities = new ArrayList<>();
List<BlockedInstanceData> blockedInstances = new ArrayList<>();
try {
JSONObject siteInfoJson = new JSONObject(siteInfo).getJSONObject("my_user");
JSONArray blockedUsersJson = (siteInfoJson.has("person_blocks")) ? siteInfoJson.getJSONArray("person_blocks") : null;
JSONArray blockedCommunitiesJson = (siteInfoJson.has("community_blocks")) ? siteInfoJson.getJSONArray("community_blocks") : null;
JSONArray blockedInstancesJson = (siteInfoJson.has("instance_blocks")) ? siteInfoJson.getJSONArray("instance_blocks") : null;
if (blockedUsersJson != null) {
for (int i = 0; i < blockedUsersJson.length(); i++) {
JSONObject blockedUserJson = blockedUsersJson.getJSONObject(i).getJSONObject("target");
@@ -57,7 +61,29 @@ public class FetchBlockedThings {
blockedCommunities.add(new BlockedCommunityData(blockedCommunityData, accountName));
}
}
fetchBlockedThingsListener.onFetchBlockedThingsSuccess(blockedUsers, blockedCommunities);
if (blockedInstancesJson != null) {
for (int i = 0; i < blockedInstancesJson.length(); i++) {
JSONObject blockedInstanceJson = blockedInstancesJson.getJSONObject(i);
// Get the "instance" object if it exists
JSONObject instanceJson = blockedInstanceJson.has("instance") ? blockedInstanceJson.getJSONObject("instance") : null;
if (instanceJson == null) {
continue;
}
int id = instanceJson.getInt("id");
String domain = instanceJson.getString("domain");
JSONObject siteJson = blockedInstanceJson.has("site") ? blockedInstanceJson.getJSONObject("site") : null;
if (siteJson == null) {
blockedInstances.add(new BlockedInstanceData(id, domain, null, null, accountName));
continue;
}
String name = siteJson.getString("name");
String icon = siteJson.optString("icon");
blockedInstances.add(new BlockedInstanceData(id, domain, name, icon, accountName));
}
}
fetchBlockedThingsListener.onFetchBlockedThingsSuccess(blockedUsers, blockedCommunities, blockedInstances);
} catch (JSONException e) {
e.printStackTrace();
fetchBlockedThingsListener.onFetchBlockedThingsFailure();
@@ -78,7 +104,7 @@ public class FetchBlockedThings {
}
public interface FetchBlockedThingsListener {
void onFetchBlockedThingsSuccess(List<BlockedUserData> blockedUsers, List<BlockedCommunityData> blockedCommunities);
void onFetchBlockedThingsSuccess(List<BlockedUserData> blockedUsers, List<BlockedCommunityData> blockedCommunities, List<BlockedInstanceData> blockedInstances);
void onFetchBlockedThingsFailure();
}

View File

@@ -283,17 +283,17 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
PostFragment fragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER);
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountQualifiedName);
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SAVED);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
bundle.putBoolean(PostFragment.EXTRA_DISABLE_READ_POSTS, true);
fragment.setArguments(bundle);
return fragment;
}
CommentsListingFragment fragment = new CommentsListingFragment();
Bundle bundle = new Bundle();
bundle.putString(CommentsListingFragment.EXTRA_USERNAME, mAccountName);
bundle.putString(CommentsListingFragment.EXTRA_USERNAME, mAccountQualifiedName);
bundle.putString(CommentsListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(CommentsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putBoolean(CommentsListingFragment.EXTRA_ARE_SAVED_COMMENTS, true);

View File

@@ -42,6 +42,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.shape.CornerFamily;
import com.google.android.material.shape.MaterialShapeDrawable;
import com.google.android.material.shape.ShapeAppearanceModel;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;
import java.lang.reflect.Field;
@@ -321,6 +322,12 @@ public abstract class BaseActivity extends AppCompatActivity implements CustomFo
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar, true);
}
protected Snackbar applySnackBarTheme(Snackbar snackbar) {
snackbar.setBackgroundTint(customThemeWrapper.getBackgroundColor());
snackbar.setTextColor(customThemeWrapper.getSecondaryTextColor());
return snackbar;
}
protected void applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(AppBarLayout appBarLayout, @Nullable CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar, boolean setToolbarBackgroundColor) {
appBarLayout.setBackgroundColor(customThemeWrapper.getColorPrimary());
if (collapsingToolbarLayout != null) {

View File

@@ -1,7 +1,6 @@
package eu.toldi.infinityforlemmy.activities;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
@@ -24,7 +23,6 @@ import androidx.core.view.inputmethod.EditorInfoCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
@@ -51,6 +49,7 @@ import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.account.FetchBlockedThings;
import eu.toldi.infinityforlemmy.asynctasks.InsertBlockedThings;
import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityData;
import eu.toldi.infinityforlemmy.blockedinstances.BlockedInstanceData;
import eu.toldi.infinityforlemmy.blockeduser.BlockedUserData;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.ViewPagerBugFixed;
@@ -58,6 +57,7 @@ import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.events.GoBackToMainPageEvent;
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
import eu.toldi.infinityforlemmy.fragments.BlockedCommunitiesListingFragment;
import eu.toldi.infinityforlemmy.fragments.BlockedInstancesListingFragment;
import eu.toldi.infinityforlemmy.fragments.BlockedUsersListingFragment;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
@@ -110,8 +110,6 @@ public class BlockedThingListingActivity extends BaseActivity implements Activit
private String mAccountQualifiedName;
private boolean mInsertSuccess = false;
private boolean mInsertMultiredditSuccess = false;
private boolean showMultiReddits = false;
private SectionsPagerAdapter sectionsPagerAdapter;
private Menu mMenu;
@@ -167,9 +165,6 @@ public class BlockedThingListingActivity extends BaseActivity implements Activit
if (savedInstanceState != null) {
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
mInsertMultiredditSuccess = savedInstanceState.getBoolean(INSERT_MULTIREDDIT_STATE);
} else {
showMultiReddits = getIntent().getBooleanExtra(EXTRA_SHOW_MULTIREDDITS, false);
}
if (mAccessToken == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@@ -216,37 +211,12 @@ public class BlockedThingListingActivity extends BaseActivity implements Activit
}
private void initializeViewPagerAndLoadSubscriptions() {
fab.setOnClickListener(view -> {
Intent intent = new Intent(this, CreateMultiRedditActivity.class);
startActivity(intent);
});
fab.hide();
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOffscreenPageLimit(2);
if (viewPager.getCurrentItem() != 2) {
fab.hide();
}
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
if (position == 0) {
unlockSwipeRightToGoBack();
fab.hide();
} else {
lockSwipeRightToGoBack();
if (position != 2) {
fab.hide();
} else {
fab.show();
}
}
}
});
tabLayout.setupWithViewPager(viewPager);
if (showMultiReddits) {
viewPager.setCurrentItem(2, false);
}
tabLayout.setupWithViewPager(viewPager);
loadBlocks(false);
}
@@ -303,7 +273,6 @@ public class BlockedThingListingActivity extends BaseActivity implements Activit
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess);
outState.putBoolean(INSERT_MULTIREDDIT_STATE, mInsertMultiredditSuccess);
}
@Override
@@ -316,9 +285,9 @@ public class BlockedThingListingActivity extends BaseActivity implements Activit
if (mAccessToken != null && !(!forceLoad && mInsertSuccess)) {
FetchBlockedThings.fetchBlockedThings(mRetrofit.getRetrofit(), mAccessToken, mAccountQualifiedName, new FetchBlockedThings.FetchBlockedThingsListener() {
@Override
public void onFetchBlockedThingsSuccess(List<BlockedUserData> blockedUsers, List<BlockedCommunityData> blockedCommunities) {
public void onFetchBlockedThingsSuccess(List<BlockedUserData> blockedUsers, List<BlockedCommunityData> blockedCommunities, List<BlockedInstanceData> blockedInstances) {
InsertBlockedThings.insertBlockedThings(mExecutor, new Handler(), mRedditDataRoomDatabase, mAccountQualifiedName,
blockedCommunities, blockedUsers, () -> {
blockedCommunities, blockedUsers, blockedInstances, () -> {
mInsertSuccess = true;
sectionsPagerAdapter.stopRefreshProgressbar();
});
@@ -396,12 +365,20 @@ public class BlockedThingListingActivity extends BaseActivity implements Activit
fragment.setArguments(bundle);
return fragment;
}
case 2: {
BlockedInstancesListingFragment fragment = new BlockedInstancesListingFragment();
Bundle bundle = new Bundle();
bundle.putString(BlockedInstancesListingFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
bundle.putString(BlockedInstancesListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
fragment.setArguments(bundle);
return fragment;
}
}
}
@Override
public int getCount() {
return 2;
return 3;
}
@Override
@@ -412,7 +389,7 @@ public class BlockedThingListingActivity extends BaseActivity implements Activit
case 1:
return Utils.getTabTextWithCustomFont(typeface, getString(R.string.users));
case 2:
return Utils.getTabTextWithCustomFont(typeface, getString(R.string.multi_reddits));
return Utils.getTabTextWithCustomFont(typeface, getString(R.string.instances));
}
return null;

View File

@@ -170,6 +170,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
String parentBodyMarkdown = intent.getStringExtra(EXTRA_COMMENT_PARENT_BODY_MARKDOWN_KEY);
String parentBody = intent.getStringExtra(EXTRA_COMMENT_PARENT_BODY_KEY);
mGlide = Glide.with(getApplication());
if (parentBodyMarkdown != null && !parentBodyMarkdown.equals("")) {
binding.commentContentMarkdownView.setVisibility(View.VISIBLE);
binding.commentContentMarkdownView.setNestedScrollingEnabled(false);
@@ -204,8 +205,9 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
builder.linkColor(linkColor);
}
};
Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(this,
miscPlugin, parentTextColor, parentSpoilerBackgroundColor, null);
miscPlugin, parentTextColor, parentSpoilerBackgroundColor, mGlide, null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter();
binding.commentContentMarkdownView.setLayoutManager(new LinearLayoutManagerBugFixed(this));
binding.commentContentMarkdownView.setAdapter(markwonAdapter);
@@ -226,8 +228,6 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
setSupportActionBar(binding.commentToolbar);
mGlide = Glide.with(getApplication());
if (savedInstanceState != null) {
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
uploadedImages = savedInstanceState.getParcelableArrayList(UPLOADED_IMAGES_STATE);

View File

@@ -0,0 +1,126 @@
package eu.toldi.infinityforlemmy.activities;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelProvider;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.adapters.CommentFilterWithUsageRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.bottomsheetfragments.CommentFilterOptionsBottomSheetFragment;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.commentfilter.DeleteCommentFilter;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.databinding.ActivityCommentFilterPreferenceBinding;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterWithUsageViewModel;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
public class CommentFilterPreferenceActivity extends BaseActivity {
private ActivityCommentFilterPreferenceBinding binding;
@Inject
@Named("default")
SharedPreferences sharedPreferences;
@Inject
RedditDataRoomDatabase redditDataRoomDatabase;
@Inject
CustomThemeWrapper customThemeWrapper;
@Inject
Executor executor;
public CommentFilterWithUsageViewModel commentFilterWithUsageViewModel;
private CommentFilterWithUsageRecyclerViewAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this);
setImmersiveModeNotApplicable();
super.onCreate(savedInstanceState);
binding = ActivityCommentFilterPreferenceBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
ButterKnife.bind(this);
applyCustomTheme();
setSupportActionBar(binding.toolbarCommentFilterPreferenceActivity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
binding.fabCommentFilterPreferenceActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, CustomizeCommentFilterActivity.class);
intent.putExtra(CustomizeCommentFilterActivity.EXTRA_FROM_SETTINGS, true);
startActivity(intent);
});
adapter = new CommentFilterWithUsageRecyclerViewAdapter(this, commentFilter -> {
CommentFilterOptionsBottomSheetFragment commentFilterOptionsBottomSheetFragment = new CommentFilterOptionsBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(CommentFilterOptionsBottomSheetFragment.EXTRA_POST_FILTER, commentFilter);
commentFilterOptionsBottomSheetFragment.setArguments(bundle);
commentFilterOptionsBottomSheetFragment.show(getSupportFragmentManager(), commentFilterOptionsBottomSheetFragment.getTag());
});
binding.recyclerViewCommentFilterPreferenceActivity.setAdapter(adapter);
commentFilterWithUsageViewModel = new ViewModelProvider(this,
new CommentFilterWithUsageViewModel.Factory(redditDataRoomDatabase)).get(CommentFilterWithUsageViewModel.class);
commentFilterWithUsageViewModel.getCommentFilterWithUsageListLiveData().observe(this, commentFilterWithUsages -> adapter.setCommentFilterWithUsageList(commentFilterWithUsages));
}
public void editCommentFilter(CommentFilter commentFilter) {
Intent intent = new Intent(this, CustomizeCommentFilterActivity.class);
intent.putExtra(CustomizeCommentFilterActivity.EXTRA_COMMENT_FILTER, commentFilter);
intent.putExtra(CustomizeCommentFilterActivity.EXTRA_FROM_SETTINGS, true);
startActivity(intent);
}
public void applyCommentFilterTo(CommentFilter commentFilter) {
Intent intent = new Intent(this, CommentFilterUsageListingActivity.class);
intent.putExtra(CommentFilterUsageListingActivity.EXTRA_COMMENT_FILTER, commentFilter);
startActivity(intent);
}
public void deleteCommentFilter(CommentFilter commentFilter) {
DeleteCommentFilter.deleteCommentFilter(redditDataRoomDatabase, executor, commentFilter);
}
@Override
protected SharedPreferences getDefaultSharedPreferences() {
return sharedPreferences;
}
@Override
protected CustomThemeWrapper getCustomThemeWrapper() {
return customThemeWrapper;
}
@Override
protected void applyCustomTheme() {
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutCommentFilterPreferenceActivity, binding.collapsingToolbarLayoutCommentFilterPreferenceActivity, binding.toolbarCommentFilterPreferenceActivity);
applyFABTheme(binding.fabCommentFilterPreferenceActivity, sharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
binding.getRoot().setBackgroundColor(customThemeWrapper.getBackgroundColor());
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return false;
}
}

View File

@@ -0,0 +1,181 @@
package eu.toldi.infinityforlemmy.activities;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.bottomsheetfragments.CommentFilterUsageOptionsBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.NewCommentFilterUsageBottomSheetFragment;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsage;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsageViewModel;
import eu.toldi.infinityforlemmy.commentfilter.DeleteCommentFilterUsage;
import eu.toldi.infinityforlemmy.commentfilter.SaveCommentFilterUsage;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.databinding.ActivityCommentFilterUsageListingBinding;
import eu.toldi.infinityforlemmy.adapters.CommentFilterUsageRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
public class CommentFilterUsageListingActivity extends BaseActivity {
public static final String EXTRA_COMMENT_FILTER = "ECF";
@Inject
@Named("default")
SharedPreferences sharedPreferences;
@Inject
RedditDataRoomDatabase redditDataRoomDatabase;
@Inject
CustomThemeWrapper customThemeWrapper;
@Inject
Executor executor;
private ActivityCommentFilterUsageListingBinding binding;
public CommentFilterUsageViewModel commentFilterUsageViewModel;
private CommentFilterUsageRecyclerViewAdapter adapter;
private CommentFilter commentFilter;
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this);
setImmersiveModeNotApplicable();
super.onCreate(savedInstanceState);
binding = ActivityCommentFilterUsageListingBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
applyCustomTheme();
setSupportActionBar(binding.toolbarCommentFilterUsageListingActivity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
commentFilter = getIntent().getParcelableExtra(EXTRA_COMMENT_FILTER);
setTitle(commentFilter.name);
binding.fabCommentFilterUsageListingActivity.setOnClickListener(view -> {
NewCommentFilterUsageBottomSheetFragment newCommentFilterUsageBottomSheetFragment = new NewCommentFilterUsageBottomSheetFragment();
newCommentFilterUsageBottomSheetFragment.show(getSupportFragmentManager(), newCommentFilterUsageBottomSheetFragment.getTag());
});
adapter = new CommentFilterUsageRecyclerViewAdapter(this, customThemeWrapper, commentFilterUsage -> {
CommentFilterUsageOptionsBottomSheetFragment commentFilterUsageOptionsBottomSheetFragment = new CommentFilterUsageOptionsBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(CommentFilterUsageOptionsBottomSheetFragment.EXTRA_COMMENT_FILTER_USAGE, commentFilterUsage);
commentFilterUsageOptionsBottomSheetFragment.setArguments(bundle);
commentFilterUsageOptionsBottomSheetFragment.show(getSupportFragmentManager(), commentFilterUsageOptionsBottomSheetFragment.getTag());
});
binding.recyclerViewCommentFilterUsageListingActivity.setAdapter(adapter);
commentFilterUsageViewModel = new ViewModelProvider(this,
new CommentFilterUsageViewModel.Factory(redditDataRoomDatabase, commentFilter.name)).get(CommentFilterUsageViewModel.class);
commentFilterUsageViewModel.getCommentFilterUsageListLiveData().observe(this, commentFilterUsages -> adapter.setCommentFilterUsages(commentFilterUsages));
}
public void newCommentFilterUsage(int type) {
switch (type) {
case CommentFilterUsage.SUBREDDIT_TYPE:
editAndCommentFilterUsageNameOfUsage(type, null);
break;
}
}
private void editAndCommentFilterUsageNameOfUsage(int type, String nameOfUsage) {
View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit_post_or_comment_filter_name_of_usage, null);
TextView messageTextView = dialogView.findViewById(R.id.message_text_view_edit_post_or_comment_filter_name_of_usage_dialog);
messageTextView.setVisibility(View.GONE);
TextInputLayout textInputLayout = dialogView.findViewById(R.id.text_input_layout_edit_post_or_comment_filter_name_of_usage_dialog);
TextInputEditText textInputEditText = dialogView.findViewById(R.id.text_input_edit_text_edit_post_or_comment_filter_name_of_usage_dialog);
int primaryTextColor = customThemeWrapper.getPrimaryTextColor();
textInputLayout.setBoxStrokeColor(primaryTextColor);
textInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
textInputEditText.setTextColor(primaryTextColor);
if (nameOfUsage != null) {
textInputEditText.setText(nameOfUsage);
}
textInputEditText.requestFocus();
int titleStringId = R.string.community;
switch (type) {
case CommentFilterUsage.SUBREDDIT_TYPE:
textInputEditText.setHint(R.string.settings_tab_community_name);
break;
}
Utils.showKeyboard(this, new Handler(), textInputEditText);
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(titleStringId)
.setView(dialogView)
.setPositiveButton(R.string.ok, (editTextDialogInterface, i1)
-> {
Utils.hideKeyboard(this);
CommentFilterUsage commentFilterUsage;
if (!textInputEditText.getText().toString().equals("")) {
commentFilterUsage = new CommentFilterUsage(commentFilter.name, type, textInputEditText.getText().toString());
SaveCommentFilterUsage.saveCommentFilterUsage(redditDataRoomDatabase, executor, commentFilterUsage);
}
})
.setNegativeButton(R.string.cancel, null)
.setOnDismissListener(editTextDialogInterface -> {
Utils.hideKeyboard(this);
})
.show();
}
public void editCommentFilterUsage(CommentFilterUsage commentFilterUsage) {
editAndCommentFilterUsageNameOfUsage(commentFilterUsage.usage, commentFilterUsage.nameOfUsage);
}
public void deleteCommentFilterUsage(CommentFilterUsage commentFilterUsage) {
DeleteCommentFilterUsage.deleteCommentFilterUsage(redditDataRoomDatabase, executor, commentFilterUsage);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return false;
}
@Override
protected SharedPreferences getDefaultSharedPreferences() {
return sharedPreferences;
}
@Override
protected CustomThemeWrapper getCustomThemeWrapper() {
return customThemeWrapper;
}
@Override
protected void applyCustomTheme() {
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutCommentFilterUsageListingActivity, binding.collapsingToolbarLayoutCommentFilterUsageListingActivity, binding.toolbarCommentFilterUsageListingActivity);
applyFABTheme(binding.fabCommentFilterUsageListingActivity, sharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
binding.getRoot().setBackgroundColor(customThemeWrapper.getBackgroundColor());
}
}

View File

@@ -34,13 +34,13 @@ import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.multireddit.CreateMultiReddit;
import eu.toldi.infinityforlemmy.multireddit.MultiRedditJSONModel;
import eu.toldi.infinityforlemmy.subreddit.SubredditWithSelection;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import retrofit2.Retrofit;
public class CreateMultiRedditActivity extends BaseActivity {
@@ -71,8 +71,8 @@ public class CreateMultiRedditActivity extends BaseActivity {
@BindView(R.id.select_subreddit_text_view_create_multi_reddit_activity)
TextView selectSubredditTextView;
@Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Named("no_oauth")
RetrofitHolder mRetrofit;
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
@@ -87,14 +87,14 @@ public class CreateMultiRedditActivity extends BaseActivity {
Executor mExecutor;
private String mAccessToken;
private String mAccountName;
private ArrayList<String> mSubreddits;
private ArrayList<SubredditWithSelection> mSubreddits;
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this);
setImmersiveModeNotApplicable();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_multi_reddit);
@@ -114,10 +114,10 @@ public class CreateMultiRedditActivity extends BaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-");
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, "-");
visibilityLinearLayout.setVisibility(View.GONE);
if (mAccessToken == null) {
visibilityLinearLayout.setVisibility(View.GONE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
nameEditText.setImeOptions(nameEditText.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING);
descriptionEditText.setImeOptions(descriptionEditText.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING);
@@ -125,7 +125,7 @@ public class CreateMultiRedditActivity extends BaseActivity {
}
if (savedInstanceState != null) {
mSubreddits = savedInstanceState.getStringArrayList(SELECTED_SUBREDDITS_STATE);
mSubreddits = savedInstanceState.getParcelableArrayList(SELECTED_SUBREDDITS_STATE);
} else {
mSubreddits = new ArrayList<>();
}
@@ -135,7 +135,7 @@ public class CreateMultiRedditActivity extends BaseActivity {
private void bindView() {
selectSubredditTextView.setOnClickListener(view -> {
Intent intent = new Intent(CreateMultiRedditActivity.this, SelectedSubredditsAndUsersActivity.class);
intent.putStringArrayListExtra(SelectedSubredditsAndUsersActivity.EXTRA_SELECTED_SUBREDDITS, mSubreddits);
intent.putParcelableArrayListExtra(SelectedSubredditsAndUsersActivity.EXTRA_SELECTED_SUBREDDITS, mSubreddits);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});
}
@@ -159,42 +159,29 @@ public class CreateMultiRedditActivity extends BaseActivity {
return true;
}
if (mAccessToken != null) {
String jsonModel = new MultiRedditJSONModel(nameEditText.getText().toString(), descriptionEditText.getText().toString(),
visibilitySwitch.isChecked(), mSubreddits).createJSONModel();
CreateMultiReddit.createMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
"/user/" + mAccountName + "/m/" + nameEditText.getText().toString(),
jsonModel, new CreateMultiReddit.CreateMultiRedditListener() {
@Override
public void success() {
finish();
}
@Override
public void failed(int errorCode) {
if (errorCode == 409) {
Snackbar.make(coordinatorLayout, R.string.duplicate_multi_reddit, Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(coordinatorLayout, R.string.create_multi_reddit_failed, Snackbar.LENGTH_SHORT).show();
}
}
});
} else {
CreateMultiReddit.anonymousCreateMultiReddit(mExecutor, new Handler(), mRedditDataRoomDatabase,
"/user/-/m/" + nameEditText.getText().toString(),
nameEditText.getText().toString(), descriptionEditText.getText().toString(),
mSubreddits, new CreateMultiReddit.CreateMultiRedditListener() {
@Override
public void success() {
finish();
}
@Override
public void failed(int errorType) {
//Will not be called
}
});
// Create a list of community qualified names seperated by a comma
StringBuilder subredditList = new StringBuilder();
String prefix = "";
for (SubredditWithSelection s : mSubreddits) {
subredditList.append(prefix);
prefix = ",";
subredditList.append(s.getQualifiedName());
}
CreateMultiReddit.anonymousCreateMultiReddit(mExecutor, new Handler(), mRedditDataRoomDatabase,
mAccountName, subredditList.toString(),
nameEditText.getText().toString(), descriptionEditText.getText().toString(),
mSubreddits, new CreateMultiReddit.CreateMultiRedditListener() {
@Override
public void success() {
finish();
}
@Override
public void failed(int errorType) {
//Will not be called
}
});
}
return false;
}
@@ -204,7 +191,7 @@ public class CreateMultiRedditActivity extends BaseActivity {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE && resultCode == RESULT_OK) {
if (data != null) {
mSubreddits = data.getStringArrayListExtra(
mSubreddits = data.getParcelableArrayListExtra(
SubredditMultiselectionActivity.EXTRA_RETURN_SELECTED_SUBREDDITS);
}
}
@@ -213,7 +200,7 @@ public class CreateMultiRedditActivity extends BaseActivity {
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putStringArrayList(SELECTED_SUBREDDITS_STATE, mSubreddits);
outState.putParcelableArrayList(SELECTED_SUBREDDITS_STATE, mSubreddits);
}
@Override

View File

@@ -0,0 +1,302 @@
package eu.toldi.infinityforlemmy.activities;
import android.app.Activity;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.concurrent.Executor;
import java.util.regex.PatternSyntaxException;
import javax.inject.Inject;
import javax.inject.Named;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.commentfilter.SaveCommentFilter;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.databinding.ActivityCustomizeCommentFilterBinding;
import eu.toldi.infinityforlemmy.utils.Utils;
public class CustomizeCommentFilterActivity extends BaseActivity {
public static final String EXTRA_COMMENT_FILTER = "ECF";
public static final String EXTRA_FROM_SETTINGS = "EFS";
public static final String RETURN_EXTRA_COMMENT_FILTER = "RECF";
private static final String COMMENT_FILTER_STATE = "CFS";
private static final String ORIGINAL_NAME_STATE = "ONS";
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
@Named("current_account")
SharedPreferences currentAccountSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
private CommentFilter commentFilter;
private boolean fromSettings;
private String originalName;
private ActivityCustomizeCommentFilterBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this);
setImmersiveModeNotApplicable();
super.onCreate(savedInstanceState);
binding = ActivityCustomizeCommentFilterBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
applyCustomTheme();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(binding.appbarLayoutCustomizeCommentFilterActivity);
}
setSupportActionBar(binding.toolbarCustomizeCommentFilterActivity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(binding.toolbarCustomizeCommentFilterActivity);
ActivityResultLauncher<Intent> requestAddUsersLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
Intent data = result.getData();
if (data == null) {
return;
}
ArrayList<String> usernames = data.getStringArrayListExtra(SearchActivity.RETURN_EXTRA_SELECTED_USERNAMES);
String currentUsers = binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.getText().toString().trim();
if (usernames != null && !usernames.isEmpty()) {
if (!currentUsers.isEmpty() && currentUsers.charAt(currentUsers.length() - 1) != ',') {
String newString = currentUsers + ",";
binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.setText(newString);
}
StringBuilder stringBuilder = new StringBuilder();
for (String s : usernames) {
stringBuilder.append(s).append(",");
}
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.append(stringBuilder.toString());
}
});
binding.addUsersImageViewCustomizeCommentFilterActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, SearchActivity.class);
intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_USERS, true);
intent.putExtra(SearchActivity.EXTRA_IS_MULTI_SELECTION, true);
requestAddUsersLauncher.launch(intent);
});
fromSettings = getIntent().getBooleanExtra(EXTRA_FROM_SETTINGS, false);
if (savedInstanceState != null) {
commentFilter = savedInstanceState.getParcelable(COMMENT_FILTER_STATE);
originalName = savedInstanceState.getString(ORIGINAL_NAME_STATE);
} else {
commentFilter = getIntent().getParcelableExtra(EXTRA_COMMENT_FILTER);
if (commentFilter == null) {
commentFilter = new CommentFilter();
originalName = "";
} else {
if (!fromSettings) {
originalName = "";
} else {
originalName = commentFilter.name;
}
}
bindView();
}
}
private void bindView() {
binding.nameTextInputEditTextCustomizeCommentFilterActivity.setText(commentFilter.name);
binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.setText(commentFilter.excludeStrings);
binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.setText(commentFilter.excludeUsers);
binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.setText(Integer.toString(commentFilter.minVote));
binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.setText(Integer.toString(commentFilter.maxVote));
}
@Override
protected SharedPreferences getDefaultSharedPreferences() {
return mSharedPreferences;
}
@Override
protected CustomThemeWrapper getCustomThemeWrapper() {
return mCustomThemeWrapper;
}
@Override
protected void applyCustomTheme() {
binding.getRoot().setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutCustomizeCommentFilterActivity, binding.collapsingToolbarLayoutCustomizeCommentFilterActivity, binding.toolbarCustomizeCommentFilterActivity);
int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
int primaryIconColor = mCustomThemeWrapper.getPrimaryIconColor();
Drawable cursorDrawable = Utils.getTintedDrawable(this, R.drawable.edit_text_cursor, primaryTextColor);
binding.nameTextInputLayoutCustomizeCommentFilterActivity.setBoxStrokeColor(primaryTextColor);
binding.nameTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
binding.nameTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
binding.excludeStringsTextInputLayoutCustomizeCommentFilterActivity.setBoxStrokeColor(primaryTextColor);
binding.excludeStringsTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
binding.excludeUsersTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
binding.addUsersImageViewCustomizeCommentFilterActivity.setImageDrawable(Utils.getTintedDrawable(this, R.drawable.ic_add_24dp, primaryIconColor));
binding.minVoteTextInputLayoutCustomizeCommentFilterActivity.setBoxStrokeColor(primaryTextColor);
binding.minVoteTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
binding.maxVoteTextInputLayoutCustomizeCommentFilterActivity.setBoxStrokeColor(primaryTextColor);
binding.maxVoteTextInputLayoutCustomizeCommentFilterActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.setTextColor(primaryTextColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
binding.nameTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.setTextCursorDrawable(cursorDrawable);
} else {
setCursorDrawableColor(binding.nameTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
setCursorDrawableColor(binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
setCursorDrawableColor(binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
setCursorDrawableColor(binding.minVoteTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
setCursorDrawableColor(binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity, primaryTextColor);
}
if (typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), typeface);
}
}
public void setCursorDrawableColor(EditText editText, int color) {
try {
Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
fCursorDrawableRes.setAccessible(true);
int mCursorDrawableRes = fCursorDrawableRes.getInt(editText);
Field fEditor = TextView.class.getDeclaredField("mEditor");
fEditor.setAccessible(true);
Object editor = fEditor.get(editText);
Class<?> clazz = editor.getClass();
Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
fCursorDrawable.setAccessible(true);
Drawable[] drawables = new Drawable[2];
drawables[0] = editText.getContext().getResources().getDrawable(mCursorDrawableRes);
drawables[1] = editText.getContext().getResources().getDrawable(mCursorDrawableRes);
drawables[0].setColorFilter(color, PorterDuff.Mode.SRC_IN);
drawables[1].setColorFilter(color, PorterDuff.Mode.SRC_IN);
fCursorDrawable.set(editor, drawables);
} catch (Throwable ignored) {
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.customize_comment_filter_activity, menu);
if (fromSettings) {
menu.findItem(R.id.action_save_customize_comment_filter_activity).setVisible(false);
}
applyMenuItemTheme(menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
} else if (item.getItemId() == R.id.action_save_customize_comment_filter_activity) {
try {
constructCommentFilter();
Intent returnIntent = new Intent();
returnIntent.putExtra(RETURN_EXTRA_COMMENT_FILTER, commentFilter);
setResult(Activity.RESULT_OK, returnIntent);
finish();
} catch (PatternSyntaxException e) {
Toast.makeText(this, R.string.invalid_regex, Toast.LENGTH_SHORT).show();
}
return true;
} else if (item.getItemId() == R.id.action_save_to_database_customize_comment_filter_activity) {
try {
constructCommentFilter();
if (!commentFilter.name.equals("")) {
saveCommentFilter(originalName);
} else {
Toast.makeText(CustomizeCommentFilterActivity.this, R.string.comment_filter_requires_a_name, Toast.LENGTH_LONG).show();
}
} catch (PatternSyntaxException e) {
Toast.makeText(this, R.string.invalid_regex, Toast.LENGTH_SHORT).show();
}
}
return false;
}
private void saveCommentFilter(String originalName) {
SaveCommentFilter.saveCommentFilter(mExecutor, new Handler(), mRedditDataRoomDatabase, commentFilter, originalName,
new SaveCommentFilter.SaveCommentFilterListener() {
@Override
public void success() {
Intent returnIntent = new Intent();
returnIntent.putExtra(RETURN_EXTRA_COMMENT_FILTER, commentFilter);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
@Override
public void duplicate() {
new MaterialAlertDialogBuilder(CustomizeCommentFilterActivity.this, R.style.MaterialAlertDialogTheme)
.setTitle(getString(R.string.duplicate_comment_filter_dialog_title, commentFilter.name))
.setMessage(R.string.duplicate_comment_filter_dialog_message)
.setPositiveButton(R.string.override, (dialogInterface, i) -> saveCommentFilter(commentFilter.name))
.setNegativeButton(R.string.cancel, null)
.show();
}
});
}
private void constructCommentFilter() throws PatternSyntaxException {
commentFilter.name = binding.nameTextInputEditTextCustomizeCommentFilterActivity.getText().toString();
commentFilter.excludeStrings = binding.excludeStringsTextInputEditTextCustomizeCommentFilterActivity.getText().toString();
commentFilter.excludeUsers = binding.excludeUsersTextInputEditTextCustomizeCommentFilterActivity.getText().toString();
commentFilter.maxVote = binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.getText() == null || binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.getText().toString().equals("") ? -1 : Integer.parseInt(binding.maxVoteTextInputEditTextCustomizeCommentFilterActivity.getText().toString());
commentFilter.minVote = binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.getText() == null || binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.getText().toString().equals("") ? -1 : Integer.parseInt(binding.minVoteTextInputEditTextCustomizeCommentFilterActivity.getText().toString());
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(COMMENT_FILTER_STATE, commentFilter);
outState.putString(ORIGINAL_NAME_STATE, originalName);
}
}

View File

@@ -157,14 +157,7 @@ public class CustomizePostFilterActivity extends BaseActivity {
TextInputEditText excludesUsersTextInputEditText;
@BindView(R.id.add_users_image_view_customize_post_filter_activity)
ImageView addUsersImageView;
@BindView(R.id.excludes_flairs_text_input_layout_customize_post_filter_activity)
TextInputLayout excludesFlairsTextInputLayout;
@BindView(R.id.excludes_flairs_text_input_edit_text_customize_post_filter_activity)
TextInputEditText excludesFlairsTextInputEditText;
@BindView(R.id.contains_flairs_text_input_layout_customize_post_filter_activity)
TextInputLayout containsFlairsTextInputLayout;
@BindView(R.id.contains_flairs_text_input_edit_text_customize_post_filter_activity)
TextInputEditText containsFlairsTextInputEditText;
@BindView(R.id.exclude_domains_text_input_layout_customize_post_filter_activity)
TextInputLayout excludeDomainsTextInputLayout;
@BindView(R.id.exclude_domains_text_input_edit_text_customize_post_filter_activity)
@@ -189,14 +182,7 @@ public class CustomizePostFilterActivity extends BaseActivity {
TextInputLayout maxCommentsTextInputLayout;
@BindView(R.id.max_comments_text_input_edit_text_customize_post_filter_activity)
TextInputEditText maxCommentsTextInputEditText;
@BindView(R.id.min_awards_text_input_layout_customize_post_filter_activity)
TextInputLayout minAwardsTextInputLayout;
@BindView(R.id.min_awards_text_input_edit_text_customize_post_filter_activity)
TextInputEditText minAwardsTextInputEditText;
@BindView(R.id.max_awards_text_input_layout_customize_post_filter_activity)
TextInputLayout maxAwardsTextInputLayout;
@BindView(R.id.max_awards_text_input_edit_text_customize_post_filter_activity)
TextInputEditText maxAwardsTextInputEditText;
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
@@ -226,10 +212,6 @@ public class CustomizePostFilterActivity extends BaseActivity {
applyCustomTheme();
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) {
Slidr.attach(this);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
@@ -327,16 +309,12 @@ public class CustomizePostFilterActivity extends BaseActivity {
titleContainsRegexTextInputEditText.setText(postFilter.postTitleContainsRegex);
excludesSubredditsTextInputEditText.setText(postFilter.excludeSubreddits);
excludesUsersTextInputEditText.setText(postFilter.excludeUsers);
excludesFlairsTextInputEditText.setText(postFilter.excludeFlairs);
containsFlairsTextInputEditText.setText(postFilter.containFlairs);
excludeDomainsTextInputEditText.setText(postFilter.excludeDomains);
containDomainsTextInputEditText.setText(postFilter.containDomains);
minVoteTextInputEditText.setText(Integer.toString(postFilter.minVote));
maxVoteTextInputEditText.setText(Integer.toString(postFilter.maxVote));
minCommentsTextInputEditText.setText(Integer.toString(postFilter.minComments));
maxCommentsTextInputEditText.setText(Integer.toString(postFilter.maxComments));
minAwardsTextInputEditText.setText(Integer.toString(postFilter.minAwards));
maxAwardsTextInputEditText.setText(Integer.toString(postFilter.maxAwards));
Intent intent = getIntent();
String excludeSubreddit = intent.getStringExtra(EXTRA_EXCLUDE_SUBREDDIT);
@@ -358,18 +336,6 @@ public class CustomizePostFilterActivity extends BaseActivity {
}
excludesUsersTextInputEditText.append(excludeUser);
}
if (excludeFlair != null && !excludeFlair.equals("")) {
if (!excludesFlairsTextInputEditText.getText().toString().equals("")) {
excludesFlairsTextInputEditText.append(",");
}
excludesFlairsTextInputEditText.append(excludeFlair);
}
if (containFlair != null && !containFlair.equals("")) {
if (!containsFlairsTextInputEditText.getText().toString().equals("")) {
containsFlairsTextInputEditText.append(",");
}
containsFlairsTextInputEditText.append(containFlair);
}
if (excludeDomain != null && !excludeDomain.equals("")) {
if (!excludeDomainsTextInputEditText.getText().toString().equals("")) {
excludeDomainsTextInputEditText.append(",");
@@ -432,12 +398,6 @@ public class CustomizePostFilterActivity extends BaseActivity {
excludesUsersTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
excludesUsersTextInputEditText.setTextColor(primaryTextColor);
addUsersImageView.setImageDrawable(Utils.getTintedDrawable(this, R.drawable.ic_add_24dp, primaryIconColor));
excludesFlairsTextInputLayout.setBoxStrokeColor(primaryTextColor);
excludesFlairsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
excludesFlairsTextInputEditText.setTextColor(primaryTextColor);
containsFlairsTextInputLayout.setBoxStrokeColor(primaryTextColor);
containsFlairsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
containsFlairsTextInputEditText.setTextColor(primaryTextColor);
excludeDomainsTextInputLayout.setBoxStrokeColor(primaryTextColor);
excludeDomainsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
excludeDomainsTextInputEditText.setTextColor(primaryTextColor);
@@ -456,13 +416,6 @@ public class CustomizePostFilterActivity extends BaseActivity {
maxCommentsTextInputLayout.setBoxStrokeColor(primaryTextColor);
maxCommentsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
maxCommentsTextInputEditText.setTextColor(primaryTextColor);
minAwardsTextInputLayout.setBoxStrokeColor(primaryTextColor);
minAwardsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
minAwardsTextInputEditText.setTextColor(primaryTextColor);
maxAwardsTextInputLayout.setBoxStrokeColor(primaryTextColor);
maxAwardsTextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
maxAwardsTextInputEditText.setTextColor(primaryTextColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
nameTextInputEditText.setTextCursorDrawable(cursorDrawable);
titleExcludesStringsTextInputEditText.setTextCursorDrawable(cursorDrawable);
@@ -471,16 +424,12 @@ public class CustomizePostFilterActivity extends BaseActivity {
titleContainsRegexTextInputEditText.setTextCursorDrawable(cursorDrawable);
excludesSubredditsTextInputEditText.setTextCursorDrawable(cursorDrawable);
excludesUsersTextInputEditText.setTextCursorDrawable(cursorDrawable);
excludesFlairsTextInputEditText.setTextCursorDrawable(cursorDrawable);
containsFlairsTextInputEditText.setTextCursorDrawable(cursorDrawable);
excludeDomainsTextInputEditText.setTextCursorDrawable(cursorDrawable);
containDomainsTextInputEditText.setTextCursorDrawable(cursorDrawable);
minVoteTextInputEditText.setTextCursorDrawable(cursorDrawable);
maxVoteTextInputEditText.setTextCursorDrawable(cursorDrawable);
minCommentsTextInputEditText.setTextCursorDrawable(cursorDrawable);
maxCommentsTextInputEditText.setTextCursorDrawable(cursorDrawable);
minAwardsTextInputEditText.setTextCursorDrawable(cursorDrawable);
maxAwardsTextInputEditText.setTextCursorDrawable(cursorDrawable);
} else {
setCursorDrawableColor(nameTextInputEditText, primaryTextColor);
setCursorDrawableColor(titleExcludesStringsTextInputEditText, primaryTextColor);
@@ -489,16 +438,12 @@ public class CustomizePostFilterActivity extends BaseActivity {
setCursorDrawableColor(titleContainsRegexTextInputEditText, primaryTextColor);
setCursorDrawableColor(excludesSubredditsTextInputEditText, primaryTextColor);
setCursorDrawableColor(excludesUsersTextInputEditText, primaryTextColor);
setCursorDrawableColor(excludesFlairsTextInputEditText, primaryTextColor);
setCursorDrawableColor(containsFlairsTextInputEditText, primaryTextColor);
setCursorDrawableColor(excludeDomainsTextInputEditText, primaryTextColor);
setCursorDrawableColor(containDomainsTextInputEditText, primaryTextColor);
setCursorDrawableColor(minVoteTextInputEditText, primaryTextColor);
setCursorDrawableColor(maxVoteTextInputEditText, primaryTextColor);
setCursorDrawableColor(minCommentsTextInputEditText, primaryTextColor);
setCursorDrawableColor(maxCommentsTextInputEditText, primaryTextColor);
setCursorDrawableColor(minAwardsTextInputEditText, primaryTextColor);
setCursorDrawableColor(maxAwardsTextInputEditText, primaryTextColor);
}
if (typeface != null) {
@@ -643,8 +588,6 @@ public class CustomizePostFilterActivity extends BaseActivity {
postFilter.minVote = minVoteTextInputEditText.getText() == null || minVoteTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(minVoteTextInputEditText.getText().toString());
postFilter.maxComments = maxCommentsTextInputEditText.getText() == null || maxCommentsTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(maxCommentsTextInputEditText.getText().toString());
postFilter.minComments = minCommentsTextInputEditText.getText() == null || minCommentsTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(minCommentsTextInputEditText.getText().toString());
postFilter.maxAwards = maxAwardsTextInputEditText.getText() == null || maxAwardsTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(maxAwardsTextInputEditText.getText().toString());
postFilter.minAwards = minAwardsTextInputEditText.getText() == null || minAwardsTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(minAwardsTextInputEditText.getText().toString());
postFilter.postTitleExcludesRegex = titleExcludesRegexTextInputEditText.getText().toString();
Pattern.compile(postFilter.postTitleExcludesRegex);
postFilter.postTitleContainsRegex = titleContainsRegexTextInputEditText.getText().toString();
@@ -653,8 +596,6 @@ public class CustomizePostFilterActivity extends BaseActivity {
postFilter.postTitleContainsStrings = titleContainsStringsTextInputEditText.getText().toString();
postFilter.excludeSubreddits = excludesSubredditsTextInputEditText.getText().toString();
postFilter.excludeUsers = excludesUsersTextInputEditText.getText().toString();
postFilter.excludeFlairs = excludesFlairsTextInputEditText.getText().toString();
postFilter.containFlairs = containsFlairsTextInputEditText.getText().toString();
postFilter.excludeDomains = excludeDomainsTextInputEditText.getText().toString();
postFilter.containDomains = containDomainsTextInputEditText.getText().toString();
postFilter.containTextType = postTypeTextCheckBox.isChecked();

View File

@@ -12,7 +12,6 @@ import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -25,6 +24,7 @@ import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.snackbar.Snackbar;
import java.util.ArrayList;
import java.util.concurrent.Executor;
import javax.inject.Inject;
@@ -40,7 +40,7 @@ import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.multireddit.EditMultiReddit;
import eu.toldi.infinityforlemmy.multireddit.FetchMultiRedditInfo;
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
import eu.toldi.infinityforlemmy.multireddit.MultiRedditJSONModel;
import eu.toldi.infinityforlemmy.subreddit.SubredditWithSelection;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import retrofit2.Retrofit;
@@ -70,12 +70,6 @@ public class EditMultiRedditActivity extends BaseActivity {
EditText descriptionEditText;
@BindView(R.id.divider_2_edit_multi_reddit_activity)
View divider2;
@BindView(R.id.visibility_wrapper_linear_layout_edit_multi_reddit_activity)
LinearLayout visibilityLinearLayout;
@BindView(R.id.visibility_text_view_edit_multi_reddit_activity)
TextView visibilityTextView;
@BindView(R.id.visibility_switch_edit_multi_reddit_activity)
Switch visibilitySwitch;
@BindView(R.id.select_subreddit_text_view_edit_multi_reddit_activity)
TextView selectSubredditTextView;
@Inject
@@ -123,10 +117,9 @@ public class EditMultiRedditActivity extends BaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-");
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, "-");
if (mAccessToken == null) {
visibilityLinearLayout.setVisibility(View.GONE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
nameEditText.setImeOptions(nameEditText.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING);
descriptionEditText.setImeOptions(descriptionEditText.getImeOptions() | EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING);
@@ -145,53 +138,44 @@ public class EditMultiRedditActivity extends BaseActivity {
private void bindView() {
if (multiReddit == null) {
if (mAccessToken == null) {
FetchMultiRedditInfo.anonymousFetchMultiRedditInfo(mExecutor, new Handler(),
mRedditDataRoomDatabase, multipath, new FetchMultiRedditInfo.FetchMultiRedditInfoListener() {
@Override
public void success(MultiReddit multiReddit) {
EditMultiRedditActivity.this.multiReddit = multiReddit;
progressBar.setVisibility(View.GONE);
linearLayout.setVisibility(View.VISIBLE);
nameEditText.setText(multiReddit.getDisplayName());
descriptionEditText.setText(multiReddit.getDescription());
}
@Override
public void failed() {
//Will not be called
}
});
} else {
FetchMultiRedditInfo.fetchMultiRedditInfo(mRetrofit, mAccessToken, multipath, new FetchMultiRedditInfo.FetchMultiRedditInfoListener() {
@Override
public void success(MultiReddit multiReddit) {
EditMultiRedditActivity.this.multiReddit = multiReddit;
progressBar.setVisibility(View.GONE);
linearLayout.setVisibility(View.VISIBLE);
nameEditText.setText(multiReddit.getDisplayName());
descriptionEditText.setText(multiReddit.getDescription());
visibilitySwitch.setChecked(!multiReddit.getVisibility().equals("public"));
}
FetchMultiRedditInfo.anonymousFetchMultiRedditInfo(mExecutor, new Handler(),
mRedditDataRoomDatabase, multipath, mAccountName, new FetchMultiRedditInfo.FetchMultiRedditInfoListener() {
@Override
public void success(MultiReddit multiReddit) {
EditMultiRedditActivity.this.multiReddit = multiReddit;
progressBar.setVisibility(View.GONE);
linearLayout.setVisibility(View.VISIBLE);
nameEditText.setText(multiReddit.getDisplayName());
descriptionEditText.setText(multiReddit.getDescription());
}
@Override
public void failed() {
//Will not be called
}
});
@Override
public void failed() {
Snackbar.make(coordinatorLayout, R.string.cannot_fetch_multireddit, Snackbar.LENGTH_SHORT).show();
}
});
}
} else {
progressBar.setVisibility(View.GONE);
linearLayout.setVisibility(View.VISIBLE);
nameEditText.setText(multiReddit.getDisplayName());
descriptionEditText.setText(multiReddit.getDescription());
visibilitySwitch.setChecked(!multiReddit.getVisibility().equals("public"));
}
selectSubredditTextView.setOnClickListener(view -> {
Intent intent = new Intent(EditMultiRedditActivity.this, SelectedSubredditsAndUsersActivity.class);
if (multiReddit.getSubreddits() != null) {
intent.putStringArrayListExtra(SelectedSubredditsAndUsersActivity.EXTRA_SELECTED_SUBREDDITS, multiReddit.getSubreddits());
if (multiReddit.getSubreddits().isEmpty() && !multiReddit.getPath().equals("")) {
String[] communities = multiReddit.getPath().split(",");
ArrayList<SubredditWithSelection> communitiesList = new ArrayList<>();
for (String community : communities) {
communitiesList.add(new SubredditWithSelection(community.substring(0, community.indexOf('@')), null, community));
}
intent.putParcelableArrayListExtra(SelectedSubredditsAndUsersActivity.EXTRA_SELECTED_SUBREDDITS, communitiesList);
} else {
intent.putParcelableArrayListExtra(SelectedSubredditsAndUsersActivity.EXTRA_SELECTED_SUBREDDITS, multiReddit.getSubreddits());
}
}
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});
@@ -216,39 +200,34 @@ public class EditMultiRedditActivity extends BaseActivity {
return true;
}
if (mAccessToken == null) {
String name = nameEditText.getText().toString();
multiReddit.setDisplayName(name);
multiReddit.setName(name);
multiReddit.setDescription(descriptionEditText.getText().toString());
EditMultiReddit.anonymousEditMultiReddit(mExecutor, new Handler(), mRedditDataRoomDatabase,
multiReddit, new EditMultiReddit.EditMultiRedditListener() {
@Override
public void success() {
finish();
}
@Override
public void failed() {
//Will not be called
}
});
} else {
String jsonModel = new MultiRedditJSONModel(nameEditText.getText().toString(), descriptionEditText.getText().toString(),
visibilitySwitch.isChecked(), multiReddit.getSubreddits()).createJSONModel();
EditMultiReddit.editMultiReddit(mRetrofit, mAccessToken, multiReddit.getPath(),
jsonModel, new EditMultiReddit.EditMultiRedditListener() {
@Override
public void success() {
finish();
}
@Override
public void failed() {
Snackbar.make(coordinatorLayout, R.string.edit_multi_reddit_failed, Snackbar.LENGTH_SHORT).show();
}
});
String name = nameEditText.getText().toString();
multiReddit.setDisplayName(name);
multiReddit.setName(name);
multiReddit.setDescription(descriptionEditText.getText().toString());
StringBuilder pathStringBuilder = new StringBuilder();
String prefix = "";
for (SubredditWithSelection s : multiReddit.getSubreddits()) {
pathStringBuilder.append(prefix);
prefix = ",";
pathStringBuilder.append(s.getQualifiedName());
}
multiReddit.setPath(pathStringBuilder.toString());
EditMultiReddit.anonymousEditMultiReddit(mExecutor, new Handler(), mRedditDataRoomDatabase,
multiReddit, multipath, new EditMultiReddit.EditMultiRedditListener() {
@Override
public void success() {
finish();
}
@Override
public void failed() {
//Will not be called
}
});
return true;
}
return false;
@@ -259,7 +238,7 @@ public class EditMultiRedditActivity extends BaseActivity {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE && resultCode == RESULT_OK) {
if (data != null) {
multiReddit.setSubreddits(data.getStringArrayListExtra(
multiReddit.setSubreddits(data.getParcelableArrayListExtra(
SelectedSubredditsAndUsersActivity.EXTRA_RETURN_SELECTED_SUBREDDITS));
}
}
@@ -296,7 +275,6 @@ public class EditMultiRedditActivity extends BaseActivity {
divider2.setBackgroundColor(dividerColor);
descriptionEditText.setTextColor(primaryTextColor);
descriptionEditText.setHintTextColor(secondaryTextColor);
visibilityTextView.setTextColor(primaryTextColor);
selectSubredditTextView.setTextColor(primaryTextColor);
if (typeface != null) {

View File

@@ -317,7 +317,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
bundle.putInt(PostFragment.EXTRA_POST_TYPE, postType);
bundle.putParcelable(PostFragment.EXTRA_FILTER, postFilter);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
if (postType == PostPagingSource.TYPE_USER) {
bundle.putString(PostFragment.EXTRA_USER_NAME, name);
bundle.putString(PostFragment.EXTRA_USER_WHERE, userWhere);
@@ -371,20 +371,17 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
} else if (itemId == R.id.action_sort_filtered_thing_activity) {
switch (postType) {
case PostPagingSource.TYPE_FRONT_PAGE:
SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(false, mFragment.getSortType());
case PostPagingSource.TYPE_SUBREDDIT:
case PostPagingSource.TYPE_MULTI_REDDIT:
case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT:
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(postType, mFragment.getSortType());
bestSortTypeBottomSheetFragment.show(getSupportFragmentManager(), bestSortTypeBottomSheetFragment.getTag());
break;
case PostPagingSource.TYPE_SEARCH:
SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = SearchPostSortTypeBottomSheetFragment.getNewInstance(mFragment.getSortType());
searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag());
break;
case PostPagingSource.TYPE_SUBREDDIT:
case PostPagingSource.TYPE_MULTI_REDDIT:
case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT:
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
SortTypeBottomSheetFragment sortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(true, mFragment.getSortType());
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag());
break;
case PostPagingSource.TYPE_USER:
UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment = UserThingSortTypeBottomSheetFragment.getNewInstance(mFragment.getSortType());
userThingSortTypeBottomSheetFragment.show(getSupportFragmentManager(), userThingSortTypeBottomSheetFragment.getTag());

View File

@@ -18,6 +18,7 @@ import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
@@ -139,7 +140,7 @@ public class FullMarkdownActivity extends BaseActivity {
}
};
Markwon markwon = MarkdownUtils.createFullRedditMarkwon(this,
miscPlugin, markdownColor, spoilerBackgroundColor, null);
miscPlugin, markdownColor, spoilerBackgroundColor, Glide.with(getApplication()), null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter();
LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() {

View File

@@ -117,7 +117,7 @@ public class GiveAwardActivity extends BaseActivity {
View layout = inflater.inflate(R.layout.dialog_give_award, null);
MaterialSwitch materialSwitch = layout.findViewById(R.id.switch_material_give_award_dialog);
new MaterialAlertDialogBuilder(this)
.setTitle(R.string.give_award_dialog_title)
.setTitle("")
.setView(layout)
.setPositiveButton(R.string.yes, (dialogInterface, i) -> {
boolean isAnonymous = materialSwitch.isChecked();
@@ -138,10 +138,10 @@ public class GiveAwardActivity extends BaseActivity {
public void failed(int code, String message) {
View layout = inflater.inflate(R.layout.copy_text_material_dialog, null);
TextView textView = layout.findViewById(R.id.text_view_copy_text_material_dialog);
String text = getString(R.string.give_award_error_message, code, message == null ? "" : message);
String text = "";
textView.setText(text);
new MaterialAlertDialogBuilder(GiveAwardActivity.this, R.style.CopyTextMaterialAlertDialogTheme)
.setTitle(R.string.give_award_failed)
.setTitle("")
.setView(layout)
.setPositiveButton(R.string.copy_all, (dialogInterface, i) -> {
ClipboardManager clipboard = (ClipboardManager) GiveAwardActivity.this.getSystemService(Context.CLIPBOARD_SERVICE);

View File

@@ -1,336 +0,0 @@
package eu.toldi.infinityforlemmy.activities;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.tabs.TabLayout;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.ActivityToolbarInterface;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.bottomsheetfragments.PostLayoutBottomSheetFragment;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.events.ChangeNSFWEvent;
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
import eu.toldi.infinityforlemmy.fragments.CommentsListingFragment;
import eu.toldi.infinityforlemmy.fragments.HistoryPostFragment;
import eu.toldi.infinityforlemmy.fragments.PostFragment;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
public class HistoryActivity extends BaseActivity implements ActivityToolbarInterface,
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
@BindView(R.id.coordinator_layout_history_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_history_activity)
AppBarLayout appBarLayout;
@BindView(R.id.collapsing_toolbar_layout_history_activity)
CollapsingToolbarLayout collapsingToolbarLayout;
@BindView(R.id.toolbar_history_activity)
Toolbar toolbar;
@BindView(R.id.tab_layout_tab_layout_history_activity_activity)
TabLayout tabLayout;
@BindView(R.id.view_pager_history_activity)
ViewPager2 viewPager2;
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
@Named("post_layout")
SharedPreferences mPostLayoutSharedPreferences;
@Inject
@Named("current_account")
SharedPreferences mCurrentAccountSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
private FragmentManager fragmentManager;
private SectionsPagerAdapter sectionsPagerAdapter;
private String mAccessToken;
private String mAccountName;
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
ButterKnife.bind(this);
EventBus.getDefault().register(this);
applyCustomTheme();
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) {
mSliderPanel = Slidr.attach(this);
}
//mViewPager2 = viewPager2;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
if (isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(appBarLayout);
}
if (isImmersiveInterface()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.setDecorFitsSystemWindows(false);
} else {
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
adjustToolbar(toolbar);
}
}
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar);
fragmentManager = getSupportFragmentManager();
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
initializeViewPager();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (sectionsPagerAdapter != null) {
return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event);
}
return super.onKeyDown(keyCode, event);
}
@Override
public SharedPreferences getDefaultSharedPreferences() {
return mSharedPreferences;
}
@Override
protected CustomThemeWrapper getCustomThemeWrapper() {
return mCustomThemeWrapper;
}
@Override
protected void applyCustomTheme() {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
applyTabLayoutTheme(tabLayout);
}
private void initializeViewPager() {
sectionsPagerAdapter = new SectionsPagerAdapter(this);
tabLayout.setVisibility(View.GONE);
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(2);
//viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false));
viewPager2.setUserInputEnabled(false);
/*new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
switch (position) {
case 0:
Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.posts));
break;
}
}).attach();*/
viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
if (position == 0) {
unlockSwipeRightToGoBack();
} else {
lockSwipeRightToGoBack();
}
}
});
fixViewPager2Sensitivity(viewPager2);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.history_activity, menu);
applyMenuItemTheme(menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int itemId = item.getItemId();
if (itemId == android.R.id.home) {
finish();
return true;
} else if (itemId == R.id.action_refresh_history_activity) {
sectionsPagerAdapter.refresh();
return true;
} else if (itemId == R.id.action_change_post_layout_history_activity) {
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
}
return false;
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
@Subscribe
public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish();
}
@Subscribe
public void onChangeNSFWEvent(ChangeNSFWEvent changeNSFWEvent) {
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
}
@Override
public void onLongPress() {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
}
@Override
public void lockSwipeRightToGoBack() {
if (mSliderPanel != null) {
mSliderPanel.lock();
}
}
@Override
public void unlockSwipeRightToGoBack() {
if (mSliderPanel != null) {
mSliderPanel.unlock();
}
}
@Override
public void postLayoutSelected(int postLayout) {
if (sectionsPagerAdapter != null) {
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.HISTORY_POST_LAYOUT_READ_POST, postLayout).apply();
sectionsPagerAdapter.changePostLayout(postLayout);
}
}
private class SectionsPagerAdapter extends FragmentStateAdapter {
SectionsPagerAdapter(FragmentActivity fa) {
super(fa);
}
@NonNull
@Override
public Fragment createFragment(int position) {
if (position == 0) {
HistoryPostFragment fragment = new HistoryPostFragment();
Bundle bundle = new Bundle();
bundle.putInt(HistoryPostFragment.EXTRA_HISTORY_TYPE, HistoryPostFragment.HISTORY_TYPE_READ_POSTS);
bundle.putString(HistoryPostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(HistoryPostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
fragment.setArguments(bundle);
return fragment;
} else {
HistoryPostFragment fragment = new HistoryPostFragment();
Bundle bundle = new Bundle();
bundle.putInt(HistoryPostFragment.EXTRA_HISTORY_TYPE, HistoryPostFragment.HISTORY_TYPE_READ_POSTS);
bundle.putString(HistoryPostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(HistoryPostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
fragment.setArguments(bundle);
return fragment;
}
}
@Nullable
private Fragment getCurrentFragment() {
if (viewPager2 == null || fragmentManager == null) {
return null;
}
return fragmentManager.findFragmentByTag("f" + viewPager2.getCurrentItem());
}
public boolean handleKeyDown(int keyCode) {
if (viewPager2.getCurrentItem() == 0) {
Fragment fragment = getCurrentFragment();
if (fragment instanceof PostFragment) {
return ((PostFragment) fragment).handleKeyDown(keyCode);
}
}
return false;
}
public void refresh() {
Fragment fragment = getCurrentFragment();
if (fragment instanceof PostFragment) {
((PostFragment) fragment).refresh();
} else if (fragment instanceof CommentsListingFragment) {
((CommentsListingFragment) fragment).refresh();
}
}
public void changeNSFW(boolean nsfw) {
Fragment fragment = getCurrentFragment();
if (fragment instanceof PostFragment) {
((PostFragment) fragment).changeNSFW(nsfw);
}
}
public void changePostLayout(int postLayout) {
Fragment fragment = getCurrentFragment();
if (fragment instanceof HistoryPostFragment) {
((HistoryPostFragment) fragment).changePostLayout(postLayout);
}
}
public void goBackToTop() {
Fragment fragment = getCurrentFragment();
if (fragment instanceof PostFragment) {
((PostFragment) fragment).goBackToTop();
} else if (fragment instanceof CommentsListingFragment) {
((CommentsListingFragment) fragment).goBackToTop();
}
}
@Override
public int getItemCount() {
return 1;
}
}
}

View File

@@ -156,7 +156,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
fragmentManager = getSupportFragmentManager();
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
if (savedInstanceState != null) {
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);

View File

@@ -1,14 +1,21 @@
package eu.toldi.infinityforlemmy.activities;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
import android.text.Spanned;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout;
@@ -16,8 +23,10 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.snackbar.Snackbar;
import java.util.List;
@@ -27,23 +36,36 @@ import javax.inject.Named;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.account.FetchBlockedThings;
import eu.toldi.infinityforlemmy.adapters.AdminRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityData;
import eu.toldi.infinityforlemmy.blockedinstances.BlockedInstanceData;
import eu.toldi.infinityforlemmy.blockeduser.BlockedUserData;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.databinding.ActivityInstanceInfoBinding;
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
import eu.toldi.infinityforlemmy.site.BlockInstance;
import eu.toldi.infinityforlemmy.site.FetchSiteInfo;
import eu.toldi.infinityforlemmy.site.SiteInfo;
import eu.toldi.infinityforlemmy.site.SiteStatistics;
import eu.toldi.infinityforlemmy.user.BasicUserInfo;
import eu.toldi.infinityforlemmy.user.MyUserInfo;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.MarkwonPlugin;
import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.recycler.MarkwonAdapter;
import retrofit2.Retrofit;
public class InstanceInfoActivity extends BaseActivity {
public static final String EXTRA_INSTANCE_DOMAIN = "instance_info_domain";
public static final String EXTRA_INSTANCE_ID = "instance_info_id";
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
@@ -55,6 +77,10 @@ public class InstanceInfoActivity extends BaseActivity {
@Named("no_oauth")
RetrofitHolder mRetorifitHolder;
@Inject
@Named("current_account")
SharedPreferences mCurrentAccountSharedPreferences;
ActivityInstanceInfoBinding mInstanceInfoActivityViewBinding;
private CoordinatorLayout coordinatorLayout;
private Toolbar toolbar;
@@ -84,6 +110,11 @@ public class InstanceInfoActivity extends BaseActivity {
private MarkwonAdapter mMarkwonAdapter;
private Markwon mPostDetailMarkwon;
private AdminRecyclerViewAdapter mAdminAdapter;
private Retrofit mRetrofit;
private String mInstanceDomain;
private int mInstanceId;
private String mAccessToken;
private String mAccountName;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -96,6 +127,25 @@ public class InstanceInfoActivity extends BaseActivity {
setContentView(view);
setSupportActionBar(mInstanceInfoActivityViewBinding.toolbarInstanceInfoActivity);
if (savedInstanceState != null) {
mInstanceDomain = savedInstanceState.getString(EXTRA_INSTANCE_DOMAIN);
mInstanceId = savedInstanceState.getInt(EXTRA_INSTANCE_ID);
} else {
mInstanceDomain = getIntent().getStringExtra(EXTRA_INSTANCE_DOMAIN);
mInstanceId = getIntent().getIntExtra(EXTRA_INSTANCE_ID, -1);
}
if (mInstanceDomain == null) {
mRetrofit = mRetorifitHolder.getRetrofit();
} else {
String originalBaseUrl = mRetorifitHolder.getBaseURL();
mRetorifitHolder.setBaseURL("https://" + mInstanceDomain);
mRetrofit = mRetorifitHolder.getRetrofit();
mRetorifitHolder.setBaseURL(originalBaseUrl);
}
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
setUpBindings();
applyCustomTheme();
@@ -105,16 +155,43 @@ public class InstanceInfoActivity extends BaseActivity {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Remove transparency from navigation bar
getWindow().setNavigationBarColor(mCustomThemeWrapper.getBackgroundColor());
int markdownColor = customThemeWrapper.getPostContentColor();
int postSpoilerBackgroundColor = markdownColor | 0xFF000000;
int linkColor = customThemeWrapper.getLinkColor();
MarkwonPlugin miscPlugin = new AbstractMarkwonPlugin() {
@Override
public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
if (InstanceInfoActivity.this.contentTypeface != null) {
textView.setTypeface(InstanceInfoActivity.this.contentTypeface);
}
textView.setTextColor(markdownColor);
textView.setHighlightColor(Color.TRANSPARENT);
}
@Override
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
builder.linkResolver((view, link) -> {
Intent intent = new Intent(InstanceInfoActivity.this, LinkResolverActivity.class);
Uri uri = Uri.parse(link);
intent.setData(uri);
InstanceInfoActivity.this.startActivity(intent);
});
}
@Override
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
builder.linkColor(linkColor);
}
};
mPostDetailMarkwon = MarkdownUtils.createFullRedditMarkwon(this,
new AbstractMarkwonPlugin() {
}, markdownColor, postSpoilerBackgroundColor, null);
miscPlugin, markdownColor, postSpoilerBackgroundColor, Glide.with(getApplication()), null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
mMarkwonAdapter = MarkdownUtils.createTablesAdapter();
mContentMarkdownView.setAdapter(mMarkwonAdapter);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
@@ -133,9 +210,9 @@ public class InstanceInfoActivity extends BaseActivity {
}
private void fetchInstanceInfo() {
FetchSiteInfo.fetchSiteInfo(mRetorifitHolder.getRetrofit(), null, new FetchSiteInfo.FetchSiteInfoListener() {
FetchSiteInfo.fetchSiteInfo(mRetrofit, null, new FetchSiteInfo.FetchSiteInfoListener() {
@Override
public void onFetchSiteInfoSuccess(SiteInfo siteInfo) {
public void onFetchSiteInfoSuccess(SiteInfo siteInfo, MyUserInfo myUserInfo) {
mLoadingConstraintLayout.setVisibility(View.GONE);
toolbar.setTitle(siteInfo.getName());
if (siteInfo.getSidebar() != null) {
@@ -162,7 +239,7 @@ public class InstanceInfoActivity extends BaseActivity {
}
@Override
public void onFetchSiteInfoFailed() {
public void onFetchSiteInfoFailed(boolean parseFailed) {
}
});
@@ -204,6 +281,9 @@ public class InstanceInfoActivity extends BaseActivity {
protected void applyCustomTheme() {
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar);
mStatisticsCardView.setCardBackgroundColor(mCustomThemeWrapper.getCardViewBackgroundColor());
mDescriptionCardView.setCardBackgroundColor(mCustomThemeWrapper.getCardViewBackgroundColor());
mAdminsCardView.setCardBackgroundColor(mCustomThemeWrapper.getCardViewBackgroundColor());
mUsersImageView.setColorFilter(mCustomThemeWrapper.getPrimaryTextColor(), PorterDuff.Mode.SRC_IN);
mCommunitiesImageView.setColorFilter(mCustomThemeWrapper.getPrimaryTextColor(), PorterDuff.Mode.SRC_IN);
mPostsImageView.setColorFilter(mCustomThemeWrapper.getPrimaryTextColor(), PorterDuff.Mode.SRC_IN);
@@ -218,11 +298,88 @@ public class InstanceInfoActivity extends BaseActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(EXTRA_INSTANCE_DOMAIN, mInstanceDomain);
outState.putInt(EXTRA_INSTANCE_ID, mInstanceId);
}
@Override
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mInstanceDomain = savedInstanceState.getString(EXTRA_INSTANCE_DOMAIN);
mInstanceId = savedInstanceState.getInt(EXTRA_INSTANCE_ID);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.instance_info_activity, menu);
if (mInstanceDomain == null || mInstanceDomain.equalsIgnoreCase(mRetorifitHolder.getBaseURL().split("/")[2])) {
menu.findItem(R.id.action_block_instance_info).setVisible(false);
menu.findItem(R.id.action_unblock_instance_info).setVisible(false);
return true;
}
if (mAccessToken == null) {
menu.findItem(R.id.action_block_instance_info).setVisible(false);
menu.findItem(R.id.action_unblock_instance_info).setVisible(false);
return true;
}
FetchBlockedThings.fetchBlockedThings(mRetorifitHolder.getRetrofit(), mAccessToken, mAccountName, new FetchBlockedThings.FetchBlockedThingsListener() {
@Override
public void onFetchBlockedThingsSuccess(List<BlockedUserData> blockedUsers, List<BlockedCommunityData> blockedCommunities, List<BlockedInstanceData> blockedInstances) {
for (BlockedInstanceData blockedInstanceData : blockedInstances) {
if (blockedInstanceData.getDomain().equals(mInstanceDomain)) {
menu.findItem(R.id.action_block_instance_info).setVisible(false);
menu.findItem(R.id.action_unblock_instance_info).setVisible(true);
return;
}
}
menu.findItem(R.id.action_block_instance_info).setVisible(true);
menu.findItem(R.id.action_unblock_instance_info).setVisible(false);
}
@Override
public void onFetchBlockedThingsFailure() {
}
});
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
} else if (item.getItemId() == R.id.action_block_instance_info) {
blockInstance(true);
return true;
} else if (item.getItemId() == R.id.action_unblock_instance_info) {
blockInstance(false);
return true;
}
return false;
return super.onOptionsItemSelected(item);
}
public void blockInstance(boolean blocked) {
BlockInstance.INSTANCE.blockInstance(mRetorifitHolder.getRetrofit(), mInstanceId, blocked, new BlockInstance.BlockInstanceResponse() {
@Override
public void onResponse() {
if (blocked) {
applySnackBarTheme(Snackbar.make(coordinatorLayout, R.string.block_instance_success, Snackbar.LENGTH_SHORT)).show();
} else {
applySnackBarTheme(Snackbar.make(coordinatorLayout, R.string.unblock_instance_success, Snackbar.LENGTH_SHORT)).show();
}
InstanceInfoActivity.this.invalidateOptionsMenu();
}
@Override
public void onFailure() {
Toast.makeText(InstanceInfoActivity.this, R.string.block_instance_failed, Toast.LENGTH_SHORT).show();
}
});
}
}

View File

@@ -7,6 +7,7 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.URLUtil;
import android.widget.Toast;
@@ -16,21 +17,30 @@ import androidx.browser.customtabs.CustomTabsIntent;
import androidx.browser.customtabs.CustomTabsService;
import org.apache.commons.io.FilenameUtils;
import org.greenrobot.eventbus.EventBus;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.asynctasks.SwitchAccount;
import eu.toldi.infinityforlemmy.comment.Comment;
import eu.toldi.infinityforlemmy.comment.FetchComment;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
import eu.toldi.infinityforlemmy.post.FetchPost;
import eu.toldi.infinityforlemmy.post.ObjectResolver;
import eu.toldi.infinityforlemmy.post.Post;
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
@@ -49,7 +59,6 @@ public class LinkResolverActivity extends AppCompatActivity {
private static final String MULTIREDDIT_PATTERN = "/user/[\\w-]+/m/\\w+/?";
private static final String MULTIREDDIT_PATTERN_2 = "/[rR]/(\\w+\\+?)+/?";
private static final String REDD_IT_POST_PATTERN = "/\\w+/?";
private static final String GFYCAT_PATTERN = "(/i?fr)?/[\\w-]+$";
private static final String REDGIFS_PATTERN = "/watch/[\\w-]+$";
private static final String IMGUR_GALLERY_PATTERN = "/gallery/\\w+/?";
private static final String IMGUR_ALBUM_PATTERN = "/(album|a)/\\w+/?";
@@ -64,6 +73,9 @@ public class LinkResolverActivity extends AppCompatActivity {
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
ObjectResolver mObjectResolver;
@@ -75,7 +87,14 @@ public class LinkResolverActivity extends AppCompatActivity {
@Named("no_oauth")
RetrofitHolder mRetrofit;
@Inject
Executor mExecutor;
@Inject
PostEnricher postEnricher;
private String mAccessToken;
private String mAccountQualifedName;
private Uri getRedditUriByPath(String path) {
if (path.charAt(0) != '/') {
@@ -91,23 +110,27 @@ public class LinkResolverActivity extends AppCompatActivity {
((Infinity) getApplication()).getAppComponent().inject(this);
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountQualifedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME,null);
if (mAccessToken != null) {
String instance = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
mRetrofit.setBaseURL(instance);
if (mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true)) {
mRetrofit.setAccessToken(mAccessToken);
}
}
Uri uri = getIntent().getData();
if (uri == null) {
String url = getIntent().getStringExtra(Intent.EXTRA_TEXT);
if (!URLUtil.isValidUrl(url)) {
Toast.makeText(this, R.string.invalid_link, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.invalid_link, Toast.LENGTH_SHORT).show();
finish();
return;
}
try {
uri = Uri.parse(url);
} catch (NullPointerException e) {
Toast.makeText(this, R.string.invalid_link, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.invalid_link, Toast.LENGTH_SHORT).show();
finish();
return;
}
@@ -115,7 +138,7 @@ public class LinkResolverActivity extends AppCompatActivity {
if (uri.getScheme() == null && uri.getHost() == null) {
if (uri.toString().isEmpty()) {
Toast.makeText(this, R.string.invalid_link, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.invalid_link, Toast.LENGTH_SHORT).show();
finish();
return;
}
@@ -127,7 +150,7 @@ public class LinkResolverActivity extends AppCompatActivity {
private void handleUri(Uri uri) {
if (uri == null) {
Toast.makeText(this, R.string.no_link_available, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.no_link_available, Toast.LENGTH_SHORT).show();
} else {
String path = uri.getPath();
if (path == null) {
@@ -201,23 +224,17 @@ public class LinkResolverActivity extends AppCompatActivity {
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
} else {
mObjectResolver.resolvePost(uri.toString(), mAccessToken, new ObjectResolver.ObjectResolverListener() {
@Override
public void onResolveObjectSuccess(Object p) {
Post post = (Post) p;
Intent intent = new Intent(LinkResolverActivity.this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, post.getId());
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
}
if (mAccountQualifedName == null || newAccountName != null && !mAccountQualifedName.equals(newAccountName)) {
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mRetrofit, mCurrentAccountSharedPreferences,
mExecutor, new Handler(), newAccountName, newAccount -> {
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
openPost(uri, segments, messageFullname);
});
} else {
openPost(uri, segments, messageFullname);
}
@Override
public void onResolveObjectFailed() {
Toast.makeText(LinkResolverActivity.this, R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
finish();
}
});
}
} else if (uri.toString().matches(COMMENT_PATTERN)) {
if (mAccessToken == null) {
@@ -237,112 +254,36 @@ public class LinkResolverActivity extends AppCompatActivity {
@Override
public void onFetchCommentFailed() {
Toast.makeText(LinkResolverActivity.this, R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
finish();
}
});
} else {
mObjectResolver.resolveComment(uri.toString(), mAccessToken, new ObjectResolver.ObjectResolverListener() {
@Override
public void onResolveObjectSuccess(Object c) {
Comment comment = (Comment) c;
Intent intent = new Intent(LinkResolverActivity.this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getPostId());
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId());
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_PARENT_ID, comment.getParentId());
startActivity(intent);
}
if (mAccountQualifedName == null || newAccountName != null && !mAccountQualifedName.equals(newAccountName)) {
SwitchAccount.switchAccount(mRedditDataRoomDatabase, mRetrofit, mCurrentAccountSharedPreferences,
mExecutor, new Handler(), newAccountName, newAccount -> {
EventBus.getDefault().post(new SwitchAccountEvent(getClass().getName()));
Toast.makeText(this, R.string.account_switched, Toast.LENGTH_SHORT).show();
openComment(uri, segments, messageFullname);
});
} else {
openComment(uri, segments, messageFullname);
}
@Override
public void onResolveObjectFailed() {
Toast.makeText(LinkResolverActivity.this, R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
finish();
}
});
}
} else if (authority.equals("v.redd.it")) {
Intent intent = new Intent(this, ViewVideoActivity.class);
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_V_REDD_IT);
intent.putExtra(ViewVideoActivity.EXTRA_V_REDD_IT_URL, uri.toString());
startActivity(intent);
} else if (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app")) {
if (authority.equals("reddit.app.link") && path.isEmpty()) {
String redirect = uri.getQueryParameter("$og_redirect");
if (redirect != null) {
handleUri(Uri.parse(redirect));
} else {
deepLinkError(uri);
}
} else if (path.isEmpty()) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
} else if (path.equals("/report")) {
openInWebView(uri);
} else if (path.matches(POST_PATTERN_3)) {
Intent intent = new Intent(this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1));
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
} else if (path.matches(WIKI_PATTERN)) {
String[] pathSegments = path.split("/");
String wikiPage;
if (pathSegments.length == 4) {
wikiPage = "index";
} else {
int lengthThroughWiki = 0;
for (int i = 1; i <= 3; ++i) {
lengthThroughWiki += pathSegments[i].length() + 1;
}
wikiPage = path.substring(lengthThroughWiki);
}
Intent intent = new Intent(this, WikiActivity.class);
intent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, segments.get(1));
intent.putExtra(WikiActivity.EXTRA_WIKI_PATH, wikiPage);
startActivity(intent);
} else if (path.matches(SIDEBAR_PATTERN)) {
Intent intent = new Intent(this, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3, path.length() - 14));
intent.putExtra(ViewSubredditDetailActivity.EXTRA_VIEW_SIDEBAR, true);
startActivity(intent);
} else if (path.matches(MULTIREDDIT_PATTERN)) {
Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class);
intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_PATH, path);
startActivity(intent);
} else if (path.matches(MULTIREDDIT_PATTERN_2)) {
String subredditName = path.substring(3);
Intent intent = new Intent(this, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
} else if (authority.equals("redd.it") && path.matches(REDD_IT_POST_PATTERN)) {
Intent intent = new Intent(this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1));
startActivity(intent);
} else {
deepLinkError(uri);
}
} else if (authority.equals("click.redditmail.com")) {
if (path.startsWith("/CL0/")) {
handleUri(Uri.parse(path.substring("/CL0/".length())));
}
} else if (authority.contains("gfycat.com")) {
if (path.matches(GFYCAT_PATTERN)) {
Intent intent = new Intent(this, ViewVideoActivity.class);
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, path.substring(path.lastIndexOf("/") + 1));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, getIntent().getBooleanExtra(EXTRA_IS_NSFW, false));
startActivity(intent);
} else {
deepLinkError(uri);
}
} else if (authority.contains("redgifs.com")) {
if (path.matches(REDGIFS_PATTERN)) {
Intent intent = new Intent(this, ViewVideoActivity.class);
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, path.substring(path.lastIndexOf("/") + 1));
intent.putExtra(ViewVideoActivity.EXTRA_REDGIFS_ID, path.substring(path.lastIndexOf("/") + 1));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, true);
startActivity(intent);
@@ -408,12 +349,110 @@ public class LinkResolverActivity extends AppCompatActivity {
finish();
}
private void openComment(Uri uri, List<String> segments, String messageFullname) {
boolean local = false;
try {
URL baseURL = new URL(mRetrofit.getBaseURL());
if (baseURL.getHost().equalsIgnoreCase(uri.getHost())) {
local = true;
FetchComment.fetchSingleComment(mRetrofit.getRetrofit(), mAccessToken, Integer.parseInt(segments.get(segments.size() - 1)), new FetchComment.FetchCommentListener() {
@Override
public void onFetchCommentSuccess(ArrayList<Comment> comments, Integer parentId, ArrayList<Integer> moreChildrenIds) {
Intent intent = new Intent(LinkResolverActivity.this, ViewPostDetailActivity.class);
Comment comment = comments.get(0);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getPostId());
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId());
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_PARENT_ID, comment.getParentId());
startActivity(intent);
}
@Override
public void onFetchCommentFailed() {
Toast.makeText(getApplicationContext(), R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
finish();
}
});
}
} catch (MalformedURLException e) {
Toast.makeText(getApplicationContext(), R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
finish();
}
if (!local) {
mObjectResolver.resolveComment(uri.toString(), mAccessToken, new ObjectResolver.ObjectResolverListener() {
@Override
public void onResolveObjectSuccess(Object c) {
Comment comment = (Comment) c;
Intent intent = new Intent(LinkResolverActivity.this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getPostId());
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId());
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_PARENT_ID, comment.getParentId());
startActivity(intent);
}
@Override
public void onResolveObjectFailed() {
Toast.makeText(getApplicationContext(), R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
finish();
}
});
}
}
private void openPost(Uri uri, List<String> segments, String messageFullname) {
boolean local = false;
try {
URL baseURL = new URL(mRetrofit.getBaseURL());
if (baseURL.getHost().equalsIgnoreCase(uri.getHost())) {
local = true;
FetchPost.fetchPost(mExecutor, new Handler(), mRetrofit.getRetrofit(), segments.get(segments.size() - 1), mAccessToken, postEnricher, new FetchPost.FetchPostListener() {
@Override
public void fetchPostSuccess(Post post) {
Intent intent = new Intent(LinkResolverActivity.this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, post.getId());
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
startActivity(intent);
}
@Override
public void fetchPostFailed() {
Toast.makeText(getApplicationContext(), R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
finish();
}
});
}
} catch (MalformedURLException e) {
Toast.makeText(getApplicationContext(), R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
finish();
}
if (!local) {
mObjectResolver.resolvePost(uri.toString(), mAccessToken, new ObjectResolver.ObjectResolverListener() {
@Override
public void onResolveObjectSuccess(Object p) {
Post post = (Post) p;
Intent intent = new Intent(LinkResolverActivity.this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, post.getId());
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
startActivity(intent);
}
@Override
public void onResolveObjectFailed() {
Toast.makeText(getApplicationContext(), R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
finish();
}
});
}
}
private void deepLinkError(Uri uri) {
PackageManager pm = getPackageManager();
String authority = uri.getAuthority();
if(authority != null && (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app.link"))) {
openInCustomTabs(uri, pm, false);
openInBrowser(uri, pm, false);
return;
}

View File

@@ -8,15 +8,16 @@ import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.util.Log;
import android.util.Patterns;
import android.view.InflateException;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
@@ -29,6 +30,8 @@ import org.json.JSONObject;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import javax.inject.Inject;
@@ -36,18 +39,22 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.FetchMyInfo;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.adapters.CustomArrayAdapter;
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.asynctasks.ParseAndInsertNewAccount;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.dto.AccountLoginDTO;
import eu.toldi.infinityforlemmy.lemmyverse.FetchInstancesListener;
import eu.toldi.infinityforlemmy.lemmyverse.LemmyInstance;
import eu.toldi.infinityforlemmy.lemmyverse.LemmyVerseFetchInstances;
import eu.toldi.infinityforlemmy.site.FetchSiteInfo;
import eu.toldi.infinityforlemmy.site.SiteInfo;
import eu.toldi.infinityforlemmy.user.MyUserInfo;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import retrofit2.Call;
@@ -60,6 +67,9 @@ public class LoginActivity extends BaseActivity {
private static final String ENABLE_DOM_STATE = "EDS";
private static final String IS_AGREE_TO_USER_AGGREMENT_STATE = "IATUAS";
public static final String EXTRA_INPUT_USERNAME = "INPUT_USERNAME";
public static final String EXTRA_INPUT_INSTANCE = "INPUT_INSTANCE";
@BindView(R.id.coordinator_layout_login_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_login_activity)
@@ -70,7 +80,7 @@ public class LoginActivity extends BaseActivity {
TextView twoFAInfoTextView;
@BindView(R.id.instance_url_input)
TextInputEditText instance_input;
AppCompatAutoCompleteTextView instance_input;
@BindView(R.id.username_input)
TextInputEditText username_input;
@BindView(R.id.user_password_input)
@@ -87,9 +97,11 @@ public class LoginActivity extends BaseActivity {
@Inject
@Named("no_oauth")
RetrofitHolder mRetrofit;
@Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Named("lemmyVerse")
Retrofit mLemmyVerseRetrofit;
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
@@ -140,9 +152,34 @@ public class LoginActivity extends BaseActivity {
isAgreeToUserAgreement = savedInstanceState.getBoolean(IS_AGREE_TO_USER_AGGREMENT_STATE);
}
// Get username and instance from intent
Intent intent = getIntent();
String username_intent = intent.getStringExtra(EXTRA_INPUT_USERNAME);
String instance_intent = intent.getStringExtra(EXTRA_INPUT_INSTANCE);
if (username_intent != null) {
username_input.setText(username_intent);
}
if (instance_intent != null) {
instance_input.setText(instance_intent);
}
LemmyVerseFetchInstances.INSTANCE.fetchInstances(mLemmyVerseRetrofit, new FetchInstancesListener() {
@Override
public void onFetchInstancesSuccess(@NonNull List<LemmyInstance> instances) {
ArrayList<String> instanceNames = new ArrayList<>();
for (LemmyInstance instance : instances) {
instanceNames.add(instance.getFqdn());
}
ArrayAdapter<String> adapter = new CustomArrayAdapter(LoginActivity.this, android.R.layout.simple_dropdown_item_1line, instanceNames, mCustomThemeWrapper);
instance_input.setAdapter(adapter);
}
});
loginButton.setOnClickListener(view -> {
Log.i("LoginActivity", "Login button clicked");
if(!checkFields())
if (!checkFields())
return;
loginButton.setEnabled(false);
progressBar.setVisibility(ProgressBar.VISIBLE);
@@ -180,53 +217,58 @@ public class LoginActivity extends BaseActivity {
try {
JSONObject responseJSON = new JSONObject(accountResponse);
String accessToken = responseJSON.getString("jwt");
mRetrofit.setAccessToken(accessToken);
FetchMyInfo.fetchAccountInfo(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, username,
accessToken, new FetchMyInfo.FetchMyInfoListener() {
@Override
public void onFetchMyInfoSuccess(String name, String display_name, String profileImageUrl, String bannerImageUrl) {
FetchSiteInfo.fetchSiteInfo(mRetrofit.getRetrofit(), accessToken, new FetchSiteInfo.FetchSiteInfoListener() {
@Override
public void onFetchSiteInfoSuccess(SiteInfo siteInfo) {
boolean canDownvote = siteInfo.isEnable_downvotes();
ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), name,display_name, accessToken, profileImageUrl, bannerImageUrl, authCode, finalInstance,canDownvote, mRedditDataRoomDatabase.accountDao(),
() -> {
Intent resultIntent = new Intent();
setResult(Activity.RESULT_OK, resultIntent);
finish();
});
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, canDownvote).apply();
}
FetchSiteInfo.fetchSiteInfo(mRetrofit.getRetrofit(), accessToken, new FetchSiteInfo.FetchSiteInfoListener() {
@Override
public void onFetchSiteInfoSuccess(SiteInfo siteInfo, MyUserInfo myUserInfo) {
if (myUserInfo == null) {
finish();
Toast.makeText(LoginActivity.this, R.string.parse_user_info_error, Toast.LENGTH_SHORT).show();
return;
}
@Override
public void onFetchSiteInfoFailed() {
ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), name,display_name, accessToken, profileImageUrl, bannerImageUrl, authCode, finalInstance,true, mRedditDataRoomDatabase.accountDao(),
() -> {
Intent resultIntent = new Intent();
setResult(Activity.RESULT_OK, resultIntent);
finish();
});
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, true).apply();
}
boolean canDownvote = siteInfo.isEnable_downvotes();
ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), myUserInfo.getQualifiedName(), myUserInfo.getDisplayName(), accessToken, myUserInfo.getProfileImageUrl(), myUserInfo.getBannerImageUrl(), authCode, finalInstance, canDownvote, mRedditDataRoomDatabase.accountDao(),
() -> {
Intent resultIntent = new Intent();
setResult(Activity.RESULT_OK, resultIntent);
finish();
});
mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, accessToken)
.putString(SharedPreferencesUtils.ACCOUNT_NAME, display_name)
.putString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, name)
.putString(SharedPreferencesUtils.ACCOUNT_INSTANCE,finalInstance)
.putString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, profileImageUrl).apply();
mCurrentAccountSharedPreferences.edit()
.putString(SharedPreferencesUtils.ACCESS_TOKEN, accessToken)
.putString(SharedPreferencesUtils.ACCOUNT_NAME, myUserInfo.getDisplayName())
.putString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, myUserInfo.getQualifiedName())
.putString(SharedPreferencesUtils.ACCOUNT_INSTANCE,finalInstance)
.putString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, myUserInfo.getProfileImageUrl())
.putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, canDownvote).apply();
String[] version = siteInfo.getVersion().split("\\.");
if (version.length > 0) {
Log.d("SwitchAccount", "Lemmy Version: " + version[0] + "." + version[1]);
int majorVersion = Integer.parseInt(version[0]);
int minorVersion = Integer.parseInt(version[1]);
if (majorVersion > 0 || (majorVersion == 0 && minorVersion >= 19)) {
mRetrofit.setAccessToken(accessToken);
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true).apply();
} else {
mRetrofit.setAccessToken(null);
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, false).apply();
}
}
}
@Override
public void onFetchMyInfoFailed(boolean parseFailed) {
if (parseFailed) {
Toast.makeText(LoginActivity.this, R.string.parse_user_info_error, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(LoginActivity.this, R.string.cannot_fetch_user_info, Toast.LENGTH_SHORT).show();
}
finish();
}
});
@Override
public void onFetchSiteInfoFailed(boolean parseFailed) {
if (parseFailed) {
finish();
Toast.makeText(LoginActivity.this, R.string.parse_user_info_error, Toast.LENGTH_SHORT).show();
} else {
progressBar.setVisibility(ProgressBar.GONE);
loginButton.setEnabled(true);
Toast.makeText(LoginActivity.this, R.string.cannot_fetch_user_info, Toast.LENGTH_SHORT).show();
}
}
});
} catch (JSONException e) {
throw new RuntimeException(e);
}
@@ -328,6 +370,7 @@ public class LoginActivity extends BaseActivity {
if (typeface != null) {
twoFAInfoTextView.setTypeface(typeface);
}
instance_input.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
}
@Override

View File

@@ -14,6 +14,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
@@ -33,6 +34,7 @@ import androidx.appcompat.app.AppCompatDelegate;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.splashscreen.SplashScreen;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
@@ -52,6 +54,7 @@ import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.navigation.NavigationView;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.google.android.material.textfield.TextInputEditText;
@@ -118,12 +121,15 @@ import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
import eu.toldi.infinityforlemmy.post.Post;
import eu.toldi.infinityforlemmy.post.PostPagingSource;
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
import eu.toldi.infinityforlemmy.site.FetchSiteInfo;
import eu.toldi.infinityforlemmy.site.SiteInfo;
import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData;
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditViewModel;
import eu.toldi.infinityforlemmy.subscribeduser.SubscribedUserData;
import eu.toldi.infinityforlemmy.user.FetchUserData;
import eu.toldi.infinityforlemmy.user.MyUserInfo;
import eu.toldi.infinityforlemmy.user.UserData;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import eu.toldi.infinityforlemmy.utils.CustomThemeSharedPreferencesUtils;
@@ -247,8 +253,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private int fabOption;
private int inboxCount;
private boolean mBearerTokenUsed = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.installSplashScreen(this);
((Infinity) getApplication()).getAppComponent().inject(this);
setTheme(R.style.AppTheme_NoActionBarWithTransparentStatusBar);
@@ -336,11 +346,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
fragmentManager = getSupportFragmentManager();
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mRetrofit.setAccessToken(mAccessToken);
mBearerTokenUsed = mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
String instance = (mAccessToken == null) ? mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI) : mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
if(instance != null) {
if (instance != null) {
mRetrofit.setBaseURL(instance);
}
@@ -365,9 +377,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
super.onResume();
if (mAccessToken == null) {
String instancePreference = mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI);
if (!mRetrofit.getBaseURL().equalsIgnoreCase(instancePreference)) {
if (!instancePreference.startsWith(mRetrofit.getBaseURL())) {
mRetrofit.setBaseURL(instancePreference);
this.recreate();
}
} else {
checkUserToken();
}
}
@@ -820,8 +835,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} else if (stringId == R.string.multi_reddit) {
intent = new Intent(MainActivity.this, SubscribedThingListingActivity.class);
intent.putExtra(SubscribedThingListingActivity.EXTRA_SHOW_MULTIREDDITS, true);
} else if (stringId == R.string.history) {
intent = new Intent(MainActivity.this, HistoryActivity.class);
} else if (stringId == R.string.trending) {
intent = new Intent(MainActivity.this, TrendingActivity.class);
} else if (stringId == R.string.upvoted) {
@@ -923,7 +936,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
sectionsPagerAdapter = new SectionsPagerAdapter(this, tabCount, mShowFavoriteMultiReddits,
mShowMultiReddits, mShowFavoriteSubscribedSubreddits, mShowSubscribedSubreddits);
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(1);
viewPager2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
viewPager2.setUserInputEnabled(!mDisableSwipingBetweenTabs);
if (mMainActivityTabsSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_TAB_NAMES, true)) {
if (mShowFavoriteMultiReddits || mShowMultiReddits || mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) {
@@ -1077,6 +1090,39 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
}
private void checkUserToken() {
if (mBearerTokenUsed) {
FetchUserData.validateAuthToken(mRetrofit.getRetrofit(), new FetchUserData.ValidateAuthTokenListener() {
@Override
public void onValidateAuthTokenSuccess() {
}
@Override
public void onValidateAuthTokenFailed() {
// Alert user that the token is invalid and they need to re-login
new MaterialAlertDialogBuilder(MainActivity.this, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.token_expired)
.setMessage(R.string.token_expired_message)
.setPositiveButton(R.string.ok, (dialogInterface, i) -> {
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
// Username without instance
String username = mAccountName.substring(0, mAccountQualifiedName.indexOf("@"));
intent.putExtra(LoginActivity.EXTRA_INPUT_USERNAME, username);
intent.putExtra(LoginActivity.EXTRA_INPUT_INSTANCE, mRetrofit.getBaseURL());
startActivity(intent);
})
.setCancelable(false)
.show();
}
@Override
public void onCheckFailed(String message) {
applySnackBarTheme(Snackbar.make(findViewById(android.R.id.content), getString(R.string.failed_to_check_token_validity,message), Snackbar.LENGTH_LONG)).show();
}
});
}
}
private void loadUserData() {
if (!mFetchUserInfoSuccess) {
FetchUserData.fetchUnreadCount(mRetrofit.getRetrofit(), mAccessToken, new FetchUserData.FetchUserUnreadCountListener() {
@@ -1102,9 +1148,35 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Override
public void onFetchUserDataFailed() {
mFetchUserInfoSuccess = false;
}
});
mFetchUserInfoSuccess = false;
}
});
if (mAccessToken != null) {
FetchSiteInfo.fetchSiteInfo(mRetrofit.getRetrofit(), mAccessToken, new FetchSiteInfo.FetchSiteInfoListener() {
@Override
public void onFetchSiteInfoSuccess(SiteInfo siteInfo, MyUserInfo myUserInfo) {
String[] version = siteInfo.getVersion().split("\\.");
if (version.length > 0) {
Log.d("MainActvity", "Lemmy Version: " + version[0] + "." + version[1]);
int majorVersion = Integer.parseInt(version[0]);
int minorVersion = Integer.parseInt(version[1]);
if (majorVersion > 0 || (majorVersion == 0 && minorVersion >= 19)) {
mRetrofit.setAccessToken(mAccessToken);
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true).apply();
checkUserToken();
} else {
mRetrofit.setAccessToken(null);
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, false).apply();
}
}
}
@Override
public void onFetchSiteInfoFailed(boolean parseFailed) {
}
});
}
}
}
@@ -1130,7 +1202,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
int currentPostType = sectionsPagerAdapter.getCurrentPostType();
PostFragment postFragment = sectionsPagerAdapter.getCurrentFragment();
if (postFragment != null) {
SortTypeBottomSheetFragment sortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(currentPostType != PostPagingSource.TYPE_FRONT_PAGE, postFragment.getSortType());
SortTypeBottomSheetFragment sortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(currentPostType, postFragment.getSortType());
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag());
}
}
@@ -1510,7 +1582,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString());
String communityName = thingEditText.getText().toString();
if (communityName.startsWith("!")) {
communityName = communityName.substring(1);
}
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
startActivity(subredditIntent);
return true;
}
@@ -1568,7 +1645,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
-> {
Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString());
String communityName = thingEditText.getText().toString();
if (communityName.startsWith("!")) {
communityName = communityName.substring(1);
}
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
startActivity(subredditIntent);
})
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
@@ -1589,7 +1670,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString());
String qualifiedName = thingEditText.getText().toString();
if (qualifiedName.startsWith("@")) {
qualifiedName = qualifiedName.substring(1);
}
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
startActivity(userIntent);
return true;
}
@@ -1602,7 +1687,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
-> {
Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString());
String qualifiedName = thingEditText.getText().toString();
if (qualifiedName.startsWith("@")) {
qualifiedName = qualifiedName.substring(1);
}
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
startActivity(userIntent);
})
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
@@ -1645,7 +1734,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
public void doNotShowRedditAPIInfoAgain() {
mInternalSharedPreferences.edit().putBoolean(SharedPreferencesUtils.DO_NOT_SHOW_REDDIT_API_INFO_AGAIN, true).apply();
mInternalSharedPreferences.edit().putBoolean(SharedPreferencesUtils.DO_NOT_SHOW_REDDIT_API_INFO_V2_AGAIN, true).apply();
}
private class SectionsPagerAdapter extends FragmentStateAdapter {
@@ -1757,7 +1846,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE : PostPagingSource.TYPE_FRONT_PAGE);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL) {
@@ -1766,7 +1855,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
bundle.putString(PostFragment.EXTRA_NAME, "all");
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_SUBREDDIT) {
@@ -1775,7 +1864,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
bundle.putString(PostFragment.EXTRA_NAME, name);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_MULTIREDDIT) {
@@ -1784,7 +1873,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bundle.putString(PostFragment.EXTRA_NAME, name);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT : PostPagingSource.TYPE_MULTI_REDDIT);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_USER) {
@@ -1794,7 +1883,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bundle.putString(PostFragment.EXTRA_USER_NAME, name);
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SUBMITTED);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_UPVOTED
@@ -1807,7 +1896,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER);
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
bundle.putBoolean(PostFragment.EXTRA_DISABLE_READ_POSTS, true);
if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_UPVOTED) {
@@ -1830,7 +1919,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
bundle.putString(PostFragment.EXTRA_NAME, "local");
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
}

View File

@@ -117,7 +117,7 @@ public class MultiredditSelectionActivity extends BaseActivity implements Activi
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
if (savedInstanceState == null) {
bindView(true);

View File

@@ -8,6 +8,7 @@ import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
@@ -16,6 +17,7 @@ import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.List;
import java.util.concurrent.Executor;
import javax.inject.Inject;
@@ -26,13 +28,14 @@ import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.adapters.PostFilterRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.adapters.PostFilterWithUsageRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.bottomsheetfragments.PostFilterOptionsBottomSheetFragment;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.post.Post;
import eu.toldi.infinityforlemmy.postfilter.DeletePostFilter;
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
import eu.toldi.infinityforlemmy.postfilter.PostFilterViewModel;
import eu.toldi.infinityforlemmy.postfilter.PostFilterWithUsageViewModel;
import eu.toldi.infinityforlemmy.postfilter.PostFilterWithUsage;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
public class PostFilterPreferenceActivity extends BaseActivity {
@@ -62,8 +65,8 @@ public class PostFilterPreferenceActivity extends BaseActivity {
CustomThemeWrapper customThemeWrapper;
@Inject
Executor executor;
public PostFilterViewModel postFilterViewModel;
private PostFilterRecyclerViewAdapter adapter;
public PostFilterWithUsageViewModel postFilterWithUsageViewModel;
private PostFilterWithUsageRecyclerViewAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -99,7 +102,7 @@ public class PostFilterPreferenceActivity extends BaseActivity {
}
});
adapter = new PostFilterRecyclerViewAdapter(this, customThemeWrapper, postFilter -> {
adapter = new PostFilterWithUsageRecyclerViewAdapter(this, customThemeWrapper, postFilter -> {
if (post != null) {
showPostFilterOptions(post, postFilter);
} else if (subredditName != null) {
@@ -117,10 +120,15 @@ public class PostFilterPreferenceActivity extends BaseActivity {
recyclerView.setAdapter(adapter);
postFilterViewModel = new ViewModelProvider(this,
new PostFilterViewModel.Factory(redditDataRoomDatabase)).get(PostFilterViewModel.class);
postFilterWithUsageViewModel = new ViewModelProvider(this,
new PostFilterWithUsageViewModel.Factory(redditDataRoomDatabase)).get(PostFilterWithUsageViewModel.class);
postFilterViewModel.getPostFilterListLiveData().observe(this, postFilters -> adapter.setPostFilterList(postFilters));
postFilterWithUsageViewModel.getPostFilterWithUsageListLiveData().observe(this, new Observer<List<PostFilterWithUsage>>() {
@Override
public void onChanged(List<PostFilterWithUsage> postFilterWithUsages) {
adapter.setPostFilterWithUsageList(postFilterWithUsages);
}
});
}
public void showPostFilterOptions(Post post, PostFilter postFilter) {

View File

@@ -126,9 +126,9 @@ public class PostFilterUsageListingActivity extends BaseActivity {
}
private void editAndPostFilterUsageNameOfUsage(int type, String nameOfUsage) {
View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit_post_filter_name_of_usage, null);
TextInputLayout textInputLayout = dialogView.findViewById(R.id.text_input_layout_edit_post_filter_name_of_usage_dialog);
TextInputEditText textInputEditText = dialogView.findViewById(R.id.text_input_edit_text_edit_post_filter_name_of_usage_dialog);
View dialogView = getLayoutInflater().inflate(R.layout.dialog_edit_post_or_comment_filter_name_of_usage, null);
TextInputLayout textInputLayout = dialogView.findViewById(R.id.text_input_layout_edit_post_or_comment_filter_name_of_usage_dialog);
TextInputEditText textInputEditText = dialogView.findViewById(R.id.text_input_edit_text_edit_post_or_comment_filter_name_of_usage_dialog);
int primaryTextColor = customThemeWrapper.getPrimaryTextColor();
textInputLayout.setBoxStrokeColor(primaryTextColor);
textInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
@@ -147,7 +147,6 @@ public class PostFilterUsageListingActivity extends BaseActivity {
titleStringId = R.string.user;
break;
case PostFilterUsage.MULTIREDDIT_TYPE:
textInputEditText.setHint(R.string.settings_tab_multi_reddit_name);
titleStringId = R.string.multi_reddit;
break;
}

View File

@@ -39,7 +39,7 @@ import com.google.android.material.divider.MaterialDivider;
import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.android.material.snackbar.Snackbar;
import com.google.gson.Gson;
import com.libRG.CustomTextView;
import eu.toldi.infinityforlemmy.CustomTextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -504,7 +504,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
}
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;

View File

@@ -39,7 +39,7 @@ import com.google.android.material.divider.MaterialDivider;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.android.material.snackbar.Snackbar;
import com.libRG.CustomTextView;
import eu.toldi.infinityforlemmy.CustomTextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -475,6 +475,8 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
nsfwTextView.setTextColor(primaryTextColor);
titleEditText.setTextColor(primaryTextColor);
titleEditText.setHintTextColor(secondaryTextColor);
contentEditText.setTextColor(primaryTextColor);
contentEditText.setHintTextColor(secondaryTextColor);
boolean circleFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false);
applyFABTheme(captureFab, circleFab);
applyFABTheme(selectFromLibraryFab, circleFab);
@@ -487,6 +489,10 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
titleEditText.setTypeface(typeface);
selectAgainTextView.setTypeface(typeface);
}
if (contentTypeface != null) {
contentEditText.setTypeface(contentTypeface);
}
}
private void loadImage() {
@@ -511,7 +517,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
}
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, communityData.getQualified_name(), mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, communityData.getQualified_name(), mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;

View File

@@ -36,7 +36,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.divider.MaterialDivider;
import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.android.material.snackbar.Snackbar;
import com.libRG.CustomTextView;
import eu.toldi.infinityforlemmy.CustomTextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -458,6 +458,8 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
titleEditText.setHintTextColor(secondaryTextColor);
suggestTitleButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
suggestTitleButton.setTextColor(mCustomThemeWrapper.getButtonTextColor());
contentEditText.setTextColor(primaryTextColor);
contentEditText.setHintTextColor(secondaryTextColor);
linkEditText.setTextColor(primaryTextColor);
linkEditText.setHintTextColor(secondaryTextColor);
if (typeface != null) {
@@ -470,6 +472,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
}
if (contentTypeface != null) {
linkEditText.setTypeface(contentTypeface);
contentEditText.setTypeface(contentTypeface);
}
}
@@ -489,7 +492,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, communityData.getQualified_name(),
mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;

View File

@@ -35,7 +35,7 @@ import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import com.google.gson.Gson;
import com.libRG.CustomTextView;
import eu.toldi.infinityforlemmy.CustomTextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -500,7 +500,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
}
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;

View File

@@ -35,7 +35,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.divider.MaterialDivider;
import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.android.material.snackbar.Snackbar;
import com.libRG.CustomTextView;
import eu.toldi.infinityforlemmy.CustomTextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -451,11 +451,11 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, communityData.getQualified_name(),
mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
});
mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
});
}
private void promptAlertDialog(int titleResId, int messageResId) {

View File

@@ -42,7 +42,7 @@ import com.google.android.material.divider.MaterialDivider;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.android.material.snackbar.Snackbar;
import com.libRG.CustomTextView;
import eu.toldi.infinityforlemmy.CustomTextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -486,11 +486,11 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
});
mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
});
}
private void promptAlertDialog(int titleResId, int messageResId) {

View File

@@ -132,7 +132,7 @@ public class RulesActivity extends BaseActivity {
mSubredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper, sliderPanel);
mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper, sliderPanel, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
recyclerView.setAdapter(mAdapter);
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), mSubredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
@Override

View File

@@ -3,6 +3,7 @@ package eu.toldi.infinityforlemmy.activities;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -27,11 +28,14 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
@@ -47,13 +51,14 @@ import eu.toldi.infinityforlemmy.apis.RedditAPI;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
import eu.toldi.infinityforlemmy.recentsearchquery.DeleteRecentSearchQuery;
import eu.toldi.infinityforlemmy.recentsearchquery.RecentSearchQuery;
import eu.toldi.infinityforlemmy.recentsearchquery.RecentSearchQueryViewModel;
import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData;
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
import eu.toldi.infinityforlemmy.subreddit.SubredditWithSelection;
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import retrofit2.Call;
@@ -98,6 +103,8 @@ public class SearchActivity extends BaseActivity {
ImageView clearSearchTextImageView;
@BindView(R.id.link_handler_image_view_search_activity)
ImageView linkHandlerImageView;
@BindView(R.id.delete_all_recent_searches_button_search_activity)
MaterialButton deleteAllSearchesButton;
@BindView(R.id.subreddit_name_relative_layout_search_activity)
RelativeLayout subredditNameRelativeLayout;
@BindView(R.id.search_in_text_view_search_activity)
@@ -124,6 +131,8 @@ public class SearchActivity extends BaseActivity {
SharedPreferences mNsfwAndSpoilerSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor executor;
private String mAccountName;
private String mAccessToken;
private String query;
@@ -163,6 +172,7 @@ public class SearchActivity extends BaseActivity {
setSupportActionBar(toolbar);
clearSearchTextImageView.setVisibility(View.GONE);
deleteAllSearchesButton.setVisibility(View.GONE);
searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false);
searchOnlyUsers = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_USERS, false);
@@ -182,9 +192,9 @@ public class SearchActivity extends BaseActivity {
if (searchOnlySubreddits) {
Intent returnIntent = new Intent();
if (getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false)) {
ArrayList<String> subredditNameList = new ArrayList<>();
subredditNameList.add(subredditData.getName());
returnIntent.putStringArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, subredditNameList);
ArrayList<SubredditWithSelection> subredditNameList = new ArrayList<>();
subredditNameList.add(new SubredditWithSelection(subredditData.getName(), subredditData.getIconUrl(), LemmyUtils.actorID2FullName(subredditData.getActorId())));
returnIntent.putParcelableArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, subredditNameList);
} else {
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, new SubscribedSubredditData(subredditData));
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, subredditData.getIconUrl());
@@ -254,7 +264,7 @@ public class SearchActivity extends BaseActivity {
});
searchEditText.setOnEditorActionListener((v, actionId, event) -> {
if ((actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_SEARCH) || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN )) {
if ((actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_SEARCH) || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)) {
if (!searchEditText.getText().toString().isEmpty()) {
search(searchEditText.getText().toString());
return true;
@@ -276,6 +286,17 @@ public class SearchActivity extends BaseActivity {
}
});
deleteAllSearchesButton.setOnClickListener(view -> {
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.confirm)
.setMessage(R.string.confirm_delete_all_recent_searches)
.setPositiveButton(R.string.yes, (dialogInterface, i) -> {
executor.execute(() -> mRedditDataRoomDatabase.recentSearchQueryDao().deleteAllRecentSearchQueries(mAccountName));
})
.setNegativeButton(R.string.no, null)
.show();
});
if (savedInstanceState != null) {
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
@@ -319,7 +340,7 @@ public class SearchActivity extends BaseActivity {
@Override
public void onDelete(RecentSearchQuery recentSearchQuery) {
DeleteRecentSearchQuery.deleteRecentSearchQueryListener(mRedditDataRoomDatabase, recentSearchQuery, () -> {});
executor.execute(() -> mRedditDataRoomDatabase.recentSearchQueryDao().deleteRecentSearchQueries(recentSearchQuery));
}
});
recyclerView.setVisibility(View.VISIBLE);
@@ -334,8 +355,10 @@ public class SearchActivity extends BaseActivity {
mRecentSearchQueryViewModel.getAllRecentSearchQueries().observe(this, recentSearchQueries -> {
if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) {
divider.setVisibility(View.VISIBLE);
deleteAllSearchesButton.setVisibility(View.VISIBLE);
} else {
divider.setVisibility(View.GONE);
deleteAllSearchesButton.setVisibility(View.GONE);
}
adapter.setRecentSearchQueries(recentSearchQueries);
});
@@ -364,6 +387,11 @@ public class SearchActivity extends BaseActivity {
intent.putExtra(SearchUsersResultActivity.EXTRA_QUERY, query);
intent.putExtra(SearchUsersResultActivity.EXTRA_IS_MULTI_SELECTION, getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false));
startActivityForResult(intent, USER_SEARCH_REQUEST_CODE);
} else if (query.startsWith("http://") || query.startsWith("https://")) {
Intent intent = new Intent(this, LinkResolverActivity.class);
intent.setData(Uri.parse(query));
startActivity(intent);
finish();
} else {
Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class);
intent.putExtra(SearchResultActivity.EXTRA_QUERY, query);
@@ -377,6 +405,7 @@ public class SearchActivity extends BaseActivity {
}
startActivity(intent);
finish();
}
}
@@ -401,6 +430,7 @@ public class SearchActivity extends BaseActivity {
linkHandlerImageView.setColorFilter(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor(), android.graphics.PorterDuff.Mode.SRC_IN);
int colorAccent = mCustomThemeWrapper.getColorAccent();
searchInTextView.setTextColor(colorAccent);
deleteAllSearchesButton.setIconTint(ColorStateList.valueOf(mCustomThemeWrapper.getPrimaryIconColor()));
subredditNameTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
divider.setBackgroundColor(mCustomThemeWrapper.getDividerColor());
if (typeface != null) {
@@ -433,18 +463,20 @@ public class SearchActivity extends BaseActivity {
if (resultCode == RESULT_OK && data != null) {
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
subredditName = communityData.getName();
subredditIsUser = false;
if (subredditName == null) {
if (communityData == null) {
subredditNameTextView.setText(R.string.all_communities);
} else {
subredditName = communityData.getName();
communityQualifiedName = communityData.getQualified_name();
subredditNameTextView.setText(subredditName);
}
} else if (requestCode == SUBREDDIT_SEARCH_REQUEST_CODE) {
Intent returnIntent = new Intent();
if (getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false)) {
returnIntent.putStringArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, data.getStringArrayListExtra(SearchSubredditsResultActivity.RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES));
returnIntent.putParcelableArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, data.getParcelableArrayListExtra(SearchSubredditsResultActivity.RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES));
} else {
SubscribedSubredditData communityData = data.getParcelableExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_NAME);
String iconUrl = data.getStringExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);

View File

@@ -38,6 +38,7 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
@@ -58,13 +59,13 @@ import eu.toldi.infinityforlemmy.bottomsheetfragments.FABMoreOptionsBottomSheetF
import eu.toldi.infinityforlemmy.bottomsheetfragments.PostLayoutBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.PostTypeBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.RandomBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.SearchPostSortTypeBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.SearchUserAndSubredditSortTypeBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.SortTimeBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.SortTypeBottomSheetFragment;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.events.ChangeNSFWEvent;
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
import eu.toldi.infinityforlemmy.fragments.CommentsListingFragment;
import eu.toldi.infinityforlemmy.fragments.PostFragment;
import eu.toldi.infinityforlemmy.fragments.SubredditListingFragment;
import eu.toldi.infinityforlemmy.fragments.UserListingFragment;
@@ -130,10 +131,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
SharedPreferences mCurrentAccountSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor executor;
private Call<String> subredditAutocompleteCall;
private String mAccessToken;
private String mAccountName;
private String mAccountQualifiedName;
private String mQuery;
private String mSubredditName;
@@ -244,7 +246,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
private void bindView(Bundle savedInstanceState) {
sectionsPagerAdapter = new SectionsPagerAdapter(this);
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(3);
viewPager2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false));
viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
@@ -269,6 +271,9 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
case 2:
Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.users));
break;
case 3:
Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.comments));
break;
}
}).attach();
fixViewPager2Sensitivity(viewPager2);
@@ -334,7 +339,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: {
Fragment fragment = sectionsPagerAdapter.getCurrentFragment();
if (fragment instanceof PostFragment) {
SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = SearchPostSortTypeBottomSheetFragment.getNewInstance(((PostFragment) fragment).getSortType());
SortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(SortTypeBottomSheetFragment.PAGE_TYPE_SEARCH,((PostFragment) fragment).getSortType());
searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag());
}
break;
@@ -392,25 +397,26 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
});
if (mAccountName != null && mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SEARCH_HISTORY, true) && !mInsertSearchQuerySuccess && mQuery != null) {
InsertRecentSearchQuery.insertRecentSearchQueryListener(mRedditDataRoomDatabase, mAccountQualifiedName,
mQuery, () -> mInsertSearchQuerySuccess = true);
InsertRecentSearchQuery.insertRecentSearchQueryListener(executor, new Handler(getMainLooper()),
mRedditDataRoomDatabase, mAccountQualifiedName, mQuery, () -> mInsertSearchQuerySuccess = true);
}
}
private void displaySortTypeBottomSheetFragment() {
Fragment fragment = sectionsPagerAdapter.getCurrentFragment();
if (fragment instanceof PostFragment) {
SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = SearchPostSortTypeBottomSheetFragment.getNewInstance(((PostFragment) fragment).getSortType());
SortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(SortTypeBottomSheetFragment.PAGE_TYPE_SEARCH,((PostFragment) fragment).getSortType());
searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag());
} else {
if (fragment instanceof SubredditListingFragment) {
SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment
= SearchUserAndSubredditSortTypeBottomSheetFragment.getNewInstance(viewPager2.getCurrentItem(), ((SubredditListingFragment) fragment).getSortType());
searchUserAndSubredditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchUserAndSubredditSortTypeBottomSheetFragment.getTag());
SortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(SortTypeBottomSheetFragment.PAGE_TYPE_SEARCH,((SubredditListingFragment) fragment).getSortType());
searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag());
} else if (fragment instanceof UserListingFragment) {
SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment
= SearchUserAndSubredditSortTypeBottomSheetFragment.getNewInstance(viewPager2.getCurrentItem(), ((UserListingFragment) fragment).getSortType());
searchUserAndSubredditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchUserAndSubredditSortTypeBottomSheetFragment.getTag());
SortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(SortTypeBottomSheetFragment.PAGE_TYPE_SEARCH,((UserListingFragment) fragment).getSortType());
searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag());
} else if (fragment instanceof CommentsListingFragment) {
SortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(SortTypeBottomSheetFragment.PAGE_TYPE_SEARCH,((CommentsListingFragment) fragment).getSortType());
searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag());
}
}
}
@@ -470,7 +476,6 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.changeSortType(sortType);
}
}
@Override
@@ -774,7 +779,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
mFragment.setArguments(bundle);
return mFragment;
}
@@ -789,7 +794,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
mFragment.setArguments(bundle);
return mFragment;
}
default: {
case 2: {
UserListingFragment mFragment = new UserListingFragment();
Bundle bundle = new Bundle();
bundle.putString(UserListingFragment.EXTRA_QUERY, mQuery);
@@ -799,6 +804,15 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
mFragment.setArguments(bundle);
return mFragment;
}
default: {
CommentsListingFragment mFragment = new CommentsListingFragment();
Bundle bundle = new Bundle();
bundle.putString(CommentsListingFragment.EXTRA_SEARCH_QUERY, mQuery);
bundle.putString(CommentsListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(CommentsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
mFragment.setArguments(bundle);
return mFragment;
}
}
}
@@ -823,9 +837,19 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
void changeSortType(SortType sortType) {
Fragment fragment = getCurrentFragment();
if (fragment instanceof PostFragment) {
((PostFragment) fragment).changeSortType(sortType);
displaySortTypeInToolbar();
} else if (fragment instanceof SubredditListingFragment) {
((SubredditListingFragment) fragment).changeSortType(sortType);
displaySortTypeInToolbar();
} else if (fragment instanceof UserListingFragment) {
((UserListingFragment) fragment).changeSortType(sortType);
displaySortTypeInToolbar();
} else if (fragment instanceof CommentsListingFragment) {
((CommentsListingFragment) fragment).changeSortType(sortType);
displaySortTypeInToolbar();
}
}
@@ -868,6 +892,8 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
((SubredditListingFragment) fragment).goBackToTop();
} else if (fragment instanceof UserListingFragment) {
((UserListingFragment) fragment).goBackToTop();
} else if (fragment instanceof CommentsListingFragment) {
((CommentsListingFragment) fragment).goBackToTop();
}
}
@@ -882,6 +908,9 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
} else if (fragment instanceof UserListingFragment) {
SortType sortType = ((UserListingFragment) fragment).getSortType();
Utils.displaySortTypeInToolbar(sortType, toolbar);
} else if (fragment instanceof CommentsListingFragment) {
SortType sortType = ((CommentsListingFragment) fragment).getSortType();
Utils.displaySortTypeInToolbar(sortType, toolbar);
}
}
@@ -901,7 +930,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
@Override
public int getItemCount() {
return 3;
return 4;
}
}

View File

@@ -35,6 +35,7 @@ import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
import eu.toldi.infinityforlemmy.fragments.SubredditListingFragment;
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
import eu.toldi.infinityforlemmy.subreddit.SubredditWithSelection;
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
@@ -171,9 +172,9 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
return true;
} else if (item.getItemId() == R.id.action_save_search_subreddits_result_activity) {
if (mFragment != null) {
ArrayList<String> selectedSubredditNames = ((SubredditListingFragment) mFragment).getSelectedSubredditNames();
ArrayList<SubredditWithSelection> selectedSubredditNames = ((SubredditListingFragment) mFragment).getSelectedSubredditNames();
Intent returnIntent = new Intent();
returnIntent.putStringArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, selectedSubredditNames);
returnIntent.putParcelableArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, selectedSubredditNames);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}

View File

@@ -138,7 +138,7 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo
flairEditText.requestFocus();
Utils.showKeyboard(this, new Handler(), flairEditText);
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.edit_flair)
.setTitle("")
.setView(dialogView)
.setPositiveButton(R.string.ok, (dialogInterface, i)
-> {
@@ -156,13 +156,13 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo
} else {
if (userFlair == null) {
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.clear_user_flair)
.setTitle("")
.setPositiveButton(R.string.yes, (dialogInterface, i) -> selectUserFlair(userFlair))
.setNegativeButton(R.string.no, null)
.show();
} else {
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.select_this_user_flair)
.setTitle("")
.setMessage(userFlair.getText())
.setPositiveButton(R.string.yes, (dialogInterface, i) -> selectUserFlair(userFlair))
.setNegativeButton(R.string.no, null)
@@ -181,9 +181,9 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo
@Override
public void success() {
if (userFlair == null) {
Toast.makeText(SelectUserFlairActivity.this, R.string.clear_user_flair_success, Toast.LENGTH_SHORT).show();
Toast.makeText(SelectUserFlairActivity.this, "", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(SelectUserFlairActivity.this, R.string.select_user_flair_success, Toast.LENGTH_SHORT).show();
Toast.makeText(SelectUserFlairActivity.this, "", Toast.LENGTH_SHORT).show();
}
finish();
}
@@ -192,9 +192,9 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo
public void failed(String errorMessage) {
if (errorMessage == null || errorMessage.equals("")) {
if (userFlair == null) {
Snackbar.make(coordinatorLayout, R.string.clear_user_flair_success, Snackbar.LENGTH_SHORT).show();
Snackbar.make(coordinatorLayout, "", Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(coordinatorLayout, R.string.select_user_flair_success, Snackbar.LENGTH_SHORT).show();
Snackbar.make(coordinatorLayout, "", Snackbar.LENGTH_SHORT).show();
}
} else {
Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_SHORT).show();

View File

@@ -18,7 +18,6 @@ import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.Collections;
import javax.inject.Inject;
import javax.inject.Named;
@@ -29,10 +28,10 @@ import eu.toldi.infinityforlemmy.ActivityToolbarInterface;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.adapters.SelectedSubredditsRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.bottomsheetfragments.SelectSubredditsOrUsersOptionsBottomSheetFragment;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.subreddit.SubredditWithSelection;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
public class SelectedSubredditsAndUsersActivity extends BaseActivity implements ActivityToolbarInterface {
@@ -62,7 +61,7 @@ public class SelectedSubredditsAndUsersActivity extends BaseActivity implements
CustomThemeWrapper mCustomThemeWrapper;
private LinearLayoutManagerBugFixed linearLayoutManager;
private SelectedSubredditsRecyclerViewAdapter adapter;
private ArrayList<String> subreddits;
private ArrayList<SubredditWithSelection> subreddits;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -86,12 +85,11 @@ public class SelectedSubredditsAndUsersActivity extends BaseActivity implements
setToolbarGoToTop(toolbar);
if (savedInstanceState != null) {
subreddits = savedInstanceState.getStringArrayList(SELECTED_SUBREDDITS_STATE);
subreddits = savedInstanceState.getParcelableArrayList(SELECTED_SUBREDDITS_STATE);
} else {
subreddits = getIntent().getStringArrayListExtra(EXTRA_SELECTED_SUBREDDITS);
subreddits = getIntent().getParcelableArrayListExtra(EXTRA_SELECTED_SUBREDDITS);
}
Collections.sort(subreddits);
adapter = new SelectedSubredditsRecyclerViewAdapter(this, mCustomThemeWrapper, subreddits);
linearLayoutManager = new LinearLayoutManagerBugFixed(this);
@@ -110,8 +108,7 @@ public class SelectedSubredditsAndUsersActivity extends BaseActivity implements
});
fab.setOnClickListener(view -> {
SelectSubredditsOrUsersOptionsBottomSheetFragment selectSubredditsOrUsersOptionsBottomSheetFragment = new SelectSubredditsOrUsersOptionsBottomSheetFragment();
selectSubredditsOrUsersOptionsBottomSheetFragment.show(getSupportFragmentManager(), selectSubredditsOrUsersOptionsBottomSheetFragment.getTag());
selectSubreddits();
});
}
@@ -158,7 +155,7 @@ public class SelectedSubredditsAndUsersActivity extends BaseActivity implements
if (subreddits == null) {
subreddits = new ArrayList<>();
}
subreddits = data.getStringArrayListExtra(SubredditMultiselectionActivity.EXTRA_RETURN_SELECTED_SUBREDDITS);
subreddits = data.getParcelableArrayListExtra(SubredditMultiselectionActivity.EXTRA_RETURN_SELECTED_SUBREDDITS);
adapter.addSubreddits(subreddits);
}
} else if (requestCode == USER_SELECTION_REQUEST_CODE) {
@@ -176,7 +173,7 @@ public class SelectedSubredditsAndUsersActivity extends BaseActivity implements
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
if (adapter != null) {
outState.putStringArrayList(SELECTED_SUBREDDITS_STATE, adapter.getSubreddits());
outState.putParcelableArrayList(SELECTED_SUBREDDITS_STATE, adapter.getSubreddits());
}
}

View File

@@ -81,7 +81,7 @@ public class SettingsActivity extends BaseActivity implements
setSupportActionBar(binding.toolbarSettingsActivity);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
if (savedInstanceState == null) {
getSupportFragmentManager()

View File

@@ -37,7 +37,7 @@ import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.materialswitch.MaterialSwitch;
import com.google.android.material.snackbar.Snackbar;
import com.libRG.CustomTextView;
import eu.toldi.infinityforlemmy.CustomTextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -71,7 +71,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
public class SubmitCrosspostActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback,
public class SubmitCrosspostActivity extends BaseActivity implements
AccountChooserBottomSheetFragment.AccountChooserListener {
public static final String EXTRA_POST = "EP";
@@ -110,10 +110,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
MaterialButton rulesButton;
@BindView(R.id.divider_1_submit_crosspost_activity)
View divider1;
@BindView(R.id.flair_custom_text_view_submit_crosspost_activity)
CustomTextView flairTextView;
@BindView(R.id.spoiler_custom_text_view_submit_crosspost_activity)
CustomTextView spoilerTextView;
@BindView(R.id.nsfw_custom_text_view_submit_crosspost_activity)
CustomTextView nsfwTextView;
@BindView(R.id.divider_2_submit_crosspost_activity)
@@ -242,7 +238,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
if (subredditName != null) {
subredditNameTextView.setTextColor(primaryTextColor);
subredditNameTextView.setText(subredditName);
flairTextView.setVisibility(View.VISIBLE);
if (!loadSubredditIconSuccessful) {
loadSubredditIcon();
}
@@ -253,17 +248,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
mPostingSnackbar.show();
}
if (flair != null) {
flairTextView.setText(flair.getText());
flairTextView.setBackgroundColor(flairBackgroundColor);
flairTextView.setBorderColor(flairBackgroundColor);
flairTextView.setTextColor(flairTextColor);
}
if (isSpoiler) {
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
spoilerTextView.setBorderColor(spoilerBackgroundColor);
spoilerTextView.setTextColor(spoilerTextColor);
}
if (isNSFW) {
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
nsfwTextView.setBorderColor(nsfwBackgroundColor);
@@ -287,13 +271,14 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
titleEditText.setText(post.getTitle());
}
if (post.getPostType() == Post.TEXT_TYPE) {
if (post.getPostType() == Post.TEXT_TYPE || post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
contentTextView.setVisibility(View.VISIBLE);
contentTextView.setText(post.getSelfTextPlain());
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
contentTextView.setVisibility(View.VISIBLE);
contentTextView.setText(post.getUrl());
contentTextView.setText(generateCrossPostText(post));
} else {
if (post.getSelfTextPlain() != null && !post.getSelfTextPlain().equals("")) {
contentTextView.setVisibility(View.VISIBLE);
contentTextView.setText(generateCrossPostText(post));
}
Post.Preview preview = getPreview(post);
if (preview != null) {
frameLayout.setVisibility(View.VISIBLE);
@@ -348,39 +333,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
}
});
flairTextView.setOnClickListener(view -> {
if (flair == null) {
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
if (subredditIsUser) {
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
} else {
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
}
flairSelectionBottomSheetFragment.setArguments(bundle);
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
} else {
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
flairTextView.setTextColor(primaryTextColor);
flairTextView.setText(getString(R.string.flair));
flair = null;
}
});
spoilerTextView.setOnClickListener(view -> {
if (!isSpoiler) {
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
spoilerTextView.setBorderColor(spoilerBackgroundColor);
spoilerTextView.setTextColor(spoilerTextColor);
isSpoiler = true;
} else {
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
spoilerTextView.setTextColor(primaryTextColor);
isSpoiler = false;
}
});
nsfwTextView.setOnClickListener(view -> {
if (!isNSFW) {
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
@@ -460,8 +412,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
flairTextView.setTextColor(primaryTextColor);
spoilerTextView.setTextColor(primaryTextColor);
nsfwTextView.setTextColor(primaryTextColor);
titleEditText.setTextColor(primaryTextColor);
titleEditText.setHintTextColor(secondaryTextColor);
@@ -473,8 +423,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
subredditNameTextView.setTypeface(typeface);
rulesButton.setTypeface(typeface);
receivePostReplyNotificationsTextView.setTypeface(typeface);
flairTextView.setTypeface(typeface);
spoilerTextView.setTypeface(typeface);
nsfwTextView.setTypeface(typeface);
titleEditText.setTypeface(typeface);
}
@@ -499,11 +447,11 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
});
mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;
});
}
private void promptAlertDialog(int titleResId, int messageResId) {
@@ -561,22 +509,19 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
mPostingSnackbar.show();
String subredditName;
if (subredditIsUser) {
subredditName = "u_" + subredditNameTextView.getText().toString();
} else {
subredditName = subredditNameTextView.getText().toString();
}
String subredditName = subredditNameTextView.getText().toString();
Intent intent = new Intent(this, SubmitPostService.class);
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
if (post.isCrosspost()) {
intent.putExtra(SubmitPostService.EXTRA_BODY, "t3_" + post.getCrosspostParentId());
} else {
intent.putExtra(SubmitPostService.EXTRA_BODY, post.getFullName());
intent.putExtra(SubmitPostService.EXTRA_BODY, generateCrossPostText(post));
if (post.getUrl() != null && !post.getUrl().equals("")) {
intent.putExtra(SubmitPostService.EXTRA_URL, post.getUrl());
}
intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_CROSSPOST);
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
@@ -635,10 +580,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
subredditNameTextView.setText(subredditName);
displaySubredditIcon();
flairTextView.setVisibility(View.VISIBLE);
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
flairTextView.setTextColor(primaryTextColor);
flairTextView.setText(getString(R.string.flair));
flair = null;
}
}
@@ -650,14 +591,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
super.onDestroy();
}
@Override
public void flairSelected(Flair flair) {
this.flair = flair;
flairTextView.setText(flair.getText());
flairTextView.setBackgroundColor(flairBackgroundColor);
flairTextView.setBorderColor(flairBackgroundColor);
flairTextView.setTextColor(flairTextColor);
}
@Override
public void onAccountSelected(Account account) {
@@ -699,4 +632,15 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
}
}
}
private static String generateCrossPostText(Post post) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("cross-posted from: ").append(post.getPermalink()).append("\n");
String[] lines = post.getSelfTextPlain().split("\n");
for (String line : lines) {
stringBuilder.append("> ").append(line).append("\n");
}
return stringBuilder.toString();
}
}

View File

@@ -37,13 +37,14 @@ import eu.toldi.infinityforlemmy.ActivityToolbarInterface;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.adapters.SubredditMultiselectionRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.subreddit.SubredditWithSelection;
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditViewModel;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class SubredditMultiselectionActivity extends BaseActivity implements ActivityToolbarInterface {
@@ -70,8 +71,8 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
@BindView(R.id.error_text_view_subscribed_subreddits_multiselection_activity)
TextView mErrorTextView;
@Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Named("no_oauth")
RetrofitHolder mRetrofit;
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
@@ -131,7 +132,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
mSwipeRefreshLayout.setEnabled(false);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-");
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, "-");
bindView();
}
@@ -150,7 +151,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
if (subscribedSubredditData == null || subscribedSubredditData.size() == 0) {
mRecyclerView.setVisibility(View.GONE);
mLinearLayout.setVisibility(View.VISIBLE);
mGlide.load(R.drawable.error_image).into(mImageView);
mGlide.load(R.mipmap.ic_launcher_round).into(mImageView);
} else {
mLinearLayout.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
@@ -177,7 +178,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
} else if (itemId == R.id.action_save_subreddit_multiselection_activity) {
if (mAdapter != null) {
Intent returnIntent = new Intent();
returnIntent.putStringArrayListExtra(EXTRA_RETURN_SELECTED_SUBREDDITS,
returnIntent.putExtra(EXTRA_RETURN_SELECTED_SUBREDDITS,
mAdapter.getAllSelectedSubreddits());
setResult(RESULT_OK, returnIntent);
}
@@ -198,12 +199,12 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SUBREDDIT_SEARCH_REQUEST_CODE && resultCode == RESULT_OK && data != null && mAdapter != null) {
Intent returnIntent = new Intent();
ArrayList<String> selectedSubreddits = mAdapter.getAllSelectedSubreddits();
ArrayList<String> searchedSubreddits = data.getStringArrayListExtra(SearchActivity.RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES);
ArrayList<SubredditWithSelection> selectedSubreddits = mAdapter.getAllSelectedSubreddits();
ArrayList<SubredditWithSelection> searchedSubreddits = data.getParcelableArrayListExtra(SearchActivity.RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES);
if (searchedSubreddits != null) {
selectedSubreddits.addAll(searchedSubreddits);
}
returnIntent.putStringArrayListExtra(EXTRA_RETURN_SELECTED_SUBREDDITS, selectedSubreddits);
returnIntent.putParcelableArrayListExtra(EXTRA_RETURN_SELECTED_SUBREDDITS, selectedSubreddits);
setResult(RESULT_OK, returnIntent);
finish();
}

View File

@@ -63,7 +63,6 @@ import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
import eu.toldi.infinityforlemmy.fragments.FollowedUsersListingFragment;
import eu.toldi.infinityforlemmy.fragments.MultiRedditListingFragment;
import eu.toldi.infinityforlemmy.fragments.SubscribedSubredditsListingFragment;
import eu.toldi.infinityforlemmy.multireddit.DeleteMultiReddit;
import eu.toldi.infinityforlemmy.multireddit.FetchMyMultiReddits;
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
@@ -112,6 +111,9 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
@Named("current_account")
SharedPreferences mCurrentAccountSharedPreferences;
@Inject
@Named("internal")
SharedPreferences mInternalSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
@@ -233,7 +235,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOffscreenPageLimit(1);
if (viewPager.getCurrentItem() != 2) {
if (viewPager.getCurrentItem() != 1) {
fab.hide();
}
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@@ -244,7 +246,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
fab.hide();
} else {
lockSwipeRightToGoBack();
if (position != 2) {
if (position != 1) {
fab.hide();
} else {
fab.show();
@@ -255,7 +257,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
tabLayout.setupWithViewPager(viewPager);
if (showMultiReddits) {
viewPager.setCurrentItem(2, false);
viewPager.setCurrentItem(1, false);
}
loadSubscriptions(false);
@@ -323,6 +325,10 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
}
public void loadSubscriptions(boolean forceLoad) {
if (!forceLoad && System.currentTimeMillis() - mInternalSharedPreferences.getLong(SharedPreferencesUtils.SUBSCRIBED_THINGS_SYNC_TIME, 0L) < 24 * 60 * 60 * 1000) {
return;
}
if (mAccessToken != null && !(!forceLoad && mInsertSuccess)) {
FetchSubscribedThing.fetchSubscribedThing(mRetrofit.getRetrofit(), mAccessToken, mAccountQualifiedName, null,
new ArrayList<>(), new ArrayList<>(),
@@ -332,6 +338,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
public void onFetchSubscribedThingSuccess(ArrayList<SubscribedSubredditData> subscribedSubredditData,
ArrayList<SubscribedUserData> subscribedUserData,
ArrayList<SubredditData> subredditData) {
mInternalSharedPreferences.edit().putLong(SharedPreferencesUtils.SUBSCRIBED_THINGS_SYNC_TIME, System.currentTimeMillis()).apply();
InsertSubscribedThings.insertSubscribedThings(
mExecutor,
new Handler(),
@@ -378,7 +385,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() {
@Override
public void success(ArrayList<MultiReddit> multiReddits) {
InsertMultireddit.insertMultireddits(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddits, mAccountName, () -> {
InsertMultireddit.insertMultireddits(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddits, mAccountQualifiedName, () -> {
mInsertMultiredditSuccess = true;
sectionsPagerAdapter.stopMultiRedditRefreshProgressbar();
});
@@ -400,27 +407,11 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
.setMessage(R.string.delete_multi_reddit_dialog_message)
.setPositiveButton(R.string.delete, (dialogInterface, i)
-> {
if (mAccessToken == null) {
DeleteMultiredditInDatabase.deleteMultiredditInDatabase(mExecutor, new Handler(), mRedditDataRoomDatabase, mAccountName, multiReddit.getPath(),
() -> Toast.makeText(SubscribedThingListingActivity.this,
R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show());
} else {
DeleteMultiReddit.deleteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase,
mAccessToken, mAccountName, multiReddit.getPath(), new DeleteMultiReddit.DeleteMultiRedditListener() {
@Override
public void success() {
Toast.makeText(SubscribedThingListingActivity.this,
R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show();
//loadMultiReddits();
}
@Override
public void failed() {
Toast.makeText(SubscribedThingListingActivity.this,
R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show();
}
});
}
DeleteMultiredditInDatabase.deleteMultiredditInDatabase(mExecutor, new Handler(), mRedditDataRoomDatabase, mAccountQualifiedName, multiReddit.getPath(),
() -> Toast.makeText(SubscribedThingListingActivity.this,
R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show());
})
.setNegativeButton(R.string.cancel, null)
.show();
@@ -476,7 +467,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
@Override
public Fragment getItem(int position) {
switch (position) {
default:
case 0: {
SubscribedSubredditsListingFragment fragment = new SubscribedSubredditsListingFragment();
Bundle bundle = new Bundle();
@@ -487,12 +478,20 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
fragment.setArguments(bundle);
return fragment;
}
default: {
MultiRedditListingFragment fragment = new MultiRedditListingFragment();
Bundle bundle = new Bundle();
bundle.putString(MultiRedditListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(MultiRedditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName == null ? "-" : mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
}
}
}
@Override
public int getCount() {
return 1;
return 2;
}
@Override
@@ -501,8 +500,6 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
case 0:
return Utils.getTabTextWithCustomFont(typeface, getString(R.string.communities));
case 1:
return Utils.getTabTextWithCustomFont(typeface, getString(R.string.users));
case 2:
return Utils.getTabTextWithCustomFont(typeface, getString(R.string.multi_reddits));
}
@@ -515,8 +512,6 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
Fragment fragment = (Fragment) super.instantiateItem(container, position);
if (position == 0) {
subscribedSubredditsListingFragment = (SubscribedSubredditsListingFragment) fragment;
} else if (position == 1) {
followedUsersListingFragment = (FollowedUsersListingFragment) fragment;
} else {
multiRedditListingFragment = (MultiRedditListingFragment) fragment;
}

View File

@@ -278,7 +278,7 @@ public class TrendingActivity extends BaseActivity {
private void showErrorView(int stringId) {
errorLinearLayout.setVisibility(View.VISIBLE);
mGlide.load(R.drawable.error_image).into(errorImageView);
mGlide.load(R.mipmap.ic_launcher_round).into(errorImageView);
errorTextView.setText(stringId);
}

View File

@@ -78,6 +78,7 @@ import eu.toldi.infinityforlemmy.font.TitleFontStyle;
import eu.toldi.infinityforlemmy.services.DownloadMediaService;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import okhttp3.OkHttpClient;
public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWallpaperCallback, CustomFontReceiver {
@@ -108,6 +109,9 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
@Named("glide")
OkHttpClient okHttpClient;
@Inject
Executor mExecutor;
private boolean isActionBarHidden = false;
private boolean isDownloading = false;
@@ -146,7 +150,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
getTheme().applyStyle(ContentFontFamily.valueOf(mSharedPreferences
.getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true);
BigImageViewer.initialize(GlideImageLoader.with(this.getApplicationContext()));
BigImageViewer.initialize(GlideImageLoader.with(this.getApplicationContext(), okHttpClient));
setContentView(R.layout.activity_view_image_or_gif);

View File

@@ -62,10 +62,8 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.NavigationWrapper;
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.events.GoBackToMainPageEvent;
import eu.toldi.infinityforlemmy.events.RefreshMultiRedditsEvent;
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
import eu.toldi.infinityforlemmy.fragments.PostFragment;
import eu.toldi.infinityforlemmy.multireddit.DeleteMultiReddit;
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
import eu.toldi.infinityforlemmy.post.Post;
@@ -430,7 +428,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
bundle.putString(PostFragment.EXTRA_NAME, multiPath);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT : PostPagingSource.TYPE_MULTI_REDDIT);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
mFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_multi_reddit_detail_activity, mFragment).commit();
}
@@ -592,7 +590,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
private void showSortTypeBottomSheetFragment() {
if (mFragment instanceof PostFragment) {
SortTypeBottomSheetFragment sortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(true, ((PostFragment) mFragment).getSortType());
SortTypeBottomSheetFragment sortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(SortTypeBottomSheetFragment.PAGE_TYPE_MULTICOMMUNITY, ((PostFragment) mFragment).getSortType());
sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag());
}
}
@@ -678,7 +676,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
-> {
Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString());
startActivity(subredditIntent);
})
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
@@ -699,7 +697,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString());
startActivity(userIntent);
return true;
}
@@ -764,6 +762,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
Intent editIntent = new Intent(this, EditMultiRedditActivity.class);
editIntent.putExtra(EditMultiRedditActivity.EXTRA_MULTI_PATH, multiPath);
startActivity(editIntent);
finish();
return true;
} else if (itemId == R.id.action_delete_view_multi_reddit_detail_activity) {
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
@@ -771,30 +770,13 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
.setMessage(R.string.delete_multi_reddit_dialog_message)
.setPositiveButton(R.string.delete, (dialogInterface, i)
-> {
if (mAccessToken == null) {
DeleteMultiredditInDatabase.deleteMultiredditInDatabase(mExecutor, new Handler(), mRedditDataRoomDatabase, mAccountName, multiPath,
() -> {
Toast.makeText(this, R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show();
finish();
});
} else {
DeleteMultiReddit.deleteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase,
mAccessToken, mAccountName, multiPath, new DeleteMultiReddit.DeleteMultiRedditListener() {
@Override
public void success() {
Toast.makeText(ViewMultiRedditDetailActivity.this,
R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new RefreshMultiRedditsEvent());
finish();
}
@Override
public void failed() {
Toast.makeText(ViewMultiRedditDetailActivity.this,
R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show();
}
});
}
DeleteMultiredditInDatabase.deleteMultiredditInDatabase(mExecutor, new Handler(), mRedditDataRoomDatabase, mAccountName, multiPath,
() -> {
Toast.makeText(this, R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show();
finish();
});
})
.setNegativeButton(R.string.cancel, null)
.show();

View File

@@ -67,6 +67,7 @@ import eu.toldi.infinityforlemmy.SaveComment;
import eu.toldi.infinityforlemmy.SaveThing;
import eu.toldi.infinityforlemmy.SortType;
import eu.toldi.infinityforlemmy.SortTypeSelectionCallback;
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.apis.RedditAPI;
import eu.toldi.infinityforlemmy.asynctasks.SwitchAccount;
import eu.toldi.infinityforlemmy.comment.Comment;
@@ -81,10 +82,12 @@ import eu.toldi.infinityforlemmy.post.HistoryPostPagingSource;
import eu.toldi.infinityforlemmy.post.ParsePost;
import eu.toldi.infinityforlemmy.post.Post;
import eu.toldi.infinityforlemmy.post.PostPagingSource;
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
import eu.toldi.infinityforlemmy.readpost.ReadPost;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
@@ -147,6 +150,11 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
@Inject
@Named("glide")
OkHttpClient okHttpClient;
@Inject
PostEnricher postEnricher;
@State
ArrayList<Post> posts;
@State
@@ -195,7 +203,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
super.onCreate(savedInstanceState);
BigImageViewer.initialize(GlideImageLoader.with(this.getApplicationContext()));
BigImageViewer.initialize(GlideImageLoader.with(this.getApplicationContext(), okHttpClient));
setContentView(R.layout.activity_view_post_detail);
@@ -526,69 +534,38 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
Handler handler = new Handler(Looper.getMainLooper());
if (postType != HistoryPostPagingSource.TYPE_READ_POSTS) {
int nextPage = posts.size() / 25 + 1;
mExecutor.execute(() -> {
RedditAPI api = (mAccessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit).create(RedditAPI.class);
LemmyAPI api = mRetrofit.getRetrofit().create(LemmyAPI.class);
Call<String> call;
String afterKey = posts.isEmpty() ? null : posts.get(posts.size() - 1).getFullName();
switch (postType) {
case PostPagingSource.TYPE_SUBREDDIT:
if (mAccessToken == null) {
call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey);
} else {
call = api.getSubredditBestPostsOauth(subredditName, sortType,
sortTime, afterKey, APIUtils.getOAuthHeader(mAccessToken));
}
call = api.getPosts(null, sortType.value, nextPage, 25, null, post.getSubredditNamePrefixed(), false, mAccessToken);
break;
case PostPagingSource.TYPE_USER:
if (mAccessToken == null) {
call = api.getUserPosts(username, afterKey, sortType, sortTime);
} else {
call = api.getUserPostsOauth(username, userWhere, afterKey, sortType,
sortTime, APIUtils.getOAuthHeader(mAccessToken));
}
call = api.getUserPosts(username, sortType.value, nextPage, 25, false, mAccessToken);
break;
case PostPagingSource.TYPE_SEARCH:
if (subredditName == null) {
if (mAccessToken == null) {
call = api.searchPosts(query, afterKey, sortType, sortTime,
trendingSource);
} else {
call = api.searchPostsOauth(query, afterKey, sortType,
sortTime, trendingSource, APIUtils.getOAuthHeader(mAccessToken));
}
} else {
if (mAccessToken == null) {
call = api.searchPostsInSpecificSubreddit(subredditName, query,
sortType, sortTime, afterKey);
} else {
call = api.searchPostsInSpecificSubredditOauth(subredditName, query,
sortType, sortTime, afterKey,
APIUtils.getOAuthHeader(mAccessToken));
}
}
call = api.search(query, null, subredditName, null, "Post", sortType.value, "All", nextPage, 25, mAccessToken);
break;
case PostPagingSource.TYPE_MULTI_REDDIT:
if (mAccessToken == null) {
call = api.getMultiRedditPosts(multiPath, afterKey, sortTime);
} else {
call = api.getMultiRedditPostsOauth(multiPath, afterKey,
sortTime, APIUtils.getOAuthHeader(mAccessToken));
}
break;
// TODO: Implement multi community
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
//case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT
call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey);
break;
// TODO: Implement anonymous front page
default:
call = api.getBestPosts(sortType, sortTime, afterKey,
APIUtils.getOAuthHeader(mAccessToken));
String type = (subredditName == null) ? "Subscribed" : (subredditName.equals("all")) ? "All" : "Local";
call = api.getPosts(type, sortType.value, nextPage, 25, null, null, false, mAccessToken);
}
try {
Response<String> response = call.execute();
if (response.isSuccessful()) {
String responseString = response.body();
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, readPostList);
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, readPostList, postEnricher);
if (newPosts == null) {
handler.post(() -> {
loadingMorePostsStatus = LoadingMorePostsStatus.NO_MORE_POSTS;
@@ -670,7 +647,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
Response<String> response = historyPosts.execute();
if (response.isSuccessful()) {
String responseString = response.body();
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null);
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null, postEnricher);
if (newPosts == null || newPosts.isEmpty()) {
handler.post(() -> {
loadingMorePostsStatus = LoadingMorePostsStatus.NO_MORE_POSTS;

View File

@@ -1,9 +1,13 @@
package eu.toldi.infinityforlemmy.activities;
import static android.graphics.BitmapFactory.decodeResource;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -40,6 +44,8 @@ import androidx.viewpager2.widget.ViewPager2;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.evernote.android.state.State;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
@@ -104,6 +110,7 @@ import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
import eu.toldi.infinityforlemmy.post.Post;
import eu.toldi.infinityforlemmy.post.PostPagingSource;
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
import eu.toldi.infinityforlemmy.shortcut.ShortcutManager;
import eu.toldi.infinityforlemmy.subreddit.CommunitySubscription;
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData;
@@ -260,10 +267,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private int subscribedColor;
private int fabOption;
private MaterialAlertDialogBuilder nsfwWarningBuilder;
private Bitmap subredditIconBitmap;
private boolean showStatistics;
private boolean disableImagePreview;
private boolean hideSubredditDescription;
private boolean isKbinMagazine = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -277,6 +288,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
hideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_FAB_IN_POST_FEED, false);
showStatistics = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_STATISTICS, true);
disableImagePreview = mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
showBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, false);
navigationWrapper = new NavigationWrapper(findViewById(R.id.bottom_app_bar_bottom_app_bar), findViewById(R.id.linear_layout_bottom_app_bar),
findViewById(R.id.option_1_bottom_app_bar), findViewById(R.id.option_2_bottom_app_bar),
@@ -380,6 +392,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
if (mAccessToken != null) {
mRetrofit.setAccessToken(mAccessToken);
}
String instance = (mAccessToken == null) ? mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI) : mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
if (instance != null) {
mRetrofit.setBaseURL(instance);
}
if (savedInstanceState == null) {
mMessageFullname = getIntent().getIntExtra(EXTRA_MESSAGE_FULLNAME, 0);
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
@@ -538,7 +558,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
return true;
};
Markwon markwon = MarkdownUtils.createDescriptionMarkwon(this, miscPlugin, onLinkLongClickListener);
Markwon markwon = MarkdownUtils.createDescriptionMarkwon(this, miscPlugin, onLinkLongClickListener, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
descriptionTextView.setOnLongClickListener(view -> {
if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
@@ -546,10 +566,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
return true;
});
String actorID = (!isKbinMagazine) ? LemmyUtils.qualifiedCommunityName2ActorId(qualifiedName) : LemmyUtils.qualifiedMagazineName2ActorId(qualifiedName);
mSubredditViewModel = new ViewModelProvider(this,
new SubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, LemmyUtils.qualifiedCommunityName2ActorId(qualifiedName)))
new SubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, actorID))
.get(SubredditViewModel.class);
addObserverToLiveData();
}
private void addObserverToLiveData() {
mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> {
if (subredditData != null) {
isNsfwSubreddit = subredditData.isNSFW();
@@ -575,11 +599,23 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
.into(iconGifImageView);
iconGifImageView.setOnClickListener(null);
} else {
glide.load(subredditData.getIconUrl())
glide.asBitmap()
.load(subredditData.getIconUrl())
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0)))
.error(glide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0))))
.into(iconGifImageView);
.into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
subredditIconBitmap = resource;
iconGifImageView.setImageBitmap(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
subredditIconBitmap = null;
}
});
iconGifImageView.setOnClickListener(view -> {
Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageOrGifActivity.class);
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, subredditData.getIconUrl());
@@ -745,6 +781,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
communityName = communityData.getTitle();
}
mCommunityStats = communityData.getCommunityStats();
if (communityData.getActorId().contains("/m/")) {
isKbinMagazine = true;
if (mSubredditViewModel != null) {
// Remove current observer
mSubredditViewModel.getSubredditLiveData().removeObservers(ViewSubredditDetailActivity.this);
addObserverToLiveData();
}
}
setupVisibleElements();
communityId = communityData.getId();
ViewSubredditDetailActivity.this.communityData = communityData;
@@ -1148,7 +1192,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
});
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(2);
viewPager2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false));
new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
switch (position) {
@@ -1170,7 +1214,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private void displaySortTypeBottomSheetFragment() {
Fragment fragment = fragmentManager.findFragmentByTag("f0");
if (fragment instanceof PostFragment) {
SortTypeBottomSheetFragment sortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(true, ((PostFragment) fragment).getSortType());
SortTypeBottomSheetFragment sortTypeBottomSheetFragment = SortTypeBottomSheetFragment.getNewInstance(SortTypeBottomSheetFragment.PAGE_TYPE_COMMUNITY, ((PostFragment) fragment).getSortType());
sortTypeBottomSheetFragment.show(fragmentManager, sortTypeBottomSheetFragment.getTag());
}
}
@@ -1274,6 +1318,15 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
});
return true;
} else if (itemId == R.id.action_add_to_home_screen_view_subreddit_detail_activity) {
Bitmap icon = subredditIconBitmap == null ? decodeResource(getResources(), R.drawable.subreddit_default_icon) : subredditIconBitmap;
return ShortcutManager.requestPinShortcut(this, qualifiedName, icon);
} else if (itemId == R.id.action_view_instance_view_subreddit_detail_activity) {
String instance = communityData.getActorId().split("/")[2];
Intent intent = new Intent(this,InstanceInfoActivity.class);
intent.putExtra(InstanceInfoActivity.EXTRA_INSTANCE_DOMAIN, instance);
intent.putExtra(InstanceInfoActivity.EXTRA_INSTANCE_ID, communityData.getInstanceId());
startActivity(intent);
}
return false;
}
@@ -1518,7 +1571,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
String communityName = thingEditText.getText().toString();
if (communityName.startsWith("!")) {
communityName = communityName.substring(1);
}
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
startActivity(subredditIntent);
return true;
}
@@ -1576,7 +1633,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
-> {
Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
String communityName = thingEditText.getText().toString();
if (communityName.startsWith("!")) {
communityName = communityName.substring(1);
}
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
startActivity(subredditIntent);
})
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
@@ -1597,7 +1658,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
String qualifiedName = thingEditText.getText().toString();
if (qualifiedName.startsWith("@")) {
qualifiedName = qualifiedName.substring(1);
}
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
startActivity(userIntent);
return true;
}
@@ -1610,7 +1675,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
-> {
Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
String qualifiedName = thingEditText.getText().toString();
if (qualifiedName.startsWith("@")) {
qualifiedName = qualifiedName.substring(1);
}
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
startActivity(userIntent);
})
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
@@ -1682,7 +1751,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
bundle.putString(PostFragment.EXTRA_NAME, qualifiedName);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SUBREDDIT);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
}
@@ -1692,6 +1761,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
bundle.putString(SidebarFragment.EXTRA_SUBREDDIT_NAME, communityName);
bundle.putString(SidebarFragment.EXTRA_COMMUNITY_QUALIFIED_NAME, qualifiedName);
bundle.putBoolean(SidebarFragment.EXTRA_SHOW_STATISTICS, !showStatistics);
bundle.putBoolean(SidebarFragment.EXTRA_DISABLE_IMAGE_PREVIEW, disableImagePreview);
fragment.setArguments(bundle);
return fragment;
}

View File

@@ -83,6 +83,7 @@ import eu.toldi.infinityforlemmy.asynctasks.AddSubredditOrUserToMultiReddit;
import eu.toldi.infinityforlemmy.asynctasks.CheckIsFollowingUser;
import eu.toldi.infinityforlemmy.asynctasks.SwitchAccount;
import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityData;
import eu.toldi.infinityforlemmy.blockedinstances.BlockedInstanceData;
import eu.toldi.infinityforlemmy.blockeduser.BlockedUserData;
import eu.toldi.infinityforlemmy.bottomsheetfragments.CopyTextBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.FABMoreOptionsBottomSheetFragment;
@@ -188,21 +189,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
@BindView(R.id.comment_count_text_view_view_user_detail_activity)
TextView commentCountTextView;
@BindView(R.id.upvote_count_post_text_view_view_user_detail_activity)
TextView upvoteCountPostTextView;
@BindView(R.id.upvote_count_comment_text_view_view_user_detail_activity)
TextView upvoteCountCommentTextView;
@BindView(R.id.posts_count_icon_image_view_view_user_detail_activity)
ImageView postsCountIconImageView;
@BindView(R.id.comments_count_icon_image_view_view_user_detail_activity)
ImageView commentsCountIconImageView;
@BindView(R.id.upvote_count_posts_icon_image_view_view_user_detail_activity)
ImageView postUpvoteCountIconImageView;
@BindView(R.id.upvote_count_comments_icon_image_view_view_user_detail_activity)
ImageView commentUpvoteCountIconImageView;
@BindView(R.id.account_created_cake_icon_image_view_view_user_detail_activity)
ImageView accountCreatedCakeIconImageView;
@@ -261,7 +252,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
private String description;
private boolean showStatistics;
private boolean showScore;
private boolean subscriptionReady = false;
private boolean mFetchUserInfoSuccess = false;
private int expandedTabTextColor;
@@ -327,7 +317,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false);
showStatistics = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_STATISTICS, true);
showScore = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_POST_AND_COMMENT_SCORE, true);
if (savedInstanceState == null) {
mMessageId = getIntent().getIntExtra(EXTRA_MESSAGE_FULLNAME, 0);
@@ -472,7 +461,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
urlMenuBottomSheetFragment.show(getSupportFragmentManager(), null);
return true;
};
Markwon markwon = MarkdownUtils.createDescriptionMarkwon(this, miscPlugin, onLinkLongClickListener);
Markwon markwon = MarkdownUtils.createDescriptionMarkwon(this, miscPlugin, onLinkLongClickListener, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
descriptionTextView.setOnLongClickListener(view -> {
if (description != null && !description.equals("") && descriptionTextView.getSelectionStart() == -1 && descriptionTextView.getSelectionEnd() == -1) {
@@ -630,17 +619,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
UserStats userStats = mUserData.getStats();
if (userStats != null && showStatistics) {
userStatisticsBlock.setVisibility(View.VISIBLE);
postCountTextView.setText(String.valueOf(userStats.getPostCount()));
commentCountTextView.setText(String.valueOf(userStats.getCommentCount()));
if (showScore) {
upvoteCountPostTextView.setText(String.valueOf(userStats.getPostScore()));
upvoteCountCommentTextView.setText(String.valueOf(userStats.getCommentScore()));
} else {
upvoteCountPostTextView.setVisibility(View.GONE);
upvoteCountCommentTextView.setVisibility(View.GONE);
postUpvoteCountIconImageView.setVisibility(View.GONE);
commentUpvoteCountIconImageView.setVisibility(View.GONE);
}
postCountTextView.setText(getString(R.string.post_count_detail, userStats.getPostCount()));
commentCountTextView.setText(getString(R.string.comment_count_detail, userStats.getCommentCount()));
}
if (userData.getDescription() == null || userData.getDescription().equals("")) {
@@ -710,9 +690,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
subscribedColor = mCustomThemeWrapper.getSubscribed();
userNameTextView.setTextColor(mCustomThemeWrapper.getUsername());
postCountTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
upvoteCountPostTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
commentCountTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
upvoteCountCommentTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
postsCountIconImageView.setColorFilter(mCustomThemeWrapper.getPrimaryTextColor(), PorterDuff.Mode.SRC_IN);
commentsCountIconImageView.setColorFilter(mCustomThemeWrapper.getPrimaryTextColor(), PorterDuff.Mode.SRC_IN);
accountCreatedCakeIconImageView.setColorFilter(mCustomThemeWrapper.getPrimaryTextColor(), PorterDuff.Mode.SRC_IN);
@@ -725,9 +703,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
if (typeface != null) {
userNameTextView.setTypeface(typeface);
postCountTextView.setTypeface(typeface);
upvoteCountPostTextView.setTypeface(typeface);
commentCountTextView.setTypeface(typeface);
upvoteCountCommentTextView.setTypeface(typeface);
cakedayTextView.setTypeface(typeface);
subscribeUserChip.setTypeface(typeface);
descriptionTextView.setTypeface(typeface);
@@ -761,7 +737,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
private void initializeViewPager() {
sectionsPagerAdapter = new SectionsPagerAdapter(this);
viewPager2.setAdapter(sectionsPagerAdapter);
viewPager2.setOffscreenPageLimit(2);
viewPager2.setOffscreenPageLimit(ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT);
viewPager2.setUserInputEnabled(!mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_SWIPING_BETWEEN_TABS, false));
new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
switch (position) {
@@ -1179,7 +1155,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
FetchBlockedThings.fetchBlockedThings(mRetrofit.getRetrofit(), mAccessToken, mAccountQualifiedName, new FetchBlockedThings.FetchBlockedThingsListener() {
@Override
public void onFetchBlockedThingsSuccess(List<BlockedUserData> blockedUsers, List<BlockedCommunityData> blockedCommunities) {
public void onFetchBlockedThingsSuccess(List<BlockedUserData> blockedUsers, List<BlockedCommunityData> blockedCommunities, List<BlockedInstanceData> blockedInstances) {
for (BlockedUserData blockedUserData : blockedUsers) {
if (blockedUserData.getQualifiedName().equals(qualifiedName)) {
isBlocked = true;
@@ -1233,7 +1209,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
getMenuInflater().inflate(R.menu.view_user_detail_activity, menu);
if (username.equals(mAccountName)) {
menu.findItem(R.id.action_send_private_message_view_user_detail_activity).setVisible(false);
menu.findItem(R.id.action_report_view_user_detail_activity).setVisible(false);
menu.findItem(R.id.action_block_user_view_user_detail_activity).setVisible(false);
} else {
menu.findItem(R.id.action_edit_profile_view_user_detail_activity).setVisible(false);
@@ -1299,11 +1274,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
intent.putExtra(PostFilterPreferenceActivity.EXTRA_USER_NAME, username);
startActivity(intent);
return true;
} else if (itemId == R.id.action_report_view_user_detail_activity) {
Intent reportIntent = new Intent(this, LinkResolverActivity.class);
reportIntent.setData(Uri.parse("https://www.reddithelp.com/en/categories/rules-reporting/account-and-community-restrictions/what-should-i-do-if-i-see-something-i"));
startActivity(reportIntent);
return true;
} else if (itemId == R.id.action_block_user_view_user_detail_activity) {
if (mAccessToken == null) {
Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show();
@@ -1353,6 +1323,12 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
Toast.makeText(ViewUserDetailActivity.this, R.string.unblock_user_failed, Toast.LENGTH_SHORT).show();
}
});
} else if (itemId == R.id.action_view_instance_view_user_detail_activity) {
String instance = mUserData.getActorId().split("/")[2];
Intent intent = new Intent(this, InstanceInfoActivity.class);
intent.putExtra(InstanceInfoActivity.EXTRA_INSTANCE_DOMAIN, instance);
intent.putExtra(InstanceInfoActivity.EXTRA_INSTANCE_ID, mUserData.getInstanceId());
startActivity(intent);
}
return false;
}
@@ -1514,7 +1490,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
String communityName = thingEditText.getText().toString();
if (communityName.startsWith("!")) {
communityName = communityName.substring(1);
}
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
startActivity(subredditIntent);
return true;
}
@@ -1572,7 +1552,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
-> {
Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
String communityName = thingEditText.getText().toString();
if (communityName.startsWith("!")) {
communityName = communityName.substring(1);
}
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
startActivity(subredditIntent);
})
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
@@ -1593,7 +1577,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
String userName = thingEditText.getText().toString();
if (userName.startsWith("@")) {
userName = userName.substring(1);
}
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, userName);
startActivity(userIntent);
return true;
}
@@ -1606,7 +1594,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
-> {
Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
String userName = thingEditText.getText().toString();
if (userName.startsWith("@")) {
userName = userName.substring(1);
}
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, userName);
startActivity(userIntent);
})
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
@@ -1773,7 +1765,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
bundle.putString(PostFragment.EXTRA_USER_NAME, qualifiedName);
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SUBMITTED);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
fragment.setArguments(bundle);
return fragment;
}

View File

@@ -23,14 +23,11 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.view.OrientationEventListener;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
@@ -70,7 +67,7 @@ import com.google.android.exoplayer2.upstream.cache.SimpleCache;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.video.VideoSize;
import com.google.android.material.bottomappbar.BottomAppBar;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.button.MaterialButton;
import com.google.common.collect.ImmutableList;
import com.otaliastudios.zoom.ZoomEngine;
import com.otaliastudios.zoom.ZoomSurfaceView;
@@ -90,7 +87,7 @@ import app.futured.hauler.LockableNestedScrollView;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.CustomFontReceiver;
import eu.toldi.infinityforlemmy.FetchGfycatOrRedgifsVideoLinks;
import eu.toldi.infinityforlemmy.FetchRedgifsVideoLinks;
import eu.toldi.infinityforlemmy.FetchStreamableVideo;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
@@ -108,6 +105,7 @@ import eu.toldi.infinityforlemmy.font.TitleFontFamily;
import eu.toldi.infinityforlemmy.font.TitleFontStyle;
import eu.toldi.infinityforlemmy.post.FetchPost;
import eu.toldi.infinityforlemmy.post.Post;
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
import eu.toldi.infinityforlemmy.services.DownloadMediaService;
import eu.toldi.infinityforlemmy.services.DownloadRedditVideoService;
import eu.toldi.infinityforlemmy.utils.APIUtils;
@@ -131,10 +129,10 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
public static final String EXTRA_VIDEO_DOWNLOAD_URL = "EVDU";
public static final String EXTRA_SUBREDDIT = "ES";
public static final String EXTRA_ID = "EI";
public static final String EXTRA_POST_TITLE = "EPT";
public static final String EXTRA_POST = "EP";
public static final String EXTRA_PROGRESS_SECONDS = "EPS";
public static final String EXTRA_VIDEO_TYPE = "EVT";
public static final String EXTRA_GFYCAT_ID = "EGI";
public static final String EXTRA_REDGIFS_ID = "ERI";
public static final String EXTRA_V_REDD_IT_URL = "EVRIU";
public static final String EXTRA_STREAMABLE_SHORT_CODE = "ESSC";
public static final String EXTRA_IS_NSFW = "EIN";
@@ -143,7 +141,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
public static final int VIDEO_TYPE_V_REDD_IT = 4;
public static final int VIDEO_TYPE_DIRECT = 3;
public static final int VIDEO_TYPE_REDGIFS = 2;
public static final int VIDEO_TYPE_GFYCAT = 1;
private static final int VIDEO_TYPE_NORMAL = 0;
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
@@ -162,17 +159,19 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
@BindView(R.id.progress_bar_view_video_activity)
ProgressBar progressBar;
@BindView(R.id.mute_exo_playback_control_view)
ImageButton muteButton;
MaterialButton muteButton;
@BindView(R.id.hd_exo_playback_control_view)
ImageButton hdButton;
MaterialButton hdButton;
@BindView(R.id.bottom_navigation_exo_playback_control_view)
BottomAppBar bottomAppBar;
@BindView(R.id.title_text_view_exo_playback_control_view)
TextView titleTextView;
@BindView(R.id.back_button_exo_playback_control_view)
MaterialButton backButton;
@BindView(R.id.download_image_view_exo_playback_control_view)
ImageView downloadImageView;
MaterialButton downloadButton;
@BindView(R.id.playback_speed_image_view_exo_playback_control_view)
ImageView playbackSpeedImageView;
MaterialButton playbackSpeedButton;
@BindView(R.id.lockable_nested_scroll_view_view_video_activity)
LockableNestedScrollView nestedScrollView;
@@ -203,10 +202,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
@Named("no_oauth")
RetrofitHolder retrofit;
@Inject
@Named("gfycat")
Retrofit gfycatRetrofit;
@Inject
@Named("redgifs")
Retrofit redgifsRetrofit;
@@ -222,10 +217,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
@Named("current_account")
SharedPreferences mCurrentAccountSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@@ -235,6 +226,9 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
@Inject
SimpleCache mSimpleCache;
@Inject
PostEnricher postEnricher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -301,6 +295,12 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
ButterKnife.bind(this);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
setTitle(" ");
if (typeface != null) {
titleTextView.setTypeface(typeface);
}
Resources resources = getResources();
getWindow().getDecorView().setSystemUiVisibility(
@@ -312,7 +312,11 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
if (useBottomAppBar) {
getSupportActionBar().hide();
bottomAppBar.setVisibility(View.VISIBLE);
downloadImageView.setOnClickListener(view -> {
backButton.setOnClickListener(view -> {
finish();
});
downloadButton.setOnClickListener(view -> {
if (isDownloading) {
return;
}
@@ -326,12 +330,8 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
requestPermissionAndDownload();
});
playbackSpeedImageView.setOnClickListener(view -> {
PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed);
playbackSpeedBottomSheetFragment.setArguments(bundle);
playbackSpeedBottomSheetFragment.show(getSupportFragmentManager(), playbackSpeedBottomSheetFragment.getTag());
playbackSpeedButton.setOnClickListener(view -> {
changePlaybackSpeed();
});
} else {
ActionBar actionBar = getSupportActionBar();
@@ -402,12 +402,15 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
};
orientationEventListener.enable();
}
} catch (Exception ignore) {}
} catch (Exception ignore) {
}
}
}
String postTitle = intent.getStringExtra(EXTRA_POST_TITLE);
setSmallTitle(postTitle);
Post post = intent.getParcelableExtra(EXTRA_POST);
if (post != null) {
titleTextView.setText(post.getTitle());
}
trackSelector = new DefaultTrackSelector(this);
if (videoType == VIDEO_TYPE_NORMAL && isDataSavingMode && dataSavingModeDefaultResolution > 0) {
@@ -539,29 +542,21 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
}
} else if (videoType == VIDEO_TYPE_V_REDD_IT) {
loadVReddItVideo(savedInstanceState);
} else if (videoType == VIDEO_TYPE_GFYCAT || videoType == VIDEO_TYPE_REDGIFS) {
} else if (videoType == VIDEO_TYPE_REDGIFS) {
if (savedInstanceState != null) {
videoDownloadUrl = savedInstanceState.getString(VIDEO_DOWNLOAD_URL_STATE);
} else {
videoDownloadUrl = intent.getStringExtra(EXTRA_VIDEO_DOWNLOAD_URL);
}
String gfycatId = intent.getStringExtra(EXTRA_GFYCAT_ID);
if (gfycatId != null && gfycatId.contains("-")) {
gfycatId = gfycatId.substring(0, gfycatId.indexOf('-'));
}
if (videoType == VIDEO_TYPE_GFYCAT) {
videoFileName = "Gfycat-" + gfycatId + ".mp4";
} else {
videoFileName = "Redgifs-" + gfycatId + ".mp4";
String redgifsId = intent.getStringExtra(EXTRA_REDGIFS_ID);
if (redgifsId != null && redgifsId.contains("-")) {
redgifsId = redgifsId.substring(0, redgifsId.indexOf('-'));
}
videoFileName = "Redgifs-" + redgifsId + ".mp4";
if (mVideoUri == null) {
if (videoType == VIDEO_TYPE_GFYCAT) {
loadGfycatOrRedgifsVideo(gfycatRetrofit, gfycatId, true, savedInstanceState, true);
} else {
loadGfycatOrRedgifsVideo(redgifsRetrofit, gfycatId, false, savedInstanceState, false);
}
loadRedgifsVideo(redgifsId, savedInstanceState);
} else {
dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache)
.setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setAllowCrossProtocolRedirects(true).setUserAgent(APIUtils.USER_AGENT));
@@ -598,20 +593,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
}
}
private void setSmallTitle(String title) {
if (title != null) {
if (useBottomAppBar) {
titleTextView.setText(Html.fromHtml(String.format("<font color=\"#FFFFFF\"><small>%s</small></font>", title)));
} else {
setTitle(Utils.getTabTextWithCustomFont(typeface, Html.fromHtml(String.format("<font color=\"#FFFFFF\"><small>%s</small></font>", title))));
}
} else {
if (!useBottomAppBar) {
setTitle("");
}
}
}
private void preparePlayer(Bundle savedInstanceState) {
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.LOOP_VIDEO, true)) {
player.setRepeatMode(Player.REPEAT_MODE_ALL);
@@ -631,17 +612,17 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
isMute = savedInstanceState.getBoolean(IS_MUTE_STATE);
if (isMute) {
player.setVolume(0f);
muteButton.setImageResource(R.drawable.ic_mute_24dp);
muteButton.setIconResource(R.drawable.ic_mute_24dp);
} else {
player.setVolume(1f);
muteButton.setImageResource(R.drawable.ic_unmute_24dp);
muteButton.setIconResource(R.drawable.ic_unmute_24dp);
}
} else if (muteVideo) {
isMute = true;
player.setVolume(0f);
muteButton.setImageResource(R.drawable.ic_mute_24dp);
muteButton.setIconResource(R.drawable.ic_mute_24dp);
} else {
muteButton.setImageResource(R.drawable.ic_unmute_24dp);
muteButton.setIconResource(R.drawable.ic_unmute_24dp);
}
player.addListener(new Player.Listener() {
@@ -685,11 +666,11 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
if (isMute) {
isMute = false;
player.setVolume(1f);
muteButton.setImageResource(R.drawable.ic_unmute_24dp);
muteButton.setIconResource(R.drawable.ic_unmute_24dp);
} else {
isMute = true;
player.setVolume(0f);
muteButton.setImageResource(R.drawable.ic_mute_24dp);
muteButton.setIconResource(R.drawable.ic_mute_24dp);
}
});
}
@@ -702,6 +683,14 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
});
}
private void changePlaybackSpeed() {
PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed);
playbackSpeedBottomSheetFragment.setArguments(bundle);
playbackSpeedBottomSheetFragment.show(getSupportFragmentManager(), playbackSpeedBottomSheetFragment.getTag());
}
private int inferPrimaryTrackType(Format format) {
int trackType = MimeTypes.getTrackType(format.sampleMimeType);
if (trackType != C.TRACK_TYPE_UNKNOWN) {
@@ -722,61 +711,28 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
return C.TRACK_TYPE_UNKNOWN;
}
private void loadGfycatOrRedgifsVideo(Retrofit retrofit, String gfycatId, boolean isGfycatVideo,
Bundle savedInstanceState, boolean needErrorHandling) {
private void loadRedgifsVideo(String redgifsId, Bundle savedInstanceState) {
progressBar.setVisibility(View.VISIBLE);
if (isGfycatVideo) {
FetchGfycatOrRedgifsVideoLinks.fetchGfycatVideoLinks(mExecutor, new Handler(), retrofit, gfycatId,
new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
@Override
public void success(String webm, String mp4) {
progressBar.setVisibility(View.GONE);
mVideoUri = Uri.parse(webm);
videoDownloadUrl = mp4;
dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache)
.setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setAllowCrossProtocolRedirects(true).setUserAgent(APIUtils.USER_AGENT));
preparePlayer(savedInstanceState);
player.prepare();
player.setMediaSource(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri)));
}
FetchRedgifsVideoLinks.fetchRedgifsVideoLinks(mExecutor, new Handler(), redgifsRetrofit,
redgifsId, new FetchRedgifsVideoLinks.FetchRedgifsVideoLinksListener() {
@Override
public void success(String webm, String mp4) {
progressBar.setVisibility(View.GONE);
mVideoUri = Uri.parse(webm);
videoDownloadUrl = mp4;
dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache)
.setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setAllowCrossProtocolRedirects(true).setUserAgent(APIUtils.USER_AGENT));
preparePlayer(savedInstanceState);
player.prepare();
player.setMediaSource(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri)));
}
@Override
public void failed(int errorCode) {
if (errorCode == 404 && needErrorHandling) {
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.AUTOMATICALLY_TRY_REDGIFS, true)) {
loadGfycatOrRedgifsVideo(redgifsRetrofit, gfycatId, false, savedInstanceState, false);
} else {
Snackbar.make(coordinatorLayout, R.string.load_video_in_redgifs, Snackbar.LENGTH_INDEFINITE).setAction(R.string.yes,
view -> loadGfycatOrRedgifsVideo(redgifsRetrofit, gfycatId, false, savedInstanceState, false)).show();
}
} else {
progressBar.setVisibility(View.GONE);
Toast.makeText(ViewVideoActivity.this, R.string.fetch_gfycat_video_failed, Toast.LENGTH_SHORT).show();
}
}
});
} else {
FetchGfycatOrRedgifsVideoLinks.fetchRedgifsVideoLinks(this, mExecutor, new Handler(), redgifsRetrofit,
mCurrentAccountSharedPreferences, gfycatId, new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
@Override
public void success(String webm, String mp4) {
progressBar.setVisibility(View.GONE);
mVideoUri = Uri.parse(webm);
videoDownloadUrl = mp4;
dataSourceFactory = new CacheDataSource.Factory().setCache(mSimpleCache)
.setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory().setAllowCrossProtocolRedirects(true).setUserAgent(APIUtils.USER_AGENT));
preparePlayer(savedInstanceState);
player.prepare();
player.setMediaSource(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri)));
}
@Override
public void failed(int errorCode) {
progressBar.setVisibility(View.GONE);
Toast.makeText(ViewVideoActivity.this, R.string.fetch_redgifs_video_failed, Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void failed(int errorCode) {
progressBar.setVisibility(View.GONE);
Toast.makeText(ViewVideoActivity.this, R.string.fetch_redgifs_video_failed, Toast.LENGTH_SHORT).show();
}
});
}
private void loadVReddItVideo(Bundle savedInstanceState) {
@@ -791,33 +747,17 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
int commentsIndex = segments.lastIndexOf("comments");
String postId = segments.get(commentsIndex + 1);
FetchPost.fetchPost(mExecutor, new Handler(), retrofit.getRetrofit(), postId, null,
new FetchPost.FetchPostListener() {
postEnricher, new FetchPost.FetchPostListener() {
@Override
public void fetchPostSuccess(Post post) {
if (post.isGfycat()) {
videoType = VIDEO_TYPE_GFYCAT;
String gfycatId = post.getGfycatId();
if (gfycatId != null && gfycatId.contains("-")) {
gfycatId = gfycatId.substring(0, gfycatId.indexOf('-'));
}
if (videoType == VIDEO_TYPE_GFYCAT) {
videoFileName = "Gfycat-" + gfycatId + ".mp4";
} else {
videoFileName = "Redgifs-" + gfycatId + ".mp4";
}
loadGfycatOrRedgifsVideo(gfycatRetrofit, gfycatId, true, savedInstanceState, true);
} else if (post.isRedgifs()) {
if (post.isRedgifs()) {
videoType = VIDEO_TYPE_REDGIFS;
String gfycatId = post.getGfycatId();
if (gfycatId != null && gfycatId.contains("-")) {
gfycatId = gfycatId.substring(0, gfycatId.indexOf('-'));
String redgifsId = post.getRedgifsId();
if (redgifsId != null && redgifsId.contains("-")) {
redgifsId = redgifsId.substring(0, redgifsId.indexOf('-'));
}
if (videoType == VIDEO_TYPE_GFYCAT) {
videoFileName = "Gfycat-" + gfycatId + ".mp4";
} else {
videoFileName = "Redgifs-" + gfycatId + ".mp4";
}
loadGfycatOrRedgifsVideo(redgifsRetrofit, gfycatId, false, savedInstanceState, false);
videoFileName = "Redgifs-" + redgifsId + ".mp4";
loadRedgifsVideo(redgifsId, savedInstanceState);
} else if (post.isStreamable()) {
videoType = VIDEO_TYPE_STREAMABLE;
String shortCode = post.getStreamableShortCode();
@@ -884,7 +824,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
Toast.makeText(ViewVideoActivity.this, R.string.fetch_streamable_video_failed, Toast.LENGTH_SHORT).show();
return;
}
setSmallTitle(streamableVideo.title);
titleTextView.setText(streamableVideo.title);
progressBar.setVisibility(View.GONE);
videoDownloadUrl = streamableVideo.mp4 == null ? streamableVideo.mp4Mobile.url : streamableVideo.mp4.url;
mVideoUri = Uri.parse(videoDownloadUrl);
@@ -939,11 +879,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
requestPermissionAndDownload();
return true;
} else if (itemId == R.id.action_playback_speed_view_video_activity) {
PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed);
playbackSpeedBottomSheetFragment.setArguments(bundle);
playbackSpeedBottomSheetFragment.show(getSupportFragmentManager(), playbackSpeedBottomSheetFragment.getTag());
changePlaybackSpeed();
return true;
}

View File

@@ -176,7 +176,7 @@ public class WikiActivity extends BaseActivity {
return true;
};
markwon = MarkdownUtils.createFullRedditMarkwon(this,
miscPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener);
miscPlugin, markdownColor, spoilerBackgroundColor, mGlide, onLinkLongClickListener, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
markwonAdapter = MarkdownUtils.createTablesAdapter();
LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() {
@@ -259,7 +259,7 @@ public class WikiActivity extends BaseActivity {
swipeRefreshLayout.setRefreshing(false);
mFetchWikiInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchWikiInfoTextView.setText(stringResId);
mGlide.load(R.drawable.error_image).into(mFetchWikiInfoImageView);
mGlide.load(R.mipmap.ic_launcher_round).into(mFetchWikiInfoImageView);
}
@Override

View File

@@ -15,6 +15,7 @@ import com.bumptech.glide.request.RequestOptions;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.regex.Pattern;
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -186,6 +187,10 @@ public class BlockedCommunitiesRecyclerViewAdapter extends RecyclerView.Adapter<
.into(((SubredditViewHolder) viewHolder).iconGifImageView);
}
((SubredditViewHolder) viewHolder).subredditNameTextView.setText(name);
if (fullname.contains("@")) {
((SubredditViewHolder) viewHolder).communityInstanceTextView.setText("@" + fullname.split(Pattern.quote("@"), 2)[1]);
((SubredditViewHolder) viewHolder).communityInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(primaryTextColor, 0.7f));
}
} else if (viewHolder instanceof FavoriteSubredditViewHolder) {
int offset;
if (itemClickListener != null) {
@@ -318,6 +323,9 @@ public class BlockedCommunitiesRecyclerViewAdapter extends RecyclerView.Adapter<
@BindView(R.id.thing_name_text_view_item_subscribed_thing)
TextView subredditNameTextView;
@BindView(R.id.thing_instance_text_view_item_subscribed_thing)
TextView communityInstanceTextView;
SubredditViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);

View File

@@ -0,0 +1,279 @@
package eu.toldi.infinityforlemmy.adapters;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import java.util.List;
import java.util.concurrent.Executor;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.activities.InstanceInfoActivity;
import eu.toldi.infinityforlemmy.blockedinstances.BlockedInstanceData;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.zhanghai.android.fastscroll.PopupTextProvider;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
public class BlockedInstancesRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements PopupTextProvider {
private static final int VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER = 0;
private static final int VIEW_TYPE_FAVORITE_SUBREDDIT = 1;
private static final int VIEW_TYPE_SUBREDDIT_DIVIDER = 2;
private static final int VIEW_TYPE_SUBREDDIT = 3;
private BaseActivity mActivity;
private Executor mExecutor;
private Retrofit mOauthRetrofit;
private RedditDataRoomDatabase mRedditDataRoomDatabase;
private List<BlockedInstanceData> mBlockedInstanceData;
private List<BlockedInstanceData> mFavoriteBlockedInstanceData;
private RequestManager glide;
private ItemClickListener itemClickListener;
private String accessToken;
private String instancename;
private String instanceIconUrl;
private boolean hasClearSelectionRow;
private int primaryTextColor;
private int secondaryTextColor;
public BlockedInstancesRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase,
CustomThemeWrapper customThemeWrapper,
String accessToken) {
mActivity = activity;
mExecutor = executor;
glide = Glide.with(activity);
mOauthRetrofit = oauthRetrofit;
mRedditDataRoomDatabase = redditDataRoomDatabase;
this.accessToken = accessToken;
primaryTextColor = customThemeWrapper.getPrimaryTextColor();
secondaryTextColor = customThemeWrapper.getSecondaryTextColor();
}
public BlockedInstancesRecyclerViewAdapter(BaseActivity activity, Executor executor, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase,
CustomThemeWrapper customThemeWrapper,
String accessToken, boolean hasClearSelectionRow,
ItemClickListener itemClickListener) {
this(activity, executor, oauthRetrofit, redditDataRoomDatabase, customThemeWrapper, accessToken);
this.hasClearSelectionRow = hasClearSelectionRow;
this.itemClickListener = itemClickListener;
}
@Override
public int getItemViewType(int position) {
if (mFavoriteBlockedInstanceData != null && mFavoriteBlockedInstanceData.size() > 0) {
if (itemClickListener != null && !hasClearSelectionRow) {
if (position == 0) {
return VIEW_TYPE_SUBREDDIT;
} else if (position == 1) {
return VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER;
} else if (position == mFavoriteBlockedInstanceData.size() + 2) {
return VIEW_TYPE_SUBREDDIT_DIVIDER;
} else if (position <= mFavoriteBlockedInstanceData.size() + 1) {
return VIEW_TYPE_FAVORITE_SUBREDDIT;
} else {
return VIEW_TYPE_SUBREDDIT;
}
} else if (hasClearSelectionRow) {
if (position == 0) {
return VIEW_TYPE_SUBREDDIT;
} else if (position == 1) {
return VIEW_TYPE_SUBREDDIT;
} else if (position == 2) {
return VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER;
} else if (position == mFavoriteBlockedInstanceData.size() + 3) {
return VIEW_TYPE_SUBREDDIT_DIVIDER;
} else if (position <= mFavoriteBlockedInstanceData.size() + 2) {
return VIEW_TYPE_FAVORITE_SUBREDDIT;
} else {
return VIEW_TYPE_SUBREDDIT;
}
} else {
if (position == 0) {
return VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER;
} else if (position == mFavoriteBlockedInstanceData.size() + 1) {
return VIEW_TYPE_SUBREDDIT_DIVIDER;
} else if (position <= mFavoriteBlockedInstanceData.size()) {
return VIEW_TYPE_FAVORITE_SUBREDDIT;
} else {
return VIEW_TYPE_SUBREDDIT;
}
}
} else {
return VIEW_TYPE_SUBREDDIT;
}
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
return new InstanceViewHolder(LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_subscribed_thing, viewGroup, false));
}
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) {
String name;
String iconUrl;
if (hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 0) {
((InstanceViewHolder) viewHolder).subredditNameTextView.setText(R.string.all_communities);
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(null));
return;
} else {
int offset = hasClearSelectionRow ? 1 : 0;
BlockedInstanceData instanceData = mBlockedInstanceData.get(viewHolder.getBindingAdapterPosition() - offset);
String domain = mBlockedInstanceData.get(viewHolder.getBindingAdapterPosition() - offset).getDomain();
String instanceName = mBlockedInstanceData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
name = instanceName != null ? instanceName + " (" + domain + ")" : domain;
iconUrl = mBlockedInstanceData.get(viewHolder.getBindingAdapterPosition() - offset).getIcon();
}
((InstanceViewHolder) viewHolder).itemView.setOnClickListener(view -> {
if (mBlockedInstanceData != null) {
BlockedInstanceData instanceData = mBlockedInstanceData.get(viewHolder.getBindingAdapterPosition());
Intent intent = new Intent(mActivity, InstanceInfoActivity.class);
intent.putExtra(InstanceInfoActivity.EXTRA_INSTANCE_DOMAIN, instanceData.getDomain());
intent.putExtra(InstanceInfoActivity.EXTRA_INSTANCE_ID, instanceData.getId());
mActivity.startActivity(intent);
}
});
if (iconUrl == null || iconUrl.equals("")) {
((InstanceViewHolder) viewHolder).iconGifImageView.setVisibility(View.GONE);
} else {
((InstanceViewHolder) viewHolder).iconGifImageView.setVisibility(View.VISIBLE);
glide.load(iconUrl)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(glide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
.into(((InstanceViewHolder) viewHolder).iconGifImageView);
}
((InstanceViewHolder) viewHolder).subredditNameTextView.setText(name);
}
@Override
public int getItemCount() {
if (mBlockedInstanceData != null) {
if (itemClickListener != null) {
return mBlockedInstanceData.size() > 0 ? mBlockedInstanceData.size() + ((hasClearSelectionRow) ? 1 : 0) : 0;
}
return mBlockedInstanceData.size();
}
return 0;
}
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
glide.clear(((InstanceViewHolder) holder).iconGifImageView);
}
public void blockedInstances(List<BlockedInstanceData> subscribedSubreddits) {
mBlockedInstanceData = subscribedSubreddits;
notifyDataSetChanged();
}
public void setFavoriteSubscribedSubreddits(List<BlockedInstanceData> favoriteBlockedInstanceData) {
mFavoriteBlockedInstanceData = favoriteBlockedInstanceData;
notifyDataSetChanged();
}
public void addInstance(String instancename, String instanceIconUrl) {
this.instancename = instancename;
this.instanceIconUrl = instanceIconUrl;
}
@NonNull
@Override
public String getPopupText(int position) {
switch (getItemViewType(position)) {
case VIEW_TYPE_SUBREDDIT:
if (hasClearSelectionRow && position == 0) {
return "";
} else if (itemClickListener != null && !hasClearSelectionRow && position == 0) {
return "";
} else if (hasClearSelectionRow && position == 1) {
return "";
} else {
int offset;
if (itemClickListener != null) {
if (hasClearSelectionRow) {
offset = (mFavoriteBlockedInstanceData != null && mFavoriteBlockedInstanceData.size() > 0) ?
mFavoriteBlockedInstanceData.size() + 4 : 0;
} else {
offset = (mFavoriteBlockedInstanceData != null && mFavoriteBlockedInstanceData.size() > 0) ?
mFavoriteBlockedInstanceData.size() + 3 : 0;
}
} else {
offset = (mFavoriteBlockedInstanceData != null && mFavoriteBlockedInstanceData.size() > 0) ?
mFavoriteBlockedInstanceData.size() + 2 : 0;
}
return mBlockedInstanceData.get(position - offset).getDomain().substring(0, 1).toUpperCase();
}
case VIEW_TYPE_FAVORITE_SUBREDDIT:
int offset;
if (itemClickListener != null) {
if (hasClearSelectionRow) {
offset = 3;
} else {
offset = 2;
}
} else {
offset = 1;
}
return mFavoriteBlockedInstanceData.get(position - offset).getDomain().substring(0, 1).toUpperCase();
default:
return "";
}
}
public interface ItemClickListener {
void onClick(BlockedInstanceData subredditData);
}
class InstanceViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.thing_icon_gif_image_view_item_subscribed_thing)
GifImageView iconGifImageView;
@BindView(R.id.thing_name_text_view_item_subscribed_thing)
TextView subredditNameTextView;
@BindView(R.id.thing_instance_text_view_item_subscribed_thing)
TextView instanceInstanceTextView;
InstanceViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
if (mActivity.typeface != null) {
subredditNameTextView.setTypeface(mActivity.typeface);
}
subredditNameTextView.setTextColor(primaryTextColor);
}
}
}

View File

@@ -0,0 +1,76 @@
package eu.toldi.infinityforlemmy.adapters;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsage;
import eu.toldi.infinityforlemmy.databinding.ItemCommentFilterUsageEmbeddedBinding;
public class CommentFilterUsageEmbeddedRecyclerViewAdapter extends RecyclerView.Adapter<CommentFilterUsageEmbeddedRecyclerViewAdapter.EntryViewHolder> {
private BaseActivity baseActivity;
private List<CommentFilterUsage> commentFilterUsageList;
public CommentFilterUsageEmbeddedRecyclerViewAdapter(BaseActivity baseActivity) {
this.baseActivity = baseActivity;
}
@NonNull
@Override
public EntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new EntryViewHolder(ItemCommentFilterUsageEmbeddedBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
}
@Override
public void onBindViewHolder(@NonNull EntryViewHolder holder, int position) {
if (commentFilterUsageList == null || commentFilterUsageList.isEmpty()) {
holder.textView.setText(R.string.comment_filter_applied_to_all_subreddits);
} else if (holder.getBindingAdapterPosition() > 4) {
holder.textView.setText(baseActivity.getString(R.string.comment_filter_usage_embedded_more_count, commentFilterUsageList.size() - 5));
} else {
CommentFilterUsage commentFilterUsage = commentFilterUsageList.get(holder.getBindingAdapterPosition());
switch (commentFilterUsage.usage) {
case CommentFilterUsage.SUBREDDIT_TYPE:
holder.textView.setText("r/" + commentFilterUsage.nameOfUsage);
break;
}
}
}
@Override
public int getItemCount() {
return commentFilterUsageList == null || commentFilterUsageList.isEmpty() ? 1 : (commentFilterUsageList.size() > 5 ? 6 : commentFilterUsageList.size());
}
public void setCommentFilterUsageList(List<CommentFilterUsage> commentFilterUsageList) {
this.commentFilterUsageList = commentFilterUsageList;
notifyDataSetChanged();
}
class EntryViewHolder extends RecyclerView.ViewHolder {
TextView textView;
public EntryViewHolder(@NonNull ItemCommentFilterUsageEmbeddedBinding binding) {
super(binding.getRoot());
textView = binding.getRoot();
textView.setTextColor(baseActivity.customThemeWrapper.getSecondaryTextColor());
if (baseActivity.typeface != null) {
textView.setTypeface(baseActivity.typeface);
}
textView.setOnClickListener(view -> {
Toast.makeText(baseActivity, textView.getText(), Toast.LENGTH_SHORT).show();
});
}
}
}

View File

@@ -0,0 +1,80 @@
package eu.toldi.infinityforlemmy.adapters;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsage;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
public class CommentFilterUsageRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<CommentFilterUsage> commentFilterUsages;
private BaseActivity activity;
private CustomThemeWrapper customThemeWrapper;
private CommentFilterUsageRecyclerViewAdapter.OnItemClickListener onItemClickListener;
public interface OnItemClickListener {
void onClick(CommentFilterUsage commentFilterUsage);
}
public CommentFilterUsageRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper,
CommentFilterUsageRecyclerViewAdapter.OnItemClickListener onItemClickListener) {
this.activity = activity;
this.customThemeWrapper = customThemeWrapper;
this.onItemClickListener = onItemClickListener;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new CommentFilterUsageRecyclerViewAdapter.CommentFilterUsageViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_filter_usage, parent, false));
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
CommentFilterUsage commentFilterUsage = commentFilterUsages.get(position);
switch (commentFilterUsage.usage) {
case CommentFilterUsage.SUBREDDIT_TYPE:
((CommentFilterUsageRecyclerViewAdapter.CommentFilterUsageViewHolder) holder).usageTextView.setText(activity.getString(R.string.post_filter_usage_community, commentFilterUsage.nameOfUsage));
break;
}
}
@Override
public int getItemCount() {
return commentFilterUsages == null ? 0 : commentFilterUsages.size();
}
public void setCommentFilterUsages(List<CommentFilterUsage> commentFilterUsages) {
this.commentFilterUsages = commentFilterUsages;
notifyDataSetChanged();
}
private class CommentFilterUsageViewHolder extends RecyclerView.ViewHolder {
TextView usageTextView;
public CommentFilterUsageViewHolder(@NonNull View itemView) {
super(itemView);
usageTextView = (TextView) itemView;
usageTextView.setTextColor(customThemeWrapper.getPrimaryTextColor());
if (activity.typeface != null) {
usageTextView.setTypeface(activity.typeface);
}
usageTextView.setOnClickListener(view -> {
onItemClickListener.onClick(commentFilterUsages.get(getBindingAdapterPosition()));
});
}
}
}

View File

@@ -0,0 +1,81 @@
package eu.toldi.infinityforlemmy.adapters;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterWithUsage;
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.databinding.ItemCommentFilterWithUsageBinding;
public class CommentFilterWithUsageRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private BaseActivity activity;
private final OnItemClickListener onItemClickListener;
private List<CommentFilterWithUsage> commentFilterWithUsageList;
private RecyclerView.RecycledViewPool recycledViewPool;
public interface OnItemClickListener {
void onItemClick(CommentFilter commentFilter);
}
public CommentFilterWithUsageRecyclerViewAdapter(BaseActivity activity, OnItemClickListener onItemClickListener) {
this.activity = activity;
this.recycledViewPool = new RecyclerView.RecycledViewPool();
this.onItemClickListener = onItemClickListener;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new CommentFilterViewHolder(ItemCommentFilterWithUsageBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof CommentFilterViewHolder) {
((CommentFilterViewHolder) holder).binding.commentFilterNameTextViewItemCommentFilter.setText(commentFilterWithUsageList.get(position).commentFilter.name);
((CommentFilterViewHolder) holder).adapter.setCommentFilterUsageList(commentFilterWithUsageList.get(position).commentFilterUsageList);
}
}
@Override
public int getItemCount() {
return commentFilterWithUsageList == null ? 0 : commentFilterWithUsageList.size();
}
public void setCommentFilterWithUsageList(List<CommentFilterWithUsage> commentFilterWithUsageList) {
this.commentFilterWithUsageList = commentFilterWithUsageList;
notifyDataSetChanged();
}
private class CommentFilterViewHolder extends RecyclerView.ViewHolder {
ItemCommentFilterWithUsageBinding binding;
CommentFilterUsageEmbeddedRecyclerViewAdapter adapter;
public CommentFilterViewHolder(@NonNull ItemCommentFilterWithUsageBinding binding) {
super(binding.getRoot());
this.binding = binding;
binding.commentFilterNameTextViewItemCommentFilter.setTextColor(activity.customThemeWrapper.getPrimaryTextColor());
if (activity.typeface != null) {
binding.commentFilterNameTextViewItemCommentFilter.setTypeface(activity.typeface);
}
binding.getRoot().setOnClickListener(view -> {
onItemClickListener.onItemClick(commentFilterWithUsageList.get(getBindingAdapterPosition()).commentFilter);
});
binding.commentFilterUsageRecyclerViewItemCommentFilter.setRecycledViewPool(recycledViewPool);
binding.commentFilterUsageRecyclerViewItemCommentFilter.setLayoutManager(new LinearLayoutManagerBugFixed(activity));
adapter = new CommentFilterUsageEmbeddedRecyclerViewAdapter(activity);
binding.commentFilterUsageRecyclerViewItemCommentFilter.setAdapter(adapter);
}
}
}

View File

@@ -4,7 +4,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
import android.text.Spanned;
@@ -12,7 +11,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
@@ -26,6 +24,9 @@ import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.google.android.material.button.MaterialButton;
import java.util.Locale;
import butterknife.BindView;
@@ -49,6 +50,7 @@ import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.customviews.SpoilerOnClickTextView;
import eu.toldi.infinityforlemmy.customviews.SwipeLockInterface;
import eu.toldi.infinityforlemmy.customviews.SwipeLockLinearLayoutManager;
import eu.toldi.infinityforlemmy.databinding.ItemCommentBinding;
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
@@ -169,7 +171,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
return true;
};
mMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity,
miscPlugin, mCommentColor, commentSpoilerBackgroundColor, onLinkLongClickListener);
miscPlugin, mCommentColor, commentSpoilerBackgroundColor, Glide.with(mActivity.getApplication()), onLinkLongClickListener, sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
recycledViewPool = new RecyclerView.RecycledViewPool();
}
@@ -177,7 +179,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
if (viewType == VIEW_TYPE_DATA) {
return new CommentViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false));
return new CommentViewHolder(ItemCommentBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
} else if (viewType == VIEW_TYPE_ERROR) {
return new ErrorViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_footer_error, parent, false));
} else {
@@ -187,24 +189,24 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof CommentViewHolder) {
if (holder instanceof CommentBaseViewHolder) {
Comment comment = getItem(holder.getBindingAdapterPosition());
if (comment != null) {
String name = comment.getCommunityQualifiedName();
((CommentViewHolder) holder).authorTextView.setText(name);
((CommentViewHolder) holder).authorTextView.setTextColor(mSubredditColor);
((CommentBaseViewHolder) holder).authorTextView.setText(name);
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mSubredditColor);
if (mShowElapsedTime) {
((CommentViewHolder) holder).commentTimeTextView.setText(
((CommentBaseViewHolder) holder).commentTimeTextView.setText(
Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis()));
} else {
((CommentViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
((CommentBaseViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
}
((CommentViewHolder) holder).markwonAdapter.setMarkdown(mMarkwon, comment.getCommentMarkdown());
// noinspection NotifyDataSetChanged
((CommentViewHolder) holder).markwonAdapter.notifyDataSetChanged();
((CommentBaseViewHolder) holder).markwonAdapter.notifyDataSetChanged();
String commentText = Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType());
@@ -213,21 +215,21 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
switch (comment.getVoteType()) {
case Comment.VOTE_TYPE_UPVOTE:
((CommentViewHolder) holder).upvoteButton
.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
((CommentBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp);
((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
break;
case Comment.VOTE_TYPE_DOWNVOTE:
((CommentViewHolder) holder).downvoteButton
.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
((CommentBaseViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp);
((CommentBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
break;
}
if (comment.isSaved()) {
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
((CommentBaseViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp);
} else {
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
((CommentBaseViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
}
}
}
@@ -249,14 +251,16 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
if (holder instanceof CommentViewHolder) {
((CommentViewHolder) holder).authorFlairTextView.setText("");
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).awardsTextView.setText("");
((CommentViewHolder) holder).awardsTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
if (holder instanceof CommentBaseViewHolder) {
((CommentBaseViewHolder) holder).authorFlairTextView.setText("");
((CommentBaseViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).awardsTextView.setText("");
((CommentBaseViewHolder) holder).awardsTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
((CommentBaseViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
((CommentBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
}
}
@@ -289,18 +293,18 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}
public void onItemSwipe(RecyclerView.ViewHolder viewHolder, int direction, int swipeLeftAction, int swipeRightAction) {
if (viewHolder instanceof CommentViewHolder) {
if (viewHolder instanceof CommentBaseViewHolder) {
if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.START) {
if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) {
((CommentViewHolder) viewHolder).upvoteButton.performClick();
((CommentBaseViewHolder) viewHolder).upvoteButton.performClick();
} else if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) {
((CommentViewHolder) viewHolder).downvoteButton.performClick();
((CommentBaseViewHolder) viewHolder).downvoteButton.performClick();
}
} else {
if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) {
((CommentViewHolder) viewHolder).upvoteButton.performClick();
((CommentBaseViewHolder) viewHolder).upvoteButton.performClick();
} else if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) {
((CommentViewHolder) viewHolder).downvoteButton.performClick();
((CommentBaseViewHolder) viewHolder).downvoteButton.performClick();
}
}
}
@@ -318,46 +322,60 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
void retryLoadingMore();
}
public class CommentViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.vertical_block_indentation_item_comment)
CommentIndentationView commentIndentationView;
@BindView(R.id.linear_layout_item_comment)
public class CommentBaseViewHolder extends RecyclerView.ViewHolder {
LinearLayout linearLayout;
@BindView(R.id.author_text_view_item_post_comment)
TextView authorTextView;
@BindView(R.id.author_flair_text_view_item_post_comment)
TextView authorFlairTextView;
@BindView(R.id.comment_time_text_view_item_post_comment)
TextView commentTimeTextView;
@BindView(R.id.awards_text_view_item_comment)
TextView awardsTextView;
@BindView(R.id.comment_markdown_view_item_post_comment)
RecyclerView commentMarkdownView;
@BindView(R.id.bottom_constraint_layout_item_post_comment)
ConstraintLayout bottomConstraintLayout;
@BindView(R.id.up_vote_button_item_post_comment)
ImageView upvoteButton;
@BindView(R.id.score_text_view_item_post_comment)
MaterialButton upvoteButton;
TextView scoreTextView;
@BindView(R.id.down_vote_button_item_post_comment)
ImageView downvoteButton;
@BindView(R.id.placeholder_item_post_comment)
MaterialButton downvoteButton;
View placeholder;
@BindView(R.id.more_button_item_post_comment)
ImageView moreButton;
@BindView(R.id.save_button_item_post_comment)
ImageView saveButton;
@BindView(R.id.expand_button_item_post_comment)
TextView expandButton;
@BindView(R.id.reply_button_item_post_comment)
ImageView replyButton;
@BindView(R.id.divider_item_comment)
MaterialButton moreButton;
MaterialButton saveButton;
MaterialButton replyButton;
View commentDivider;
CustomMarkwonAdapter markwonAdapter;
CommentViewHolder(View itemView) {
CommentBaseViewHolder(@NonNull View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
void setBaseView(LinearLayout linearLayout,
TextView authorTextView,
TextView authorFlairTextView,
TextView commentTimeTextView,
TextView awardsTextView,
RecyclerView commentMarkdownView,
ConstraintLayout bottomConstraintLayout,
MaterialButton upvoteButton,
TextView scoreTextView,
MaterialButton downvoteButton,
View placeholder,
MaterialButton moreButton,
MaterialButton saveButton,
TextView expandButton,
MaterialButton replyButton,
CommentIndentationView commentIndentationView,
View commentDivider) {
this.linearLayout = linearLayout;
this.authorTextView = authorTextView;
this.authorFlairTextView = authorFlairTextView;
this.commentTimeTextView = commentTimeTextView;
this.awardsTextView = awardsTextView;
this.commentMarkdownView = commentMarkdownView;
this.bottomConstraintLayout = bottomConstraintLayout;
this.upvoteButton = upvoteButton;
this.scoreTextView = scoreTextView;
this.downvoteButton = downvoteButton;
this.placeholder = placeholder;
this.moreButton = moreButton;
this.saveButton = saveButton;
this.replyButton = replyButton;
this.commentDivider = commentDivider;
replyButton.setVisibility(View.GONE);
@@ -413,19 +431,19 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
authorFlairTextView.setTypeface(mActivity.typeface);
commentTimeTextView.setTypeface(mActivity.typeface);
awardsTextView.setTypeface(mActivity.typeface);
scoreTextView.setTypeface(mActivity.typeface);
upvoteButton.setTypeface(mActivity.typeface);
}
itemView.setBackgroundColor(mCommentBackgroundColor);
authorTextView.setTextColor(mUsernameColor);
authorFlairTextView.setTextColor(mAuthorFlairColor);
commentTimeTextView.setTextColor(mSecondaryTextColor);
awardsTextView.setTextColor(mSecondaryTextColor);
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setTextColor(mCommentIconAndInfoColor);
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
moreButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
saveButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
replyButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
moreButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
saveButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
replyButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
commentDivider.setBackgroundColor(mDividerColor);
authorTextView.setOnClickListener(view -> {
@@ -517,20 +535,22 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
int previousVoteType = comment.getVoteType();
int newVoteType;
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
if (previousVoteType != Comment.VOTE_TYPE_UPVOTE) {
//Not upvoted before
comment.setVoteType(Comment.VOTE_TYPE_UPVOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_UPVOTE);
upvoteButton
.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor));
scoreTextView.setTextColor(mUpvotedColor);
} else {
//Upvoted before
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_UNVOTE);
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
@@ -539,30 +559,32 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
comment.getScore() + comment.getVoteType()));
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.voteComment(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
if (newVoteType == Integer.parseInt(APIUtils.DIR_UPVOTE)) {
comment.setVoteType(Comment.VOTE_TYPE_UPVOTE);
if (currentPosition == position) {
upvoteButton.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor));
scoreTextView.setTextColor(mUpvotedColor);
}
} else {
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
if (currentPosition == position) {
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
}
if (currentPosition == position) {
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
}
@@ -573,6 +595,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}
});
scoreTextView.setOnClickListener(view -> {
upvoteButton.performClick();
});
downvoteButton.setOnClickListener(view -> {
if (mAccessToken == null) {
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
@@ -588,19 +614,22 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
int previousVoteType = comment.getVoteType();
int newVoteType;
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
if (previousVoteType != Comment.VOTE_TYPE_DOWNVOTE) {
//Not downvoted before
comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_DOWNVOTE);
downvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor));
scoreTextView.setTextColor(mDownvotedColor);
} else {
//Downvoted before
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_UNVOTE);
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
@@ -609,29 +638,31 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
comment.getScore() + comment.getVoteType()));
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.voteComment(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
if (newVoteType == Integer.parseInt(APIUtils.DIR_DOWNVOTE)) {
comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE);
if (currentPosition == position) {
downvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor));
scoreTextView.setTextColor(mDownvotedColor);
}
} else {
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
if (currentPosition == position) {
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setTextColor(mCommentIconAndInfoColor);
}
}
if (currentPosition == position) {
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
}
@@ -657,7 +688,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
public void success() {
comment.setSaved(false);
if (getBindingAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show();
}
@@ -666,7 +697,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
public void failed() {
comment.setSaved(true);
if (getBindingAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show();
}
@@ -678,7 +709,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
public void success() {
comment.setSaved(true);
if (getBindingAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_saved_success, Toast.LENGTH_SHORT).show();
}
@@ -687,7 +718,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
public void failed() {
comment.setSaved(false);
if (getBindingAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show();
}
@@ -698,6 +729,32 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}
}
class CommentViewHolder extends CommentBaseViewHolder {
ItemCommentBinding binding;
CommentViewHolder(ItemCommentBinding binding) {
super(binding.getRoot());
this.binding = binding;
setBaseView(binding.linearLayoutItemComment,
binding.authorTextViewItemPostComment,
binding.authorFlairTextViewItemPostComment,
binding.commentTimeTextViewItemPostComment,
binding.awardsTextViewItemComment,
binding.commentMarkdownViewItemPostComment,
binding.bottomConstraintLayoutItemPostComment,
binding.upvoteButtonItemPostComment,
binding.scoreTextViewItemPostComment,
binding.downvoteButtonItemPostComment,
binding.placeholderItemPostComment,
binding.moreButtonItemPostComment,
binding.saveButtonItemPostComment,
binding.expandButtonItemPostComment,
binding.replyButtonItemPostComment,
binding.verticalBlockIndentationItemComment,
binding.dividerItemComment);
}
}
class ErrorViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.error_text_view_item_footer_error)
TextView errorTextView;

View File

@@ -4,7 +4,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
@@ -31,6 +30,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.button.MaterialButton;
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
import java.util.ArrayList;
@@ -43,6 +43,7 @@ import java.util.regex.Pattern;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.DualBadgeDrawable;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.SaveComment;
@@ -58,6 +59,7 @@ import eu.toldi.infinityforlemmy.bottomsheetfragments.CommentMoreBottomSheetFrag
import eu.toldi.infinityforlemmy.bottomsheetfragments.UrlMenuBottomSheetFragment;
import eu.toldi.infinityforlemmy.comment.Comment;
import eu.toldi.infinityforlemmy.comment.FetchComment;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.CommentIndentationView;
import eu.toldi.infinityforlemmy.customviews.CustomMarkwonAdapter;
@@ -65,6 +67,7 @@ import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.customviews.SpoilerOnClickTextView;
import eu.toldi.infinityforlemmy.customviews.SwipeLockInterface;
import eu.toldi.infinityforlemmy.customviews.SwipeLockLinearLayoutManager;
import eu.toldi.infinityforlemmy.databinding.ItemCommentBinding;
import eu.toldi.infinityforlemmy.fragments.ViewPostDetailFragment;
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
import eu.toldi.infinityforlemmy.post.Post;
@@ -153,6 +156,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
private int mUsernameColor;
private int mSubmitterColor;
private int mModeratorColor;
private int mAdminColor;
private int mCurrentUserColor;
private int mAuthorFlairTextColor;
private int mUpvotedColor;
@@ -160,7 +164,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
private int mSingleCommentThreadBackgroundColor;
private int mVoteAndReplyUnavailableVoteButtonColor;
private int mButtonTextColor;
private int mPostIconAndInfoColor;
private int mCommentIconAndInfoColor;
private int mFullyCollapsedCommentBackgroundColor;
private int mAwardedCommentBackgroundColor;
@@ -220,7 +223,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
return true;
};
mCommentMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity,
miscPlugin, mCommentTextColor, commentSpoilerBackgroundColor, onLinkLongClickListener);
miscPlugin, mCommentTextColor, commentSpoilerBackgroundColor, mGlide, onLinkLongClickListener, sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
recycledViewPool = new RecyclerView.RecycledViewPool();
mAccessToken = accessToken;
mAccountQualifiedName = accountName;
@@ -270,6 +273,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mCommentBackgroundColor = customThemeWrapper.getCommentBackgroundColor();
mSubmitterColor = customThemeWrapper.getSubmitter();
mModeratorColor = customThemeWrapper.getModerator();
mAdminColor = customThemeWrapper.getAdmin();
mCurrentUserColor = customThemeWrapper.getCurrentUser();
mAuthorFlairTextColor = customThemeWrapper.getAuthorFlairTextColor();
mUsernameColor = customThemeWrapper.getUsername();
@@ -278,7 +282,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
mSingleCommentThreadBackgroundColor = customThemeWrapper.getSingleCommentThreadBackgroundColor();
mVoteAndReplyUnavailableVoteButtonColor = customThemeWrapper.getVoteAndReplyUnavailableButtonColor();
mButtonTextColor = customThemeWrapper.getButtonTextColor();
mPostIconAndInfoColor = customThemeWrapper.getPostIconAndInfoColor();
mCommentIconAndInfoColor = customThemeWrapper.getCommentIconAndInfoColor();
mFullyCollapsedCommentBackgroundColor = customThemeWrapper.getFullyCollapsedCommentBackgroundColor();
mAwardedCommentBackgroundColor = customThemeWrapper.getAwardedCommentBackgroundColor();
@@ -360,7 +363,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
case VIEW_TYPE_NO_COMMENT_PLACEHOLDER:
return new NoCommentViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_no_comment_placeholder, parent, false));
case VIEW_TYPE_COMMENT:
return new CommentViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment, parent, false));
return new CommentViewHolder(ItemCommentBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
case VIEW_TYPE_COMMENT_FULLY_COLLAPSED:
return new CommentFullyCollapsedViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment_fully_collapsed, parent, false));
case VIEW_TYPE_LOAD_MORE_CHILD_COMMENTS:
@@ -376,7 +379,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof CommentViewHolder) {
if (holder instanceof CommentBaseViewHolder) {
Comment comment = getCurrentComment(position);
if (comment != null) {
if (mIsSingleCommentThreadMode && comment.getId() == mSingleCommentId) {
@@ -384,23 +387,35 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
String authorDisplayName = (mShowUserDisplayName) ? comment.getAuthorName() : comment.getAuthor().getUsername();
String authorInstance = (mHideUserInstance) ? "" : "@" + comment.getAuthor().getQualifiedName().split(Pattern.quote("@"))[1];
((CommentViewHolder) holder).authorTextView.setText(authorDisplayName + authorInstance);
((CommentBaseViewHolder) holder).authorTextView.setText(authorDisplayName + authorInstance);
if (comment.isSubmitter()) {
((CommentViewHolder) holder).authorTextView.setTextColor(mSubmitterColor);
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mSubmitterColor);
Drawable submitterDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_mic_14dp, mSubmitterColor);
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
submitterDrawable, null, null, null);
} else if (comment.isModerator()) {
((CommentViewHolder) holder).authorTextView.setTextColor(mModeratorColor);
} else if (comment.isModerator() && comment.isAdmin()) {
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mModeratorColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
Drawable adminDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mAdminColor);
Drawable dualDrawable = new DualBadgeDrawable(adminDrawable, moderatorDrawable);
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
dualDrawable, null, null, null);
} else if (comment.isModerator()) {
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mModeratorColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
moderatorDrawable, null, null, null);
} else if (comment.isAdmin()) {
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mAdminColor);
Drawable adminDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mAdminColor);
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
adminDrawable, null, null, null);
} else if (comment.getAuthorQualifiedName().equals(mAccountQualifiedName)) {
((CommentViewHolder) holder).authorTextView.setTextColor(mCurrentUserColor);
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mCurrentUserColor);
Drawable currentUserDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_current_user_14dp, mCurrentUserColor);
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
currentUserDrawable, null, null, null);
}
@@ -416,7 +431,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
.into(((CommentViewHolder) holder).authorIconImageView);
.into(((CommentBaseViewHolder) holder).authorIconImageView);
}
});
} else {
@@ -424,33 +439,39 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
.into(((CommentViewHolder) holder).authorIconImageView);
.into(((CommentBaseViewHolder) holder).authorIconImageView);
}
if (mShowElapsedTime) {
((CommentViewHolder) holder).commentTimeTextView.setText(
((CommentBaseViewHolder) holder).commentTimeTextView.setText(
Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis()));
} else {
((CommentViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
((CommentBaseViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
}
if (mCommentToolbarHidden) {
((CommentViewHolder) holder).bottomConstraintLayout.getLayoutParams().height = 0;
((CommentBaseViewHolder) holder).bottomConstraintLayout.getLayoutParams().height = 0;
if (!mHideTheNumberOfVotes) {
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.VISIBLE);
((CommentBaseViewHolder) holder).topScoreTextView.setVisibility(View.VISIBLE);
}
} else {
((CommentViewHolder) holder).bottomConstraintLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT;
((CommentViewHolder) holder).topScoreTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).bottomConstraintLayout.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT;
((CommentBaseViewHolder) holder).topScoreTextView.setVisibility(View.GONE);
}
String text = comment.getCommentMarkdown();
if (comment.isRemoved()) {
text = "*"+mActivity.getString(R.string.removed_by_moderator)+"*";
} else if (comment.isDeleted()) {
text = "*"+mActivity.getString(R.string.deleted_by_creator)+"*";
}
((CommentViewHolder) holder).mMarkwonAdapter.setMarkdown(mCommentMarkwon, comment.getCommentMarkdown());
((CommentBaseViewHolder) holder).mMarkwonAdapter.setMarkdown(mCommentMarkwon,text);
// noinspection NotifyDataSetChanged
((CommentViewHolder) holder).mMarkwonAdapter.notifyDataSetChanged();
((CommentBaseViewHolder) holder).mMarkwonAdapter.notifyDataSetChanged();
if (mHideDownvotes) {
((CommentViewHolder) holder).downvoteButton.setVisibility(View.GONE);
((CommentViewHolder) holder).downvoteTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).downvoteButton.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).downvoteTextView.setVisibility(View.GONE);
}
if (!mHideTheNumberOfVotes) {
@@ -466,96 +487,89 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (mSeperateUpandDownvote) {
int upvotes = (comment.getVoteType() == 1) ? comment.getUpvotes() + 1 : comment.getUpvotes();
int downvotes = (comment.getVoteType() == -1) ? comment.getDownvotes() + 1 : comment.getDownvotes();
((CommentViewHolder) holder).downvoteTextView.setVisibility(View.VISIBLE);
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, upvotes));
((CommentViewHolder) holder).downvoteTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, downvotes));
((CommentViewHolder) holder).scoreTextView.setGravity(Gravity.START);
((CommentViewHolder) holder).scoreTextView.getLayoutParams().width = (int) (32 * mActivity.getResources().getDisplayMetrics().density);
((CommentBaseViewHolder) holder).downvoteTextView.setVisibility(View.VISIBLE);
((CommentBaseViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, upvotes));
((CommentBaseViewHolder) holder).downvoteTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, downvotes));
((CommentBaseViewHolder) holder).scoreTextView.setGravity(Gravity.START);
((CommentBaseViewHolder) holder).scoreTextView.getLayoutParams().width = (int) (32 * mActivity.getResources().getDisplayMetrics().density);
((CommentViewHolder) holder).scoreTextView.setPadding(0, 0, 6, 0);
((CommentViewHolder) holder).downvoteButton.setPadding(24, 0, 12, 0);
((CommentViewHolder) holder).upvoteButton.setPadding(24, 0, 12, 0);
((CommentBaseViewHolder) holder).scoreTextView.setPadding(0, 0, 6, 0);
((CommentBaseViewHolder) holder).downvoteButton.setPadding(24, 0, 12, 0);
((CommentBaseViewHolder) holder).upvoteButton.setPadding(24, 0, 12, 0);
} else {
((CommentViewHolder) holder).scoreTextView.setText(commentText);
((CommentBaseViewHolder) holder).scoreTextView.setText(commentText);
}
((CommentViewHolder) holder).topScoreTextView.setText(topScoreText);
((CommentBaseViewHolder) holder).topScoreTextView.setText(topScoreText);
} else {
((CommentViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote));
((CommentBaseViewHolder) holder).scoreTextView.setText(mActivity.getString(R.string.vote));
}
if (comment.isEdited()) {
((CommentViewHolder) holder).editedTextView.setVisibility(View.VISIBLE);
((CommentBaseViewHolder) holder).editedTextView.setVisibility(View.VISIBLE);
} else {
((CommentViewHolder) holder).editedTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).editedTextView.setVisibility(View.GONE);
}
((CommentViewHolder) holder).commentIndentationView.setShowOnlyOneDivider(mShowOnlyOneCommentLevelIndicator);
((CommentViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors);
((CommentBaseViewHolder) holder).commentIndentationView.setShowOnlyOneDivider(mShowOnlyOneCommentLevelIndicator);
((CommentBaseViewHolder) holder).commentIndentationView.setLevelAndColors(comment.getDepth(), verticalBlockColors);
if (comment.getDepth() >= mDepthThreshold) {
((CommentViewHolder) holder).saveButton.setVisibility(View.GONE);
((CommentViewHolder) holder).replyButton.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).saveButton.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).replyButton.setVisibility(View.GONE);
} else {
((CommentViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
((CommentViewHolder) holder).replyButton.setVisibility(View.VISIBLE);
((CommentBaseViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
((CommentBaseViewHolder) holder).replyButton.setVisibility(View.VISIBLE);
}
if (comment.hasReply()) {
if (comment.getChildCount() > 0 && (mAlwaysShowChildCommentCount || !comment.isExpanded())) {
((CommentViewHolder) holder).expandButton.setText("+" + comment.getChildCount());
((CommentBaseViewHolder) holder).expandButton.setText("+" + comment.getChildCount());
}
if (comment.isExpanded()) {
((CommentViewHolder) holder).expandButton.setCompoundDrawablesWithIntrinsicBounds(collapseDrawable, null, null, null);
((CommentBaseViewHolder) holder).expandButton.setCompoundDrawablesWithIntrinsicBounds(collapseDrawable, null, null, null);
} else {
((CommentViewHolder) holder).expandButton.setCompoundDrawablesWithIntrinsicBounds(expandDrawable, null, null, null);
((CommentBaseViewHolder) holder).expandButton.setCompoundDrawablesWithIntrinsicBounds(expandDrawable, null, null, null);
}
((CommentViewHolder) holder).expandButton.setVisibility(View.VISIBLE);
((CommentBaseViewHolder) holder).expandButton.setVisibility(View.VISIBLE);
}
switch (comment.getVoteType()) {
case Comment.VOTE_TYPE_UPVOTE:
((CommentViewHolder) holder).upvoteButton
.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
((CommentViewHolder) holder).topScoreTextView.setTextColor(mUpvotedColor);
((CommentViewHolder) holder).downvoteTextView.setTextColor(mCommentIconAndInfoColor);
((CommentBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp);
((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
((CommentBaseViewHolder) holder).topScoreTextView.setTextColor(mUpvotedColor);
((CommentBaseViewHolder) holder).downvoteTextView.setTextColor(mCommentIconAndInfoColor);
break;
case Comment.VOTE_TYPE_DOWNVOTE:
((CommentViewHolder) holder).downvoteButton
.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
if(mSeperateUpandDownvote) {
((CommentViewHolder) holder).downvoteTextView.setTextColor(mDownvotedColor);
((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
((CommentBaseViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp);
((CommentBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor));
if (mSeperateUpandDownvote) {
((CommentBaseViewHolder) holder).downvoteTextView.setTextColor(mDownvotedColor);
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
} else {
((CommentViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
}
((CommentViewHolder) holder).topScoreTextView.setTextColor(mDownvotedColor);
((CommentBaseViewHolder) holder).topScoreTextView.setTextColor(mDownvotedColor);
break;
default:
((CommentViewHolder) holder).downvoteTextView.setTextColor(mCommentIconAndInfoColor);
((CommentBaseViewHolder) holder).downvoteTextView.setTextColor(mCommentIconAndInfoColor);
}
if (mPost.isArchived()) {
((CommentViewHolder) holder).replyButton
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).upvoteButton
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).downvoteButton
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
PorterDuff.Mode.SRC_IN);
((CommentBaseViewHolder) holder).replyButton.setIconTint(ColorStateList.valueOf(mVoteAndReplyUnavailableVoteButtonColor));
((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mVoteAndReplyUnavailableVoteButtonColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mVoteAndReplyUnavailableVoteButtonColor);
((CommentBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mVoteAndReplyUnavailableVoteButtonColor));
}
if (mPost.isLocked()) {
((CommentViewHolder) holder).replyButton
.setColorFilter(mVoteAndReplyUnavailableVoteButtonColor,
PorterDuff.Mode.SRC_IN);
((CommentBaseViewHolder) holder).replyButton.setIconTint(ColorStateList.valueOf(mVoteAndReplyUnavailableVoteButtonColor));
}
if (comment.isSaved()) {
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
((CommentBaseViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp);
} else {
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
((CommentBaseViewHolder) holder).saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
}
if (position == mSearchCommentIndex) {
@@ -572,7 +586,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
} else if (holder instanceof CommentFullyCollapsedViewHolder) {
Comment comment = getCurrentComment(position);
if (comment != null) {
String authorWithPrefix = "u/" + comment.getAuthorName();
String author_name = (mShowUserDisplayName) ? comment.getAuthorName() : comment.getAuthor().getUsername();
String authorInstance = (mHideUserInstance) ? "" : "@" + comment.getAuthor().getQualifiedName().split(Pattern.quote("@"))[1];
String authorWithPrefix = author_name + authorInstance;
((CommentFullyCollapsedViewHolder) holder).usernameTextView.setText(authorWithPrefix);
if (comment.getAuthorIconUrl() == null) {
@@ -659,24 +675,24 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
SortType.Type sortType = mCommentRecyclerViewAdapterCallback.getSortType();
FetchComment.fetchComments(mExecutor, new Handler(), retrofit, mAccessToken,
mPost.getId(), parentComment.getId(), sortType,
mExpandChildren, 1, new FetchComment.FetchCommentListener() {
mExpandChildren, 1, new CommentFilter(), new FetchComment.FetchCommentListener() {
@Override
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) {
if (mVisibleComments.size() > parentPosition
&& parentComment.getId() == mVisibleComments.get(parentPosition).getId()) {
if (parentComment.getId() == mVisibleComments.get(parentPosition).getId()) {
if (mVisibleComments.get(parentPosition).isExpanded()) {
mVisibleComments.get(parentPosition).getChildren()
.remove(mVisibleComments.get(parentPosition).getChildren().size() - 1);
// mVisibleComments.get(parentPosition).removeMoreChildrenIds();
int placeholderPosition = findLoadMoreCommentsPlaceholderPosition(parentComment.getFullName(), commentPosition);
if (placeholderPosition != -1) {
mVisibleComments.remove(placeholderPosition);
if (position != -1) {
if (mIsSingleCommentThreadMode) {
notifyItemRemoved(placeholderPosition + 1);
mVisibleComments.remove(position - 1);
notifyItemRemoved(position + 1);
} else {
notifyItemRemoved(placeholderPosition);
mVisibleComments.remove(position);
notifyItemRemoved(position);
}
List<Comment> trulyNewComments = new ArrayList<>();
for (int i = 0; i < expandedComments.size(); i++) {
@@ -686,11 +702,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
trulyNewComments.add(expandedComments.get(i));
loadedComments.add(expandedComments.get(i).getId());
}
mVisibleComments.addAll(placeholderPosition, trulyNewComments);
if (mIsSingleCommentThreadMode) {
notifyItemRangeInserted(placeholderPosition + 1, trulyNewComments.size());
} else {
notifyItemRangeInserted(placeholderPosition, trulyNewComments.size());
if (!trulyNewComments.isEmpty()) {
mVisibleComments.addAll(position, trulyNewComments);
if (mIsSingleCommentThreadMode) {
notifyItemRangeInserted(position + 1, trulyNewComments.size());
} else {
notifyItemRangeInserted(position, trulyNewComments.size());
}
}
}
@@ -720,7 +738,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (mVisibleComments.get(i).getFullName().equals(parentComment.getFullName())) {
if (mVisibleComments.get(i).isExpanded()) {
int placeholderPositionHint = i + mVisibleComments.get(i).getChildren().size();
int placeholderPosition = findLoadMoreCommentsPlaceholderPosition(parentComment.getFullName(), placeholderPositionHint);
int placeholderPosition = findLoadMoreCommentsPlaceholderPosition(parentComment.getId(), placeholderPositionHint);
if (placeholderPosition != -1) {
mVisibleComments.get(placeholderPosition).setLoadingMoreChildren(false);
@@ -758,7 +776,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
@Override
public void onFetchCommentFailed() {
int currentParentPosition = findCommentPosition(parentComment.getFullName(), parentPosition);
int currentParentPosition = findCommentPosition(parentComment.getId(), parentPosition);
if (currentParentPosition == -1) {
// note: returning here is probably a mistake, because
// parent is just not visible, but it can still exist in the comments tree.
@@ -768,7 +786,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (currentParentComment.isExpanded()) {
int placeholderPositionHint = currentParentPosition + currentParentComment.getChildren().size();
int placeholderPosition = findLoadMoreCommentsPlaceholderPosition(parentComment.getFullName(), placeholderPositionHint);
int placeholderPosition = findLoadMoreCommentsPlaceholderPosition(parentComment.getId(), placeholderPositionHint);
if (placeholderPosition != -1) {
mVisibleComments.get(placeholderPosition).setLoadingMoreChildren(false);
@@ -814,33 +832,31 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
/**
* Find position of comment with given {@code fullName} and
* {@link Comment#NOT_PLACEHOLDER} placeholder type
*
* @return position of the placeholder or -1 if not found
*/
private int findCommentPosition(String fullName, int positionHint) {
private int findCommentPosition(int fullName, int positionHint) {
return findCommentPosition(fullName, positionHint, Comment.NOT_PLACEHOLDER);
}
/**
* Find position of comment with given {@code fullName} and
* {@link Comment#PLACEHOLDER_LOAD_MORE_COMMENTS} placeholder type
*
* @return position of the placeholder or -1 if not found
*/
private int findLoadMoreCommentsPlaceholderPosition(String fullName, int positionHint) {
return findCommentPosition(fullName, positionHint, Comment.PLACEHOLDER_LOAD_MORE_COMMENTS);
private int findLoadMoreCommentsPlaceholderPosition(int id, int positionHint) {
return findCommentPosition(id, positionHint, Comment.PLACEHOLDER_LOAD_MORE_COMMENTS);
}
private int findCommentPosition(String fullName, int positionHint, int placeholderType) {
private int findCommentPosition(int id, int positionHint, int placeholderType) {
if (0 <= positionHint && positionHint < mVisibleComments.size()
&& mVisibleComments.get(positionHint).getFullName().equals(fullName)
&& mVisibleComments.get(positionHint).getId() == id
&& mVisibleComments.get(positionHint).getPlaceholderType() == placeholderType) {
return positionHint;
}
for (int i = 0; i < mVisibleComments.size(); i++) {
Comment comment = mVisibleComments.get(i);
if (comment.getFullName().equals(fullName) && comment.getPlaceholderType() == placeholderType) {
if (comment.getId() == id && comment.getPlaceholderType() == placeholderType) {
return i;
}
}
@@ -1119,18 +1135,18 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
public void onItemSwipe(RecyclerView.ViewHolder viewHolder, int direction, int swipeLeftAction, int swipeRightAction) {
if (viewHolder instanceof CommentViewHolder) {
if (viewHolder instanceof CommentBaseViewHolder) {
if (direction == ItemTouchHelper.LEFT || direction == ItemTouchHelper.START) {
if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) {
((CommentViewHolder) viewHolder).upvoteButton.performClick();
((CommentBaseViewHolder) viewHolder).upvoteButton.performClick();
} else if (swipeLeftAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) {
((CommentViewHolder) viewHolder).downvoteButton.performClick();
((CommentBaseViewHolder) viewHolder).downvoteButton.performClick();
}
} else {
if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_UPVOTE) {
((CommentViewHolder) viewHolder).upvoteButton.performClick();
((CommentBaseViewHolder) viewHolder).upvoteButton.performClick();
} else if (swipeRightAction == SharedPreferencesUtils.SWIPE_ACITON_DOWNVOTE) {
((CommentViewHolder) viewHolder).downvoteButton.performClick();
((CommentBaseViewHolder) viewHolder).downvoteButton.performClick();
}
}
}
@@ -1157,21 +1173,23 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
if (holder instanceof CommentViewHolder) {
if (holder instanceof CommentBaseViewHolder) {
holder.itemView.setBackgroundColor(mCommentBackgroundColor);
((CommentViewHolder) holder).authorTextView.setTextColor(mUsernameColor);
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
mGlide.clear(((CommentViewHolder) holder).authorIconImageView);
((CommentViewHolder) holder).topScoreTextView.setTextColor(mSecondaryTextColor);
((CommentViewHolder) holder).awardsTextView.setText("");
((CommentViewHolder) holder).awardsTextView.setVisibility(View.GONE);
((CommentViewHolder) holder).expandButton.setVisibility(View.GONE);
((CommentViewHolder) holder).upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
((CommentViewHolder) holder).expandButton.setText("");
((CommentViewHolder) holder).replyButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mUsernameColor);
((CommentBaseViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
mGlide.clear(((CommentBaseViewHolder) holder).authorIconImageView);
((CommentBaseViewHolder) holder).topScoreTextView.setTextColor(mSecondaryTextColor);
((CommentBaseViewHolder) holder).awardsTextView.setText("");
((CommentBaseViewHolder) holder).awardsTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).expandButton.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
((CommentBaseViewHolder) holder).downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
((CommentBaseViewHolder) holder).downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
((CommentBaseViewHolder) holder).expandButton.setText("");
((CommentBaseViewHolder) holder).replyButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
params.setMargins(0, 0, 0, 0);
}
@@ -1206,55 +1224,76 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
SortType.Type getSortType();
}
public class CommentViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.linear_layout_item_comment)
public class CommentBaseViewHolder extends RecyclerView.ViewHolder {
LinearLayout linearLayout;
@BindView(R.id.author_icon_image_view_item_post_comment)
ImageView authorIconImageView;
@BindView(R.id.author_text_view_item_post_comment)
TextView authorTextView;
@BindView(R.id.author_flair_text_view_item_post_comment)
TextView authorFlairTextView;
@BindView(R.id.comment_time_text_view_item_post_comment)
TextView commentTimeTextView;
@BindView(R.id.top_score_text_view_item_post_comment)
TextView topScoreTextView;
@BindView(R.id.awards_text_view_item_comment)
TextView awardsTextView;
@BindView(R.id.comment_markdown_view_item_post_comment)
RecyclerView commentMarkdownView;
@BindView(R.id.edited_text_view_item_post_comment)
TextView editedTextView;
@BindView(R.id.bottom_constraint_layout_item_post_comment)
ConstraintLayout bottomConstraintLayout;
@BindView(R.id.up_vote_button_item_post_comment)
ImageView upvoteButton;
@BindView(R.id.score_text_view_item_post_comment)
MaterialButton upvoteButton;
TextView scoreTextView;
@BindView(R.id.downvote_text_view_item_post_comment)
TextView downvoteTextView;
@BindView(R.id.down_vote_button_item_post_comment)
ImageView downvoteButton;
@BindView(R.id.placeholder_item_post_comment)
MaterialButton downvoteButton;
View placeholder;
@BindView(R.id.more_button_item_post_comment)
ImageView moreButton;
@BindView(R.id.save_button_item_post_comment)
ImageView saveButton;
@BindView(R.id.expand_button_item_post_comment)
MaterialButton moreButton;
MaterialButton saveButton;
TextView expandButton;
@BindView(R.id.reply_button_item_post_comment)
ImageView replyButton;
@BindView(R.id.vertical_block_indentation_item_comment)
MaterialButton replyButton;
CommentIndentationView commentIndentationView;
@BindView(R.id.divider_item_comment)
View commentDivider;
CustomMarkwonAdapter mMarkwonAdapter;
CommentViewHolder(View itemView) {
CommentBaseViewHolder(@NonNull View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
void setBaseView(LinearLayout linearLayout,
ImageView authorIconImageView,
TextView authorTextView,
TextView authorFlairTextView,
TextView commentTimeTextView,
TextView topScoreTextView,
TextView awardsTextView,
RecyclerView commentMarkdownView,
TextView editedTextView,
ConstraintLayout bottomConstraintLayout,
MaterialButton upvoteButton,
TextView scoreTextView,
MaterialButton downvoteButton,
TextView downvoteTextView,
View placeholder,
MaterialButton moreButton,
MaterialButton saveButton,
TextView expandButton,
MaterialButton replyButton,
CommentIndentationView commentIndentationView,
View commentDivider) {
this.linearLayout = linearLayout;
this.authorIconImageView = authorIconImageView;
this.authorTextView = authorTextView;
this.authorFlairTextView = authorFlairTextView;
this.commentTimeTextView = commentTimeTextView;
this.topScoreTextView = topScoreTextView;
this.awardsTextView = awardsTextView;
this.commentMarkdownView = commentMarkdownView;
this.editedTextView = editedTextView;
this.bottomConstraintLayout = bottomConstraintLayout;
this.upvoteButton = upvoteButton;
this.scoreTextView = scoreTextView;
this.downvoteButton = downvoteButton;
this.downvoteTextView = downvoteTextView;
this.placeholder = placeholder;
this.moreButton = moreButton;
this.saveButton = saveButton;
this.expandButton = expandButton;
this.replyButton = replyButton;
this.commentIndentationView = commentIndentationView;
this.commentDivider = commentDivider;
if (mVoteButtonsOnTheRight) {
ConstraintSet constraintSet = new ConstraintSet();
@@ -1356,14 +1395,14 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
editedTextView.setTextColor(mSecondaryTextColor);
awardsTextView.setTextColor(mSecondaryTextColor);
commentDivider.setBackgroundColor(mDividerColor);
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setTextColor(mCommentIconAndInfoColor);
downvoteTextView.setTextColor(mCommentIconAndInfoColor);
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
moreButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
moreButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
expandButton.setTextColor(mCommentIconAndInfoColor);
saveButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
replyButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
saveButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
replyButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
authorFlairTextView.setOnClickListener(view -> authorTextView.performClick());
@@ -1450,20 +1489,23 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
int previousVoteType = comment.getVoteType();
int newVoteType;
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
if (previousVoteType != Comment.VOTE_TYPE_UPVOTE) {
//Not upvoted before
comment.setVoteType(Comment.VOTE_TYPE_UPVOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_UPVOTE);
upvoteButton.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor));
scoreTextView.setTextColor(mUpvotedColor);
topScoreTextView.setTextColor(mUpvotedColor);
} else {
//Upvoted before
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_UNVOTE);
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setTextColor(mCommentIconAndInfoColor);
downvoteTextView.setTextColor(mCommentIconAndInfoColor);
topScoreTextView.setTextColor(mSecondaryTextColor);
@@ -1493,7 +1535,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (newVoteType == Integer.parseInt(APIUtils.DIR_UPVOTE)) {
comment.setVoteType(Comment.VOTE_TYPE_UPVOTE);
if (currentPosition == position) {
upvoteButton.setColorFilter(mUpvotedColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconResource(R.drawable.ic_upvote_filled_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mUpvotedColor));
scoreTextView.setTextColor(mUpvotedColor);
topScoreTextView.setTextColor(mUpvotedColor);
downvoteTextView.setTextColor(mCommentIconAndInfoColor);
@@ -1501,7 +1544,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
} else {
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
if (currentPosition == position) {
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setTextColor(mCommentIconAndInfoColor);
topScoreTextView.setTextColor(mSecondaryTextColor);
downvoteTextView.setTextColor(mCommentIconAndInfoColor);
@@ -1509,9 +1553,10 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
if (currentPosition == position) {
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
if (!mHideTheNumberOfVotes) {
if(mSeperateUpandDownvote){
if (mSeperateUpandDownvote) {
int upvoteCount = (comment.getVoteType() == 1) ? comment.getUpvotes() + 1 : comment.getUpvotes();
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
upvoteCount));
@@ -1536,6 +1581,14 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
});
scoreTextView.setOnClickListener(view -> {
upvoteButton.performClick();
});
downvoteTextView.setOnClickListener(view -> {
downvoteButton.performClick();
});
downvoteButton.setOnClickListener(view -> {
if (mPost.isArchived()) {
Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show();
@@ -1552,17 +1605,19 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
int previousVoteType = comment.getVoteType();
int newVoteType;
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
if (previousVoteType != Comment.VOTE_TYPE_DOWNVOTE) {
//Not downvoted before
comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_DOWNVOTE);
downvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
if(mSeperateUpandDownvote){
downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor));
if (mSeperateUpandDownvote) {
downvoteTextView.setTextColor(mDownvotedColor);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
}else {
} else {
scoreTextView.setTextColor(mDownvotedColor);
}
topScoreTextView.setTextColor(mDownvotedColor);
@@ -1570,7 +1625,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
//Downvoted before
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
newVoteType = Integer.parseInt(APIUtils.DIR_UNVOTE);
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
downvoteTextView.setTextColor(mCommentIconAndInfoColor);
scoreTextView.setTextColor(mCommentIconAndInfoColor);
topScoreTextView.setTextColor(mSecondaryTextColor);
@@ -1600,7 +1656,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
if (newVoteType == Integer.parseInt(APIUtils.DIR_DOWNVOTE)) {
comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE);
if (currentPosition == position) {
downvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconResource(R.drawable.ic_downvote_filled_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mDownvotedColor));
if (mSeperateUpandDownvote) {
downvoteTextView.setTextColor(mDownvotedColor);
} else {
@@ -1611,7 +1668,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
} else {
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
if (currentPosition == position) {
downvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
downvoteButton.setIconResource(R.drawable.ic_downvote_24dp);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setTextColor(mCommentIconAndInfoColor);
downvoteTextView.setTextColor(mCommentIconAndInfoColor);
topScoreTextView.setTextColor(mSecondaryTextColor);
@@ -1619,11 +1677,12 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
if (currentPosition == position) {
upvoteButton.setColorFilter(mCommentIconAndInfoColor, PorterDuff.Mode.SRC_IN);
upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
if (!mHideTheNumberOfVotes) {
if(mSeperateUpandDownvote){
int downvotes = (comment.getVoteType() == -1) ? comment.getDownvotes() +1 : comment.getDownvotes();
int upvotes = (comment.getVoteType() == 1) ? comment.getUpvotes() +1 : comment.getUpvotes();
if (mSeperateUpandDownvote) {
int downvotes = (comment.getVoteType() == -1) ? comment.getDownvotes() + 1 : comment.getDownvotes();
int upvotes = (comment.getVoteType() == 1) ? comment.getUpvotes() + 1 : comment.getUpvotes();
downvoteTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, downvotes));
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
upvotes));
@@ -1631,7 +1690,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
}
topScoreTextView.setText(mActivity.getString(R.string.top_score,
Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())));
@@ -1658,7 +1716,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
public void success() {
comment.setSaved(false);
if (getBindingAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show();
}
@@ -1667,7 +1725,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
public void failed() {
comment.setSaved(true);
if (getBindingAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show();
}
@@ -1679,7 +1737,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
public void success() {
comment.setSaved(true);
if (getBindingAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
saveButton.setIconResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_saved_success, Toast.LENGTH_SHORT).show();
}
@@ -1688,7 +1746,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
public void failed() {
comment.setSaved(false);
if (getBindingAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
saveButton.setIconResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show();
}
@@ -1826,6 +1884,36 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
}
class CommentViewHolder extends CommentBaseViewHolder {
ItemCommentBinding binding;
CommentViewHolder(ItemCommentBinding binding) {
super(binding.getRoot());
this.binding = binding;
setBaseView(binding.linearLayoutItemComment,
binding.authorIconImageViewItemPostComment,
binding.authorTextViewItemPostComment,
binding.authorFlairTextViewItemPostComment,
binding.commentTimeTextViewItemPostComment,
binding.topScoreTextViewItemPostComment,
binding.awardsTextViewItemComment,
binding.commentMarkdownViewItemPostComment,
binding.editedTextViewItemPostComment,
binding.bottomConstraintLayoutItemPostComment,
binding.upvoteButtonItemPostComment,
binding.scoreTextViewItemPostComment,
binding.downvoteButtonItemPostComment,
binding.downvoteTextViewItemPostComment,
binding.placeholderItemPostComment,
binding.moreButtonItemPostComment,
binding.saveButtonItemPostComment,
binding.expandButtonItemPostComment,
binding.replyButtonItemPostComment,
binding.verticalBlockIndentationItemComment,
binding.dividerItemComment);
}
}
@Nullable
private Comment getCurrentComment(RecyclerView.ViewHolder holder) {
return getCurrentComment(holder.getBindingAdapterPosition());

View File

@@ -0,0 +1,41 @@
package eu.toldi.infinityforlemmy.adapters;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import java.util.List;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
public class CustomArrayAdapter extends ArrayAdapter<String> {
CustomThemeWrapper customThemeWrapper;
public CustomArrayAdapter(@NonNull Context context, int textViewResourceId, @NonNull List<String> objects, CustomThemeWrapper customThemeWrapper) {
super(context, textViewResourceId, objects);
this.customThemeWrapper = customThemeWrapper;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView itemView = (TextView) super.getView(position, convertView, parent);
itemView.setTextColor(customThemeWrapper.getPrimaryTextColor()); // Set the text color
itemView.setBackgroundColor(customThemeWrapper.getBackgroundColor()); // Set the background color
// Apply any other styling as needed
return itemView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView itemView = (TextView) super.getDropDownView(position, convertView, parent);
itemView.setTextColor(customThemeWrapper.getPrimaryTextColor()); // Set the text color
itemView.setBackgroundColor(customThemeWrapper.getBackgroundColor()); // Set the background color
// Apply any other styling as needed
return itemView;
}
}

View File

@@ -52,7 +52,7 @@ public class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter<Fl
flairEditText.requestFocus();
Utils.showKeyboard(activity, new Handler(), flairEditText);
new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.edit_flair)
.setTitle("")
.setView(dialogView)
.setPositiveButton(R.string.ok, (dialogInterface, i)
-> {

View File

@@ -156,7 +156,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<CommentInteract
CommentInteraction message = getItem(holder.getBindingAdapterPosition());
if (message != null) {
if (message.isRead()) {
if (!message.isRead()) {
if (markAllMessagesAsRead) {
message.markAsRead();
} else {
@@ -193,7 +193,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<CommentInteract
mActivity.startActivity(intent);
}
if (message.isRead()) {
if (!message.isRead()) {
holder.itemView.setBackgroundColor(mMessageBackgroundColor);

View File

@@ -6,7 +6,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
@@ -20,19 +19,18 @@ import java.util.concurrent.Executor;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.zhanghai.android.fastscroll.PopupTextProvider;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.asynctasks.InsertMultireddit;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.multireddit.FavoriteMultiReddit;
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.zhanghai.android.fastscroll.PopupTextProvider;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements PopupTextProvider {
public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements PopupTextProvider {
private static final int VIEW_TYPE_FAVORITE_MULTI_REDDIT_DIVIDER = 0;
private static final int VIEW_TYPE_FAVORITE_MULTI_REDDIT = 1;
@@ -54,6 +52,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
public interface OnItemClickListener {
void onClick(MultiReddit multiReddit);
void onLongClick(MultiReddit multiReddit);
}
@@ -120,80 +119,31 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
MultiReddit multiReddit = mMultiReddits.get(holder.getBindingAdapterPosition() - offset);
name = multiReddit.getDisplayName();
iconUrl = multiReddit.getIconUrl();
if(multiReddit.isFavorite()) {
if (multiReddit.isFavorite()) {
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
} else {
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
((MultiRedditViewHolder) holder).favoriteImageView.setOnClickListener(view -> {
if(multiReddit.isFavorite()) {
if (multiReddit.isFavorite()) {
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
multiReddit.setFavorite(false);
if (mAccessToken == null) {
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit,
() -> {
//Do nothing
});
} else {
FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase,
mAccessToken, false, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@Override
public void success() {
int position = holder.getBindingAdapterPosition() - offset;
if(position >= 0 && mMultiReddits.size() > position) {
mMultiReddits.get(position).setFavorite(false);
}
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
@Override
public void failed() {
Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show();
int position = holder.getBindingAdapterPosition() - offset;
if(position >= 0 && mMultiReddits.size() > position) {
mMultiReddits.get(position).setFavorite(true);
}
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
}
}
);
}
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit,
() -> {
//Do nothing
});
} else {
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
multiReddit.setFavorite(true);
if (mAccessToken == null) {
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit,
() -> {
//Do nothing
});
} else {
FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase,
mAccessToken, true, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@Override
public void success() {
int position = holder.getBindingAdapterPosition() - offset;
if(position >= 0 && mMultiReddits.size() > position) {
mMultiReddits.get(position).setFavorite(true);
}
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
}
@Override
public void failed() {
Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show();
int position = holder.getBindingAdapterPosition() - offset;
if(position >= 0 && mMultiReddits.size() > position) {
mMultiReddits.get(position).setFavorite(false);
}
((MultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
}
);
}
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit,
() -> {
//Do nothing
});
}
});
holder.itemView.setOnClickListener(view -> {
mOnItemClickListener.onClick(multiReddit);
@@ -220,79 +170,29 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
MultiReddit multiReddit = mFavoriteMultiReddits.get(holder.getBindingAdapterPosition() - 1);
String name = multiReddit.getDisplayName();
String iconUrl = multiReddit.getIconUrl();
if(multiReddit.isFavorite()) {
if (multiReddit.isFavorite()) {
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
} else {
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setOnClickListener(view -> {
if(multiReddit.isFavorite()) {
if (multiReddit.isFavorite()) {
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
multiReddit.setFavorite(false);
if (mAccessToken == null) {
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit,
() -> {
//Do nothing
});
} else {
FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase,
mAccessToken, false, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@Override
public void success() {
int position = holder.getBindingAdapterPosition() - 1;
if(position >= 0 && mFavoriteMultiReddits.size() > position) {
mFavoriteMultiReddits.get(position).setFavorite(false);
}
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit,
() -> {
//Do nothing
});
@Override
public void failed() {
Toast.makeText(mActivity, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show();
int position = holder.getBindingAdapterPosition() - 1;
if(position >= 0 && mFavoriteMultiReddits.size() > position) {
mFavoriteMultiReddits.get(position).setFavorite(true);
}
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
}
}
);
}
} else {
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
multiReddit.setFavorite(true);
if (mAccessToken == null) {
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit,
() -> {
//Do nothing
});
} else {
FavoriteMultiReddit.favoriteMultiReddit(mExecutor, new Handler(), mOauthRetrofit, mRedditDataRoomDatabase,
mAccessToken, true, multiReddit,
new FavoriteMultiReddit.FavoriteMultiRedditListener() {
@Override
public void success() {
int position = holder.getBindingAdapterPosition() - 1;
if(position >= 0 && mFavoriteMultiReddits.size() > position) {
mFavoriteMultiReddits.get(position).setFavorite(true);
}
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
}
@Override
public void failed() {
Toast.makeText(mActivity, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show();
int position = holder.getBindingAdapterPosition() - 1;
if(position >= 0 && mFavoriteMultiReddits.size() > position) {
mFavoriteMultiReddits.get(position).setFavorite(false);
}
((FavoriteMultiRedditViewHolder) holder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
}
);
}
InsertMultireddit.insertMultireddit(mExecutor, new Handler(), mRedditDataRoomDatabase, multiReddit,
() -> {
//Do nothing
});
}
});
holder.itemView.setOnClickListener(view -> {
@@ -322,7 +222,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
@Override
public int getItemCount() {
if (mMultiReddits != null) {
if(mFavoriteMultiReddits != null && mFavoriteMultiReddits.size() > 0) {
if (mFavoriteMultiReddits != null && mFavoriteMultiReddits.size() > 0) {
return mMultiReddits.size() > 0 ?
mFavoriteMultiReddits.size() + mMultiReddits.size() + 2 : 0;
}
@@ -334,7 +234,7 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
if(holder instanceof MultiRedditViewHolder) {
if (holder instanceof MultiRedditViewHolder) {
mGlide.clear(((MultiRedditViewHolder) holder).iconImageView);
} else if (holder instanceof FavoriteMultiRedditViewHolder) {
mGlide.clear(((FavoriteMultiRedditViewHolder) holder).iconImageView);
@@ -403,7 +303,8 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
}
class FavoriteMultiRedditsDividerViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.divider_text_view_item_favorite_thing_divider) TextView dividerTextView;
@BindView(R.id.divider_text_view_item_favorite_thing_divider)
TextView dividerTextView;
FavoriteMultiRedditsDividerViewHolder(@NonNull View itemView) {
super(itemView);
@@ -417,7 +318,8 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
}
class AllMultiRedditsDividerViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.divider_text_view_item_favorite_thing_divider) TextView dividerTextView;
@BindView(R.id.divider_text_view_item_favorite_thing_divider)
TextView dividerTextView;
AllMultiRedditsDividerViewHolder(@NonNull View itemView) {
super(itemView);

View File

@@ -12,11 +12,15 @@ import java.util.List;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.adapters.navigationdrawer.PostFilterUsageEmbeddedRecyclerViewAdapter;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.databinding.ItemPostFilterWithUsageBinding;
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
import eu.toldi.infinityforlemmy.postfilter.PostFilterWithUsage;
import eu.toldi.infinityforlemmy.utils.Utils;
public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public class PostFilterWithUsageRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int VIEW_TYPE_HEADER = 1;
private static final int VIEW_TYPE_POST_FILTER = 2;
@@ -24,16 +28,18 @@ public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private BaseActivity activity;
private CustomThemeWrapper customThemeWrapper;
private final OnItemClickListener onItemClickListener;
private List<PostFilter> postFilterList;
private List<PostFilterWithUsage> postFilterWithUsageList;
private RecyclerView.RecycledViewPool recycledViewPool;
public interface OnItemClickListener {
void onItemClick(PostFilter postFilter);
}
public PostFilterRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper,
OnItemClickListener onItemClickListener) {
public PostFilterWithUsageRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper,
OnItemClickListener onItemClickListener) {
this.activity = activity;
this.customThemeWrapper = customThemeWrapper;
this.recycledViewPool = new RecyclerView.RecycledViewPool();
this.onItemClickListener = onItemClickListener;
}
@@ -51,43 +57,49 @@ public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
if (viewType == VIEW_TYPE_HEADER) {
return new HeaderViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_filter_fragment_header, parent, false));
} else {
return new PostFilterViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_filter, parent, false));
return new PostFilterViewHolder(ItemPostFilterWithUsageBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof PostFilterViewHolder) {
((PostFilterViewHolder) holder).textView.setText(postFilterList.get(position - 1).name);
((PostFilterViewHolder) holder).binding.postFilterNameTextViewItemPostFilter.setText(postFilterWithUsageList.get(position - 1).postFilter.name);
((PostFilterViewHolder) holder).adapter.setPostFilterUsageList(postFilterWithUsageList.get(position - 1).postFilterUsages);
}
}
@Override
public int getItemCount() {
return postFilterList == null ? 1 : 1 + postFilterList.size();
return postFilterWithUsageList == null ? 1 : 1 + postFilterWithUsageList.size();
}
public void setPostFilterList(List<PostFilter> postFilterList) {
this.postFilterList = postFilterList;
public void setPostFilterWithUsageList(List<PostFilterWithUsage> postFilterWithUsageList) {
this.postFilterWithUsageList = postFilterWithUsageList;
notifyDataSetChanged();
}
private class PostFilterViewHolder extends RecyclerView.ViewHolder {
TextView textView;
ItemPostFilterWithUsageBinding binding;
PostFilterUsageEmbeddedRecyclerViewAdapter adapter;
public PostFilterViewHolder(@NonNull View itemView) {
super(itemView);
textView = (TextView) itemView;
textView.setTextColor(customThemeWrapper.getPrimaryTextColor());
public PostFilterViewHolder(@NonNull ItemPostFilterWithUsageBinding binding) {
super(binding.getRoot());
this.binding = binding;
binding.postFilterNameTextViewItemPostFilter.setTextColor(customThemeWrapper.getPrimaryTextColor());
if (activity.typeface != null) {
textView.setTypeface(activity.typeface);
binding.postFilterNameTextViewItemPostFilter.setTypeface(activity.typeface);
}
itemView.setOnClickListener(view -> {
onItemClickListener.onItemClick(postFilterList.get(getBindingAdapterPosition() - 1));
binding.getRoot().setOnClickListener(view -> {
onItemClickListener.onItemClick(postFilterWithUsageList.get(getBindingAdapterPosition() - 1).postFilter);
});
binding.postFilterUsageRecyclerViewItemPostFilter.setRecycledViewPool(recycledViewPool);
binding.postFilterUsageRecyclerViewItemPostFilter.setLayoutManager(new LinearLayoutManagerBugFixed(activity));
adapter = new PostFilterUsageEmbeddedRecyclerViewAdapter(activity);
binding.postFilterUsageRecyclerViewItemPostFilter.setAdapter(adapter);
}
}
@@ -100,4 +112,4 @@ public class PostFilterRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
infoTextView.setCompoundDrawablesWithIntrinsicBounds(Utils.getTintedDrawable(activity, R.drawable.ic_info_preference_24dp, activity.customThemeWrapper.getPrimaryIconColor()), null, null, null);
}
}
}
}

View File

@@ -18,17 +18,18 @@ import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import java.util.ArrayList;
import io.noties.markwon.Markwon;
import jp.wasabeef.glide.transformations.BlurTransformation;
import eu.toldi.infinityforlemmy.SaveMemoryCenterInisdeDownsampleStrategy;
import eu.toldi.infinityforlemmy.databinding.ItemGalleryImageInPostFeedBinding;
import eu.toldi.infinityforlemmy.post.Post;
import io.noties.markwon.Markwon;
import jp.wasabeef.glide.transformations.BlurTransformation;
public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapter<PostGalleryTypeImageRecyclerViewAdapter.ImageViewHolder> {
private RequestManager glide;
@@ -128,7 +129,7 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
return;
}
RequestBuilder<Drawable> imageRequestBuilder = glide.load(galleryImages.get(index).url).listener(new RequestListener<>() {
RequestBuilder<Drawable> imageRequestBuilder = glide.load(galleryImages.get(index).url).override(1024).listener(new RequestListener<>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
holder.binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.GONE);
@@ -144,10 +145,10 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
}
});
if (blurImage) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).thumbnail(0.1f).downsample(DownsampleStrategy.CENTER_INSIDE).override(1024)
.into(holder.binding.imageViewItemGalleryImageInPostFeed);
} else {
imageRequestBuilder.centerInside().downsample(saveMemoryCenterInisdeDownsampleStrategy).into(holder.binding.imageViewItemGalleryImageInPostFeed);
imageRequestBuilder.centerInside().downsample(saveMemoryCenterInisdeDownsampleStrategy).override(1024).thumbnail(0.1f).downsample(DownsampleStrategy.CENTER_INSIDE).into(holder.binding.imageViewItemGalleryImageInPostFeed);
}
}

View File

@@ -12,6 +12,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import java.util.ArrayList;
import butterknife.BindView;
@@ -37,6 +39,7 @@ import me.saket.bettermovementmethod.BetterLinkMovementMethod;
public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecyclerViewAdapter.RuleViewHolder> {
private BaseActivity activity;
private Markwon markwon;
private boolean mDisableImagePreview;
@Nullable
private final SliderPanel sliderPanel;
private ArrayList<Rule> rules;
@@ -44,10 +47,11 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
public RulesRecyclerViewAdapter(@NonNull BaseActivity activity,
@NonNull CustomThemeWrapper customThemeWrapper,
@Nullable SliderPanel sliderPanel) {
@Nullable SliderPanel sliderPanel, boolean disableImagePreview) {
this.activity = activity;
this.sliderPanel = sliderPanel;
mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor();
mDisableImagePreview = disableImagePreview;
int spoilerBackgroundColor = mPrimaryTextColor | 0xFF000000;
MarkwonPlugin miscPlugin = new AbstractMarkwonPlugin() {
@Override
@@ -82,7 +86,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
return true;
};
markwon = MarkdownUtils.createFullRedditMarkwon(activity,
miscPlugin, mPrimaryTextColor, spoilerBackgroundColor, onLinkLongClickListener);
miscPlugin, mPrimaryTextColor, spoilerBackgroundColor, Glide.with(activity.getApplication()), onLinkLongClickListener, mDisableImagePreview);
}
@NonNull

View File

@@ -2,21 +2,17 @@ package eu.toldi.infinityforlemmy.adapters;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.databinding.ItemRecentSearchQueryBinding;
import eu.toldi.infinityforlemmy.recentsearchquery.RecentSearchQuery;
import eu.toldi.infinityforlemmy.utils.Utils;
@@ -45,14 +41,14 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new RecentSearchQueryViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recent_search_query, parent, false));
return new RecentSearchQueryViewHolder(ItemRecentSearchQueryBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof RecentSearchQueryViewHolder) {
if (recentSearchQueries != null && !recentSearchQueries.isEmpty() && position < recentSearchQueries.size()) {
((RecentSearchQueryViewHolder) holder).recentSearchQueryTextView.setText(recentSearchQueries.get(position).getSearchQuery());
((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryTextViewItemRecentSearchQuery.setText(recentSearchQueries.get(position).getSearchQuery());
}
}
}
@@ -68,22 +64,18 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
class RecentSearchQueryViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.recent_search_query_text_view_item_recent_search_query)
TextView recentSearchQueryTextView;
@BindView(R.id.delete_image_view_item_recent_search_query)
ImageView deleteImageView;
ItemRecentSearchQueryBinding binding;
public RecentSearchQueryViewHolder(@NonNull View itemView) {
super(itemView);
public RecentSearchQueryViewHolder(@NonNull ItemRecentSearchQueryBinding binding) {
super(binding.getRoot());
this.binding = binding;
ButterKnife.bind(this, itemView);
recentSearchQueryTextView.setTextColor(primaryTextColor);
recentSearchQueryTextView.setCompoundDrawablesWithIntrinsicBounds(historyIcon, null, null, null);
deleteImageView.setImageDrawable(deleteIcon);
binding.recentSearchQueryTextViewItemRecentSearchQuery.setTextColor(primaryTextColor);
binding.recentSearchQueryTextViewItemRecentSearchQuery.setCompoundDrawablesWithIntrinsicBounds(historyIcon, null, null, null);
binding.deleteButtonItemRecentSearchQuery.setIcon(deleteIcon);
if (activity.typeface != null) {
recentSearchQueryTextView.setTypeface(activity.typeface);
binding.recentSearchQueryTextViewItemRecentSearchQuery.setTypeface(activity.typeface);
}
itemView.setOnClickListener(view -> {
@@ -92,7 +84,7 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
});
deleteImageView.setOnClickListener(view -> {
binding.deleteButtonItemRecentSearchQuery.setOnClickListener(view -> {
itemOnClickListener.onDelete(recentSearchQueries.get(getBindingAdapterPosition()));
});
}

View File

@@ -16,13 +16,14 @@ import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.subreddit.SubredditWithSelection;
public class SelectedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private BaseActivity activity;
private CustomThemeWrapper customThemeWrapper;
private ArrayList<String> subreddits;
private ArrayList<SubredditWithSelection> subreddits;
public SelectedSubredditsRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, ArrayList<String> subreddits) {
public SelectedSubredditsRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper, ArrayList<SubredditWithSelection> subreddits) {
this.activity = activity;
this.customThemeWrapper = customThemeWrapper;
if (subreddits == null) {
@@ -42,7 +43,7 @@ public class SelectedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof SubredditViewHolder) {
((SubredditViewHolder) holder).subredditNameTextView.setText(subreddits.get(holder.getBindingAdapterPosition()));
((SubredditViewHolder) holder).subredditNameTextView.setText(subreddits.get(holder.getBindingAdapterPosition()).getQualifiedName());
((SubredditViewHolder) holder).deleteButton.setOnClickListener(view -> {
subreddits.remove(holder.getBindingAdapterPosition());
notifyItemRemoved(holder.getBindingAdapterPosition());
@@ -55,18 +56,22 @@ public class SelectedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter<
return subreddits.size();
}
public void addSubreddits(ArrayList<String> newSubreddits) {
public void addSubreddits(ArrayList<SubredditWithSelection> newSubreddits) {
int oldSize = subreddits.size();
subreddits.addAll(newSubreddits);
for (SubredditWithSelection subreddit : newSubreddits) {
if (!subreddits.contains(subreddit)) {
subreddits.add(subreddit);
}
}
notifyItemRangeInserted(oldSize, newSubreddits.size());
}
public void addUserInSubredditType(String username) {
subreddits.add(username);
notifyItemInserted(subreddits.size());
/*subreddits.add(username);
notifyItemInserted(subreddits.size());*/
}
public ArrayList<String> getSubreddits() {
public ArrayList<SubredditWithSelection> getSubreddits() {
return subreddits;
}

View File

@@ -141,7 +141,8 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
.into(((DataViewHolder) holder).iconGifImageView);
}
((DataViewHolder) holder).subredditNameTextView.setText(subredditData.getName());
((DataViewHolder) holder).subredditNameTextView.setText(subredditData.getTitle());
((DataViewHolder) holder).communityInstanceTextView.setText('@' + LemmyUtils.actorID2FullName(subredditData.getActorId()).split("@")[1]);
((DataViewHolder) holder).subscriberCountTextView.setText(activity.getString(R.string.subscribers_number_detail, subredditData.getNSubscribers()));
if (!isMultiSelection) {
@@ -262,6 +263,9 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
GifImageView iconGifImageView;
@BindView(R.id.subreddit_name_text_view_item_subreddit_listing)
TextView subredditNameTextView;
@BindView(R.id.community_instance_text_view_item_subreddit_listing)
TextView communityInstanceTextView;
@BindView(R.id.subscriber_count_text_view_item_subreddit_listing)
TextView subscriberCountTextView;
@BindView(R.id.subscribe_image_view_item_subreddit_listing)
@@ -273,6 +277,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
super(itemView);
ButterKnife.bind(this, itemView);
subredditNameTextView.setTextColor(primaryTextColor);
communityInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(primaryTextColor, 0.7f));
subscriberCountTextView.setTextColor(secondaryTextColor);
subscribeButton.setColorFilter(unsubscribed, android.graphics.PorterDuff.Mode.SRC_IN);
if (isMultiSelection) {

View File

@@ -19,12 +19,12 @@ import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.subreddit.SubredditWithSelection;
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@@ -53,6 +53,7 @@ public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Ada
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof SubscribedSubredditViewHolder) {
((SubscribedSubredditViewHolder) holder).nameTextView.setText(subscribedSubreddits.get(position).getName());
((SubscribedSubredditViewHolder) holder).instanceTextView.setText(subscribedSubreddits.get(position).getQualifiedName().substring(subscribedSubreddits.get(position).getQualifiedName().indexOf("@")));
glide.load(subscribedSubreddits.get(position).getIconUrl())
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(glide.load(R.drawable.subreddit_default_icon)
@@ -91,11 +92,11 @@ public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Ada
notifyDataSetChanged();
}
public ArrayList<String> getAllSelectedSubreddits() {
ArrayList<String> selectedSubreddits = new ArrayList<>();
public ArrayList<SubredditWithSelection> getAllSelectedSubreddits() {
ArrayList<SubredditWithSelection> selectedSubreddits = new ArrayList<>();
for (SubredditWithSelection s : subscribedSubreddits) {
if (s.isSelected()) {
selectedSubreddits.add(s.getName());
selectedSubreddits.add(s);
}
}
return selectedSubreddits;
@@ -107,6 +108,9 @@ public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Ada
GifImageView iconImageView;
@BindView(R.id.name_text_view_item_subscribed_subreddit_multiselection)
TextView nameTextView;
@BindView(R.id.instance_text_view_item_subscribed_subreddit_multiselection)
TextView instanceTextView;
@BindView(R.id.checkbox_item_subscribed_subreddit_multiselection)
CheckBox checkBox;
@@ -115,10 +119,12 @@ public class SubredditMultiselectionRecyclerViewAdapter extends RecyclerView.Ada
this.itemView = itemView;
ButterKnife.bind(this, itemView);
nameTextView.setTextColor(primaryTextColor);
instanceTextView.setTextColor(primaryTextColor);
checkBox.setButtonTintList(ColorStateList.valueOf(colorAccent));
if (activity.typeface != null) {
nameTextView.setTypeface(activity.typeface);
instanceTextView.setTypeface(activity.typeface);
}
}
}

View File

@@ -84,12 +84,10 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
if (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) {
if (itemClickListener != null && !hasClearSelectionRow) {
if (position == 0) {
return VIEW_TYPE_SUBREDDIT;
} else if (position == 1) {
return VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER;
} else if (position == mFavoriteSubscribedSubredditData.size() + 2) {
} else if (position == mFavoriteSubscribedSubredditData.size() + 1) {
return VIEW_TYPE_SUBREDDIT_DIVIDER;
} else if (position <= mFavoriteSubscribedSubredditData.size() + 1) {
} else if (position <= mFavoriteSubscribedSubredditData.size()) {
return VIEW_TYPE_FAVORITE_SUBREDDIT;
} else {
return VIEW_TYPE_SUBREDDIT;
@@ -98,12 +96,10 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
if (position == 0) {
return VIEW_TYPE_SUBREDDIT;
} else if (position == 1) {
return VIEW_TYPE_SUBREDDIT;
} else if (position == 2) {
return VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER;
} else if (position == mFavoriteSubscribedSubredditData.size() + 3) {
} else if (position == mFavoriteSubscribedSubredditData.size() + 2) {
return VIEW_TYPE_SUBREDDIT_DIVIDER;
} else if (position <= mFavoriteSubscribedSubredditData.size() + 2) {
} else if (position < mFavoriteSubscribedSubredditData.size() + 2) {
return VIEW_TYPE_FAVORITE_SUBREDDIT;
} else {
return VIEW_TYPE_SUBREDDIT;
@@ -155,8 +151,22 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(null));
return;
} else {
int offset = hasClearSelectionRow ? 1 : 0;
SubscribedSubredditData communityData = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset);
int offset;
if (itemClickListener != null) {
if (hasClearSelectionRow) {
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
mFavoriteSubscribedSubredditData.size() + 3 : 1;
} else {
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
mFavoriteSubscribedSubredditData.size() + 2 : 0;
}
} else {
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
mFavoriteSubscribedSubredditData.size() + 2 : 0;
}
name = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
fullname = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getQualified_name();
iconUrl = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl();
@@ -181,6 +191,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
});
if (itemClickListener != null) {
SubscribedSubredditData communityData = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset);
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(communityData));
}
}
@@ -209,19 +220,23 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
.into(((SubredditViewHolder) viewHolder).iconGifImageView);
}
((SubredditViewHolder) viewHolder).subredditNameTextView.setText(name);
if (fullname.contains("@")) {
((SubredditViewHolder) viewHolder).communityInstanceTextView.setText(fullname.substring(fullname.indexOf("@")));
}
} else if (viewHolder instanceof FavoriteSubredditViewHolder) {
int offset;
if (itemClickListener != null) {
if (hasClearSelectionRow) {
offset = 3;
} else {
offset = 2;
} else {
offset = 1;
}
} else {
offset = 1;
}
SubscribedSubredditData communityData = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset);
String name = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
String fullname = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getQualified_name();
String iconUrl = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl();
if (mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).isFavorite()) {
@@ -267,15 +282,26 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
.into(((FavoriteSubredditViewHolder) viewHolder).iconGifImageView);
}
((FavoriteSubredditViewHolder) viewHolder).subredditNameTextView.setText(name);
if (fullname.contains("@")) {
((FavoriteSubredditViewHolder) viewHolder).communityInstanceTextView.setText(fullname.substring(fullname.indexOf("@")));
}
}
}
@Override
public int getItemCount() {
if (mSubscribedSubredditData != null) {
if (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) {
if (itemClickListener != null) {
return mSubscribedSubredditData.size() > 0 ?
mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + ((hasClearSelectionRow) ? 3 : 2) : 0;
}
return mSubscribedSubredditData.size() > 0 ?
mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + 2 : 0;
}
if (itemClickListener != null) {
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + ((hasClearSelectionRow) ? 1 : 0) : 0;
return (hasClearSelectionRow) ? mSubscribedSubredditData.size() + 1 : mSubscribedSubredditData.size();
}
return mSubscribedSubredditData.size();
@@ -283,6 +309,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
return 0;
}
@Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
if(holder instanceof SubredditViewHolder) {
@@ -324,10 +351,10 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
if (itemClickListener != null) {
if (hasClearSelectionRow) {
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
mFavoriteSubscribedSubredditData.size() + 4 : 0;
mFavoriteSubscribedSubredditData.size() + 3 : 0;
} else {
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
mFavoriteSubscribedSubredditData.size() + 3 : 0;
mFavoriteSubscribedSubredditData.size() + 2 : 0;
}
} else {
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
@@ -340,9 +367,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
int offset;
if (itemClickListener != null) {
if (hasClearSelectionRow) {
offset = 3;
} else {
offset = 2;
} else {
offset = 1;
}
} else {
offset = 1;
@@ -362,6 +389,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
GifImageView iconGifImageView;
@BindView(R.id.thing_name_text_view_item_subscribed_thing)
TextView subredditNameTextView;
@BindView(R.id.thing_instance_text_view_item_subscribed_thing)
TextView communityInstanceTextView;
@BindView(R.id.favorite_image_view_item_subscribed_thing)
ImageView favoriteImageView;
@@ -370,8 +400,10 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
ButterKnife.bind(this, itemView);
if (mActivity.typeface != null) {
subredditNameTextView.setTypeface(mActivity.typeface);
communityInstanceTextView.setTypeface(mActivity.typeface);
}
subredditNameTextView.setTextColor(primaryTextColor);
communityInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(primaryTextColor, 0.7f));
}
}
@@ -380,6 +412,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
GifImageView iconGifImageView;
@BindView(R.id.thing_name_text_view_item_subscribed_thing)
TextView subredditNameTextView;
@BindView(R.id.thing_instance_text_view_item_subscribed_thing)
TextView communityInstanceTextView;
@BindView(R.id.favorite_image_view_item_subscribed_thing)
ImageView favoriteImageView;
@@ -389,8 +424,10 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
ButterKnife.bind(this, itemView);
if (mActivity.typeface != null) {
subredditNameTextView.setTypeface(mActivity.typeface);
communityInstanceTextView.setTypeface(mActivity.typeface);
}
subredditNameTextView.setTextColor(primaryTextColor);
communityInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(primaryTextColor, 0.7f));
}
}

View File

@@ -47,7 +47,6 @@ public class UserFlairRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerV
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof UserFlairViewHolder) {
if (position == 0) {
((UserFlairViewHolder) holder).userFlairHtmlTextView.setText(R.string.clear_user_flair);
((UserFlairViewHolder) holder).editUserFlairImageView.setVisibility(View.GONE);
} else {
UserFlair userFlair = userFlairs.get(holder.getBindingAdapterPosition() - 1);

View File

@@ -136,7 +136,9 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R
.into(((DataViewHolder) holder).iconGifImageView);
}
((DataViewHolder) holder).userNameTextView.setText(userData.getName());
((DataViewHolder) holder).userNameTextView.setText(userData.getTitle().equals("") ? userData.getName() : userData.getTitle());
String qualifiedName = LemmyUtils.actorID2FullName(userData.getActorId());
((DataViewHolder) holder).userInstanceTextView.setText(qualifiedName.substring(qualifiedName.indexOf('@')));
if (!isMultiSelection) {
CheckIsFollowingUser.checkIsFollowingUser(executor, new Handler(), redditDataRoomDatabase,
@@ -237,6 +239,9 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R
GifImageView iconGifImageView;
@BindView(R.id.user_name_text_view_item_user_listing)
TextView userNameTextView;
@BindView(R.id.user_instance_text_view_item_user_listing)
TextView userInstanceTextView;
@BindView(R.id.subscribe_image_view_item_user_listing)
ImageView subscribeButton;
@BindView(R.id.checkbox__item_user_listing)
@@ -246,6 +251,7 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R
super(itemView);
ButterKnife.bind(this, itemView);
userNameTextView.setTextColor(primaryTextColor);
userInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(primaryTextColor, 0.7f));
subscribeButton.setColorFilter(unsubscribedColor, android.graphics.PorterDuff.Mode.SRC_IN);
if (activity.typeface != null) {

View File

@@ -24,8 +24,8 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private static final int VIEW_TYPE_MENU_GROUP_TITLE = 1;
private static final int VIEW_TYPE_MENU_ITEM = 2;
private static final int ACCOUNT_SECTION_ITEMS = 4;
private static final int ANONYMOUS_ACCOUNT_SECTION_ITEMS = 1;
private static final int ACCOUNT_SECTION_ITEMS = 5;
private static final int ANONYMOUS_ACCOUNT_SECTION_ITEMS = 2;
private BaseActivity baseActivity;
private int inboxCount;
@@ -113,6 +113,10 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy
baseActivity.startActivity(intent);
});
break;
case 4:
stringId = R.string.multi_reddit;
drawableId = R.drawable.ic_multi_reddit_24dp;
break;
default:
stringId = R.string.account_saved_thing_activity_label;
drawableId = R.drawable.ic_outline_bookmarks_24dp;
@@ -125,6 +129,10 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy
stringId = R.string.subscriptions;
drawableId = R.drawable.ic_subscritptions_bottom_app_bar_24dp;
break;
case 2:
stringId = R.string.multi_reddit;
drawableId = R.drawable.ic_multi_reddit_24dp;
break;
default:
stringId = R.string.anonymous_account_instance;
drawableId = R.drawable.ic_account_circle_24dp;

View File

@@ -0,0 +1,102 @@
package eu.toldi.infinityforlemmy.adapters.navigationdrawer;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.databinding.ItemPostFilterUsageEmbeddedBinding;
import eu.toldi.infinityforlemmy.postfilter.PostFilterUsage;
public class PostFilterUsageEmbeddedRecyclerViewAdapter extends RecyclerView.Adapter<PostFilterUsageEmbeddedRecyclerViewAdapter.EntryViewHolder> {
private BaseActivity baseActivity;
private List<PostFilterUsage> postFilterUsageList;
public PostFilterUsageEmbeddedRecyclerViewAdapter(BaseActivity baseActivity) {
this.baseActivity = baseActivity;
}
@NonNull
@Override
public EntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new EntryViewHolder(ItemPostFilterUsageEmbeddedBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
}
@Override
public void onBindViewHolder(@NonNull EntryViewHolder holder, int position) {
if (postFilterUsageList == null || postFilterUsageList.isEmpty()) {
holder.textView.setText(R.string.click_to_apply_post_filter);
} else if (holder.getBindingAdapterPosition() > 4) {
holder.textView.setText(baseActivity.getString(R.string.post_filter_usage_embedded_more_count, postFilterUsageList.size() - 5));
} else {
PostFilterUsage postFilterUsage = postFilterUsageList.get(holder.getBindingAdapterPosition());
switch (postFilterUsage.usage) {
case PostFilterUsage.HOME_TYPE:
holder.textView.setText(R.string.post_filter_usage_home);
break;
case PostFilterUsage.SUBREDDIT_TYPE:
if (postFilterUsage.nameOfUsage.equals(PostFilterUsage.NO_USAGE)) {
holder.textView.setText(R.string.post_filter_usage_embedded_subreddit_all);
} else {
holder.textView.setText("r/" + postFilterUsage.nameOfUsage);
}
break;
case PostFilterUsage.USER_TYPE:
if (postFilterUsage.nameOfUsage.equals(PostFilterUsage.NO_USAGE)) {
holder.textView.setText(R.string.post_filter_usage_embedded_user_all);
} else {
holder.textView.setText("u/" + postFilterUsage.nameOfUsage);
}
break;
case PostFilterUsage.SEARCH_TYPE:
holder.textView.setText(R.string.post_filter_usage_search);
break;
case PostFilterUsage.MULTIREDDIT_TYPE:
if (postFilterUsage.nameOfUsage.equals(PostFilterUsage.NO_USAGE)) {
holder.textView.setText(R.string.post_filter_usage_embedded_multireddit_all);
} else {
holder.textView.setText(postFilterUsage.nameOfUsage);
}
break;
}
}
}
@Override
public int getItemCount() {
return postFilterUsageList == null || postFilterUsageList.isEmpty() ? 1 : (postFilterUsageList.size() > 5 ? 6 : postFilterUsageList.size());
}
public void setPostFilterUsageList(List<PostFilterUsage> postFilterUsageList) {
this.postFilterUsageList = postFilterUsageList;
notifyDataSetChanged();
}
class EntryViewHolder extends RecyclerView.ViewHolder {
TextView textView;
public EntryViewHolder(@NonNull ItemPostFilterUsageEmbeddedBinding binding) {
super(binding.getRoot());
textView = binding.getRoot();
textView.setTextColor(baseActivity.customThemeWrapper.getSecondaryTextColor());
if (baseActivity.typeface != null) {
textView.setTypeface(baseActivity.typeface);
}
textView.setOnClickListener(view -> {
Toast.makeText(baseActivity, textView.getText(), Toast.LENGTH_SHORT).show();
});
}
}
}

View File

@@ -1,10 +0,0 @@
package eu.toldi.infinityforlemmy.apis;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
public interface GfycatAPI {
@GET("{gfyid}")
Call<String> getGfycatData(@Path("gfyid") String gfyId);
}

Some files were not shown because too many files have changed in this diff Show More