Compare commits

...

126 Commits

Author SHA1 Message Date
Balazs Toldi
726eac70a9
Minor improvements to manage multicommunities 2023-11-10 22:48:26 +01:00
Balazs Toldi
421342734c
Multicommunity Working?
This commit improves the existing PoC multicommunity implementation with a "less hacked together" one
2023-11-10 22:12:42 +01:00
Balazs Toldi
ee7f2e271c
Prototype multicomm
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
2023-11-10 11:06:50 +01:00
Balazs Toldi
c387e4abbc
Some changes to enable multicomm (not working yet) 2023-11-10 11:06:50 +01:00
Balazs Toldi
ff3ccca3eb
Minor fix to comment filters 2023-11-10 11:01:35 +01: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
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
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
302 changed files with 16573 additions and 13180 deletions

BIN
.assets/fdroid-badge.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 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

@ -2,6 +2,7 @@ steps:
build:
image: alvrme/alpine-android:android-33-jdk11
commands:
- apk add --no-cache python3
- ./gradlew :app:assembleRelease
when:
path: [ app/**, build.gradle ]

View File

@ -8,6 +8,7 @@ steps:
build:
image: alvrme/alpine-android:android-33-jdk11
commands:
- apk add --no-cache python3
- ./gradlew :app:assembleNightly
sign:
image: alvrme/alpine-android:android-33-jdk11

View File

@ -1,5 +1,5 @@
<h1 align="center">
Eternity (formerly Infinity for Lemmy)
Eternity for Lemmy
</h1>
<div align="center">
@ -20,9 +20,13 @@ A Lemmy client for Android written in Java. It's a fork of the [Infinity for Red
</div>
<div align="center">
<a href="https://f-droid.org/packages/eu.toldi.infinityforlemmy/">
<img src="./.assets/fdroid-badge.png" height="80">
</a>
<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://apt.izzysoft.de/fdroid/index/apk/eu.toldi.infinityforlemmy">
<img src="./.assets/IzzyOnDroid.png" height="80">
</a>
@ -36,24 +40,62 @@ A Lemmy client for Android written in Java. It's a fork of the [Infinity for Red
---
## 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
@ -72,9 +114,9 @@ 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/Eternity/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/Eternity/-/app/multi-auto.svg)](https://translate.codeberg.org/engage/Eternity/)
[![Translation](https://translate.codeberg.org/widgets/infinity-for-lemmy/-/app/multi-auto.svg)](https://translate.codeberg.org/engage/Eternity/)
### Reporting bugs

View File

@ -21,8 +21,8 @@ android {
applicationId "eu.toldi.infinityforlemmy"
minSdk 21
targetSdk 33
versionCode 130
versionName "0.1.1"
versionCode 131
versionName "0.1.2"
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 {
@ -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"
@ -239,9 +271,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>
@ -22,6 +23,7 @@
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application
@ -40,6 +42,23 @@
android:configChanges="orientation|screenLayout|screenSize|layoutDirection"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.Slidable" />
<activity
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.HistoryActivity"
android:exported="false"
@ -407,11 +426,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 +454,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 +514,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"

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;
@ -75,7 +77,6 @@ import eu.toldi.infinityforlemmy.fragments.BlockedCommunitiesListingFragment;
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 +114,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 +310,6 @@ public interface AppComponent {
void inject(MaterialYouWorker materialYouWorker);
void inject(HistoryPostFragment historyPostFragment);
void inject(HistoryActivity historyActivity);
void inject(MorePostsInfoFragment morePostsInfoFragment);
void inject(BlockedThingListingActivity blockedThingListingActivity);
@ -327,6 +324,12 @@ public interface AppComponent {
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

@ -1,7 +1,5 @@
package eu.toldi.infinityforlemmy;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;
import org.json.JSONException;
@ -12,9 +10,7 @@ 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;
@ -44,14 +40,12 @@ public class FetchGfycatOrRedgifsVideoLinks {
});
}
public static void fetchRedgifsVideoLinks(Context context, Executor executor, Handler handler, Retrofit redgifsRetrofit,
SharedPreferences currentAccountSharedPreferences,
public static void fetchRedgifsVideoLinks(Executor executor, Handler handler, Retrofit redgifsRetrofit,
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();
Response<String> response = redgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(gfycatId).execute();
if (response.isSuccessful()) {
parseRedgifsVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
} else {

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,6 +9,7 @@ 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.comment.LemmyCommentAPI;
import eu.toldi.infinityforlemmy.post.LemmyPostAPI;
@ -37,7 +38,8 @@ abstract class NetworkModule {
@Provides
@Named("glide")
@Singleton
static OkHttpClient provideGlideOkHttp(@Named("base") OkHttpClient baseOkHttp) {
static OkHttpClient provideGlideOkHttp(@Named("base") OkHttpClient baseOkHttp,
@Named("RedgifsAccessTokenAuthenticator") Interceptor redGifsAuthenticator) {
return baseOkHttp.newBuilder()
.addInterceptor(chain -> chain.proceed(
chain.request()
@ -45,6 +47,7 @@ abstract class NetworkModule {
.header("User-Agent", APIUtils.USER_AGENT)
.build()
))
.addInterceptor(redGifsAuthenticator)
.build();
}
@ -178,6 +181,12 @@ abstract class NetworkModule {
.build();
}
@Provides
@Singleton
static RedgifsAPI provideRedgifsAPI(@Named("redgifs") Retrofit redgifsRetrofit) {
return redgifsRetrofit.create(RedgifsAPI.class);
}
@Provides
@Named("imgur")
@Singleton
@ -246,4 +255,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,26 @@
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

@ -17,6 +17,10 @@ import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityDao;
import eu.toldi.infinityforlemmy.blockedcommunity.BlockedCommunityData;
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 +46,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, CommentFilter.class, CommentFilterUsage.class}, version = 28)
public abstract class RedditDataRoomDatabase extends RoomDatabase {
public static RedditDataRoomDatabase create(final Context context) {
@ -53,7 +58,7 @@ 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)
.build();
}
@ -85,6 +90,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 +433,16 @@ 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)");
}
};
}

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

@ -69,15 +69,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 +88,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

@ -283,7 +283,7 @@ 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);
@ -293,7 +293,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
}
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

@ -205,7 +205,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
}
};
Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(this,
miscPlugin, parentTextColor, parentSpoilerBackgroundColor, null);
miscPlugin, parentTextColor, parentSpoilerBackgroundColor, null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter();
binding.commentContentMarkdownView.setLayoutManager(new LinearLayoutManagerBugFixed(this));
binding.commentContentMarkdownView.setAdapter(markwonAdapter);

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

@ -226,10 +226,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);
}

View File

@ -40,7 +40,6 @@ 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.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
import retrofit2.Retrofit;
@ -123,7 +122,7 @@ 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);
@ -145,41 +144,24 @@ 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);
@ -191,7 +173,7 @@ public class EditMultiRedditActivity extends BaseActivity {
selectSubredditTextView.setOnClickListener(view -> {
Intent intent = new Intent(EditMultiRedditActivity.this, SelectedSubredditsAndUsersActivity.class);
if (multiReddit.getSubreddits() != null) {
intent.putStringArrayListExtra(SelectedSubredditsAndUsersActivity.EXTRA_SELECTED_SUBREDDITS, multiReddit.getSubreddits());
intent.putParcelableArrayListExtra(SelectedSubredditsAndUsersActivity.EXTRA_SELECTED_SUBREDDITS, multiReddit.getSubreddits());
}
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});
@ -216,39 +198,24 @@ 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();
}
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
}
});
@Override
public void failed() {
Snackbar.make(coordinatorLayout, R.string.edit_multi_reddit_failed, Snackbar.LENGTH_SHORT).show();
}
});
}
return true;
}
return false;
@ -259,7 +226,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));
}
}

View File

@ -139,7 +139,7 @@ public class FullMarkdownActivity extends BaseActivity {
}
};
Markwon markwon = MarkdownUtils.createFullRedditMarkwon(this,
miscPlugin, markdownColor, spoilerBackgroundColor, null);
miscPlugin, markdownColor, spoilerBackgroundColor, null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter();
LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() {

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

@ -149,7 +149,7 @@ public class InstanceInfoActivity extends BaseActivity {
};
mPostDetailMarkwon = MarkdownUtils.createFullRedditMarkwon(this,
miscPlugin, markdownColor, postSpoilerBackgroundColor, null);
miscPlugin, markdownColor, postSpoilerBackgroundColor, null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
mMarkwonAdapter = MarkdownUtils.createTablesAdapter();
mContentMarkdownView.setAdapter(mMarkwonAdapter);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);

View File

@ -36,6 +36,7 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
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;
@ -83,6 +84,9 @@ public class LinkResolverActivity extends AppCompatActivity {
@Inject
Executor mExecutor;
@Inject
PostEnricher postEnricher;
private String mAccessToken;
private Uri getRedditUriByPath(String path) {
@ -102,6 +106,9 @@ public class LinkResolverActivity extends AppCompatActivity {
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();
@ -214,7 +221,7 @@ public class LinkResolverActivity extends AppCompatActivity {
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, new FetchPost.FetchPostListener() {
FetchPost.fetchPost(mExecutor, new Handler(), mRetrofit.getRetrofit(), segments.get(segments.size() - 1), mAccessToken, postEnricher, new FetchPost.FetchPostListener() {
@Override
public void fetchPostSuccess(Post post) {
@ -335,64 +342,6 @@ public class LinkResolverActivity extends AppCompatActivity {
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())));
@ -481,7 +430,7 @@ public class LinkResolverActivity extends AppCompatActivity {
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;
@ -41,11 +44,15 @@ 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.utils.SharedPreferencesUtils;
@ -70,7 +77,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 +94,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 +149,23 @@ public class LoginActivity extends BaseActivity {
isAgreeToUserAgreement = savedInstanceState.getBoolean(IS_AGREE_TO_USER_AGGREMENT_STATE);
}
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,6 +203,7 @@ public class LoginActivity extends BaseActivity {
try {
JSONObject responseJSON = new JSONObject(accountResponse);
String accessToken = responseJSON.getString("jwt");
mRetrofit.setAccessToken(null);
FetchMyInfo.fetchAccountInfo(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, username,
accessToken, new FetchMyInfo.FetchMyInfoListener() {
@ -189,13 +213,23 @@ public class LoginActivity extends BaseActivity {
@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(),
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();
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();
}
}
}
@Override
@ -328,6 +362,7 @@ public class LoginActivity extends BaseActivity {
if (typeface != null) {
twoFAInfoTextView.setTypeface(typeface);
}
instance_input.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
}
@Override

View File

@ -33,6 +33,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;
@ -249,6 +250,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.installSplashScreen(this);
((Infinity) getApplication()).getAppComponent().inject(this);
setTheme(R.style.AppTheme_NoActionBarWithTransparentStatusBar);
@ -336,11 +339,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
fragmentManager = getSupportFragmentManager();
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mRetrofit.setAccessToken(mAccessToken);
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);
}
@ -821,8 +826,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) {
@ -924,7 +927,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) {
@ -1511,7 +1514,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;
}
@ -1569,7 +1577,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) -> {
@ -1590,7 +1602,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;
}
@ -1603,7 +1619,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) -> {
@ -1646,7 +1666,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 {

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));

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());
@ -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);
});
@ -401,6 +424,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) {

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;
@ -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
@ -392,8 +394,8 @@ 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);
}
}

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;
@ -33,6 +32,7 @@ import eu.toldi.infinityforlemmy.bottomsheetfragments.SelectSubredditsOrUsersOpt
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 +62,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 +86,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);
@ -158,7 +157,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 +175,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

@ -112,8 +112,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
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)
@ -259,11 +257,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
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 +280,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);
@ -368,18 +362,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
}
});
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) {
@ -461,7 +443,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
flairTextView.setTextColor(primaryTextColor);
spoilerTextView.setTextColor(primaryTextColor);
nsfwTextView.setTextColor(primaryTextColor);
titleEditText.setTextColor(primaryTextColor);
titleEditText.setHintTextColor(secondaryTextColor);
@ -474,7 +455,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
rulesButton.setTypeface(typeface);
receivePostReplyNotificationsTextView.setTypeface(typeface);
flairTextView.setTypeface(typeface);
spoilerTextView.setTypeface(typeface);
nsfwTextView.setTypeface(typeface);
titleEditText.setTypeface(typeface);
}
@ -561,22 +541,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);
@ -699,4 +676,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();
}
@ -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();
@ -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

@ -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,6 +82,7 @@ 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;
@ -151,6 +153,8 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
@Inject
@Named("glide")
OkHttpClient okHttpClient;
@Inject
PostEnricher postEnricher;
@State
ArrayList<Post> posts;
@State
@ -530,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;
@ -674,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),
@ -538,7 +550,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 +558,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 +591,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 +773,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 +1184,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) {
@ -1274,6 +1310,9 @@ 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);
}
return false;
}
@ -1518,7 +1557,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 +1619,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 +1644,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 +1661,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) -> {
@ -1692,6 +1747,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

@ -472,7 +472,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) {
@ -761,7 +761,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) {
@ -1514,7 +1514,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 +1576,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 +1601,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 +1618,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) -> {

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,6 +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.button.MaterialButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.common.collect.ImmutableList;
import com.otaliastudios.zoom.ZoomEngine;
@ -108,6 +106,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,7 +130,7 @@ 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";
@ -162,17 +161,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;
@ -222,10 +223,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
@Named("current_account")
SharedPreferences mCurrentAccountSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@ -235,6 +232,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 +301,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 +318,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 +336,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 +408,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) {
@ -598,20 +607,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 +626,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 +680,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 +697,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) {
@ -756,8 +759,8 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
}
});
} else {
FetchGfycatOrRedgifsVideoLinks.fetchRedgifsVideoLinks(this, mExecutor, new Handler(), redgifsRetrofit,
mCurrentAccountSharedPreferences, gfycatId, new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
FetchGfycatOrRedgifsVideoLinks.fetchRedgifsVideoLinks(mExecutor, new Handler(), redgifsRetrofit,
gfycatId, new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
@Override
public void success(String webm, String mp4) {
progressBar.setVisibility(View.GONE);
@ -791,7 +794,7 @@ 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()) {
@ -884,7 +887,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 +942,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, onLinkLongClickListener, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
markwonAdapter = MarkdownUtils.createTablesAdapter();
LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() {

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,8 @@ import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.button.MaterialButton;
import java.util.Locale;
import butterknife.BindView;
@ -49,6 +49,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 +170,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
return true;
};
mMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity,
miscPlugin, mCommentColor, commentSpoilerBackgroundColor, onLinkLongClickListener);
miscPlugin, mCommentColor, commentSpoilerBackgroundColor, onLinkLongClickListener, sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
recycledViewPool = new RecyclerView.RecycledViewPool();
}
@ -177,7 +178,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 +188,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 +214,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 +250,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 +292,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 +321,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 +430,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 +534,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);
}
@ -546,23 +565,25 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
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 +594,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 +613,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);
}
@ -616,22 +644,24 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
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 +687,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 +696,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 +708,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 +717,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 +728,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;
@ -58,6 +58,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 +66,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;
@ -160,7 +162,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 +221,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
return true;
};
mCommentMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity,
miscPlugin, mCommentTextColor, commentSpoilerBackgroundColor, onLinkLongClickListener);
miscPlugin, mCommentTextColor, commentSpoilerBackgroundColor, onLinkLongClickListener, sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false));
recycledViewPool = new RecyclerView.RecycledViewPool();
mAccessToken = accessToken;
mAccountQualifiedName = accountName;
@ -278,7 +279,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 +360,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 +376,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 +384,23 @@ 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);
((CommentBaseViewHolder) holder).authorTextView.setTextColor(mModeratorColor);
Drawable moderatorDrawable = Utils.getTintedDrawable(mActivity, R.drawable.ic_verified_user_14dp, mModeratorColor);
((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(
moderatorDrawable, 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 +416,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 +424,33 @@ 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);
}
((CommentViewHolder) holder).mMarkwonAdapter.setMarkdown(mCommentMarkwon, comment.getCommentMarkdown());
((CommentBaseViewHolder) holder).mMarkwonAdapter.setMarkdown(mCommentMarkwon, comment.getCommentMarkdown());
// 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 +466,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) {
@ -661,7 +654,7 @@ 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 (parentComment.getId() == mVisibleComments.get(parentPosition).getId()) {
@ -818,7 +811,6 @@ 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(int fullName, int positionHint) {
@ -828,7 +820,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
/**
* 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(int id, int positionHint) {
@ -1123,18 +1114,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();
}
}
}
@ -1161,21 +1152,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);
}
@ -1210,55 +1203,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();
@ -1360,14 +1374,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());
@ -1454,20 +1468,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);
@ -1497,7 +1514,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);
@ -1505,7 +1523,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);
@ -1513,9 +1532,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));
@ -1540,6 +1560,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();
@ -1556,17 +1584,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);
@ -1574,7 +1604,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);
@ -1604,7 +1635,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 {
@ -1615,7 +1647,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);
@ -1623,11 +1656,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));
@ -1635,7 +1669,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())));
@ -1662,7 +1695,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();
}
@ -1671,7 +1704,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();
}
@ -1683,7 +1716,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();
}
@ -1692,7 +1725,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();
}
@ -1830,6 +1863,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

@ -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

@ -37,6 +37,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 +45,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 +84,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
return true;
};
markwon = MarkdownUtils.createFullRedditMarkwon(activity,
miscPlugin, mPrimaryTextColor, spoilerBackgroundColor, onLinkLongClickListener);
miscPlugin, mPrimaryTextColor, spoilerBackgroundColor, 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()).getName());
((SubredditViewHolder) holder).deleteButton.setOnClickListener(view -> {
subreddits.remove(holder.getBindingAdapterPosition());
notifyItemRemoved(holder.getBindingAdapterPosition());
@ -55,18 +56,18 @@ 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);
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

@ -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> {
@ -91,11 +91,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;

View File

@ -158,7 +158,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
mFavoriteSubscribedSubredditData.size() + 3 : 1;
} else {
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
mFavoriteSubscribedSubredditData.size() + 2 : 1;
mFavoriteSubscribedSubredditData.size() + 2 : 0;
}
} else {
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
@ -301,7 +301,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
}
if (itemClickListener != null) {
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + 1 : 0;
return (hasClearSelectionRow) ? mSubscribedSubredditData.size() + 1 : mSubscribedSubredditData.size();
}
return mSubscribedSubredditData.size();

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

@ -101,7 +101,16 @@ public interface LemmyAPI {
Call<String> postDelete(@Body DeletePostDTO params);
@GET("api/v3/user")
ListenableFuture<Response<String>> getUserPosts(
ListenableFuture<Response<String>> getUserPostsListenableFuture(
@Query("username") String username,
@Query("sort") String sort,
@Query("page") Integer page,
@Query("limit") Integer limit,
@Query("saved_only") Boolean saved_only,
@Query("auth") String access_token);
@GET("api/v3/user")
Call<String> getUserPosts(
@Query("username") String username,
@Query("sort") String sort,
@Query("page") Integer page,
@ -129,7 +138,19 @@ public interface LemmyAPI {
);
@GET("api/v3/post/list")
ListenableFuture<Response<String>> getPosts(
ListenableFuture<Response<String>> getPostsListenableFuture(
@Query("type_") String type_,
@Query("sort") String sort,
@Query("page") Integer page,
@Query("limit") Integer limit,
@Query("community_id") Integer community_id,
@Query("community_name") String community_name,
@Query("saved_only") Boolean saved_only,
@Query("auth") String auth
);
@GET("api/v3/post/list")
Call<String> getPosts(
@Query("type_") String type_,
@Query("sort") String sort,
@Query("page") Integer page,

View File

@ -54,19 +54,19 @@ public interface RedditAPI {
@GET("user/{username}/about.json?raw_json=1")
Call<String> getUserData(@Path("username") String username);
@GET("user/{username}/about.json?raw_json=1")
@GET("user/{username}/about.json?raw_json=1&limit=100")
Call<String> getUserDataOauth(@HeaderMap Map<String, String> headers, @Path("username") String username);
@GET("user/{username}/comments.json?raw_json=1")
@GET("user/{username}/comments.json?raw_json=1&limit=100")
Call<String> getUserComments(@Path("username") String username, @Query("after") String after,
@Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime);
@GET("user/{username}/comments.json?raw_json=1")
@GET("user/{username}/comments.json?raw_json=1&limit=100")
Call<String> getUserCommentsOauth(@HeaderMap Map<String, String> headers, @Path("username") String username,
@Query("after") String after, @Query("sort") SortType.Type sortType,
@Query("t") SortType.Time sortTime);
@GET("user/{username}/{where}.json?&type=comments&raw_json=1&limit=25")
@GET("user/{username}/{where}.json?&type=comments&raw_json=1&limit=100")
Call<String> getUserSavedCommentsOauth(@Path("username") String username, @Path("where") String where,
@Query("after") String lastItem, @Query("sort") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @HeaderMap Map<String, String> headers);
@ -273,108 +273,108 @@ public interface RedditAPI {
@GET("/r/{subredditName}/wiki/{wikiPage}.json?raw_json=1")
Call<String> getWikiPage(@Path("subredditName") String subredditName, @Path("wikiPage") String wikiPage);
@GET("{sortType}?raw_json=1")
@GET("{sortType}?raw_json=1&limit=100")
ListenableFuture<Response<String>> getBestPostsListenableFuture(@Path("sortType") SortType.Type sortType, @Query("t") SortType.Time sortTime,
@Query("after") String lastItem, @HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1")
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1")
ListenableFuture<Response<String>> getSubredditBestPostsOauthListenableFuture(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @Query("after") String lastItem,
@HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1")
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1")
ListenableFuture<Response<String>> getSubredditBestPostsListenableFuture(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @Query("after") String lastItem);
@GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=25")
@GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=100")
ListenableFuture<Response<String>> getUserPostsOauthListenableFuture(@Path("username") String username, @Path("where") String where,
@Query("after") String lastItem, @Query("sort") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @HeaderMap Map<String, String> headers);
@GET("user/{username}/submitted.json?raw_json=1&limit=25")
@GET("user/{username}/submitted.json?raw_json=1&limit=100")
ListenableFuture<Response<String>> getUserPostsListenableFuture(@Path("username") String username, @Query("after") String lastItem,
@Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime);
@GET("search.json?include_over_18=1&raw_json=1&type=link")
@GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link")
ListenableFuture<Response<String>> searchPostsOauthListenableFuture(@Query("q") String query, @Query("after") String after,
@Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime,
@Query("source") String source,
@HeaderMap Map<String, String> headers);
@GET("search.json?include_over_18=1&raw_json=1&type=link")
@GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link")
ListenableFuture<Response<String>> searchPostsListenableFuture(@Query("q") String query, @Query("after") String after,
@Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime,
@Query("source") String source);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true")
ListenableFuture<Response<String>> searchPostsInSpecificSubredditOauthListenableFuture(@Path("subredditName") String subredditName,
@Query("q") String query, @Query("sort") SortType.Type sort,
@Query("t") SortType.Time sortTime, @Query("after") String after,
@HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true")
ListenableFuture<Response<String>> searchPostsInSpecificSubredditListenableFuture(@Path("subredditName") String subredditName,
@Query("q") String query, @Query("sort") SortType.Type sort,
@Query("t") SortType.Time sortTime, @Query("after") String after);
@GET("{multipath}?raw_json=1")
@GET("{multipath}?raw_json=1&limit=100")
ListenableFuture<Response<String>> getMultiRedditPostsListenableFuture(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after, @Query("t") SortType.Time sortTime);
@GET("{multipath}.json?raw_json=1")
@GET("{multipath}.json?raw_json=1&limit=100")
ListenableFuture<Response<String>> getMultiRedditPostsOauthListenableFuture(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after, @Query("t") SortType.Time sortTime,
@HeaderMap Map<String, String> headers);
@GET("{sortType}?raw_json=1")
@GET("{sortType}?raw_json=1&limit=100")
Call<String> getBestPosts(@Path("sortType") SortType.Type sortType, @Query("t") SortType.Time sortTime,
@Query("after") String lastItem, @HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1")
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1")
Call<String> getSubredditBestPostsOauth(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @Query("after") String lastItem,
@HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1")
@GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1")
Call<String> getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @Query("after") String lastItem);
@GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=25")
@GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=100")
Call<String> getUserPostsOauth(@Path("username") String username, @Path("where") String where,
@Query("after") String lastItem, @Query("sort") SortType.Type sortType,
@Query("t") SortType.Time sortTime, @HeaderMap Map<String, String> headers);
@GET("user/{username}/submitted.json?raw_json=1&limit=25")
@GET("user/{username}/submitted.json?raw_json=1&limit=100")
Call<String> getUserPosts(@Path("username") String username, @Query("after") String lastItem,
@Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime);
@GET("search.json?include_over_18=1&raw_json=1&type=link")
@GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link")
Call<String> searchPostsOauth(@Query("q") String query, @Query("after") String after,
@Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime,
@Query("source") String source,
@HeaderMap Map<String, String> headers);
@GET("search.json?include_over_18=1&raw_json=1&type=link")
@GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link")
Call<String> searchPosts(@Query("q") String query, @Query("after") String after,
@Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime,
@Query("source") String source);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true")
Call<String> searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName,
@Query("q") String query, @Query("sort") SortType.Type sort,
@Query("t") SortType.Time sortTime, @Query("after") String after,
@HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true")
@GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true")
Call<String> searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName,
@Query("q") String query, @Query("sort") SortType.Type sort,
@Query("t") SortType.Time sortTime, @Query("after") String after);
@GET("{multipath}?raw_json=1")
@GET("{multipath}?raw_json=1&limit=100")
Call<String> getMultiRedditPosts(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after, @Query("t") SortType.Time sortTime);
@GET("{multipath}.json?raw_json=1")
@GET("{multipath}.json?raw_json=1&limit=100")
Call<String> getMultiRedditPostsOauth(@Path(value = "multipath", encoded = true) String multiPath,
@Query("after") String after, @Query("t") SortType.Time sortTime,
@HeaderMap Map<String, String> headers);

View File

@ -6,14 +6,16 @@ import retrofit2.Call;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.HeaderMap;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Query;
public interface RedgifsAPI {
@GET("/v2/gifs/{id}")
Call<String> getRedgifsData(@HeaderMap Map<String, String> headers, @Path("id") String id, @Query("user-agent") String userAgent);
Call<String> getRedgifsData(@Path("id") String id);
@GET("/v2/gifs")
Call<String> getRedgifsMultipleData(@Query("ids") String ids);
@FormUrlEncoded
@POST("/v2/oauth/client")

View File

@ -13,11 +13,7 @@ public class DeleteMultiredditInDatabase {
String accountName, String multipath,
DeleteMultiredditInDatabaseListener deleteMultiredditInDatabaseListener) {
executor.execute(() -> {
if (accountName.equals("-")) {
redditDataRoomDatabase.multiRedditDao().anonymousDeleteMultiReddit(multipath);
} else {
redditDataRoomDatabase.multiRedditDao().deleteMultiReddit(multipath, accountName);
}
redditDataRoomDatabase.multiRedditDao().anonymousDeleteMultiReddit(multipath);
handler.post(deleteMultiredditInDatabaseListener::success);
});
}

View File

@ -49,6 +49,7 @@ public class InsertSubscribedThings {
for (SubscribedSubredditData s : subscribedSubredditDataList) {
if (existingSubscribedSubredditDataList.contains(s)) {
subscribedSubredditDao.updateSubscribedSubreddit(s.getQualified_name(), s.getName(), s.getIconUrl(), accountName);
continue;
}
subscribedSubredditDao.insert(s);

View File

@ -2,6 +2,7 @@ package eu.toldi.infinityforlemmy.asynctasks;
import android.content.SharedPreferences;
import android.os.Handler;
import android.util.Log;
import java.util.concurrent.Executor;
@ -25,18 +26,31 @@ public class SwitchAccount {
.putString(SharedPreferencesUtils.ACCESS_TOKEN, account.getAccessToken())
.putString(SharedPreferencesUtils.ACCOUNT_NAME, account.getDisplay_name())
.putString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, account.getAccountName())
.putString(SharedPreferencesUtils.ACCOUNT_INSTANCE,account.getInstance_url())
.putString(SharedPreferencesUtils.ACCOUNT_INSTANCE, account.getInstance_url())
.putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, false)
.putString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, account.getProfileImageUrl()).apply();
retrofitHolder.setBaseURL(account.getInstance_url());
retrofitHolder.setAccessToken(null);
FetchSiteInfo.fetchSiteInfo(retrofitHolder.getRetrofit(), account.getAccessToken(), new FetchSiteInfo.FetchSiteInfoListener() {
@Override
public void onFetchSiteInfoSuccess(SiteInfo siteInfo) {
boolean canDownvote = siteInfo.isEnable_downvotes();
currentAccountSharedPreferences.edit().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)) {
retrofitHolder.setAccessToken(account.getAccessToken());
currentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true).apply();
}
}
}
@Override
public void onFetchSiteInfoFailed() {
Log.e("SwitchAccount", "Failed to fetch site info");
currentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, true).apply();
}
});

View File

@ -0,0 +1,63 @@
package eu.toldi.infinityforlemmy.bottomsheetfragments;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import eu.toldi.infinityforlemmy.activities.CommentFilterPreferenceActivity;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.databinding.FragmentCommentFilterOptionsBottomSheetBinding;
import eu.toldi.infinityforlemmy.utils.Utils;
public class CommentFilterOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
public static final String EXTRA_POST_FILTER = "EPF";
private CommentFilterPreferenceActivity activity;
public CommentFilterOptionsBottomSheetFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
FragmentCommentFilterOptionsBottomSheetBinding binding = FragmentCommentFilterOptionsBottomSheetBinding.inflate(inflater, container, false);
CommentFilter commentFilter = getArguments().getParcelable(EXTRA_POST_FILTER);
binding.editTextViewCommentFilterOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.editCommentFilter(commentFilter);
dismiss();
});
binding.applyToTextViewCommentFilterOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.applyCommentFilterTo(commentFilter);
dismiss();
});
binding.deleteTextViewCommentFilterOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.deleteCommentFilter(commentFilter);
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
}
return binding.getRoot();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
activity = (CommentFilterPreferenceActivity) context;
}
}

View File

@ -0,0 +1,57 @@
package eu.toldi.infinityforlemmy.bottomsheetfragments;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import eu.toldi.infinityforlemmy.activities.CommentFilterUsageListingActivity;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsage;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.databinding.FragmentCommentFilterUsageOptionsBottomSheetBinding;
import eu.toldi.infinityforlemmy.utils.Utils;
public class CommentFilterUsageOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
public static final String EXTRA_COMMENT_FILTER_USAGE = "ECFU";
private CommentFilterUsageListingActivity activity;
public CommentFilterUsageOptionsBottomSheetFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
FragmentCommentFilterUsageOptionsBottomSheetBinding binding = FragmentCommentFilterUsageOptionsBottomSheetBinding.inflate(inflater, container, false);
CommentFilterUsage commentFilterUsage = getArguments().getParcelable(EXTRA_COMMENT_FILTER_USAGE);
binding.editTextViewCommentFilterUsageOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.editCommentFilterUsage(commentFilterUsage);
dismiss();
});
binding.deleteTextViewCommentFilterUsageOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.deleteCommentFilterUsage(commentFilterUsage);
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
}
return binding.getRoot();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
activity = (CommentFilterUsageListingActivity) context;
}
}

View File

@ -0,0 +1,48 @@
package eu.toldi.infinityforlemmy.bottomsheetfragments;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import eu.toldi.infinityforlemmy.activities.CommentFilterUsageListingActivity;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilterUsage;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.databinding.FragmentNewCommentFilterUsageBottomSheetBinding;
import eu.toldi.infinityforlemmy.utils.Utils;
public class NewCommentFilterUsageBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
private CommentFilterUsageListingActivity activity;
public NewCommentFilterUsageBottomSheetFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
FragmentNewCommentFilterUsageBottomSheetBinding binding = FragmentNewCommentFilterUsageBottomSheetBinding.inflate(inflater, container, false);
binding.subredditTextViewNewCommentFilterUsageBottomSheetFragment.setOnClickListener(view -> {
activity.newCommentFilterUsage(CommentFilterUsage.SUBREDDIT_TYPE);
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
}
return binding.getRoot();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
activity = (CommentFilterUsageListingActivity) context;
}
}

View File

@ -5,26 +5,17 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.PostFilterPreferenceActivity;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.databinding.FragmentPostFilterOptionsBottomSheetBinding;
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
import eu.toldi.infinityforlemmy.utils.Utils;
public class PostFilterOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
@BindView(R.id.edit_text_view_post_filter_options_bottom_sheet_fragment)
TextView editTextView;
@BindView(R.id.apply_to_text_view_post_filter_options_bottom_sheet_fragment)
TextView applyToTextView;
@BindView(R.id.delete_text_view_post_filter_options_bottom_sheet_fragment)
TextView deleteTextView;
public static final String EXTRA_POST_FILTER = "EPF";
private PostFilterPreferenceActivity activity;
@ -36,32 +27,30 @@ public class PostFilterOptionsBottomSheetFragment extends LandscapeExpandedRound
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_post_filter_options_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
FragmentPostFilterOptionsBottomSheetBinding binding = FragmentPostFilterOptionsBottomSheetBinding.inflate(inflater, container, false);
PostFilter postFilter = getArguments().getParcelable(EXTRA_POST_FILTER);
editTextView.setOnClickListener(view -> {
binding.editTextViewPostFilterOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.editPostFilter(postFilter);
dismiss();
});
applyToTextView.setOnClickListener(view -> {
binding.applyToTextViewPostFilterOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.applyPostFilterTo(postFilter);
dismiss();
});
deleteTextView.setOnClickListener(view -> {
binding.deleteTextViewPostFilterOptionsBottomSheetFragment.setOnClickListener(view -> {
activity.deletePostFilter(postFilter);
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(rootView, activity.typeface);
Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
}
return rootView;
return binding.getRoot();
}
@Override

View File

@ -6,16 +6,13 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.BaseActivity;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.databinding.FragmentPostLayoutBottomSheetBinding;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
@ -24,14 +21,7 @@ import eu.toldi.infinityforlemmy.utils.Utils;
*/
public class PostLayoutBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
@BindView(R.id.card_layout_text_view_post_layout_bottom_sheet_fragment)
TextView cardLayoutTextView;
@BindView(R.id.card_layout_2_text_view_post_layout_bottom_sheet_fragment)
TextView cardLayout2TextView;
@BindView(R.id.compact_layout_text_view_post_layout_bottom_sheet_fragment)
TextView compactLayoutTextView;
@BindView(R.id.gallery_layout_text_view_post_layout_bottom_sheet_fragment)
TextView galleryLayoutTextView;
private FragmentPostLayoutBottomSheetBinding binding;
private BaseActivity activity;
public PostLayoutBottomSheetFragment() {
// Required empty public constructor
@ -39,33 +29,36 @@ public class PostLayoutBottomSheetFragment extends LandscapeExpandedRoundedBotto
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_post_layot_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
binding = FragmentPostLayoutBottomSheetBinding.inflate(inflater, container, false);
cardLayoutTextView.setOnClickListener(view -> {
binding.cardLayoutTextViewPostLayoutBottomSheetFragment.setOnClickListener(view -> {
((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_CARD);
dismiss();
});
compactLayoutTextView.setOnClickListener(view -> {
binding.compactLayoutTextViewPostLayoutBottomSheetFragment.setOnClickListener(view -> {
((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_COMPACT);
dismiss();
});
galleryLayoutTextView.setOnClickListener(view -> {
binding.galleryLayoutTextViewPostLayoutBottomSheetFragment.setOnClickListener(view -> {
((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_GALLERY);
dismiss();
});
cardLayout2TextView.setOnClickListener(view -> {
binding.cardLayout2TextViewPostLayoutBottomSheetFragment.setOnClickListener(view -> {
((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_CARD_2);
dismiss();
});
binding.cardLayout3TextViewPostLayoutBottomSheetFragment.setOnClickListener(view -> {
((PostLayoutSelectionCallback) activity).postLayoutSelected(SharedPreferencesUtils.POST_LAYOUT_CARD_3);
dismiss();
});
if (activity.typeface != null) {
Utils.setFontToAllTextViews(rootView, activity.typeface);
Utils.setFontToAllTextViews(binding.getRoot(), activity.typeface);
}
return rootView;
return binding.getRoot();
}
@Override

View File

@ -1,73 +0,0 @@
package eu.toldi.infinityforlemmy.bottomsheetfragments;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.activities.LinkResolverActivity;
import eu.toldi.infinityforlemmy.activities.MainActivity;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.databinding.FragmentRedditApiInfoBottomSheetBinding;
import eu.toldi.infinityforlemmy.utils.Utils;
public class RedditAPIInfoBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {
private MainActivity mainActivity;
public RedditAPIInfoBottomSheetFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
FragmentRedditApiInfoBottomSheetBinding binding = FragmentRedditApiInfoBottomSheetBinding.inflate(inflater, container, false);
if (mainActivity != null && mainActivity.typeface != null) {
Utils.setFontToAllTextViews(binding.getRoot(), mainActivity.typeface);
}
binding.getRoot().setNestedScrollingEnabled(true);
SpannableString message = new SpannableString(getString(R.string.reddit_api_info, "https://www.reddit.com/r/reddit/comments/145bram/addressing_the_community_about_changes_to_our_api", "https://www.reddit.com/r/Infinity_For_Reddit/comments/147bhsg/the_future_of_infinity"));
Linkify.addLinks(message, Linkify.WEB_URLS);
binding.messageTextViewRedditApiInfoBottomSheetFragment.setText(message);
binding.messageTextViewRedditApiInfoBottomSheetFragment.setMovementMethod(BetterLinkMovementMethod.newInstance().setOnLinkClickListener((textView, url) -> {
Intent intent = new Intent(mainActivity, LinkResolverActivity.class);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}));
binding.messageTextViewRedditApiInfoBottomSheetFragment.setLinkTextColor(getResources().getColor(R.color.colorAccent));
binding.doNotShowThisAgainTextView.setOnClickListener(view -> {
binding.doNotShowThisAgainCheckBox.toggle();
});
binding.continueButtonRedditApiInfoBottomSheetFragment.setOnClickListener(view -> {
if (binding.doNotShowThisAgainCheckBox.isChecked()) {
mainActivity.doNotShowRedditAPIInfoAgain();
}
dismiss();
});
return binding.getRoot();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
mainActivity = (MainActivity) context;
}
}

View File

@ -35,13 +35,14 @@ public class CommentViewModel extends ViewModel {
hasCommentLiveData = Transformations.switchMap(commentDataSourceFactory.getCommentDataSourceLiveData(),
CommentDataSource::hasPostLiveData);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
sortTypeLiveData = new MutableLiveData<>(sortType);
PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
.setEnablePlaceholders(false)
.setPageSize(25)
.setPageSize(100)
.setPrefetchDistance(10)
.setInitialLoadSizeHint(10)
.build();
comments = Transformations.switchMap(sortTypeLiveData, sort -> {

View File

@ -13,6 +13,7 @@ import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.SortType;
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@ -22,19 +23,20 @@ public class FetchComment {
public static void fetchComments(Executor executor, Handler handler, Retrofit retrofit,
@Nullable String accessToken, Integer article,
Integer commentId, SortType.Type sortType, boolean expandChildren,
Integer page, FetchCommentListener fetchCommentListener) {
Integer page, CommentFilter commentFilter, FetchCommentListener fetchCommentListener) {
LemmyAPI api = retrofit.create(LemmyAPI.class);
Call<String> comments;
comments = api.getComments("All", sortType.value, 8, page, 25, null, null, article, commentId, false, accessToken);
comments.enqueue(new Callback<String>() {
comments.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {
ParseComment.parseComments(executor, handler, response.body(), commentId,
expandChildren, new ParseComment.ParseCommentListener() {
expandChildren, commentFilter,
new ParseComment.ParseCommentListener() {
@Override
public void onParseCommentSuccess(ArrayList<Comment> topLevelComments,
ArrayList<Comment> expandedComments,
@ -70,7 +72,7 @@ public class FetchComment {
moreComments = api.getComments("All", sortType.value, 8, page, 25, null, null, article, commentId, false, accessToken);
moreComments.enqueue(new Callback<String>() {
moreComments.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {

View File

@ -24,14 +24,14 @@ import java.util.TimeZone;
import java.util.concurrent.Executor;
import java.util.regex.Pattern;
import eu.toldi.infinityforlemmy.commentfilter.CommentFilter;
import eu.toldi.infinityforlemmy.user.BasicUserInfo;
import eu.toldi.infinityforlemmy.utils.JSONUtils;
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
public class ParseComment {
public static void parseComments(Executor executor, Handler handler, String response, Integer commentId,
boolean expandChildren,
boolean expandChildren, CommentFilter commentFilter,
ParseCommentListener parseCommentListener) {
executor.execute(() -> {
try {
@ -50,6 +50,9 @@ public class ParseComment {
orderedComments.add(singleComment);
parsedComments.put(singleComment.getId(), singleComment);
if (singleComment.getDepth() == 0) {
if (!CommentFilter.isCommentAllowed(singleComment, commentFilter)) {
continue;
}
topLevelComments.add(singleComment);
}
}
@ -58,7 +61,9 @@ public class ParseComment {
if (parentComment.getDepth() == 0) {
parentComment = null;
} else {
expandedNewComments.add(parentComment);
if (CommentFilter.isCommentAllowed(parentComment, commentFilter)) {
expandedNewComments.add(parentComment);
}
}
}
@ -68,6 +73,9 @@ public class ParseComment {
if (c.getParentId() != null) {
Comment parent = parsedComments.get(c.getParentId());
if (parent != null) {
if (!CommentFilter.isCommentAllowed(c, commentFilter)) {
continue;
}
parent.addChild(c);
}
}
@ -81,8 +89,13 @@ public class ParseComment {
if (topLevelComments.isEmpty() && !parsedComments.isEmpty() && parentComment != null) {
for (int i = 0; i < orderedComments.size(); i++) {
Comment c = orderedComments.get(i);
if (c.getParentId() == parentComment.getId())
if (c.getParentId() == parentComment.getId()) {
if (!CommentFilter.isCommentAllowed(c, commentFilter)) {
continue;
}
expandedNewComments.add(c);
}
}
}
@ -205,7 +218,8 @@ public class ParseComment {
}
private static void parseCommentRecursion(JSONArray comments, ArrayList<Comment> newCommentData,
ArrayList<String> moreChildrenIds, int depth) throws JSONException {
ArrayList<String> moreChildrenIds, int depth,
CommentFilter commentFilter) throws JSONException {
int actualCommentLength;
if (comments.length() == 0) {

View File

@ -0,0 +1,123 @@
package eu.toldi.infinityforlemmy.commentfilter;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
import java.util.List;
import eu.toldi.infinityforlemmy.comment.Comment;
@Entity(tableName = "comment_filter")
public class CommentFilter implements Parcelable {
@PrimaryKey
@NonNull
public String name = "New Filter";
@ColumnInfo(name = "max_vote")
public int maxVote = -1;
@ColumnInfo(name = "min_vote")
public int minVote = -1;
@ColumnInfo(name = "exclude_strings")
public String excludeStrings;
@ColumnInfo(name = "exclude_users")
public String excludeUsers;
public CommentFilter() {
}
protected CommentFilter(Parcel in) {
name = in.readString();
maxVote = in.readInt();
minVote = in.readInt();
excludeStrings = in.readString();
excludeUsers = in.readString();
}
public static final Creator<CommentFilter> CREATOR = new Creator<CommentFilter>() {
@Override
public CommentFilter createFromParcel(Parcel in) {
return new CommentFilter(in);
}
@Override
public CommentFilter[] newArray(int size) {
return new CommentFilter[size];
}
};
public static boolean isCommentAllowed(Comment comment, CommentFilter commentFilter) {
int score = comment.getScore() + comment.getVoteType();
if (commentFilter.maxVote >= 0 && score > commentFilter.maxVote) {
return false;
}
if (commentFilter.minVote >= 0 && score < commentFilter.minVote) {
return false;
}
if (commentFilter.excludeStrings != null && !commentFilter.excludeStrings.equals("")) {
String[] titles = commentFilter.excludeStrings.split(",", 0);
for (String t : titles) {
if (!t.trim().equals("") && comment.getCommentRawText().toLowerCase().contains(t.toLowerCase().trim())) {
return false;
}
}
}
if (commentFilter.excludeUsers != null && !commentFilter.excludeUsers.equals("")) {
String[] users = commentFilter.excludeUsers.split(",", 0);
for (String u : users) {
if (!u.trim().equals("") && comment.getAuthor().getQualifiedName().equalsIgnoreCase(u.trim())) {
return false;
}
}
}
return true;
}
public static CommentFilter mergeCommentFilter(List<CommentFilter> commentFilterList) {
if (commentFilterList.size() == 1) {
return commentFilterList.get(0);
}
CommentFilter commentFilter = new CommentFilter();
StringBuilder stringBuilder;
commentFilter.name = "Merged";
for (CommentFilter c : commentFilterList) {
commentFilter.maxVote = Math.min(c.maxVote, commentFilter.maxVote);
commentFilter.minVote = Math.max(c.minVote, commentFilter.minVote);
if (c.excludeStrings != null && !c.excludeStrings.equals("")) {
stringBuilder = new StringBuilder(commentFilter.excludeStrings == null ? "" : commentFilter.excludeStrings);
stringBuilder.append(",").append(c.excludeStrings);
commentFilter.excludeStrings = stringBuilder.toString();
}
if (c.excludeUsers != null && !c.excludeUsers.equals("")) {
stringBuilder = new StringBuilder(commentFilter.excludeUsers == null ? "" : commentFilter.excludeUsers);
stringBuilder.append(",").append(c.excludeUsers);
commentFilter.excludeUsers = stringBuilder.toString();
}
}
return commentFilter;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(maxVote);
dest.writeInt(minVote);
dest.writeString(excludeStrings);
dest.writeString(excludeUsers);
}
}

View File

@ -0,0 +1,47 @@
package eu.toldi.infinityforlemmy.commentfilter;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Transaction;
import java.util.List;
@Dao
public interface CommentFilterDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(CommentFilter CommentFilter);
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertAll(List<CommentFilter> CommentFilters);
@Query("DELETE FROM comment_filter")
void deleteAllCommentFilters();
@Delete
void deleteCommentFilter(CommentFilter CommentFilter);
@Query("DELETE FROM comment_filter WHERE name = :name")
void deleteCommentFilter(String name);
@Query("SELECT * FROM comment_filter WHERE name = :name LIMIT 1")
CommentFilter getCommentFilter(String name);
@Query("SELECT * FROM comment_filter ORDER BY name")
LiveData<List<CommentFilter>> getAllCommentFiltersLiveData();
@Query("SELECT * FROM comment_filter")
List<CommentFilter> getAllCommentFilters();
@Query("SELECT * FROM comment_filter WHERE (comment_filter.name IN " +
"(SELECT comment_filter_usage.name FROM comment_filter_usage WHERE (usage = :usage AND name_of_usage = :nameOfUsage COLLATE NOCASE)))" +
" OR (comment_filter.name NOT IN (SELECT comment_filter_usage.name FROM comment_filter_usage))")
List<CommentFilter> getValidCommentFilters(int usage, String nameOfUsage);
@Transaction
@Query("SELECT * FROM comment_filter ORDER BY name")
public LiveData<List<CommentFilterWithUsage>> getAllCommentFilterWithUsageLiveData();
}

View File

@ -0,0 +1,61 @@
package eu.toldi.infinityforlemmy.commentfilter;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
@Entity(tableName = "comment_filter_usage", primaryKeys = {"name", "usage", "name_of_usage"},
foreignKeys = @ForeignKey(entity = CommentFilter.class, parentColumns = "name",
childColumns = "name", onDelete = ForeignKey.CASCADE))
public class CommentFilterUsage implements Parcelable {
public static final int SUBREDDIT_TYPE = 1;
@NonNull
@ColumnInfo(name = "name")
public String name;
@ColumnInfo(name = "usage")
public int usage;
@NonNull
@ColumnInfo(name = "name_of_usage")
public String nameOfUsage;
public CommentFilterUsage(@NonNull String name, int usage, @NonNull String nameOfUsage) {
this.name = name;
this.usage = usage;
this.nameOfUsage = nameOfUsage;
}
protected CommentFilterUsage(Parcel in) {
name = in.readString();
usage = in.readInt();
nameOfUsage = in.readString();
}
public static final Creator<CommentFilterUsage> CREATOR = new Creator<CommentFilterUsage>() {
@Override
public CommentFilterUsage createFromParcel(Parcel in) {
return new CommentFilterUsage(in);
}
@Override
public CommentFilterUsage[] newArray(int size) {
return new CommentFilterUsage[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(usage);
dest.writeString(nameOfUsage);
}
}

View File

@ -0,0 +1,31 @@
package eu.toldi.infinityforlemmy.commentfilter;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import java.util.List;
@Dao
public interface CommentFilterUsageDao {
@Query("SELECT * FROM comment_filter_usage WHERE name = :name")
LiveData<List<CommentFilterUsage>> getAllCommentFilterUsageLiveData(String name);
@Query("SELECT * FROM comment_filter_usage WHERE name = :name")
List<CommentFilterUsage> getAllCommentFilterUsage(String name);
@Query("SELECT * FROM comment_filter_usage")
List<CommentFilterUsage> getAllCommentFilterUsageForBackup();
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(CommentFilterUsage CommentFilterUsage);
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertAll(List<CommentFilterUsage> CommentFilterUsageList);
@Delete
void deleteCommentFilterUsage(CommentFilterUsage CommentFilterUsage);
}

View File

@ -0,0 +1,41 @@
package eu.toldi.infinityforlemmy.commentfilter;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import java.util.List;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class CommentFilterUsageViewModel extends ViewModel {
private LiveData<List<CommentFilterUsage>> mCommentFilterUsageListLiveData;
public CommentFilterUsageViewModel(RedditDataRoomDatabase redditDataRoomDatabase, String name) {
mCommentFilterUsageListLiveData = redditDataRoomDatabase.commentFilterUsageDao().getAllCommentFilterUsageLiveData(name);
}
public LiveData<List<CommentFilterUsage>> getCommentFilterUsageListLiveData() {
return mCommentFilterUsageListLiveData;
}
public static class Factory extends ViewModelProvider.NewInstanceFactory {
private final RedditDataRoomDatabase mRedditDataRoomDatabase;
private final String mName;
public Factory(RedditDataRoomDatabase redditDataRoomDatabase, String name) {
mRedditDataRoomDatabase = redditDataRoomDatabase;
mName = name;
}
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
//noinspection unchecked
return (T) new CommentFilterUsageViewModel(mRedditDataRoomDatabase, mName);
}
}
}

View File

@ -0,0 +1,16 @@
package eu.toldi.infinityforlemmy.commentfilter;
import androidx.room.Embedded;
import androidx.room.Relation;
import java.util.List;
public class CommentFilterWithUsage {
@Embedded
public CommentFilter commentFilter;
@Relation(
parentColumn = "name",
entityColumn = "name"
)
public List<CommentFilterUsage> commentFilterUsageList;
}

View File

@ -0,0 +1,39 @@
package eu.toldi.infinityforlemmy.commentfilter;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import java.util.List;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class CommentFilterWithUsageViewModel extends ViewModel {
private LiveData<List<CommentFilterWithUsage>> mCommentFilterWithUsageListLiveData;
public CommentFilterWithUsageViewModel(RedditDataRoomDatabase redditDataRoomDatabase) {
mCommentFilterWithUsageListLiveData = redditDataRoomDatabase.commentFilterDao().getAllCommentFilterWithUsageLiveData();
}
public LiveData<List<CommentFilterWithUsage>> getCommentFilterWithUsageListLiveData() {
return mCommentFilterWithUsageListLiveData;
}
public static class Factory extends ViewModelProvider.NewInstanceFactory {
private final RedditDataRoomDatabase mRedditDataRoomDatabase;
public Factory(RedditDataRoomDatabase redditDataRoomDatabase) {
mRedditDataRoomDatabase = redditDataRoomDatabase;
}
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
//noinspection unchecked
return (T) new CommentFilterWithUsageViewModel(mRedditDataRoomDatabase);
}
}
}

View File

@ -0,0 +1,12 @@
package eu.toldi.infinityforlemmy.commentfilter;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class DeleteCommentFilter {
public static void deleteCommentFilter(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor, CommentFilter commentFilter) {
executor.execute(() -> redditDataRoomDatabase.commentFilterDao().deleteCommentFilter(commentFilter));
}
}

View File

@ -0,0 +1,13 @@
package eu.toldi.infinityforlemmy.commentfilter;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class DeleteCommentFilterUsage {
public static void deleteCommentFilterUsage(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor,
CommentFilterUsage commentFilterUsage) {
executor.execute(() -> redditDataRoomDatabase.commentFilterUsageDao().deleteCommentFilterUsage(commentFilterUsage));
}
}

View File

@ -0,0 +1,25 @@
package eu.toldi.infinityforlemmy.commentfilter;
import android.os.Handler;
import java.util.List;
import java.util.concurrent.Executor;
;import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class FetchCommentFilter {
public static void fetchCommentFilter(Executor executor, Handler handler,
RedditDataRoomDatabase redditDataRoomDatabase,
String subreddit, FetchCommentFilterListener fetchCommentFilterListener) {
executor.execute(() -> {
List<CommentFilter> commentFilterList = redditDataRoomDatabase.commentFilterDao().getValidCommentFilters(CommentFilterUsage.SUBREDDIT_TYPE, subreddit);
CommentFilter commentFilter = CommentFilter.mergeCommentFilter(commentFilterList);
handler.post(() -> fetchCommentFilterListener.success(commentFilter));
});
}
public interface FetchCommentFilterListener {
void success(CommentFilter commentFilter);
}
}

View File

@ -0,0 +1,38 @@
package eu.toldi.infinityforlemmy.commentfilter;
import android.os.Handler;
import java.util.List;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class SaveCommentFilter {
public interface SaveCommentFilterListener {
void success();
void duplicate();
}
public static void saveCommentFilter(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase,
CommentFilter commentFilter, String originalName, SaveCommentFilter.SaveCommentFilterListener saveCommentFilterListener) {
executor.execute(() -> {
if (!originalName.equals(commentFilter.name) &&
redditDataRoomDatabase.commentFilterDao().getCommentFilter(commentFilter.name) != null) {
handler.post(saveCommentFilterListener::duplicate);
} else {
List<CommentFilterUsage> commentFilterUsages = redditDataRoomDatabase.commentFilterUsageDao().getAllCommentFilterUsage(originalName);
if (!originalName.equals(commentFilter.name)) {
redditDataRoomDatabase.commentFilterDao().deleteCommentFilter(originalName);
}
redditDataRoomDatabase.commentFilterDao().insert(commentFilter);
for (CommentFilterUsage commentFilterUsage : commentFilterUsages) {
commentFilterUsage.name = commentFilter.name;
redditDataRoomDatabase.commentFilterUsageDao().insert(commentFilterUsage);
}
handler.post(saveCommentFilterListener::success);
}
});
}
}

View File

@ -0,0 +1,13 @@
package eu.toldi.infinityforlemmy.commentfilter;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
public class SaveCommentFilterUsage {
public static void saveCommentFilterUsage(RedditDataRoomDatabase redditDataRoomDatabase, Executor executor,
CommentFilterUsage commentFilterUsage) {
executor.execute(() -> redditDataRoomDatabase.commentFilterUsageDao().insert(commentFilterUsage));
}
}

View File

@ -64,6 +64,10 @@ public class CustomTheme {
public int cardViewBackgroundColor;
@ColumnInfo(name = "read_post_card_view_background_color")
public int readPostCardViewBackgroundColor;
@ColumnInfo(name = "filled_card_view_background_color")
public int filledCardViewBackgroundColor;
@ColumnInfo(name = "read_post_filled_card_view_background_color")
public int readPostFilledCardViewBackgroundColor;
@ColumnInfo(name = "comment_background_color")
public int commentBackgroundColor;
@ColumnInfo(name = "bottom_app_bar_background_color")
@ -255,71 +259,73 @@ public class CustomTheme {
customTheme.backgroundColor = customThemeSettingsItems.get(19).colorValue;
customTheme.cardViewBackgroundColor = customThemeSettingsItems.get(20).colorValue;
customTheme.readPostCardViewBackgroundColor = customThemeSettingsItems.get(21).colorValue;
customTheme.commentBackgroundColor = customThemeSettingsItems.get(22).colorValue;
customTheme.fullyCollapsedCommentBackgroundColor = customThemeSettingsItems.get(23).colorValue;
customTheme.awardedCommentBackgroundColor = customThemeSettingsItems.get(24).colorValue;
customTheme.receivedMessageBackgroundColor = customThemeSettingsItems.get(25).colorValue;
customTheme.sentMessageBackgroundColor = customThemeSettingsItems.get(26).colorValue;
customTheme.bottomAppBarBackgroundColor = customThemeSettingsItems.get(27).colorValue;
customTheme.primaryIconColor = customThemeSettingsItems.get(28).colorValue;
customTheme.bottomAppBarIconColor = customThemeSettingsItems.get(29).colorValue;
customTheme.postIconAndInfoColor = customThemeSettingsItems.get(30).colorValue;
customTheme.commentIconAndInfoColor = customThemeSettingsItems.get(31).colorValue;
customTheme.fabIconColor = customThemeSettingsItems.get(32).colorValue;
customTheme.sendMessageIconColor = customThemeSettingsItems.get(33).colorValue;
customTheme.toolbarPrimaryTextAndIconColor = customThemeSettingsItems.get(34).colorValue;
customTheme.toolbarSecondaryTextColor = customThemeSettingsItems.get(35).colorValue;
customTheme.circularProgressBarBackground = customThemeSettingsItems.get(36).colorValue;
customTheme.mediaIndicatorIconColor = customThemeSettingsItems.get(37).colorValue;
customTheme.mediaIndicatorBackgroundColor = customThemeSettingsItems.get(38).colorValue;
customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = customThemeSettingsItems.get(39).colorValue;
customTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = customThemeSettingsItems.get(40).colorValue;
customTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(41).colorValue;
customTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = customThemeSettingsItems.get(42).colorValue;
customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = customThemeSettingsItems.get(43).colorValue;
customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(44).colorValue;
customTheme.upvoted = customThemeSettingsItems.get(45).colorValue;
customTheme.downvoted = customThemeSettingsItems.get(46).colorValue;
customTheme.postTypeBackgroundColor = customThemeSettingsItems.get(47).colorValue;
customTheme.postTypeTextColor = customThemeSettingsItems.get(48).colorValue;
customTheme.spoilerBackgroundColor = customThemeSettingsItems.get(49).colorValue;
customTheme.spoilerTextColor = customThemeSettingsItems.get(50).colorValue;
customTheme.nsfwBackgroundColor = customThemeSettingsItems.get(51).colorValue;
customTheme.nsfwTextColor = customThemeSettingsItems.get(52).colorValue;
customTheme.flairBackgroundColor = customThemeSettingsItems.get(53).colorValue;
customTheme.flairTextColor = customThemeSettingsItems.get(54).colorValue;
customTheme.awardsBackgroundColor = customThemeSettingsItems.get(55).colorValue;
customTheme.awardsTextColor = customThemeSettingsItems.get(56).colorValue;
customTheme.archivedTint = customThemeSettingsItems.get(57).colorValue;
customTheme.lockedIconTint = customThemeSettingsItems.get(58).colorValue;
customTheme.crosspostIconTint = customThemeSettingsItems.get(59).colorValue;
customTheme.upvoteRatioIconTint = customThemeSettingsItems.get(60).colorValue;
customTheme.stickiedPostIconTint = customThemeSettingsItems.get(61).colorValue;
customTheme.noPreviewPostTypeIconTint = customThemeSettingsItems.get(62).colorValue;
customTheme.subscribed = customThemeSettingsItems.get(63).colorValue;
customTheme.unsubscribed = customThemeSettingsItems.get(64).colorValue;
customTheme.username = customThemeSettingsItems.get(65).colorValue;
customTheme.subreddit = customThemeSettingsItems.get(66).colorValue;
customTheme.authorFlairTextColor = customThemeSettingsItems.get(67).colorValue;
customTheme.submitter = customThemeSettingsItems.get(68).colorValue;
customTheme.moderator = customThemeSettingsItems.get(69).colorValue;
customTheme.currentUser = customThemeSettingsItems.get(70).colorValue;
customTheme.singleCommentThreadBackgroundColor = customThemeSettingsItems.get(71).colorValue;
customTheme.unreadMessageBackgroundColor = customThemeSettingsItems.get(72).colorValue;
customTheme.dividerColor = customThemeSettingsItems.get(73).colorValue;
customTheme.noPreviewPostTypeBackgroundColor = customThemeSettingsItems.get(74).colorValue;
customTheme.voteAndReplyUnavailableButtonColor = customThemeSettingsItems.get(75).colorValue;
customTheme.commentVerticalBarColor1 = customThemeSettingsItems.get(76).colorValue;
customTheme.commentVerticalBarColor2 = customThemeSettingsItems.get(77).colorValue;
customTheme.commentVerticalBarColor3 = customThemeSettingsItems.get(78).colorValue;
customTheme.commentVerticalBarColor4 = customThemeSettingsItems.get(79).colorValue;
customTheme.commentVerticalBarColor5 = customThemeSettingsItems.get(80).colorValue;
customTheme.commentVerticalBarColor6 = customThemeSettingsItems.get(81).colorValue;
customTheme.commentVerticalBarColor7 = customThemeSettingsItems.get(82).colorValue;
customTheme.navBarColor = customThemeSettingsItems.get(83).colorValue;
customTheme.isLightStatusBar = customThemeSettingsItems.get(84).isEnabled;
customTheme.isLightNavBar = customThemeSettingsItems.get(85).isEnabled;
customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = customThemeSettingsItems.get(86).isEnabled;
customTheme.filledCardViewBackgroundColor = customThemeSettingsItems.get(22).colorValue;
customTheme.readPostFilledCardViewBackgroundColor = customThemeSettingsItems.get(23).colorValue;
customTheme.commentBackgroundColor = customThemeSettingsItems.get(24).colorValue;
customTheme.fullyCollapsedCommentBackgroundColor = customThemeSettingsItems.get(25).colorValue;
customTheme.awardedCommentBackgroundColor = customThemeSettingsItems.get(26).colorValue;
customTheme.receivedMessageBackgroundColor = customThemeSettingsItems.get(27).colorValue;
customTheme.sentMessageBackgroundColor = customThemeSettingsItems.get(28).colorValue;
customTheme.bottomAppBarBackgroundColor = customThemeSettingsItems.get(29).colorValue;
customTheme.primaryIconColor = customThemeSettingsItems.get(30).colorValue;
customTheme.bottomAppBarIconColor = customThemeSettingsItems.get(31).colorValue;
customTheme.postIconAndInfoColor = customThemeSettingsItems.get(32).colorValue;
customTheme.commentIconAndInfoColor = customThemeSettingsItems.get(33).colorValue;
customTheme.fabIconColor = customThemeSettingsItems.get(34).colorValue;
customTheme.sendMessageIconColor = customThemeSettingsItems.get(35).colorValue;
customTheme.toolbarPrimaryTextAndIconColor = customThemeSettingsItems.get(36).colorValue;
customTheme.toolbarSecondaryTextColor = customThemeSettingsItems.get(37).colorValue;
customTheme.circularProgressBarBackground = customThemeSettingsItems.get(38).colorValue;
customTheme.mediaIndicatorIconColor = customThemeSettingsItems.get(39).colorValue;
customTheme.mediaIndicatorBackgroundColor = customThemeSettingsItems.get(40).colorValue;
customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = customThemeSettingsItems.get(41).colorValue;
customTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = customThemeSettingsItems.get(42).colorValue;
customTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(43).colorValue;
customTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = customThemeSettingsItems.get(44).colorValue;
customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = customThemeSettingsItems.get(45).colorValue;
customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(46).colorValue;
customTheme.upvoted = customThemeSettingsItems.get(47).colorValue;
customTheme.downvoted = customThemeSettingsItems.get(48).colorValue;
customTheme.postTypeBackgroundColor = customThemeSettingsItems.get(49).colorValue;
customTheme.postTypeTextColor = customThemeSettingsItems.get(50).colorValue;
customTheme.spoilerBackgroundColor = customThemeSettingsItems.get(51).colorValue;
customTheme.spoilerTextColor = customThemeSettingsItems.get(52).colorValue;
customTheme.nsfwBackgroundColor = customThemeSettingsItems.get(53).colorValue;
customTheme.nsfwTextColor = customThemeSettingsItems.get(54).colorValue;
customTheme.flairBackgroundColor = customThemeSettingsItems.get(55).colorValue;
customTheme.flairTextColor = customThemeSettingsItems.get(56).colorValue;
customTheme.awardsBackgroundColor = customThemeSettingsItems.get(57).colorValue;
customTheme.awardsTextColor = customThemeSettingsItems.get(58).colorValue;
customTheme.archivedTint = customThemeSettingsItems.get(59).colorValue;
customTheme.lockedIconTint = customThemeSettingsItems.get(60).colorValue;
customTheme.crosspostIconTint = customThemeSettingsItems.get(61).colorValue;
customTheme.upvoteRatioIconTint = customThemeSettingsItems.get(62).colorValue;
customTheme.stickiedPostIconTint = customThemeSettingsItems.get(63).colorValue;
customTheme.noPreviewPostTypeIconTint = customThemeSettingsItems.get(64).colorValue;
customTheme.subscribed = customThemeSettingsItems.get(65).colorValue;
customTheme.unsubscribed = customThemeSettingsItems.get(66).colorValue;
customTheme.username = customThemeSettingsItems.get(67).colorValue;
customTheme.subreddit = customThemeSettingsItems.get(68).colorValue;
customTheme.authorFlairTextColor = customThemeSettingsItems.get(69).colorValue;
customTheme.submitter = customThemeSettingsItems.get(70).colorValue;
customTheme.moderator = customThemeSettingsItems.get(71).colorValue;
customTheme.currentUser = customThemeSettingsItems.get(72).colorValue;
customTheme.singleCommentThreadBackgroundColor = customThemeSettingsItems.get(73).colorValue;
customTheme.unreadMessageBackgroundColor = customThemeSettingsItems.get(74).colorValue;
customTheme.dividerColor = customThemeSettingsItems.get(75).colorValue;
customTheme.noPreviewPostTypeBackgroundColor = customThemeSettingsItems.get(76).colorValue;
customTheme.voteAndReplyUnavailableButtonColor = customThemeSettingsItems.get(77).colorValue;
customTheme.commentVerticalBarColor1 = customThemeSettingsItems.get(78).colorValue;
customTheme.commentVerticalBarColor2 = customThemeSettingsItems.get(79).colorValue;
customTheme.commentVerticalBarColor3 = customThemeSettingsItems.get(80).colorValue;
customTheme.commentVerticalBarColor4 = customThemeSettingsItems.get(81).colorValue;
customTheme.commentVerticalBarColor5 = customThemeSettingsItems.get(82).colorValue;
customTheme.commentVerticalBarColor6 = customThemeSettingsItems.get(83).colorValue;
customTheme.commentVerticalBarColor7 = customThemeSettingsItems.get(84).colorValue;
customTheme.navBarColor = customThemeSettingsItems.get(85).colorValue;
customTheme.isLightStatusBar = customThemeSettingsItems.get(86).isEnabled;
customTheme.isLightNavBar = customThemeSettingsItems.get(87).isEnabled;
customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = customThemeSettingsItems.get(88).isEnabled;
return customTheme;
}

View File

@ -144,6 +144,14 @@ public class CustomThemeSettingsItem implements Parcelable {
context.getString(R.string.theme_item_read_post_card_view_background_color),
context.getString(R.string.theme_item_read_post_card_view_background_color_detail),
customTheme.readPostCardViewBackgroundColor));
customThemeSettingsItems.add(new CustomThemeSettingsItem(
context.getString(R.string.theme_item_filled_card_view_background_color),
context.getString(R.string.theme_item_filled_card_view_background_color_detail),
customTheme.filledCardViewBackgroundColor));
customThemeSettingsItems.add(new CustomThemeSettingsItem(
context.getString(R.string.theme_item_read_post_filled_card_view_background_color),
context.getString(R.string.theme_item_read_post_filled_card_view_background_color_detail),
customTheme.readPostFilledCardViewBackgroundColor));
customThemeSettingsItems.add(new CustomThemeSettingsItem(
context.getString(R.string.theme_item_comment_background_color),
context.getString(R.string.theme_item_comment_background_color_detail),

View File

@ -127,6 +127,16 @@ public class CustomThemeWrapper {
getDefaultColor("#F2E9E1", "#2B3B51", "#282828"));
}
public int getFilledCardViewBackgroundColor() {
return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.FILLED_CARD_VIEW_BACKGROUND_COLOR,
getDefaultColor("#E6F4FF", "#242424", "#000000"));
}
public int getReadPostFilledCardViewBackgroundColor() {
return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.READ_POST_FILLED_CARD_VIEW_BACKGROUND_COLOR,
getDefaultColor("#F5F5F5", "#101010", "#000000"));
}
public int getCommentBackgroundColor() {
return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_BACKGROUND_COLOR,
getDefaultColor("#F6F2EE", "#192330", "#282828"));
@ -548,6 +558,8 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#FFFFFF");
customTheme.cardViewBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#F5F5F5");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#E6F4FF");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#F5F5F5");
customTheme.commentBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.primaryIconColor = Color.parseColor("#000000");
@ -641,6 +653,8 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#121212");
customTheme.cardViewBackgroundColor = Color.parseColor("#242424");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#101010");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#242424");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#101010");
customTheme.commentBackgroundColor = Color.parseColor("#242424");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#121212");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@ -734,6 +748,8 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#000000");
customTheme.cardViewBackgroundColor = Color.parseColor("#000000");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.commentBackgroundColor = Color.parseColor("#000000");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#000000");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@ -827,6 +843,8 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#FFFFFF");
customTheme.cardViewBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#F5F5F5");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#E6F4FF");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#F5F5F5");
customTheme.commentBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.primaryIconColor = Color.parseColor("#000000");
@ -920,6 +938,8 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#121212");
customTheme.cardViewBackgroundColor = Color.parseColor("#242424");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#101010");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#242424");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#101010");
customTheme.commentBackgroundColor = Color.parseColor("#242424");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#121212");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@ -1013,6 +1033,8 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#000000");
customTheme.cardViewBackgroundColor = Color.parseColor("#000000");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.commentBackgroundColor = Color.parseColor("#000000");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#000000");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@ -1106,6 +1128,8 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#FFFFFF");
customTheme.cardViewBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#F5F5F5");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#FFE9F3");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#F5F5F5");
customTheme.commentBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#FFFFFF");
customTheme.primaryIconColor = Color.parseColor("#000000");
@ -1199,6 +1223,8 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#121212");
customTheme.cardViewBackgroundColor = Color.parseColor("#242424");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#101010");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#242424");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#101010");
customTheme.commentBackgroundColor = Color.parseColor("#242424");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#121212");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@ -1292,6 +1318,8 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#000000");
customTheme.cardViewBackgroundColor = Color.parseColor("#000000");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#000000");
customTheme.commentBackgroundColor = Color.parseColor("#000000");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#000000");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@ -1385,6 +1413,8 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#282A36");
customTheme.cardViewBackgroundColor = Color.parseColor("#393A59");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#1C1F3D");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#393A59");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#1C1F3D");
customTheme.commentBackgroundColor = Color.parseColor("#393A59");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#393A59");
customTheme.primaryIconColor = Color.parseColor("#FFFFFF");
@ -1478,6 +1508,8 @@ public class CustomThemeWrapper {
customTheme.backgroundColor = Color.parseColor("#DAD0DE");
customTheme.cardViewBackgroundColor = Color.parseColor("#C0F0F4");
customTheme.readPostCardViewBackgroundColor = Color.parseColor("#D2E7EA");
customTheme.filledCardViewBackgroundColor = Color.parseColor("#C0F0F4");
customTheme.readPostFilledCardViewBackgroundColor = Color.parseColor("#D2E7EA");
customTheme.commentBackgroundColor = Color.parseColor("#C0F0F4");
customTheme.bottomAppBarBackgroundColor = Color.parseColor("#D48AE0");
customTheme.primaryIconColor = Color.parseColor("#000000");

View File

@ -0,0 +1,31 @@
package eu.toldi.infinityforlemmy.customviews;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
public class InterceptTouchEventLinearLayout extends LinearLayout {
public InterceptTouchEventLinearLayout(Context context) {
super(context);
}
public InterceptTouchEventLinearLayout(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public InterceptTouchEventLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return true;
}
public InterceptTouchEventLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
}

View File

@ -389,7 +389,7 @@ public class SliderPanel extends FrameLayout {
/**
* The drag helper callbacks for dragging the slidr attachment from the bottom of hte screen
* The drag helper callbacks for dragging the slidr attachment from the bottom of the screen
*/
private final ViewDragHelper.Callback bottomCallback = new ViewDragHelper.Callback() {
@Override

View File

@ -154,7 +154,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
@Override
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
if (!(viewHolder instanceof CommentsListingRecyclerViewAdapter.CommentViewHolder)) {
if (!(viewHolder instanceof CommentsListingRecyclerViewAdapter.CommentBaseViewHolder)) {
return makeMovementFlags(0, 0);
}
int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;

View File

@ -29,7 +29,6 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import me.zhanghai.android.fastscroll.FastScrollerBuilder;
import eu.toldi.infinityforlemmy.FragmentCommunicator;
import eu.toldi.infinityforlemmy.Infinity;
import eu.toldi.infinityforlemmy.R;
@ -45,6 +44,7 @@ import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
import eu.toldi.infinityforlemmy.multireddit.MultiRedditViewModel;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import me.zhanghai.android.fastscroll.FastScrollerBuilder;
import retrofit2.Retrofit;
public class MultiRedditListingFragment extends Fragment implements FragmentCommunicator {
@ -111,9 +111,9 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
boolean isGettingMultiredditInfo = getArguments().getBoolean(EXTRA_IS_GETTING_MULTIREDDIT_INFO, false);
if (accessToken == null) {
mSwipeRefreshLayout.setEnabled(false);
}
mSwipeRefreshLayout.setEnabled(false);
mGlide = Glide.with(this);
@ -122,7 +122,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(mActivity,
mExecutor, mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken,
new MultiRedditListingRecyclerViewAdapter.OnItemClickListener() {
@Override
@Override
public void onClick(MultiReddit multiReddit) {
if (mActivity instanceof MultiredditSelectionActivity) {
((MultiredditSelectionActivity) mActivity).getSelectedMultireddit(multiReddit);

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