mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-11-01 09:28:12 +01:00
Compare commits
104 Commits
alpha_vers
...
v0.0.8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffc2d669e5 | ||
|
|
926e1162f0 | ||
|
|
6cf69ee26d | ||
|
|
279820c1be | ||
|
|
1d7031f3d4 | ||
|
|
252e00b67a | ||
|
|
a8d63c7480 | ||
|
|
2020172b56 | ||
|
|
2d55a4c8ec | ||
|
|
20a3e0220b | ||
|
|
feeeefa2d2 | ||
|
|
d25137020f | ||
|
|
3c4fb4162e | ||
|
|
28e9ae950e | ||
|
|
888e741aa9 | ||
|
|
9f7a6e1738 | ||
|
|
76f4a0738f | ||
|
|
63327946be | ||
|
|
84d90adc54 | ||
|
|
cf15732a39 | ||
|
|
2eee73753f | ||
|
|
62d097357a | ||
|
|
c35a690335 | ||
|
|
18af76ce92 | ||
|
|
6e7256d9a5 | ||
|
|
2af6c5a742 | ||
|
|
5c39fddbc6 | ||
|
|
a708853199 | ||
|
|
acb651cf92 | ||
|
|
562c91acb2 | ||
|
|
484f9607b1 | ||
|
|
9149ee224c | ||
|
|
1bb1d3b9af | ||
|
|
0b76390069 | ||
|
|
5de8751079 | ||
|
|
4bfe1b0c02 | ||
|
|
15c1676d0b | ||
|
|
49ff90aad1 | ||
|
|
6adaaf1965 | ||
|
|
6d114f84fa | ||
|
|
394cff9ebe | ||
|
|
465abd4498 | ||
|
|
0178569f14 | ||
|
|
f7185445e1 | ||
|
|
d4b107bc79 | ||
|
|
fd14753a1d | ||
|
|
7cc4e93ad4 | ||
|
|
4c95404fe1 | ||
|
|
1c2212f0fe | ||
|
|
065fcedd34 | ||
|
|
3a66a79f49 | ||
|
|
907f6e92c3 | ||
|
|
426c3e6979 | ||
|
|
92292be472 | ||
|
|
3e10186c7c | ||
|
|
1974322013 | ||
|
|
a2e22bc525 | ||
|
|
7e433954c5 | ||
|
|
d47e2dac92 | ||
|
|
de3bea0729 | ||
|
|
3c91007d93 | ||
|
|
debb3e04df | ||
|
|
8c758460bc | ||
|
|
2bb1189e15 | ||
|
|
233fc38c23 | ||
|
|
215d31f8ea | ||
|
|
8ae681c753 | ||
|
|
554eb3c2fe | ||
|
|
c1f8f5a681 | ||
|
|
bb5c82aa60 | ||
|
|
72ba41c940 | ||
|
|
40b6722e66 | ||
|
|
dd3b72bc1f | ||
|
|
e9ecae117d | ||
|
|
5e4793bdaf | ||
|
|
fe351a8466 | ||
|
|
b1b12aba31 | ||
|
|
d2b95e1db6 | ||
|
|
20c317b63f | ||
|
|
f2d14a975d | ||
|
|
442310cad3 | ||
|
|
b8da5c6acb | ||
|
|
2ed15f3d5c | ||
|
|
d926fabe09 | ||
|
|
e815a1444d | ||
|
|
df81866821 | ||
|
|
497f6c79d2 | ||
|
|
6eb585800f | ||
|
|
df842d33e1 | ||
|
|
919d259f61 | ||
|
|
2fc4020b72 | ||
|
|
9d6e15edb7 | ||
|
|
44956bd951 | ||
|
|
388b895499 | ||
|
|
5b26d57fdb | ||
|
|
e2de8b8160 | ||
|
|
f3bff30ef0 | ||
|
|
6704772fb2 | ||
|
|
efc74a074c | ||
|
|
3b5852d1e4 | ||
|
|
0fa2da6ffa | ||
|
|
e3a4db17d2 | ||
|
|
2828429120 | ||
|
|
f2f057827a |
49
.gitea/issue_template/bug_report.md
Normal file
49
.gitea/issue_template/bug_report.md
Normal file
@@ -0,0 +1,49 @@
|
||||
---
|
||||
|
||||
name: "Bug Report"
|
||||
about: "Report a Bug!"
|
||||
title: " [Bug] "
|
||||
ref: "master"
|
||||
labels:
|
||||
|
||||
- Kind/Bug
|
||||
|
||||
---
|
||||
### Description of the Issue:
|
||||
|
||||
<!-- Provide a clear and concise description of what the issue is about. -->
|
||||
|
||||
### Steps to Reproduce:
|
||||
|
||||
<!-- Explain the steps to reproduce the issue, if applicable. -->
|
||||
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
### Expected Behavior:
|
||||
|
||||
<!-- Describe what you expected to happen. -->
|
||||
|
||||
### Actual Behavior:
|
||||
|
||||
<!-- Describe what actually happened. Include screenshots if applicable. -->
|
||||
|
||||
### App Information:
|
||||
|
||||
- **Version:** <!-- e.g. 1.0.0 -->
|
||||
- **Device:** <!-- e.g. Samsung Galaxy S10 -->
|
||||
- **Android Version:** <!-- e.g. Android 11 -->
|
||||
- **Installation Source:** <!-- e.g. Google Play Store, APK -->
|
||||
|
||||
### Log Files:
|
||||
|
||||
<!-- If applicable, include log files or error messages related to this issue. -->
|
||||
|
||||
### Additional Context:
|
||||
|
||||
<!-- Add any other context about the problem here, such as relevant system configuration or screenshots. -->
|
||||
|
||||
### Potential Solutions or Workarounds:
|
||||
|
||||
<!-- If you know of any potential solutions or workarounds for this issue, please describe them here. -->
|
||||
1
.github/CODE_OF_CONDUCT.md
vendored
1
.github/CODE_OF_CONDUCT.md
vendored
@@ -1 +0,0 @@
|
||||
|
||||
1
.github/CONTRIBUTING.md
vendored
1
.github/CONTRIBUTING.md
vendored
@@ -1 +0,0 @@
|
||||
|
||||
14
.github/DISCUSSION_TEMPLATE/announcements.yml
vendored
14
.github/DISCUSSION_TEMPLATE/announcements.yml
vendored
@@ -1,14 +0,0 @@
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to read this announcement!
|
||||
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: description
|
||||
description: Please describe the announcement in as much detail as possible.
|
||||
placeholder: Make an announcement here...
|
||||
validations:
|
||||
required: true
|
||||
74
.github/DISCUSSION_TEMPLATE/ideas.yml
vendored
74
.github/DISCUSSION_TEMPLATE/ideas.yml
vendored
@@ -1,74 +0,0 @@
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Have an idea for a new feature or an improvement? Let us know here!
|
||||
|
||||
- type: checkboxes
|
||||
id: checklist
|
||||
attributes:
|
||||
label: Checklist
|
||||
options:
|
||||
- label: I have used the search function for [open](https://github.com/Docile-Alligator/Infinity-For-Reddit/discussions/categories/ideas) **and** [closed](https://github.com/Docile-Alligator/Infinity-For-Reddit/discussions/categories/completed-ideas) ideas to see if someone else has already submitted the same request.
|
||||
required: true
|
||||
- label: I will describe the feature with as much detail as possible.
|
||||
required: true
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to share your idea!
|
||||
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Description
|
||||
description: Please describe your idea in as much detail as possible.
|
||||
placeholder: I think it would be great if...
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
id: alternatives
|
||||
attributes:
|
||||
label: Alternatives
|
||||
description: Please describe any alternative solutions or features you've considered.
|
||||
placeholder: I've considered...
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: additional
|
||||
attributes:
|
||||
label: Additional context
|
||||
description: Add your use-case, screenshots, mock-up, or anything else you think might be helpful.
|
||||
placeholder: I think this would be a great addition because...
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
id: importance
|
||||
attributes:
|
||||
label: How important is this feature?
|
||||
multiple: false
|
||||
options:
|
||||
- Critical
|
||||
- Important
|
||||
- Nice to have
|
||||
|
||||
- type: textarea
|
||||
id: other
|
||||
attributes:
|
||||
label: Anything else?
|
||||
description: Is there anything else you'd like to add?
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: solution
|
||||
attributes:
|
||||
label: Solution
|
||||
description: If you have an idea of how this can be implemented, please share it here.
|
||||
placeholder: I think this could be done by...
|
||||
validations:
|
||||
required: false
|
||||
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -1,2 +0,0 @@
|
||||
github: Docile-Alligator
|
||||
patreon: docile_alligator
|
||||
94
.github/ISSUE_TEMPLATE/BUG_REPORT.yml
vendored
94
.github/ISSUE_TEMPLATE/BUG_REPORT.yml
vendored
@@ -1,94 +0,0 @@
|
||||
name: Bug Report
|
||||
description: Create a report to help us improve existing features
|
||||
labels: ['type: possible bug']
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this bug report!
|
||||
|
||||
- type: checkboxes
|
||||
id: checklist
|
||||
attributes:
|
||||
label: Checklist
|
||||
options:
|
||||
- label: I have used the search function for [open](https://github.com/Docile-Alligator/Infinity-For-Reddit/issues) **and** [closed](https://github.com/Docile-Alligator/Infinity-For-Reddit/issues?q=is%3Aissue+is%3Aclosed) issues to see if someone else has already submitted the same bug report.
|
||||
required: true
|
||||
- label: I will describe the problem with as much detail as possible.
|
||||
required: true
|
||||
- label: If the bug only occurs with a certain link, post, image..., I will include the URL.
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: App version
|
||||
description: We need the actual version number found on the settings screen.
|
||||
placeholder: x.y.z
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: dropdown
|
||||
id: source
|
||||
attributes:
|
||||
label: Where did you get the app from
|
||||
multiple: false
|
||||
options:
|
||||
- Google Play
|
||||
- F-Droid
|
||||
- Other
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: android_version
|
||||
attributes:
|
||||
label: Android version
|
||||
description: Please mention if you are using a custom rom!
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
id: device
|
||||
attributes:
|
||||
label: Device model
|
||||
|
||||
- type: input
|
||||
id: first
|
||||
attributes:
|
||||
label: First occurred
|
||||
placeholder: about x days/weeks ago
|
||||
|
||||
- type: textarea
|
||||
id: steps
|
||||
attributes:
|
||||
label: Steps to reproduce
|
||||
placeholder: |
|
||||
1. This
|
||||
2. Then that
|
||||
3. Then this
|
||||
4. Etc.
|
||||
|
||||
- type: textarea
|
||||
id: links
|
||||
attributes:
|
||||
label: Example post, link, markdown...
|
||||
|
||||
- type: textarea
|
||||
id: expected
|
||||
attributes:
|
||||
label: Expected behaviour
|
||||
description: After following the steps, what did you think Infinity would do?
|
||||
|
||||
- type: textarea
|
||||
id: current
|
||||
attributes:
|
||||
label: Current behaviour
|
||||
description: What did Infinity do instead? Screenshots might help. Usually, you can take a screenshot of your smartphone by pressing *Power* + *Volume down* for a few seconds.
|
||||
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Logs
|
||||
description: If you are experiencing a crash, including the stacktrace will likely get it fixed sooner.
|
||||
11
.github/ISSUE_TEMPLATE/config.yml
vendored
11
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,11 +0,0 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Feature Request
|
||||
url: https://github.com/Docile-Alligator/Infinity-For-Reddit/discussions/categories/ideas
|
||||
about: Discuss ideas for new features of changes
|
||||
- name: Questions
|
||||
url: https://github.com/Docile-Alligator/Infinity-For-Reddit/discussions/categories/q-a
|
||||
about: Please ask and answer questions here.
|
||||
- name: Help needed
|
||||
url: https://github.com/Docile-Alligator/Infinity-For-Reddit/discussions/categories/help-needed
|
||||
about: Please ask for help here
|
||||
23
.github/dependabot.yml
vendored
23
.github/dependabot.yml
vendored
@@ -1,23 +0,0 @@
|
||||
version: 2
|
||||
updates:
|
||||
# Updates for Gradle dependencies used in the app
|
||||
- package-ecosystem: gradle
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
commit-message:
|
||||
prefix: "⬆[Gradle]"
|
||||
reviewers:
|
||||
- "Wladefant"
|
||||
- "Docile-Alligator"
|
||||
|
||||
# Updates for GitHub Actions used in the repository
|
||||
- package-ecosystem: github-actions
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
commit-message:
|
||||
prefix: "⬆[GitHub Actions]"
|
||||
reviewers:
|
||||
- "Wladefant"
|
||||
- "Docile-Alligator"
|
||||
32
.github/workflows/build.yml
vendored
32
.github/workflows/build.yml
vendored
@@ -1,32 +0,0 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
Build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set-up JDK 11
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'temurin'
|
||||
|
||||
- name: Setup and build with Gradle
|
||||
uses: gradle/gradle-build-action@v2
|
||||
with:
|
||||
arguments: build -x lint
|
||||
|
||||
- name: Upload apk
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: Infinity-${{github.sha}}
|
||||
path: app/build/outputs/apk/
|
||||
if-no-files-found: error
|
||||
34
.github/workflows/codeql-analysis.yml
vendored
34
.github/workflows/codeql-analysis.yml
vendored
@@ -1,34 +0,0 @@
|
||||
name: CodeQL
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 12 * * *'
|
||||
|
||||
jobs:
|
||||
Analyze:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: java
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
18
README.md
18
README.md
@@ -1,12 +1,12 @@
|
||||
<h1 align="center">
|
||||
|
||||
Infinity for Lemmy
|
||||
</h1>
|
||||
|
||||
<div align="center">
|
||||
|
||||
A Lemmy client on Android written in Java. It's a fork of the [Infinity for Reddit](https://github.com/Docile-Alligator/Infinity-For-Reddit) project, currenty in early development.
|
||||
A Lemmy client for Android written in Java. It's a fork of the [Infinity for Reddit](https://github.com/Docile-Alligator/Infinity-For-Reddit) project, currenty in early development.
|
||||
|
||||
<img align="right" src="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/raw/branch/master/fastlane/metadata/android/en-US/images/LemmInfinity.png" width=200>
|
||||
<img align="right" src="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/raw/branch/master/fastlane/metadata/android/en-US/images/icon.png" width=200>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -16,6 +16,7 @@ A Lemmy client on Android written in Java. It's a fork of the [Infinity for Redd
|
||||
<div align="center">
|
||||
|
||||
[](https://ci.codeberg.org/12474)
|
||||
[](https://liberapay.com/Bazsalanszky)
|
||||
|
||||
<a href="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/issues">Report a Bug</a>
|
||||
|
||||
@@ -33,19 +34,22 @@ A Lemmy client on Android written in Java. It's a fork of the [Infinity for Redd
|
||||
|
||||
---
|
||||
|
||||
## Action Items for LemmInfinity
|
||||
## Action Items for Infinity for Lemmy
|
||||
|
||||
LemmInfinity is currently in the early stages of development. Expect many unfinished features and bugs!
|
||||
Infinity for Lemmy 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
|
||||
- [ ] Capability for creating a new post
|
||||
- [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
|
||||
- [ ] Incorporation of private messaging feature
|
||||
- [ ] Feature for saving posts
|
||||
- [x] Feature for saving posts/comments
|
||||
- [x] Resolving links
|
||||
- [ ] Account editing function
|
||||
- [ ] Multi community view?
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ android {
|
||||
applicationId "eu.toldi.infinityforlemmy"
|
||||
minSdk 21
|
||||
targetSdk 33
|
||||
versionCode 122
|
||||
versionName "0.0.2"
|
||||
versionCode 128
|
||||
versionName "0.0.8"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
@@ -52,6 +52,10 @@ android {
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
doNotStrip '**/*.so'
|
||||
}
|
||||
namespace 'eu.toldi.infinityforlemmy'
|
||||
}
|
||||
|
||||
@@ -165,6 +169,7 @@ dependencies {
|
||||
implementation "io.noties.markwon:recycler-table:$markwonVersion"
|
||||
implementation "io.noties.markwon:simple-ext:$markwonVersion"
|
||||
implementation "io.noties.markwon:inline-parser:$markwonVersion"
|
||||
implementation "io.noties.markwon:image-glide:$markwonVersion"
|
||||
implementation 'com.atlassian.commonmark:commonmark-ext-gfm-tables:0.14.0'
|
||||
implementation 'me.saket:better-link-movement-method:2.2.0'
|
||||
|
||||
|
||||
@@ -291,18 +291,70 @@
|
||||
|
||||
<data android:scheme="https" />
|
||||
<data android:scheme="http" />
|
||||
<data android:host="www.reddit.com" />
|
||||
<data android:host="reddit.com" />
|
||||
<data android:host="v.redd.it" />
|
||||
<data android:host="amp.reddit.com" />
|
||||
<data android:host="m.reddit.com" />
|
||||
<data android:host="old.reddit.com" />
|
||||
<data android:host="new.reddit.com" />
|
||||
<data android:host="np.reddit.com" />
|
||||
<data android:host="reddit.app.link" />
|
||||
<data android:host="redd.it" />
|
||||
<data android:host="s.reddit.com" />
|
||||
<data android:host="click.redditmail.com" />
|
||||
<data android:host="lemmy.world" />
|
||||
<data android:host="lemmy.ml" />
|
||||
<data android:host="beehaw.org" />
|
||||
<data android:host="lemm.ee" />
|
||||
<data android:host="sh.itjust.works" />
|
||||
<data android:host="feddit.de" />
|
||||
<data android:host="lemmy.fmhy.ml" />
|
||||
<data android:host="lemmy.ca" />
|
||||
<data android:host="www.hexbear.net" />
|
||||
<data android:host="programming.dev" />
|
||||
<data android:host="lemmy.dbzer0.com" />
|
||||
<data android:host="lemmy.blahaj.zone" />
|
||||
<data android:host="lemmy.one" />
|
||||
<data android:host="vlemmy.net" />
|
||||
<data android:host="lemmy.sdf.org" />
|
||||
<data android:host="discuss.tchncs.de" />
|
||||
<data android:host="lemmygrad.ml" />
|
||||
<data android:host="sopuli.xyz" />
|
||||
<data android:host="reddthat.com" />
|
||||
<data android:host="aussie.zone" />
|
||||
<data android:host="feddit.uk" />
|
||||
<data android:host="feddit.nl" />
|
||||
<data android:host="midwest.social" />
|
||||
<data android:host="infosec.pub" />
|
||||
<data android:host="feddit.it" />
|
||||
<data android:host="ttrpg.network" />
|
||||
<data android:host="pawb.social" />
|
||||
<data android:host="lemmy.zip" />
|
||||
<data android:host="startrek.website" />
|
||||
<data android:host="burggit.moe" />
|
||||
<data android:host="slrpnk.net" />
|
||||
<data android:host="mander.xyz" />
|
||||
<data android:host="lemmy.eco.br" />
|
||||
<data android:host="lemmy.nz" />
|
||||
<data android:host="dormi.zone" />
|
||||
<data android:host="exploding-heads.com" />
|
||||
<data android:host="delraymisfitsboard.com" />
|
||||
<data android:host="monyet.cc" />
|
||||
<data android:host="feddit.dk" />
|
||||
<data android:host="lemmy.pt" />
|
||||
<data android:host="szmer.info" />
|
||||
<data android:host="yiffit.net" />
|
||||
<data android:host="geddit.social" />
|
||||
<data android:host="waveform.social" />
|
||||
<data android:host="discuss.online" />
|
||||
<data android:host="monero.town" />
|
||||
<data android:host="feddit.cl" />
|
||||
<data android:host="iusearchlinux.fyi" />
|
||||
<data android:host="dataterm.digital" />
|
||||
<data android:host="lemmy.whynotdrs.org" />
|
||||
<data android:host="feddit.ch" />
|
||||
<data android:host="enterprise.lemmy.ml" />
|
||||
<data android:host="lemmy.run" />
|
||||
<data android:host="jlai.lu" />
|
||||
<data android:host="pornlemmy.com" />
|
||||
<data android:host="lemdro.id" />
|
||||
<data android:host="lemmyrs.org" />
|
||||
<data android:host="latte.isnot.coffee" />
|
||||
<data android:host="feddit.nu" />
|
||||
<data android:host="lemmy.film" />
|
||||
<data android:host="bakchodi.org" />
|
||||
<data android:host="mujico.org" />
|
||||
<data android:host="lemmy.studio" />
|
||||
<data android:host="lemmy.toldi.eu" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
@@ -307,6 +307,7 @@ public interface AppComponent {
|
||||
|
||||
void inject(MorePostsInfoFragment morePostsInfoFragment);
|
||||
|
||||
|
||||
@Component.Factory
|
||||
interface Factory {
|
||||
AppComponent create(@BindsInstance Application application);
|
||||
|
||||
@@ -22,6 +22,8 @@ import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.LoopAvailableExoCreator;
|
||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||
import eu.toldi.infinityforlemmy.post.ObjectResolver;
|
||||
import eu.toldi.infinityforlemmy.utils.CustomThemeSharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.videoautoplay.Config;
|
||||
@@ -192,8 +194,8 @@ abstract class AppModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
static ExoCreator provideExoCreator(Config config,
|
||||
ToroExo toroExo,
|
||||
@Named("default") SharedPreferences sharedPreferences) {
|
||||
ToroExo toroExo,
|
||||
@Named("default") SharedPreferences sharedPreferences) {
|
||||
return new LoopAvailableExoCreator(toroExo, config, sharedPreferences);
|
||||
}
|
||||
|
||||
@@ -202,4 +204,16 @@ abstract class AppModule {
|
||||
static Executor provideExecutor() {
|
||||
return Executors.newFixedThreadPool(4);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static ObjectResolver provideObjectResolver(@Named("no_oauth") RetrofitHolder retrofitHolder) {
|
||||
return new ObjectResolver(retrofitHolder);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static MarkPostAsRead provideMarkPostAsRead(@Named("no_oauth") RetrofitHolder retrofitHolder) {
|
||||
return new MarkPostAsRead(retrofitHolder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ import androidx.annotation.NonNull;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.dto.DeleteCommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.DeletePostDTO;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
@@ -13,10 +15,11 @@ import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class DeleteThing {
|
||||
public static void delete(Retrofit oauthRetrofit, String fullname, String accessToken, DeleteThingListener deleteThingListener) {
|
||||
|
||||
public static void deletePost(Retrofit retrofit, int post_id, String accessToken, DeleteThingListener deleteThingListener) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(APIUtils.ID_KEY, fullname);
|
||||
oauthRetrofit.create(RedditAPI.class).delete(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
|
||||
params.put(APIUtils.ID_KEY, String.valueOf(post_id));
|
||||
retrofit.create(LemmyAPI.class).postDelete(new DeletePostDTO(post_id, true, accessToken)).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
@@ -33,6 +36,27 @@ public class DeleteThing {
|
||||
});
|
||||
}
|
||||
|
||||
public static void deleteComment(Retrofit retrofit, int comment_id, String accessToken, DeleteThingListener deleteThingListener) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(APIUtils.ID_KEY, String.valueOf(comment_id));
|
||||
retrofit.create(LemmyAPI.class).commentDelete(new DeleteCommentDTO(comment_id, true, accessToken)).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
deleteThingListener.deleteSuccess();
|
||||
} else {
|
||||
deleteThingListener.deleteFailed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
deleteThingListener.deleteFailed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public interface DeleteThingListener {
|
||||
void deleteSuccess();
|
||||
|
||||
|
||||
@@ -4,10 +4,12 @@ import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import androidx.work.Worker;
|
||||
@@ -28,13 +30,11 @@ import javax.inject.Named;
|
||||
import eu.toldi.infinityforlemmy.account.Account;
|
||||
import eu.toldi.infinityforlemmy.activities.InboxActivity;
|
||||
import eu.toldi.infinityforlemmy.activities.LinkResolverActivity;
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.comment.Comment;
|
||||
import eu.toldi.infinityforlemmy.comment.ParseComment;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.message.FetchMessage;
|
||||
import eu.toldi.infinityforlemmy.message.Message;
|
||||
import eu.toldi.infinityforlemmy.message.ParseMessage;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
||||
import eu.toldi.infinityforlemmy.message.CommentInteraction;
|
||||
import eu.toldi.infinityforlemmy.utils.NotificationUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import retrofit2.Call;
|
||||
@@ -88,9 +88,16 @@ public class PullNotificationWorker extends Worker {
|
||||
|
||||
if (response != null && response.isSuccessful() && response.body() != null) {
|
||||
String responseBody = response.body();
|
||||
JSONArray messageArray = new JSONObject(responseBody).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
|
||||
ArrayList<Message> messages = ParseMessage.parseMessages(messageArray,
|
||||
context.getResources().getConfiguration().locale, FetchMessage.MESSAGE_TYPE_NOTIFICATION);
|
||||
JSONArray messageArray = new JSONObject(responseBody).getJSONArray("replies");
|
||||
List<CommentInteraction> messages = new ArrayList<>();
|
||||
for (int i = 0; i < messageArray.length(); i++) {
|
||||
JSONObject commentInteractionObject = messageArray.getJSONObject(i);
|
||||
Comment comment = ParseComment.parseSingleComment(commentInteractionObject);
|
||||
boolean isRead = !commentInteractionObject.getJSONObject("comment_reply").getBoolean("read");
|
||||
int id = commentInteractionObject.getJSONObject("comment_reply").getInt("id");
|
||||
messages.add(new CommentInteraction(id, comment, isRead));
|
||||
}
|
||||
|
||||
|
||||
if (!messages.isEmpty()) {
|
||||
NotificationCompat.Builder summaryBuilder = NotificationUtils.buildSummaryNotification(context,
|
||||
@@ -110,77 +117,36 @@ public class PullNotificationWorker extends Worker {
|
||||
|
||||
int pendingIntentFlags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_UPDATE_CURRENT;
|
||||
for (int messageIndex = messageSize - 1; messageIndex >= 0; messageIndex--) {
|
||||
Message message = messages.get(messageIndex);
|
||||
if (message.getTimeUTC() <= lastNotificationTime) {
|
||||
CommentInteraction message = messages.get(messageIndex);
|
||||
if (message.getComment().getCommentTimeMillis() <= lastNotificationTime) {
|
||||
continue;
|
||||
}
|
||||
|
||||
hasValidMessage = true;
|
||||
|
||||
inboxStyle.addLine(message.getAuthor() + " " + message.getBody());
|
||||
inboxStyle.addLine(message.getComment().getAuthorQualifiedName() + " " + message.getComment().getCommentMarkdown());
|
||||
|
||||
|
||||
String title = message.getComment().getAuthorQualifiedName();
|
||||
String summary = message.getComment().getCommunityQualifiedName();
|
||||
|
||||
String kind = message.getKind();
|
||||
String title;
|
||||
String summary;
|
||||
if (kind.equals(Message.TYPE_COMMENT) || kind.equals(Message.TYPE_LINK)) {
|
||||
title = message.getAuthor();
|
||||
summary = message.getSubject().substring(0, 1).toUpperCase() + message.getSubject().substring(1);
|
||||
} else {
|
||||
title = message.getTitle() == null || message.getTitle().equals("") ? message.getSubject() : message.getTitle();
|
||||
if (kind.equals(Message.TYPE_ACCOUNT)) {
|
||||
summary = context.getString(R.string.notification_summary_account);
|
||||
} else if (kind.equals(Message.TYPE_MESSAGE)) {
|
||||
summary = context.getString(R.string.notification_summary_message);
|
||||
} else if (kind.equals(Message.TYPE_SUBREDDIT)) {
|
||||
summary = context.getString(R.string.notification_summary_community);
|
||||
} else {
|
||||
summary = context.getString(R.string.notification_summary_award);
|
||||
}
|
||||
}
|
||||
|
||||
NotificationCompat.Builder builder = NotificationUtils.buildNotification(notificationManager,
|
||||
context, title, message.getBody(), summary,
|
||||
context, title, message.getComment().getCommentMarkdown(), summary,
|
||||
NotificationUtils.CHANNEL_ID_NEW_MESSAGES,
|
||||
NotificationUtils.CHANNEL_NEW_MESSAGES,
|
||||
NotificationUtils.getAccountGroupName(accountName), color);
|
||||
|
||||
if (kind.equals(Message.TYPE_COMMENT)) {
|
||||
Intent intent = new Intent(context, LinkResolverActivity.class);
|
||||
Uri uri = Uri.parse(message.getContext());
|
||||
intent.setData(uri);
|
||||
intent.putExtra(LinkResolverActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
|
||||
intent.putExtra(LinkResolverActivity.EXTRA_MESSAGE_FULLNAME, message.getFullname());
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, accountIndex * 6, intent, pendingIntentFlags);
|
||||
builder.setContentIntent(pendingIntent);
|
||||
} else if (kind.equals(Message.TYPE_ACCOUNT)) {
|
||||
Intent intent = new Intent(context, InboxActivity.class);
|
||||
intent.putExtra(InboxActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
|
||||
PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 1, intent, pendingIntentFlags);
|
||||
builder.setContentIntent(summaryPendingIntent);
|
||||
} else if (kind.equals(Message.TYPE_LINK)) {
|
||||
Intent intent = new Intent(context, LinkResolverActivity.class);
|
||||
Uri uri = Uri.parse(message.getContext());
|
||||
intent.setData(uri);
|
||||
intent.putExtra(LinkResolverActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
|
||||
intent.putExtra(LinkResolverActivity.EXTRA_MESSAGE_FULLNAME, message.getFullname());
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 2, intent, pendingIntentFlags);
|
||||
builder.setContentIntent(pendingIntent);
|
||||
} else if (kind.equals(Message.TYPE_MESSAGE)) {
|
||||
Intent intent = new Intent(context, InboxActivity.class);
|
||||
intent.putExtra(InboxActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
|
||||
intent.putExtra(InboxActivity.EXTRA_VIEW_MESSAGE, true);
|
||||
PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 3, intent, pendingIntentFlags);
|
||||
builder.setContentIntent(summaryPendingIntent);
|
||||
} else if (kind.equals(Message.TYPE_SUBREDDIT)) {
|
||||
Intent intent = new Intent(context, InboxActivity.class);
|
||||
intent.putExtra(InboxActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
|
||||
PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 4, intent, pendingIntentFlags);
|
||||
builder.setContentIntent(summaryPendingIntent);
|
||||
} else {
|
||||
Intent intent = new Intent(context, InboxActivity.class);
|
||||
intent.putExtra(InboxActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
|
||||
PendingIntent summaryPendingIntent = PendingIntent.getActivity(context, accountIndex * 6 + 5, intent, pendingIntentFlags);
|
||||
builder.setContentIntent(summaryPendingIntent);
|
||||
Intent intent = new Intent(context, LinkResolverActivity.class);
|
||||
Uri uri = Uri.parse(message.getComment().getPermalink());
|
||||
intent.setData(uri);
|
||||
intent.putExtra(LinkResolverActivity.EXTRA_NEW_ACCOUNT_NAME, accountName);
|
||||
intent.putExtra(LinkResolverActivity.EXTRA_MESSAGE_FULLNAME, message.getId());
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, accountIndex * 6, intent, pendingIntentFlags);
|
||||
builder.setContentIntent(pendingIntent);
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(this.getApplicationContext(), android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||
return Result.failure();
|
||||
}
|
||||
notificationManager.notify(NotificationUtils.getNotificationIdUnreadMessage(accountIndex, messageIndex), builder.build());
|
||||
}
|
||||
@@ -216,10 +182,7 @@ public class PullNotificationWorker extends Worker {
|
||||
if (retryCount < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Call<String> call = mOauthWithoutAuthenticatorRetrofit.create(RedditAPI.class)
|
||||
.getMessages(APIUtils.getOAuthHeader(account.getAccessToken()),
|
||||
FetchMessage.WHERE_UNREAD, null);
|
||||
Call<String> call = mRetrofit.getRetrofit().create(LemmyAPI.class).userReplies("New", 1, 25, true, account.getAccessToken());
|
||||
Response<String> response = call.execute();
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
|
||||
@@ -38,7 +38,7 @@ 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}, version = 23)
|
||||
ReadPost.class, PostFilter.class, PostFilterUsage.class, AnonymousMultiredditSubreddit.class}, version = 24)
|
||||
public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
|
||||
public static RedditDataRoomDatabase create(final Context context) {
|
||||
@@ -49,7 +49,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_21_22, MIGRATION_22_23, MIGRATION_23_24)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -383,4 +383,11 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static final Migration MIGRATION_23_24 = new Migration(23, 24) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("ALTER TABLE accounts ADD COLUMN can_downvote INTEGER DEFAULT 1 NOT NULL");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,13 +12,19 @@ public class RetrofitHolder {
|
||||
|
||||
private Retrofit retrofit;
|
||||
private OkHttpClient okHttpClient;
|
||||
private String baseURL = APIUtils.API_BASE_URI;
|
||||
|
||||
public Retrofit getRetrofit() {
|
||||
return retrofit;
|
||||
}
|
||||
|
||||
public void setBaseURL(String baseURL){
|
||||
retrofit = createRetrofit(okHttpClient,baseURL);
|
||||
public void setBaseURL(String baseURL) {
|
||||
retrofit = createRetrofit(okHttpClient, baseURL);
|
||||
this.baseURL = baseURL;
|
||||
}
|
||||
|
||||
public String getBaseURL() {
|
||||
return baseURL;
|
||||
}
|
||||
|
||||
public RetrofitHolder(OkHttpClient okHttpClient) {
|
||||
|
||||
53
app/src/main/java/eu/toldi/infinityforlemmy/SaveComment.java
Normal file
53
app/src/main/java/eu/toldi/infinityforlemmy/SaveComment.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package eu.toldi.infinityforlemmy;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.dto.SaveCommentDTO;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class SaveComment implements SaveThing {
|
||||
@Override
|
||||
public void saveThing(Retrofit retrofit, String accessToken, int id, SaveThingListener saveThingListener) {
|
||||
|
||||
retrofit.create(LemmyAPI.class).commentSave(new SaveCommentDTO(id, true, accessToken)).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
saveThingListener.success();
|
||||
} else {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsaveThing(Retrofit retrofit, String accessToken, int id, SaveThingListener saveThingListener) {
|
||||
|
||||
retrofit.create(LemmyAPI.class).commentSave(new SaveCommentDTO(id, false, accessToken)).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
saveThingListener.success();
|
||||
} else {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
55
app/src/main/java/eu/toldi/infinityforlemmy/SavePost.java
Normal file
55
app/src/main/java/eu/toldi/infinityforlemmy/SavePost.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package eu.toldi.infinityforlemmy;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.dto.SavePostDTO;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class SavePost implements SaveThing {
|
||||
|
||||
@Override
|
||||
public void saveThing(Retrofit retrofit, String accessToken, int id, SaveThingListener saveThingListener) {
|
||||
|
||||
|
||||
retrofit.create(LemmyAPI.class).postSave(new SavePostDTO(id, true, accessToken)).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
saveThingListener.success();
|
||||
} else {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsaveThing(Retrofit retrofit, String accessToken, int id, SaveThingListener saveThingListener) {
|
||||
|
||||
retrofit.create(LemmyAPI.class).postSave(new SavePostDTO(id, false, accessToken)).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
saveThingListener.success();
|
||||
} else {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,13 @@
|
||||
package eu.toldi.infinityforlemmy;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class SaveThing {
|
||||
public static void saveThing(Retrofit oauthRetrofit, String accessToken, String fullname,
|
||||
SaveThingListener saveThingListener) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(APIUtils.ID_KEY, fullname);
|
||||
oauthRetrofit.create(RedditAPI.class).save(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
saveThingListener.success();
|
||||
} else {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
}
|
||||
public interface SaveThing {
|
||||
void saveThing(Retrofit oauthRetrofit, String accessToken, int id,
|
||||
SaveThingListener saveThingListener);
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void unsaveThing(Retrofit oauthRetrofit, String accessToken, String fullname,
|
||||
SaveThingListener saveThingListener) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(APIUtils.ID_KEY, fullname);
|
||||
oauthRetrofit.create(RedditAPI.class).unsave(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
saveThingListener.success();
|
||||
} else {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
void unsaveThing(Retrofit oauthRetrofit, String accessToken, int id,
|
||||
SaveThingListener saveThingListener);
|
||||
|
||||
public interface SaveThingListener {
|
||||
void success();
|
||||
|
||||
@@ -32,6 +32,9 @@ public class Account implements Parcelable {
|
||||
@ColumnInfo(name = "instance_url")
|
||||
private String instance_url;
|
||||
|
||||
@ColumnInfo(name = "can_downvote")
|
||||
private boolean canDownvote = true;
|
||||
|
||||
@Ignore
|
||||
protected Account(Parcel in) {
|
||||
accountName = in.readString();
|
||||
@@ -42,6 +45,7 @@ public class Account implements Parcelable {
|
||||
code = in.readString();
|
||||
isCurrentUser = in.readByte() != 0;
|
||||
instance_url = in.readString();
|
||||
canDownvote = in.readByte() != 0;
|
||||
}
|
||||
|
||||
public static final Creator<Account> CREATOR = new Creator<Account>() {
|
||||
@@ -58,11 +62,11 @@ public class Account implements Parcelable {
|
||||
|
||||
@Ignore
|
||||
public static Account getAnonymousAccount() {
|
||||
return new Account("-",null, null, null, null, null, false,null);
|
||||
return new Account("-",null, null, null, null, null, false,null,true);
|
||||
}
|
||||
|
||||
public Account(@NonNull String accountName, String display_name, String accessToken, String code,
|
||||
String profileImageUrl, String bannerImageUrl, boolean isCurrentUser,String instance_url) {
|
||||
String profileImageUrl, String bannerImageUrl, boolean isCurrentUser,String instance_url, boolean canDownvote) {
|
||||
this.accountName = accountName;
|
||||
this.display_name = display_name;
|
||||
this.accessToken = accessToken;
|
||||
@@ -71,6 +75,7 @@ public class Account implements Parcelable {
|
||||
this.bannerImageUrl = bannerImageUrl;
|
||||
this.isCurrentUser = isCurrentUser;
|
||||
this.instance_url = instance_url;
|
||||
this.canDownvote = canDownvote;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -116,6 +121,10 @@ public class Account implements Parcelable {
|
||||
return instance_url;
|
||||
}
|
||||
|
||||
public boolean canDownvote() {
|
||||
return canDownvote;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(accountName);
|
||||
@@ -126,5 +135,6 @@ public class Account implements Parcelable {
|
||||
dest.writeString(code);
|
||||
dest.writeByte((byte) (isCurrentUser ? 1 : 0));
|
||||
dest.writeString(instance_url);
|
||||
dest.writeByte((byte) (canDownvote ? 1 : 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -40,6 +41,7 @@ import eu.toldi.infinityforlemmy.events.ChangeNSFWEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.fragments.CommentsListingFragment;
|
||||
import eu.toldi.infinityforlemmy.fragments.PostFragment;
|
||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
@@ -64,10 +66,15 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
|
||||
@Inject
|
||||
MarkPostAsRead markPostAsRead;
|
||||
private FragmentManager fragmentManager;
|
||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
|
||||
private String mAccountQualifiedName;
|
||||
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
|
||||
private ActivityAccountSavedThingBinding binding;
|
||||
|
||||
@@ -116,6 +123,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
|
||||
initializeViewPager();
|
||||
}
|
||||
@@ -249,7 +257,17 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||
markPostAsRead.markPostAsRead(post.getId(), mAccessToken, new MarkPostAsRead.MarkPostAsReadListener() {
|
||||
@Override
|
||||
public void onMarkPostAsReadSuccess() {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkPostAsReadFailed() {
|
||||
Toast.makeText(AccountSavedThingActivity.this, R.string.mark_post_as_read_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class SectionsPagerAdapter extends FragmentStateAdapter {
|
||||
|
||||
@@ -39,6 +39,9 @@ import androidx.viewpager2.widget.ViewPager2;
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.shape.CornerFamily;
|
||||
import com.google.android.material.shape.MaterialShapeDrawable;
|
||||
import com.google.android.material.shape.ShapeAppearanceModel;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -377,9 +380,18 @@ public abstract class BaseActivity extends AppCompatActivity implements CustomFo
|
||||
button.setTextColor(customThemeWrapper.getFABIconColor());
|
||||
}
|
||||
|
||||
protected void applyFABTheme(FloatingActionButton fab) {
|
||||
protected void applyFABTheme(FloatingActionButton fab, boolean isCircular) {
|
||||
fab.setBackgroundTintList(ColorStateList.valueOf(customThemeWrapper.getColorAccent()));
|
||||
fab.setImageTintList(ColorStateList.valueOf(customThemeWrapper.getFABIconColor()));
|
||||
if (isCircular) {
|
||||
ShapeAppearanceModel shapeAppearanceModel = ShapeAppearanceModel.builder()
|
||||
.setAllCorners(CornerFamily.ROUNDED, 100) // Adjust the radius value to control the roundness
|
||||
.build();
|
||||
|
||||
// Apply the circular shape to the FAB
|
||||
MaterialShapeDrawable shapeDrawable = new MaterialShapeDrawable(shapeAppearanceModel);
|
||||
fab.setShapeAppearanceModel(shapeAppearanceModel);
|
||||
}
|
||||
}
|
||||
|
||||
protected void fixViewPager2Sensitivity(ViewPager2 viewPager2) {
|
||||
|
||||
@@ -39,17 +39,10 @@ import java.util.concurrent.Executor;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||
import io.noties.markwon.Markwon;
|
||||
import io.noties.markwon.MarkwonConfiguration;
|
||||
import io.noties.markwon.MarkwonPlugin;
|
||||
import io.noties.markwon.core.MarkwonTheme;
|
||||
import io.noties.markwon.recycler.MarkwonAdapter;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.UploadImageEnabledActivity;
|
||||
import eu.toldi.infinityforlemmy.UploadedImage;
|
||||
import eu.toldi.infinityforlemmy.account.Account;
|
||||
@@ -66,6 +59,13 @@ import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||
import io.noties.markwon.Markwon;
|
||||
import io.noties.markwon.MarkwonConfiguration;
|
||||
import io.noties.markwon.MarkwonPlugin;
|
||||
import io.noties.markwon.core.MarkwonTheme;
|
||||
import io.noties.markwon.recycler.MarkwonAdapter;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class CommentActivity extends BaseActivity implements UploadImageEnabledActivity, AccountChooserBottomSheetFragment.AccountChooserListener {
|
||||
@@ -449,10 +449,10 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
|
||||
Toast.makeText(CommentActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit.getRetrofit(), mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, binding.commentCommentEditText, binding.commentCoordinatorLayout, data.getData(), uploadedImages);
|
||||
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit.getRetrofit(), mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, binding.commentCommentEditText, binding.commentCoordinatorLayout, capturedImageUri, uploadedImages);
|
||||
} else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
|
||||
sendComment(mMenu == null ? null : mMenu.findItem(R.id.action_send_comment_activity));
|
||||
@@ -513,8 +513,8 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
|
||||
int start = Math.max(binding.commentCommentEditText.getSelectionStart(), 0);
|
||||
int end = Math.max(binding.commentCommentEditText.getSelectionEnd(), 0);
|
||||
binding.commentCommentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
|
||||
"[" + uploadedImage.imageName + "](" + uploadedImage.imageUrl + ")",
|
||||
0, "[]()".length() + uploadedImage.imageName.length() + uploadedImage.imageUrl.length());
|
||||
"",
|
||||
0, "![]()".length() + uploadedImage.imageName.length() + uploadedImage.imageUrl.length());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,6 +51,7 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeViewModel;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.events.RecreateActivityEvent;
|
||||
import eu.toldi.infinityforlemmy.utils.CustomThemeSharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
|
||||
public class CustomThemeListingActivity extends BaseActivity implements
|
||||
@@ -154,7 +155,7 @@ public class CustomThemeListingActivity extends BaseActivity implements
|
||||
@Override
|
||||
protected void applyCustomTheme() {
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
|
||||
applyFABTheme(fab);
|
||||
applyFABTheme(fab, sharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,8 +32,6 @@ import org.greenrobot.eventbus.Subscribe;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -43,15 +41,16 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.UploadImageEnabledActivity;
|
||||
import eu.toldi.infinityforlemmy.UploadedImage;
|
||||
import eu.toldi.infinityforlemmy.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.bottomsheetfragments.UploadedImagesBottomSheetFragment;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
import eu.toldi.infinityforlemmy.dto.EditCommentDTO;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import retrofit2.Call;
|
||||
@@ -84,8 +83,8 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
||||
@BindView(R.id.markdown_bottom_bar_recycler_view_edit_comment_activity)
|
||||
RecyclerView markdownBottomBarRecyclerView;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder retrofit;
|
||||
@Inject
|
||||
@Named("upload_media")
|
||||
Retrofit mUploadMediaRetrofit;
|
||||
@@ -99,7 +98,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
private String mFullName;
|
||||
private int mCommentId;
|
||||
private String mAccessToken;
|
||||
private String mCommentContent;
|
||||
private boolean isSubmitting = false;
|
||||
@@ -129,7 +128,10 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
mFullName = getIntent().getStringExtra(EXTRA_FULLNAME);
|
||||
mCommentId = getIntent().getIntExtra(EXTRA_FULLNAME, 0);
|
||||
if (mCommentId == 0) {
|
||||
finish();
|
||||
}
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mCommentContent = getIntent().getStringExtra(EXTRA_CONTENT);
|
||||
contentEditText.setText(mCommentContent);
|
||||
@@ -225,12 +227,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
||||
|
||||
String content = contentEditText.getText().toString();
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(APIUtils.THING_ID_KEY, mFullName);
|
||||
params.put(APIUtils.TEXT_KEY, content);
|
||||
|
||||
mOauthRetrofit.create(RedditAPI.class)
|
||||
.editPostOrComment(APIUtils.getOAuthHeader(mAccessToken), params)
|
||||
retrofit.getRetrofit().create(LemmyAPI.class).commentEdit(new EditCommentDTO(mCommentId, content, null, null, mAccessToken))
|
||||
.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
@@ -278,10 +275,10 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
||||
Toast.makeText(EditCommentActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, retrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages);
|
||||
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
|
||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, retrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
|
||||
} else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
|
||||
editComment();
|
||||
@@ -348,7 +345,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
||||
int start = Math.max(contentEditText.getSelectionStart(), 0);
|
||||
int end = Math.max(contentEditText.getSelectionEnd(), 0);
|
||||
contentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
|
||||
"[" + uploadedImage.imageName + "](" + uploadedImage.imageUrl + ")",
|
||||
0, "[]()".length() + uploadedImage.imageName.length() + uploadedImage.imageUrl.length());
|
||||
"",
|
||||
0, "![]()".length() + uploadedImage.imageName.length() + uploadedImage.imageUrl.length());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,20 @@ package eu.toldi.infinityforlemmy.activities;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -23,18 +26,22 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestManager;
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.json.JSONException;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -44,17 +51,20 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.UploadImageEnabledActivity;
|
||||
import eu.toldi.infinityforlemmy.UploadedImage;
|
||||
import eu.toldi.infinityforlemmy.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.bottomsheetfragments.UploadedImagesBottomSheetFragment;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
|
||||
import eu.toldi.infinityforlemmy.dto.EditPostDTO;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.UploadImageUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
@@ -63,16 +73,19 @@ import retrofit2.Retrofit;
|
||||
|
||||
public class EditPostActivity extends BaseActivity implements UploadImageEnabledActivity {
|
||||
|
||||
public static final String EXTRA_TITLE = "ET";
|
||||
public static final String EXTRA_CONTENT = "EC";
|
||||
public static final String EXTRA_FULLNAME = "EF";
|
||||
public static final String EXTRA_DATA = "ED";
|
||||
|
||||
|
||||
private static final int UPLOAD_IMAGE_REQUEST_CODE = 1;
|
||||
private static final int PICK_IMAGE_REQUEST_CODE = 100;
|
||||
private static final int CAPTURE_IMAGE_REQUEST_CODE = 200;
|
||||
private static final int MARKDOWN_PREVIEW_REQUEST_CODE = 300;
|
||||
|
||||
private static final String UPLOADED_IMAGES_STATE = "UIS";
|
||||
|
||||
private static final String picturePattern = "https:\\/\\/[^\\/]+\\/pictrs\\/image\\/([a-f\\d-]+\\.jpeg)";
|
||||
|
||||
|
||||
@BindView(R.id.coordinator_layout_edit_post_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@BindView(R.id.appbar_layout_edit_post_activity)
|
||||
@@ -80,16 +93,25 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
|
||||
@BindView(R.id.toolbar_edit_post_activity)
|
||||
Toolbar toolbar;
|
||||
@BindView(R.id.post_title_text_view_edit_post_activity)
|
||||
TextView titleTextView;
|
||||
EditText titleEditText;
|
||||
@BindView(R.id.divider_edit_post_activity)
|
||||
View divider;
|
||||
@BindView(R.id.post_text_content_edit_text_edit_post_activity)
|
||||
EditText contentEditText;
|
||||
@BindView(R.id.markdown_bottom_bar_recycler_view_edit_post_activity)
|
||||
RecyclerView markdownBottomBarRecyclerView;
|
||||
@BindView(R.id.post_link_edit_text_post_edit_activity)
|
||||
EditText linkEditText;
|
||||
|
||||
@BindView(R.id.upload_image_button_post_edit_activity)
|
||||
MaterialButton uploadImageButton;
|
||||
|
||||
@BindView(R.id.image_view_post_edit_activity)
|
||||
ImageView imageView;
|
||||
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
@Inject
|
||||
@Named("upload_media")
|
||||
Retrofit mUploadMediaRetrofit;
|
||||
@@ -103,13 +125,16 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
private String mFullName;
|
||||
private Post mPost;
|
||||
|
||||
private String mAccessToken;
|
||||
private String mPostContent;
|
||||
private boolean isSubmitting = false;
|
||||
private Uri capturedImageUri;
|
||||
private ArrayList<UploadedImage> uploadedImages = new ArrayList<>();
|
||||
|
||||
|
||||
private RequestManager mGlide;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
((Infinity) getApplication()).getAppComponent().inject(this);
|
||||
@@ -137,11 +162,49 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
mFullName = getIntent().getStringExtra(EXTRA_FULLNAME);
|
||||
mPost = getIntent().getParcelableExtra(EXTRA_DATA);
|
||||
if (mPost == null) {
|
||||
finish();
|
||||
}
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
titleTextView.setText(getIntent().getStringExtra(EXTRA_TITLE));
|
||||
mPostContent = getIntent().getStringExtra(EXTRA_CONTENT);
|
||||
contentEditText.setText(mPostContent);
|
||||
titleEditText.setText(mPost.getTitle());
|
||||
contentEditText.setText(mPost.getSelfText());
|
||||
linkEditText.setText(mPost.getUrl());
|
||||
|
||||
mGlide = Glide.with(this);
|
||||
|
||||
if (mPost.getUrl() != null && mPost.getUrl().matches(picturePattern)) {
|
||||
loadImage();
|
||||
}
|
||||
|
||||
linkEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
if (charSequence.toString().matches(picturePattern)) {
|
||||
loadImage();
|
||||
} else {
|
||||
uploadImageButton.setVisibility(View.VISIBLE);
|
||||
imageView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
}
|
||||
});
|
||||
|
||||
uploadImageButton.setOnClickListener(view -> {
|
||||
Intent intent = new Intent();
|
||||
intent.setType("image/*");
|
||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
startActivityForResult(Intent.createChooser(intent, getString(R.string.select_from_gallery)), UPLOAD_IMAGE_REQUEST_CODE);
|
||||
});
|
||||
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
uploadedImages = savedInstanceState.getParcelableArrayList(UPLOADED_IMAGES_STATE);
|
||||
@@ -189,18 +252,27 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
|
||||
protected void applyCustomTheme() {
|
||||
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar);
|
||||
titleTextView.setTextColor(mCustomThemeWrapper.getPostTitleColor());
|
||||
titleEditText.setTextColor(mCustomThemeWrapper.getPostTitleColor());
|
||||
divider.setBackgroundColor(mCustomThemeWrapper.getPostTitleColor());
|
||||
contentEditText.setTextColor(mCustomThemeWrapper.getPostContentColor());
|
||||
linkEditText.setTextColor(mCustomThemeWrapper.getPostContentColor());
|
||||
|
||||
uploadImageButton.setTextColor(mCustomThemeWrapper.getButtonTextColor());
|
||||
uploadImageButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
|
||||
if (titleTypeface != null) {
|
||||
titleTextView.setTypeface(titleTypeface);
|
||||
titleEditText.setTypeface(titleTypeface);
|
||||
}
|
||||
if (contentTypeface != null) {
|
||||
contentEditText.setTypeface(contentTypeface);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadImage() {
|
||||
uploadImageButton.setVisibility(View.GONE);
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
mGlide.load(mPost.getUrl()).into(imageView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
@@ -236,21 +308,19 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
|
||||
isSubmitting = true;
|
||||
|
||||
Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_SHORT).show();
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(APIUtils.THING_ID_KEY, mFullName);
|
||||
params.put(APIUtils.TEXT_KEY, contentEditText.getText().toString());
|
||||
|
||||
mOauthRetrofit.create(RedditAPI.class)
|
||||
.editPostOrComment(APIUtils.getOAuthHeader(mAccessToken), params)
|
||||
mRetrofit.getRetrofit().create(LemmyAPI.class).postUpdate(new EditPostDTO(mPost.getId(), titleEditText.getText().toString(), linkEditText.getText().toString(), contentEditText.getText().toString(), mPost.isNSFW(), null, mAccessToken))
|
||||
.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
isSubmitting = false;
|
||||
Toast.makeText(EditPostActivity.this, R.string.edit_success, Toast.LENGTH_SHORT).show();
|
||||
Intent returnIntent = new Intent();
|
||||
setResult(RESULT_OK, returnIntent);
|
||||
finish();
|
||||
if (response.isSuccessful()) {
|
||||
Toast.makeText(EditPostActivity.this, R.string.edit_success, Toast.LENGTH_SHORT).show();
|
||||
Intent returnIntent = new Intent();
|
||||
setResult(RESULT_OK, returnIntent);
|
||||
finish();
|
||||
} else {
|
||||
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -272,15 +342,49 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
|
||||
Toast.makeText(EditPostActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages);
|
||||
} else if (requestCode == UPLOAD_IMAGE_REQUEST_CODE) {
|
||||
if (data == null) {
|
||||
Snackbar.make(coordinatorLayout, R.string.error_getting_image, Snackbar.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Toast.makeText(this, R.string.uploading_image, Toast.LENGTH_SHORT).show();
|
||||
Handler handler = new Handler();
|
||||
Uri imageUri = data.getData();
|
||||
mExecutor.execute(() -> {
|
||||
try {
|
||||
Bitmap bitmap = Glide.with(this).asBitmap().load(imageUri).submit().get();
|
||||
String imageUrlOrError = UploadImageUtils.uploadImage(mRetrofit, mAccessToken, bitmap);
|
||||
handler.post(() -> {
|
||||
if (imageUrlOrError != null && !imageUrlOrError.startsWith("Error: ")) {
|
||||
String fileName = Utils.getFileName(this, imageUri);
|
||||
if (fileName == null) {
|
||||
fileName = imageUrlOrError;
|
||||
}
|
||||
mPost.setUrl(imageUrlOrError);
|
||||
linkEditText.setText(imageUrlOrError);
|
||||
Snackbar.make(coordinatorLayout, R.string.upload_image_success, Snackbar.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(this, R.string.upload_image_failed, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
handler.post(() -> Toast.makeText(this, R.string.get_image_bitmap_failed, Toast.LENGTH_LONG).show());
|
||||
} catch (XmlPullParserException | JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
handler.post(() -> Toast.makeText(this, R.string.error_processing_image, Toast.LENGTH_LONG).show());
|
||||
}
|
||||
});
|
||||
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
|
||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
|
||||
} else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
|
||||
editPost();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -304,7 +408,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
|
||||
if (isSubmitting) {
|
||||
promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_edit_post_detail);
|
||||
} else {
|
||||
if (contentEditText.getText().toString().equals(mPostContent)) {
|
||||
if (contentEditText.getText().toString().equals(mPost.getSelfText())) {
|
||||
finish();
|
||||
} else {
|
||||
promptAlertDialog(R.string.discard, R.string.discard_detail);
|
||||
@@ -352,7 +456,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
|
||||
int start = Math.max(contentEditText.getSelectionStart(), 0);
|
||||
int end = Math.max(contentEditText.getSelectionEnd(), 0);
|
||||
contentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
|
||||
"[" + uploadedImage.imageName + "](" + uploadedImage.imageUrl + ")",
|
||||
0, "[]()".length() + uploadedImage.imageName.length() + uploadedImage.imageUrl.length());
|
||||
"",
|
||||
0, "![]()".length() + uploadedImage.imageName.length() + uploadedImage.imageUrl.length());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,8 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
public SubredditViewModel mSubredditViewModel;
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
|
||||
private String mAccountQualifiedName;
|
||||
private String name;
|
||||
private String userWhere;
|
||||
private int postType;
|
||||
@@ -158,6 +160,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
name = getIntent().getStringExtra(EXTRA_NAME);
|
||||
postType = getIntent().getIntExtra(EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
|
||||
|
||||
@@ -262,7 +265,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
protected void applyCustomTheme() {
|
||||
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
|
||||
applyFABTheme(fab);
|
||||
applyFABTheme(fab, mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
|
||||
}
|
||||
|
||||
private void bindView(PostFilter postFilter, boolean initializeFragment) {
|
||||
@@ -470,7 +473,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,6 @@ import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RecyclerViewContentScrollingInterface;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.asynctasks.SwitchAccount;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
|
||||
@@ -56,15 +55,11 @@ import eu.toldi.infinityforlemmy.events.PassPrivateMessageEvent;
|
||||
import eu.toldi.infinityforlemmy.events.PassPrivateMessageIndexEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.fragments.InboxFragment;
|
||||
import eu.toldi.infinityforlemmy.message.CommentInteraction;
|
||||
import eu.toldi.infinityforlemmy.message.FetchMessage;
|
||||
import eu.toldi.infinityforlemmy.message.Message;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.message.ReadMessage;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class InboxActivity extends BaseActivity implements ActivityToolbarInterface, RecyclerViewContentScrollingInterface {
|
||||
|
||||
@@ -93,9 +88,6 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
||||
@Named("base")
|
||||
RetrofitHolder mRetrofit;
|
||||
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Inject
|
||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
@Inject
|
||||
@@ -233,7 +225,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
||||
mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(mAppBarLayout, mCollapsingToolbarLayout, mToolbar);
|
||||
applyTabLayoutTheme(tabLayout);
|
||||
applyFABTheme(fab);
|
||||
applyFABTheme(fab, mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
|
||||
}
|
||||
|
||||
private void getCurrentAccountAndFetchMessage(Bundle savedInstanceState) {
|
||||
@@ -272,13 +264,16 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
||||
}
|
||||
});
|
||||
viewPager2.setAdapter(sectionsPagerAdapter);
|
||||
viewPager2.setOffscreenPageLimit(2);
|
||||
viewPager2.setOffscreenPageLimit(3);
|
||||
new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> {
|
||||
switch (position) {
|
||||
case 0:
|
||||
Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.notifications));
|
||||
Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.replies));
|
||||
break;
|
||||
case 1:
|
||||
Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.mentions));
|
||||
break;
|
||||
case 2:
|
||||
Utils.setTitleWithCustomFontToTab(typeface, tab, getString(R.string.messages));
|
||||
break;
|
||||
}
|
||||
@@ -306,31 +301,21 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_read_all_messages_inbox_activity) {
|
||||
if (mAccessToken != null) {
|
||||
Toast.makeText(this, R.string.please_wait, Toast.LENGTH_SHORT).show();
|
||||
mOauthRetrofit.create(RedditAPI.class).readAllMessages(APIUtils.getOAuthHeader(mAccessToken))
|
||||
.enqueue(new Callback<>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
Toast.makeText(InboxActivity.this, R.string.read_all_messages_success, Toast.LENGTH_SHORT).show();
|
||||
if (sectionsPagerAdapter != null) {
|
||||
sectionsPagerAdapter.readAllMessages();
|
||||
}
|
||||
EventBus.getDefault().post(new ChangeInboxCountEvent(0));
|
||||
} else {
|
||||
if (response.code() == 429) {
|
||||
Toast.makeText(InboxActivity.this, R.string.read_all_messages_time_limit, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(InboxActivity.this, R.string.read_all_messages_failed, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
ReadMessage.readAllMessages(mRetrofit.getRetrofit(), mAccessToken, new ReadMessage.ReadMessageListener() {
|
||||
@Override
|
||||
public void readSuccess() {
|
||||
Toast.makeText(InboxActivity.this, R.string.read_all_messages_success, Toast.LENGTH_SHORT).show();
|
||||
if (sectionsPagerAdapter != null) {
|
||||
sectionsPagerAdapter.readAllMessages();
|
||||
}
|
||||
EventBus.getDefault().post(new ChangeInboxCountEvent(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
Toast.makeText(InboxActivity.this, R.string.read_all_messages_failed, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void readFailed() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
@@ -442,7 +427,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
||||
}
|
||||
}
|
||||
|
||||
Message getPrivateMessage(int index) {
|
||||
CommentInteraction getPrivateMessage(int index) {
|
||||
if (viewPager2 == null || fragmentManager == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -456,26 +441,29 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
if (position == 0) {
|
||||
InboxFragment fragment = new InboxFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(InboxFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(InboxFragment.EXTRA_MESSAGE_WHERE, FetchMessage.WHERE_INBOX);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
} else {
|
||||
InboxFragment fragment = new InboxFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(InboxFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(InboxFragment.EXTRA_MESSAGE_WHERE, FetchMessage.WHERE_MESSAGES);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
InboxFragment fragment = new InboxFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(InboxFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
switch (position) {
|
||||
case 0:
|
||||
bundle.putString(InboxFragment.EXTRA_MESSAGE_WHERE, FetchMessage.WHERE_REPLIES);
|
||||
break;
|
||||
case 1:
|
||||
bundle.putString(InboxFragment.EXTRA_MESSAGE_WHERE, FetchMessage.WHERE_MENTIONS);
|
||||
fragment.setArguments(bundle);
|
||||
break;
|
||||
case 2:
|
||||
bundle.putString(InboxFragment.EXTRA_MESSAGE_WHERE, FetchMessage.WHERE_MESSAGES);
|
||||
fragment.setArguments(bundle);
|
||||
break;
|
||||
}
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,12 @@ import javax.inject.Named;
|
||||
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.comment.Comment;
|
||||
import eu.toldi.infinityforlemmy.comment.FetchComment;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.post.ObjectResolver;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
|
||||
@@ -35,10 +40,9 @@ public class LinkResolverActivity extends AppCompatActivity {
|
||||
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
|
||||
public static final String EXTRA_IS_NSFW = "EIN";
|
||||
|
||||
private static final String POST_PATTERN = "/r/[\\w-]+/comments/\\w+/?\\w+/?";
|
||||
private static final String POST_PATTERN_2 = "/(u|U|user)/[\\w-]+/comments/\\w+/?\\w+/?";
|
||||
private static final String POST_PATTERN = "https?:\\/\\/\\S+\\/post\\/\\d+";
|
||||
private static final String POST_PATTERN_3 = "/[\\w-]+$";
|
||||
private static final String COMMENT_PATTERN = "/(r|u|U|user)/[\\w-]+/comments/\\w+/?[\\w-]+/\\w+/?";
|
||||
private static final String COMMENT_PATTERN = "https?:\\/\\/\\S+\\/comment\\/\\d+";
|
||||
private static final String SUBREDDIT_PATTERN = "(?:https?://[\\w.-]+)?/c/[\\w-]+(@[\\w.-]+)?";
|
||||
private static final String USER_PATTERN = "(?:https?://[\\w.-]+)?/u(sers)?/[\\w-]+(@[\\w.-]+)?";
|
||||
private static final String SIDEBAR_PATTERN = "/[rR]/[\\w-]+/about/sidebar";
|
||||
@@ -60,6 +64,19 @@ public class LinkResolverActivity extends AppCompatActivity {
|
||||
@Inject
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
|
||||
@Inject
|
||||
ObjectResolver mObjectResolver;
|
||||
|
||||
@Inject
|
||||
@Named("current_account")
|
||||
SharedPreferences mCurrentAccountSharedPreferences;
|
||||
|
||||
@Inject
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
|
||||
private String mAccessToken;
|
||||
|
||||
private Uri getRedditUriByPath(String path) {
|
||||
if (path.charAt(0) != '/') {
|
||||
return Uri.parse("https://www.reddit.com/" + path);
|
||||
@@ -73,6 +90,7 @@ public class LinkResolverActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
((Infinity) getApplication()).getAppComponent().inject(this);
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
|
||||
Uri uri = getIntent().getData();
|
||||
if (uri == null) {
|
||||
@@ -169,6 +187,77 @@ public class LinkResolverActivity extends AppCompatActivity {
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
|
||||
startActivity(intent);
|
||||
} else if (uri.toString().matches(POST_PATTERN)) {
|
||||
if (mAccessToken == null) {
|
||||
// switch retrofit to use the current instance for anonymous requests
|
||||
mRetrofit.setBaseURL(uri.getScheme() + "://" + uri.getHost() + "/");
|
||||
Intent intent = new Intent(LinkResolverActivity.this, ViewPostDetailActivity.class);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, Integer.parseInt(segments.get(segments.size() - 1)));
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
mObjectResolver.resolvePost(uri.toString(), mAccessToken, new ObjectResolver.ObjectResolverListener() {
|
||||
@Override
|
||||
public void onResolveObjectSuccess(Object p) {
|
||||
Post post = (Post) p;
|
||||
Intent intent = new Intent(LinkResolverActivity.this, ViewPostDetailActivity.class);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, post.getId());
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResolveObjectFailed() {
|
||||
Toast.makeText(LinkResolverActivity.this, R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (uri.toString().matches(COMMENT_PATTERN)) {
|
||||
if (mAccessToken == null) {
|
||||
mRetrofit.setBaseURL(uri.getScheme() + "://" + uri.getHost() + "/");
|
||||
FetchComment.fetchSingleComment(mRetrofit.getRetrofit(), null, Integer.parseInt(segments.get(segments.size() - 1)), new FetchComment.FetchCommentListener() {
|
||||
@Override
|
||||
public void onFetchCommentSuccess(ArrayList<Comment> comments, Integer parentId, ArrayList<Integer> moreChildrenIds) {
|
||||
Intent intent = new Intent(LinkResolverActivity.this, ViewPostDetailActivity.class);
|
||||
Comment comment = comments.get(0);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getPostId());
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId());
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_PARENT_ID, comment.getParentId());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchCommentFailed() {
|
||||
Toast.makeText(LinkResolverActivity.this, R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mObjectResolver.resolveComment(uri.toString(), mAccessToken, new ObjectResolver.ObjectResolverListener() {
|
||||
@Override
|
||||
public void onResolveObjectSuccess(Object c) {
|
||||
Comment comment = (Comment) c;
|
||||
Intent intent = new Intent(LinkResolverActivity.this, ViewPostDetailActivity.class);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getPostId());
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId());
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_PARENT_ID, comment.getParentId());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResolveObjectFailed() {
|
||||
Toast.makeText(LinkResolverActivity.this, R.string.could_not_resolve_link, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (authority.equals("v.redd.it")) {
|
||||
Intent intent = new Intent(this, ViewVideoActivity.class);
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_V_REDD_IT);
|
||||
@@ -187,35 +276,12 @@ public class LinkResolverActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
} else if (path.equals("/report")) {
|
||||
openInWebView(uri);
|
||||
} else if (path.matches(POST_PATTERN) || path.matches(POST_PATTERN_2)) {
|
||||
int commentsIndex = segments.lastIndexOf("comments");
|
||||
if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) {
|
||||
Intent intent = new Intent(this, ViewPostDetailActivity.class);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1));
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
deepLinkError(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(COMMENT_PATTERN)) {
|
||||
int commentsIndex = segments.lastIndexOf("comments");
|
||||
if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) {
|
||||
Intent intent = new Intent(this, ViewPostDetailActivity.class);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1));
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, segments.get(segments.size() - 1));
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
deepLinkError(uri);
|
||||
}
|
||||
} else if (path.matches(WIKI_PATTERN)) {
|
||||
String[] pathSegments = path.split("/");
|
||||
String wikiPage;
|
||||
|
||||
@@ -21,11 +21,11 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -43,6 +43,8 @@ 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.site.FetchSiteInfo;
|
||||
import eu.toldi.infinityforlemmy.site.SiteInfo;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import retrofit2.Call;
|
||||
@@ -139,9 +141,9 @@ public class LoginActivity extends BaseActivity {
|
||||
Log.i("LoginActivity", "Login button clicked");
|
||||
loginButton.setEnabled(false);
|
||||
progressBar.setVisibility(ProgressBar.VISIBLE);
|
||||
String username = username_input.getText().toString();
|
||||
String instance = correctURL(instance_input.getText().toString());
|
||||
if(!Patterns.WEB_URL.matcher(instance).matches()){
|
||||
String username = username_input.getText().toString().trim();
|
||||
String instance = correctURL(instance_input.getText().toString().trim());
|
||||
if (!Patterns.WEB_URL.matcher(instance).matches()) {
|
||||
instance_input.setError("Invalid instance URL");
|
||||
Toast.makeText(LoginActivity.this, "Invalid instance URL", Toast.LENGTH_SHORT).show();
|
||||
loginButton.setEnabled(true);
|
||||
@@ -149,7 +151,7 @@ public class LoginActivity extends BaseActivity {
|
||||
return;
|
||||
}
|
||||
Log.i("LoginActivity", "Instance: " + instance);
|
||||
AccountLoginDTO accountLoginDTO = new AccountLoginDTO(username,password_input.getText().toString(),token_2fa_input.getText().toString());
|
||||
AccountLoginDTO accountLoginDTO = new AccountLoginDTO(username, password_input.getText().toString(), token_2fa_input.getText().toString());
|
||||
mRetrofit.setBaseURL(instance);
|
||||
LemmyAPI api = mRetrofit.getRetrofit().create(LemmyAPI.class);
|
||||
Call<String> accessTokenCall = api.userLogin(accountLoginDTO);
|
||||
@@ -158,14 +160,16 @@ public class LoginActivity extends BaseActivity {
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
progressBar.setVisibility(ProgressBar.GONE);
|
||||
loginButton.setEnabled(true);
|
||||
String accountResponse = response.body();
|
||||
if (accountResponse == null) {
|
||||
Log.e("LoginActivity", "Account response is null");
|
||||
Toast.makeText(LoginActivity.this, R.string.cannot_fetch_user_info, Toast.LENGTH_SHORT).show();
|
||||
//Handle error
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
String accountResponse = response.body();
|
||||
if (accountResponse == null) {
|
||||
Log.e("LoginActivity", "Account response is null");
|
||||
Toast.makeText(LoginActivity.this, R.string.invalid_response, Toast.LENGTH_SHORT).show();
|
||||
//Handle error
|
||||
return;
|
||||
}
|
||||
try {
|
||||
JSONObject responseJSON = new JSONObject(accountResponse);
|
||||
String accessToken = responseJSON.getString("jwt");
|
||||
@@ -173,18 +177,36 @@ public class LoginActivity extends BaseActivity {
|
||||
FetchMyInfo.fetchAccountInfo(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, username,
|
||||
accessToken, new FetchMyInfo.FetchMyInfoListener() {
|
||||
@Override
|
||||
public void onFetchMyInfoSuccess(String name,String display_name, String profileImageUrl, String bannerImageUrl) {
|
||||
public void onFetchMyInfoSuccess(String name, String display_name, String profileImageUrl, String bannerImageUrl) {
|
||||
FetchSiteInfo.fetchSiteInfo(mRetrofit.getRetrofit(), accessToken, new FetchSiteInfo.FetchSiteInfoListener() {
|
||||
@Override
|
||||
public void onFetchSiteInfoSuccess(SiteInfo siteInfo) {
|
||||
boolean canDownvote = siteInfo.isEnable_downvotes();
|
||||
ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), name,display_name, accessToken, profileImageUrl, bannerImageUrl, authCode,instance,canDownvote, mRedditDataRoomDatabase.accountDao(),
|
||||
() -> {
|
||||
Intent resultIntent = new Intent();
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
finish();
|
||||
});
|
||||
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, canDownvote).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSiteInfoFailed() {
|
||||
ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), name,display_name, accessToken, profileImageUrl, bannerImageUrl, authCode,instance,true, mRedditDataRoomDatabase.accountDao(),
|
||||
() -> {
|
||||
Intent resultIntent = new Intent();
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
finish();
|
||||
});
|
||||
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, true).apply();
|
||||
}
|
||||
});
|
||||
mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, accessToken)
|
||||
.putString(SharedPreferencesUtils.ACCOUNT_NAME, display_name)
|
||||
.putString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, name)
|
||||
.putString(SharedPreferencesUtils.ACCOUNT_INSTANCE,instance)
|
||||
.putString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, profileImageUrl).apply();
|
||||
ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), name,display_name, accessToken, profileImageUrl, bannerImageUrl, authCode,instance, mRedditDataRoomDatabase.accountDao(),
|
||||
() -> {
|
||||
Intent resultIntent = new Intent();
|
||||
setResult(Activity.RESULT_OK, resultIntent);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -206,18 +228,25 @@ public class LoginActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject responseObject = new JSONObject(accountResponse);
|
||||
if(responseObject.has("error")) {
|
||||
Toast.makeText(LoginActivity.this, "Error:"+responseObject.getString("error"), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else {
|
||||
String errorBody = response.errorBody().string();
|
||||
Log.e("LoginActivity", "Error body: " + errorBody.trim());
|
||||
JSONObject responseObject = new JSONObject(errorBody.trim());
|
||||
if (responseObject.has("error")) {
|
||||
if (responseObject.getString("error").equals("incorrect_login")) {
|
||||
Toast.makeText(LoginActivity.this, R.string.invalid_username_or_password, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(LoginActivity.this, "Error:" + responseObject.getString("error"), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(LoginActivity.this, R.string.cannot_fetch_user_info, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Toast.makeText(LoginActivity.this, R.string.cannot_fetch_user_info, Toast.LENGTH_SHORT).show();
|
||||
} catch (IOException e) {
|
||||
Toast.makeText(LoginActivity.this, R.string.cannot_fetch_user_info, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
Log.e("LoginActivity", "Failed to get access token: " + response.code() + " " + response.message() + " " + response.errorBody());
|
||||
Log.e("LoginActivity", "Failed to get access token: " + response.code() + " " + response.message());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -71,7 +73,6 @@ import javax.inject.Named;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.ActivityToolbarInterface;
|
||||
import eu.toldi.infinityforlemmy.FetchMyInfo;
|
||||
import eu.toldi.infinityforlemmy.FetchSubscribedThing;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.MarkPostAsReadInterface;
|
||||
@@ -106,12 +107,14 @@ import eu.toldi.infinityforlemmy.events.ChangeLockBottomAppBarEvent;
|
||||
import eu.toldi.infinityforlemmy.events.ChangeNSFWEvent;
|
||||
import eu.toldi.infinityforlemmy.events.ChangeRequireAuthToAccountSectionEvent;
|
||||
import eu.toldi.infinityforlemmy.events.ChangeShowAvatarOnTheRightInTheNavigationDrawerEvent;
|
||||
import eu.toldi.infinityforlemmy.events.ChangeUseCircularFabEvent;
|
||||
import eu.toldi.infinityforlemmy.events.RecreateActivityEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.fragments.PostFragment;
|
||||
import eu.toldi.infinityforlemmy.message.ReadMessage;
|
||||
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
|
||||
import eu.toldi.infinityforlemmy.multireddit.MultiRedditViewModel;
|
||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
@@ -212,6 +215,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
|
||||
@Inject
|
||||
MarkPostAsRead markPostAsRead;
|
||||
|
||||
private FragmentManager fragmentManager;
|
||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||
private NavigationDrawerRecyclerViewMergedAdapter adapter;
|
||||
@@ -224,9 +231,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
private boolean mFetchUserInfoSuccess = false;
|
||||
private boolean mFetchSubscriptionsSuccess = false;
|
||||
private boolean mDrawerOnAccountSwitch = false;
|
||||
private String mMessageFullname;
|
||||
private int mMessageFullname;
|
||||
private String mNewAccountName;
|
||||
private boolean hideFab;
|
||||
|
||||
private boolean useCircularFab;
|
||||
private boolean showBottomAppBar;
|
||||
private int mBackButtonAction;
|
||||
private boolean mLockBottomAppBar;
|
||||
@@ -253,6 +262,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
ButterKnife.bind(this);
|
||||
|
||||
hideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_FAB_IN_POST_FEED, false);
|
||||
useCircularFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, 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),
|
||||
@@ -326,9 +336,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
fragmentManager = getSupportFragmentManager();
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
String instance = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
|
||||
String instance = (mAccessToken == null) ? mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI) : mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
|
||||
if(instance != null) {
|
||||
mRetrofit.setBaseURL(instance);
|
||||
}
|
||||
@@ -337,11 +348,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
|
||||
mFetchSubscriptionsSuccess = savedInstanceState.getBoolean(FETCH_SUBSCRIPTIONS_STATE);
|
||||
mDrawerOnAccountSwitch = savedInstanceState.getBoolean(DRAWER_ON_ACCOUNT_SWITCH_STATE);
|
||||
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
|
||||
mMessageFullname = savedInstanceState.getInt(MESSAGE_FULLNAME_STATE);
|
||||
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
|
||||
inboxCount = savedInstanceState.getInt(INBOX_COUNT_STATE);
|
||||
} else {
|
||||
mMessageFullname = getIntent().getStringExtra(EXTRA_MESSSAGE_FULLNAME);
|
||||
mMessageFullname = getIntent().getIntExtra(EXTRA_MESSSAGE_FULLNAME, 0);
|
||||
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
|
||||
}
|
||||
|
||||
@@ -349,6 +360,17 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
initializeNotificationAndBindView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (mAccessToken == null) {
|
||||
String instancePreference = mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI);
|
||||
if (!mRetrofit.getBaseURL().equalsIgnoreCase(instancePreference)) {
|
||||
this.recreate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharedPreferences getDefaultSharedPreferences() {
|
||||
return mSharedPreferences;
|
||||
@@ -367,7 +389,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
navigationView.setBackgroundColor(backgroundColor);
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
|
||||
applyTabLayoutTheme(tabLayout);
|
||||
applyFABTheme(navigationWrapper.floatingActionButton);
|
||||
applyFABTheme(navigationWrapper.floatingActionButton, useCircularFab);
|
||||
}
|
||||
|
||||
private void initializeNotificationAndBindView() {
|
||||
@@ -859,6 +881,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
startActivity(logOutIntent);
|
||||
finish();
|
||||
});
|
||||
} else if (stringId == R.string.anonymous_account_instance) {
|
||||
changeAnonymousAccountInstance();
|
||||
}
|
||||
if (intent != null) {
|
||||
startActivity(intent);
|
||||
@@ -1005,11 +1029,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
loadUserData();
|
||||
|
||||
if (mAccessToken != null) {
|
||||
if (mMessageFullname != null) {
|
||||
if (mMessageFullname != 0) {
|
||||
ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
|
||||
@Override
|
||||
public void readSuccess() {
|
||||
mMessageFullname = null;
|
||||
mMessageFullname = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1052,20 +1076,29 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
|
||||
private void loadUserData() {
|
||||
if (!mFetchUserInfoSuccess) {
|
||||
FetchUserData.fetchUserData(mRedditDataRoomDatabase, mRetrofit.getRetrofit(), mAccessToken,
|
||||
mAccountName, new FetchUserData.FetchUserDataListener() {
|
||||
FetchUserData.fetchUnreadCount(mRetrofit.getRetrofit(), mAccessToken, new FetchUserData.FetchUserUnreadCountListener() {
|
||||
@Override
|
||||
public void onFetchUserDataSuccess(UserData userData, int inboxCount) {
|
||||
public void onFetchUserUnreadCountSuccess(int inboxCount) {
|
||||
MainActivity.this.inboxCount = inboxCount;
|
||||
mAccountName = userData.getName();
|
||||
mFetchUserInfoSuccess = true;
|
||||
if (adapter != null) {
|
||||
adapter.setInboxCount(inboxCount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchUserDataFailed() {
|
||||
public void onFetchUserUnreadCountFailed() {
|
||||
}
|
||||
});
|
||||
FetchUserData.fetchUserData(mRedditDataRoomDatabase, mRetrofit.getRetrofit(), mAccessToken,
|
||||
mAccountName, new FetchUserData.FetchUserDataListener() {
|
||||
@Override
|
||||
public void onFetchUserDataSuccess(UserData userData, int inboxCount) {
|
||||
mAccountName = userData.getName();
|
||||
mFetchUserInfoSuccess = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchUserDataFailed() {
|
||||
mFetchUserInfoSuccess = false;
|
||||
}
|
||||
});
|
||||
@@ -1157,7 +1190,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess);
|
||||
outState.putBoolean(FETCH_SUBSCRIPTIONS_STATE, mFetchSubscriptionsSuccess);
|
||||
outState.putBoolean(DRAWER_ON_ACCOUNT_SWITCH_STATE, mDrawerOnAccountSwitch);
|
||||
outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
|
||||
outState.putInt(MESSAGE_FULLNAME_STATE, mMessageFullname);
|
||||
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
||||
outState.putInt(INBOX_COUNT_STATE, inboxCount);
|
||||
}
|
||||
@@ -1316,6 +1349,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
navigationWrapper.floatingActionButton.setVisibility(hideFab ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onChangeUseCircularFab(ChangeUseCircularFabEvent event) {
|
||||
useCircularFab = event.isUseCircularFab();
|
||||
applyFABTheme(navigationWrapper.floatingActionButton, useCircularFab);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongPress() {
|
||||
if (sectionsPagerAdapter != null) {
|
||||
@@ -1361,10 +1400,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
goToUser();
|
||||
break;
|
||||
}
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_RANDOM: {
|
||||
randomThing();
|
||||
break;
|
||||
}
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_HIDE_READ_POSTS: {
|
||||
if (sectionsPagerAdapter != null) {
|
||||
sectionsPagerAdapter.hideReadPosts();
|
||||
@@ -1386,6 +1421,72 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
}
|
||||
}
|
||||
|
||||
private void changeAnonymousAccountInstance() {
|
||||
View rootView = getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, coordinatorLayout, false);
|
||||
TextInputEditText thingEditText = rootView.findViewById(R.id.text_input_edit_text_go_to_thing_edit_text);
|
||||
|
||||
thingEditText.requestFocus();
|
||||
thingEditText.setText(mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI));
|
||||
Utils.showKeyboard(this, new Handler(), thingEditText);
|
||||
thingEditText.setOnEditorActionListener((textView, i, keyEvent) -> {
|
||||
if (i == EditorInfo.IME_ACTION_DONE) {
|
||||
Utils.hideKeyboard(this);
|
||||
String url = thingEditText.getText().toString();
|
||||
if (url.isEmpty()) {
|
||||
thingEditText.setError("Instance URL cannot be empty");
|
||||
return false;
|
||||
}
|
||||
if (!url.startsWith("http://") || !url.startsWith("https://")) {
|
||||
url = "https://" + url;
|
||||
}
|
||||
try {
|
||||
URL urlObj = new URL(url);
|
||||
url = urlObj.getProtocol() + "://" + urlObj.getHost() + "/";
|
||||
mSharedPreferences.edit().putString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, url).apply();
|
||||
mRetrofit.setBaseURL(url);
|
||||
sectionsPagerAdapter.getCurrentFragment().refresh();
|
||||
} catch (MalformedURLException e) {
|
||||
thingEditText.setError("Invalid URL");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
|
||||
.setTitle(R.string.anonymous_account_instance)
|
||||
.setView(rootView)
|
||||
.setPositiveButton(R.string.ok, (dialogInterface, i)
|
||||
-> {
|
||||
Utils.hideKeyboard(this);
|
||||
String url = thingEditText.getText().toString();
|
||||
if (url.isEmpty()) {
|
||||
thingEditText.setError("Instance URL cannot be empty");
|
||||
return;
|
||||
}
|
||||
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
||||
url = "https://" + url;
|
||||
}
|
||||
try {
|
||||
URL urlObj = new URL(url);
|
||||
url = urlObj.getProtocol() + "://" + urlObj.getHost() + "/";
|
||||
mSharedPreferences.edit().putString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, url).apply();
|
||||
mRetrofit.setBaseURL(url);
|
||||
sectionsPagerAdapter.getCurrentFragment().refresh();
|
||||
} catch (MalformedURLException e) {
|
||||
thingEditText.setError("Invalid URL");
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||
Utils.hideKeyboard(this);
|
||||
})
|
||||
.setOnDismissListener(dialogInterface -> {
|
||||
Utils.hideKeyboard(this);
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
private void goToSubreddit() {
|
||||
View rootView = getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, coordinatorLayout, false);
|
||||
TextInputEditText thingEditText = rootView.findViewById(R.id.text_input_edit_text_go_to_thing_edit_text);
|
||||
@@ -1406,7 +1507,7 @@ 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_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
|
||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString());
|
||||
startActivity(subredditIntent);
|
||||
return true;
|
||||
}
|
||||
@@ -1464,7 +1565,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
-> {
|
||||
Utils.hideKeyboard(this);
|
||||
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
|
||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString());
|
||||
startActivity(subredditIntent);
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||
@@ -1485,7 +1586,7 @@ 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_USER_NAME_KEY, thingEditText.getText().toString());
|
||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString());
|
||||
startActivity(userIntent);
|
||||
return true;
|
||||
}
|
||||
@@ -1498,7 +1599,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
-> {
|
||||
Utils.hideKeyboard(this);
|
||||
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
|
||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString());
|
||||
startActivity(userIntent);
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||
@@ -1527,7 +1628,17 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||
markPostAsRead.markPostAsRead(post.getId(), mAccessToken, new MarkPostAsRead.MarkPostAsReadListener() {
|
||||
@Override
|
||||
public void onMarkPostAsReadSuccess() {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkPostAsReadFailed() {
|
||||
Toast.makeText(MainActivity.this, R.string.mark_post_as_read_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void doNotShowRedditAPIInfoAgain() {
|
||||
@@ -1649,7 +1760,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL) {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE : PostPagingSource.TYPE_FRONT_PAGE);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
|
||||
bundle.putString(PostFragment.EXTRA_NAME, "all");
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
@@ -1713,7 +1824,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
} else {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE : PostPagingSource.TYPE_FRONT_PAGE);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
|
||||
bundle.putString(PostFragment.EXTRA_NAME, "local");
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
|
||||
@@ -33,6 +33,7 @@ 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.utils.SharedPreferencesUtils;
|
||||
|
||||
public class PostFilterPreferenceActivity extends BaseActivity {
|
||||
|
||||
@@ -205,7 +206,7 @@ public class PostFilterPreferenceActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void applyCustomTheme() {
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
|
||||
applyFABTheme(fab);
|
||||
applyFABTheme(fab, sharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
|
||||
coordinatorLayout.setBackgroundColor(customThemeWrapper.getBackgroundColor());
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||
import eu.toldi.infinityforlemmy.postfilter.PostFilterUsage;
|
||||
import eu.toldi.infinityforlemmy.postfilter.PostFilterUsageViewModel;
|
||||
import eu.toldi.infinityforlemmy.postfilter.SavePostFilterUsage;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
|
||||
public class PostFilterUsageListingActivity extends BaseActivity {
|
||||
@@ -206,7 +207,7 @@ public class PostFilterUsageListingActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void applyCustomTheme() {
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
|
||||
applyFABTheme(fab);
|
||||
applyFABTheme(fab, sharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
|
||||
coordinatorLayout.setBackgroundColor(customThemeWrapper.getBackgroundColor());
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,9 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitGalleryPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.UploadImageUtils;
|
||||
@@ -102,6 +105,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||
private static final int PICK_IMAGE_REQUEST_CODE = 1;
|
||||
private static final int CAPTURE_IMAGE_REQUEST_CODE = 2;
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_gallery_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@@ -123,10 +127,6 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
MaterialButton rulesButton;
|
||||
@BindView(R.id.divider_1_post_gallery_activity)
|
||||
MaterialDivider divider1;
|
||||
@BindView(R.id.flair_custom_text_view_post_gallery_activity)
|
||||
CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_gallery_activity)
|
||||
CustomTextView spoilerTextView;
|
||||
@BindView(R.id.nsfw_custom_text_view_post_gallery_activity)
|
||||
CustomTextView nsfwTextView;
|
||||
@BindView(R.id.receive_post_reply_notifications_linear_layout_post_gallery_activity)
|
||||
@@ -168,6 +168,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
private String mAccountName;
|
||||
private String iconUrl;
|
||||
private String subredditName;
|
||||
private SubscribedSubredditData communityData;
|
||||
private boolean subredditSelected = false;
|
||||
private boolean subredditIsUser;
|
||||
private boolean loadSubredditIconSuccessful = true;
|
||||
@@ -245,6 +246,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||
@@ -279,7 +281,6 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
if (subredditName != null) {
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if (!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
}
|
||||
@@ -290,17 +291,6 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
mPostingSnackbar.show();
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
if (isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
}
|
||||
if (isNSFW) {
|
||||
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
|
||||
nsfwTextView.setBorderColor(nsfwBackgroundColor);
|
||||
@@ -314,11 +304,25 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
loadSubredditIconSuccessful = false;
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
{
|
||||
communityData = new SubscribedSubredditData(subredditData);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
loadSubredditIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -347,40 +351,12 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
if (subredditIsUser) {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, communityData.getQualified_name());
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
flairTextView.setOnClickListener(view -> {
|
||||
if (flair == null) {
|
||||
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
flairSelectionBottomSheetFragment.setArguments(bundle);
|
||||
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
|
||||
} else {
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
});
|
||||
|
||||
spoilerTextView.setOnClickListener(view -> {
|
||||
if (!isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
isSpoiler = true;
|
||||
} else {
|
||||
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
isSpoiler = false;
|
||||
}
|
||||
});
|
||||
|
||||
nsfwTextView.setOnClickListener(view -> {
|
||||
if (!isNSFW) {
|
||||
@@ -449,8 +425,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
|
||||
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
|
||||
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
|
||||
nsfwTextView.setTextColor(primaryTextColor);
|
||||
titleEditText.setTextColor(primaryTextColor);
|
||||
titleEditText.setHintTextColor(secondaryTextColor);
|
||||
@@ -458,8 +433,6 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
rulesButton.setTypeface(typeface);
|
||||
receivePostReplyNotificationsTextView.setTypeface(typeface);
|
||||
flairTextView.setTypeface(typeface);
|
||||
spoilerTextView.setTypeface(typeface);
|
||||
nsfwTextView.setTypeface(typeface);
|
||||
titleEditText.setTypeface(typeface);
|
||||
}
|
||||
@@ -492,7 +465,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
mExecutor.execute(() -> {
|
||||
try {
|
||||
Bitmap resource = Glide.with(PostGalleryActivity.this).asBitmap().load(imageUri).submit().get();
|
||||
String response = UploadImageUtils.uploadImage(mOauthRetrofit, mUploadMediaRetrofit, mAccessToken, resource, true);
|
||||
String response = UploadImageUtils.uploadImage(mRetrofit, mAccessToken, resource, true);
|
||||
String mediaId = new JSONObject(response).getJSONObject(JSONUtils.ASSET_KEY).getString(JSONUtils.ASSET_ID_KEY);
|
||||
handler.post(() -> {
|
||||
adapter.setImageAsUploaded(mediaId);
|
||||
@@ -612,7 +585,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_GALLERY);
|
||||
ArrayList<RedditGalleryPayload.Item> items = new ArrayList<>();
|
||||
for (RedditGallerySubmissionRecyclerViewAdapter.RedditGalleryImageInfo i : redditGalleryImageInfoList) {
|
||||
@@ -648,6 +621,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
|
||||
@@ -666,19 +640,16 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
subredditIsUser = false;
|
||||
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
} else if (requestCode == PICK_IMAGE_REQUEST_CODE) {
|
||||
@@ -709,10 +680,6 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
this.flair = flair;
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@ import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -25,6 +26,8 @@ import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestManager;
|
||||
@@ -43,6 +46,7 @@ import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -55,22 +59,31 @@ import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.UploadImageEnabledActivity;
|
||||
import eu.toldi.infinityforlemmy.UploadedImage;
|
||||
import eu.toldi.infinityforlemmy.account.Account;
|
||||
import eu.toldi.infinityforlemmy.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
||||
import eu.toldi.infinityforlemmy.asynctasks.LoadSubredditIcon;
|
||||
import eu.toldi.infinityforlemmy.bottomsheetfragments.AccountChooserBottomSheetFragment;
|
||||
import eu.toldi.infinityforlemmy.bottomsheetfragments.FlairBottomSheetFragment;
|
||||
import eu.toldi.infinityforlemmy.bottomsheetfragments.UploadedImagesBottomSheetFragment;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitImagePostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitVideoOrGifPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class PostImageActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback,
|
||||
AccountChooserBottomSheetFragment.AccountChooserListener {
|
||||
UploadImageEnabledActivity, AccountChooserBottomSheetFragment.AccountChooserListener {
|
||||
|
||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||
|
||||
@@ -90,6 +103,10 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
private static final int PICK_IMAGE_REQUEST_CODE = 1;
|
||||
private static final int CAPTURE_IMAGE_REQUEST_CODE = 2;
|
||||
|
||||
private static final int PICK_IMAGE_REQUEST_CODE_2 = 100;
|
||||
private static final int CAPTURE_IMAGE_REQUEST_CODE_2 = 200;
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_image_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@BindView(R.id.appbar_layout_post_image_activity)
|
||||
@@ -110,10 +127,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
MaterialButton rulesButton;
|
||||
@BindView(R.id.divider_1_post_image_activity)
|
||||
MaterialDivider divider1;
|
||||
@BindView(R.id.flair_custom_text_view_post_image_activity)
|
||||
CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_image_activity)
|
||||
CustomTextView spoilerTextView;
|
||||
@BindView(R.id.nsfw_custom_text_view_post_image_activity)
|
||||
CustomTextView nsfwTextView;
|
||||
@BindView(R.id.receive_post_reply_notifications_linear_layout_post_image_activity)
|
||||
@@ -153,6 +166,11 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
@Inject
|
||||
@Named("current_account")
|
||||
SharedPreferences mCurrentAccountSharedPreferences;
|
||||
|
||||
@BindView(R.id.post_text_content_edit_text_post_text_activity)
|
||||
EditText contentEditText;
|
||||
@BindView(R.id.markdown_bottom_bar_recycler_view_post_text_activity)
|
||||
RecyclerView markdownBottomBarRecyclerView;
|
||||
@Inject
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
@@ -162,6 +180,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
private String mAccountName;
|
||||
private String iconUrl;
|
||||
private String subredditName;
|
||||
private SubscribedSubredditData communityData;
|
||||
private boolean subredditSelected = false;
|
||||
private boolean subredditIsUser;
|
||||
private boolean loadSubredditIconSuccessful = true;
|
||||
@@ -183,6 +202,9 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
private FlairBottomSheetFragment flairSelectionBottomSheetFragment;
|
||||
private Snackbar mPostingSnackbar;
|
||||
|
||||
private Uri capturedImageUri;
|
||||
private ArrayList<UploadedImage> uploadedImages = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
((Infinity) getApplication()).getAppComponent().inject(this);
|
||||
@@ -217,6 +239,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||
@@ -247,7 +270,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (subredditName != null) {
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if (!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
}
|
||||
@@ -258,17 +280,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
mPostingSnackbar.show();
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
if (isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
}
|
||||
if (isNSFW) {
|
||||
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
|
||||
nsfwTextView.setBorderColor(nsfwBackgroundColor);
|
||||
@@ -282,11 +293,25 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
loadSubredditIconSuccessful = false;
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
{
|
||||
communityData = new SubscribedSubredditData(subredditData);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
loadSubredditIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -320,40 +345,12 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (subredditIsUser) {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, communityData.getQualified_name());
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
flairTextView.setOnClickListener(view -> {
|
||||
if (flair == null) {
|
||||
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
flairSelectionBottomSheetFragment.setArguments(bundle);
|
||||
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
|
||||
} else {
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
});
|
||||
|
||||
spoilerTextView.setOnClickListener(view -> {
|
||||
if (!isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
isSpoiler = true;
|
||||
} else {
|
||||
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
isSpoiler = false;
|
||||
}
|
||||
});
|
||||
|
||||
nsfwTextView.setOnClickListener(view -> {
|
||||
if (!isNSFW) {
|
||||
@@ -400,6 +397,30 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
imageView.setVisibility(View.GONE);
|
||||
constraintLayout.setVisibility(View.VISIBLE);
|
||||
});
|
||||
|
||||
MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter(
|
||||
mCustomThemeWrapper, new MarkdownBottomBarRecyclerViewAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public void onClick(int item) {
|
||||
MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener(
|
||||
PostImageActivity.this, contentEditText, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUploadImage() {
|
||||
Utils.hideKeyboard(PostImageActivity.this);
|
||||
UploadedImagesBottomSheetFragment fragment = new UploadedImagesBottomSheetFragment();
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putParcelableArrayList(UploadedImagesBottomSheetFragment.EXTRA_UPLOADED_IMAGES,
|
||||
uploadedImages);
|
||||
fragment.setArguments(arguments);
|
||||
fragment.show(getSupportFragmentManager(), fragment.getTag());
|
||||
}
|
||||
});
|
||||
|
||||
markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this,
|
||||
LinearLayoutManager.HORIZONTAL, false));
|
||||
markdownBottomBarRecyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void loadCurrentAccount() {
|
||||
@@ -451,20 +472,17 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
|
||||
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
|
||||
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
nsfwTextView.setTextColor(primaryTextColor);
|
||||
titleEditText.setTextColor(primaryTextColor);
|
||||
titleEditText.setHintTextColor(secondaryTextColor);
|
||||
applyFABTheme(captureFab);
|
||||
applyFABTheme(selectFromLibraryFab);
|
||||
boolean circleFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false);
|
||||
applyFABTheme(captureFab, circleFab);
|
||||
applyFABTheme(selectFromLibraryFab, circleFab);
|
||||
selectAgainTextView.setTextColor(mCustomThemeWrapper.getColorAccent());
|
||||
if (typeface != null) {
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
rulesButton.setTypeface(typeface);
|
||||
receivePostReplyNotificationsTextView.setTypeface(typeface);
|
||||
flairTextView.setTypeface(typeface);
|
||||
spoilerTextView.setTypeface(typeface);
|
||||
nsfwTextView.setTypeface(typeface);
|
||||
titleEditText.setTypeface(typeface);
|
||||
selectAgainTextView.setTypeface(typeface);
|
||||
@@ -570,8 +588,9 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.setData(imageUri);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_BODY, contentEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
|
||||
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
|
||||
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
|
||||
@@ -608,6 +627,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
@Override
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
@@ -628,19 +648,15 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getExtras().getParcelable(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
|
||||
subredditIsUser = false;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
} else if (requestCode == PICK_IMAGE_REQUEST_CODE) {
|
||||
@@ -657,6 +673,16 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (resultCode == RESULT_OK) {
|
||||
loadImage();
|
||||
}
|
||||
} else if (requestCode == PICK_IMAGE_REQUEST_CODE_2) {
|
||||
if (data == null) {
|
||||
Toast.makeText(PostImageActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages);
|
||||
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE_2) {
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -669,10 +695,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
this.flair = flair;
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -700,8 +722,8 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
isPosting = false;
|
||||
mPostingSnackbar.dismiss();
|
||||
if (submitImagePostEvent.postSuccess) {
|
||||
Intent intent = new Intent(PostImageActivity.this, ViewUserDetailActivity.class);
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName);
|
||||
Intent intent = new Intent(PostImageActivity.this, ViewPostDetailActivity.class);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, submitImagePostEvent.post);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
} else {
|
||||
@@ -740,4 +762,37 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadImage() {
|
||||
Intent intent = new Intent();
|
||||
intent.setType("image/*");
|
||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
startActivityForResult(Intent.createChooser(intent,
|
||||
getResources().getString(R.string.select_from_gallery)), PICK_IMAGE_REQUEST_CODE_2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void captureImage() {
|
||||
Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
try {
|
||||
capturedImageUri = FileProvider.getUriForFile(this, "eu.toldi.infinityforlemmy.provider",
|
||||
File.createTempFile("captured_image", ".jpg", getExternalFilesDir(Environment.DIRECTORY_PICTURES)));
|
||||
pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri);
|
||||
startActivityForResult(pictureIntent, CAPTURE_IMAGE_REQUEST_CODE_2);
|
||||
} catch (IOException ex) {
|
||||
Toast.makeText(this, R.string.error_creating_temp_file, Toast.LENGTH_SHORT).show();
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(this, R.string.no_camera_available, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertImageUrl(UploadedImage uploadedImage) {
|
||||
int start = Math.max(contentEditText.getSelectionStart(), 0);
|
||||
int end = Math.max(contentEditText.getSelectionEnd(), 0);
|
||||
contentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
|
||||
"",
|
||||
0, "![]()".length() + uploadedImage.imageName.length() + uploadedImage.imageUrl.length());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package eu.toldi.infinityforlemmy.activities;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.webkit.URLUtil;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
@@ -20,6 +23,9 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestManager;
|
||||
@@ -35,6 +41,9 @@ import com.libRG.CustomTextView;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -47,17 +56,26 @@ import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.UploadImageEnabledActivity;
|
||||
import eu.toldi.infinityforlemmy.UploadedImage;
|
||||
import eu.toldi.infinityforlemmy.account.Account;
|
||||
import eu.toldi.infinityforlemmy.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
||||
import eu.toldi.infinityforlemmy.apis.TitleSuggestion;
|
||||
import eu.toldi.infinityforlemmy.asynctasks.LoadSubredditIcon;
|
||||
import eu.toldi.infinityforlemmy.bottomsheetfragments.AccountChooserBottomSheetFragment;
|
||||
import eu.toldi.infinityforlemmy.bottomsheetfragments.FlairBottomSheetFragment;
|
||||
import eu.toldi.infinityforlemmy.bottomsheetfragments.UploadedImagesBottomSheetFragment;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitTextOrLinkPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
import retrofit2.Call;
|
||||
@@ -67,12 +85,13 @@ import retrofit2.Retrofit;
|
||||
import retrofit2.converter.scalars.ScalarsConverterFactory;
|
||||
|
||||
public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback,
|
||||
AccountChooserBottomSheetFragment.AccountChooserListener {
|
||||
UploadImageEnabledActivity, AccountChooserBottomSheetFragment.AccountChooserListener {
|
||||
|
||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||
static final String EXTRA_LINK = "EL";
|
||||
|
||||
private static final String SELECTED_ACCOUNT_STATE = "SAS";
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
private static final String SUBREDDIT_NAME_STATE = "SNS";
|
||||
private static final String SUBREDDIT_ICON_STATE = "SIS";
|
||||
private static final String SUBREDDIT_SELECTED_STATE = "SSS";
|
||||
@@ -84,6 +103,9 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
private static final String IS_NSFW_STATE = "INS";
|
||||
|
||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||
private static final int PICK_IMAGE_REQUEST_CODE = 100;
|
||||
private static final int CAPTURE_IMAGE_REQUEST_CODE = 200;
|
||||
private static final int MARKDOWN_PREVIEW_REQUEST_CODE = 300;
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_link_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@@ -107,10 +129,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
MaterialDivider divider1;
|
||||
@BindView(R.id.divider_2_post_link_activity)
|
||||
MaterialDivider divider2;
|
||||
@BindView(R.id.flair_custom_text_view_post_link_activity)
|
||||
CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_link_activity)
|
||||
CustomTextView spoilerTextView;
|
||||
@BindView(R.id.nsfw_custom_text_view_post_link_activity)
|
||||
CustomTextView nsfwTextView;
|
||||
@BindView(R.id.receive_post_reply_notifications_linear_layout_post_link_activity)
|
||||
@@ -125,6 +143,11 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
MaterialButton suggestTitleButton;
|
||||
@BindView(R.id.post_link_edit_text_post_link_activity)
|
||||
EditText linkEditText;
|
||||
|
||||
@BindView(R.id.post_text_content_edit_text_post_text_activity)
|
||||
EditText contentEditText;
|
||||
@BindView(R.id.markdown_bottom_bar_recycler_view_post_text_activity)
|
||||
RecyclerView markdownBottomBarRecyclerView;
|
||||
@Inject
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
@@ -147,6 +170,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
private String mAccessToken;
|
||||
private String iconUrl;
|
||||
private String subredditName;
|
||||
private SubscribedSubredditData communityData;
|
||||
private boolean subredditSelected = false;
|
||||
private boolean subredditIsUser;
|
||||
private boolean loadSubredditIconSuccessful = true;
|
||||
@@ -167,6 +191,9 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
private FlairBottomSheetFragment flairSelectionBottomSheetFragment;
|
||||
private Snackbar mPostingSnackbar;
|
||||
|
||||
private Uri capturedImageUri;
|
||||
private ArrayList<UploadedImage> uploadedImages = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
((Infinity) getApplication()).getAppComponent().inject(this);
|
||||
@@ -200,6 +227,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||
@@ -225,7 +253,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (subredditName != null) {
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if (!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
}
|
||||
@@ -236,17 +263,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
mPostingSnackbar.show();
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
if (isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
}
|
||||
if (isNSFW) {
|
||||
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
|
||||
nsfwTextView.setBorderColor(nsfwBackgroundColor);
|
||||
@@ -260,11 +276,25 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
loadSubredditIconSuccessful = false;
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
{
|
||||
communityData = new SubscribedSubredditData(subredditData);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
loadSubredditIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -298,40 +328,12 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (subredditIsUser) {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, communityData.getQualified_name());
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
flairTextView.setOnClickListener(view -> {
|
||||
if (flair == null) {
|
||||
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
flairSelectionBottomSheetFragment.setArguments(bundle);
|
||||
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
|
||||
} else {
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
});
|
||||
|
||||
spoilerTextView.setOnClickListener(view -> {
|
||||
if (!isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
isSpoiler = true;
|
||||
} else {
|
||||
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
isSpoiler = false;
|
||||
}
|
||||
});
|
||||
|
||||
nsfwTextView.setOnClickListener(view -> {
|
||||
if (!isNSFW) {
|
||||
@@ -360,21 +362,46 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
.baseUrl("http://localhost/")
|
||||
.addConverterFactory(ScalarsConverterFactory.create())
|
||||
.build().create(TitleSuggestion.class).getHtml(url).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
titleEditText.setText(response.body().substring(response.body().indexOf("<title>") + 7, response.body().indexOf("</title>")));
|
||||
} else {
|
||||
Toast.makeText(PostLinkActivity.this, R.string.suggest_title_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
titleEditText.setText(response.body().substring(response.body().indexOf("<title>") + 7, response.body().indexOf("</title>")));
|
||||
} else {
|
||||
Toast.makeText(PostLinkActivity.this, R.string.suggest_title_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
Toast.makeText(PostLinkActivity.this, R.string.suggest_title_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
Toast.makeText(PostLinkActivity.this, R.string.suggest_title_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter(
|
||||
mCustomThemeWrapper, new MarkdownBottomBarRecyclerViewAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public void onClick(int item) {
|
||||
MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener(
|
||||
PostLinkActivity.this, contentEditText, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUploadImage() {
|
||||
Utils.hideKeyboard(PostLinkActivity.this);
|
||||
UploadedImagesBottomSheetFragment fragment = new UploadedImagesBottomSheetFragment();
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putParcelableArrayList(UploadedImagesBottomSheetFragment.EXTRA_UPLOADED_IMAGES,
|
||||
uploadedImages);
|
||||
fragment.setArguments(arguments);
|
||||
fragment.show(getSupportFragmentManager(), fragment.getTag());
|
||||
}
|
||||
});
|
||||
|
||||
markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this,
|
||||
LinearLayoutManager.HORIZONTAL, false));
|
||||
markdownBottomBarRecyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void loadCurrentAccount() {
|
||||
@@ -426,8 +453,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
|
||||
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
|
||||
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
nsfwTextView.setTextColor(primaryTextColor);
|
||||
titleEditText.setTextColor(primaryTextColor);
|
||||
titleEditText.setHintTextColor(secondaryTextColor);
|
||||
@@ -439,8 +464,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
rulesButton.setTypeface(typeface);
|
||||
receivePostReplyNotificationsTextView.setTypeface(typeface);
|
||||
flairTextView.setTypeface(typeface);
|
||||
spoilerTextView.setTypeface(typeface);
|
||||
nsfwTextView.setTypeface(typeface);
|
||||
titleEditText.setTypeface(typeface);
|
||||
suggestTitleButton.setTypeface(typeface);
|
||||
@@ -467,10 +490,10 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
private void loadSubredditIcon() {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
|
||||
mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
|
||||
iconUrl = iconImageUrl;
|
||||
displaySubredditIcon();
|
||||
loadSubredditIconSuccessful = true;
|
||||
});
|
||||
iconUrl = iconImageUrl;
|
||||
displaySubredditIcon();
|
||||
loadSubredditIconSuccessful = true;
|
||||
});
|
||||
}
|
||||
|
||||
private void promptAlertDialog(int titleResId, int messageResId) {
|
||||
@@ -541,9 +564,10 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_CONTENT, linkEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_BODY, contentEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_URL, linkEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_LINK);
|
||||
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
|
||||
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
|
||||
@@ -575,6 +599,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
|
||||
@@ -589,22 +614,29 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
communityData = data.getExtras().getParcelable(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
subredditIsUser = false;
|
||||
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
} else if (requestCode == PICK_IMAGE_REQUEST_CODE) {
|
||||
if (data == null) {
|
||||
Toast.makeText(PostLinkActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages);
|
||||
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -618,10 +650,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
this.flair = flair;
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -664,4 +692,37 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadImage() {
|
||||
Intent intent = new Intent();
|
||||
intent.setType("image/*");
|
||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
startActivityForResult(Intent.createChooser(intent,
|
||||
getResources().getString(R.string.select_from_gallery)), PICK_IMAGE_REQUEST_CODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void captureImage() {
|
||||
Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
try {
|
||||
capturedImageUri = FileProvider.getUriForFile(this, "eu.toldi.infinityforlemmy.provider",
|
||||
File.createTempFile("captured_image", ".jpg", getExternalFilesDir(Environment.DIRECTORY_PICTURES)));
|
||||
pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri);
|
||||
startActivityForResult(pictureIntent, CAPTURE_IMAGE_REQUEST_CODE);
|
||||
} catch (IOException ex) {
|
||||
Toast.makeText(this, R.string.error_creating_temp_file, Toast.LENGTH_SHORT).show();
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(this, R.string.no_camera_available, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertImageUrl(UploadedImage uploadedImage) {
|
||||
int start = Math.max(contentEditText.getSelectionStart(), 0);
|
||||
int end = Math.max(contentEditText.getSelectionEnd(), 0);
|
||||
contentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
|
||||
"",
|
||||
0, "![]()".length() + uploadedImage.imageName.length() + uploadedImage.imageUrl.length());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@@ -64,6 +63,9 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitPollPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
@@ -87,6 +89,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
private static final String IS_NSFW_STATE = "INS";
|
||||
|
||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_poll_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@@ -108,10 +111,6 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
MaterialButton rulesButton;
|
||||
@BindView(R.id.divider_1_post_poll_activity)
|
||||
MaterialDivider divider1;
|
||||
@BindView(R.id.flair_custom_text_view_post_poll_activity)
|
||||
CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_poll_activity)
|
||||
CustomTextView spoilerTextView;
|
||||
@BindView(R.id.nsfw_custom_text_view_post_poll_activity)
|
||||
CustomTextView nsfwTextView;
|
||||
@BindView(R.id.receive_post_reply_notifications_linear_layout_post_poll_activity)
|
||||
@@ -173,6 +172,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
private Account selectedAccount;
|
||||
private SubscribedSubredditData communityData;
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
private String iconUrl;
|
||||
@@ -232,6 +232,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||
@@ -257,7 +258,6 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (subredditName != null) {
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if (!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
}
|
||||
@@ -268,17 +268,6 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
mPostingSnackbar.show();
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
if (isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
}
|
||||
if (isNSFW) {
|
||||
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
|
||||
nsfwTextView.setBorderColor(nsfwBackgroundColor);
|
||||
@@ -292,11 +281,25 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
loadSubredditIconSuccessful = false;
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
{
|
||||
communityData = new SubscribedSubredditData(subredditData);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
loadSubredditIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -325,40 +328,12 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (subredditIsUser) {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, communityData.getQualified_name());
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
flairTextView.setOnClickListener(view -> {
|
||||
if (flair == null) {
|
||||
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
flairSelectionBottomSheetFragment.setArguments(bundle);
|
||||
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
|
||||
} else {
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
});
|
||||
|
||||
spoilerTextView.setOnClickListener(view -> {
|
||||
if (!isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
isSpoiler = true;
|
||||
} else {
|
||||
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
isSpoiler = false;
|
||||
}
|
||||
});
|
||||
|
||||
nsfwTextView.setOnClickListener(view -> {
|
||||
if (!isNSFW) {
|
||||
@@ -431,8 +406,6 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
|
||||
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
|
||||
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
nsfwTextView.setTextColor(primaryTextColor);
|
||||
titleEditText.setTextColor(primaryTextColor);
|
||||
titleEditText.setHintTextColor(secondaryTextColor);
|
||||
@@ -481,8 +454,6 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
rulesButton.setTypeface(typeface);
|
||||
receivePostReplyNotificationsTextView.setTypeface(typeface);
|
||||
flairTextView.setTypeface(typeface);
|
||||
spoilerTextView.setTypeface(typeface);
|
||||
nsfwTextView.setTypeface(typeface);
|
||||
titleEditText.setTypeface(typeface);
|
||||
option1TextInputEditText.setTypeface(typeface);
|
||||
@@ -631,7 +602,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_POLL);
|
||||
PollPayload payload = new PollPayload(subredditName, titleEditText.getText().toString(),
|
||||
optionList.toArray(new String[0]), (int) votingLengthSlider.getValue(), isNSFW, isSpoiler, flair, receivePostReplyNotificationsSwitchMaterial.isChecked(),
|
||||
@@ -669,6 +640,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
|
||||
@@ -685,19 +657,16 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
subredditIsUser = false;
|
||||
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
}
|
||||
@@ -706,10 +675,6 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
this.flair = flair;
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,6 @@ import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@@ -69,6 +68,9 @@ import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitTextOrLinkPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
@@ -78,7 +80,6 @@ import retrofit2.Retrofit;
|
||||
|
||||
public class PostTextActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback,
|
||||
UploadImageEnabledActivity, AccountChooserBottomSheetFragment.AccountChooserListener {
|
||||
|
||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||
static final String EXTRA_CONTENT = "EC";
|
||||
|
||||
@@ -98,6 +99,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
private static final int PICK_IMAGE_REQUEST_CODE = 100;
|
||||
private static final int CAPTURE_IMAGE_REQUEST_CODE = 200;
|
||||
private static final int MARKDOWN_PREVIEW_REQUEST_CODE = 300;
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_text_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@@ -119,10 +121,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
MaterialButton rulesButton;
|
||||
@BindView(R.id.divider_1_post_text_activity)
|
||||
MaterialDivider divider1;
|
||||
@BindView(R.id.flair_custom_text_view_post_text_activity)
|
||||
CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_text_activity)
|
||||
CustomTextView spoilerTextView;
|
||||
@BindView(R.id.nsfw_custom_text_view_post_text_activity)
|
||||
CustomTextView nsfwTextView;
|
||||
@BindView(R.id.receive_post_reply_notifications_linear_layout_post_text_activity)
|
||||
@@ -164,6 +162,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
private String mAccessToken;
|
||||
private String iconUrl;
|
||||
private String subredditName;
|
||||
private SubscribedSubredditData communityData;
|
||||
private boolean subredditSelected = false;
|
||||
private boolean subredditIsUser;
|
||||
private boolean loadSubredditIconSuccessful = true;
|
||||
@@ -219,6 +218,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||
@@ -245,7 +245,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (subredditName != null) {
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if (!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
}
|
||||
@@ -256,17 +255,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
mPostingSnackbar.show();
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
if (isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
}
|
||||
if (isNSFW) {
|
||||
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
|
||||
nsfwTextView.setBorderColor(nsfwBackgroundColor);
|
||||
@@ -280,11 +268,25 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
loadSubredditIconSuccessful = false;
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
{
|
||||
communityData = new SubscribedSubredditData(subredditData);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
loadSubredditIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -318,44 +320,12 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (subredditIsUser) {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, communityData.getQualified_name());
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
flairTextView.setOnClickListener(view -> {
|
||||
if (flair == null) {
|
||||
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
if (subredditIsUser) {
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
}
|
||||
flairSelectionBottomSheetFragment.setArguments(bundle);
|
||||
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
|
||||
} else {
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
});
|
||||
|
||||
spoilerTextView.setOnClickListener(view -> {
|
||||
if (!isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
isSpoiler = true;
|
||||
} else {
|
||||
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
isSpoiler = false;
|
||||
}
|
||||
});
|
||||
|
||||
nsfwTextView.setOnClickListener(view -> {
|
||||
if (!isNSFW) {
|
||||
@@ -448,8 +418,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
|
||||
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
|
||||
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
nsfwTextView.setTextColor(primaryTextColor);
|
||||
titleEditText.setTextColor(primaryTextColor);
|
||||
titleEditText.setHintTextColor(secondaryTextColor);
|
||||
@@ -459,8 +427,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
rulesButton.setTypeface(typeface);
|
||||
receivePostReplyNotificationsTextView.setTypeface(typeface);
|
||||
flairTextView.setTypeface(typeface);
|
||||
spoilerTextView.setTypeface(typeface);
|
||||
nsfwTextView.setTypeface(typeface);
|
||||
titleEditText.setTypeface(typeface);
|
||||
}
|
||||
@@ -562,18 +528,12 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
mPostingSnackbar.show();
|
||||
|
||||
String subredditName;
|
||||
if (subredditIsUser) {
|
||||
subredditName = "u_" + subredditNameTextView.getText().toString();
|
||||
} else {
|
||||
subredditName = subredditNameTextView.getText().toString();
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_CONTENT, contentEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_BODY, contentEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_SELF);
|
||||
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
|
||||
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
|
||||
@@ -599,6 +559,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
@Override
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
@@ -617,19 +578,16 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
subredditIsUser = false;
|
||||
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
|
||||
} else if (requestCode == PICK_IMAGE_REQUEST_CODE) {
|
||||
@@ -637,10 +595,10 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
Toast.makeText(PostTextActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages);
|
||||
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
|
||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
|
||||
} else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
|
||||
submitPost(mMenu.findItem(R.id.action_send_post_text_activity));
|
||||
@@ -658,10 +616,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
this.flair = flair;
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -719,8 +673,8 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
int start = Math.max(contentEditText.getSelectionStart(), 0);
|
||||
int end = Math.max(contentEditText.getSelectionEnd(), 0);
|
||||
contentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
|
||||
"[" + uploadedImage.imageName + "](" + uploadedImage.imageUrl + ")",
|
||||
0, "[]()".length() + uploadedImage.imageName.length() + uploadedImage.imageUrl.length());
|
||||
"",
|
||||
0, "![]()".length() + uploadedImage.imageName.length() + uploadedImage.imageUrl.length());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -67,6 +67,9 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitVideoOrGifPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
@@ -92,6 +95,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||
private static final int PICK_VIDEO_REQUEST_CODE = 1;
|
||||
private static final int CAPTURE_VIDEO_REQUEST_CODE = 2;
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_video_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@@ -113,10 +117,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
MaterialButton rulesButton;
|
||||
@BindView(R.id.divider_1_post_video_activity)
|
||||
MaterialDivider divider1;
|
||||
@BindView(R.id.flair_custom_text_view_post_video_activity)
|
||||
CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_video_activity)
|
||||
CustomTextView spoilerTextView;
|
||||
@BindView(R.id.nsfw_custom_text_view_post_video_activity)
|
||||
CustomTextView nsfwTextView;
|
||||
@BindView(R.id.receive_post_reply_notifications_linear_layout_post_video_activity)
|
||||
@@ -168,6 +168,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
private String mAccountName;
|
||||
private String iconUrl;
|
||||
private String subredditName;
|
||||
private SubscribedSubredditData communityData;
|
||||
private boolean subredditSelected = false;
|
||||
private boolean subredditIsUser;
|
||||
private Uri videoUri;
|
||||
@@ -235,6 +236,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
@@ -266,7 +268,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (subredditName != null) {
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if (!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
}
|
||||
@@ -277,17 +278,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
mPostingSnackbar.show();
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
if (isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
}
|
||||
if (isNSFW) {
|
||||
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
|
||||
nsfwTextView.setBorderColor(nsfwBackgroundColor);
|
||||
@@ -301,11 +291,25 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
loadSubredditIconSuccessful = false;
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
{
|
||||
communityData = new SubscribedSubredditData(subredditData);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
loadSubredditIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -341,40 +345,12 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (subredditIsUser) {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, communityData.getQualified_name());
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
flairTextView.setOnClickListener(view -> {
|
||||
if (flair == null) {
|
||||
mFlairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
mFlairSelectionBottomSheetFragment.setArguments(bundle);
|
||||
mFlairSelectionBottomSheetFragment.show(getSupportFragmentManager(), mFlairSelectionBottomSheetFragment.getTag());
|
||||
} else {
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
});
|
||||
|
||||
spoilerTextView.setOnClickListener(view -> {
|
||||
if (!isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
isSpoiler = true;
|
||||
} else {
|
||||
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
isSpoiler = false;
|
||||
}
|
||||
});
|
||||
|
||||
nsfwTextView.setOnClickListener(view -> {
|
||||
if (!isNSFW) {
|
||||
@@ -468,20 +444,17 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
|
||||
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
|
||||
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
nsfwTextView.setTextColor(primaryTextColor);
|
||||
titleEditText.setTextColor(primaryTextColor);
|
||||
titleEditText.setHintTextColor(secondaryTextColor);
|
||||
applyFABTheme(captureFab);
|
||||
applyFABTheme(selectFromLibraryFab);
|
||||
boolean circularFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false);
|
||||
applyFABTheme(captureFab, circularFab);
|
||||
applyFABTheme(selectFromLibraryFab, circularFab);
|
||||
selectAgainTextView.setTextColor(mCustomThemeWrapper.getColorAccent());
|
||||
if (typeface != null) {
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
rulesButton.setTypeface(typeface);
|
||||
receivePostReplyNotificationsTextView.setTypeface(typeface);
|
||||
flairTextView.setTypeface(typeface);
|
||||
spoilerTextView.setTypeface(typeface);
|
||||
nsfwTextView.setTypeface(typeface);
|
||||
titleEditText.setTypeface(typeface);
|
||||
selectAgainTextView.setTypeface(typeface);
|
||||
@@ -589,7 +562,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.setData(videoUri);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
|
||||
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
|
||||
@@ -637,6 +610,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
|
||||
@@ -657,19 +631,16 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (data != null) {
|
||||
subredditName = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getBooleanExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER, false);
|
||||
subredditIsUser = false;
|
||||
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
}
|
||||
@@ -707,10 +678,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
this.flair = flair;
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.content.SharedPreferences;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
@@ -31,7 +30,6 @@ import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.FetchRules;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
@@ -41,6 +39,8 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
|
||||
import eu.toldi.infinityforlemmy.customviews.slidr.widget.SliderPanel;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
@@ -134,26 +134,27 @@ public class RulesActivity extends BaseActivity {
|
||||
|
||||
mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper, sliderPanel);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
FetchRules.fetchRules(mExecutor, new Handler(), mAccessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit, mAccessToken, mSubredditName, new FetchRules.FetchRulesListener() {
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), mSubredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void success(ArrayList<Rule> rules) {
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
if (rules == null || rules.size() == 0) {
|
||||
String description = subredditData.getDescription();
|
||||
if (description == null || description.isEmpty()) {
|
||||
errorTextView.setVisibility(View.VISIBLE);
|
||||
errorTextView.setText(R.string.no_rule);
|
||||
errorTextView.setOnClickListener(view -> {
|
||||
});
|
||||
}
|
||||
ArrayList<Rule> rules = new ArrayList<>();
|
||||
rules.add(new Rule("Rules", description));
|
||||
mAdapter.changeDataset(rules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed() {
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
displayError();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -184,21 +185,24 @@ public class RulesActivity extends BaseActivity {
|
||||
errorTextView.setOnClickListener(view -> {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
errorTextView.setVisibility(View.GONE);
|
||||
FetchRules.fetchRules(mExecutor, new Handler(), mAccessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit, mAccessToken, mSubredditName, new FetchRules.FetchRulesListener() {
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), mSubredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void success(ArrayList<Rule> rules) {
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
if (rules == null || rules.size() == 0) {
|
||||
String description = subredditData.getDescription();
|
||||
if (description == null || description.isEmpty()) {
|
||||
errorTextView.setVisibility(View.VISIBLE);
|
||||
errorTextView.setText(R.string.no_rule);
|
||||
errorTextView.setOnClickListener(view -> {
|
||||
});
|
||||
}
|
||||
ArrayList<Rule> rules = new ArrayList<>();
|
||||
rules.add(new Rule("Rules", description));
|
||||
mAdapter.changeDataset(rules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed() {
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
displayError();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -52,6 +52,7 @@ 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.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
@@ -128,6 +129,8 @@ public class SearchActivity extends BaseActivity {
|
||||
private String query;
|
||||
private String subredditName;
|
||||
|
||||
private SubscribedSubredditData communityData;
|
||||
|
||||
private String communityQualifiedName;
|
||||
private boolean subredditIsUser;
|
||||
private boolean searchOnlySubreddits;
|
||||
@@ -183,7 +186,7 @@ public class SearchActivity extends BaseActivity {
|
||||
subredditNameList.add(subredditData.getName());
|
||||
returnIntent.putStringArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, subredditNameList);
|
||||
} else {
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, subredditData.getName());
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, new SubscribedSubredditData(subredditData));
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, subredditData.getIconUrl());
|
||||
}
|
||||
setResult(Activity.RESULT_OK, returnIntent);
|
||||
@@ -429,8 +432,9 @@ public class SearchActivity extends BaseActivity {
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
subredditName = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
subredditIsUser = data.getBooleanExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER, false);
|
||||
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
|
||||
if (subredditName == null) {
|
||||
subredditNameTextView.setText(R.string.all_communities);
|
||||
@@ -442,9 +446,9 @@ public class SearchActivity extends BaseActivity {
|
||||
if (getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false)) {
|
||||
returnIntent.putStringArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, data.getStringArrayListExtra(SearchSubredditsResultActivity.RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES));
|
||||
} else {
|
||||
String name = data.getStringExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
SubscribedSubredditData communityData = data.getParcelableExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
String iconUrl = data.getStringExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, communityData);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl);
|
||||
}
|
||||
setResult(Activity.RESULT_OK, returnIntent);
|
||||
|
||||
@@ -238,7 +238,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
||||
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
|
||||
applyTabLayoutTheme(tabLayout);
|
||||
applyFABTheme(fab);
|
||||
applyFABTheme(fab, mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
|
||||
}
|
||||
|
||||
private void bindView(Bundle savedInstanceState) {
|
||||
@@ -558,10 +558,6 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
||||
goToUser();
|
||||
break;
|
||||
}
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_RANDOM: {
|
||||
random();
|
||||
break;
|
||||
}
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_HIDE_READ_POSTS: {
|
||||
if (sectionsPagerAdapter != null) {
|
||||
sectionsPagerAdapter.hideReadPosts();
|
||||
@@ -788,7 +784,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
||||
bundle.putString(SubredditListingFragment.EXTRA_QUERY, mQuery);
|
||||
bundle.putBoolean(SubredditListingFragment.EXTRA_IS_GETTING_SUBREDDIT_INFO, false);
|
||||
bundle.putString(SubredditListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(SubredditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
bundle.putString(SubredditListingFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
|
||||
mFragment.setArguments(bundle);
|
||||
return mFragment;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.fragments.SubredditListingFragment;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
|
||||
public class SearchSubredditsResultActivity extends BaseActivity implements ActivityToolbarInterface {
|
||||
@@ -64,6 +66,8 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
|
||||
private String mAccountQualifiedName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
((Infinity) getApplication()).getAppComponent().inject(this);
|
||||
@@ -107,6 +111,7 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
mFragment = new SubredditListingFragment();
|
||||
@@ -114,7 +119,7 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
||||
bundle.putString(SubredditListingFragment.EXTRA_QUERY, query);
|
||||
bundle.putBoolean(SubredditListingFragment.EXTRA_IS_GETTING_SUBREDDIT_INFO, true);
|
||||
bundle.putString(SubredditListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(SubredditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
bundle.putString(SubredditListingFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
|
||||
bundle.putBoolean(SubredditListingFragment.EXTRA_IS_MULTI_SELECTION, getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false));
|
||||
mFragment.setArguments(bundle);
|
||||
} else {
|
||||
@@ -141,10 +146,10 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar);
|
||||
}
|
||||
|
||||
public void getSelectedSubreddit(String name, String iconUrl) {
|
||||
public void getSelectedSubreddit(SubredditData subredditData) {
|
||||
Intent returnIntent = new Intent();
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, new SubscribedSubredditData(subredditData));
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, subredditData.getIconUrl());
|
||||
setResult(Activity.RESULT_OK, returnIntent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ public class SelectedSubredditsAndUsersActivity extends BaseActivity implements
|
||||
protected void applyCustomTheme() {
|
||||
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
|
||||
applyFABTheme(fab);
|
||||
applyFABTheme(fab, mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -64,6 +64,7 @@ import eu.toldi.infinityforlemmy.events.SubmitCrosspostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
@@ -87,6 +88,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
private static final String IS_NSFW_STATE = "INS";
|
||||
|
||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_submit_crosspost_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@@ -159,6 +161,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
private Post post;
|
||||
private String iconUrl;
|
||||
private String subredditName;
|
||||
private SubscribedSubredditData communityData;
|
||||
private boolean subredditSelected = false;
|
||||
private boolean subredditIsUser;
|
||||
private boolean loadSubredditIconSuccessful = true;
|
||||
@@ -212,6 +215,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
@@ -566,12 +570,12 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
|
||||
if (post.isCrosspost()) {
|
||||
intent.putExtra(SubmitPostService.EXTRA_CONTENT, "t3_" + post.getCrosspostParentId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_BODY, "t3_" + post.getCrosspostParentId());
|
||||
} else {
|
||||
intent.putExtra(SubmitPostService.EXTRA_CONTENT, post.getFullName());
|
||||
intent.putExtra(SubmitPostService.EXTRA_BODY, post.getFullName());
|
||||
}
|
||||
intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_CROSSPOST);
|
||||
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
|
||||
@@ -604,6 +608,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
|
||||
@@ -620,10 +625,11 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
subredditIsUser = false;
|
||||
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
@@ -33,7 +32,6 @@ import javax.inject.Named;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.ActivityToolbarInterface;
|
||||
import eu.toldi.infinityforlemmy.AnyAccountAccessTokenAuthenticator;
|
||||
import eu.toldi.infinityforlemmy.FetchSubscribedThing;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
@@ -49,17 +47,12 @@ import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribeduser.SubscribedUserData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.OkHttpClient;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class SubredditSelectionActivity extends BaseActivity implements ActivityToolbarInterface {
|
||||
|
||||
public static final String EXTRA_SPECIFIED_ACCOUNT = "ESA";
|
||||
public static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS";
|
||||
public static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
|
||||
public static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIURL";
|
||||
public static final String EXTRA_RETURN_SUBREDDIT_IS_USER = "ERSIU";
|
||||
public static final String EXTRA_RETURN_COMMUNITY_DATA = "ERCD";
|
||||
|
||||
private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 0;
|
||||
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
|
||||
@@ -77,9 +70,6 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Inject
|
||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
@Inject
|
||||
@Named("default")
|
||||
@@ -142,21 +132,14 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
||||
mAccountName = specifiedAccount.getAccountName();
|
||||
mAccountProfileImageUrl = specifiedAccount.getProfileImageUrl();
|
||||
|
||||
mOauthRetrofit = mOauthRetrofit.newBuilder().client(new OkHttpClient.Builder().authenticator(new AnyAccountAccessTokenAuthenticator(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, specifiedAccount, mCurrentAccountSharedPreferences))
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
|
||||
.build())
|
||||
.build();
|
||||
} else {
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
|
||||
}
|
||||
} else {
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
|
||||
}
|
||||
|
||||
@@ -198,6 +181,7 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
||||
mFragment = new SubscribedSubredditsListingFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_QUALIFIED_NAME, mAccountName);
|
||||
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_PROFILE_IMAGE_URL, mAccountProfileImageUrl);
|
||||
bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_IS_SUBREDDIT_SELECTION, true);
|
||||
@@ -262,11 +246,9 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
||||
return false;
|
||||
}
|
||||
|
||||
public void getSelectedSubreddit(String name, String iconUrl, boolean subredditIsUser) {
|
||||
public void getSelectedSubreddit(SubscribedSubredditData communityData) {
|
||||
Intent returnIntent = new Intent();
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_IS_USER, subredditIsUser);
|
||||
returnIntent.putExtra(EXTRA_RETURN_COMMUNITY_DATA, communityData);
|
||||
setResult(Activity.RESULT_OK, returnIntent);
|
||||
finish();
|
||||
}
|
||||
@@ -275,13 +257,13 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
if (requestCode == SUBREDDIT_SEARCH_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
String name = data.getStringExtra(SearchActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
String iconUrl = data.getStringExtra(SearchActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
|
||||
SubscribedSubredditData communityData = data.getParcelableExtra(SearchActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
String iconUrl = communityData.getIconUrl();
|
||||
Intent returnIntent = new Intent();
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_IS_USER, false);
|
||||
returnIntent.putExtra(EXTRA_RETURN_COMMUNITY_DATA, communityData);
|
||||
setResult(Activity.RESULT_OK, returnIntent);
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
||||
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
|
||||
applyTabLayoutTheme(tabLayout);
|
||||
applyFABTheme(fab);
|
||||
applyFABTheme(fab, mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
|
||||
searchEditText.setTextColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
|
||||
searchEditText.setHintTextColor(mCustomThemeWrapper.getToolbarSecondaryTextColor());
|
||||
}
|
||||
@@ -233,7 +233,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
||||
});
|
||||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
viewPager.setAdapter(sectionsPagerAdapter);
|
||||
viewPager.setOffscreenPageLimit(3);
|
||||
viewPager.setOffscreenPageLimit(1);
|
||||
if (viewPager.getCurrentItem() != 2) {
|
||||
fab.hide();
|
||||
}
|
||||
@@ -358,7 +358,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
||||
}
|
||||
|
||||
if (!(!forceLoad && mInsertMultiredditSuccess)) {
|
||||
loadMultiReddits();
|
||||
//loadMultiReddits();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,7 +412,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
||||
public void success() {
|
||||
Toast.makeText(SubscribedThingListingActivity.this,
|
||||
R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show();
|
||||
loadMultiReddits();
|
||||
//loadMultiReddits();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -439,7 +439,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
||||
|
||||
@Subscribe
|
||||
public void onRefreshMultiRedditsEvent(RefreshMultiRedditsEvent event) {
|
||||
loadMultiReddits();
|
||||
//loadMultiReddits();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -477,6 +477,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,28 +488,12 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
case 1: {
|
||||
FollowedUsersListingFragment fragment = new FollowedUsersListingFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FollowedUsersListingFragment.EXTRA_ACCOUNT_NAME, mAccountName == null ? "-" : mAccountName);
|
||||
bundle.putString(FollowedUsersListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
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 ? "-" : mAccountName);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 3;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -67,6 +67,7 @@ import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.fragments.PostFragment;
|
||||
import eu.toldi.infinityforlemmy.multireddit.DeleteMultiReddit;
|
||||
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
|
||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
@@ -131,8 +132,11 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
@Inject
|
||||
MarkPostAsRead markPostAsRead;
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
private String mAccountQualifiedName;
|
||||
private String multiPath;
|
||||
private Fragment mFragment;
|
||||
private int fabOption;
|
||||
@@ -221,6 +225,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
@@ -848,7 +853,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
||||
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar);
|
||||
navigationWrapper.applyCustomTheme(mCustomThemeWrapper.getBottomAppBarIconColor(), mCustomThemeWrapper.getBottomAppBarBackgroundColor());
|
||||
applyFABTheme(navigationWrapper.floatingActionButton);
|
||||
applyFABTheme(navigationWrapper.floatingActionButton, mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -868,7 +873,17 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||
markPostAsRead.markPostAsRead(post.getId(), mAccessToken, new MarkPostAsRead.MarkPostAsReadListener() {
|
||||
@Override
|
||||
public void onMarkPostAsReadSuccess() {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkPostAsReadFailed() {
|
||||
Toast.makeText(ViewMultiRedditDetailActivity.this, R.string.mark_post_as_read_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -931,10 +946,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
|
||||
goToUser();
|
||||
break;
|
||||
}
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_RANDOM: {
|
||||
random();
|
||||
break;
|
||||
}
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_HIDE_READ_POSTS: {
|
||||
if (mFragment instanceof PostFragment) {
|
||||
((PostFragment) mFragment).hideReadPosts();
|
||||
|
||||
@@ -63,6 +63,7 @@ import eu.toldi.infinityforlemmy.LoadingMorePostsStatus;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.SaveComment;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.SortType;
|
||||
import eu.toldi.infinityforlemmy.SortTypeSelectionCallback;
|
||||
@@ -94,6 +95,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
public static final String EXTRA_POST_ID = "EPI";
|
||||
public static final String EXTRA_POST_LIST_POSITION = "EPLP";
|
||||
public static final String EXTRA_SINGLE_COMMENT_ID = "ESCI";
|
||||
public static final String EXTRA_SINGLE_COMMENT_PARENT_ID = "ESCPI";
|
||||
public static final String EXTRA_CONTEXT_NUMBER = "ECN";
|
||||
public static final String EXTRA_MESSAGE_FULLNAME = "ENI";
|
||||
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
|
||||
@@ -334,7 +336,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
protected void applyCustomTheme() {
|
||||
mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(mAppBarLayout, mCollapsingToolbarLayout, mToolbar);
|
||||
applyFABTheme(fab);
|
||||
applyFABTheme(fab, mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
|
||||
searchPanelMaterialCardView.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimary()));
|
||||
int searchPanelTextAndIconColor = mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor();
|
||||
searchTextInputLayout.setBoxStrokeColor(searchPanelTextAndIconColor);
|
||||
@@ -424,11 +426,11 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
}
|
||||
|
||||
|
||||
public void deleteComment(String fullName, int position) {
|
||||
public void deleteComment(int comment_id, int position) {
|
||||
if (sectionsPagerAdapter != null) {
|
||||
ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment();
|
||||
if (fragment != null) {
|
||||
fragment.deleteComment(fullName, position);
|
||||
fragment.deleteComment(comment_id, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -443,9 +445,10 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
}
|
||||
|
||||
public void saveComment(@NonNull Comment comment, int position) {
|
||||
SaveComment saveComment = new SaveComment();
|
||||
if (comment.isSaved()) {
|
||||
comment.setSaved(false);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
saveComment.unsaveThing(mOauthRetrofit, mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment();
|
||||
@@ -466,7 +469,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
});
|
||||
} else {
|
||||
comment.setSaved(true);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
saveComment.saveThing(mRetrofit.getRetrofit(), mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment();
|
||||
@@ -867,7 +870,8 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
if (postListPosition == position && post != null) {
|
||||
bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, post);
|
||||
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, position);
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getStringExtra(EXTRA_SINGLE_COMMENT_ID));
|
||||
bundle.putInt(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getIntExtra(EXTRA_SINGLE_COMMENT_ID, 0));
|
||||
bundle.putInt(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_PARENT_ID, getIntent().getIntExtra(EXTRA_SINGLE_COMMENT_PARENT_ID, 0));
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_CONTEXT_NUMBER, getIntent().getStringExtra(EXTRA_CONTEXT_NUMBER));
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME));
|
||||
} else {
|
||||
@@ -883,12 +887,13 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
}
|
||||
} else {
|
||||
if (post == null) {
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_POST_ID, getIntent().getStringExtra(EXTRA_POST_ID));
|
||||
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_ID, getIntent().getIntExtra(EXTRA_POST_ID, 0));
|
||||
} else {
|
||||
bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, post);
|
||||
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, postListPosition);
|
||||
}
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getStringExtra(EXTRA_SINGLE_COMMENT_ID));
|
||||
bundle.putInt(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getIntExtra(EXTRA_SINGLE_COMMENT_ID, 0));
|
||||
bundle.putInt(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_PARENT_ID, getIntent().getIntExtra(EXTRA_SINGLE_COMMENT_PARENT_ID, 0));
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_CONTEXT_NUMBER, getIntent().getStringExtra(EXTRA_CONTEXT_NUMBER));
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME));
|
||||
}
|
||||
|
||||
@@ -229,13 +229,15 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
||||
}
|
||||
if (fullnames.length() > 0) {
|
||||
fullnames.deleteCharAt(fullnames.length() - 1);
|
||||
ReadMessage.readMessage(mOauthRetrofit, mAccessToken, fullnames.toString(),
|
||||
ReadMessage.readMessage(mOauthRetrofit, mAccessToken, 0,
|
||||
new ReadMessage.ReadMessageListener() {
|
||||
@Override
|
||||
public void readSuccess() {}
|
||||
public void readSuccess() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFailed() {}
|
||||
public void readFailed() {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -332,7 +334,7 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
||||
|
||||
@Subscribe
|
||||
public void onPassPrivateMessageEvent(PassPrivateMessageEvent passPrivateMessageEvent) {
|
||||
privateMessage = passPrivateMessageEvent.message;
|
||||
/* privateMessage = passPrivateMessageEvent.message;
|
||||
if (privateMessage != null) {
|
||||
if (privateMessage.getAuthor().equals(mAccountName)) {
|
||||
if (privateMessage.getReplies() != null) {
|
||||
@@ -351,7 +353,7 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
||||
}
|
||||
|
||||
bindView();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public interface ProvideUserAvatarCallback {
|
||||
|
||||
@@ -93,13 +93,14 @@ import eu.toldi.infinityforlemmy.fragments.SidebarFragment;
|
||||
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
|
||||
import eu.toldi.infinityforlemmy.message.ReadMessage;
|
||||
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
|
||||
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.subreddit.CommunitySubscription;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditSubscription;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditViewModel;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
@@ -116,7 +117,6 @@ import pl.droidsonroids.gif.GifImageView;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class ViewSubredditDetailActivity extends BaseActivity implements SortTypeSelectionCallback,
|
||||
PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback,
|
||||
@@ -174,9 +174,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Inject
|
||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
@Inject
|
||||
@Named("default")
|
||||
@@ -200,6 +197,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
@Inject
|
||||
MarkPostAsRead markPostAsRead;
|
||||
|
||||
private FragmentManager fragmentManager;
|
||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||
private NavigationWrapper navigationWrapper;
|
||||
@@ -207,7 +207,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
private String mAccountQualifiedName;
|
||||
private String subredditName;
|
||||
private String communityName;
|
||||
|
||||
private int communityId;
|
||||
private String description;
|
||||
|
||||
private String qualifiedName;
|
||||
@@ -219,7 +221,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
private boolean hideFab;
|
||||
private boolean showBottomAppBar;
|
||||
private boolean lockBottomAppBar;
|
||||
private String mMessageFullname;
|
||||
private int mMessageFullname;
|
||||
private String mNewAccountName;
|
||||
private RequestManager glide;
|
||||
private int expandedTabTextColor;
|
||||
@@ -340,8 +342,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false);
|
||||
hideSubredditDescription = mSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_DESCRIPTION, false);
|
||||
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME_KEY);
|
||||
qualifiedName = getIntent().getStringExtra(EXTRA_COMMUNITY_FULL_NAME_KEY);
|
||||
communityName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME_KEY);
|
||||
qualifiedName = getIntent().getStringExtra(EXTRA_COMMUNITY_FULL_NAME_KEY);
|
||||
|
||||
fragmentManager = getSupportFragmentManager();
|
||||
|
||||
@@ -350,12 +352,12 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME);
|
||||
mMessageFullname = getIntent().getIntExtra(EXTRA_MESSAGE_FULLNAME, 0);
|
||||
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
|
||||
} else {
|
||||
mFetchSubredditInfoSuccess = savedInstanceState.getBoolean(FETCH_SUBREDDIT_INFO_STATE);
|
||||
mNCurrentOnlineSubscribers = savedInstanceState.getInt(CURRENT_ONLINE_SUBSCRIBERS_STATE);
|
||||
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
|
||||
mMessageFullname = savedInstanceState.getInt(MESSAGE_FULLNAME_STATE);
|
||||
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
|
||||
|
||||
if (mFetchSubredditInfoSuccess) {
|
||||
@@ -366,7 +368,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
checkNewAccountAndBindView();
|
||||
|
||||
fetchSubredditData();
|
||||
if (subredditName != null) {
|
||||
if (communityName != null) {
|
||||
setupVisibleElements();
|
||||
}
|
||||
}
|
||||
@@ -418,7 +420,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
descriptionTextView.setTextColor(primaryTextColor);
|
||||
navigationWrapper.applyCustomTheme(mCustomThemeWrapper.getBottomAppBarIconColor(), mCustomThemeWrapper.getBottomAppBarBackgroundColor());
|
||||
applyTabLayoutTheme(tabLayout);
|
||||
applyFABTheme(navigationWrapper.floatingActionButton);
|
||||
applyFABTheme(navigationWrapper.floatingActionButton, mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
|
||||
if (typeface != null) {
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
subscribeSubredditChip.setTypeface(typeface);
|
||||
@@ -457,10 +459,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
}
|
||||
|
||||
private void setupVisibleElements() {
|
||||
subredditNameTextView.setText(subredditName);
|
||||
subredditNameTextView.setText(communityName);
|
||||
communityFullNameTextView.setText(qualifiedName);
|
||||
|
||||
toolbar.setTitle(subredditName);
|
||||
toolbar.setTitle(communityName);
|
||||
setSupportActionBar(toolbar);
|
||||
setToolbarGoToTop(toolbar);
|
||||
|
||||
@@ -514,8 +516,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
bannerImageView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageOrGifActivity.class);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, subredditData.getBannerUrl());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, subredditName + "-banner.jpg");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, subredditName);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, communityName + "-banner.jpg");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, communityName);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
@@ -534,14 +536,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
iconGifImageView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageOrGifActivity.class);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, subredditData.getIconUrl());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, subredditName + "-icon.jpg");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, subredditName);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, communityName + "-icon.jpg");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, communityName);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
String subredditFullName = subredditData.getTitle();
|
||||
if (!subredditName.equals(subredditFullName)) {
|
||||
if (!communityName.equals(subredditFullName)) {
|
||||
getSupportActionBar().setTitle(subredditFullName);
|
||||
}
|
||||
subredditNameTextView.setText(subredditFullName);
|
||||
@@ -552,12 +554,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
creationTimeTextView.setText(subredditData.getCreatedUTC());
|
||||
description = subredditData.getDescription();
|
||||
|
||||
if (hideSubredditDescription || description.equals("")) {
|
||||
descriptionTextView.setVisibility(View.GONE);
|
||||
} else {
|
||||
descriptionTextView.setVisibility(View.VISIBLE);
|
||||
markwon.setMarkdown(descriptionTextView, description);
|
||||
}
|
||||
|
||||
descriptionTextView.setVisibility(View.GONE);
|
||||
|
||||
|
||||
if (subredditData.isNSFW()) {
|
||||
if (nsfwWarningBuilder == null
|
||||
@@ -577,21 +576,130 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
});
|
||||
}
|
||||
|
||||
private void setupSubscribeChip() {
|
||||
subscribeSubredditChip.setOnClickListener(view -> {
|
||||
if (mAccessToken == null) {
|
||||
if (subscriptionReady) {
|
||||
subscriptionReady = false;
|
||||
if (getResources().getString(R.string.subscribe).contentEquals(subscribeSubredditChip.getText())) {
|
||||
CommunitySubscription.anonymousSubscribeToSubreddit(mExecutor, new Handler(),
|
||||
mRetrofit.getRetrofit(), mRedditDataRoomDatabase, qualifiedName,
|
||||
new CommunitySubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
|
||||
makeSnackbar(R.string.subscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.subscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
CommunitySubscription.anonymousUnsubscribeToSubreddit(mExecutor, new Handler(),
|
||||
mRedditDataRoomDatabase, qualifiedName,
|
||||
new CommunitySubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.subscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
|
||||
makeSnackbar(R.string.unsubscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.unsubscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (subscriptionReady) {
|
||||
subscriptionReady = false;
|
||||
if (getResources().getString(R.string.subscribe).contentEquals(subscribeSubredditChip.getText())) {
|
||||
CommunitySubscription.subscribeToCommunity(mExecutor, new Handler(),
|
||||
mRetrofit.getRetrofit(), mAccessToken, communityId, qualifiedName, mAccountQualifiedName, mRedditDataRoomDatabase,
|
||||
new CommunitySubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
|
||||
makeSnackbar(R.string.subscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.subscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
CommunitySubscription.unsubscribeToCommunity(mExecutor, new Handler(),
|
||||
mRetrofit.getRetrofit(), mAccessToken, communityId, qualifiedName, mAccountName, mRedditDataRoomDatabase,
|
||||
new CommunitySubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.subscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
|
||||
makeSnackbar(R.string.unsubscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.unsubscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
CheckIsSubscribedToSubreddit.checkIsSubscribedToSubreddit(mExecutor, new Handler(),
|
||||
mRedditDataRoomDatabase, qualifiedName, mAccountQualifiedName,
|
||||
new CheckIsSubscribedToSubreddit.CheckIsSubscribedToSubredditListener() {
|
||||
@Override
|
||||
public void isSubscribed() {
|
||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isNotSubscribed() {
|
||||
subscribeSubredditChip.setText(R.string.subscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void fetchSubredditData() {
|
||||
if (!mFetchSubredditInfoSuccess) {
|
||||
FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit.getRetrofit(), qualifiedName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), qualifiedName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
qualifiedName = LemmyUtils.actorID2FullName(subredditData.getActorId());
|
||||
if (subredditName == null) {
|
||||
subredditName = subredditData.getTitle();
|
||||
public void onFetchSubredditDataSuccess(SubredditData communityData, int nCurrentOnlineSubscribers) {
|
||||
qualifiedName = LemmyUtils.actorID2FullName(communityData.getActorId());
|
||||
if (communityName == null) {
|
||||
communityName = communityData.getTitle();
|
||||
|
||||
setupVisibleElements();
|
||||
}
|
||||
communityId = communityData.getId();
|
||||
setupSubscribeChip();
|
||||
|
||||
mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers;
|
||||
nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers));
|
||||
InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||
subredditData, () -> mFetchSubredditInfoSuccess = true);
|
||||
communityData, () -> mFetchSubredditInfoSuccess = true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -648,7 +756,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
}
|
||||
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SEARCH: {
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
@@ -761,11 +869,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
}
|
||||
|
||||
private void bindView() {
|
||||
if (mMessageFullname != null) {
|
||||
ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
|
||||
if (mMessageFullname != 0) {
|
||||
ReadMessage.readMessage(mRetrofit.getRetrofit(), mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
|
||||
@Override
|
||||
public void readSuccess() {
|
||||
mMessageFullname = null;
|
||||
mMessageFullname = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -920,7 +1028,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
}
|
||||
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH: {
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
@@ -964,109 +1072,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
});
|
||||
navigationWrapper.floatingActionButton.setVisibility(hideFab ? View.GONE : View.VISIBLE);
|
||||
|
||||
subscribeSubredditChip.setOnClickListener(view -> {
|
||||
if (mAccessToken == null) {
|
||||
if (subscriptionReady) {
|
||||
subscriptionReady = false;
|
||||
if (getResources().getString(R.string.subscribe).contentEquals(subscribeSubredditChip.getText())) {
|
||||
SubredditSubscription.anonymousSubscribeToSubreddit(mExecutor, new Handler(),
|
||||
mRetrofit.getRetrofit(), mRedditDataRoomDatabase, subredditName,
|
||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
|
||||
makeSnackbar(R.string.subscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.subscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
SubredditSubscription.anonymousUnsubscribeToSubreddit(mExecutor, new Handler(),
|
||||
mRedditDataRoomDatabase, subredditName,
|
||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.subscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
|
||||
makeSnackbar(R.string.unsubscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.unsubscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (subscriptionReady) {
|
||||
subscriptionReady = false;
|
||||
if (getResources().getString(R.string.subscribe).contentEquals(subscribeSubredditChip.getText())) {
|
||||
SubredditSubscription.subscribeToSubreddit(mExecutor, new Handler(), mOauthRetrofit,
|
||||
mRetrofit.getRetrofit(), mAccessToken, subredditName, mAccountName, mRedditDataRoomDatabase,
|
||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
|
||||
makeSnackbar(R.string.subscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.subscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
SubredditSubscription.unsubscribeToSubreddit(mExecutor, new Handler(), mOauthRetrofit,
|
||||
mAccessToken, subredditName, mAccountName, mRedditDataRoomDatabase,
|
||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.subscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
|
||||
makeSnackbar(R.string.unsubscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.unsubscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
CheckIsSubscribedToSubreddit.checkIsSubscribedToSubreddit(mExecutor, new Handler(),
|
||||
mRedditDataRoomDatabase, qualifiedName, mAccountQualifiedName,
|
||||
new CheckIsSubscribedToSubreddit.CheckIsSubscribedToSubredditListener() {
|
||||
@Override
|
||||
public void isSubscribed() {
|
||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isNotSubscribed() {
|
||||
subscribeSubredditChip.setText(R.string.subscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
|
||||
sectionsPagerAdapter = new SectionsPagerAdapter(this);
|
||||
viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
||||
@@ -1133,7 +1138,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
return true;
|
||||
} else if (itemId == R.id.action_search_view_subreddit_detail_activity) {
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
intent.putExtra(SearchActivity.EXTRA_COMMUNITY_FULL_NAME, qualifiedName);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
@@ -1152,7 +1157,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
return true;
|
||||
}
|
||||
Intent selectUserFlairIntent = new Intent(this, SelectUserFlairActivity.class);
|
||||
selectUserFlairIntent.putExtra(SelectUserFlairActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
selectUserFlairIntent.putExtra(SelectUserFlairActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(selectUserFlairIntent);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_add_to_multireddit_view_subreddit_detail_activity) {
|
||||
@@ -1164,13 +1169,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
startActivityForResult(intent, ADD_TO_MULTIREDDIT_REQUEST_CODE);
|
||||
} else if (itemId == R.id.action_add_to_post_filter_view_subreddit_detail_activity) {
|
||||
Intent intent = new Intent(this, PostFilterPreferenceActivity.class);
|
||||
intent.putExtra(PostFilterPreferenceActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostFilterPreferenceActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_share_view_subreddit_detail_activity) {
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.setType("text/plain");
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, qualifiedName);
|
||||
String baseURL = mRetrofit.getBaseURL().endsWith("/") ? mRetrofit.getBaseURL() : mRetrofit.getBaseURL() + "/";
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, baseURL + "/" + qualifiedName);
|
||||
if (shareIntent.resolveActivity(getPackageManager()) != null) {
|
||||
startActivity(Intent.createChooser(shareIntent, getString(R.string.share)));
|
||||
} else {
|
||||
@@ -1179,13 +1185,13 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
return true;
|
||||
} else if (itemId == R.id.action_go_to_wiki_view_subreddit_detail_activity) {
|
||||
Intent wikiIntent = new Intent(this, WikiActivity.class);
|
||||
wikiIntent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
wikiIntent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
wikiIntent.putExtra(WikiActivity.EXTRA_WIKI_PATH, "index");
|
||||
startActivity(wikiIntent);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_contact_mods_view_subreddit_detail_activity) {
|
||||
Intent intent = new Intent(this, SendPrivateMessageActivity.class);
|
||||
intent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, "r/" + subredditName);
|
||||
intent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, "r/" + communityName);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
@@ -1199,19 +1205,19 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
if (data != null) {
|
||||
MultiReddit multiReddit = data.getParcelableExtra(MultiredditSelectionActivity.EXTRA_RETURN_MULTIREDDIT);
|
||||
if (multiReddit != null) {
|
||||
AddSubredditOrUserToMultiReddit.addSubredditOrUserToMultiReddit(mOauthRetrofit,
|
||||
mAccessToken, multiReddit.getPath(), subredditName,
|
||||
AddSubredditOrUserToMultiReddit.addSubredditOrUserToMultiReddit(mRetrofit.getRetrofit(),
|
||||
mAccessToken, multiReddit.getPath(), communityName,
|
||||
new AddSubredditOrUserToMultiReddit.AddSubredditOrUserToMultiRedditListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
Toast.makeText(ViewSubredditDetailActivity.this,
|
||||
getString(R.string.add_community_or_user_to_multireddit_success, subredditName, multiReddit.getDisplayName()), Toast.LENGTH_LONG).show();
|
||||
getString(R.string.add_community_or_user_to_multireddit_success, communityName, multiReddit.getDisplayName()), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(int code) {
|
||||
Toast.makeText(ViewSubredditDetailActivity.this,
|
||||
getString(R.string.add_community_or_user_to_multireddit_failed, subredditName, multiReddit.getDisplayName()), Toast.LENGTH_LONG).show();
|
||||
getString(R.string.add_community_or_user_to_multireddit_failed, communityName, multiReddit.getDisplayName()), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1225,7 +1231,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(FETCH_SUBREDDIT_INFO_STATE, mFetchSubredditInfoSuccess);
|
||||
outState.putInt(CURRENT_ONLINE_SUBSCRIBERS_STATE, mNCurrentOnlineSubscribers);
|
||||
outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
|
||||
outState.putInt(MESSAGE_FULLNAME_STATE, mMessageFullname);
|
||||
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
||||
}
|
||||
|
||||
@@ -1274,39 +1280,39 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
switch (postType) {
|
||||
case PostTypeBottomSheetFragment.TYPE_TEXT:
|
||||
intent = new Intent(this, PostTextActivity.class);
|
||||
intent.putExtra(PostTextActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostTextActivity.EXTRA_SUBREDDIT_NAME, qualifiedName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case PostTypeBottomSheetFragment.TYPE_LINK:
|
||||
intent = new Intent(this, PostLinkActivity.class);
|
||||
intent.putExtra(PostLinkActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostLinkActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case PostTypeBottomSheetFragment.TYPE_IMAGE:
|
||||
intent = new Intent(this, PostImageActivity.class);
|
||||
intent.putExtra(PostImageActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostImageActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case PostTypeBottomSheetFragment.TYPE_VIDEO:
|
||||
intent = new Intent(this, PostVideoActivity.class);
|
||||
intent.putExtra(PostVideoActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostVideoActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case PostTypeBottomSheetFragment.TYPE_GALLERY:
|
||||
intent = new Intent(this, PostGalleryActivity.class);
|
||||
intent.putExtra(PostGalleryActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostGalleryActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case PostTypeBottomSheetFragment.TYPE_POLL:
|
||||
intent = new Intent(this, PostPollActivity.class);
|
||||
intent.putExtra(PostPollActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostPollActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postLayoutSelected(int postLayout) {
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, postLayout).apply();
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + communityName, postLayout).apply();
|
||||
sectionsPagerAdapter.changePostLayout(postLayout);
|
||||
}
|
||||
|
||||
@@ -1382,7 +1388,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
break;
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SEARCH:
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_GO_TO_SUBREDDIT: {
|
||||
@@ -1393,10 +1399,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
goToUser();
|
||||
break;
|
||||
}
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_RANDOM: {
|
||||
random();
|
||||
break;
|
||||
}
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_HIDE_READ_POSTS: {
|
||||
if (sectionsPagerAdapter != null) {
|
||||
sectionsPagerAdapter.hideReadPosts();
|
||||
@@ -1460,7 +1462,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
if (subredditAutocompleteCall != null) {
|
||||
subredditAutocompleteCall.cancel();
|
||||
}
|
||||
subredditAutocompleteCall = mOauthRetrofit.create(RedditAPI.class).subredditAutocomplete(APIUtils.getOAuthHeader(mAccessToken),
|
||||
subredditAutocompleteCall = mRetrofit.getRetrofit().create(RedditAPI.class).subredditAutocomplete(APIUtils.getOAuthHeader(mAccessToken),
|
||||
editable.toString(), nsfw);
|
||||
subredditAutocompleteCall.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
@@ -1557,7 +1559,18 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||
markPostAsRead.markPostAsRead(post.getId(), mAccessToken, new MarkPostAsRead.MarkPostAsReadListener() {
|
||||
@Override
|
||||
public void onMarkPostAsReadSuccess() {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkPostAsReadFailed() {
|
||||
Toast.makeText(ViewSubredditDetailActivity.this, R.string.mark_post_as_read_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1596,7 +1609,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
SidebarFragment fragment = new SidebarFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(SidebarFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(SidebarFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
bundle.putString(SidebarFragment.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
bundle.putString(SidebarFragment.EXTRA_COMMUNITY_QUALIFIED_NAME, qualifiedName);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
|
||||
@@ -95,6 +95,7 @@ import eu.toldi.infinityforlemmy.fragments.PostFragment;
|
||||
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
|
||||
import eu.toldi.infinityforlemmy.message.ReadMessage;
|
||||
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
|
||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
@@ -202,6 +203,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
|
||||
@Inject
|
||||
MarkPostAsRead markPostAsRead;
|
||||
public UserViewModel userViewModel;
|
||||
private FragmentManager fragmentManager;
|
||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||
@@ -210,6 +214,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
private Call<String> subredditAutocompleteCall;
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
private String mAccountQualifiedName;
|
||||
private String username;
|
||||
private String qualifiedName;
|
||||
private String description;
|
||||
@@ -228,7 +233,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
private boolean hideFab;
|
||||
private boolean showBottomAppBar;
|
||||
private boolean lockBottomAppBar;
|
||||
private String mMessageFullname;
|
||||
private int mMessageId;
|
||||
private String mNewAccountName;
|
||||
|
||||
private UserData mUserData;
|
||||
@@ -272,15 +277,16 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false);
|
||||
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME);
|
||||
mMessageId = getIntent().getIntExtra(EXTRA_MESSAGE_FULLNAME, 0);
|
||||
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
|
||||
} else {
|
||||
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
|
||||
mMessageFullname = savedInstanceState.getString(MESSAGE_FULLNAME_STATE);
|
||||
mMessageId = savedInstanceState.getInt(MESSAGE_FULLNAME_STATE);
|
||||
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
|
||||
}
|
||||
|
||||
@@ -625,7 +631,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
karmaTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
|
||||
cakedayTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
|
||||
navigationWrapper.applyCustomTheme(mCustomThemeWrapper.getBottomAppBarIconColor(), mCustomThemeWrapper.getBottomAppBarBackgroundColor());
|
||||
applyFABTheme(navigationWrapper.floatingActionButton);
|
||||
applyFABTheme(navigationWrapper.floatingActionButton, mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_CIRCULAR_FAB, false));
|
||||
descriptionTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
|
||||
subscribeUserChip.setTextColor(mCustomThemeWrapper.getChipTextColor());
|
||||
applyTabLayoutTheme(tabLayout);
|
||||
@@ -700,11 +706,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
|
||||
fixViewPager2Sensitivity(viewPager2);
|
||||
|
||||
if (mMessageFullname != null) {
|
||||
ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
|
||||
if (mMessageId != 0) {
|
||||
ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageId, new ReadMessage.ReadMessageListener() {
|
||||
@Override
|
||||
public void readSuccess() {
|
||||
mMessageFullname = null;
|
||||
mMessageId = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1092,12 +1098,12 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteComment(String fullName) {
|
||||
public void deleteComment(int commentId) {
|
||||
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
|
||||
.setTitle(R.string.delete_this_comment)
|
||||
.setMessage(R.string.are_you_sure)
|
||||
.setPositiveButton(R.string.delete, (dialogInterface, i)
|
||||
-> DeleteThing.delete(mOauthRetrofit, fullName, mAccessToken, new DeleteThing.DeleteThingListener() {
|
||||
-> DeleteThing.deleteComment(mRetrofit.getRetrofit(), commentId, mAccessToken, new DeleteThing.DeleteThingListener() {
|
||||
@Override
|
||||
public void deleteSuccess() {
|
||||
Toast.makeText(ViewUserDetailActivity.this, R.string.delete_post_success, Toast.LENGTH_SHORT).show();
|
||||
@@ -1154,7 +1160,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
} else if (itemId == R.id.action_share_view_user_detail_activity) {
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.setType("text/plain");
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, "https://www.reddit.com/user/" + username);
|
||||
String baseURL = mRetrofit.getBaseURL().endsWith("/") ? mRetrofit.getBaseURL() : mRetrofit.getBaseURL() + "/";
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, baseURL + qualifiedName);
|
||||
if (shareIntent.resolveActivity(getPackageManager()) != null) {
|
||||
startActivity(Intent.createChooser(shareIntent, getString(R.string.share)));
|
||||
} else {
|
||||
@@ -1261,7 +1268,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess);
|
||||
outState.putString(MESSAGE_FULLNAME_STATE, mMessageFullname);
|
||||
outState.putInt(MESSAGE_FULLNAME_STATE, mMessageId);
|
||||
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
||||
}
|
||||
|
||||
@@ -1334,10 +1341,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
goToUser();
|
||||
break;
|
||||
}
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_RANDOM: {
|
||||
random();
|
||||
break;
|
||||
}
|
||||
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_HIDE_READ_POSTS: {
|
||||
if (sectionsPagerAdapter != null) {
|
||||
sectionsPagerAdapter.hideReadPosts();
|
||||
@@ -1549,7 +1553,17 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
|
||||
@Override
|
||||
public void markPostAsRead(Post post) {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountName, post.getId());
|
||||
markPostAsRead.markPostAsRead(post.getId(), mAccessToken, new MarkPostAsRead.MarkPostAsReadListener() {
|
||||
@Override
|
||||
public void onMarkPostAsReadSuccess() {
|
||||
InsertReadPost.insertReadPost(mRedditDataRoomDatabase, mExecutor, mAccountQualifiedName, post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkPostAsReadFailed() {
|
||||
Toast.makeText(ViewUserDetailActivity.this, R.string.mark_post_as_read_failed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,6 +32,7 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.NetworkState;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.SaveComment;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.VoteThing;
|
||||
import eu.toldi.infinityforlemmy.activities.BaseActivity;
|
||||
@@ -76,7 +77,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
}
|
||||
};
|
||||
private BaseActivity mActivity;
|
||||
private Retrofit mOauthRetrofit;
|
||||
private Retrofit retrofit;
|
||||
private Locale mLocale;
|
||||
private Markwon mMarkwon;
|
||||
private RecyclerView.RecycledViewPool recycledViewPool;
|
||||
@@ -109,7 +110,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
String accountName, RetryLoadingMoreCallback retryLoadingMoreCallback) {
|
||||
super(DIFF_CALLBACK);
|
||||
mActivity = activity;
|
||||
mOauthRetrofit = oauthRetrofit;
|
||||
retrofit = oauthRetrofit;
|
||||
mCommentColor = customThemeWrapper.getCommentColor();
|
||||
int commentSpoilerBackgroundColor = mCommentColor | 0xFF000000;
|
||||
mLocale = locale;
|
||||
@@ -189,7 +190,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
if (holder instanceof CommentViewHolder) {
|
||||
Comment comment = getItem(holder.getBindingAdapterPosition());
|
||||
if (comment != null) {
|
||||
String name = "r/" + comment.getCommunityName();
|
||||
String name = comment.getCommunityQualifiedName();
|
||||
((CommentViewHolder) holder).authorTextView.setText(name);
|
||||
((CommentViewHolder) holder).authorTextView.setTextColor(mSubredditColor);
|
||||
|
||||
@@ -436,6 +437,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
if (comment != null) {
|
||||
Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class);
|
||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, comment.getCommunityName());
|
||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, comment.getCommunityQualifiedName());
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
@@ -468,8 +470,9 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
Comment comment = getItem(getBindingAdapterPosition());
|
||||
if (comment != null) {
|
||||
Intent intent = new Intent(mActivity, ViewPostDetailActivity.class);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getLinkId());
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getPostId());
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId());
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_PARENT_ID, comment.getParentId());
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
@@ -536,7 +539,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
comment.getScore() + comment.getVoteType()));
|
||||
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -606,7 +609,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
comment.getScore() + comment.getVoteType()));
|
||||
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -646,9 +649,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
}
|
||||
Comment comment = getItem(position);
|
||||
if (comment != null) {
|
||||
SaveComment saveComment = new SaveComment();
|
||||
if (comment.isSaved()) {
|
||||
comment.setSaved(false);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
saveComment.unsaveThing(retrofit, mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
comment.setSaved(false);
|
||||
@@ -669,7 +673,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
});
|
||||
} else {
|
||||
comment.setSaved(true);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
saveComment.saveThing(retrofit, mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
comment.setSaved(true);
|
||||
|
||||
@@ -42,6 +42,7 @@ import java.util.concurrent.Executor;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.SaveComment;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.SortType;
|
||||
import eu.toldi.infinityforlemmy.VoteThing;
|
||||
@@ -160,7 +161,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
|
||||
public CommentsRecyclerViewAdapter(BaseActivity activity, ViewPostDetailFragment fragment,
|
||||
CustomThemeWrapper customThemeWrapper,
|
||||
Executor executor, Retrofit retrofit, Retrofit oauthRetrofit,
|
||||
Executor executor, Retrofit retrofit,
|
||||
String accessToken, String accountName,
|
||||
Post post, Locale locale, Integer singleCommentId,
|
||||
boolean isSingleCommentThreadMode,
|
||||
@@ -170,7 +171,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
mFragment = fragment;
|
||||
mExecutor = executor;
|
||||
mRetrofit = retrofit;
|
||||
mOauthRetrofit = oauthRetrofit;
|
||||
mGlide = Glide.with(activity);
|
||||
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
||||
mCommentTextColor = customThemeWrapper.getCommentColor();
|
||||
@@ -391,13 +391,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
}
|
||||
|
||||
if (comment.getAuthorIconUrl() == null) {
|
||||
mFragment.loadIcon(comment.getAuthor(), (authorName, iconUrl) -> {
|
||||
if (authorName.equals(comment.getAuthor())) {
|
||||
mFragment.loadIcon(comment.getAuthorQualifiedName(), (authorName, iconUrl) -> {
|
||||
if (authorName.equals(comment.getAuthorQualifiedName())) {
|
||||
comment.setAuthorIconUrl(iconUrl);
|
||||
}
|
||||
|
||||
Comment currentComment = getCurrentComment(holder);
|
||||
if (currentComment != null && authorName.equals(currentComment.getAuthor())) {
|
||||
if (currentComment != null && authorName.equals(currentComment.getAuthorQualifiedName())) {
|
||||
mGlide.load(iconUrl)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||
@@ -536,13 +536,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
((CommentFullyCollapsedViewHolder) holder).usernameTextView.setText(authorWithPrefix);
|
||||
|
||||
if (comment.getAuthorIconUrl() == null) {
|
||||
mFragment.loadIcon(comment.getAuthor(), (authorName, iconUrl) -> {
|
||||
if (authorName.equals(comment.getAuthor())) {
|
||||
mFragment.loadIcon(comment.getAuthorQualifiedName(), (authorName, iconUrl) -> {
|
||||
if (authorName.equals(comment.getAuthorQualifiedName())) {
|
||||
comment.setAuthorIconUrl(iconUrl);
|
||||
}
|
||||
|
||||
Comment currentComment = getCurrentComment(holder);
|
||||
if (currentComment != null && authorName.equals(currentComment.getAuthor())) {
|
||||
if (currentComment != null && authorName.equals(currentComment.getAuthorQualifiedName())) {
|
||||
mGlide.load(iconUrl)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||
@@ -856,6 +856,16 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
}
|
||||
}
|
||||
|
||||
List<Comment> newComments = new ArrayList<>();
|
||||
for (int i = 0; i < comments.size(); i++) {
|
||||
if (loadedComments.contains(comments.get(i).getId())) {
|
||||
continue;
|
||||
}
|
||||
newComments.add(comments.get(i));
|
||||
loadedComments.add(comments.get(i).getId());
|
||||
}
|
||||
comments = (ArrayList<Comment>) newComments;
|
||||
|
||||
int sizeBefore = mVisibleComments.size();
|
||||
mVisibleComments.addAll(comments);
|
||||
for (int i = 0; i < comments.size(); i++) {
|
||||
@@ -1535,9 +1545,10 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
Comment comment = getCurrentComment(this);
|
||||
if (comment != null) {
|
||||
int position = getBindingAdapterPosition();
|
||||
SaveComment saveComment = new SaveComment();
|
||||
if (comment.isSaved()) {
|
||||
comment.setSaved(false);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
saveComment.unsaveThing(mRetrofit, mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
comment.setSaved(false);
|
||||
@@ -1558,7 +1569,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
});
|
||||
} else {
|
||||
comment.setSaved(true);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
saveComment.saveThing(mRetrofit, mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
comment.setSaved(true);
|
||||
@@ -1913,6 +1924,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
if (mActivity != null && mActivity instanceof ViewPostDetailActivity) {
|
||||
mIsSingleCommentThreadMode = false;
|
||||
mSingleCommentId = null;
|
||||
loadedComments.clear();
|
||||
notifyItemRemoved(0);
|
||||
mFragment.changeToNormalThreadMode();
|
||||
}
|
||||
@@ -1925,4 +1937,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
((TextView) itemView).setTextColor(mColorAccent);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearLoadedComments() {
|
||||
loadedComments.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ import eu.toldi.infinityforlemmy.FetchGfycatOrRedgifsVideoLinks;
|
||||
import eu.toldi.infinityforlemmy.FetchStreamableVideo;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.SaveMemoryCenterInisdeDownsampleStrategy;
|
||||
import eu.toldi.infinityforlemmy.SavePost;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.StreamableVideo;
|
||||
import eu.toldi.infinityforlemmy.VoteThing;
|
||||
@@ -140,7 +141,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
private SharedPreferences mSharedPreferences;
|
||||
private SharedPreferences mCurrentAccountSharedPreferences;
|
||||
private Executor mExecutor;
|
||||
private Retrofit mOauthRetrofit;
|
||||
private Retrofit retrofit;
|
||||
private Retrofit mGfycatRetrofit;
|
||||
private Retrofit mRedgifsRetrofit;
|
||||
private Provider<StreamableAPI> mStreamableApiProvider;
|
||||
@@ -236,7 +237,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
mSharedPreferences = sharedPreferences;
|
||||
mCurrentAccountSharedPreferences = currentAccountSharedPreferences;
|
||||
mExecutor = executor;
|
||||
mOauthRetrofit = oauthRetrofit;
|
||||
retrofit = oauthRetrofit;
|
||||
mGfycatRetrofit = gfycatRetrofit;
|
||||
mRedgifsRetrofit = redgifsRetrofit;
|
||||
mStreamableApiProvider = streambleApiProvider;
|
||||
@@ -2326,7 +2327,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -2418,7 +2419,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -2476,10 +2477,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
SavePost savePost = new SavePost();
|
||||
if (post.isSaved()) {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
savePost.unsaveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -2503,7 +2504,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
});
|
||||
} else {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
savePost.saveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -3652,7 +3653,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -3744,7 +3745,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -3804,9 +3805,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
}
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
SavePost savePost = new SavePost();
|
||||
if (post.isSaved()) {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
savePost.unsaveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -3830,7 +3832,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
});
|
||||
} else {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
savePost.saveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
|
||||
public static final int CODE_BLOCK = 9;
|
||||
public static final int UPLOAD_IMAGE = 10;
|
||||
|
||||
private static final int ITEM_COUNT = 10;
|
||||
private static final int ITEM_COUNT = 11;
|
||||
|
||||
private CustomThemeWrapper customThemeWrapper;
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
@@ -19,24 +19,13 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||
import io.noties.markwon.Markwon;
|
||||
import io.noties.markwon.MarkwonConfiguration;
|
||||
import io.noties.markwon.core.MarkwonTheme;
|
||||
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||
import io.noties.markwon.inlineparser.BangInlineProcessor;
|
||||
import io.noties.markwon.inlineparser.HtmlInlineProcessor;
|
||||
import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin;
|
||||
import io.noties.markwon.linkify.LinkifyPlugin;
|
||||
import io.noties.markwon.movement.MovementMethodPlugin;
|
||||
import eu.toldi.infinityforlemmy.NetworkState;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.activities.BaseActivity;
|
||||
import eu.toldi.infinityforlemmy.activities.LinkResolverActivity;
|
||||
import eu.toldi.infinityforlemmy.activities.ViewPostDetailActivity;
|
||||
import eu.toldi.infinityforlemmy.activities.ViewPrivateMessagesActivity;
|
||||
import eu.toldi.infinityforlemmy.activities.ViewUserDetailActivity;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
@@ -45,28 +34,38 @@ import eu.toldi.infinityforlemmy.markdown.RedditHeadingPlugin;
|
||||
import eu.toldi.infinityforlemmy.markdown.SpoilerAwareMovementMethod;
|
||||
import eu.toldi.infinityforlemmy.markdown.SpoilerParserPlugin;
|
||||
import eu.toldi.infinityforlemmy.markdown.SuperscriptPlugin;
|
||||
import eu.toldi.infinityforlemmy.message.CommentInteraction;
|
||||
import eu.toldi.infinityforlemmy.message.FetchMessage;
|
||||
import eu.toldi.infinityforlemmy.message.Message;
|
||||
import eu.toldi.infinityforlemmy.message.ReadMessage;
|
||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||
import io.noties.markwon.Markwon;
|
||||
import io.noties.markwon.MarkwonConfiguration;
|
||||
import io.noties.markwon.core.MarkwonTheme;
|
||||
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||
import io.noties.markwon.image.glide.GlideImagesPlugin;
|
||||
import io.noties.markwon.inlineparser.HtmlInlineProcessor;
|
||||
import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin;
|
||||
import io.noties.markwon.linkify.LinkifyPlugin;
|
||||
import io.noties.markwon.movement.MovementMethodPlugin;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, RecyclerView.ViewHolder> {
|
||||
public class MessageRecyclerViewAdapter extends PagedListAdapter<CommentInteraction, RecyclerView.ViewHolder> {
|
||||
private static final int VIEW_TYPE_DATA = 0;
|
||||
private static final int VIEW_TYPE_ERROR = 1;
|
||||
private static final int VIEW_TYPE_LOADING = 2;
|
||||
private static final DiffUtil.ItemCallback<Message> DIFF_CALLBACK = new DiffUtil.ItemCallback<>() {
|
||||
private static final DiffUtil.ItemCallback<CommentInteraction> DIFF_CALLBACK = new DiffUtil.ItemCallback<>() {
|
||||
@Override
|
||||
public boolean areItemsTheSame(@NonNull Message message, @NonNull Message t1) {
|
||||
return message.getId().equals(t1.getId());
|
||||
public boolean areItemsTheSame(@NonNull CommentInteraction message, @NonNull CommentInteraction t1) {
|
||||
return message.getComment().getId() == t1.getComment().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(@NonNull Message message, @NonNull Message t1) {
|
||||
return message.getBody().equals(t1.getBody());
|
||||
public boolean areContentsTheSame(@NonNull CommentInteraction message, @NonNull CommentInteraction t1) {
|
||||
return message.getComment().getCommentMarkdown().equals(t1.getComment().getCommentMarkdown());
|
||||
}
|
||||
};
|
||||
private BaseActivity mActivity;
|
||||
private Retrofit mOauthRetrofit;
|
||||
private Retrofit retrofit;
|
||||
private Markwon mMarkwon;
|
||||
private String mAccessToken;
|
||||
private int mMessageType;
|
||||
@@ -88,7 +87,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
||||
RetryLoadingMoreCallback retryLoadingMoreCallback) {
|
||||
super(DIFF_CALLBACK);
|
||||
mActivity = activity;
|
||||
mOauthRetrofit = oauthRetrofit;
|
||||
retrofit = oauthRetrofit;
|
||||
mRetryLoadingMoreCallback = retryLoadingMoreCallback;
|
||||
|
||||
mColorAccent = customThemeWrapper.getColorAccent();
|
||||
@@ -106,7 +105,6 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
||||
mMarkwon = Markwon.builder(mActivity)
|
||||
.usePlugin(MarkwonInlineParserPlugin.create(plugin -> {
|
||||
plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
|
||||
plugin.excludeInlineProcessor(BangInlineProcessor.class);
|
||||
}))
|
||||
.usePlugin(new AbstractMarkwonPlugin() {
|
||||
@Override
|
||||
@@ -130,6 +128,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
||||
.usePlugin(StrikethroughPlugin.create())
|
||||
.usePlugin(MovementMethodPlugin.create(new SpoilerAwareMovementMethod()))
|
||||
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
|
||||
.usePlugin(GlideImagesPlugin.create(mActivity))
|
||||
.build();
|
||||
mAccessToken = accessToken;
|
||||
if (where.equals(FetchMessage.WHERE_MESSAGES)) {
|
||||
@@ -154,41 +153,38 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof DataViewHolder) {
|
||||
Message message = getItem(holder.getBindingAdapterPosition());
|
||||
CommentInteraction message = getItem(holder.getBindingAdapterPosition());
|
||||
if (message != null) {
|
||||
ArrayList<Message> replies = message.getReplies();
|
||||
Message displayedMessage;
|
||||
if (replies != null && !replies.isEmpty() && replies.get(replies.size() - 1) != null) {
|
||||
displayedMessage = replies.get(replies.size() - 1);
|
||||
} else {
|
||||
displayedMessage = message;
|
||||
}
|
||||
if (message.isNew()) {
|
||||
|
||||
if (message.isRead()) {
|
||||
if (markAllMessagesAsRead) {
|
||||
message.setNew(false);
|
||||
message.markAsRead();
|
||||
} else {
|
||||
holder.itemView.setBackgroundColor(
|
||||
mUnreadMessageBackgroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
if (message.wasComment()) {
|
||||
((DataViewHolder) holder).titleTextView.setText(message.getTitle());
|
||||
} else {
|
||||
((DataViewHolder) holder).titleTextView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
((DataViewHolder) holder).authorTextView.setText(displayedMessage.getAuthor());
|
||||
String subject = displayedMessage.getSubject().substring(0, 1).toUpperCase() + displayedMessage.getSubject().substring(1);
|
||||
((DataViewHolder) holder).titleTextView.setVisibility(View.GONE);
|
||||
|
||||
|
||||
((DataViewHolder) holder).authorTextView.setText(message.getComment().getAuthorQualifiedName());
|
||||
String subject = message.getComment().getCommunityQualifiedName();
|
||||
((DataViewHolder) holder).subjectTextView.setText(subject);
|
||||
mMarkwon.setMarkdown(((DataViewHolder) holder).contentCustomMarkwonView, displayedMessage.getBody());
|
||||
mMarkwon.setMarkdown(((DataViewHolder) holder).contentCustomMarkwonView, message.getComment().getCommentMarkdown());
|
||||
|
||||
holder.itemView.setOnClickListener(view -> {
|
||||
if (mMessageType == FetchMessage.MESSAGE_TYPE_INBOX
|
||||
&& message.getContext() != null && !message.getContext().equals("")) {
|
||||
Uri uri = Uri.parse(message.getContext());
|
||||
Intent intent = new Intent(mActivity, LinkResolverActivity.class);
|
||||
intent.setData(uri);
|
||||
&& message.getComment() != null) {
|
||||
|
||||
Intent intent = new Intent(mActivity, ViewPostDetailActivity.class);
|
||||
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, message.getComment().getPostId());
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, message.getComment().getId());
|
||||
if(message.getComment().getDepth() > 0) {
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_PARENT_ID, message.getComment().getParentId());
|
||||
}
|
||||
mActivity.startActivity(intent);
|
||||
} else if (mMessageType == FetchMessage.MESSAGE_TYPE_PRIVATE_MESSAGE) {
|
||||
Intent intent = new Intent(mActivity, ViewPrivateMessagesActivity.class);
|
||||
@@ -197,20 +193,21 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
|
||||
if (displayedMessage.isNew()) {
|
||||
if (message.isRead()) {
|
||||
holder.itemView.setBackgroundColor(mMessageBackgroundColor);
|
||||
message.setNew(false);
|
||||
|
||||
ReadMessage.readMessage(mOauthRetrofit, mAccessToken, message.getFullname(),
|
||||
|
||||
ReadMessage.readMessage(retrofit, mAccessToken, message.getId(),
|
||||
new ReadMessage.ReadMessageListener() {
|
||||
@Override
|
||||
public void readSuccess() {
|
||||
message.markAsRead();
|
||||
EventBus.getDefault().post(new ChangeInboxCountEvent(-1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFailed() {
|
||||
message.setNew(true);
|
||||
message.markAsUnRead();
|
||||
holder.itemView.setBackgroundColor(mUnreadMessageBackgroundColor);
|
||||
}
|
||||
});
|
||||
@@ -218,11 +215,10 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
||||
});
|
||||
|
||||
((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
|
||||
if (message.isAuthorDeleted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getAuthor());
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getComment().getAuthor());
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, message.getComment().getAuthorQualifiedName());
|
||||
mActivity.startActivity(intent);
|
||||
});
|
||||
}
|
||||
@@ -280,9 +276,9 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
||||
}
|
||||
}
|
||||
|
||||
public void updateMessageReply(Message newReply, int position) {
|
||||
public void updateMessageReply(CommentInteraction newReply, int position) {
|
||||
if (position >= 0 && position < super.getItemCount()) {
|
||||
Message message = getItem(position);
|
||||
CommentInteraction message = getItem(position);
|
||||
if (message != null) {
|
||||
notifyItemChanged(position);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,9 @@ import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.engine.GlideException;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.google.android.exoplayer2.Tracks;
|
||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||
import com.google.android.exoplayer2.ui.DefaultTimeBar;
|
||||
@@ -64,6 +66,7 @@ import eu.toldi.infinityforlemmy.FetchStreamableVideo;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.SaveMemoryCenterInisdeDownsampleStrategy;
|
||||
import eu.toldi.infinityforlemmy.SavePost;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.StreamableVideo;
|
||||
import eu.toldi.infinityforlemmy.VoteThing;
|
||||
@@ -95,6 +98,7 @@ import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
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 eu.toldi.infinityforlemmy.videoautoplay.CacheManager;
|
||||
@@ -213,7 +217,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
|
||||
public PostDetailRecyclerViewAdapter(BaseActivity activity, ViewPostDetailFragment fragment,
|
||||
Executor executor, CustomThemeWrapper customThemeWrapper,
|
||||
Retrofit retrofit, Retrofit oauthRetrofit, Retrofit gfycatRetrofit,
|
||||
Retrofit retrofit, Retrofit gfycatRetrofit,
|
||||
Retrofit redgifsRetrofit, Provider<StreamableAPI> streamableApiProvider,
|
||||
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
|
||||
boolean separatePostAndComments, String accessToken,
|
||||
@@ -228,7 +232,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
mFragment = fragment;
|
||||
mExecutor = executor;
|
||||
mRetrofit = retrofit;
|
||||
mOauthRetrofit = oauthRetrofit;
|
||||
mGfycatRetrofit = gfycatRetrofit;
|
||||
mRedgifsRetrofit = redgifsRetrofit;
|
||||
mStreamableApiProvider = streamableApiProvider;
|
||||
@@ -436,7 +439,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
}
|
||||
return new PostDetailVideoAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(mLegacyAutoplayVideoControllerUI ? R.layout.item_post_detail_video_autoplay_legacy_controller : R.layout.item_post_detail_video_autoplay, parent, false));
|
||||
case VIEW_TYPE_POST_DETAIL_VIDEO_AND_GIF_PREVIEW:
|
||||
if (mDataSavingMode && (mDisableImagePreview || mOnlyDisablePreviewInVideoAndGifPosts)) {
|
||||
if (mDataSavingMode && (mDisableImagePreview || mOnlyDisablePreviewInVideoAndGifPosts) || mPost.getPreviews().isEmpty()) {
|
||||
return new PostDetailNoPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_no_preview, parent, false));
|
||||
}
|
||||
return new PostDetailVideoAndGifPreviewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_detail_video_and_gif_preview, parent, false));
|
||||
@@ -473,8 +476,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
((PostDetailBaseViewHolder) holder).mTitleTextView.setText(mPost.getTitle());
|
||||
if (mPost.getSubredditNamePrefixed().startsWith("u/")) {
|
||||
if (mPost.getAuthorIconUrl() == null) {
|
||||
String authorName = mPost.isAuthorDeleted() ? mPost.getSubredditNamePrefixed().substring(2) : mPost.getAuthor();
|
||||
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, authorName, mOauthRetrofit, iconImageUrl -> {
|
||||
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase,mPost.getAuthorNamePrefixed(), mOauthRetrofit, iconImageUrl -> {
|
||||
if (mActivity != null && getItemCount() > 0) {
|
||||
if (iconImageUrl == null || iconImageUrl.equals("")) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
@@ -507,7 +509,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
} else {
|
||||
if (mPost.getSubredditIconUrl() == null) {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(),
|
||||
mRedditDataRoomDatabase, mPost.getSubredditNamePrefixed().substring(2),
|
||||
mRedditDataRoomDatabase, mPost.getSubredditNamePrefixed(),
|
||||
mAccessToken, mOauthRetrofit, mRetrofit, iconImageUrl -> {
|
||||
if (iconImageUrl == null || iconImageUrl.equals("")) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
@@ -634,8 +636,20 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
((PostDetailVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE);
|
||||
Post.Preview preview = getSuitablePreview(mPost.getPreviews());
|
||||
if (preview != null) {
|
||||
((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight());
|
||||
mGlide.load(preview.getPreviewUrl()).centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
|
||||
mGlide.load(preview.getPreviewUrl()).centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
int width = resource.getIntrinsicWidth();
|
||||
int height = resource.getIntrinsicHeight();
|
||||
((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) width / height);
|
||||
((PostDetailVideoAutoplayViewHolder) holder).previewImageView.setImageDrawable(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
|
||||
}
|
||||
@@ -843,9 +857,45 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
});
|
||||
|
||||
if (blurImage) {
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
int width = resource.getIntrinsicWidth();
|
||||
int height = resource.getIntrinsicHeight();
|
||||
if (preview.getPreviewHeight() == 0 || preview.getPreviewWidth() == 0) {
|
||||
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setRatio((float) height / width);
|
||||
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.getLayoutParams().height = height;
|
||||
preview.setPreviewHeight(height);
|
||||
preview.setPreviewWidth(width);
|
||||
}
|
||||
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setImageDrawable(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setImageDrawable(null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
int width = resource.getIntrinsicWidth();
|
||||
int height = resource.getIntrinsicHeight();
|
||||
if (preview.getPreviewHeight() == 0 || preview.getPreviewWidth() == 0) {
|
||||
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setRatio((float) height / width);
|
||||
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.getLayoutParams().height = height;
|
||||
preview.setPreviewHeight(height);
|
||||
preview.setPreviewWidth(width);
|
||||
}
|
||||
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setImageDrawable(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setImageDrawable(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (holder instanceof PostDetailVideoAndGifPreviewHolder) {
|
||||
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl())
|
||||
@@ -871,9 +921,45 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
|
||||
if ((mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()))) {
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
|
||||
.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
|
||||
.into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
int width = resource.getIntrinsicWidth();
|
||||
int height = resource.getIntrinsicHeight();
|
||||
if (preview.getPreviewHeight() == 0 || preview.getPreviewWidth() == 0) {
|
||||
((PostDetailVideoAndGifPreviewHolder) holder).mImageView.setRatio((float) height / width);
|
||||
((PostDetailVideoAndGifPreviewHolder) holder).mImageView.getLayoutParams().height = height;
|
||||
preview.setPreviewHeight(height);
|
||||
preview.setPreviewWidth(width);
|
||||
}
|
||||
((PostDetailVideoAndGifPreviewHolder) holder).mImageView.setImageDrawable(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
((PostDetailVideoAndGifPreviewHolder) holder).mImageView.setImageDrawable(null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
int width = resource.getIntrinsicWidth();
|
||||
int height = resource.getIntrinsicHeight();
|
||||
if (preview.getPreviewHeight() == 0 || preview.getPreviewWidth() == 0) {
|
||||
((PostDetailVideoAndGifPreviewHolder) holder).mImageView.setRatio((float) height / width);
|
||||
((PostDetailVideoAndGifPreviewHolder) holder).mImageView.getLayoutParams().height = height;
|
||||
preview.setPreviewHeight(height);
|
||||
preview.setPreviewWidth(width);
|
||||
}
|
||||
((PostDetailVideoAndGifPreviewHolder) holder).mImageView.setImageDrawable(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
((PostDetailVideoAndGifPreviewHolder) holder).mImageView.setImageDrawable(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (holder instanceof PostDetailLinkViewHolder) {
|
||||
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl())
|
||||
@@ -899,9 +985,51 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
|
||||
if ((mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()))) {
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
|
||||
.into(((PostDetailLinkViewHolder) holder).mImageView);
|
||||
.into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
int width = resource.getIntrinsicWidth();
|
||||
int height = resource.getIntrinsicHeight();
|
||||
if (preview.getPreviewHeight() == 0 || preview.getPreviewWidth() == 0) {
|
||||
((PostDetailLinkViewHolder) holder).mImageView.setRatio((float) height / width);
|
||||
((PostDetailLinkViewHolder) holder).mImageView.getLayoutParams().height = height;
|
||||
preview.setPreviewHeight(height);
|
||||
preview.setPreviewWidth(width);
|
||||
} else {
|
||||
((PostDetailLinkViewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
((PostDetailLinkViewHolder) holder).mImageView.getLayoutParams().height = height;
|
||||
}
|
||||
((PostDetailLinkViewHolder) holder).mImageView.setImageDrawable(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
((PostDetailLinkViewHolder) holder).mImageView.setImageDrawable(null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostDetailLinkViewHolder) holder).mImageView);
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
int width = resource.getIntrinsicWidth();
|
||||
int height = resource.getIntrinsicHeight();
|
||||
((PostDetailLinkViewHolder) holder).mImageView.setImageDrawable(resource);
|
||||
if (preview.getPreviewHeight() == 0 || preview.getPreviewWidth() == 0) {
|
||||
((PostDetailLinkViewHolder) holder).mImageView.setRatio((float) height / width);
|
||||
((PostDetailLinkViewHolder) holder).mImageView.getLayoutParams().height = height;
|
||||
preview.setPreviewHeight(height);
|
||||
preview.setPreviewWidth(width);
|
||||
} else {
|
||||
((PostDetailLinkViewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
((PostDetailLinkViewHolder) holder).mImageView.setImageDrawable(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1091,6 +1219,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
this.mSaveButton = mSaveButton;
|
||||
this.mShareButton = mShareButton;
|
||||
|
||||
if(!mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.CAN_DOWNVOTE,true)){
|
||||
mDownvoteButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mIconGifImageView.setOnClickListener(view -> mSubredditTextView.performClick());
|
||||
|
||||
mSubredditTextView.setOnClickListener(view -> {
|
||||
@@ -1350,10 +1482,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
SavePost savePost = new SavePost();
|
||||
if (mPost.isSaved()) {
|
||||
mSaveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(),
|
||||
savePost.unsaveThing(mOauthRetrofit, mAccessToken, mPost.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -1373,7 +1505,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
});
|
||||
} else {
|
||||
mSaveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(),
|
||||
savePost.saveThing(mRetrofit, mAccessToken, mPost.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -1637,8 +1769,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
} else {
|
||||
intent.setData(Uri.parse(mPost.getVideoUrl()));
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT);
|
||||
|
||||
}
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle());
|
||||
if (helper != null) {
|
||||
@@ -1910,8 +2042,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, mPost.getStreamableShortCode());
|
||||
} else {
|
||||
intent.setData(Uri.parse(mPost.getVideoUrl()));
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT);
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
|
||||
}
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle());
|
||||
@@ -2249,7 +2380,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, mPost.getStreamableShortCode());
|
||||
} else {
|
||||
intent.setData(Uri.parse(mPost.getVideoUrl()));
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT);
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
|
||||
}
|
||||
|
||||
@@ -44,7 +44,9 @@ import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.engine.GlideException;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.google.android.exoplayer2.Tracks;
|
||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||
import com.google.android.exoplayer2.ui.DefaultTimeBar;
|
||||
@@ -68,6 +70,7 @@ import eu.toldi.infinityforlemmy.FetchStreamableVideo;
|
||||
import eu.toldi.infinityforlemmy.MarkPostAsReadInterface;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.SaveMemoryCenterInisdeDownsampleStrategy;
|
||||
import eu.toldi.infinityforlemmy.SavePost;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.StreamableVideo;
|
||||
import eu.toldi.infinityforlemmy.VoteThing;
|
||||
@@ -145,7 +148,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
private SharedPreferences mSharedPreferences;
|
||||
private SharedPreferences mCurrentAccountSharedPreferences;
|
||||
private Executor mExecutor;
|
||||
private Retrofit mOauthRetrofit;
|
||||
private Retrofit retrofit;
|
||||
private Retrofit mGfycatRetrofit;
|
||||
private Retrofit mRedgifsRetrofit;
|
||||
private Provider<StreamableAPI> mStreamableApiProvider;
|
||||
@@ -249,7 +252,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
mSharedPreferences = sharedPreferences;
|
||||
mCurrentAccountSharedPreferences = currentAccountSharedPreferences;
|
||||
mExecutor = executor;
|
||||
mOauthRetrofit = oauthRetrofit;
|
||||
retrofit = oauthRetrofit;
|
||||
mGfycatRetrofit = gfycatRetrofit;
|
||||
mRedgifsRetrofit = redgifsRetrofit;
|
||||
mStreamableApiProvider = streamableApiProvider;
|
||||
@@ -438,7 +441,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
switch (post.getPostType()) {
|
||||
case Post.VIDEO_TYPE:
|
||||
if (mAutoplay) {
|
||||
if ((!mAutoplayNsfwVideos && post.isNSFW()) ) {
|
||||
if ((!mAutoplayNsfwVideos && post.isNSFW())) {
|
||||
return VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE;
|
||||
}
|
||||
return VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE;
|
||||
@@ -523,7 +526,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
|
||||
((PostBaseViewHolder) holder).titleTextView.setTextColor(mReadPostTitleColor);
|
||||
}
|
||||
String authorPrefixed = post.getAuthorNamePrefixed();
|
||||
String authorPrefixed = post.getAuthorNamePrefixed();
|
||||
|
||||
if (mHideSubredditAndUserPrefix) {
|
||||
((PostBaseViewHolder) holder).subredditTextView.setText(post.getSubredditName());
|
||||
@@ -539,7 +542,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
if (mDisplaySubredditName) {
|
||||
if (authorPrefixed.equals(post.getSubredditNamePrefixed())) {
|
||||
if (post.getAuthorIconUrl() == null) {
|
||||
mFragment.loadIcon(post.getAuthor(), false, (subredditOrUserName, iconUrl) -> {
|
||||
mFragment.loadIcon(post.getAuthorNamePrefixed(), false, (subredditOrUserName, iconUrl) -> {
|
||||
if (mActivity != null && getItemCount() > 0 && post.getAuthor().equals(subredditOrUserName)) {
|
||||
if (iconUrl == null || iconUrl.equals("")) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
@@ -571,7 +574,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
} else {
|
||||
if (post.getSubredditIconUrl() == null) {
|
||||
mFragment.loadIcon(post.getSubredditName(), true, (subredditOrUserName, iconUrl) -> {
|
||||
mFragment.loadIcon(post.getSubredditNamePrefixed(), true, (subredditOrUserName, iconUrl) -> {
|
||||
if (mActivity != null && getItemCount() > 0 && post.getSubredditName().equals(subredditOrUserName)) {
|
||||
if (iconUrl == null || iconUrl.equals("")) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
@@ -605,7 +608,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
} else {
|
||||
if (post.getAuthorIconUrl() == null) {
|
||||
String authorName = post.isAuthorDeleted() ? post.getSubredditName() : post.getAuthor();
|
||||
mFragment.loadIcon(authorName, post.isAuthorDeleted(), (subredditOrUserName, iconUrl) -> {
|
||||
mFragment.loadIcon(post.getSubredditNamePrefixed(), post.isAuthorDeleted(), (subredditOrUserName, iconUrl) -> {
|
||||
if (mActivity != null && getItemCount() > 0) {
|
||||
if (iconUrl == null || iconUrl.equals("") && authorName.equals(subredditOrUserName)) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
@@ -713,8 +716,28 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE);
|
||||
Post.Preview preview = getSuitablePreview(post.getPreviews());
|
||||
if (!mFixedHeightPreviewInCard && preview != null) {
|
||||
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight());
|
||||
mGlide.load(preview.getPreviewUrl()).centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
|
||||
mGlide.load(preview.getPreviewUrl()).centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
int width = resource.getIntrinsicWidth();
|
||||
int height = resource.getIntrinsicHeight();
|
||||
((PostVideoAutoplayViewHolder) holder).previewImageView.setImageDrawable(resource);
|
||||
if (preview.getPreviewHeight() <= 0 || preview.getPreviewWidth() <= 0) {
|
||||
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) height / width);
|
||||
((PostVideoAutoplayViewHolder) holder).previewImageView.getLayoutParams().height = height;
|
||||
preview.setPreviewHeight(height);
|
||||
preview.setPreviewWidth(width);
|
||||
} else {
|
||||
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
((PostVideoAutoplayViewHolder) holder).previewImageView.getLayoutParams().height = preview.getPreviewHeight();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
|
||||
}
|
||||
@@ -751,7 +774,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if(post.isStreamable() && !post.isLoadGfycatOrStreamableVideoSuccess()) {
|
||||
} else if (post.isStreamable() && !post.isLoadGfycatOrStreamableVideoSuccess()) {
|
||||
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
||||
mStreamableApiProvider.get().getStreamableData(post.getStreamableShortCode());
|
||||
FetchStreamableVideo.fetchStreamableVideoInRecyclerViewAdapter(mExecutor, new Handler(),
|
||||
@@ -832,21 +855,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
if (preview != null) {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setVisibility(View.VISIBLE);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.VISIBLE);
|
||||
if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) {
|
||||
if (mFixedHeightPreviewInCard) {
|
||||
int height = (int) (400 * mScale);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.getLayoutParams().height = height;
|
||||
} else {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
loadImage(holder);
|
||||
} else {
|
||||
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
|
||||
if (post.getPostType() == Post.VIDEO_TYPE) {
|
||||
@@ -872,10 +886,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostBaseGalleryTypeViewHolder) holder).imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, 1, post.getGallery().size()));
|
||||
Post.Preview preview = getSuitablePreview(post.getPreviews());
|
||||
if (preview != null) {
|
||||
if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) {
|
||||
if (mFixedHeightPreviewInCard) {
|
||||
((PostBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1);
|
||||
} else {
|
||||
((PostBaseGalleryTypeViewHolder) holder).adapter.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
} else {
|
||||
((PostBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1);
|
||||
@@ -885,7 +897,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
(post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())));
|
||||
}
|
||||
} else if (holder instanceof PostTextTypeViewHolder) {
|
||||
if (!mHideTextPostContent && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) {
|
||||
if (!mHideTextPostContent && post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) {
|
||||
((PostTextTypeViewHolder) holder).contentTextView.setVisibility(View.VISIBLE);
|
||||
if (post.isRead()) {
|
||||
((PostTextTypeViewHolder) holder).contentTextView.setTextColor(mReadPostContentColor);
|
||||
@@ -896,8 +908,28 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostCard2VideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE);
|
||||
Post.Preview preview = getSuitablePreview(post.getPreviews());
|
||||
if (!mFixedHeightPreviewInCard && preview != null) {
|
||||
((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight());
|
||||
mGlide.load(preview.getPreviewUrl()).centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostCard2VideoAutoplayViewHolder) holder).previewImageView);
|
||||
mGlide.load(preview.getPreviewUrl()).centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
int width = resource.getIntrinsicWidth();
|
||||
int height = resource.getIntrinsicHeight();
|
||||
((PostCard2VideoAutoplayViewHolder) holder).previewImageView.setImageDrawable(resource);
|
||||
if (preview.getPreviewHeight() <= 0 || preview.getPreviewWidth() <= 0) {
|
||||
((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) height / width);
|
||||
((PostCard2VideoAutoplayViewHolder) holder).previewImageView.getLayoutParams().height = height;
|
||||
preview.setPreviewHeight(height);
|
||||
preview.setPreviewWidth(width);
|
||||
} else {
|
||||
((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
((PostCard2VideoAutoplayViewHolder) holder).previewImageView.getLayoutParams().height = height;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
|
||||
}
|
||||
@@ -934,7 +966,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if(post.isStreamable() && !post.isLoadGfycatOrStreamableVideoSuccess()) {
|
||||
} else if (post.isStreamable() && !post.isLoadGfycatOrStreamableVideoSuccess()) {
|
||||
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
||||
mStreamableApiProvider.get().getStreamableData(post.getStreamableShortCode());
|
||||
FetchStreamableVideo.fetchStreamableVideoInRecyclerViewAdapter(mExecutor, new Handler(),
|
||||
@@ -1022,21 +1054,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostCard2WithPreviewViewHolder) holder).preview = preview;
|
||||
if (preview != null) {
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.VISIBLE);
|
||||
if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) {
|
||||
if (mFixedHeightPreviewInCard) {
|
||||
int height = (int) (400 * mScale);
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.getLayoutParams().height = height;
|
||||
} else {
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
loadImage(holder);
|
||||
} else {
|
||||
((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE);
|
||||
((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
|
||||
@@ -1076,8 +1099,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostCompactBaseViewHolder) holder).titleTextView.setTextColor(mReadPostTitleColor);
|
||||
}
|
||||
final String subredditNamePrefixed = post.getSubredditNamePrefixed();
|
||||
String subredditName = subredditNamePrefixed.substring(2);
|
||||
String authorPrefixed = post.getAuthorNamePrefixed();
|
||||
String subredditName = subredditNamePrefixed;
|
||||
String authorPrefixed = post.getAuthorNamePrefixed();
|
||||
final String title = post.getTitle();
|
||||
int voteType = post.getVoteType();
|
||||
boolean nsfw = post.isNSFW();
|
||||
@@ -1086,8 +1109,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
if (mDisplaySubredditName) {
|
||||
if (authorPrefixed.equals(subredditNamePrefixed)) {
|
||||
if (post.getAuthorIconUrl() == null) {
|
||||
mFragment.loadIcon(post.getAuthor(), false, (subredditOrUserName, iconUrl) -> {
|
||||
if (mActivity != null && getItemCount() > 0 && post.getAuthor().equals(subredditOrUserName)) {
|
||||
mFragment.loadIcon(post.getAuthorNamePrefixed(), false, (subredditOrUserName, iconUrl) -> {
|
||||
if (mActivity != null && getItemCount() > 0 && post.getAuthorNamePrefixed().equals(subredditOrUserName)) {
|
||||
if (iconUrl == null || iconUrl.equals("")) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -1118,7 +1141,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
} else {
|
||||
if (post.getSubredditIconUrl() == null) {
|
||||
mFragment.loadIcon(subredditName, true, (subredditOrUserName, iconUrl) -> {
|
||||
mFragment.loadIcon(subredditNamePrefixed, true, (subredditOrUserName, iconUrl) -> {
|
||||
if (mActivity != null && getItemCount() > 0 && subredditName.equals(subredditOrUserName)) {
|
||||
if (iconUrl == null || iconUrl.equals("")) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
@@ -1154,12 +1177,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
if (mHideSubredditAndUserPrefix) {
|
||||
((PostCompactBaseViewHolder) holder).nameTextView.setText(post.getSubredditName());
|
||||
} else {
|
||||
((PostCompactBaseViewHolder) holder).nameTextView.setText("r/" + post.getSubredditName());
|
||||
((PostCompactBaseViewHolder) holder).nameTextView.setText(post.getSubredditNamePrefixed());
|
||||
}
|
||||
} else {
|
||||
if (post.getAuthorIconUrl() == null) {
|
||||
String authorName = post.isAuthorDeleted() ? post.getSubredditName() : post.getAuthor();
|
||||
mFragment.loadIcon(authorName, post.isAuthorDeleted(), (subredditOrUserName, iconUrl) -> {
|
||||
String authorName = post.getAuthorNamePrefixed();
|
||||
mFragment.loadIcon(post.getAuthorNamePrefixed(), false, (subredditOrUserName, iconUrl) -> {
|
||||
if (mActivity != null && getItemCount() > 0 && authorName.equals(subredditOrUserName)) {
|
||||
if (iconUrl == null || iconUrl.equals("")) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
@@ -1400,21 +1423,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) {
|
||||
if (mFixedHeightPreviewInCard) {
|
||||
int height = (int) (400 * mScale);
|
||||
((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height;
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
loadImage(holder);
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp);
|
||||
@@ -1422,7 +1436,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
break;
|
||||
}
|
||||
case Post.GIF_TYPE: {
|
||||
if (post.getPostType() == Post.GIF_TYPE && ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mAutoplay && mAutoplayNsfwVideos)) )) {
|
||||
if (post.getPostType() == Post.GIF_TYPE && ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mAutoplay && mAutoplayNsfwVideos)))) {
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp);
|
||||
} else {
|
||||
@@ -1434,21 +1448,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
|
||||
|
||||
if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) {
|
||||
if (mFixedHeightPreviewInCard) {
|
||||
int height = (int) (400 * mScale);
|
||||
((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height;
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
loadImage(holder);
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp);
|
||||
@@ -1465,21 +1470,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
|
||||
|
||||
if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) {
|
||||
if (mFixedHeightPreviewInCard) {
|
||||
int height = (int) (400 * mScale);
|
||||
((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height;
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
loadImage(holder);
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp);
|
||||
@@ -1495,21 +1491,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_link_post_type_indicator));
|
||||
|
||||
if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) {
|
||||
if (mFixedHeightPreviewInCard) {
|
||||
int height = (int) (400 * mScale);
|
||||
((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height;
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
loadImage(holder);
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link);
|
||||
@@ -1548,10 +1535,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostGalleryBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.VISIBLE);
|
||||
((PostGalleryBaseGalleryTypeViewHolder) holder).imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, 1, post.getGallery().size()));
|
||||
if (preview != null) {
|
||||
if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) {
|
||||
if (mFixedHeightPreviewInCard) {
|
||||
((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1);
|
||||
} else {
|
||||
((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
} else {
|
||||
((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1);
|
||||
@@ -1604,9 +1589,71 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url).listener(((PostWithPreviewTypeViewHolder) holder).glideRequestListener);
|
||||
if (blurImage) {
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
|
||||
.into(((PostWithPreviewTypeViewHolder) holder).imageView);
|
||||
.into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onLoadStarted(@Nullable Drawable placeholder) {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setVisibility(View.GONE);
|
||||
((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setImageDrawable(resource);
|
||||
int height = resource.getIntrinsicHeight();
|
||||
if (!mFixedHeightPreviewInCard) {
|
||||
float imageRatio = (float) resource.getIntrinsicHeight() / resource.getIntrinsicWidth();
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setRatio(imageRatio);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setImageDrawable(resource);
|
||||
} else {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setRatio(-1);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.getLayoutParams().height = height;
|
||||
}
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setVisibility(View.VISIBLE);
|
||||
((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
// Reset to default aspect ratio
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setRatio(1);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setImageDrawable(placeholder);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setVisibility(View.GONE);
|
||||
((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostWithPreviewTypeViewHolder) holder).imageView);
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onLoadStarted(@Nullable Drawable placeholder) {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setVisibility(View.GONE);
|
||||
((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setImageDrawable(resource);
|
||||
int height = resource.getIntrinsicHeight();
|
||||
if (!mFixedHeightPreviewInCard) {
|
||||
float imageRatio = (float) resource.getIntrinsicHeight() / resource.getIntrinsicWidth();
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setRatio(imageRatio);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setImageDrawable(resource);
|
||||
} else {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setRatio(-1);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.getLayoutParams().height = height;
|
||||
}
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setVisibility(View.VISIBLE);
|
||||
((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
// Reset to default aspect ratio
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setRatio(1);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setImageDrawable(placeholder);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.setVisibility(View.GONE);
|
||||
((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (holder instanceof PostCompactBaseViewHolder) {
|
||||
@@ -1644,9 +1691,71 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
|
||||
if (blurImage) {
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
|
||||
.into(((PostGalleryViewHolder) holder).imageView);
|
||||
.into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onLoadStarted(@Nullable Drawable placeholder) {
|
||||
((PostGalleryViewHolder) holder).imageView.setVisibility(View.GONE);
|
||||
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
((PostGalleryViewHolder) holder).imageView.setImageDrawable(resource);
|
||||
int height = resource.getIntrinsicHeight();
|
||||
if (!mFixedHeightPreviewInCard) {
|
||||
float imageRatio = (float) resource.getIntrinsicHeight() / resource.getIntrinsicWidth();
|
||||
((PostGalleryViewHolder) holder).imageView.setRatio(imageRatio);
|
||||
((PostGalleryViewHolder) holder).imageView.setImageDrawable(resource);
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).imageView.setRatio(-1);
|
||||
((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height;
|
||||
}
|
||||
((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
// Reset to default aspect ratio
|
||||
((PostGalleryViewHolder) holder).imageView.setRatio(1);
|
||||
((PostGalleryViewHolder) holder).imageView.setImageDrawable(placeholder);
|
||||
((PostGalleryViewHolder) holder).imageView.setVisibility(View.GONE);
|
||||
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostGalleryViewHolder) holder).imageView);
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onLoadStarted(@Nullable Drawable placeholder) {
|
||||
((PostGalleryViewHolder) holder).imageView.setVisibility(View.GONE);
|
||||
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
((PostGalleryViewHolder) holder).imageView.setImageDrawable(resource);
|
||||
int height = resource.getIntrinsicHeight();
|
||||
if (!mFixedHeightPreviewInCard) {
|
||||
float imageRatio = (float) resource.getIntrinsicHeight() / resource.getIntrinsicWidth();
|
||||
((PostGalleryViewHolder) holder).imageView.setRatio(imageRatio);
|
||||
((PostGalleryViewHolder) holder).imageView.setImageDrawable(resource);
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).imageView.setRatio(-1);
|
||||
((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height;
|
||||
}
|
||||
((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
// Reset to default aspect ratio
|
||||
((PostGalleryViewHolder) holder).imageView.setRatio(1);
|
||||
((PostGalleryViewHolder) holder).imageView.setImageDrawable(placeholder);
|
||||
((PostGalleryViewHolder) holder).imageView.setVisibility(View.GONE);
|
||||
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (holder instanceof PostCard2WithPreviewViewHolder) {
|
||||
@@ -1664,9 +1773,71 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
|
||||
if (blurImage) {
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
|
||||
.into(((PostCard2WithPreviewViewHolder) holder).imageView);
|
||||
.into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onLoadStarted(@Nullable Drawable placeholder) {
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.GONE);
|
||||
((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setImageDrawable(resource);
|
||||
int height = resource.getIntrinsicHeight();
|
||||
if (!mFixedHeightPreviewInCard) {
|
||||
float imageRatio = (float) resource.getIntrinsicHeight() / resource.getIntrinsicWidth();
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setRatio(imageRatio);
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setImageDrawable(resource);
|
||||
} else {
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setRatio(-1);
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.getLayoutParams().height = height;
|
||||
}
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.VISIBLE);
|
||||
((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
// Reset to default aspect ratio
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setRatio(1);
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setImageDrawable(placeholder);
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.GONE);
|
||||
((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostCard2WithPreviewViewHolder) holder).imageView);
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onLoadStarted(@Nullable Drawable placeholder) {
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.GONE);
|
||||
((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setImageDrawable(resource);
|
||||
int height = resource.getIntrinsicHeight();
|
||||
if (!mFixedHeightPreviewInCard) {
|
||||
float imageRatio = (float) resource.getIntrinsicHeight() / resource.getIntrinsicWidth();
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setRatio(imageRatio);
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setImageDrawable(resource);
|
||||
} else {
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setRatio(-1);
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.getLayoutParams().height = height;
|
||||
}
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.VISIBLE);
|
||||
((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
// Reset to default aspect ratio
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setRatio(1);
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setImageDrawable(placeholder);
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.GONE);
|
||||
((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2078,8 +2249,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode());
|
||||
} else {
|
||||
intent.setData(Uri.parse(post.getVideoUrl()));
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_DIRECT);
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
|
||||
}
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle());
|
||||
@@ -2200,6 +2370,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
this.shareButton = shareButton;
|
||||
|
||||
scoreTextView.setOnClickListener(null);
|
||||
if(!mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.CAN_DOWNVOTE,true)){
|
||||
downvoteButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (mVoteButtonsOnTheRight) {
|
||||
ConstraintSet constraintSet = new ConstraintSet();
|
||||
@@ -2433,7 +2606,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -2529,7 +2702,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -2587,10 +2760,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
SavePost savePost = new SavePost();
|
||||
if (post.isSaved()) {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
savePost.unsaveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -2614,7 +2787,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
});
|
||||
} else {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
savePost.saveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -3306,7 +3479,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
downY = e.getRawY();
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if(Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) {
|
||||
if (Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) {
|
||||
dragged = true;
|
||||
}
|
||||
break;
|
||||
@@ -3509,21 +3682,21 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
|
||||
void setBaseView(AspectRatioGifImageView iconGifImageView,
|
||||
TextView nameTextView, ImageView stickiedPostImageView,
|
||||
TextView postTimeTextView, ConstraintLayout titleAndImageConstraintLayout,
|
||||
TextView titleTextView, CustomTextView typeTextView,
|
||||
ImageView archivedImageView, ImageView lockedImageView,
|
||||
ImageView crosspostImageView, CustomTextView nsfwTextView,
|
||||
CustomTextView spoilerTextView, CustomTextView flairTextView,
|
||||
CustomTextView awardsTextView, TextView linkTextView,
|
||||
RelativeLayout relativeLayout, ProgressBar progressBar,
|
||||
ImageView imageView, ImageView playButtonImageView,
|
||||
FrameLayout noPreviewLinkImageFrameLayout,
|
||||
ImageView noPreviewLinkImageView, Barrier imageBarrier,
|
||||
ConstraintLayout bottomConstraintLayout, ImageView upvoteButton,
|
||||
TextView scoreTextView, ImageView downvoteButton,
|
||||
TextView commentsCountTextView, ImageView saveButton,
|
||||
ImageView shareButton, View divider) {
|
||||
TextView nameTextView, ImageView stickiedPostImageView,
|
||||
TextView postTimeTextView, ConstraintLayout titleAndImageConstraintLayout,
|
||||
TextView titleTextView, CustomTextView typeTextView,
|
||||
ImageView archivedImageView, ImageView lockedImageView,
|
||||
ImageView crosspostImageView, CustomTextView nsfwTextView,
|
||||
CustomTextView spoilerTextView, CustomTextView flairTextView,
|
||||
CustomTextView awardsTextView, TextView linkTextView,
|
||||
RelativeLayout relativeLayout, ProgressBar progressBar,
|
||||
ImageView imageView, ImageView playButtonImageView,
|
||||
FrameLayout noPreviewLinkImageFrameLayout,
|
||||
ImageView noPreviewLinkImageView, Barrier imageBarrier,
|
||||
ConstraintLayout bottomConstraintLayout, ImageView upvoteButton,
|
||||
TextView scoreTextView, ImageView downvoteButton,
|
||||
TextView commentsCountTextView, ImageView saveButton,
|
||||
ImageView shareButton, View divider) {
|
||||
this.iconGifImageView = iconGifImageView;
|
||||
this.nameTextView = nameTextView;
|
||||
this.stickiedPostImageView = stickiedPostImageView;
|
||||
@@ -3557,6 +3730,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
|
||||
scoreTextView.setOnClickListener(null);
|
||||
|
||||
if(!mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.CAN_DOWNVOTE,true)){
|
||||
downvoteButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (mVoteButtonsOnTheRight) {
|
||||
ConstraintSet constraintSet = new ConstraintSet();
|
||||
constraintSet.clone(bottomConstraintLayout);
|
||||
@@ -3792,7 +3969,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -3888,7 +4065,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -3948,9 +4125,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
SavePost postSave = new SavePost();
|
||||
if (post.isSaved()) {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
postSave.unsaveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -3974,7 +4152,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
});
|
||||
} else {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
postSave.saveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -4417,7 +4595,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
downTime = System.currentTimeMillis();
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if(Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) {
|
||||
if (Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) {
|
||||
dragged = true;
|
||||
}
|
||||
if (!dragged) {
|
||||
|
||||
@@ -33,8 +33,8 @@ import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.activities.BaseActivity;
|
||||
import eu.toldi.infinityforlemmy.asynctasks.CheckIsSubscribedToSubreddit;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.subreddit.CommunitySubscription;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditSubscription;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
@@ -125,7 +125,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
|
||||
if (isMultiSelection) {
|
||||
((DataViewHolder) holder).checkBox.performClick();
|
||||
} else {
|
||||
callback.subredditSelected(subredditData.getName(), LemmyUtils.actorID2FullName(subredditData.getActorId()), subredditData.getIconUrl());
|
||||
callback.subredditSelected(subredditData);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -158,10 +158,10 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
|
||||
((DataViewHolder) holder).subscribeButton.setVisibility(View.VISIBLE);
|
||||
((DataViewHolder) holder).subscribeButton.setOnClickListener(view -> {
|
||||
if (accessToken != null) {
|
||||
SubredditSubscription.subscribeToSubreddit(executor, new Handler(),
|
||||
oauthRetrofit, retrofit, accessToken, subredditData.getName(),
|
||||
CommunitySubscription.subscribeToCommunity(executor, new Handler(),
|
||||
retrofit, accessToken, subredditData.getId(), LemmyUtils.actorID2FullName(subredditData.getActorId()),
|
||||
accountName, redditDataRoomDatabase,
|
||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||
new CommunitySubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE);
|
||||
@@ -174,9 +174,9 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
|
||||
}
|
||||
});
|
||||
} else {
|
||||
SubredditSubscription.anonymousSubscribeToSubreddit(executor, new Handler(),
|
||||
CommunitySubscription.anonymousSubscribeToSubreddit(executor, new Handler(),
|
||||
retrofit, redditDataRoomDatabase, subredditData.getName(),
|
||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||
new CommunitySubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE);
|
||||
@@ -252,7 +252,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
|
||||
public interface Callback {
|
||||
void retryLoadingMore();
|
||||
|
||||
void subredditSelected(String subredditName, String communityFullName,String iconUrl);
|
||||
void subredditSelected(SubredditData communityData);
|
||||
}
|
||||
|
||||
class DataViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@@ -149,39 +149,17 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
||||
|
||||
if (hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 0) {
|
||||
((SubredditViewHolder) viewHolder).subredditNameTextView.setText(R.string.all_communities);
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(null, null, false));
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(null));
|
||||
return;
|
||||
} else if (itemClickListener != null && !hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 0) {
|
||||
name = username;
|
||||
iconUrl = userIconUrl;
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true));
|
||||
} else if (hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 1) {
|
||||
name = username;
|
||||
iconUrl = userIconUrl;
|
||||
if (itemClickListener != null) {
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true));
|
||||
}
|
||||
} else {
|
||||
int offset;
|
||||
if (itemClickListener != null) {
|
||||
if (hasClearSelectionRow) {
|
||||
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
||||
mFavoriteSubscribedSubredditData.size() + 4 : 2;
|
||||
} else {
|
||||
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
||||
mFavoriteSubscribedSubredditData.size() + 3 : 1;
|
||||
}
|
||||
} else {
|
||||
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
||||
mFavoriteSubscribedSubredditData.size() + 2 : 0;
|
||||
}
|
||||
|
||||
int offset = hasClearSelectionRow ? 1 : 0;
|
||||
SubscribedSubredditData communityData = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset);
|
||||
name = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
|
||||
fullname = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getQualified_name();
|
||||
iconUrl = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl();
|
||||
|
||||
if (itemClickListener != null) {
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, false));
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(communityData));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,11 +197,12 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
||||
} else {
|
||||
offset = 1;
|
||||
}
|
||||
SubscribedSubredditData communityData = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset);
|
||||
String name = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
|
||||
String iconUrl = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl();
|
||||
|
||||
if (itemClickListener != null) {
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, false));
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(communityData));
|
||||
} else {
|
||||
viewHolder.itemView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class);
|
||||
@@ -250,26 +229,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (mSubscribedSubredditData != null) {
|
||||
if(mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) {
|
||||
if (itemClickListener != null) {
|
||||
if (hasClearSelectionRow) {
|
||||
return mSubscribedSubredditData.size() > 0 ?
|
||||
mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + 4 : 0;
|
||||
} else {
|
||||
return mSubscribedSubredditData.size() > 0 ?
|
||||
mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + 3 : 0;
|
||||
}
|
||||
}
|
||||
return mSubscribedSubredditData.size() > 0 ?
|
||||
mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + 2 : 0;
|
||||
}
|
||||
|
||||
if (itemClickListener != null) {
|
||||
if (hasClearSelectionRow) {
|
||||
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + 2 : 0;
|
||||
} else {
|
||||
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + 1 : 0;
|
||||
}
|
||||
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + ((hasClearSelectionRow) ? 1 : 0) : 0;
|
||||
}
|
||||
|
||||
return mSubscribedSubredditData.size();
|
||||
@@ -347,7 +309,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
||||
}
|
||||
|
||||
public interface ItemClickListener {
|
||||
void onClick(String name, String iconUrl, boolean subredditIsUser);
|
||||
void onClick(SubscribedSubredditData subredditData);
|
||||
}
|
||||
|
||||
class SubredditViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@@ -24,8 +24,8 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
|
||||
private static final int VIEW_TYPE_MENU_GROUP_TITLE = 1;
|
||||
private static final int VIEW_TYPE_MENU_ITEM = 2;
|
||||
private static final int ACCOUNT_SECTION_ITEMS = 5;
|
||||
private static final int ANONYMOUS_ACCOUNT_SECTION_ITEMS = 3;
|
||||
private static final int ACCOUNT_SECTION_ITEMS = 4;
|
||||
private static final int ANONYMOUS_ACCOUNT_SECTION_ITEMS = 2;
|
||||
|
||||
private BaseActivity baseActivity;
|
||||
private int inboxCount;
|
||||
@@ -101,10 +101,6 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
drawableId = R.drawable.ic_subscritptions_bottom_app_bar_24dp;
|
||||
break;
|
||||
case 3:
|
||||
stringId = R.string.multi_reddit;
|
||||
drawableId = R.drawable.ic_multi_reddit_24dp;
|
||||
break;
|
||||
case 4:
|
||||
setOnClickListener = false;
|
||||
if (inboxCount > 0) {
|
||||
((MenuItemViewHolder) holder).menuTextView.setText(baseActivity.getString(R.string.inbox_with_count, inboxCount));
|
||||
@@ -118,23 +114,21 @@ public class AccountSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
||||
});
|
||||
break;
|
||||
default:
|
||||
stringId = R.string.history;
|
||||
drawableId = R.drawable.ic_history_24dp;
|
||||
|
||||
stringId = R.string.account_saved_thing_activity_label;
|
||||
drawableId = R.drawable.ic_outline_bookmarks_24dp;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (position) {
|
||||
|
||||
case 1:
|
||||
stringId = R.string.subscriptions;
|
||||
drawableId = R.drawable.ic_subscritptions_bottom_app_bar_24dp;
|
||||
break;
|
||||
case 2:
|
||||
stringId = R.string.multi_reddit;
|
||||
drawableId = R.drawable.ic_multi_reddit_24dp;
|
||||
break;
|
||||
default:
|
||||
stringId = R.string.history;
|
||||
drawableId = R.drawable.ic_history_24dp;
|
||||
stringId = R.string.anonymous_account_instance;
|
||||
drawableId = R.drawable.ic_account_circle_24dp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ import java.util.concurrent.Executor;
|
||||
|
||||
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.utils.SharedPreferencesUtils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
|
||||
public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
@@ -65,7 +65,7 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
requireAuthToAccountSection = securitySharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false);
|
||||
showAvatarOnTheRightInTheNavigationDrawer = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT, false);
|
||||
showAvatarOnTheRightInTheNavigationDrawer = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT, false);
|
||||
this.hideKarma = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_ACCOUNT_KARMA_NAV_BAR, false);
|
||||
this.hideKarma = true;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
||||
@@ -17,8 +17,6 @@ import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
public class NavigationDrawerRecyclerViewMergedAdapter {
|
||||
private HeaderSectionRecyclerViewAdapter headerSectionRecyclerViewAdapter;
|
||||
private AccountSectionRecyclerViewAdapter accountSectionRecyclerViewAdapter;
|
||||
private RedditSectionRecyclerViewAdapter redditSectionRecyclerViewAdapter;
|
||||
private PostSectionRecyclerViewAdapter postSectionRecyclerViewAdapter;
|
||||
private PreferenceSectionRecyclerViewAdapter preferenceSectionRecyclerViewAdapter;
|
||||
private FavoriteSubscribedSubredditsSectionRecyclerViewAdapter favoriteSubscribedSubredditsSectionRecyclerViewAdapter;
|
||||
private SubscribedSubredditsRecyclerViewAdapter subscribedSubredditsRecyclerViewAdapter;
|
||||
@@ -49,10 +47,6 @@ public class NavigationDrawerRecyclerViewMergedAdapter {
|
||||
});
|
||||
accountSectionRecyclerViewAdapter = new AccountSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
|
||||
navigationDrawerSharedPreferences, accountName != null, itemClickListener);
|
||||
redditSectionRecyclerViewAdapter = new RedditSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
|
||||
navigationDrawerSharedPreferences, itemClickListener);
|
||||
postSectionRecyclerViewAdapter = new PostSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
|
||||
navigationDrawerSharedPreferences, accountName != null, itemClickListener);
|
||||
preferenceSectionRecyclerViewAdapter = new PreferenceSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
|
||||
accountName, nsfwAndSpoilerSharedPreferences, navigationDrawerSharedPreferences, itemClickListener);
|
||||
favoriteSubscribedSubredditsSectionRecyclerViewAdapter = new FavoriteSubscribedSubredditsSectionRecyclerViewAdapter(
|
||||
@@ -65,8 +59,6 @@ public class NavigationDrawerRecyclerViewMergedAdapter {
|
||||
mainPageConcatAdapter = new ConcatAdapter(
|
||||
headerSectionRecyclerViewAdapter,
|
||||
accountSectionRecyclerViewAdapter,
|
||||
redditSectionRecyclerViewAdapter,
|
||||
postSectionRecyclerViewAdapter,
|
||||
preferenceSectionRecyclerViewAdapter,
|
||||
favoriteSubscribedSubredditsSectionRecyclerViewAdapter,
|
||||
subscribedSubredditsRecyclerViewAdapter);
|
||||
@@ -78,8 +70,6 @@ public class NavigationDrawerRecyclerViewMergedAdapter {
|
||||
|
||||
private void openAccountSection() {
|
||||
mainPageConcatAdapter.removeAdapter(accountSectionRecyclerViewAdapter);
|
||||
mainPageConcatAdapter.removeAdapter(redditSectionRecyclerViewAdapter);
|
||||
mainPageConcatAdapter.removeAdapter(postSectionRecyclerViewAdapter);
|
||||
mainPageConcatAdapter.removeAdapter(preferenceSectionRecyclerViewAdapter);
|
||||
mainPageConcatAdapter.removeAdapter(favoriteSubscribedSubredditsSectionRecyclerViewAdapter);
|
||||
mainPageConcatAdapter.removeAdapter(subscribedSubredditsRecyclerViewAdapter);
|
||||
@@ -91,8 +81,6 @@ public class NavigationDrawerRecyclerViewMergedAdapter {
|
||||
mainPageConcatAdapter.removeAdapter(accountManagementSectionRecyclerViewAdapter);
|
||||
|
||||
mainPageConcatAdapter.addAdapter(accountSectionRecyclerViewAdapter);
|
||||
mainPageConcatAdapter.addAdapter(redditSectionRecyclerViewAdapter);
|
||||
mainPageConcatAdapter.addAdapter(postSectionRecyclerViewAdapter);
|
||||
mainPageConcatAdapter.addAdapter(preferenceSectionRecyclerViewAdapter);
|
||||
mainPageConcatAdapter.addAdapter(favoriteSubscribedSubredditsSectionRecyclerViewAdapter);
|
||||
mainPageConcatAdapter.addAdapter(subscribedSubredditsRecyclerViewAdapter);
|
||||
|
||||
@@ -24,6 +24,9 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
private static final int VIEW_TYPE_MENU_ITEM = 2;
|
||||
private static final int REDDIT_SECTION_ITEMS = 1;
|
||||
|
||||
private static final int REDDIT_SECTION_ANONYMOUS_ITEMS = 2;
|
||||
private final boolean isLoggedIn;
|
||||
|
||||
private BaseActivity baseActivity;
|
||||
private int primaryTextColor;
|
||||
private int secondaryTextColor;
|
||||
@@ -33,13 +36,14 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
|
||||
public RedditSectionRecyclerViewAdapter(BaseActivity baseActivity, CustomThemeWrapper customThemeWrapper,
|
||||
SharedPreferences navigationDrawerSharedPreferences,
|
||||
NavigationDrawerRecyclerViewMergedAdapter.ItemClickListener itemClickListener) {
|
||||
NavigationDrawerRecyclerViewMergedAdapter.ItemClickListener itemClickListener, boolean isLoggedIn) {
|
||||
this.baseActivity = baseActivity;
|
||||
primaryTextColor = customThemeWrapper.getPrimaryTextColor();
|
||||
secondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
||||
primaryIconColor = customThemeWrapper.getPrimaryIconColor();
|
||||
collapseRedditSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_REDDIT_SECTION, false);
|
||||
this.itemClickListener = itemClickListener;
|
||||
this.isLoggedIn = isLoggedIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,6 +92,9 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
stringId = R.string.trending;
|
||||
drawableId = R.drawable.ic_trending_24dp;
|
||||
break;
|
||||
case 2:
|
||||
stringId = R.string.anonymous_account_instance;
|
||||
drawableId = R.drawable.ic_account_circle_24dp;
|
||||
}
|
||||
|
||||
((MenuItemViewHolder) holder).menuTextView.setText(stringId);
|
||||
@@ -99,7 +106,7 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return collapseRedditSection ? 1 : REDDIT_SECTION_ITEMS + 1;
|
||||
return !collapseRedditSection ? (isLoggedIn ? REDDIT_SECTION_ITEMS + 1 : REDDIT_SECTION_ANONYMOUS_ITEMS + 1) : 1;
|
||||
}
|
||||
|
||||
class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@@ -1,17 +1,37 @@
|
||||
package eu.toldi.infinityforlemmy.apis;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import eu.toldi.infinityforlemmy.dto.AccountLoginDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.AuthDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.CommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.CommentVoteDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.DeleteCommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.DeletePostDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.EditCommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.EditPostDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.FollowCommunityDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.PostVoteDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.ReadCommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.ReadMessageDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.ReadPostDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.SaveCommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.SavePostDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.SubmitPostDTO;
|
||||
import eu.toldi.infinityforlemmy.message.MessageCount;
|
||||
import okhttp3.MultipartBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.Multipart;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
import retrofit2.http.Part;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface LemmyAPI {
|
||||
@@ -22,12 +42,48 @@ public interface LemmyAPI {
|
||||
@GET("api/v3/user")
|
||||
Call<String> userInfo(@Query("username") String username, @Query("auth") String access_token);
|
||||
|
||||
@GET("api/v3/user/mention")
|
||||
Call<String> userMentions(@Query("sort") String sort, @Query("page") Integer page, @Query("limit") Integer limit, @Query("unread_only") boolean unread_only, @Query("auth") String access_token);
|
||||
|
||||
@GET("api/v3/user/replies")
|
||||
Call<String> userReplies(@Query("sort") String sort, @Query("page") Integer page, @Query("limit") Integer limit, @Query("unread_only") boolean unread_only, @Query("auth") String access_token);
|
||||
|
||||
@GET("api/v3/private_message/list")
|
||||
Call<String> privateMessageList(@Query("page") Integer page, @Query("limit") Integer limit, @Query("unread_only") boolean unread_only, @Query("auth") String access_token);
|
||||
|
||||
@GET("api/v3/user/unread_count")
|
||||
Call<MessageCount> userUnreadCount(@NonNull @Query("auth") String access_token);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/user/mention/mark_as_read")
|
||||
Call<String> userMentionMarkAsRead(@Body ReadMessageDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/comment/mark_as_read")
|
||||
Call<String> commentMarkAsRead(@Body ReadCommentDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/user/mark_all_as_read")
|
||||
Call<String> userMarkAllAsRead(@Body AuthDTO params);
|
||||
|
||||
@GET("api/v3/community")
|
||||
Call<String> communityInfo(@Query("name") String name, @Query("auth") String access_token);
|
||||
|
||||
@GET("api/v3/post")
|
||||
Call<String> postInfo(@Query("id") Integer postID, @Query("comment_id") Integer comment_id, @Query("auth") String access_token);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/post")
|
||||
Call<String> postCreate(@Body SubmitPostDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@PUT("api/v3/post")
|
||||
Call<String> postUpdate(@Body EditPostDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/post/delete")
|
||||
Call<String> postDelete(@Body DeletePostDTO params);
|
||||
|
||||
@GET("api/v3/user")
|
||||
ListenableFuture<Response<String>> getUserPosts(
|
||||
@Query("username") String username,
|
||||
@@ -37,6 +93,16 @@ public interface LemmyAPI {
|
||||
@Query("saved_only") Boolean saved_only,
|
||||
@Query("auth") String access_token);
|
||||
|
||||
@GET("api/v3/user")
|
||||
Call<String> getUserComments(
|
||||
@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/community/list")
|
||||
Call<String> listCommunities(
|
||||
@Query("type_") String type_,
|
||||
@@ -66,6 +132,22 @@ public interface LemmyAPI {
|
||||
@POST("api/v3/comment/like")
|
||||
Call<String> commentLike(@Body CommentVoteDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/community/follow")
|
||||
Call<String> communityFollow(@Body FollowCommunityDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@PUT("api/v3/post/save")
|
||||
Call<String> postSave(@Body SavePostDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/post/mark_as_read")
|
||||
Call<String> postRead(@Body ReadPostDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@PUT("api/v3/comment/save")
|
||||
Call<String> commentSave(@Body SaveCommentDTO params);
|
||||
|
||||
@GET("api/v3/comment/list")
|
||||
Call<String> getComments(
|
||||
@Query("type_") String type,
|
||||
@@ -112,4 +194,36 @@ public interface LemmyAPI {
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/comment")
|
||||
Call<String> postComment(@Body CommentDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/comment/delete")
|
||||
Call<String> commentDelete(@Body DeleteCommentDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@PUT("api/v3/comment")
|
||||
Call<String> commentEdit(@Body EditCommentDTO params);
|
||||
|
||||
@Multipart
|
||||
@POST("/pictrs/image")
|
||||
Call<String> uploadImage(
|
||||
@Header("Cookie") String token,
|
||||
@Part MultipartBody.Part filePart
|
||||
);
|
||||
|
||||
@GET("api/v3/resolve_object")
|
||||
Call<String> resolveObject(
|
||||
@Query("q") String query,
|
||||
@Query("auth") String auth
|
||||
);
|
||||
|
||||
@GET("api/v3/comment")
|
||||
Call<String> getComment(
|
||||
@Query("id") int commentId,
|
||||
@Query("auth") String auth
|
||||
);
|
||||
|
||||
@GET("api/v3/site")
|
||||
Call<String> getSiteInfo(
|
||||
@Query("auth") String auth
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditDao;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class LoadSubredditIcon {
|
||||
@@ -18,12 +19,12 @@ public class LoadSubredditIcon {
|
||||
LoadSubredditIconAsyncTaskListener loadSubredditIconAsyncTaskListener) {
|
||||
executor.execute(() -> {
|
||||
SubredditDao subredditDao = redditDataRoomDatabase.subredditDao();
|
||||
SubredditData subredditData = subredditDao.getSubredditData(subredditName);
|
||||
SubredditData subredditData = subredditDao.getSubredditDataByActorId(LemmyUtils.qualifiedCommunityName2ActorId(subredditName));
|
||||
if (subredditData != null) {
|
||||
String iconImageUrl = subredditDao.getSubredditData(subredditName).getIconUrl();
|
||||
String iconImageUrl = subredditDao.getSubredditDataByActorId(LemmyUtils.qualifiedCommunityName2ActorId(subredditName)).getIconUrl();
|
||||
handler.post(() -> loadSubredditIconAsyncTaskListener.loadIconSuccess(iconImageUrl));
|
||||
} else {
|
||||
handler.post(() -> FetchSubredditData.fetchSubredditData(oauthRetrofit, retrofit, subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
handler.post(() -> FetchSubredditData.fetchSubredditData(retrofit, subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData1, int nCurrentOnlineSubscribers) {
|
||||
ArrayList<SubredditData> singleSubredditDataList = new ArrayList<>();
|
||||
|
||||
@@ -8,6 +8,7 @@ import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.user.FetchUserData;
|
||||
import eu.toldi.infinityforlemmy.user.UserDao;
|
||||
import eu.toldi.infinityforlemmy.user.UserData;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class LoadUserData {
|
||||
@@ -16,8 +17,9 @@ public class LoadUserData {
|
||||
Retrofit retrofit, LoadUserDataAsyncTaskListener loadUserDataAsyncTaskListener) {
|
||||
executor.execute(() -> {
|
||||
UserDao userDao = redditDataRoomDatabase.userDao();
|
||||
if (userDao.getUserData(userName) != null) {
|
||||
String iconImageUrl = userDao.getUserData(userName).getIconUrl();
|
||||
UserData userData= userDao.getUserDataByActorId(LemmyUtils.qualifiedUserName2ActorId(userName));
|
||||
if (userData != null) {
|
||||
String iconImageUrl = userData.getIconUrl();
|
||||
handler.post(() -> loadUserDataAsyncTaskListener.loadUserDataSuccess(iconImageUrl));
|
||||
} else {
|
||||
handler.post(() -> FetchUserData.fetchUserData(retrofit, userName, new FetchUserData.FetchUserDataListener() {
|
||||
|
||||
@@ -11,11 +11,11 @@ public class ParseAndInsertNewAccount {
|
||||
|
||||
public static void parseAndInsertNewAccount(Executor executor, Handler handler, String username,
|
||||
String display_name,String accessToken, String profileImageUrl,
|
||||
String bannerImageUrl, String code,String instance, AccountDao accountDao,
|
||||
String bannerImageUrl, String code,String instance,boolean can_downvote, AccountDao accountDao,
|
||||
ParseAndInsertAccountListener parseAndInsertAccountListener) {
|
||||
executor.execute(() -> {
|
||||
Account account = new Account(username,display_name, accessToken, code, profileImageUrl,
|
||||
bannerImageUrl, true,instance);
|
||||
bannerImageUrl, true,instance,true);
|
||||
accountDao.markAllAccountsNonCurrent();
|
||||
accountDao.insert(account);
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import java.util.concurrent.Executor;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.account.Account;
|
||||
import eu.toldi.infinityforlemmy.site.FetchSiteInfo;
|
||||
import eu.toldi.infinityforlemmy.site.SiteInfo;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
|
||||
public class SwitchAccount {
|
||||
@@ -26,6 +28,18 @@ public class SwitchAccount {
|
||||
.putString(SharedPreferencesUtils.ACCOUNT_INSTANCE,account.getInstance_url())
|
||||
.putString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, account.getProfileImageUrl()).apply();
|
||||
retrofitHolder.setBaseURL(account.getInstance_url());
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSiteInfoFailed() {
|
||||
currentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, true).apply();
|
||||
}
|
||||
});
|
||||
handler.post(() -> switchAccountListener.switched(account));
|
||||
});
|
||||
|
||||
|
||||
@@ -55,12 +55,8 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
|
||||
TextView shareTextView;
|
||||
@BindView(R.id.copy_text_view_comment_more_bottom_sheet_fragment)
|
||||
TextView copyTextView;
|
||||
@BindView(R.id.give_award_text_view_comment_more_bottom_sheet_fragment)
|
||||
TextView giveAwardTextView;
|
||||
@BindView(R.id.report_view_comment_more_bottom_sheet_fragment)
|
||||
TextView reportTextView;
|
||||
@BindView(R.id.see_removed_view_comment_more_bottom_sheet_fragment)
|
||||
TextView seeRemovedTextView;
|
||||
private BaseActivity activity;
|
||||
|
||||
public CommentMoreBottomSheetFragment() {
|
||||
@@ -93,18 +89,6 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
|
||||
boolean showReplyAndSaveOption = bundle.getBoolean(EXTRA_SHOW_REPLY_AND_SAVE_OPTION, false);
|
||||
|
||||
if (accessToken != null && !accessToken.equals("")) {
|
||||
giveAwardTextView.setVisibility(View.VISIBLE);
|
||||
giveAwardTextView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(activity, GiveAwardActivity.class);
|
||||
intent.putExtra(GiveAwardActivity.EXTRA_THING_FULLNAME, comment.getFullName());
|
||||
intent.putExtra(GiveAwardActivity.EXTRA_ITEM_POSITION, bundle.getInt(EXTRA_POSITION));
|
||||
if (activity instanceof ViewPostDetailActivity) {
|
||||
activity.startActivityForResult(intent, ViewPostDetailActivity.GIVE_AWARD_REQUEST_CODE);
|
||||
} else if (activity instanceof ViewUserDetailActivity) {
|
||||
activity.startActivityForResult(intent, ViewUserDetailActivity.GIVE_AWARD_REQUEST_CODE);
|
||||
}
|
||||
dismiss();
|
||||
});
|
||||
|
||||
if (editAndDeleteAvailable) {
|
||||
editTextView.setVisibility(View.VISIBLE);
|
||||
@@ -112,7 +96,7 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
|
||||
|
||||
editTextView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(activity, EditCommentActivity.class);
|
||||
intent.putExtra(EditCommentActivity.EXTRA_FULLNAME, comment.getFullName());
|
||||
intent.putExtra(EditCommentActivity.EXTRA_FULLNAME, comment.getId());
|
||||
intent.putExtra(EditCommentActivity.EXTRA_CONTENT, comment.getCommentMarkdown());
|
||||
intent.putExtra(EditCommentActivity.EXTRA_POSITION, bundle.getInt(EXTRA_POSITION));
|
||||
if (activity instanceof ViewPostDetailActivity) {
|
||||
@@ -127,9 +111,9 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
|
||||
deleteTextView.setOnClickListener(view -> {
|
||||
dismiss();
|
||||
if (activity instanceof ViewPostDetailActivity) {
|
||||
((ViewPostDetailActivity) activity).deleteComment(comment.getFullName(), bundle.getInt(EXTRA_POSITION));
|
||||
((ViewPostDetailActivity) activity).deleteComment(comment.getId(), bundle.getInt(EXTRA_POSITION));
|
||||
} else if (activity instanceof ViewUserDetailActivity) {
|
||||
((ViewUserDetailActivity) activity).deleteComment(comment.getFullName());
|
||||
((ViewUserDetailActivity) activity).deleteComment(comment.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -193,27 +177,14 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
|
||||
});
|
||||
|
||||
reportTextView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(activity, ReportActivity.class);
|
||||
/*Intent intent = new Intent(activity, ReportActivity.class);
|
||||
intent.putExtra(ReportActivity.EXTRA_SUBREDDIT_NAME, comment.getCommunityName());
|
||||
intent.putExtra(ReportActivity.EXTRA_THING_FULLNAME, comment.getFullName());
|
||||
activity.startActivity(intent);
|
||||
|
||||
activity.startActivity(intent);*/
|
||||
Toast.makeText(activity, R.string.not_implemented, Toast.LENGTH_SHORT).show();
|
||||
dismiss();
|
||||
});
|
||||
|
||||
if ("[deleted]".equals(comment.getAuthor()) ||
|
||||
"[deleted]".equals(comment.getCommentRawText()) ||
|
||||
"[removed]".equals(comment.getCommentRawText())
|
||||
) {
|
||||
seeRemovedTextView.setVisibility(View.VISIBLE);
|
||||
|
||||
seeRemovedTextView.setOnClickListener(view -> {
|
||||
dismiss();
|
||||
if (activity instanceof ViewPostDetailActivity) {
|
||||
((ViewPostDetailActivity) activity).showRemovedComment(comment, bundle.getInt(EXTRA_POSITION));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (activity.typeface != null) {
|
||||
Utils.setFontToAllTextViews(rootView, activity.typeface);
|
||||
|
||||
@@ -24,7 +24,6 @@ public class FABMoreOptionsBottomSheetFragment extends LandscapeExpandedRoundedB
|
||||
public static final int FAB_OPTION_SEARCH = 4;
|
||||
public static final int FAB_OPTION_GO_TO_SUBREDDIT = 5;
|
||||
public static final int FAB_OPTION_GO_TO_USER = 6;
|
||||
public static final int FAB_RANDOM = 7;
|
||||
public static final int FAB_HIDE_READ_POSTS = 8;
|
||||
public static final int FAB_FILTER_POSTS = 9;
|
||||
public static final int FAB_GO_TO_TOP = 10;
|
||||
@@ -86,10 +85,6 @@ public class FABMoreOptionsBottomSheetFragment extends LandscapeExpandedRoundedB
|
||||
dismiss();
|
||||
});
|
||||
|
||||
binding.randomTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
|
||||
activity.fabOptionSelected(FAB_RANDOM);
|
||||
dismiss();
|
||||
});
|
||||
|
||||
binding.filterPostsTextViewFabMoreOptionsBottomSheetFragment.setOnClickListener(view -> {
|
||||
activity.fabOptionSelected(FAB_FILTER_POSTS);
|
||||
|
||||
@@ -38,12 +38,6 @@ public class PostTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS
|
||||
TextView linkTypeTextView;
|
||||
@BindView(R.id.image_type_linear_layout_post_type_bottom_sheet_fragment)
|
||||
TextView imageTypeTextView;
|
||||
@BindView(R.id.video_type_linear_layout_post_type_bottom_sheet_fragment)
|
||||
TextView videoTypeTextView;
|
||||
@BindView(R.id.gallery_type_linear_layout_post_type_bottom_sheet_fragment)
|
||||
TextView galleryTypeTextView;
|
||||
@BindView(R.id.poll_type_linear_layout_post_type_bottom_sheet_fragment)
|
||||
TextView pollTypeTextView;
|
||||
private BaseActivity activity;
|
||||
|
||||
public PostTypeBottomSheetFragment() {
|
||||
@@ -76,20 +70,6 @@ public class PostTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS
|
||||
dismiss();
|
||||
});
|
||||
|
||||
videoTypeTextView.setOnClickListener(view -> {
|
||||
((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_VIDEO);
|
||||
dismiss();
|
||||
});
|
||||
|
||||
galleryTypeTextView.setOnClickListener(view -> {
|
||||
((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_GALLERY);
|
||||
dismiss();
|
||||
});
|
||||
|
||||
pollTypeTextView.setOnClickListener(view -> {
|
||||
((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_POLL);
|
||||
dismiss();
|
||||
});
|
||||
|
||||
if (activity.typeface != null) {
|
||||
Utils.setFontToAllTextViews(rootView, activity.typeface);
|
||||
|
||||
@@ -31,16 +31,12 @@ public class SearchPostSortTypeBottomSheetFragment extends LandscapeExpandedRoun
|
||||
|
||||
public static final String EXTRA_CURRENT_SORT_TYPE = "ECST";
|
||||
|
||||
@BindView(R.id.relevance_type_text_view_search_sort_type_bottom_sheet_fragment)
|
||||
TextView relevanceTypeTextView;
|
||||
@BindView(R.id.hot_type_text_view_search_sort_type_bottom_sheet_fragment)
|
||||
TextView hotTypeTextView;
|
||||
@BindView(R.id.top_type_text_view_search_sort_type_bottom_sheet_fragment)
|
||||
TextView topTypeTextView;
|
||||
@BindView(R.id.new_type_text_view_search_sort_type_bottom_sheet_fragment)
|
||||
TextView newTypeTextView;
|
||||
@BindView(R.id.comments_type_text_view_search_sort_type_bottom_sheet_fragment)
|
||||
TextView commentsTypeTextView;
|
||||
@BindView(R.id.old_type_text_view_search_sort_type_bottom_sheet_fragment)
|
||||
TextView oldTypeTextView;
|
||||
private BaseActivity activity;
|
||||
public SearchPostSortTypeBottomSheetFragment() {
|
||||
// Required empty public constructor
|
||||
@@ -61,14 +57,12 @@ public class SearchPostSortTypeBottomSheetFragment extends LandscapeExpandedRoun
|
||||
ButterKnife.bind(this, rootView);
|
||||
|
||||
String currentSortType = getArguments().getString(EXTRA_CURRENT_SORT_TYPE);
|
||||
if (currentSortType.equals(SortType.Type.HOT.fullName)) {
|
||||
hotTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(hotTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
|
||||
} else if (currentSortType.equals(SortType.Type.TOP.fullName)) {
|
||||
if (currentSortType.equals(SortType.Type.TOP.fullName)) {
|
||||
topTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(topTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
|
||||
} else if (currentSortType.equals(SortType.Type.NEW.fullName)) {
|
||||
newTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(newTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
|
||||
} else if (currentSortType.equals(SortType.Type.OLD.fullName)) {
|
||||
commentsTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(commentsTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
|
||||
oldTypeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(oldTypeTextView.getCompoundDrawablesRelative()[0], null, AppCompatResources.getDrawable(activity, R.drawable.ic_round_check_circle_day_night_24dp), null);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
@@ -76,15 +70,6 @@ public class SearchPostSortTypeBottomSheetFragment extends LandscapeExpandedRoun
|
||||
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
|
||||
}
|
||||
|
||||
/*relevanceTypeTextView.setOnClickListener(view -> {
|
||||
((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.RELEVANCE.name());
|
||||
dismiss();
|
||||
});*/
|
||||
|
||||
hotTypeTextView.setOnClickListener(view -> {
|
||||
((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.HOT.name());
|
||||
dismiss();
|
||||
});
|
||||
|
||||
topTypeTextView.setOnClickListener(view -> {
|
||||
((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.TOP.name());
|
||||
@@ -92,12 +77,12 @@ public class SearchPostSortTypeBottomSheetFragment extends LandscapeExpandedRoun
|
||||
});
|
||||
|
||||
newTypeTextView.setOnClickListener(view -> {
|
||||
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.NEW));
|
||||
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.NEW,null));
|
||||
dismiss();
|
||||
});
|
||||
|
||||
commentsTypeTextView.setOnClickListener(view -> {
|
||||
((SortTypeSelectionCallback) activity).sortTypeSelected(SortType.Type.MOST_COMMENTS.name());
|
||||
oldTypeTextView.setOnClickListener(view -> {
|
||||
((SortTypeSelectionCallback) activity).sortTypeSelected(new SortType(SortType.Type.OLD,null));
|
||||
dismiss();
|
||||
});
|
||||
|
||||
|
||||
@@ -49,6 +49,8 @@ public class Comment implements Parcelable {
|
||||
private int depth;
|
||||
private int childCount;
|
||||
private boolean collapsed;
|
||||
|
||||
private boolean isDeleted;
|
||||
private boolean hasReply;
|
||||
private boolean saved;
|
||||
private boolean isExpanded;
|
||||
@@ -67,7 +69,7 @@ public class Comment implements Parcelable {
|
||||
long commentTimeMillis, String commentMarkdown, String commentRawText,
|
||||
String linkId, String communityName, String communityQualifiedName, Integer parentId, int score,
|
||||
int voteType, boolean isSubmitter, String distinguished, String permalink,
|
||||
int depth, boolean collapsed, boolean hasReply, boolean saved, long edited, String[] path) {
|
||||
int depth, boolean collapsed, boolean hasReply, boolean saved, boolean deleted, long edited, String[] path) {
|
||||
this.id = id;
|
||||
this.postId = postId;
|
||||
this.fullName = fullName;
|
||||
@@ -90,6 +92,7 @@ public class Comment implements Parcelable {
|
||||
this.collapsed = collapsed;
|
||||
this.hasReply = hasReply;
|
||||
this.saved = saved;
|
||||
this.isDeleted = deleted;
|
||||
this.isExpanded = false;
|
||||
this.hasExpandedBefore = false;
|
||||
this.editedTimeMillis = edited;
|
||||
|
||||
@@ -16,16 +16,13 @@ import java.util.Locale;
|
||||
|
||||
import eu.toldi.infinityforlemmy.NetworkState;
|
||||
import eu.toldi.infinityforlemmy.SortType;
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
public class CommentDataSource extends PageKeyedDataSource<Integer, Comment> {
|
||||
|
||||
private Retrofit retrofit;
|
||||
private Locale locale;
|
||||
@@ -39,8 +36,8 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
private MutableLiveData<NetworkState> initialLoadStateLiveData;
|
||||
private MutableLiveData<Boolean> hasPostLiveData;
|
||||
|
||||
private LoadParams<String> params;
|
||||
private LoadCallback<String, Comment> callback;
|
||||
private LoadParams<Integer> params;
|
||||
private LoadCallback<Integer, Comment> callback;
|
||||
|
||||
CommentDataSource(Retrofit retrofit, Locale locale, @Nullable String accessToken, String username, SortType sortType,
|
||||
boolean areSavedComments) {
|
||||
@@ -72,42 +69,27 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull LoadInitialCallback<String, Comment> callback) {
|
||||
public void loadInitial(@NonNull LoadInitialParams<Integer> params, @NonNull LoadInitialCallback<Integer, Comment> callback) {
|
||||
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
||||
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
Call<String> commentsCall;
|
||||
if (areSavedComments) {
|
||||
commentsCall = api.getUserSavedCommentsOauth(username, PostPagingSource.USER_WHERE_SAVED,
|
||||
null, sortType.getType(), sortType.getTime(),
|
||||
APIUtils.getOAuthHeader(accessToken));
|
||||
} else {
|
||||
if (accessToken == null) {
|
||||
commentsCall = api.getUserComments(username, null, sortType.getType(),
|
||||
sortType.getTime());
|
||||
} else {
|
||||
commentsCall = api.getUserCommentsOauth(APIUtils.getOAuthHeader(accessToken), username,
|
||||
null, sortType.getType(), sortType.getTime());
|
||||
}
|
||||
}
|
||||
LemmyAPI api = retrofit.create(LemmyAPI.class);
|
||||
Call<String> commentsCall = api.getUserComments(username, sortType.getType().value, 1, 25, areSavedComments, accessToken);
|
||||
|
||||
commentsCall.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
new ParseCommentAsyncTask(response.body(), locale, new ParseCommentAsyncTask.ParseCommentAsyncTaskListener() {
|
||||
@Override
|
||||
public void parseSuccessful(ArrayList<Comment> comments, String after) {
|
||||
if (comments.size() == 0) {
|
||||
public void parseSuccessful(ArrayList<Comment> comments, Integer after) {
|
||||
if (comments.isEmpty()) {
|
||||
callback.onResult(comments, null, null);
|
||||
hasPostLiveData.postValue(false);
|
||||
} else {
|
||||
hasPostLiveData.postValue(true);
|
||||
callback.onResult(comments, null, 2);
|
||||
}
|
||||
|
||||
if (after == null || after.equals("") || after.equals("null")) {
|
||||
callback.onResult(comments, null, null);
|
||||
} else {
|
||||
callback.onResult(comments, null, after);
|
||||
}
|
||||
initialLoadStateLiveData.postValue(NetworkState.LOADED);
|
||||
}
|
||||
|
||||
@@ -129,39 +111,27 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadBefore(@NonNull LoadParams<String> params, @NonNull LoadCallback<String, Comment> callback) {
|
||||
public void loadBefore(@NonNull LoadParams<Integer> params, @NonNull LoadCallback<Integer, Comment> callback) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAfter(@NonNull LoadParams<String> params, @NonNull LoadCallback<String, Comment> callback) {
|
||||
public void loadAfter(@NonNull LoadParams<Integer> params, @NonNull LoadCallback<Integer, Comment> callback) {
|
||||
this.params = params;
|
||||
this.callback = callback;
|
||||
|
||||
paginationNetworkStateLiveData.postValue(NetworkState.LOADING);
|
||||
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
Call<String> commentsCall;
|
||||
if (areSavedComments) {
|
||||
commentsCall = api.getUserSavedCommentsOauth(username, PostPagingSource.USER_WHERE_SAVED, params.key,
|
||||
sortType.getType(), sortType.getTime(), APIUtils.getOAuthHeader(accessToken));
|
||||
} else {
|
||||
if (accessToken == null) {
|
||||
commentsCall = api.getUserComments(username, params.key, sortType.getType(),
|
||||
sortType.getTime());
|
||||
} else {
|
||||
commentsCall = api.getUserCommentsOauth(APIUtils.getOAuthHeader(accessToken),
|
||||
username, params.key, sortType.getType(), sortType.getTime());
|
||||
}
|
||||
}
|
||||
LemmyAPI api = retrofit.create(LemmyAPI.class);
|
||||
Call<String> commentsCall = api.getUserComments(username, sortType.getType().value, params.key, 25, areSavedComments, accessToken);
|
||||
commentsCall.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
new ParseCommentAsyncTask(response.body(), locale, new ParseCommentAsyncTask.ParseCommentAsyncTaskListener() {
|
||||
@Override
|
||||
public void parseSuccessful(ArrayList<Comment> comments, String after) {
|
||||
if (after == null || after.equals("") || after.equals("null")) {
|
||||
public void parseSuccessful(ArrayList<Comment> comments, Integer after) {
|
||||
if (comments.isEmpty()) {
|
||||
callback.onResult(comments, null);
|
||||
} else {
|
||||
callback.onResult(comments, after);
|
||||
@@ -187,7 +157,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
}
|
||||
|
||||
private static class ParseCommentAsyncTask extends AsyncTask<Void, ArrayList<Comment>, ArrayList<Comment>> {
|
||||
private String after;
|
||||
private Integer after;
|
||||
private Locale locale;
|
||||
private JSONArray commentsJSONArray;
|
||||
private boolean parseFailed;
|
||||
@@ -197,9 +167,8 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
this.locale = locale;
|
||||
this.parseCommentAsyncTaskListener = parseCommentAsyncTaskListener;
|
||||
try {
|
||||
JSONObject data = new JSONObject(response).getJSONObject(JSONUtils.DATA_KEY);
|
||||
commentsJSONArray = data.getJSONArray(JSONUtils.CHILDREN_KEY);
|
||||
after = data.getString(JSONUtils.AFTER_KEY);
|
||||
JSONObject data = new JSONObject(response);
|
||||
commentsJSONArray = data.getJSONArray("comments");
|
||||
parseFailed = false;
|
||||
} catch (JSONException e) {
|
||||
parseFailed = true;
|
||||
@@ -216,7 +185,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
ArrayList<Comment> comments = new ArrayList<>();
|
||||
for (int i = 0; i < commentsJSONArray.length(); i++) {
|
||||
try {
|
||||
JSONObject commentJSON = commentsJSONArray.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
||||
JSONObject commentJSON = commentsJSONArray.getJSONObject(i);
|
||||
comments.add(ParseComment.parseSingleComment(commentJSON));
|
||||
} catch (JSONException ignored) {
|
||||
}
|
||||
@@ -235,7 +204,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
}
|
||||
|
||||
interface ParseCommentAsyncTaskListener {
|
||||
void parseSuccessful(ArrayList<Comment> comments, String after);
|
||||
void parseSuccessful(ArrayList<Comment> comments, Integer page);
|
||||
|
||||
void parseFailed();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import android.os.Handler;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@@ -98,6 +101,32 @@ public class FetchComment {
|
||||
});
|
||||
}
|
||||
|
||||
public static void fetchSingleComment(Retrofit retrofit, @Nullable String accessToken, int commentId,
|
||||
FetchCommentListener fetchCommentListener) {
|
||||
LemmyAPI api = retrofit.create(LemmyAPI.class);
|
||||
Call<String> comment = api.getComment(commentId, accessToken);
|
||||
comment.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
try {
|
||||
Comment c = ParseComment.parseSingleComment(new JSONObject(response.body()).getJSONObject("comment_view"));
|
||||
ArrayList<Comment> comments = new ArrayList<>();
|
||||
comments.add(c);
|
||||
fetchCommentListener.onFetchCommentSuccess(comments, null, null);
|
||||
} catch (JSONException e) {
|
||||
fetchCommentListener.onFetchCommentFailed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
fetchCommentListener.onFetchCommentFailed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface FetchCommentListener {
|
||||
void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children);
|
||||
|
||||
|
||||
@@ -9,13 +9,18 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -34,7 +39,6 @@ public class ParseComment {
|
||||
|
||||
ArrayList<Comment> expandedNewComments = new ArrayList<>();
|
||||
ArrayList<Integer> moreChildrenIds = new ArrayList<>();
|
||||
ArrayList<Comment> newComments = new ArrayList<>();
|
||||
|
||||
|
||||
Map<Integer, Comment> parsedComments = new HashMap<>();
|
||||
@@ -49,8 +53,13 @@ public class ParseComment {
|
||||
}
|
||||
}
|
||||
Comment parentComment = (commentId != null) ? parsedComments.get(commentId) : null;
|
||||
if (parentComment != null && parentComment.getDepth() == 0)
|
||||
parentComment = null;
|
||||
if (parentComment != null) {
|
||||
if (parentComment.getDepth() == 0) {
|
||||
parentComment = null;
|
||||
} else {
|
||||
expandedNewComments.add(parentComment);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = orderedComments.size() - 1; i >= 0; i--) {
|
||||
Comment c = orderedComments.get(i);
|
||||
@@ -64,9 +73,7 @@ public class ParseComment {
|
||||
}
|
||||
|
||||
//Add all comments to newComments
|
||||
for (int i = 0; i < topLevelComments.size(); i++) {
|
||||
newComments.add(topLevelComments.get(i));
|
||||
}
|
||||
ArrayList<Comment> newComments = new ArrayList<>(topLevelComments);
|
||||
|
||||
expandChildren(newComments, expandedNewComments, expandChildren);
|
||||
|
||||
@@ -277,19 +284,42 @@ public class ParseComment {
|
||||
String author = creatorObj.getString("name");
|
||||
String authorQualifiedName = LemmyUtils.actorID2FullName(creatorObj.getString("actor_id"));
|
||||
String linkAuthor = creatorObj.getString("actor_id");
|
||||
|
||||
|
||||
String authorAvatar = null;
|
||||
if(creatorObj.has("avatar")){
|
||||
authorAvatar = creatorObj.getString("avatar");
|
||||
}
|
||||
long commentTimeMillis = 0;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
commentTimeMillis = ZonedDateTime.parse(commentObj.getString("published"),
|
||||
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.of("Z"))).toInstant().toEpochMilli();
|
||||
} else {
|
||||
String dateStr = commentObj.getString("published");
|
||||
|
||||
dateStr = dateStr.substring(0, dateStr.lastIndexOf(".") + 4) + 'Z';
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
try {
|
||||
Date date = sdf.parse(dateStr);
|
||||
if (date != null) {
|
||||
commentTimeMillis = date.getTime();
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
String commentMarkdown = commentObj.getString("content");
|
||||
String commentRawText = commentObj.getString("content");
|
||||
String content = commentObj.getString("content");
|
||||
String commentMarkdown = content;
|
||||
String commentRawText = content;
|
||||
String linkId = postObj.getString("id");
|
||||
String communityName = communityObj.getString("name");
|
||||
String communityQualifiedName = communityObj.getString("actor_id");
|
||||
String communityQualifiedName = LemmyUtils.actorID2FullName(communityObj.getString("actor_id"));
|
||||
|
||||
int score = countsObj.getInt("score");
|
||||
int voteType = (jsonObject.isNull("my_vote")) ? 0 : jsonObject.getInt("my_vote");
|
||||
if (voteType != 0)
|
||||
score -= 1;
|
||||
boolean isSubmitter = creatorObj.getInt("id") == postObj.getInt("creator_id");
|
||||
String distinguished = commentObj.getString("distinguished");
|
||||
String permalink = commentObj.getString("ap_id");
|
||||
@@ -302,13 +332,15 @@ public class ParseComment {
|
||||
boolean collapsed = false;
|
||||
boolean hasReply = countsObj.getInt("child_count") > 0;
|
||||
boolean saved = jsonObject.getBoolean("saved");
|
||||
boolean deleted = commentObj.getBoolean("deleted");
|
||||
long edited = 0;
|
||||
|
||||
Comment comment = new Comment(id,postID, fullName, author, authorQualifiedName, linkAuthor, commentTimeMillis,
|
||||
Comment comment = new Comment(id, postID, fullName, author, authorQualifiedName, linkAuthor, commentTimeMillis,
|
||||
commentMarkdown, commentRawText, linkId, communityName, communityQualifiedName, parentId,
|
||||
score, voteType, isSubmitter, distinguished, permalink, depth, collapsed, hasReply, saved, edited, path);
|
||||
score, voteType, isSubmitter, distinguished, permalink, depth, collapsed, hasReply, saved, deleted, edited, path);
|
||||
int child_count = countsObj.getInt("child_count");
|
||||
comment.setChildCount(child_count);
|
||||
comment.setAuthorIconUrl(authorAvatar);
|
||||
return comment;
|
||||
}
|
||||
|
||||
|
||||
14
app/src/main/java/eu/toldi/infinityforlemmy/dto/AuthDTO.java
Normal file
14
app/src/main/java/eu/toldi/infinityforlemmy/dto/AuthDTO.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class AuthDTO {
|
||||
|
||||
private String auth;
|
||||
|
||||
public AuthDTO(String auth) {
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class DeleteCommentDTO {
|
||||
|
||||
private int comment_id;
|
||||
boolean deleted;
|
||||
String auth;
|
||||
|
||||
public DeleteCommentDTO(int comment_id, boolean deleted, String auth) {
|
||||
this.comment_id = comment_id;
|
||||
this.deleted = deleted;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getComment_id() {
|
||||
return comment_id;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class DeletePostDTO {
|
||||
|
||||
int post_id;
|
||||
boolean deleted;
|
||||
String auth;
|
||||
|
||||
public DeletePostDTO(int post_id, boolean deleted, String auth) {
|
||||
this.post_id = post_id;
|
||||
this.deleted = deleted;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getPost_id() {
|
||||
return post_id;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class EditCommentDTO {
|
||||
|
||||
private int comment_id;
|
||||
private String content;
|
||||
private Integer language_id;
|
||||
private String form_id;
|
||||
private String auth;
|
||||
|
||||
public EditCommentDTO(int comment_id, String content, Integer language_id, String form_id, String auth) {
|
||||
this.comment_id = comment_id;
|
||||
this.content = content;
|
||||
this.language_id = language_id;
|
||||
this.form_id = form_id;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getComment_id() {
|
||||
return comment_id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public Integer getLanguage_id() {
|
||||
return language_id;
|
||||
}
|
||||
|
||||
public String getForm_id() {
|
||||
return form_id;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class EditPostDTO {
|
||||
|
||||
private int post_id;
|
||||
private String name;
|
||||
private String url;
|
||||
private String body;
|
||||
private boolean nsfw;
|
||||
private Integer language_id;
|
||||
private String auth;
|
||||
|
||||
public EditPostDTO(int post_id, String name, String url, String body, boolean nsfw, Integer language_id, String auth) {
|
||||
this.post_id = post_id;
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.body = body;
|
||||
this.nsfw = nsfw;
|
||||
this.language_id = language_id;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getPost_id() {
|
||||
return post_id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public boolean isNsfw() {
|
||||
return nsfw;
|
||||
}
|
||||
|
||||
public Integer getLanguage_id() {
|
||||
return language_id;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class FollowCommunityDTO {
|
||||
|
||||
private int community_id;
|
||||
private boolean follow;
|
||||
private String auth;
|
||||
|
||||
public FollowCommunityDTO(int community_id, boolean follow, String auth) {
|
||||
this.community_id = community_id;
|
||||
this.follow = follow;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getCommunity_id() {
|
||||
return community_id;
|
||||
}
|
||||
|
||||
public boolean isFollow() {
|
||||
return follow;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class ReadCommentDTO {
|
||||
|
||||
private int comment_reply_id;
|
||||
private boolean read;
|
||||
private String auth;
|
||||
|
||||
public ReadCommentDTO(int comment_reply_id, boolean read, String auth) {
|
||||
this.comment_reply_id = comment_reply_id;
|
||||
this.read = read;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getComment_reply_id() {
|
||||
return comment_reply_id;
|
||||
}
|
||||
|
||||
public boolean isRead() {
|
||||
return read;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class ReadMessageDTO {
|
||||
|
||||
private int person_mention_id;
|
||||
private boolean read;
|
||||
private String auth;
|
||||
|
||||
public ReadMessageDTO(int person_mention_id, boolean read, String auth) {
|
||||
this.person_mention_id = person_mention_id;
|
||||
this.read = read;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getPerson_mention_id() {
|
||||
return person_mention_id;
|
||||
}
|
||||
|
||||
public boolean isRead() {
|
||||
return read;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class ReadPostDTO {
|
||||
|
||||
private int post_id;
|
||||
private boolean read;
|
||||
private String auth;
|
||||
|
||||
public ReadPostDTO(int post_id, boolean read, String auth) {
|
||||
this.post_id = post_id;
|
||||
this.read = read;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getPost_id() {
|
||||
return post_id;
|
||||
}
|
||||
|
||||
public boolean isRead() {
|
||||
return read;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class SaveCommentDTO {
|
||||
|
||||
private int comment_id;
|
||||
private boolean save;
|
||||
private String auth;
|
||||
|
||||
public SaveCommentDTO(int comment_id, boolean save, String auth) {
|
||||
this.comment_id = comment_id;
|
||||
this.save = save;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getComment_id() {
|
||||
return comment_id;
|
||||
}
|
||||
|
||||
public boolean isSave() {
|
||||
return save;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class SavePostDTO {
|
||||
|
||||
|
||||
private int post_id;
|
||||
private boolean save;
|
||||
private String auth;
|
||||
|
||||
public SavePostDTO(int post_id, boolean save, String auth) {
|
||||
this.post_id = post_id;
|
||||
this.save = save;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getPost_id() {
|
||||
return post_id;
|
||||
}
|
||||
|
||||
public boolean isSave() {
|
||||
return save;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class SubmitPostDTO {
|
||||
|
||||
private String name;
|
||||
private int community_id;
|
||||
private String url;
|
||||
private String body;
|
||||
private String honeypot;
|
||||
private boolean nsfw;
|
||||
private Integer language_id;
|
||||
private String auth;
|
||||
|
||||
public SubmitPostDTO(String name, int community_id, String url, String body, String honeypot, boolean nsfw, Integer language_id, String auth) {
|
||||
this.name = name;
|
||||
this.community_id = community_id;
|
||||
this.url = url;
|
||||
this.body = body;
|
||||
this.honeypot = honeypot;
|
||||
this.nsfw = nsfw;
|
||||
this.language_id = language_id;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getCommunity_id() {
|
||||
return community_id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public String getHoneypot() {
|
||||
return honeypot;
|
||||
}
|
||||
|
||||
public boolean isNsfw() {
|
||||
return nsfw;
|
||||
}
|
||||
|
||||
public Integer getLanguage_id() {
|
||||
return language_id;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package eu.toldi.infinityforlemmy.events;
|
||||
|
||||
public class ChangeUseCircularFabEvent {
|
||||
|
||||
private boolean useCircularFab;
|
||||
|
||||
public ChangeUseCircularFabEvent(boolean useCircularFab) {
|
||||
this.useCircularFab = useCircularFab;
|
||||
}
|
||||
|
||||
public boolean isUseCircularFab() {
|
||||
return useCircularFab;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package eu.toldi.infinityforlemmy.events;
|
||||
|
||||
import eu.toldi.infinityforlemmy.message.Message;
|
||||
import eu.toldi.infinityforlemmy.message.CommentInteraction;
|
||||
|
||||
public class PassPrivateMessageEvent {
|
||||
public Message message;
|
||||
public CommentInteraction message;
|
||||
|
||||
public PassPrivateMessageEvent(Message message) {
|
||||
public PassPrivateMessageEvent(CommentInteraction message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package eu.toldi.infinityforlemmy.events;
|
||||
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
|
||||
public class SubmitImagePostEvent {
|
||||
public boolean postSuccess;
|
||||
public String errorMessage;
|
||||
public Post post;
|
||||
|
||||
public SubmitImagePostEvent(boolean postSuccess, String errorMessage) {
|
||||
public SubmitImagePostEvent(boolean postSuccess, String errorMessage, Post post) {
|
||||
this.postSuccess = postSuccess;
|
||||
this.errorMessage = errorMessage;
|
||||
this.post = post;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
|
||||
/**
|
||||
@@ -82,9 +81,6 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Inject
|
||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
@Inject
|
||||
@Named("default")
|
||||
@@ -253,6 +249,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
|
||||
|
||||
new Handler().postDelayed(() -> bindView(resources), 0);
|
||||
|
||||
return rootView;
|
||||
@@ -263,7 +260,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
||||
mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity);
|
||||
mCommentRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||
|
||||
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit, customThemeWrapper,
|
||||
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mRetrofit.getRetrofit(), customThemeWrapper,
|
||||
getResources().getConfiguration().locale, mSharedPreferences,
|
||||
getArguments().getString(EXTRA_ACCESS_TOKEN), getArguments().getString(EXTRA_ACCOUNT_NAME),
|
||||
() -> mCommentViewModel.retryLoadingMore());
|
||||
@@ -294,15 +291,11 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
||||
|
||||
CommentViewModel.Factory factory;
|
||||
|
||||
if (mAccessToken == null) {
|
||||
factory = new CommentViewModel.Factory(mRetrofit.getRetrofit(),
|
||||
resources.getConfiguration().locale, null, username, sortType,
|
||||
getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
|
||||
} else {
|
||||
factory = new CommentViewModel.Factory(mOauthRetrofit,
|
||||
resources.getConfiguration().locale, mAccessToken, username, sortType,
|
||||
getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
|
||||
}
|
||||
|
||||
factory = new CommentViewModel.Factory(mRetrofit.getRetrofit(),
|
||||
resources.getConfiguration().locale, mAccessToken, username, sortType,
|
||||
getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
|
||||
|
||||
|
||||
mCommentViewModel = new ViewModelProvider(this, factory).get(CommentViewModel.class);
|
||||
mCommentViewModel.getComments().observe(getViewLifecycleOwner(), comments -> mAdapter.submitList(comments));
|
||||
|
||||
@@ -380,7 +380,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
|
||||
if (historyType == HISTORY_TYPE_READ_POSTS) {
|
||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.HISTORY_POST_LAYOUT_READ_POST, defaultPostLayout);
|
||||
|
||||
mAdapter = new HistoryPostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
|
||||
mAdapter = new HistoryPostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
|
||||
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
|
||||
accessToken, accountName, postType, postLayout, true,
|
||||
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences,
|
||||
|
||||
@@ -35,15 +35,15 @@ import eu.toldi.infinityforlemmy.NetworkState;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RecyclerViewContentScrollingInterface;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.activities.BaseActivity;
|
||||
import eu.toldi.infinityforlemmy.adapters.MessageRecyclerViewAdapter;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
import eu.toldi.infinityforlemmy.events.RepliedToPrivateMessageEvent;
|
||||
import eu.toldi.infinityforlemmy.message.CommentInteraction;
|
||||
import eu.toldi.infinityforlemmy.message.FetchMessage;
|
||||
import eu.toldi.infinityforlemmy.message.Message;
|
||||
import eu.toldi.infinityforlemmy.message.MessageViewModel;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class InboxFragment extends Fragment implements FragmentCommunicator {
|
||||
|
||||
@@ -61,8 +61,8 @@ public class InboxFragment extends Fragment implements FragmentCommunicator {
|
||||
TextView mFetchMessageInfoTextView;
|
||||
MessageViewModel mMessageViewModel;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
@Inject
|
||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
@Inject
|
||||
@@ -106,7 +106,7 @@ public class InboxFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
|
||||
mWhere = arguments.getString(EXTRA_MESSAGE_WHERE, FetchMessage.WHERE_INBOX);
|
||||
mAdapter = new MessageRecyclerViewAdapter(mActivity, mOauthRetrofit, mCustomThemeWrapper,
|
||||
mAdapter = new MessageRecyclerViewAdapter(mActivity, mRetrofit.getRetrofit(), mCustomThemeWrapper,
|
||||
mAccessToken, mWhere, () -> mMessageViewModel.retryLoadingMore());
|
||||
mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity);
|
||||
mRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||
@@ -127,7 +127,7 @@ public class InboxFragment extends Fragment implements FragmentCommunicator {
|
||||
});
|
||||
}
|
||||
|
||||
MessageViewModel.Factory factory = new MessageViewModel.Factory(mOauthRetrofit,
|
||||
MessageViewModel.Factory factory = new MessageViewModel.Factory(mRetrofit.getRetrofit(),
|
||||
getResources().getConfiguration().locale, mAccessToken, mWhere);
|
||||
mMessageViewModel = new ViewModelProvider(this, factory).get(MessageViewModel.class);
|
||||
mMessageViewModel.getMessages().observe(getViewLifecycleOwner(), messages -> mAdapter.submitList(messages));
|
||||
@@ -216,11 +216,11 @@ public class InboxFragment extends Fragment implements FragmentCommunicator {
|
||||
mAdapter.setNetworkState(null);
|
||||
}
|
||||
|
||||
public Message getMessageByIndex(int index) {
|
||||
public CommentInteraction getMessageByIndex(int index) {
|
||||
if (mMessageViewModel == null || index < 0) {
|
||||
return null;
|
||||
}
|
||||
PagedList<Message> messages = mMessageViewModel.getMessages().getValue();
|
||||
PagedList<CommentInteraction> messages = mMessageViewModel.getMessages().getValue();
|
||||
if (messages == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -245,8 +245,8 @@ public class InboxFragment extends Fragment implements FragmentCommunicator {
|
||||
|
||||
@Subscribe
|
||||
public void onRepliedToPrivateMessageEvent(RepliedToPrivateMessageEvent repliedToPrivateMessageEvent) {
|
||||
if (mAdapter != null && mWhere.equals(FetchMessage.WHERE_MESSAGES)) {
|
||||
/* if (mAdapter != null && mWhere.equals(FetchMessage.WHERE_MESSAGES)) {
|
||||
mAdapter.updateMessageReply(repliedToPrivateMessageEvent.newReply, repliedToPrivateMessageEvent.messagePosition);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user