Compare commits
184 Commits
3.1.0-rc2
...
7-assign-t
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71d7f543a6 | ||
|
|
244dc12fc3 | ||
|
|
8ea7e470c5 | ||
|
|
77edf450c6 | ||
|
|
e0ff35d530 | ||
|
|
f88a2df749 | ||
|
|
bb392fb639 | ||
|
|
6a6ecd251a | ||
|
|
1693acaa70 | ||
|
|
1e8c8efd6b | ||
|
|
5544ae4248 | ||
|
|
36f20bb1aa | ||
|
|
0e696eb46f | ||
|
|
2b3b0fbe0f | ||
|
|
f96827488b | ||
|
|
8d0df59bfe | ||
|
|
d567a012d8 | ||
|
|
0fc845e058 | ||
|
|
b97fa45b18 | ||
|
|
d458d60122 | ||
|
|
881aad5f2d | ||
|
|
547e7c705d | ||
|
|
cc70fe9a68 | ||
|
|
3b3b0ada2f | ||
|
|
a9f1010add | ||
|
|
c8872ade9f | ||
|
|
960eaa1cf9 | ||
|
|
224ead33bf | ||
|
|
1dd615fcae | ||
|
|
36808b1dbb | ||
|
|
8741074906 | ||
|
|
23b8301fbf | ||
|
|
cd902ff1ca | ||
|
|
d72f097012 | ||
|
|
9d3cd49d23 | ||
|
|
e8f938bdb0 | ||
|
|
27a4bab73c | ||
|
|
8312983ed3 | ||
|
|
69a5f00771 | ||
|
|
8104889bf6 | ||
|
|
bd3e6ff20a | ||
|
|
a384128c8f | ||
|
|
a47be21017 | ||
|
|
4b140f3195 | ||
|
|
4ccc66b04e | ||
|
|
7c6247782b | ||
|
|
3e5fca4f52 | ||
|
|
a848cabcda | ||
|
|
0b8d8618ed | ||
|
|
62ce30db23 | ||
|
|
dc29a31e63 | ||
|
|
98cf1a1976 | ||
|
|
69b7984d85 | ||
|
|
ef3108db14 | ||
|
|
f1c88921bc | ||
|
|
26b623a35b | ||
|
|
fb0bd0299c | ||
|
|
c353275ab8 | ||
|
|
328dbaa01c | ||
|
|
ff915f1813 | ||
|
|
77e39952c1 | ||
|
|
afffb7c15a | ||
|
|
47d6c68410 | ||
|
|
57ce453661 | ||
|
|
d8a14105c9 | ||
|
|
711711274e | ||
|
|
44b8ad8d1c | ||
|
|
fc49e29703 | ||
|
|
7f8595defc | ||
|
|
eb858f3535 | ||
|
|
29653cade2 | ||
|
|
df3e1b9940 | ||
|
|
d72cd57cd7 | ||
|
|
1d15f9b1d2 | ||
|
|
cb241d80f3 | ||
|
|
3c381f372e | ||
|
|
2398995928 | ||
|
|
7faf800d02 | ||
|
|
1e838031e1 | ||
|
|
d0c06a65f4 | ||
|
|
c6ebca8a08 | ||
|
|
20b203c4ad | ||
|
|
b02c87b143 | ||
|
|
093204df43 | ||
|
|
a26737e510 | ||
|
|
371649b8ca | ||
|
|
5b92be3a28 | ||
|
|
8c62ecadbc | ||
|
|
b75bf84d43 | ||
|
|
5d2bb02b2d | ||
|
|
fef1597522 | ||
|
|
1f9a3eb85d | ||
|
|
a51ba4f2a8 | ||
|
|
4c4a7376cb | ||
|
|
bbbcb56b98 | ||
|
|
b871a1fb22 | ||
|
|
f2bc81210c | ||
|
|
a6e97a1b36 | ||
|
|
2ebcdf9186 | ||
|
|
272fc78df9 | ||
|
|
3aa819f3ef | ||
|
|
e9fa2984a1 | ||
|
|
240cdf5701 | ||
|
|
a170c10e43 | ||
|
|
d11da92fc4 | ||
|
|
3b53111981 | ||
|
|
ade7b797f1 | ||
|
|
f97f668363 | ||
|
|
639cf51027 | ||
|
|
a92da6a6d4 | ||
|
|
87379ae0b2 | ||
|
|
43166237ee | ||
|
|
a3bd5c2af2 | ||
|
|
0f5858f292 | ||
|
|
dcec158076 | ||
|
|
63d3c95501 | ||
|
|
f111f7f2df | ||
|
|
5807d11e8c | ||
|
|
4a9bde8731 | ||
|
|
f64e23dcc1 | ||
|
|
6a9144435e | ||
|
|
3c7b505b5b | ||
|
|
2064c40c7d | ||
|
|
65c0ecaad1 | ||
|
|
99925621f1 | ||
|
|
d3fe4d6d41 | ||
|
|
8e86fa668d | ||
|
|
044f6191bf | ||
|
|
9e19945ad4 | ||
|
|
fbd92eb06b | ||
|
|
cafb29f8b7 | ||
|
|
f727ec51b8 | ||
|
|
d346d68b4f | ||
|
|
57f0d23ef0 | ||
|
|
1e30c37d7c | ||
|
|
829320ca0c | ||
|
|
1bf023357b | ||
|
|
4d1d7a7204 | ||
|
|
3235caf07d | ||
|
|
0f014c2822 | ||
|
|
996983d7a3 | ||
|
|
00cfcbc9cf | ||
|
|
74669a9dcb | ||
|
|
d52d7a188e | ||
|
|
d20a773d1d | ||
|
|
bf19e52799 | ||
|
|
8612258174 | ||
|
|
a31abf0974 | ||
|
|
6d466e2542 | ||
|
|
01bd61ad8e | ||
|
|
4031c32fc8 | ||
|
|
d51d2d5164 | ||
|
|
7b8bc21a83 | ||
|
|
1c1f73eafc | ||
|
|
02672aef3d | ||
|
|
23fb1ce71f | ||
|
|
1f5eeb5632 | ||
|
|
78782d159a | ||
|
|
a009e5dac9 | ||
|
|
a75ffe0381 | ||
|
|
c4279dcd77 | ||
|
|
14b1256ce1 | ||
|
|
7b72815bcb | ||
|
|
5e6c600e71 | ||
|
|
dbf5be25a5 | ||
|
|
2bfe0b8d1a | ||
|
|
0c92eb3fa2 | ||
|
|
32f3080283 | ||
|
|
7342668a1b | ||
|
|
6f9bbe4c58 | ||
|
|
b2b42887f7 | ||
|
|
37f622b952 | ||
|
|
d677c90b01 | ||
|
|
23d3ba7f42 | ||
|
|
a42d888eb7 | ||
|
|
bbcffd67d6 | ||
|
|
00eb9c9135 | ||
|
|
28a23d30f8 | ||
|
|
82f874dc37 | ||
|
|
b60a0e7a92 | ||
|
|
185bdb863d | ||
|
|
da338fcc83 | ||
|
|
6d8a87358d | ||
|
|
5fc6cdde63 |
12
.drone.yml
12
.drone.yml
@@ -15,8 +15,8 @@ steps:
|
|||||||
image: zosiab/eclint:latest
|
image: zosiab/eclint:latest
|
||||||
depends_on: [ clone ]
|
depends_on: [ clone ]
|
||||||
commands:
|
commands:
|
||||||
- git pull origin master
|
- git pull origin main
|
||||||
- eclint check $(git diff --name-only origin/master)
|
- eclint check $(git diff --name-only origin/main)
|
||||||
|
|
||||||
# This may be used in the future, because it makes of intellij's native code inspection/formatting capabilities.
|
# This may be used in the future, because it makes of intellij's native code inspection/formatting capabilities.
|
||||||
# Additional information: https://www.jetbrains.com/help/idea/command-line-formatter.html
|
# Additional information: https://www.jetbrains.com/help/idea/command-line-formatter.html
|
||||||
@@ -54,7 +54,7 @@ trigger:
|
|||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
branch:
|
branch:
|
||||||
- master
|
- main
|
||||||
|
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
@@ -66,7 +66,7 @@ steps:
|
|||||||
- name: build
|
- name: build
|
||||||
image: nextcloudci/android:android-49
|
image: nextcloudci/android:android-49
|
||||||
commands:
|
commands:
|
||||||
- ./gradlew build
|
- ./gradlew assembleFreeRelease
|
||||||
|
|
||||||
- name: sign
|
- name: sign
|
||||||
image: nextcloudci/android:android-49
|
image: nextcloudci/android:android-49
|
||||||
@@ -78,7 +78,7 @@ steps:
|
|||||||
KEY_PASS:
|
KEY_PASS:
|
||||||
from_secret: KEY_PASS
|
from_secret: KEY_PASS
|
||||||
OUTPUT: signed.apk
|
OUTPUT: signed.apk
|
||||||
GITEA: https://gitea.com
|
INSTANCE: https://codeberg.org
|
||||||
KS_FILE: ci_keystore.jks
|
KS_FILE: ci_keystore.jks
|
||||||
KS_REPO:
|
KS_REPO:
|
||||||
from_secret: KS_REPO
|
from_secret: KS_REPO
|
||||||
@@ -101,4 +101,4 @@ trigger:
|
|||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
branch:
|
branch:
|
||||||
- master
|
- main
|
||||||
|
|||||||
@@ -1,32 +1,37 @@
|
|||||||
## # What do you want to address?
|
## # What do you want to address?
|
||||||
(This step is required; examples are shown below)
|
<!-- This step is required; examples are shown below -->
|
||||||
|
|
||||||
- [ ] Bug
|
- [ ] Bug
|
||||||
- [ ] Feature
|
- [ ] Feature
|
||||||
- [ ] Suggestion
|
- [ ] Suggestion
|
||||||
|
|
||||||
## # Describe your matter briefly
|
## # Describe your matter briefly
|
||||||
(This step is required)
|
<!-- This step is required. -->
|
||||||
|
<br><br>
|
||||||
|
|
||||||
|
##### What did you expect? <!-- Useful when addressing bugs -->
|
||||||
##### What did you expect? (Useful when addressing bugs)
|
|
||||||
---
|
---
|
||||||
_(This step is optional)_
|
<!-- This step is optional. -->
|
||||||
|
<br><br>
|
||||||
|
|
||||||
|
##### Some additional details <!-- Useful, when we are trying to reproduce a bug -->
|
||||||
##### Some additional details (Useful, when we are trying to reproduce a bug)
|
|
||||||
---
|
---
|
||||||
_(This step is optional; an example is shown below)_
|
<!-- This step is optional; an example is shown below -->
|
||||||
|
|
||||||
* The version of **Gitea** you are using:
|
* The version of **Gitea** you are using:
|
||||||
* The version of **GitNex** you are using:
|
* The version of **GitNex** you are using:
|
||||||
* Phone **OS** version and model:
|
* Source of installation (Play Store, F-Droid, APK):
|
||||||
* The type of certificate you are using (self-signed, signed):
|
* Current android version and phone model/manufacturer:
|
||||||
|
* The type of certificate your instance is using (self-signed, signed):
|
||||||
* How you used to log in (via password or token):
|
* How you used to log in (via password or token):
|
||||||
|
<br>
|
||||||
|
|
||||||
##### We would appreciate some screenshots or stacktrace's, but this is also not required.
|
##### We would appreciate some screenshots or stacktrace's, but this is also not required.
|
||||||
---
|
---
|
||||||
_(Screenshots and stacktrace's can go here)_
|
<!-- Screenshots and stacktrace's can go here. -->
|
||||||
|
<br><br>
|
||||||
|
|
||||||
|
- [ ] I carefully read the [contribution guidelines](https://codeberg.org/GitNex/GitNex/src/branch/main/CONTRIBUTING.md).
|
||||||
|
<br>
|
||||||
|
|
||||||
#### Thank you for your time.
|
#### Thank you for your time.
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
Please check the following:
|
### Describe what your pull request does and which issue you’re targeting
|
||||||
|
<!-- Create a new issue, if it doesn't exist yet -->
|
||||||
|
<br><br>
|
||||||
|
|
||||||
1. Make sure you are targeting the `master` branch, pull requests on release branches are only allowed for bug fixes.
|
<!-- Make sure you are targeting the "main" branch, pull requests on release branches are only allowed for bug fixes. -->
|
||||||
2. Read contributing guidelines: [CONTRIBUTING.md](https://gitea.com/GitNex/GitNex/src/branch/master/CONTRIBUTING.md)
|
|
||||||
3. Please follow the [Code-Standards](https://gitea.com/gitnex/GitNex/wiki/Code-Standards)
|
|
||||||
4. Describe what your pull request does and which issue you’re targeting (create one if does not exist)
|
|
||||||
|
|
||||||
**You MUST delete the content above including this line before posting, otherwise your pull request will be invalid.**
|
- [ ] I carefully read the [contribution guidelines](https://codeberg.org/GitNex/GitNex/src/branch/main/CONTRIBUTING.md).
|
||||||
|
- [ ] I'm following the code standards as defined [here](https://codeberg.org/gitnex/GitNex/wiki/Code-Standards).
|
||||||
|
- [ ] By submitting this pull request, I permit GitNex to license my work under the [GNU General Public License v3](https://codeberg.org/GitNex/GitNex/src/branch/main/LICENSE).
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -11,6 +11,9 @@
|
|||||||
# Release dir
|
# Release dir
|
||||||
app/release/*
|
app/release/*
|
||||||
|
|
||||||
|
# Pro dir
|
||||||
|
app/pro/*
|
||||||
|
|
||||||
# Files for the ART/Dalvik VM
|
# Files for the ART/Dalvik VM
|
||||||
*.dex
|
*.dex
|
||||||
|
|
||||||
@@ -192,3 +195,6 @@ crowdin.yml
|
|||||||
!/gradle/wrapper/gradle-wrapper.jar
|
!/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
# End of https://www.gitignore.io/api/android,androidstudio
|
# End of https://www.gitignore.io/api/android,androidstudio
|
||||||
|
|
||||||
|
# Crowdin Config
|
||||||
|
crowdin.yml
|
||||||
|
|||||||
@@ -1,35 +1,43 @@
|
|||||||
stages:
|
stages:
|
||||||
- test
|
|
||||||
- build
|
- build
|
||||||
- sign
|
- sign
|
||||||
- publish
|
- publish
|
||||||
|
|
||||||
test:
|
on_setup:
|
||||||
image: nextcloudci/android:android-49
|
image: curlimages/curl:7.77.0
|
||||||
stage: test
|
stage: .pre
|
||||||
|
only:
|
||||||
|
- main
|
||||||
|
- tags
|
||||||
|
variables:
|
||||||
|
INSTANCE: "https://codeberg.org"
|
||||||
|
MAIN_REPO: gitnex/GitNex
|
||||||
|
STATE: pending
|
||||||
script:
|
script:
|
||||||
- ./gradlew test
|
- ./scripts/add-commit-status.sh
|
||||||
|
|
||||||
build:
|
build:
|
||||||
image: nextcloudci/android:android-49
|
image: nextcloudci/android:android-54
|
||||||
stage: build
|
stage: build
|
||||||
only:
|
only:
|
||||||
- master
|
- main
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- ./gradlew build
|
- ./gradlew assembleFreeRelease
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- app/build/outputs/
|
- app/build/outputs/
|
||||||
expire_in: 15 minutes
|
expire_in: 15 minutes
|
||||||
|
|
||||||
sign:
|
sign:
|
||||||
image: nextcloudci/android:android-49
|
image: nextcloudci/android:android-54
|
||||||
stage: sign
|
stage: sign
|
||||||
only:
|
only:
|
||||||
- master
|
- main
|
||||||
|
- tags
|
||||||
variables:
|
variables:
|
||||||
OUTPUT: "signed.apk"
|
OUTPUT: "signed.apk"
|
||||||
GITEA: "https://gitea.com"
|
INSTANCE: "https://codeberg.org"
|
||||||
KS_FILE: "ci_keystore.jks"
|
KS_FILE: "ci_keystore.jks"
|
||||||
script:
|
script:
|
||||||
- ./scripts/sign-build.sh
|
- ./scripts/sign-build.sh
|
||||||
@@ -39,10 +47,11 @@ sign:
|
|||||||
expire_in: 15 minutes
|
expire_in: 15 minutes
|
||||||
|
|
||||||
latest:
|
latest:
|
||||||
image: tutum/curl
|
image: curlimages/curl:7.77.0
|
||||||
stage: publish
|
stage: publish
|
||||||
only:
|
only:
|
||||||
- master
|
- main
|
||||||
|
- tags
|
||||||
variables:
|
variables:
|
||||||
WEBDAV_USERNAME: "GitNexBot"
|
WEBDAV_USERNAME: "GitNexBot"
|
||||||
PLUGIN_FILE: "signed.apk"
|
PLUGIN_FILE: "signed.apk"
|
||||||
@@ -51,7 +60,7 @@ latest:
|
|||||||
- curl -T "$PLUGIN_FILE" -u "$WEBDAV_USERNAME":"$WEBDAV_PASSWORD" "$PLUGIN_DESTINATION"
|
- curl -T "$PLUGIN_FILE" -u "$WEBDAV_USERNAME":"$WEBDAV_PASSWORD" "$PLUGIN_DESTINATION"
|
||||||
|
|
||||||
release:
|
release:
|
||||||
image: tutum/curl
|
image: curlimages/curl:7.77.0
|
||||||
stage: publish
|
stage: publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
@@ -61,3 +70,31 @@ release:
|
|||||||
script:
|
script:
|
||||||
- "[[ $CI_COMMIT_REF_NAME == *'-rc'* ]] && echo 'Upload blocked. Build seems to be a release candidate.' && exit 0"
|
- "[[ $CI_COMMIT_REF_NAME == *'-rc'* ]] && echo 'Upload blocked. Build seems to be a release candidate.' && exit 0"
|
||||||
- curl -T "$PLUGIN_FILE" -u "$WEBDAV_USERNAME":"$WEBDAV_PASSWORD" 'https://cloud.swatian.com/remote.php/dav/files/GitNexBot/gitnex/releases/'"$CI_COMMIT_REF_NAME"'.apk'
|
- curl -T "$PLUGIN_FILE" -u "$WEBDAV_USERNAME":"$WEBDAV_PASSWORD" 'https://cloud.swatian.com/remote.php/dav/files/GitNexBot/gitnex/releases/'"$CI_COMMIT_REF_NAME"'.apk'
|
||||||
|
|
||||||
|
on_success:
|
||||||
|
image: curlimages/curl:7.77.0
|
||||||
|
stage: .post
|
||||||
|
only:
|
||||||
|
- main
|
||||||
|
- tags
|
||||||
|
variables:
|
||||||
|
INSTANCE: "https://codeberg.org"
|
||||||
|
MAIN_REPO: gitnex/GitNex
|
||||||
|
STATE: success
|
||||||
|
script:
|
||||||
|
- ./scripts/add-commit-status.sh
|
||||||
|
when: on_success
|
||||||
|
|
||||||
|
on_failure:
|
||||||
|
image: curlimages/curl:7.77.0
|
||||||
|
stage: .post
|
||||||
|
only:
|
||||||
|
- main
|
||||||
|
- tags
|
||||||
|
variables:
|
||||||
|
INSTANCE: "https://codeberg.org"
|
||||||
|
MAIN_REPO: gitnex/GitNex
|
||||||
|
STATE: failure
|
||||||
|
script:
|
||||||
|
- ./scripts/add-commit-status.sh
|
||||||
|
when: on_failure
|
||||||
|
|||||||
18
.idea/codeStyles/Project.xml
generated
18
.idea/codeStyles/Project.xml
generated
@@ -16,6 +16,24 @@
|
|||||||
</value>
|
</value>
|
||||||
</option>
|
</option>
|
||||||
</JavaCodeStyleSettings>
|
</JavaCodeStyleSettings>
|
||||||
|
<JetCodeStyleSettings>
|
||||||
|
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||||
|
<value>
|
||||||
|
<package name="java.util" alias="false" withSubpackages="false" />
|
||||||
|
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
||||||
|
<package name="io.ktor" alias="false" withSubpackages="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="PACKAGES_IMPORT_LAYOUT">
|
||||||
|
<value>
|
||||||
|
<package name="" alias="false" withSubpackages="true" />
|
||||||
|
<package name="java" alias="false" withSubpackages="true" />
|
||||||
|
<package name="javax" alias="false" withSubpackages="true" />
|
||||||
|
<package name="kotlin" alias="false" withSubpackages="true" />
|
||||||
|
<package name="" alias="true" withSubpackages="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</JetCodeStyleSettings>
|
||||||
<codeStyleSettings language="JAVA">
|
<codeStyleSettings language="JAVA">
|
||||||
<option name="RIGHT_MARGIN" value="220" />
|
<option name="RIGHT_MARGIN" value="220" />
|
||||||
<option name="KEEP_LINE_BREAKS" value="false" />
|
<option name="KEEP_LINE_BREAKS" value="false" />
|
||||||
|
|||||||
@@ -2,26 +2,35 @@
|
|||||||
|
|
||||||
Please take a few minutes to read this document to make the process of contribution more easy and healthy for all involved.
|
Please take a few minutes to read this document to make the process of contribution more easy and healthy for all involved.
|
||||||
|
|
||||||
## Pull Requests
|
### General
|
||||||
Patches, enhancements, features are always welcome. The PR should focus on the scope of work and avoid many unnecessary commits. Please provide as much detail and context as possible to explain the work submitted.
|
> **Be polite and gentle while commenting or creating new issues to maintain a healthy environment in which __everyone__ is able to feel comfortable.**
|
||||||
|
<br>
|
||||||
|
|
||||||
Please ask if you are not sure about the scope of work to be submitted to avoid waste of time spent on the work.
|
### Issues and Reports
|
||||||
|
Before creating an issue please take a moment and search the repository issues(open/closed) to avoid duplicate issues either it's a bug or feature.
|
||||||
|
In case you want to submit a bug report, please provide as much details as possible to better debug the problem. The important part is how to reproduce the bug and steps to reproduce are appreciated.<br><br>
|
||||||
|
**Note:** Please contact the project directly via [email](mailto:gitnex@swatian.com) if have to share sensitive and security related details.
|
||||||
|
<br>
|
||||||
|
|
||||||
**Code Standards**
|
### Pull Requests
|
||||||
|
Patches, enhancements and features are always welcome.
|
||||||
|
The PR should focus on the scope of work and avoid many unnecessary commits.
|
||||||
|
Please provide as much detail and context as possible to explain the work submitted.
|
||||||
|
|
||||||
|
**Please ask if you are not sure about the scope of work to be submitted to avoid waste of time spent on the work.** (Submit an issue, __before__ submitting a PR)
|
||||||
|
|
||||||
|
**Code Standards**<br><br>
|
||||||
Please follow the code standards, this will help other developers to understand your code too.
|
Please follow the code standards, this will help other developers to understand your code too.
|
||||||
It also helps maintaining the code afterwards.
|
It also helps maintaining the code afterwards.
|
||||||
It is documented in the Wiki: [Code-Standards](https://codeberg.org/gitnex/GitNex/wiki/Code-Standards)
|
It is documented in the Wiki: [Code-Standards](https://codeberg.org/gitnex/GitNex/wiki/Code-Standards)
|
||||||
|
|
||||||
**How to submit a PR**
|
**How to submit a PR (Pull Request)**
|
||||||
Fork this repository. Pull the forked repository from your namespace to your local machine. Create new branch and work on the bug/feature/enhancement you would like to submit. Push it to your forked version. From there create Pull Request(PR) against **master** branch.
|
1. Fork this repository.
|
||||||
|
2. Clone the forked repository from your namespace to your local machine.
|
||||||
|
3. Create a new branch and work on your feature, enhancement or patch.
|
||||||
|
4. Push your commits to your forked version.
|
||||||
|
5. You can now create a PR using the web interface against **main** branch.
|
||||||
|
|
||||||
**IMPORTANT:** By submitting PR, you agree to allow GitNex to license your work under the same license as that used by GitNex.
|
For more information, click [here](http://makeapullrequest.com/).
|
||||||
|
|
||||||
## Issues and Reports
|
**IMPORTANT:** By submitting PR, you agree to allow GitNex to license your work under the same license as that used by GitNex.
|
||||||
*1st of please be polite and gentle while commenting or creating new issue to maintain a healthy environment.*
|
|
||||||
|
|
||||||
Before creating an issue please take a moment and search the repository issues(open/closed) to avoid duplicate issues either it's a bug or feature.
|
|
||||||
|
|
||||||
In case you want to submit a bug report, please provide as much details as possible to better debug the problem. The important part is how to reproduce the bug and steps to reproduce are appreciated.
|
|
||||||
|
|
||||||
**Note:** Please contact the project directly via email(gitnex@swatian.com) if have to share sensitive and security related details.
|
|
||||||
79
README.md
79
README.md
@@ -1,17 +1,17 @@
|
|||||||
[](https://www.gnu.org/licenses/gpl-3.0) [](https://codeberg.org/gitnex/GitNex/releases) [](https://crowdin.com/project/gitnex) [](https://discord.gg/FbSS4rf)
|
[](https://www.gnu.org/licenses/gpl-3.0) [](https://gitlab.com/opyale/gitnex/-/pipelines) [](https://codeberg.org/gitnex/GitNex/releases) [](https://crowdin.com/project/gitnex) [](https://discord.gg/FbSS4rf)
|
||||||
|
|
||||||
[<img alt="Become a Patroen" src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" height="40"/>](https://www.patreon.com/mmarif) [<img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg" height="40"/>](https://liberapay.com/mmarif/donate)
|
[<img alt="Become a Patroen" src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" height="40"/>](https://www.patreon.com/mmarif)
|
||||||
|
|
||||||
# GitNex - Android client for Gitea
|
# GitNex - Android client for Gitea
|
||||||
|
|
||||||
GitNex is a free, open-source Android client for Git repository management tool Gitea. Gitea is a community managed fork of Gogs, lightweight code hosting solution written in Go.
|
GitNex is a free/paid, open-source Android client for Git repository management tool Gitea. Gitea is a community managed fork of Gogs, lightweight code hosting solution written in Go.
|
||||||
|
|
||||||
GitNex is licensed under GPLv3 License. See the LICENSE file for the full license text. No trackers are used and source code is available here for anyone to audit.
|
GitNex is licensed under GPLv3 License. See the LICENSE file for the full license text. **No trackers are used** and source code is available here for anyone to audit.
|
||||||
|
|
||||||
## Downloads
|
## Downloads
|
||||||
[<img alt='Get it on F-droid' src='https://gitlab.com/fdroid/artwork/raw/master/badge/get-it-on.png' height="80"/>](https://f-droid.org/en/packages/org.mian.gitnex/)
|
[<img alt='Get it on F-droid' src='https://gitlab.com/fdroid/artwork/raw/master/badge/get-it-on.png' height="80"/>](https://f-droid.org/en/packages/org.mian.gitnex/)
|
||||||
[<img alt='Get it on Google Play' src='https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png' height="80"/>](https://play.google.com/store/apps/details?id=org.mian.gitnex)
|
[<img alt='Get it on Google Play' src='https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png' height="80"/>](https://play.google.com/store/apps/details?id=org.mian.gitnex.pro)
|
||||||
[<img alt='Download builds and releases' src='assets/apk-badge.png' height="82"/>](https://cloud.swatian.com/s/DN7E5xxtaw4fRbE)
|
[<img alt='Download builds and releases' src='https://codeberg.org/gitnex/GitNex/raw/branch/main/assets/apk-badge.png' height="82"/>](https://cloud.swatian.com/s/DN7E5xxtaw4fRbE)
|
||||||
|
|
||||||
## Note about Gitea version
|
## Note about Gitea version
|
||||||
Please make sure that you are on latest stable release or later for better app experience.
|
Please make sure that you are on latest stable release or later for better app experience.
|
||||||
@@ -21,10 +21,10 @@ Check the versions [compatibility page](https://codeberg.org/gitnex/GitNex/wiki/
|
|||||||
## Build from source
|
## Build from source
|
||||||
Option 1 - Download the source code, open it in Android Studio and build it there.
|
Option 1 - Download the source code, open it in Android Studio and build it there.
|
||||||
|
|
||||||
Option 2 - Open terminal(Linux) and cd to the project dir. Run `./gradlew build`.
|
Option 2 - Open terminal(Linux) and cd to the project dir. Run `./gradlew assembleFree`.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- Repositories / issues/ org list
|
- Multiple accounts support
|
||||||
- File and directory browser
|
- File and directory browser
|
||||||
- File viewer
|
- File viewer
|
||||||
- Create files
|
- Create files
|
||||||
@@ -33,10 +33,11 @@ Option 2 - Open terminal(Linux) and cd to the project dir. Run `./gradlew build`
|
|||||||
- Files diff for PRs
|
- Files diff for PRs
|
||||||
- Notifications
|
- Notifications
|
||||||
- Drafts
|
- Drafts
|
||||||
|
- Repositories / issues / org list
|
||||||
- [MANY MORE](https://codeberg.org/gitnex/GitNex/wiki/Features)
|
- [MANY MORE](https://codeberg.org/gitnex/GitNex/wiki/Features)
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
[CONTRIBUTING](https://codeberg.org/gitnex/GitNex/src/branch/master/CONTRIBUTING.md)
|
[CONTRIBUTING](https://codeberg.org/gitnex/GitNex/src/branch/main/CONTRIBUTING.md)
|
||||||
|
|
||||||
## Translation
|
## Translation
|
||||||
Help us translate GitNex to your native language.
|
Help us translate GitNex to your native language.
|
||||||
@@ -47,13 +48,9 @@ We use [Crowdin](https://crowdin.com/project/gitnex) for translation. If your la
|
|||||||
|
|
||||||
## Screenshots:
|
## Screenshots:
|
||||||
|
|
||||||
<img src="https://codeberg.org/gitnex/GitNex/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/001.png" alt="001.png" width="200"/> | <img src="https://codeberg.org/gitnex/GitNex/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/002.png" alt="002.png" width="200"/> | <img src="https://codeberg.org/gitnex/GitNex/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/003.png" alt="003.png" width="200"/> | <img src="https://codeberg.org/gitnex/GitNex/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/004.png" alt="004.png" width="200"/>
|
<img src="https://codeberg.org/gitnex/GitNex/raw/branch/main/fastlane/metadata/android/en-US/images/phoneScreenshots/001.png" alt="001.png" width="200"/> | <img src="https://codeberg.org/gitnex/GitNex/raw/branch/main/fastlane/metadata/android/en-US/images/phoneScreenshots/002.png" alt="002.png" width="200"/> | <img src="https://codeberg.org/gitnex/GitNex/raw/branch/main/fastlane/metadata/android/en-US/images/phoneScreenshots/003.png" alt="003.png" width="200"/> | <img src="https://codeberg.org/gitnex/GitNex/raw/branch/main/fastlane/metadata/android/en-US/images/phoneScreenshots/004.png" alt="004.png" width="200"/>
|
||||||
---|---|---|---
|
---|---|---|---
|
||||||
<img src="https://codeberg.org/gitnex/GitNex/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/005.png" alt="005.png" width="200"/> | <img src="https://codeberg.org/gitnex/GitNex/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/006.png" alt="006.png" width="200"/> | <img src="https://codeberg.org/gitnex/GitNex/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/007.png" alt="007.png" width="200"/> | <img src="https://codeberg.org/gitnex/GitNex/raw/branch/master/fastlane/metadata/android/en-US/images/phoneScreenshots/008.png" alt="008.png" width="200"/>
|
<img src="https://codeberg.org/gitnex/GitNex/raw/branch/main/fastlane/metadata/android/en-US/images/phoneScreenshots/005.png" alt="005.png" width="200"/> | <img src="https://codeberg.org/gitnex/GitNex/raw/branch/main/fastlane/metadata/android/en-US/images/phoneScreenshots/006.png" alt="006.png" width="200"/> | <img src="https://codeberg.org/gitnex/GitNex/raw/branch/main/fastlane/metadata/android/en-US/images/phoneScreenshots/007.png" alt="007.png" width="200"/> | <img src="https://codeberg.org/gitnex/GitNex/raw/branch/main/fastlane/metadata/android/en-US/images/phoneScreenshots/008.png" alt="008.png" width="200"/>
|
||||||
|
|
||||||
|
|
||||||
## FAQ
|
|
||||||
[Faq](https://codeberg.org/gitnex/GitNex/wiki/FAQ)
|
|
||||||
|
|
||||||
## Links
|
## Links
|
||||||
[Website](https://gitnex.com)
|
[Website](https://gitnex.com)
|
||||||
@@ -64,31 +61,39 @@ We use [Crowdin](https://crowdin.com/project/gitnex) for translation. If your la
|
|||||||
|
|
||||||
[Troubleshoot Guide](https://codeberg.org/gitnex/GitNex/wiki/Troubleshoot-Guide)
|
[Troubleshoot Guide](https://codeberg.org/gitnex/GitNex/wiki/Troubleshoot-Guide)
|
||||||
|
|
||||||
|
[Faq](https://codeberg.org/gitnex/GitNex/wiki/FAQ)
|
||||||
|
|
||||||
|
[Release Blog](https://gitnex.codeberg.page)
|
||||||
|
|
||||||
## Thanks
|
## Thanks
|
||||||
Thanks to all the open source libraries, contributors and donators.
|
Thanks to all the open source libraries, contributors and donators.
|
||||||
|
|
||||||
#### Open source libraries
|
#### Open source libraries
|
||||||
- Retrofit
|
- [square/retrofit](https://github.com/square/retrofit)
|
||||||
- Gson
|
- [google/gson](https://github.com/google/gson)
|
||||||
- Okhttp
|
- [square/okhttp](https://github.com/square/okhttp)
|
||||||
- ViHtarb/tooltip
|
- [square/picasso](https://github.com/square/picasso)
|
||||||
- Picasso
|
- [wasabeef/picasso-transformations](https://github.com/wasabeef/picasso-transformations)
|
||||||
- Markwon
|
- [cats-oss/android-gpuimage](https://github.com/cats-oss/android-gpuimage)
|
||||||
- Prettytime
|
- [noties/Markwon](https://github.com/noties/Markwon)
|
||||||
- Amulyakhare/textdrawable
|
- [noties/Prism4j](https://github.com/noties/Prism4j)
|
||||||
- Vdurmont/emoji-java
|
- [ocpsoft/prettytime](https://github.com/ocpsoft/prettytime)
|
||||||
- Abumoallim/android-multi-select-dialog
|
- [amulyakhare/TextDrawable](https://github.com/amulyakhare/TextDrawable)
|
||||||
- Pes/materialcolorpicker
|
- [vdurmont/emoji-java](https://github.com/vdurmont/emoji-java)
|
||||||
- Hendraanggrian/socialview
|
- [Pes8/android-material-color-picker-dialog](https://github.com/Pes8/android-material-color-picker-dialog)
|
||||||
- HamidrezaAmz/BreadcrumbsView
|
- [HamidrezaAmz/BreadcrumbsView](https://github.com/HamidrezaAmz/BreadcrumbsView)
|
||||||
- Chrisbanes/PhotoView
|
- [Baseflow/PhotoView](https://github.com/Baseflow/PhotoView)
|
||||||
- Pddstudio/highlightjs-android
|
- [apache/commons](https://github.com/apache/commons-io)
|
||||||
- Apache/commons-io
|
- [ge0rg/MemorizingTrustManager](https://github.com/ge0rg/MemorizingTrustManager)
|
||||||
- Caverock/androidsvg
|
- [mikaelhg/urlbuilder](https://github.com/mikaelhg/urlbuilder)
|
||||||
- Droidsonroids.gif/android-gif-drawable
|
- [ACRA/acra](https://github.com/ACRA/acra)
|
||||||
- Barteksc/AndroidPdfViewer
|
- [chrisvest/stormpot](https://github.com/chrisvest/stormpot)
|
||||||
- Ge0rg/MemorizingTrustManager
|
|
||||||
- Dimezis/BlurView
|
#### Icon sets
|
||||||
- mikaelhg/urlbuilder
|
- [feathericons/feather](https://github.com/feathericons/feather)
|
||||||
|
- [primer/octicons](https://github.com/primer/octicons)
|
||||||
|
- [google/material-design-icons](https://github.com/google/material-design-icons)
|
||||||
|
|
||||||
[Follow me on Fediverse - mastodon.social/@mmarif](https://mastodon.social/@mmarif)
|
[Follow me on Fediverse - mastodon.social/@mmarif](https://mastodon.social/@mmarif)
|
||||||
|
|
||||||
|
*All trademarks and logos are the properties of their respective owners.*
|
||||||
|
|||||||
@@ -1,23 +1,36 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 29
|
compileSdkVersion 30
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "org.mian.gitnex"
|
applicationId "org.mian.gitnex"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 29
|
targetSdkVersion 30
|
||||||
versionCode 308
|
versionCode 405
|
||||||
versionName "3.1.0-rc2"
|
versionName "4.1.0-dev"
|
||||||
|
multiDexEnabled true
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
dexOptions {
|
||||||
|
javaMaxHeapSize "4g"
|
||||||
|
}
|
||||||
|
flavorDimensions "default"
|
||||||
|
productFlavors {
|
||||||
|
free {
|
||||||
|
applicationId "org.mian.gitnex"
|
||||||
|
}
|
||||||
|
pro {
|
||||||
|
applicationId "org.mian.gitnex.pro"
|
||||||
|
}
|
||||||
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
viewBinding = true
|
viewBinding true
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
shrinkResources false
|
shrinkResources false
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lintOptions {
|
lintOptions {
|
||||||
@@ -25,8 +38,13 @@ android {
|
|||||||
abortOnError false
|
abortOnError false
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
targetCompatibility = "8"
|
coreLibraryDesugaringEnabled true
|
||||||
sourceCompatibility = "8"
|
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
defaultConfig{
|
||||||
|
vectorDrawables.useSupportLibrary = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,31 +54,32 @@ configurations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
def lifecycle_version = "2.3.0-alpha06"
|
def lifecycle_version = '2.3.1'
|
||||||
def markwon_version = "4.4.0"
|
def markwon_version = '4.6.2'
|
||||||
def work_version = "2.4.0"
|
def work_version = "2.7.0-alpha05"
|
||||||
def acra = "5.5.0"
|
def acra = "5.7.0"
|
||||||
|
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
implementation "androidx.appcompat:appcompat:1.3.0-alpha01"
|
implementation 'androidx.appcompat:appcompat:1.4.0-alpha03'
|
||||||
implementation "com.google.android.material:material:1.3.0-alpha02"
|
implementation 'com.google.android.material:material:1.4.0'
|
||||||
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
|
implementation 'androidx.viewpager2:viewpager2:1.1.0-alpha01'
|
||||||
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
|
||||||
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
||||||
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
|
||||||
testImplementation "junit:junit:4.13"
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation "androidx.test:runner:1.2.0"
|
androidTestImplementation 'androidx.test:runner:1.4.0'
|
||||||
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||||
implementation "com.github.vihtarb:tooltip:0.2.0"
|
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2'
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.8.0'
|
|
||||||
implementation "com.google.code.gson:gson:2.8.6"
|
implementation "com.google.code.gson:gson:2.8.6"
|
||||||
implementation "com.squareup.picasso:picasso:2.71828"
|
implementation "com.squareup.picasso:picasso:2.71828"
|
||||||
|
implementation 'jp.wasabeef:picasso-transformations:2.4.0'
|
||||||
|
implementation 'jp.co.cyberagent.android:gpuimage:2.1.0'
|
||||||
implementation "com.amulyakhare:com.amulyakhare.textdrawable:1.0.1"
|
implementation "com.amulyakhare:com.amulyakhare.textdrawable:1.0.1"
|
||||||
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
|
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
|
||||||
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
|
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
|
||||||
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
|
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
|
||||||
implementation 'com.squareup.okhttp3:logging-interceptor:4.8.0'
|
implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2'
|
||||||
implementation 'org.ocpsoft.prettytime:prettytime:4.0.5.Final'
|
implementation 'org.ocpsoft.prettytime:prettytime:5.0.0.Final'
|
||||||
implementation "com.vdurmont:emoji-java:5.1.1"
|
|
||||||
implementation "com.pes.materialcolorpicker:library:1.2.5"
|
implementation "com.pes.materialcolorpicker:library:1.2.5"
|
||||||
implementation "io.noties.markwon:core:$markwon_version"
|
implementation "io.noties.markwon:core:$markwon_version"
|
||||||
implementation "io.noties.markwon:ext-latex:$markwon_version"
|
implementation "io.noties.markwon:ext-latex:$markwon_version"
|
||||||
@@ -75,22 +94,24 @@ dependencies {
|
|||||||
implementation "io.noties.markwon:recycler-table:$markwon_version"
|
implementation "io.noties.markwon:recycler-table:$markwon_version"
|
||||||
implementation "io.noties.markwon:simple-ext:$markwon_version"
|
implementation "io.noties.markwon:simple-ext:$markwon_version"
|
||||||
implementation "io.noties.markwon:syntax-highlight:$markwon_version"
|
implementation "io.noties.markwon:syntax-highlight:$markwon_version"
|
||||||
implementation "com.caverock:androidsvg:1.4"
|
implementation "io.noties.markwon:image-picasso:$markwon_version"
|
||||||
implementation "pl.droidsonroids.gif:android-gif-drawable:1.2.19"
|
implementation "io.noties:prism4j:2.0.0"
|
||||||
implementation "com.hendraanggrian.appcompat:socialview:0.2"
|
annotationProcessor "io.noties:prism4j-bundler:2.0.0"
|
||||||
implementation "com.hendraanggrian.appcompat:socialview-commons:0.2"
|
|
||||||
implementation "com.github.HamidrezaAmz:BreadcrumbsView:0.2.9"
|
implementation "com.github.HamidrezaAmz:BreadcrumbsView:0.2.9"
|
||||||
implementation "commons-io:commons-io:20030203.000550"
|
implementation "commons-io:commons-io:20030203.000550"
|
||||||
implementation 'org.apache.commons:commons-lang3:3.11'
|
implementation 'org.apache.commons:commons-lang3:3.12.0'
|
||||||
implementation "com.github.chrisbanes:PhotoView:2.3.0"
|
implementation "com.github.chrisbanes:PhotoView:2.3.0"
|
||||||
implementation "com.github.barteksc:android-pdf-viewer:3.2.0-beta.1"
|
|
||||||
implementation "ch.acra:acra-mail:$acra"
|
implementation "ch.acra:acra-mail:$acra"
|
||||||
implementation "ch.acra:acra-limiter:$acra"
|
implementation "ch.acra:acra-limiter:$acra"
|
||||||
implementation "ch.acra:acra-notification:$acra"
|
implementation "ch.acra:acra-notification:$acra"
|
||||||
implementation "androidx.room:room-runtime:2.2.5"
|
implementation 'androidx.room:room-runtime:2.3.0'
|
||||||
annotationProcessor "androidx.room:room-compiler:2.2.5"
|
annotationProcessor 'androidx.room:room-compiler:2.3.0'
|
||||||
implementation "androidx.work:work-runtime:$work_version"
|
implementation "androidx.work:work-runtime:$work_version"
|
||||||
implementation "com.eightbitlab:blurview:1.6.3"
|
|
||||||
implementation "io.mikael:urlbuilder:2.0.9"
|
implementation "io.mikael:urlbuilder:2.0.9"
|
||||||
|
implementation "org.codeberg.gitnex-garage:emoji-java:v5.1.2"
|
||||||
|
implementation "org.codeberg.gitnex:tea4j:1.0.16"
|
||||||
|
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5"
|
||||||
|
implementation 'androidx.biometric:biometric:1.1.0'
|
||||||
|
implementation 'com.github.chrisvest:stormpot:2.4.2'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
2
app/proguard-rules.pro
vendored
2
app/proguard-rules.pro
vendored
@@ -19,3 +19,5 @@
|
|||||||
# If you keep the line number information, uncomment this to
|
# If you keep the line number information, uncomment this to
|
||||||
# hide the original source file name.
|
# hide the original source file name.
|
||||||
#-renamesourcefileattribute SourceFile
|
#-renamesourcefileattribute SourceFile
|
||||||
|
-optimizationpasses 30
|
||||||
|
-allowaccessmodification
|
||||||
|
|||||||
@@ -6,60 +6,90 @@
|
|||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
|
android:name=".core.MainApplication"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/app_logo"
|
android:icon="@mipmap/app_logo"
|
||||||
android:label="@string/app_name"
|
android:label="@string/appName"
|
||||||
android:networkSecurityConfig="@xml/network_security_config"
|
android:networkSecurityConfig="@xml/network_security_config"
|
||||||
android:resizeableActivity="true"
|
android:resizeableActivity="true"
|
||||||
android:roundIcon="@mipmap/app_logo_round"
|
android:roundIcon="@mipmap/app_logo_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
tools:targetApi="n">
|
tools:targetApi="n">
|
||||||
|
|
||||||
<activity android:name=".activities.MergePullRequestActivity" />
|
<activity
|
||||||
|
android:name=".activities.MergePullRequestActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.FileViewActivity"
|
android:name=".activities.FileViewActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
|
||||||
android:theme="@style/AppTheme.NoActionBar" />
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.CreateFileActivity"
|
android:name=".activities.CreateFileActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
|
||||||
android:theme="@style/AppTheme.NoActionBar" />
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.RepoWatchersActivity"
|
android:name=".activities.RepoWatchersActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
|
||||||
android:theme="@style/AppTheme.NoActionBar" />
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.RepoStargazersActivity"
|
android:name=".activities.RepoStargazersActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
|
||||||
android:theme="@style/AppTheme.NoActionBar" />
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
<activity android:name=".activities.AdminGetUsersActivity" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.AddRemoveAssigneesActivity"
|
android:name=".activities.AdminGetUsersActivity"
|
||||||
android:theme="@style/Theme.AppCompat.Light.Dialog" />
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
<activity android:name=".activities.CreateReleaseActivity" />
|
|
||||||
<activity android:name=".activities.EditIssueActivity" />
|
|
||||||
<activity android:name=".activities.CreateNewUserActivity" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.AddRemoveLabelsActivity"
|
android:name=".activities.CreateReleaseActivity"
|
||||||
android:theme="@style/Theme.AppCompat.Light.Dialog" />
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
<activity android:name=".activities.ProfileEmailActivity" />
|
<activity
|
||||||
<activity android:name=".activities.AddCollaboratorToRepositoryActivity" />
|
android:name=".activities.EditIssueActivity"
|
||||||
<activity android:name=".activities.CreateTeamByOrgActivity" />
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
<activity android:name=".activities.OrganizationTeamMembersActivity" />
|
<activity
|
||||||
|
android:name=".activities.CreateNewUserActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.MyProfileEmailActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.AddCollaboratorToRepositoryActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.CreateTeamByOrgActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.OrganizationTeamMembersActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.OrganizationDetailActivity"
|
android:name=".activities.OrganizationDetailActivity"
|
||||||
android:label="@string/title_activity_org_detail"
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
|
||||||
|
android:label="@string/titleActivityOrgDetail"
|
||||||
android:theme="@style/AppTheme.NoActionBar" />
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
<activity android:name=".activities.CreateLabelActivity" />
|
<activity
|
||||||
<activity android:name=".activities.CreateIssueActivity" />
|
android:name=".activities.CreateLabelActivity"
|
||||||
<activity android:name=".activities.CreateMilestoneActivity" />
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
<activity android:name=".activities.ReplyToIssueActivity" />
|
<activity
|
||||||
|
android:name=".activities.CreateIssueActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.CreateMilestoneActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.IssueDetailActivity"
|
android:name=".activities.IssueDetailActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
|
||||||
android:windowSoftInputMode="adjustNothing" />
|
android:windowSoftInputMode="adjustNothing" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.RepoDetailActivity"
|
android:name=".activities.RepoDetailActivity"
|
||||||
android:label="@string/title_activity_repo_detail"
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
|
||||||
|
android:label="@string/titleActivityRepoDetail"
|
||||||
android:theme="@style/AppTheme.NoActionBar" />
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
<activity android:name=".activities.MainActivity" android:theme="@android:style/Theme.NoTitleBar" android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation">
|
<activity
|
||||||
|
android:name=".activities.MainActivity"
|
||||||
|
android:theme="@android:style/Theme.NoTitleBar"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
|
||||||
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
@@ -68,28 +98,102 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.LoginActivity"
|
android:name=".activities.LoginActivity"
|
||||||
android:launchMode="singleTask" android:theme="@android:style/Theme.NoTitleBar"/>
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
|
||||||
<activity android:name=".activities.CreateRepoActivity" />
|
android:launchMode="singleTask"
|
||||||
<activity android:name=".activities.CreateOrganizationActivity" />
|
android:theme="@android:style/Theme.NoTitleBar"/>
|
||||||
<activity android:name=".activities.OpenRepoInBrowserActivity" />
|
<activity
|
||||||
<activity android:name=".activities.FileDiffActivity" />
|
android:name=".activities.CreateRepoActivity"
|
||||||
<activity android:name=".activities.CommitsActivity" />
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
<activity android:name=".helpers.ssl.MemorizingActivity" android:theme="@android:style/Theme.Material.Dialog" />
|
<activity
|
||||||
<activity android:name=".activities.SettingsAppearanceActivity" />
|
android:name=".activities.CreateOrganizationActivity"
|
||||||
<activity android:name=".activities.SettingsFileViewerActivity" />
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
<activity android:name=".activities.SettingsSecurityActivity" />
|
<activity
|
||||||
<activity android:name=".activities.SettingsTranslationActivity" />
|
android:name=".activities.OpenRepoInBrowserActivity"
|
||||||
<activity android:name=".activities.SettingsReportsActivity" />
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
<activity android:name=".activities.AddNewTeamMemberActivity" />
|
<activity
|
||||||
<activity android:name=".activities.SettingsDraftsActivity" />
|
android:name=".activities.FileDiffActivity"
|
||||||
<activity android:name=".activities.RepoForksActivity" />
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
<activity android:name=".activities.AddNewAccountActivity" />
|
<activity
|
||||||
|
android:name=".activities.CommitsActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".helpers.ssl.MemorizingActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
|
||||||
|
android:theme="@android:style/Theme.Material.Dialog" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.SettingsAppearanceActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.ProfileActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.SettingsSecurityActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.SettingsTranslationActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.SettingsReportsActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.AddNewTeamMemberActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.SettingsDraftsActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.RepoForksActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.AddNewAccountActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.RepositorySettingsActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.CreatePullRequestActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.SettingsGeneralActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
<activity
|
||||||
|
android:name=".activities.SettingsNotificationsActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".activities.AdminCronTasksActivity"
|
||||||
|
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||||
|
|
||||||
<!-- Version < 3.0. DeX Mode and Screen Mirroring support -->
|
<!-- Version < 3.0. DeX Mode and Screen Mirroring support -->
|
||||||
<meta-data android:name="com.samsung.android.keepalive.density" android:value="true"/>
|
<meta-data android:name="com.samsung.android.keepalive.density" android:value="true"/>
|
||||||
<!-- Version >= 3.0. DeX Dual Mode support -->
|
<!-- Version >= 3.0. DeX Dual Mode support -->
|
||||||
<meta-data android:name="com.samsung.android.multidisplay.keep_process_alive" android:value="true"/>
|
<meta-data android:name="com.samsung.android.multidisplay.keep_process_alive" android:value="true"/>
|
||||||
|
|
||||||
|
<!-- deep links -->
|
||||||
|
<activity
|
||||||
|
android:name=".activities.DeepLinksActivity"
|
||||||
|
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||||
|
android:noHistory="true"
|
||||||
|
android:launchMode="singleTask"
|
||||||
|
android:exported="true">
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
<data android:scheme="http" />
|
||||||
|
<data android:scheme="https" />
|
||||||
|
<data android:host="codeberg.org" />
|
||||||
|
<data android:host="gitea.com" />
|
||||||
|
<data android:host="try.gitea.io" />
|
||||||
|
<data android:host="code.obermui.de" />
|
||||||
|
<data android:host="git.fsfe.org" />
|
||||||
|
<data android:host="opendev.org" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
</activity>
|
||||||
|
<!-- deep links -->
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
BIN
app/src/main/app_logo-playstore.png
Normal file
BIN
app/src/main/app_logo-playstore.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB |
File diff suppressed because one or more lines are too long
@@ -1 +0,0 @@
|
|||||||
!function(e){"use strict";function t(){"complete"===document.readyState?n():e.addEventListener("DOMContentLoaded",n)}function n(){try{var e=document.querySelectorAll("code.hljs");for(var t in e)e.hasOwnProperty(t)&&r(e[t])}catch(n){console.error("LineNumbers error: ",n)}}function r(e){if("object"==typeof e){var t=e.parentNode,n=o(t.textContent);if(n>1){for(var r="",c=0;n>c;c++)r+=c+1+"\n";var l=document.createElement("code");l.className="hljs hljs-line-numbers",l.style["float"]="left",l.textContent=r,t.insertBefore(l,e)}}}function o(e){if(0===e.length)return 0;var t=/\r\n|\r|\n/g,n=e.match(t);return n=n?n.length:0,e[e.length-1].match(t)||(n+=1),n}"undefined"==typeof e.hljs?console.error("highlight.js not detected!"):(e.hljs.initLineNumbersOnLoad=t,e.hljs.lineNumbersBlock=r)}(window);
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
Date: 24 Fev 2015
|
|
||||||
Author: Pedro Oliveira <kanytu@gmail . com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
.hljs {
|
|
||||||
color: #a9b7c6;
|
|
||||||
background: #282b2e;
|
|
||||||
display: block;
|
|
||||||
overflow-x: auto;
|
|
||||||
padding: 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-number,
|
|
||||||
.hljs-literal,
|
|
||||||
.hljs-symbol,
|
|
||||||
.hljs-bullet {
|
|
||||||
color: #6897BB;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-keyword,
|
|
||||||
.hljs-selector-tag,
|
|
||||||
.hljs-deletion {
|
|
||||||
color: #cc7832;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-variable,
|
|
||||||
.hljs-template-variable,
|
|
||||||
.hljs-link {
|
|
||||||
color: #629755;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-comment,
|
|
||||||
.hljs-quote {
|
|
||||||
color: #808080;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-meta {
|
|
||||||
color: #bbb529;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-string,
|
|
||||||
.hljs-attribute,
|
|
||||||
.hljs-addition {
|
|
||||||
color: #6A8759;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-section,
|
|
||||||
.hljs-title,
|
|
||||||
.hljs-type {
|
|
||||||
color: #ffc66d;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-name,
|
|
||||||
.hljs-selector-id,
|
|
||||||
.hljs-selector-class {
|
|
||||||
color: #e8bf6a;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-emphasis {
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-strong {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Arduino® Light Theme - Stefania Mellai <s.mellai@arduino.cc>
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
.hljs {
|
|
||||||
display: block;
|
|
||||||
overflow-x: auto;
|
|
||||||
padding: 0.5em;
|
|
||||||
background: #FFFFFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs,
|
|
||||||
.hljs-subst {
|
|
||||||
color: #434f54;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-keyword,
|
|
||||||
.hljs-attribute,
|
|
||||||
.hljs-selector-tag,
|
|
||||||
.hljs-doctag,
|
|
||||||
.hljs-name {
|
|
||||||
color: #00979D;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-built_in,
|
|
||||||
.hljs-literal,
|
|
||||||
.hljs-bullet,
|
|
||||||
.hljs-code,
|
|
||||||
.hljs-addition {
|
|
||||||
color: #D35400;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-regexp,
|
|
||||||
.hljs-symbol,
|
|
||||||
.hljs-variable,
|
|
||||||
.hljs-template-variable,
|
|
||||||
.hljs-link,
|
|
||||||
.hljs-selector-attr,
|
|
||||||
.hljs-selector-pseudo {
|
|
||||||
color: #00979D;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-type,
|
|
||||||
.hljs-string,
|
|
||||||
.hljs-selector-id,
|
|
||||||
.hljs-selector-class,
|
|
||||||
.hljs-quote,
|
|
||||||
.hljs-template-tag,
|
|
||||||
.hljs-deletion {
|
|
||||||
color: #005C5F;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-title,
|
|
||||||
.hljs-section {
|
|
||||||
color: #880000;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-comment {
|
|
||||||
color: rgba(149,165,166,.8);
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-meta-keyword {
|
|
||||||
color: #728E00;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-meta {
|
|
||||||
color: #434f54;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-emphasis {
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-strong {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-function {
|
|
||||||
color: #728E00;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-number {
|
|
||||||
color: #8A7B52;
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
FAR Style (c) MajestiC <majestic2k@gmail.com>
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
.hljs {
|
|
||||||
display: block;
|
|
||||||
overflow-x: auto;
|
|
||||||
padding: 0.5em;
|
|
||||||
background: #000080;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs,
|
|
||||||
.hljs-subst {
|
|
||||||
color: #0ff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-string,
|
|
||||||
.hljs-attribute,
|
|
||||||
.hljs-symbol,
|
|
||||||
.hljs-bullet,
|
|
||||||
.hljs-built_in,
|
|
||||||
.hljs-builtin-name,
|
|
||||||
.hljs-template-tag,
|
|
||||||
.hljs-template-variable,
|
|
||||||
.hljs-addition {
|
|
||||||
color: #ff0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-keyword,
|
|
||||||
.hljs-selector-tag,
|
|
||||||
.hljs-section,
|
|
||||||
.hljs-type,
|
|
||||||
.hljs-name,
|
|
||||||
.hljs-selector-id,
|
|
||||||
.hljs-selector-class,
|
|
||||||
.hljs-variable {
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-comment,
|
|
||||||
.hljs-quote,
|
|
||||||
.hljs-doctag,
|
|
||||||
.hljs-deletion {
|
|
||||||
color: #888;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-number,
|
|
||||||
.hljs-regexp,
|
|
||||||
.hljs-literal,
|
|
||||||
.hljs-link {
|
|
||||||
color: #0f0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-meta {
|
|
||||||
color: #008080;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-keyword,
|
|
||||||
.hljs-selector-tag,
|
|
||||||
.hljs-title,
|
|
||||||
.hljs-section,
|
|
||||||
.hljs-name,
|
|
||||||
.hljs-strong {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-emphasis {
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
.hljs {
|
|
||||||
display: block;
|
|
||||||
overflow-x: auto;
|
|
||||||
padding: 0.5em;
|
|
||||||
color: #333;
|
|
||||||
background: #f8f8f8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-comment,
|
|
||||||
.hljs-quote {
|
|
||||||
color: #998;
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-keyword,
|
|
||||||
.hljs-selector-tag,
|
|
||||||
.hljs-subst {
|
|
||||||
color: #333;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-number,
|
|
||||||
.hljs-literal,
|
|
||||||
.hljs-variable,
|
|
||||||
.hljs-template-variable,
|
|
||||||
.hljs-tag .hljs-attr {
|
|
||||||
color: #008080;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-string,
|
|
||||||
.hljs-doctag {
|
|
||||||
color: #d14;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-title,
|
|
||||||
.hljs-section,
|
|
||||||
.hljs-selector-id {
|
|
||||||
color: #900;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-subst {
|
|
||||||
font-weight: normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-type,
|
|
||||||
.hljs-class .hljs-title {
|
|
||||||
color: #458;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-tag,
|
|
||||||
.hljs-name,
|
|
||||||
.hljs-attribute {
|
|
||||||
color: #000080;
|
|
||||||
font-weight: normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-regexp,
|
|
||||||
.hljs-link {
|
|
||||||
color: #009926;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-symbol,
|
|
||||||
.hljs-bullet {
|
|
||||||
color: #990073;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-built_in,
|
|
||||||
.hljs-builtin-name {
|
|
||||||
color: #0086b3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-meta {
|
|
||||||
color: #999;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-deletion {
|
|
||||||
background: #fdd;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-addition {
|
|
||||||
background: #dfd;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-emphasis {
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-strong {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
IR_Black style (c) Vasily Mikhailitchenko <vaskas@programica.ru>
|
|
||||||
*/
|
|
||||||
|
|
||||||
.hljs {
|
|
||||||
display: block;
|
|
||||||
overflow-x: auto;
|
|
||||||
padding: 0.5em;
|
|
||||||
background: #000;
|
|
||||||
color: #f8f8f8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-comment,
|
|
||||||
.hljs-quote,
|
|
||||||
.hljs-meta {
|
|
||||||
color: #7c7c7c;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-keyword,
|
|
||||||
.hljs-selector-tag,
|
|
||||||
.hljs-tag,
|
|
||||||
.hljs-name {
|
|
||||||
color: #96cbfe;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-attribute,
|
|
||||||
.hljs-selector-id {
|
|
||||||
color: #ffffb6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-string,
|
|
||||||
.hljs-selector-attr,
|
|
||||||
.hljs-selector-pseudo,
|
|
||||||
.hljs-addition {
|
|
||||||
color: #a8ff60;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-subst {
|
|
||||||
color: #daefa3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-regexp,
|
|
||||||
.hljs-link {
|
|
||||||
color: #e9c062;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-title,
|
|
||||||
.hljs-section,
|
|
||||||
.hljs-type,
|
|
||||||
.hljs-doctag {
|
|
||||||
color: #ffffb6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-symbol,
|
|
||||||
.hljs-bullet,
|
|
||||||
.hljs-variable,
|
|
||||||
.hljs-template-variable,
|
|
||||||
.hljs-literal {
|
|
||||||
color: #c6c5fe;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-number,
|
|
||||||
.hljs-deletion {
|
|
||||||
color:#ff73fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-emphasis {
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-strong {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
Monokai Sublime style. Derived from Monokai by noformnocontent http://nn.mit-license.org/
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
.hljs {
|
|
||||||
display: block;
|
|
||||||
overflow-x: auto;
|
|
||||||
padding: 0.5em;
|
|
||||||
background: #23241f;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs,
|
|
||||||
.hljs-tag,
|
|
||||||
.hljs-subst {
|
|
||||||
color: #f8f8f2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-strong,
|
|
||||||
.hljs-emphasis {
|
|
||||||
color: #a8a8a2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-bullet,
|
|
||||||
.hljs-quote,
|
|
||||||
.hljs-number,
|
|
||||||
.hljs-regexp,
|
|
||||||
.hljs-literal,
|
|
||||||
.hljs-link {
|
|
||||||
color: #ae81ff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-code,
|
|
||||||
.hljs-title,
|
|
||||||
.hljs-section,
|
|
||||||
.hljs-selector-class {
|
|
||||||
color: #a6e22e;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-strong {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-emphasis {
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-keyword,
|
|
||||||
.hljs-selector-tag,
|
|
||||||
.hljs-name,
|
|
||||||
.hljs-attr {
|
|
||||||
color: #f92672;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-symbol,
|
|
||||||
.hljs-attribute {
|
|
||||||
color: #66d9ef;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-params,
|
|
||||||
.hljs-class .hljs-title {
|
|
||||||
color: #f8f8f2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-string,
|
|
||||||
.hljs-type,
|
|
||||||
.hljs-built_in,
|
|
||||||
.hljs-builtin-name,
|
|
||||||
.hljs-selector-id,
|
|
||||||
.hljs-selector-attr,
|
|
||||||
.hljs-selector-pseudo,
|
|
||||||
.hljs-addition,
|
|
||||||
.hljs-variable,
|
|
||||||
.hljs-template-variable {
|
|
||||||
color: #e6db74;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs-comment,
|
|
||||||
.hljs-deletion,
|
|
||||||
.hljs-meta {
|
|
||||||
color: #75715e;
|
|
||||||
}
|
|
||||||
80
app/src/main/java/org/mian/gitnex/actions/ActionResult.java
Normal file
80
app/src/main/java/org/mian/gitnex/actions/ActionResult.java
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package org.mian.gitnex.actions;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author opyale
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ActionResult<R> {
|
||||||
|
|
||||||
|
public enum Status { SUCCESS, FAILED }
|
||||||
|
|
||||||
|
private final BlockingQueue<Boolean> blockingQueue;
|
||||||
|
private final List<OnFinishedListener<R>> onFinishedListeners;
|
||||||
|
|
||||||
|
private boolean invalidated = false;
|
||||||
|
|
||||||
|
public ActionResult() {
|
||||||
|
|
||||||
|
blockingQueue = new ArrayBlockingQueue<>(1);
|
||||||
|
onFinishedListeners = new ArrayList<>();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void finish(@NonNull Status status) {
|
||||||
|
|
||||||
|
finish(status, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void finish(@NonNull Status status, R result) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(blockingQueue.poll(5, TimeUnit.SECONDS)) {
|
||||||
|
|
||||||
|
for(OnFinishedListener<R> onFinishedListener : onFinishedListeners)
|
||||||
|
onFinishedListener.onFinished(status, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (InterruptedException ignored) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void invalidate() {
|
||||||
|
|
||||||
|
if(invalidated) throw new IllegalStateException("Already invalidated");
|
||||||
|
this.invalidated = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
public synchronized final void accept(@NonNull OnFinishedListener<R>... onFinishedListeners) {
|
||||||
|
|
||||||
|
invalidate();
|
||||||
|
|
||||||
|
this.blockingQueue.add(true);
|
||||||
|
this.onFinishedListeners.addAll(Arrays.asList(onFinishedListeners));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized final void discard() {
|
||||||
|
|
||||||
|
invalidate();
|
||||||
|
this.blockingQueue.add(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class None {}
|
||||||
|
|
||||||
|
public interface OnFinishedListener<R> {
|
||||||
|
|
||||||
|
void onFinished(Status status, R result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
118
app/src/main/java/org/mian/gitnex/actions/AssigneesActions.java
Normal file
118
app/src/main/java/org/mian/gitnex/actions/AssigneesActions.java
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
package org.mian.gitnex.actions;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import org.gitnex.tea4j.models.Collaborators;
|
||||||
|
import org.gitnex.tea4j.models.Issues;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.adapters.AssigneesListAdapter;
|
||||||
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.CustomAssigneesSelectionDialogBinding;
|
||||||
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import java.util.List;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AssigneesActions {
|
||||||
|
|
||||||
|
public static void getCurrentIssueAssignees(Context ctx, String repoOwner, String repoName, int issueIndex, List<String> currentAssignees) {
|
||||||
|
|
||||||
|
Call<Issues> callSingleIssueLabels = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.getIssueByIndex(Authorization.get(ctx), repoOwner, repoName, issueIndex);
|
||||||
|
|
||||||
|
callSingleIssueLabels.enqueue(new Callback<Issues>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<Issues> call, @NonNull retrofit2.Response<Issues> response) {
|
||||||
|
|
||||||
|
if(response.code() == 200) {
|
||||||
|
|
||||||
|
Issues issueAssigneesList = response.body();
|
||||||
|
assert issueAssigneesList != null;
|
||||||
|
|
||||||
|
if (issueAssigneesList.getAssignees() != null) {
|
||||||
|
|
||||||
|
if(issueAssigneesList.getAssignees().size() > 0) {
|
||||||
|
|
||||||
|
for(int i = 0; i < issueAssigneesList.getAssignees().size(); i++) {
|
||||||
|
|
||||||
|
currentAssignees.add(issueAssigneesList.getAssignees().get(i).getLogin());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<Issues> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
Log.e("onFailure", t.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void getRepositoryAssignees(Context ctx, String repoOwner, String repoName, List<Collaborators> assigneesList, Dialog dialogAssignees, AssigneesListAdapter assigneesAdapter, CustomAssigneesSelectionDialogBinding assigneesBinding) {
|
||||||
|
|
||||||
|
TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||||
|
|
||||||
|
Call<List<Collaborators>> call = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.getCollaborators(Authorization.get(ctx), repoOwner, repoName);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<List<Collaborators>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull retrofit2.Response<List<Collaborators>> response) {
|
||||||
|
|
||||||
|
assigneesList.clear();
|
||||||
|
List<Collaborators> assigneesList_ = response.body();
|
||||||
|
|
||||||
|
assigneesBinding.progressBar.setVisibility(View.GONE);
|
||||||
|
assigneesBinding.dialogFrame.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (response.code() == 200) {
|
||||||
|
|
||||||
|
assert assigneesList_ != null;
|
||||||
|
|
||||||
|
if(assigneesList_.size() > 0) {
|
||||||
|
|
||||||
|
assigneesList.add(new Collaborators(tinyDB.getString("userFullname"), tinyDB.getString("loginUid"), tinyDB.getString("userAvatar")));
|
||||||
|
assigneesList.addAll(assigneesList_);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
dialogAssignees.dismiss();
|
||||||
|
Toasty.warning(ctx, ctx.getResources().getString(R.string.noAssigneesFound));
|
||||||
|
}
|
||||||
|
|
||||||
|
assigneesBinding.assigneesRecyclerView.setAdapter(assigneesAdapter);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
Toasty.error(ctx, ctx.getResources().getString(R.string.genericError));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, ctx.getResources().getString(R.string.genericServerResponseError));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@ package org.mian.gitnex.actions;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import org.gitnex.tea4j.models.Collaborators;
|
||||||
|
import org.gitnex.tea4j.models.Permission;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.activities.AddCollaboratorToRepositoryActivity;
|
import org.mian.gitnex.activities.AddCollaboratorToRepositoryActivity;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
@@ -10,10 +12,10 @@ import org.mian.gitnex.helpers.AlertDialogs;
|
|||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.Collaborators;
|
import java.util.List;
|
||||||
import org.mian.gitnex.models.Permission;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -23,21 +25,16 @@ public class CollaboratorActions {
|
|||||||
|
|
||||||
public static void deleteCollaborator(final Context context, final String searchKeyword, String userName) {
|
public static void deleteCollaborator(final Context context, final String searchKeyword, String userName) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(context);
|
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
|
|
||||||
Call<Collaborators> call;
|
Call<Collaborators> call = RetrofitClient
|
||||||
|
.getApiInterface(context)
|
||||||
call = RetrofitClient
|
.deleteCollaborator(Authorization.get(context), repoOwner, repoName, userName);
|
||||||
.getInstance(instanceUrl, context)
|
|
||||||
.getApiInterface()
|
|
||||||
.deleteCollaborator(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName, userName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<Collaborators>() {
|
call.enqueue(new Callback<Collaborators>() {
|
||||||
|
|
||||||
@@ -52,7 +49,7 @@ public class CollaboratorActions {
|
|||||||
//Log.i("addCollaboratorSearch", addCollaboratorSearch.getText().toString());
|
//Log.i("addCollaboratorSearch", addCollaboratorSearch.getText().toString());
|
||||||
//tinyDb.putBoolean("updateDataSet", true);
|
//tinyDb.putBoolean("updateDataSet", true);
|
||||||
//AddCollaboratorToRepositoryActivity usersSearchData = new AddCollaboratorToRepositoryActivity();
|
//AddCollaboratorToRepositoryActivity usersSearchData = new AddCollaboratorToRepositoryActivity();
|
||||||
//usersSearchData.loadUserSearchList(instanceUrl, instanceToken, searchKeyword, context);
|
//usersSearchData.loadUserSearchList(instanceToken, searchKeyword, context);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,22 +89,18 @@ public class CollaboratorActions {
|
|||||||
|
|
||||||
public static void addCollaborator(final Context context, String permission, String userName) {
|
public static void addCollaborator(final Context context, String permission, String userName) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(context);
|
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
|
|
||||||
Permission permissionString = new Permission(permission);
|
Permission permissionString = new Permission(permission);
|
||||||
Call<Permission> call;
|
|
||||||
|
|
||||||
call = RetrofitClient
|
Call<Permission> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, context)
|
.getApiInterface(context)
|
||||||
.getApiInterface()
|
.addCollaborator(Authorization.get(context), repoOwner, repoName, userName, permissionString);
|
||||||
.addCollaborator(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName, userName, permissionString);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<Permission>() {
|
call.enqueue(new Callback<Permission>() {
|
||||||
|
|
||||||
@@ -120,7 +113,7 @@ public class CollaboratorActions {
|
|||||||
Toasty.success(context, context.getString(R.string.addCollaboratorToastText));
|
Toasty.success(context, context.getString(R.string.addCollaboratorToastText));
|
||||||
((AddCollaboratorToRepositoryActivity)context).finish();
|
((AddCollaboratorToRepositoryActivity)context).finish();
|
||||||
//AddCollaboratorToRepositoryActivity usersSearchData = new AddCollaboratorToRepositoryActivity();
|
//AddCollaboratorToRepositoryActivity usersSearchData = new AddCollaboratorToRepositoryActivity();
|
||||||
//usersSearchData.loadUserSearchList(instanceUrl, instanceToken, searchKeyword, context);
|
//usersSearchData.loadUserSearchList(instanceToken, searchKeyword, context);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,8 +147,50 @@ public class CollaboratorActions {
|
|||||||
public void onFailure(@NonNull Call<Permission> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<Permission> call, @NonNull Throwable t) {
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ActionResult<List<Collaborators>> getCollaborators(Context context) {
|
||||||
|
|
||||||
|
ActionResult<List<Collaborators>> actionResult = new ActionResult<>();
|
||||||
|
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
|
|
||||||
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
|
String[] parts = repoFullName.split("/");
|
||||||
|
String repoOwner = parts[0];
|
||||||
|
String repoName = parts[1];
|
||||||
|
|
||||||
|
Call<List<Collaborators>> call = RetrofitClient
|
||||||
|
.getApiInterface(context)
|
||||||
|
.getCollaborators(Authorization.get(context), repoOwner, repoName);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<List<Collaborators>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
|
||||||
|
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
|
||||||
|
assert response.body() != null;
|
||||||
|
actionResult.finish(ActionResult.Status.SUCCESS, response.body());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
actionResult.finish(ActionResult.Status.FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
actionResult.finish(ActionResult.Status.FAILED);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return actionResult;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
package org.mian.gitnex.actions;
|
package org.mian.gitnex.actions;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import org.gitnex.tea4j.models.IssueComments;
|
||||||
|
import org.gitnex.tea4j.models.Issues;
|
||||||
|
import org.gitnex.tea4j.models.UpdateIssueState;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.activities.ReplyToIssueActivity;
|
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
import org.mian.gitnex.database.api.DraftsApi;
|
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.IssueComments;
|
|
||||||
import org.mian.gitnex.models.UpdateIssueState;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -23,87 +22,72 @@ import retrofit2.Callback;
|
|||||||
|
|
||||||
public class IssueActions {
|
public class IssueActions {
|
||||||
|
|
||||||
public static void editIssueComment(final Context ctx, final int commentId, final String commentBody, long draftIdOnCreate) {
|
public static ActionResult<Response<?>> edit(Context context, String comment, int commentId) {
|
||||||
|
|
||||||
|
ActionResult<Response<?>> actionResult = new ActionResult<>();
|
||||||
|
|
||||||
|
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(ctx);
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
|
|
||||||
IssueComments commentBodyJson = new IssueComments(commentBody);
|
String repoOwner = parts[0];
|
||||||
Call<IssueComments> call;
|
String repoName = parts[1];
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().patchIssueComment(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, commentId, commentBodyJson);
|
Call<IssueComments> call = RetrofitClient
|
||||||
|
.getApiInterface(context)
|
||||||
|
.patchIssueComment(Authorization.get(context), repoOwner, repoName, commentId, new IssueComments(comment));
|
||||||
|
|
||||||
call.enqueue(new Callback<IssueComments>() {
|
call.enqueue(new Callback<IssueComments>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<IssueComments> call, @NonNull retrofit2.Response<IssueComments> response) {
|
public void onResponse(@NonNull Call<IssueComments> call, @NonNull retrofit2.Response<IssueComments> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
switch(response.code()) {
|
||||||
if(response.code() == 200) {
|
|
||||||
|
|
||||||
tinyDb.putBoolean("commentEdited", true);
|
case 200:
|
||||||
Toasty.info(ctx, ctx.getString(R.string.editCommentUpdatedText));
|
actionResult.finish(ActionResult.Status.SUCCESS);
|
||||||
|
break;
|
||||||
|
|
||||||
DraftsApi draftsApi = new DraftsApi(ctx);
|
case 401:
|
||||||
draftsApi.deleteSingleDraft((int) draftIdOnCreate);
|
actionResult.finish(ActionResult.Status.FAILED, response);
|
||||||
|
AlertDialogs.authorizationTokenRevokedDialog(context, context.getResources().getString(R.string.alertDialogTokenRevokedTitle), context.getResources().getString(R.string.alertDialogTokenRevokedMessage), context.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), context.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
break;
|
||||||
|
|
||||||
((ReplyToIssueActivity) ctx).finish();
|
default:
|
||||||
|
actionResult.finish(ActionResult.Status.FAILED, response);
|
||||||
}
|
break;
|
||||||
}
|
|
||||||
else if(response.code() == 401) {
|
|
||||||
|
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, ctx.getResources().getString(R.string.alertDialogTokenRevokedTitle), ctx.getResources().getString(R.string.alertDialogTokenRevokedMessage), ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 403) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 404) {
|
|
||||||
|
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<IssueComments> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<IssueComments> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
actionResult.finish(ActionResult.Status.FAILED);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return actionResult;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void closeReopenIssue(final Context ctx, final int issueIndex, final String issueState) {
|
public static void closeReopenIssue(final Context ctx, final int issueIndex, final String issueState) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(ctx);
|
final TinyDB tinyDb = TinyDB.getInstance(ctx);
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
|
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
|
|
||||||
UpdateIssueState issueStatJson = new UpdateIssueState(issueState);
|
UpdateIssueState issueStatJson = new UpdateIssueState(issueState);
|
||||||
Call<JsonElement> call;
|
Call<JsonElement> call;
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().closeReopenIssue(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, issueStatJson);
|
call = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.closeReopenIssue(Authorization.get(ctx), repoOwner, repoName, issueIndex, issueStatJson);
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
@@ -157,7 +141,7 @@ public class IssueActions {
|
|||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Toasty.error(ctx, ctx.getResources().getString(R.string.genericServerResponseError));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -165,20 +149,23 @@ public class IssueActions {
|
|||||||
|
|
||||||
public static void subscribe(final Context ctx) {
|
public static void subscribe(final Context ctx) {
|
||||||
|
|
||||||
final TinyDB tinyDB = new TinyDB(ctx);
|
final TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||||
|
|
||||||
final String instanceUrl = tinyDB.getString("instanceUrl");
|
|
||||||
String[] repoFullName = tinyDB.getString("repoFullName").split("/");
|
String[] repoFullName = tinyDB.getString("repoFullName").split("/");
|
||||||
|
|
||||||
if(repoFullName.length != 2) {
|
if(repoFullName.length != 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String userLogin = tinyDB.getString("userLogin");
|
final String userLogin = tinyDB.getString("userLogin");
|
||||||
final String token = "token " + tinyDB.getString(tinyDB.getString("loginUid") + "-token");
|
final String token = "token " + tinyDB.getString(tinyDB.getString("loginUid") + "-token");
|
||||||
final int issueNr = Integer.parseInt(tinyDB.getString("issueNumber"));
|
final int issueNr = Integer.parseInt(tinyDB.getString("issueNumber"));
|
||||||
|
|
||||||
Call<Void> call;
|
Call<Void> call;
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().addIssueSubscriber(token, repoFullName[0], repoFullName[1], issueNr, userLogin);
|
call = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.addIssueSubscriber(token, repoFullName[0], repoFullName[1], issueNr, userLogin);
|
||||||
|
|
||||||
call.enqueue(new Callback<Void>() {
|
call.enqueue(new Callback<Void>() {
|
||||||
|
|
||||||
@@ -217,7 +204,7 @@ public class IssueActions {
|
|||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Toasty.success(ctx, ctx.getString(R.string.unsubscribedSuccessfully));
|
Toasty.error(ctx, ctx.getResources().getString(R.string.genericServerResponseError));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -225,9 +212,8 @@ public class IssueActions {
|
|||||||
|
|
||||||
public static void unsubscribe(final Context ctx) {
|
public static void unsubscribe(final Context ctx) {
|
||||||
|
|
||||||
final TinyDB tinyDB = new TinyDB(ctx);
|
final TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||||
|
|
||||||
final String instanceUrl = tinyDB.getString("instanceUrl");
|
|
||||||
String[] repoFullName = tinyDB.getString("repoFullName").split("/");
|
String[] repoFullName = tinyDB.getString("repoFullName").split("/");
|
||||||
if(repoFullName.length != 2) {
|
if(repoFullName.length != 2) {
|
||||||
return;
|
return;
|
||||||
@@ -238,7 +224,7 @@ public class IssueActions {
|
|||||||
|
|
||||||
Call<Void> call;
|
Call<Void> call;
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().delIssueSubscriber(token, repoFullName[0], repoFullName[1], issueNr, userLogin);
|
call = RetrofitClient.getApiInterface(ctx).delIssueSubscriber(token, repoFullName[0], repoFullName[1], issueNr, userLogin);
|
||||||
|
|
||||||
call.enqueue(new Callback<Void>() {
|
call.enqueue(new Callback<Void>() {
|
||||||
|
|
||||||
@@ -268,7 +254,7 @@ public class IssueActions {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.unsubscriptionError));
|
Toasty.error(ctx, ctx.getString(R.string.unSubscriptionError));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,9 +263,65 @@ public class IssueActions {
|
|||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.unsubscriptionError));
|
Toasty.error(ctx, ctx.getResources().getString(R.string.genericServerResponseError));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ActionResult<ActionResult.None> reply(Context context, String comment, int issueIndex) {
|
||||||
|
|
||||||
|
ActionResult<ActionResult.None> actionResult = new ActionResult<>();
|
||||||
|
|
||||||
|
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
|
|
||||||
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
|
String[] parts = repoFullName.split("/");
|
||||||
|
String repoOwner = parts[0];
|
||||||
|
String repoName = parts[1];
|
||||||
|
|
||||||
|
Issues issueComment = new Issues(comment);
|
||||||
|
|
||||||
|
Call<Issues> call = RetrofitClient
|
||||||
|
.getApiInterface(context)
|
||||||
|
.replyCommentToIssue(Authorization.get(context), repoOwner, repoName, issueIndex, issueComment);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<Issues>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<Issues> call, @NonNull retrofit2.Response<Issues> response) {
|
||||||
|
|
||||||
|
if(response.code() == 201) {
|
||||||
|
|
||||||
|
actionResult.finish(ActionResult.Status.SUCCESS);
|
||||||
|
|
||||||
|
tinyDb.putBoolean("commentPosted", true);
|
||||||
|
tinyDb.putBoolean("resumeIssues", true);
|
||||||
|
tinyDb.putBoolean("resumePullRequests", true);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
|
AlertDialogs.authorizationTokenRevokedDialog(context, context.getString(R.string.alertDialogTokenRevokedTitle),
|
||||||
|
context.getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
|
context.getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
|
context.getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
actionResult.finish(ActionResult.Status.FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<Issues> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
Toasty.error(context, context.getResources().getString(R.string.genericServerResponseError));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return actionResult;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
131
app/src/main/java/org/mian/gitnex/actions/LabelsActions.java
Normal file
131
app/src/main/java/org/mian/gitnex/actions/LabelsActions.java
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
package org.mian.gitnex.actions;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import org.gitnex.tea4j.models.Labels;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.adapters.LabelsListAdapter;
|
||||||
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.CustomLabelsSelectionDialogBinding;
|
||||||
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import java.util.List;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class LabelsActions {
|
||||||
|
|
||||||
|
public static void getCurrentIssueLabels(Context ctx, String repoOwner, String repoName, int issueIndex, List<Integer> currentLabelsIds) {
|
||||||
|
|
||||||
|
Call<List<Labels>> callSingleIssueLabels = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.getIssueLabels(Authorization.get(ctx), repoOwner, repoName, issueIndex);
|
||||||
|
|
||||||
|
callSingleIssueLabels.enqueue(new Callback<List<Labels>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> response) {
|
||||||
|
|
||||||
|
if(response.code() == 200) {
|
||||||
|
|
||||||
|
List<Labels> issueLabelsList = response.body();
|
||||||
|
|
||||||
|
assert issueLabelsList != null;
|
||||||
|
|
||||||
|
if(issueLabelsList.size() > 0) {
|
||||||
|
|
||||||
|
for (int i = 0; i < issueLabelsList.size(); i++) {
|
||||||
|
|
||||||
|
currentLabelsIds.add(issueLabelsList.get(i).getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<List<Labels>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
Log.e("onFailure", t.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void getRepositoryLabels(Context ctx, String repoOwner, String repoName, List<Labels> labelsList, Dialog dialogLabels, LabelsListAdapter labelsAdapter, CustomLabelsSelectionDialogBinding labelsBinding) {
|
||||||
|
|
||||||
|
Call<List<Labels>> call = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.getLabels(Authorization.get(ctx), repoOwner, repoName);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<List<Labels>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> response) {
|
||||||
|
|
||||||
|
labelsList.clear();
|
||||||
|
|
||||||
|
if (response.code() == 200) {
|
||||||
|
|
||||||
|
if(response.body() != null) {
|
||||||
|
|
||||||
|
labelsList.addAll(response.body());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load organization labels
|
||||||
|
Call<List<Labels>> callOrgLabels = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.getOrganizationLabels(Authorization.get(ctx), repoOwner);
|
||||||
|
|
||||||
|
callOrgLabels.enqueue(new Callback<List<Labels>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> responseOrg) {
|
||||||
|
|
||||||
|
labelsBinding.progressBar.setVisibility(View.GONE);
|
||||||
|
labelsBinding.dialogFrame.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if(responseOrg.body() != null) {
|
||||||
|
|
||||||
|
labelsList.addAll(responseOrg.body());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(labelsList.isEmpty()) {
|
||||||
|
|
||||||
|
dialogLabels.dismiss();
|
||||||
|
Toasty.warning(ctx, ctx.getResources().getString(R.string.noLabelsFound));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
labelsBinding.labelsRecyclerView.setAdapter(labelsAdapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void onFailure(@NonNull Call<List<Labels>> call, @NonNull Throwable t) {}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
Toasty.error(ctx, ctx.getResources().getString(R.string.genericError));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<List<Labels>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, ctx.getResources().getString(R.string.genericServerResponseError));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,12 +4,12 @@ import android.content.Context;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import org.gitnex.tea4j.models.Milestones;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.Milestones;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
|
|
||||||
@@ -23,9 +23,8 @@ public class MilestoneActions {
|
|||||||
|
|
||||||
public static void closeMilestone(final Context ctx, int milestoneId_) {
|
public static void closeMilestone(final Context ctx, int milestoneId_) {
|
||||||
|
|
||||||
final TinyDB tinyDB = new TinyDB(ctx);
|
final TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||||
|
|
||||||
final String instanceUrl = tinyDB.getString("instanceUrl");
|
|
||||||
String repoFullName = tinyDB.getString("repoFullName");
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
@@ -37,8 +36,7 @@ public class MilestoneActions {
|
|||||||
Call<JsonElement> call;
|
Call<JsonElement> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
|
||||||
.closeReopenMilestone(token, repoOwner, repoName, milestoneId_, milestoneStateJson);
|
.closeReopenMilestone(token, repoOwner, repoName, milestoneId_, milestoneStateJson);
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
@@ -81,9 +79,8 @@ public class MilestoneActions {
|
|||||||
|
|
||||||
public static void openMilestone(final Context ctx, int milestoneId_) {
|
public static void openMilestone(final Context ctx, int milestoneId_) {
|
||||||
|
|
||||||
final TinyDB tinyDB = new TinyDB(ctx);
|
final TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||||
|
|
||||||
final String instanceUrl = tinyDB.getString("instanceUrl");
|
|
||||||
String repoFullName = tinyDB.getString("repoFullName");
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
@@ -95,8 +92,7 @@ public class MilestoneActions {
|
|||||||
Call<JsonElement> call;
|
Call<JsonElement> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
|
||||||
.closeReopenMilestone(token, repoOwner, repoName, milestoneId_, milestoneStateJson);
|
.closeReopenMilestone(token, repoOwner, repoName, milestoneId_, milestoneStateJson);
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package org.mian.gitnex.actions;
|
package org.mian.gitnex.actions;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import org.gitnex.tea4j.models.NotificationThread;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.models.NotificationThread;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import okhttp3.ResponseBody;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,24 +19,22 @@ public class NotificationsActions {
|
|||||||
|
|
||||||
private TinyDB tinyDB;
|
private TinyDB tinyDB;
|
||||||
private Context context;
|
private Context context;
|
||||||
private String instanceUrl;
|
|
||||||
private String instanceToken;
|
private String instanceToken;
|
||||||
|
|
||||||
public NotificationsActions(Context context) {
|
public NotificationsActions(Context context) {
|
||||||
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.tinyDB = new TinyDB(context);
|
this.tinyDB = TinyDB.getInstance(context);
|
||||||
|
|
||||||
String loginUid = tinyDB.getString("loginUid");
|
String loginUid = tinyDB.getString("loginUid");
|
||||||
|
|
||||||
instanceUrl = tinyDB.getString("instanceUrl");
|
|
||||||
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNotificationStatus(NotificationThread notificationThread, NotificationStatus notificationStatus) throws IOException {
|
public void setNotificationStatus(NotificationThread notificationThread, NotificationStatus notificationStatus) throws IOException {
|
||||||
|
|
||||||
Call<ResponseBody> call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface()
|
Call<Void> call = RetrofitClient.getApiInterface(context)
|
||||||
.markNotificationThreadAsRead(instanceToken, notificationThread.getId(), notificationStatus.name());
|
.markNotificationThreadAsRead(instanceToken, notificationThread.getId(), notificationStatus.name());
|
||||||
|
|
||||||
if(!call.execute().isSuccessful()) {
|
if(!call.execute().isSuccessful()) {
|
||||||
@@ -48,7 +45,7 @@ public class NotificationsActions {
|
|||||||
|
|
||||||
public boolean setAllNotificationsRead(Date date) throws IOException {
|
public boolean setAllNotificationsRead(Date date) throws IOException {
|
||||||
|
|
||||||
Call<ResponseBody> call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface()
|
Call<Void> call = RetrofitClient.getApiInterface(context)
|
||||||
.markNotificationThreadsAsRead(instanceToken, AppUtil.getTimestampFromDate(context, date), true,
|
.markNotificationThreadsAsRead(instanceToken, AppUtil.getTimestampFromDate(context, date), true,
|
||||||
new String[]{"unread", "pinned"}, "read");
|
new String[]{"unread", "pinned"}, "read");
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package org.mian.gitnex.actions;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author qwerty287
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PullRequestActions {
|
||||||
|
|
||||||
|
public static void deleteHeadBranch(Context context, String repoOwner, String repoName, String headBranch, boolean showToasts) {
|
||||||
|
Call<JsonElement> call = RetrofitClient
|
||||||
|
.getApiInterface(context)
|
||||||
|
.deleteBranch(Authorization.get(context), repoOwner, repoName, headBranch);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||||
|
|
||||||
|
if(response.code() == 204) {
|
||||||
|
|
||||||
|
if(showToasts) Toasty.success(context, context.getString(R.string.deleteBranchSuccess));
|
||||||
|
}
|
||||||
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
|
AlertDialogs
|
||||||
|
.authorizationTokenRevokedDialog(context, context.getResources().getString(R.string.alertDialogTokenRevokedTitle), context.getResources().getString(R.string.alertDialogTokenRevokedMessage), context.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), context.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
}
|
||||||
|
else if(response.code() == 403) {
|
||||||
|
|
||||||
|
if(showToasts) Toasty.error(context, context.getString(R.string.authorizeError));
|
||||||
|
}
|
||||||
|
else if(response.code() == 404) {
|
||||||
|
|
||||||
|
if(showToasts) Toasty.warning(context, context.getString(R.string.deleteBranchErrorNotFound));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
if(showToasts) Toasty.error(context, context.getString(R.string.genericError));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
if(showToasts) Toasty.error(context, context.getString(R.string.deleteBranchError));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -21,10 +21,8 @@ public class RepositoryActions {
|
|||||||
|
|
||||||
public static void starRepository(final Context context) {
|
public static void starRepository(final Context context) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(context);
|
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
@@ -33,9 +31,8 @@ public class RepositoryActions {
|
|||||||
Call<JsonElement> call;
|
Call<JsonElement> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, context)
|
.getApiInterface(context)
|
||||||
.getApiInterface()
|
.starRepository(Authorization.get(context), repoOwner, repoName);
|
||||||
.starRepository(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
@@ -86,10 +83,8 @@ public class RepositoryActions {
|
|||||||
|
|
||||||
public static void unStarRepository(final Context context) {
|
public static void unStarRepository(final Context context) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(context);
|
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
@@ -98,9 +93,8 @@ public class RepositoryActions {
|
|||||||
Call<JsonElement> call;
|
Call<JsonElement> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, context)
|
.getApiInterface(context)
|
||||||
.getApiInterface()
|
.unStarRepository(Authorization.get(context), repoOwner, repoName);
|
||||||
.unStarRepository(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
@@ -151,10 +145,8 @@ public class RepositoryActions {
|
|||||||
|
|
||||||
public static void watchRepository(final Context context) {
|
public static void watchRepository(final Context context) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(context);
|
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
@@ -163,9 +155,8 @@ public class RepositoryActions {
|
|||||||
Call<JsonElement> call;
|
Call<JsonElement> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, context)
|
.getApiInterface(context)
|
||||||
.getApiInterface()
|
.watchRepository(Authorization.get(context), repoOwner, repoName);
|
||||||
.watchRepository(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
@@ -216,10 +207,8 @@ public class RepositoryActions {
|
|||||||
|
|
||||||
public static void unWatchRepository(final Context context) {
|
public static void unWatchRepository(final Context context) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(context);
|
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
@@ -228,9 +217,8 @@ public class RepositoryActions {
|
|||||||
Call<JsonElement> call;
|
Call<JsonElement> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, context)
|
.getApiInterface(context)
|
||||||
.getApiInterface()
|
.unWatchRepository(Authorization.get(context), repoOwner, repoName);
|
||||||
.unWatchRepository(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
|
|||||||
@@ -21,17 +21,13 @@ public class TeamActions {
|
|||||||
|
|
||||||
public static void removeTeamMember(final Context context, String userName, int teamId) {
|
public static void removeTeamMember(final Context context, String userName, int teamId) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(context);
|
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
Call<JsonElement> call;
|
Call<JsonElement> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, context)
|
.getApiInterface(context)
|
||||||
.getApiInterface()
|
.removeTeamMember(Authorization.get(context), teamId, userName);
|
||||||
.removeTeamMember(Authorization.returnAuthentication(context, loginUid, instanceToken), teamId, userName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
@@ -87,17 +83,11 @@ public class TeamActions {
|
|||||||
|
|
||||||
public static void addTeamMember(final Context context, String userName, int teamId) {
|
public static void addTeamMember(final Context context, String userName, int teamId) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(context);
|
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
Call<JsonElement> call;
|
Call<JsonElement> call = RetrofitClient
|
||||||
|
.getApiInterface(context)
|
||||||
call = RetrofitClient
|
.addTeamMember(Authorization.get(context), teamId, userName);
|
||||||
.getInstance(instanceUrl, context)
|
|
||||||
.getApiInterface()
|
|
||||||
.addTeamMember(Authorization.returnAuthentication(context, loginUid, instanceToken), teamId, userName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
|
|||||||
@@ -13,13 +13,12 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import org.mian.gitnex.R;
|
import org.gitnex.tea4j.models.UserInfo;
|
||||||
|
import org.gitnex.tea4j.models.UserSearch;
|
||||||
import org.mian.gitnex.adapters.UserSearchAdapter;
|
import org.mian.gitnex.adapters.UserSearchAdapter;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityAddCollaboratorToRepositoryBinding;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.models.UserInfo;
|
|
||||||
import org.mian.gitnex.models.UserSearch;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
@@ -32,39 +31,27 @@ import retrofit2.Response;
|
|||||||
public class AddCollaboratorToRepositoryActivity extends BaseActivity {
|
public class AddCollaboratorToRepositoryActivity extends BaseActivity {
|
||||||
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private TextView addCollaboratorSearch;
|
private TextView addCollaboratorSearch;
|
||||||
private TextView noData;
|
private TextView noData;
|
||||||
private ProgressBar mProgressBar;
|
private ProgressBar mProgressBar;
|
||||||
|
|
||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_add_collaborator_to_repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
ActivityAddCollaboratorToRepositoryBinding activityAddCollaboratorToRepositoryBinding = ActivityAddCollaboratorToRepositoryBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityAddCollaboratorToRepositoryBinding.getRoot());
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
ImageView closeActivity = activityAddCollaboratorToRepositoryBinding.close;
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
addCollaboratorSearch = activityAddCollaboratorToRepositoryBinding.addCollaboratorSearch;
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
mRecyclerView = activityAddCollaboratorToRepositoryBinding.recyclerViewUserSearch;
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
mProgressBar = activityAddCollaboratorToRepositoryBinding.progressBar;
|
||||||
String[] parts = repoFullName.split("/");
|
noData = activityAddCollaboratorToRepositoryBinding.noData;
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
|
||||||
addCollaboratorSearch = findViewById(R.id.addCollaboratorSearch);
|
|
||||||
mRecyclerView = findViewById(R.id.recyclerViewUserSearch);
|
|
||||||
mProgressBar = findViewById(R.id.progress_bar);
|
|
||||||
noData = findViewById(R.id.noData);
|
|
||||||
|
|
||||||
addCollaboratorSearch.requestFocus();
|
addCollaboratorSearch.requestFocus();
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
@@ -76,8 +63,11 @@ public class AddCollaboratorToRepositoryActivity extends BaseActivity {
|
|||||||
addCollaboratorSearch.setOnEditorActionListener((v, actionId, event) -> {
|
addCollaboratorSearch.setOnEditorActionListener((v, actionId, event) -> {
|
||||||
|
|
||||||
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
||||||
|
|
||||||
if(!addCollaboratorSearch.getText().toString().equals("")) {
|
if(!addCollaboratorSearch.getText().toString().equals("")) {
|
||||||
loadUserSearchList(instanceUrl, instanceToken, addCollaboratorSearch.getText().toString(), loginUid);
|
|
||||||
|
mProgressBar.setVisibility(View.VISIBLE);
|
||||||
|
loadUserSearchList(addCollaboratorSearch.getText().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,22 +77,26 @@ public class AddCollaboratorToRepositoryActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadUserSearchList(String instanceUrl, String token, String searchKeyword, String loginUid) {
|
public void loadUserSearchList(String searchKeyword) {
|
||||||
|
|
||||||
Call<UserSearch> call = RetrofitClient
|
Call<UserSearch> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(appCtx)
|
||||||
.getApiInterface()
|
.getUserBySearch(Authorization.get(ctx), searchKeyword, 10);
|
||||||
.getUserBySearch(Authorization.returnAuthentication(ctx, loginUid, token), searchKeyword, 10);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<UserSearch>() {
|
call.enqueue(new Callback<UserSearch>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<UserSearch> call, @NonNull Response<UserSearch> response) {
|
public void onResponse(@NonNull Call<UserSearch> call, @NonNull Response<UserSearch> response) {
|
||||||
|
|
||||||
if (response.isSuccessful()) {
|
mProgressBar.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
if (response.code() == 200) {
|
||||||
|
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
getUsersList(response.body().getData(), ctx);
|
getUsersList(response.body().getData(), ctx);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
Log.i("onResponse", String.valueOf(response.code()));
|
Log.i("onResponse", String.valueOf(response.code()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,20 +123,20 @@ public class AddCollaboratorToRepositoryActivity extends BaseActivity {
|
|||||||
mProgressBar.setVisibility(View.VISIBLE);
|
mProgressBar.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if(adapter.getItemCount() > 0) {
|
if(adapter.getItemCount() > 0) {
|
||||||
|
|
||||||
mRecyclerView.setAdapter(adapter);
|
mRecyclerView.setAdapter(adapter);
|
||||||
noData.setVisibility(View.GONE);
|
noData.setVisibility(View.GONE);
|
||||||
mProgressBar.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
noData.setVisibility(View.VISIBLE);
|
noData.setVisibility(View.VISIBLE);
|
||||||
mProgressBar.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mProgressBar.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
onClickListener = view -> finish();
|
onClickListener = view -> finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -9,18 +8,18 @@ import android.view.View;
|
|||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import org.gitnex.tea4j.models.GiteaVersion;
|
||||||
|
import org.gitnex.tea4j.models.UserInfo;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.database.api.BaseApi;
|
||||||
import org.mian.gitnex.database.api.UserAccountsApi;
|
import org.mian.gitnex.database.api.UserAccountsApi;
|
||||||
import org.mian.gitnex.databinding.ActivityAddNewAccountBinding;
|
import org.mian.gitnex.databinding.ActivityAddNewAccountBinding;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.PathsHelper;
|
import org.mian.gitnex.helpers.PathsHelper;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.UrlHelper;
|
import org.mian.gitnex.helpers.UrlHelper;
|
||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.models.GiteaVersion;
|
|
||||||
import org.mian.gitnex.models.UserInfo;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import io.mikael.urlbuilder.UrlBuilder;
|
import io.mikael.urlbuilder.UrlBuilder;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@@ -32,55 +31,43 @@ import retrofit2.Callback;
|
|||||||
|
|
||||||
public class AddNewAccountActivity extends BaseActivity {
|
public class AddNewAccountActivity extends BaseActivity {
|
||||||
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private TinyDB tinyDB;
|
|
||||||
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
private ActivityAddNewAccountBinding viewBinding;
|
private ActivityAddNewAccountBinding viewBinding;
|
||||||
|
|
||||||
private enum Protocol {HTTPS, HTTP}
|
private enum Protocol {HTTPS, HTTP}
|
||||||
|
private String spinnerSelectedValue;
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_add_new_account;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
tinyDB = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
viewBinding = ActivityAddNewAccountBinding.inflate(getLayoutInflater());
|
viewBinding = ActivityAddNewAccountBinding.inflate(getLayoutInflater());
|
||||||
View view = viewBinding.getRoot();
|
setContentView(viewBinding.getRoot());
|
||||||
setContentView(view);
|
|
||||||
|
|
||||||
getWindow().getDecorView().setBackground(new ColorDrawable(Color.TRANSPARENT));
|
getWindow().getDecorView().setBackground(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
viewBinding.close.setOnClickListener(onClickListener);
|
viewBinding.close.setOnClickListener(onClickListener);
|
||||||
|
viewBinding.instanceUrl.setText(getIntent().getStringExtra("instanceUrl"));
|
||||||
|
|
||||||
ArrayAdapter<AddNewAccountActivity.Protocol> adapterProtocols = new ArrayAdapter<>(AddNewAccountActivity.this, R.layout.spinner_item, AddNewAccountActivity.Protocol.values());
|
ArrayAdapter<Protocol> adapterProtocols = new ArrayAdapter<>(ctx, R.layout.list_spinner_items, Protocol.values());
|
||||||
adapterProtocols.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
|
||||||
|
|
||||||
viewBinding.protocolSpinner.setAdapter(adapterProtocols);
|
viewBinding.protocolSpinner.setAdapter(adapterProtocols);
|
||||||
|
viewBinding.protocolSpinner.setOnItemClickListener((parent, view1, position, id) -> spinnerSelectedValue = String.valueOf(parent.getItemAtPosition(position)));
|
||||||
viewBinding.addNewAccount.setOnClickListener(login -> {
|
viewBinding.addNewAccount.setOnClickListener(login -> {
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
|
|
||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
processLogin();
|
processLogin();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,9 +75,15 @@ public class AddNewAccountActivity extends BaseActivity {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String instanceUrlET = viewBinding.instanceUrl.getText().toString();
|
String instanceUrlET = String.valueOf(viewBinding.instanceUrl.getText());
|
||||||
String loginToken = viewBinding.loginToken.getText().toString();
|
String loginToken = String.valueOf(viewBinding.loginToken.getText());
|
||||||
Protocol protocol = (Protocol) viewBinding.protocolSpinner.getSelectedItem();
|
String protocol = spinnerSelectedValue;
|
||||||
|
|
||||||
|
if(protocol == null) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getResources().getString(R.string.protocolEmptyError));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(instanceUrlET.equals("")) {
|
if(instanceUrlET.equals("")) {
|
||||||
|
|
||||||
@@ -106,10 +99,7 @@ public class AddNewAccountActivity extends BaseActivity {
|
|||||||
|
|
||||||
URI rawInstanceUrl = UrlBuilder.fromString(UrlHelper.fixScheme(instanceUrlET, "http")).toUri();
|
URI rawInstanceUrl = UrlBuilder.fromString(UrlHelper.fixScheme(instanceUrlET, "http")).toUri();
|
||||||
|
|
||||||
URI instanceUrlWithProtocol = UrlBuilder.fromUri(rawInstanceUrl).withPath(PathsHelper.join(rawInstanceUrl.getPath()))
|
URI instanceUrl = UrlBuilder.fromUri(rawInstanceUrl).withScheme(protocol.toLowerCase()).withPath(PathsHelper.join(rawInstanceUrl.getPath(), "/api/v1/"))
|
||||||
.withScheme(protocol.name().toLowerCase()).toUri();
|
|
||||||
|
|
||||||
URI instanceUrl = UrlBuilder.fromUri(instanceUrlWithProtocol).withPath(PathsHelper.join(instanceUrlWithProtocol.getPath(), "/api/v1/"))
|
|
||||||
.toUri();
|
.toUri();
|
||||||
|
|
||||||
versionCheck(instanceUrl.toString(), loginToken);
|
versionCheck(instanceUrl.toString(), loginToken);
|
||||||
@@ -126,9 +116,7 @@ public class AddNewAccountActivity extends BaseActivity {
|
|||||||
private void versionCheck(final String instanceUrl, final String loginToken) {
|
private void versionCheck(final String instanceUrl, final String loginToken) {
|
||||||
|
|
||||||
Call<GiteaVersion> callVersion;
|
Call<GiteaVersion> callVersion;
|
||||||
|
callVersion = RetrofitClient.getApiInterface(ctx, instanceUrl).getGiteaVersionWithToken("token " + loginToken);
|
||||||
callVersion = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithToken(loginToken);
|
|
||||||
|
|
||||||
callVersion.enqueue(new Callback<GiteaVersion>() {
|
callVersion.enqueue(new Callback<GiteaVersion>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -137,19 +125,18 @@ public class AddNewAccountActivity extends BaseActivity {
|
|||||||
if(responseVersion.code() == 200) {
|
if(responseVersion.code() == 200) {
|
||||||
|
|
||||||
GiteaVersion version = responseVersion.body();
|
GiteaVersion version = responseVersion.body();
|
||||||
Version giteaVersion;
|
|
||||||
|
|
||||||
assert version != null;
|
assert version != null;
|
||||||
|
|
||||||
try {
|
if(!Version.valid(version.getVersion())) {
|
||||||
giteaVersion = new Version(version.getVersion());
|
|
||||||
}
|
|
||||||
catch(Exception e) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.versionUnknown));
|
Toasty.error(ctx, getResources().getString(R.string.versionUnknown));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tinyDB.putString("giteaVersion", version.getVersion());
|
||||||
|
Version giteaVersion = new Version(version.getVersion());
|
||||||
|
|
||||||
if(giteaVersion.less(getString(R.string.versionLow))) {
|
if(giteaVersion.less(getString(R.string.versionLow))) {
|
||||||
|
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctx).setTitle(getString(R.string.versionAlertDialogHeader))
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctx).setTitle(getString(R.string.versionAlertDialogHeader))
|
||||||
@@ -159,7 +146,6 @@ public class AddNewAccountActivity extends BaseActivity {
|
|||||||
alertDialogBuilder.setNegativeButton(getString(R.string.cancelButton), (dialog, which) -> {
|
alertDialogBuilder.setNegativeButton(getString(R.string.cancelButton), (dialog, which) -> {
|
||||||
|
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
//enableProcessButton();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
alertDialogBuilder.setPositiveButton(getString(R.string.textContinue), (dialog, which) -> {
|
alertDialogBuilder.setPositiveButton(getString(R.string.textContinue), (dialog, which) -> {
|
||||||
@@ -169,7 +155,6 @@ public class AddNewAccountActivity extends BaseActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
alertDialogBuilder.create().show();
|
alertDialogBuilder.create().show();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(giteaVersion.lessOrEqual(getString(R.string.versionHigh))) {
|
else if(giteaVersion.lessOrEqual(getString(R.string.versionHigh))) {
|
||||||
|
|
||||||
@@ -179,7 +164,6 @@ public class AddNewAccountActivity extends BaseActivity {
|
|||||||
|
|
||||||
Toasty.warning(ctx, getResources().getString(R.string.versionUnsupportedNew));
|
Toasty.warning(ctx, getResources().getString(R.string.versionUnsupportedNew));
|
||||||
login(instanceUrl, loginToken);
|
login(instanceUrl, loginToken);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -192,7 +176,6 @@ public class AddNewAccountActivity extends BaseActivity {
|
|||||||
private void login(String instanceUrl, String loginToken) {
|
private void login(String instanceUrl, String loginToken) {
|
||||||
|
|
||||||
setupNewAccountWithToken(instanceUrl, loginToken);
|
setupNewAccountWithToken(instanceUrl, loginToken);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -206,7 +189,7 @@ public class AddNewAccountActivity extends BaseActivity {
|
|||||||
|
|
||||||
private void setupNewAccountWithToken(String instanceUrl, final String loginToken) {
|
private void setupNewAccountWithToken(String instanceUrl, final String loginToken) {
|
||||||
|
|
||||||
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserInfo("token " + loginToken);
|
Call<UserInfo> call = RetrofitClient.getApiInterface(ctx, instanceUrl).getUserInfo("token " + loginToken);
|
||||||
|
|
||||||
call.enqueue(new Callback<UserInfo>() {
|
call.enqueue(new Callback<UserInfo>() {
|
||||||
|
|
||||||
@@ -222,14 +205,15 @@ public class AddNewAccountActivity extends BaseActivity {
|
|||||||
assert userDetails != null;
|
assert userDetails != null;
|
||||||
// insert new account to db if does not exist
|
// insert new account to db if does not exist
|
||||||
String accountName = userDetails.getUsername() + "@" + instanceUrl;
|
String accountName = userDetails.getUsername() + "@" + instanceUrl;
|
||||||
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
|
UserAccountsApi userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class);
|
||||||
int checkAccount = userAccountsApi.getCount(accountName);
|
boolean userAccountExists = userAccountsApi.userAccountExists(accountName);
|
||||||
|
|
||||||
if(checkAccount == 0) {
|
if(!userAccountExists) {
|
||||||
|
|
||||||
userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), loginToken, "");
|
userAccountsApi.createNewAccount(accountName, instanceUrl, userDetails.getUsername(), loginToken, "");
|
||||||
Toasty.success(ctx, getResources().getString(R.string.accountAddedMessage));
|
Toasty.success(ctx, getResources().getString(R.string.accountAddedMessage));
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
@@ -239,12 +223,12 @@ public class AddNewAccountActivity extends BaseActivity {
|
|||||||
|
|
||||||
case 401:
|
case 401:
|
||||||
|
|
||||||
Toasty.error(ctx,getResources().getString(R.string.unauthorizedApiError));
|
Toasty.error(ctx, getResources().getString(R.string.unauthorizedApiError));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
Toasty.error(ctx,getResources().getString(R.string.genericApiStatusError) + response.code());
|
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -253,7 +237,7 @@ public class AddNewAccountActivity extends BaseActivity {
|
|||||||
public void onFailure(@NonNull Call<UserInfo> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<UserInfo> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
Toasty.error(ctx,getResources().getString(R.string.genericError));
|
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -14,13 +14,12 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import org.mian.gitnex.R;
|
import org.gitnex.tea4j.models.UserInfo;
|
||||||
|
import org.gitnex.tea4j.models.UserSearch;
|
||||||
import org.mian.gitnex.adapters.UserSearchForTeamMemberAdapter;
|
import org.mian.gitnex.adapters.UserSearchForTeamMemberAdapter;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityAddNewTeamMemberBinding;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.models.UserInfo;
|
|
||||||
import org.mian.gitnex.models.UserSearch;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -35,8 +34,6 @@ import retrofit2.Response;
|
|||||||
public class AddNewTeamMemberActivity extends BaseActivity {
|
public class AddNewTeamMemberActivity extends BaseActivity {
|
||||||
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private TextView addNewTeamMember;
|
private TextView addNewTeamMember;
|
||||||
private TextView noData;
|
private TextView noData;
|
||||||
private ProgressBar mProgressBar;
|
private ProgressBar mProgressBar;
|
||||||
@@ -47,31 +44,21 @@ public class AddNewTeamMemberActivity extends BaseActivity {
|
|||||||
|
|
||||||
private String teamId;
|
private String teamId;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
return R.layout.activity_add_new_team_member;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
ActivityAddNewTeamMemberBinding activityAddNewTeamMemberBinding = ActivityAddNewTeamMemberBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityAddNewTeamMemberBinding.getRoot());
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
ImageView closeActivity = activityAddNewTeamMemberBinding.close;
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
addNewTeamMember = activityAddNewTeamMemberBinding.addNewTeamMember;
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
mRecyclerView = activityAddNewTeamMemberBinding.recyclerViewUserSearch;
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
mProgressBar = activityAddNewTeamMemberBinding.progressBar;
|
||||||
String[] parts = repoFullName.split("/");
|
noData = activityAddNewTeamMemberBinding.noData;
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
|
||||||
addNewTeamMember = findViewById(R.id.addNewTeamMember);
|
|
||||||
mRecyclerView = findViewById(R.id.recyclerViewUserSearch);
|
|
||||||
mProgressBar = findViewById(R.id.progress_bar);
|
|
||||||
noData = findViewById(R.id.noData);
|
|
||||||
|
|
||||||
addNewTeamMember.requestFocus();
|
addNewTeamMember.requestFocus();
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
@@ -81,9 +68,11 @@ public class AddNewTeamMemberActivity extends BaseActivity {
|
|||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
if(getIntent().getStringExtra("teamId") != null && !Objects.requireNonNull(getIntent().getStringExtra("teamId")).equals("")) {
|
if(getIntent().getStringExtra("teamId") != null && !Objects.requireNonNull(getIntent().getStringExtra("teamId")).equals("")) {
|
||||||
|
|
||||||
teamId = getIntent().getStringExtra("teamId");
|
teamId = getIntent().getStringExtra("teamId");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
teamId = "0";
|
teamId = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,10 +92,8 @@ public class AddNewTeamMemberActivity extends BaseActivity {
|
|||||||
if(!addNewTeamMember.getText().toString().equals("") && addNewTeamMember.getText().toString().length() > 1) {
|
if(!addNewTeamMember.getText().toString().equals("") && addNewTeamMember.getText().toString().length() > 1) {
|
||||||
|
|
||||||
adapter = new UserSearchForTeamMemberAdapter(dataList, ctx, Integer.parseInt(teamId));
|
adapter = new UserSearchForTeamMemberAdapter(dataList, ctx, Integer.parseInt(teamId));
|
||||||
loadUserSearchList(instanceUrl, instanceToken, addNewTeamMember.getText().toString(), loginUid, teamId);
|
loadUserSearchList(addNewTeamMember.getText().toString(), teamId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -121,9 +108,9 @@ public class AddNewTeamMemberActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadUserSearchList(String instanceUrl, String token, String searchKeyword, String loginUid, String teamId) {
|
public void loadUserSearchList(String searchKeyword, String teamId) {
|
||||||
|
|
||||||
Call<UserSearch> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserBySearch(Authorization.returnAuthentication(ctx, loginUid, token), searchKeyword, 10);
|
Call<UserSearch> call = RetrofitClient.getApiInterface(ctx).getUserBySearch(Authorization.get(ctx), searchKeyword, 10);
|
||||||
|
|
||||||
mProgressBar.setVisibility(View.VISIBLE);
|
mProgressBar.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
@@ -141,16 +128,13 @@ public class AddNewTeamMemberActivity extends BaseActivity {
|
|||||||
dataList.addAll(response.body().getData());
|
dataList.addAll(response.body().getData());
|
||||||
mRecyclerView.setAdapter(adapter);
|
mRecyclerView.setAdapter(adapter);
|
||||||
noData.setVisibility(View.GONE);
|
noData.setVisibility(View.GONE);
|
||||||
mProgressBar.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
noData.setVisibility(View.VISIBLE);
|
noData.setVisibility(View.VISIBLE);
|
||||||
mProgressBar.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mProgressBar.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,294 +0,0 @@
|
|||||||
package org.mian.gitnex.activities;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.drawable.ColorDrawable;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.Log;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import org.mian.gitnex.R;
|
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
|
||||||
import org.mian.gitnex.helpers.MultiSelectDialog;
|
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
|
||||||
import org.mian.gitnex.models.Collaborators;
|
|
||||||
import org.mian.gitnex.models.Issues;
|
|
||||||
import org.mian.gitnex.models.MultiSelectModel;
|
|
||||||
import org.mian.gitnex.models.UpdateIssueAssignees;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import retrofit2.Call;
|
|
||||||
import retrofit2.Callback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Author M M Arif
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class AddRemoveAssigneesActivity extends BaseActivity {
|
|
||||||
|
|
||||||
private ArrayList<MultiSelectModel> listOfCollaborators = new ArrayList<>();
|
|
||||||
private ArrayList<Integer> issueAssigneesIds = new ArrayList<>();
|
|
||||||
private Boolean assigneesFlag = false;
|
|
||||||
private MultiSelectDialog multiSelectDialogAssignees;
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_add_remove_assignees;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
appCtx = getApplicationContext();
|
|
||||||
//supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
||||||
|
|
||||||
getWindow().getDecorView().setBackground(new ColorDrawable(Color.TRANSPARENT));
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
final int issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
|
|
||||||
|
|
||||||
getAssignees(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getAssignees(final String instanceUrl, final String instanceToken, final String repoOwner, final String repoName, final int issueIndex, final String loginUid) {
|
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
Call<List<Collaborators>> call = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Collaborators>>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull final Call<List<Collaborators>> call, @NonNull final retrofit2.Response<List<Collaborators>> response) {
|
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
|
||||||
if(response.code() == 200) {
|
|
||||||
|
|
||||||
final List<Collaborators> collaboratorsList_ = response.body();
|
|
||||||
|
|
||||||
assert collaboratorsList_ != null;
|
|
||||||
if(collaboratorsList_.size() > 0) {
|
|
||||||
for (int i = 0; i < collaboratorsList_.size(); i++) {
|
|
||||||
|
|
||||||
listOfCollaborators.add(new MultiSelectModel(collaboratorsList_.get(i).getId(), collaboratorsList_.get(i).getUsername().trim()));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// get current issue assignees
|
|
||||||
Call<Issues> callSingleIssueAssignees = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.getIssueByIndex(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
|
|
||||||
|
|
||||||
callSingleIssueAssignees.enqueue(new Callback<Issues>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<Issues> call, @NonNull retrofit2.Response<Issues> response) {
|
|
||||||
|
|
||||||
if(response.code() == 200) {
|
|
||||||
|
|
||||||
Issues issueAssigneesList = response.body();
|
|
||||||
|
|
||||||
assert issueAssigneesList != null;
|
|
||||||
if (issueAssigneesList.getAssignees() != null) {
|
|
||||||
if (issueAssigneesList.getAssignees().size() > 0) {
|
|
||||||
for (int i = 0; i < issueAssigneesList.getAssignees().size(); i++) {
|
|
||||||
|
|
||||||
issueAssigneesIds.add(issueAssigneesList.getAssignees().get(i).getId());
|
|
||||||
|
|
||||||
if(issueAssigneesList.getAssignees().get(i).getUsername().equals(loginUid)) {
|
|
||||||
listOfCollaborators.add(new MultiSelectModel(issueAssigneesList.getAssignees().get(i).getId(), issueAssigneesList.getAssignees().get(i).getUsername().trim()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
assigneesFlag = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
listOfCollaborators.add(new MultiSelectModel(tinyDb.getInt("userId"), loginUid));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(assigneesFlag) {
|
|
||||||
|
|
||||||
multiSelectDialogAssignees = new MultiSelectDialog()
|
|
||||||
.title(getResources().getString(R.string.newIssueSelectAssigneesListTitle))
|
|
||||||
.titleSize(25)
|
|
||||||
.positiveText(getResources().getString(R.string.saveButton))
|
|
||||||
.negativeText(getResources().getString(R.string.cancelButton))
|
|
||||||
.setMinSelectionLimit(0)
|
|
||||||
.preSelectIDsList(issueAssigneesIds)
|
|
||||||
.setMaxSelectionLimit(listOfCollaborators.size())
|
|
||||||
.multiSelectList(listOfCollaborators)
|
|
||||||
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
|
|
||||||
@Override
|
|
||||||
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
|
|
||||||
|
|
||||||
Log.i("selectedNames", String.valueOf(selectedNames));
|
|
||||||
|
|
||||||
updateIssueAssignees(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, loginUid, issueIndex, selectedNames);
|
|
||||||
tinyDb.putBoolean("singleIssueUpdate", true);
|
|
||||||
CloseActivity();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCancel() {
|
|
||||||
CloseActivity();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
multiSelectDialogAssignees = new MultiSelectDialog()
|
|
||||||
.title(getResources().getString(R.string.newIssueSelectAssigneesListTitle))
|
|
||||||
.titleSize(25)
|
|
||||||
.positiveText(getResources().getString(R.string.saveButton))
|
|
||||||
.negativeText(getResources().getString(R.string.cancelButton))
|
|
||||||
.setMinSelectionLimit(0)
|
|
||||||
.setMaxSelectionLimit(listOfCollaborators.size())
|
|
||||||
.multiSelectList(listOfCollaborators)
|
|
||||||
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
|
|
||||||
@Override
|
|
||||||
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
|
|
||||||
|
|
||||||
updateIssueAssignees(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, loginUid, issueIndex, selectedNames);
|
|
||||||
tinyDb.putBoolean("singleIssueUpdate", true);
|
|
||||||
CloseActivity();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCancel() {
|
|
||||||
CloseActivity();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
multiSelectDialogAssignees.show(getSupportFragmentManager(), "issueMultiSelectDialog");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<Issues> call, @NonNull Throwable t) {
|
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
// get current issue assignees
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 401) {
|
|
||||||
|
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 403) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 404) {
|
|
||||||
|
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.genericError));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
|
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CloseActivity() {
|
|
||||||
this.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateIssueAssignees(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, String loginUid, int issueIndex, List<String> issueAssigneesList) {
|
|
||||||
|
|
||||||
UpdateIssueAssignees updateAssigneeJson = new UpdateIssueAssignees(issueAssigneesList);
|
|
||||||
|
|
||||||
Call<JsonElement> call3;
|
|
||||||
|
|
||||||
call3 = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.patchIssueAssignees(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, updateAssigneeJson);
|
|
||||||
|
|
||||||
call3.enqueue(new Callback<JsonElement>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response2) {
|
|
||||||
|
|
||||||
if(response2.code() == 201) {
|
|
||||||
|
|
||||||
Toasty.success(ctx, ctx.getString(R.string.assigneesUpdated));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response2.code() == 401) {
|
|
||||||
|
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response2.code() == 403) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response2.code() == 404) {
|
|
||||||
|
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.genericError));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,308 +0,0 @@
|
|||||||
package org.mian.gitnex.activities;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.drawable.ColorDrawable;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.Log;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import org.mian.gitnex.R;
|
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
|
||||||
import org.mian.gitnex.helpers.MultiSelectDialog;
|
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
|
||||||
import org.mian.gitnex.models.Labels;
|
|
||||||
import org.mian.gitnex.models.MultiSelectModel;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import retrofit2.Call;
|
|
||||||
import retrofit2.Callback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Author M M Arif
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class AddRemoveLabelsActivity extends BaseActivity {
|
|
||||||
|
|
||||||
private ArrayList<MultiSelectModel> listOfLabels = new ArrayList<>();
|
|
||||||
private ArrayList<Integer> issueLabelIds = new ArrayList<>();
|
|
||||||
private Boolean labelsFlag = false;
|
|
||||||
private MultiSelectDialog multiSelectDialogLabels;
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_add_remove_labels;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
appCtx = getApplicationContext();
|
|
||||||
//supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
||||||
|
|
||||||
getWindow().getDecorView().setBackground(new ColorDrawable(Color.TRANSPARENT));
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
final int issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
|
|
||||||
|
|
||||||
getLabels(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getLabels(final String instanceUrl, final String instanceToken, final String repoOwner, final String repoName, final int issueIndex, final String loginUid) {
|
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
Call<List<Labels>> call = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.getlabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Labels>>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> response) {
|
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
|
||||||
if(response.code() == 200) {
|
|
||||||
|
|
||||||
List<Labels> labelsList_ = response.body();
|
|
||||||
|
|
||||||
assert labelsList_ != null;
|
|
||||||
if(labelsList_.size() > 0) {
|
|
||||||
for (int i = 0; i < labelsList_.size(); i++) {
|
|
||||||
|
|
||||||
listOfLabels.add(new MultiSelectModel(labelsList_.get(i).getId(), labelsList_.get(i).getName().trim()));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// get current issue labels
|
|
||||||
Call<List<Labels>> callSingleIssueLabels = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.getIssueLabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
|
|
||||||
|
|
||||||
callSingleIssueLabels.enqueue(new Callback<List<Labels>>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> response) {
|
|
||||||
|
|
||||||
if(response.code() == 200) {
|
|
||||||
|
|
||||||
List<Labels> issueLabelsList = response.body();
|
|
||||||
|
|
||||||
assert issueLabelsList != null;
|
|
||||||
if(issueLabelsList.size() > 0) {
|
|
||||||
for (int i = 0; i < issueLabelsList.size(); i++) {
|
|
||||||
|
|
||||||
issueLabelIds.add(issueLabelsList.get(i).getId());
|
|
||||||
|
|
||||||
}
|
|
||||||
labelsFlag = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(labelsFlag) {
|
|
||||||
|
|
||||||
multiSelectDialogLabels = new MultiSelectDialog()
|
|
||||||
.title(getResources().getString(R.string.newIssueSelectLabelsListTitle))
|
|
||||||
.titleSize(25)
|
|
||||||
.positiveText(getResources().getString(R.string.saveButton))
|
|
||||||
.negativeText(getResources().getString(R.string.cancelButton))
|
|
||||||
.setMinSelectionLimit(0)
|
|
||||||
.preSelectIDsList(issueLabelIds)
|
|
||||||
.setMaxSelectionLimit(listOfLabels.size())
|
|
||||||
.multiSelectList(listOfLabels)
|
|
||||||
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
|
|
||||||
@Override
|
|
||||||
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
|
|
||||||
|
|
||||||
String labelIds = selectedIds.toString();
|
|
||||||
int[] integers;
|
|
||||||
if (selectedIds.size() > 0) {
|
|
||||||
|
|
||||||
String[] items = labelIds.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\s", "").split(",");
|
|
||||||
integers = new int[items.length];
|
|
||||||
for (int i = 0; i < integers.length; i++) {
|
|
||||||
integers[i] = Integer.parseInt(items[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
integers = new int[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
updateIssueLabels(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, integers, loginUid);
|
|
||||||
tinyDb.putBoolean("singleIssueUpdate", true);
|
|
||||||
CloseActivity();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCancel() {
|
|
||||||
CloseActivity();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
multiSelectDialogLabels = new MultiSelectDialog()
|
|
||||||
.title(getResources().getString(R.string.newIssueSelectLabelsListTitle))
|
|
||||||
.titleSize(25)
|
|
||||||
.positiveText(getResources().getString(R.string.saveButton))
|
|
||||||
.negativeText(getResources().getString(R.string.cancelButton))
|
|
||||||
.setMinSelectionLimit(0)
|
|
||||||
.setMaxSelectionLimit(listOfLabels.size())
|
|
||||||
.multiSelectList(listOfLabels)
|
|
||||||
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
|
|
||||||
@Override
|
|
||||||
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
|
|
||||||
|
|
||||||
String labelIds = selectedIds.toString();
|
|
||||||
int[] integers;
|
|
||||||
if (selectedIds.size() > 0) {
|
|
||||||
|
|
||||||
String[] items = labelIds.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\s", "").split(",");
|
|
||||||
integers = new int[items.length];
|
|
||||||
for (int i = 0; i < integers.length; i++) {
|
|
||||||
integers[i] = Integer.parseInt(items[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
integers = new int[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
updateIssueLabels(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, integers, loginUid);
|
|
||||||
tinyDb.putBoolean("singleIssueUpdate", true);
|
|
||||||
CloseActivity();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCancel() {
|
|
||||||
CloseActivity();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
multiSelectDialogLabels.show(getSupportFragmentManager(), "issueMultiSelectDialog");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<List<Labels>> call, @NonNull Throwable t) {
|
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
// get current issue labels
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 401) {
|
|
||||||
|
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 403) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 404) {
|
|
||||||
|
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.genericError));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<List<Labels>> call, @NonNull Throwable t) {
|
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateIssueLabels(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, int issueIndex, int[] issueLabels, String loginUid) {
|
|
||||||
|
|
||||||
Labels patchIssueLabels = new Labels(issueLabels);
|
|
||||||
|
|
||||||
Call<JsonElement> call = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.updateIssueLabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, patchIssueLabels);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
|
||||||
|
|
||||||
if(response.code() == 200) {
|
|
||||||
|
|
||||||
Toasty.success(ctx, ctx.getString(R.string.labelsUpdated));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 401) {
|
|
||||||
|
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 403) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 404) {
|
|
||||||
|
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.genericError));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CloseActivity() {
|
|
||||||
this.finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.view.View;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import org.mian.gitnex.adapters.AdminCronTasksAdapter;
|
||||||
|
import org.mian.gitnex.databinding.ActivityAdminCronTasksBinding;
|
||||||
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
|
import org.mian.gitnex.viewmodels.AdminCronTasksViewModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AdminCronTasksActivity extends BaseActivity {
|
||||||
|
|
||||||
|
private View.OnClickListener onClickListener;
|
||||||
|
private AdminCronTasksAdapter adapter;
|
||||||
|
|
||||||
|
private ActivityAdminCronTasksBinding activityAdminCronTasksBinding;
|
||||||
|
|
||||||
|
public static final int PAGE = 1;
|
||||||
|
public static final int LIMIT = 50;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
activityAdminCronTasksBinding = ActivityAdminCronTasksBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityAdminCronTasksBinding.getRoot());
|
||||||
|
|
||||||
|
initCloseListener();
|
||||||
|
activityAdminCronTasksBinding.close.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
|
Toolbar toolbar = activityAdminCronTasksBinding.toolbar;
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
|
activityAdminCronTasksBinding.recyclerView.setHasFixedSize(true);
|
||||||
|
activityAdminCronTasksBinding.recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
||||||
|
|
||||||
|
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(activityAdminCronTasksBinding.recyclerView.getContext(),
|
||||||
|
DividerItemDecoration.VERTICAL);
|
||||||
|
activityAdminCronTasksBinding.recyclerView.addItemDecoration(dividerItemDecoration);
|
||||||
|
|
||||||
|
activityAdminCronTasksBinding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
|
|
||||||
|
activityAdminCronTasksBinding.pullToRefresh.setRefreshing(false);
|
||||||
|
AdminCronTasksViewModel.loadCronTasksList(ctx, Authorization.get(ctx), PAGE, LIMIT);
|
||||||
|
|
||||||
|
}, 500));
|
||||||
|
|
||||||
|
fetchDataAsync(ctx, Authorization.get(ctx));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fetchDataAsync(Context ctx, String instanceToken) {
|
||||||
|
|
||||||
|
AdminCronTasksViewModel cronTasksViewModel = new ViewModelProvider(this).get(AdminCronTasksViewModel.class);
|
||||||
|
|
||||||
|
cronTasksViewModel.getCronTasksList(ctx, instanceToken, PAGE, LIMIT).observe(this, cronTasksListMain -> {
|
||||||
|
|
||||||
|
adapter = new AdminCronTasksAdapter(ctx, cronTasksListMain);
|
||||||
|
|
||||||
|
if(adapter.getItemCount() > 0) {
|
||||||
|
|
||||||
|
activityAdminCronTasksBinding.recyclerView.setVisibility(View.VISIBLE);
|
||||||
|
activityAdminCronTasksBinding.recyclerView.setAdapter(adapter);
|
||||||
|
activityAdminCronTasksBinding.noData.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
activityAdminCronTasksBinding.recyclerView.setVisibility(View.GONE);
|
||||||
|
activityAdminCronTasksBinding.noData.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initCloseListener() {
|
||||||
|
onClickListener = view -> finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -20,10 +21,10 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.adapters.AdminGetUsersAdapter;
|
import org.mian.gitnex.adapters.AdminGetUsersAdapter;
|
||||||
|
import org.mian.gitnex.databinding.ActivityAdminGetUsersBinding;
|
||||||
import org.mian.gitnex.fragments.BottomSheetAdminUsersFragment;
|
import org.mian.gitnex.fragments.BottomSheetAdminUsersFragment;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.viewmodels.AdminGetUsersViewModel;
|
import org.mian.gitnex.viewmodels.AdminGetUsersViewModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,36 +34,26 @@ import org.mian.gitnex.viewmodels.AdminGetUsersViewModel;
|
|||||||
public class AdminGetUsersActivity extends BaseActivity implements BottomSheetAdminUsersFragment.BottomSheetListener {
|
public class AdminGetUsersActivity extends BaseActivity implements BottomSheetAdminUsersFragment.BottomSheetListener {
|
||||||
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private AdminGetUsersAdapter adapter;
|
private AdminGetUsersAdapter adapter;
|
||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
private TextView noDataUsers;
|
private TextView noDataUsers;
|
||||||
private Boolean searchFilter = false;
|
private Boolean searchFilter = false;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_admin_get_users;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
ActivityAdminGetUsersBinding activityAdminGetUsersBinding = ActivityAdminGetUsersBinding.inflate(getLayoutInflater());
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
setContentView(activityAdminGetUsersBinding.getRoot());
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activityAdminGetUsersBinding.close;
|
||||||
noDataUsers = findViewById(R.id.noDataUsers);
|
noDataUsers = activityAdminGetUsersBinding.noDataUsers;
|
||||||
mRecyclerView = findViewById(R.id.recyclerView);
|
mRecyclerView = activityAdminGetUsersBinding.recyclerView;
|
||||||
|
|
||||||
final SwipeRefreshLayout swipeRefresh = findViewById(R.id.pullToRefresh);
|
final SwipeRefreshLayout swipeRefresh = activityAdminGetUsersBinding.pullToRefresh;
|
||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = activityAdminGetUsersBinding.toolbar;
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
@@ -75,33 +66,33 @@ public class AdminGetUsersActivity extends BaseActivity implements BottomSheetAd
|
|||||||
DividerItemDecoration.VERTICAL);
|
DividerItemDecoration.VERTICAL);
|
||||||
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
||||||
|
|
||||||
swipeRefresh.setOnRefreshListener(() -> new Handler().postDelayed(() -> {
|
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
|
|
||||||
swipeRefresh.setRefreshing(false);
|
swipeRefresh.setRefreshing(false);
|
||||||
AdminGetUsersViewModel.loadUsersList(ctx, instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken));
|
AdminGetUsersViewModel.loadUsersList(ctx, Authorization.get(ctx));
|
||||||
|
|
||||||
}, 500));
|
}, 500));
|
||||||
|
|
||||||
fetchDataAsync(ctx, instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken));
|
fetchDataAsync(ctx, Authorization.get(ctx));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchDataAsync(Context ctx, String instanceUrl, String instanceToken) {
|
private void fetchDataAsync(Context ctx, String instanceToken) {
|
||||||
|
|
||||||
AdminGetUsersViewModel usersModel = new ViewModelProvider(this).get(AdminGetUsersViewModel.class);
|
AdminGetUsersViewModel usersModel = new ViewModelProvider(this).get(AdminGetUsersViewModel.class);
|
||||||
|
|
||||||
usersModel.getUsersList(ctx, instanceUrl, instanceToken).observe(this, usersListMain -> {
|
usersModel.getUsersList(ctx, instanceToken).observe(this, usersListMain -> {
|
||||||
|
|
||||||
adapter = new AdminGetUsersAdapter(ctx, usersListMain);
|
adapter = new AdminGetUsersAdapter(ctx, usersListMain);
|
||||||
if(adapter.getItemCount() > 0) {
|
if(adapter.getItemCount() > 0) {
|
||||||
|
|
||||||
mRecyclerView.setVisibility(View.VISIBLE);
|
mRecyclerView.setVisibility(View.VISIBLE);
|
||||||
mRecyclerView.setAdapter(adapter);
|
mRecyclerView.setAdapter(adapter);
|
||||||
noDataUsers.setVisibility(View.GONE);
|
noDataUsers.setVisibility(View.GONE);
|
||||||
searchFilter = true;
|
searchFilter = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//adapter.notifyDataSetChanged();
|
|
||||||
//mRecyclerView.setAdapter(adapter);
|
|
||||||
mRecyclerView.setVisibility(View.GONE);
|
mRecyclerView.setVisibility(View.GONE);
|
||||||
noDataUsers.setVisibility(View.VISIBLE);
|
noDataUsers.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
@@ -116,7 +107,7 @@ public class AdminGetUsersActivity extends BaseActivity implements BottomSheetAd
|
|||||||
final MenuInflater inflater = getMenuInflater();
|
final MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
||||||
|
|
||||||
new Handler().postDelayed(() -> {
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
|
|
||||||
if(searchFilter) {
|
if(searchFilter) {
|
||||||
|
|
||||||
@@ -139,6 +130,7 @@ public class AdminGetUsersActivity extends BaseActivity implements BottomSheetAd
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String newText) {
|
public boolean onQueryTextChange(String newText) {
|
||||||
|
|
||||||
adapter.getFilter().filter(newText);
|
adapter.getFilter().filter(newText);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -156,18 +148,21 @@ public class AdminGetUsersActivity extends BaseActivity implements BottomSheetAd
|
|||||||
|
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
|
|
||||||
switch (id) {
|
if(id == android.R.id.home) {
|
||||||
case android.R.id.home:
|
|
||||||
finish();
|
|
||||||
return true;
|
|
||||||
case R.id.genericMenu:
|
|
||||||
BottomSheetAdminUsersFragment bottomSheet = new BottomSheetAdminUsersFragment();
|
|
||||||
bottomSheet.show(getSupportFragmentManager(), "usersBottomSheet");
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(id == R.id.genericMenu) {
|
||||||
|
|
||||||
|
BottomSheetAdminUsersFragment bottomSheet = new BottomSheetAdminUsersFragment();
|
||||||
|
bottomSheet.show(getSupportFragmentManager(), "usersBottomSheet");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,143 +2,135 @@ package org.mian.gitnex.activities;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import org.acra.ACRA;
|
import androidx.biometric.BiometricPrompt;
|
||||||
import org.acra.BuildConfig;
|
import androidx.core.content.ContextCompat;
|
||||||
import org.acra.annotation.AcraNotification;
|
|
||||||
import org.acra.config.CoreConfigurationBuilder;
|
|
||||||
import org.acra.config.LimiterConfigurationBuilder;
|
|
||||||
import org.acra.config.MailSenderConfigurationBuilder;
|
|
||||||
import org.acra.data.StringFormat;
|
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.FontsOverride;
|
|
||||||
import org.mian.gitnex.helpers.TimeHelper;
|
import org.mian.gitnex.helpers.TimeHelper;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.notifications.NotificationsMaster;
|
import org.mian.gitnex.notifications.Notifications;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@AcraNotification(resIcon = R.drawable.gitnex_transparent,
|
|
||||||
resTitle = R.string.crashTitle,
|
|
||||||
resChannelName = R.string.setCrashReports,
|
|
||||||
resText = R.string.crashMessage)
|
|
||||||
|
|
||||||
public abstract class BaseActivity extends AppCompatActivity {
|
public abstract class BaseActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private Context appCtx;
|
protected TinyDB tinyDB;
|
||||||
|
|
||||||
|
protected Context ctx = this;
|
||||||
|
protected Context appCtx;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
appCtx = getApplicationContext();
|
super.onCreate(savedInstanceState);
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
switch(tinyDb.getInt("themeId")) {
|
this.appCtx = getApplicationContext();
|
||||||
|
this.tinyDB = TinyDB.getInstance(appCtx);
|
||||||
|
|
||||||
|
switch(tinyDB.getInt("themeId")) {
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
|
||||||
|
tinyDB.putString("currentTheme", "light");
|
||||||
setTheme(R.style.AppThemeLight);
|
setTheme(R.style.AppThemeLight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
if(TimeHelper.timeBetweenHours(18, 6)) { // 6pm to 6am
|
|
||||||
|
if(TimeHelper.timeBetweenHours(tinyDB.getInt("darkThemeTimeHour"), tinyDB.getInt("lightThemeTimeHour"), tinyDB.getInt("darkThemeTimeMinute"), tinyDB.getInt("lightThemeTimeMinute"))) {
|
||||||
|
|
||||||
|
tinyDB.putString("currentTheme", "dark");
|
||||||
setTheme(R.style.AppTheme);
|
setTheme(R.style.AppTheme);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
tinyDB.putString("currentTheme", "light");
|
||||||
setTheme(R.style.AppThemeLight);
|
setTheme(R.style.AppThemeLight);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 3:
|
||||||
|
|
||||||
|
tinyDB.putString("currentTheme", "light");
|
||||||
|
setTheme(R.style.AppThemeRetro);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if(TimeHelper.timeBetweenHours(tinyDB.getInt("darkThemeTimeHour"), tinyDB.getInt("lightThemeTimeHour"), tinyDB.getInt("darkThemeTimeMinute"), tinyDB.getInt("lightThemeTimeMinute"))) {
|
||||||
|
|
||||||
|
tinyDB.putString("currentTheme", "dark");
|
||||||
|
setTheme(R.style.AppTheme);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
tinyDB.putString("currentTheme", "light");
|
||||||
|
setTheme(R.style.AppThemeRetro);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
|
||||||
|
tinyDB.putString("currentTheme", "dark");
|
||||||
|
setTheme(R.style.AppThemePitchBlack);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
|
tinyDB.putString("currentTheme", "dark");
|
||||||
setTheme(R.style.AppTheme);
|
setTheme(R.style.AppTheme);
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String appLocale = tinyDb.getString("locale");
|
String locale = tinyDB.getString("locale");
|
||||||
AppUtil.setAppLocale(getResources(), appLocale);
|
if (locale.isEmpty()) {
|
||||||
|
AppUtil.setAppLocale(getResources(), Locale.getDefault().getLanguage());
|
||||||
super.onCreate(savedInstanceState);
|
}
|
||||||
setContentView(getLayoutResourceId());
|
else {
|
||||||
|
AppUtil.setAppLocale(getResources(), locale);
|
||||||
switch(tinyDb.getInt("customFontId", -1)) {
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/roboto.ttf");
|
|
||||||
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/roboto.ttf");
|
|
||||||
FontsOverride.setDefaultFont(this, "SERIF", "fonts/roboto.ttf");
|
|
||||||
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/roboto.ttf");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/sourcecodeproregular.ttf");
|
|
||||||
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/sourcecodeproregular.ttf");
|
|
||||||
FontsOverride.setDefaultFont(this, "SERIF", "fonts/sourcecodeproregular.ttf");
|
|
||||||
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/sourcecodeproregular.ttf");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/manroperegular.ttf");
|
|
||||||
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/manroperegular.ttf");
|
|
||||||
FontsOverride.setDefaultFont(this, "SERIF", "fonts/manroperegular.ttf");
|
|
||||||
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/manroperegular.ttf");
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(tinyDb.getInt("pollingDelayMinutes") == 0) {
|
|
||||||
tinyDb.putInt("pollingDelayMinutes", 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
NotificationsMaster.hireWorker(appCtx);
|
|
||||||
|
|
||||||
// enabling counter badges by default
|
|
||||||
if(tinyDb.getString("enableCounterBadgesInit").isEmpty()) {
|
|
||||||
tinyDb.putBoolean("enableCounterBadges", true);
|
|
||||||
tinyDb.putString("enableCounterBadgesInit", "yes");
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable crash reports by default
|
|
||||||
if(tinyDb.getString("crashReportingEnabledInit").isEmpty()) {
|
|
||||||
tinyDb.putBoolean("crashReportingEnabled", true);
|
|
||||||
tinyDb.putString("crashReportingEnabledInit", "yes");
|
|
||||||
}
|
|
||||||
|
|
||||||
// default cache setter
|
|
||||||
if(tinyDb.getString("cacheSizeStr").isEmpty()) {
|
|
||||||
tinyDb.putString("cacheSizeStr", getResources().getString(R.string.cacheSizeDataSelectionSelectedText));
|
|
||||||
}
|
|
||||||
if(tinyDb.getString("cacheSizeImagesStr").isEmpty()) {
|
|
||||||
tinyDb.putString("cacheSizeImagesStr", getResources().getString(R.string.cacheSizeImagesSelectionSelectedText));
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable comment drafts by default
|
|
||||||
if(tinyDb.getString("draftsCommentsDeletionEnabledInit").isEmpty()) {
|
|
||||||
tinyDb.putBoolean("draftsCommentsDeletionEnabled", true);
|
|
||||||
tinyDb.putString("draftsCommentsDeletionEnabledInit", "yes");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!tinyDb.getString("instanceUrlWithProtocol").endsWith("/")) {
|
|
||||||
|
|
||||||
tinyDb.putString("instanceUrlWithProtocol", tinyDb.getString("instanceUrlWithProtocol") + "/");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tinyDb.getBoolean("crashReportingEnabled")) {
|
|
||||||
|
|
||||||
CoreConfigurationBuilder ACRABuilder = new CoreConfigurationBuilder(this);
|
|
||||||
ACRABuilder.setBuildConfigClass(BuildConfig.class).setReportFormat(StringFormat.KEY_VALUE_LIST);
|
|
||||||
ACRABuilder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder.class).setReportAsFile(true).setMailTo(getResources().getString(R.string.appEmail)).setSubject(getResources().getString(R.string.crashReportEmailSubject, AppUtil.getAppBuildNo(getApplicationContext()))).setEnabled(true);
|
|
||||||
ACRABuilder.getPluginConfigurationBuilder(LimiterConfigurationBuilder.class).setEnabled(true);
|
|
||||||
ACRA.init(getApplication(), ACRABuilder);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Notifications.startWorker(appCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract int getLayoutResourceId();
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
if(tinyDB.getBoolean("biometricStatus") && !tinyDB.getBoolean("biometricLifeCycle")) {
|
||||||
|
|
||||||
|
Executor executor = ContextCompat.getMainExecutor(this);
|
||||||
|
|
||||||
|
BiometricPrompt biometricPrompt = new BiometricPrompt(this, executor, new BiometricPrompt.AuthenticationCallback() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
|
||||||
|
|
||||||
|
super.onAuthenticationError(errorCode, errString);
|
||||||
|
|
||||||
|
// Authentication error, close the app
|
||||||
|
if(errorCode == BiometricPrompt.ERROR_USER_CANCELED ||
|
||||||
|
errorCode == BiometricPrompt.ERROR_NEGATIVE_BUTTON) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Authentication succeeded, continue to app
|
||||||
|
@Override public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) { super.onAuthenticationSucceeded(result); tinyDB.putBoolean("biometricLifeCycle", true); }
|
||||||
|
|
||||||
|
// Authentication failed, close the app
|
||||||
|
@Override public void onAuthenticationFailed() { super.onAuthenticationFailed(); }
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
BiometricPrompt.PromptInfo biometricPromptBuilder = new BiometricPrompt.PromptInfo.Builder()
|
||||||
|
.setTitle(getString(R.string.biometricAuthTitle))
|
||||||
|
.setSubtitle(getString(R.string.biometricAuthSubTitle))
|
||||||
|
.setNegativeButtonText(getString(R.string.cancelButton)).build();
|
||||||
|
|
||||||
|
biometricPrompt.authenticate(biometricPromptBuilder);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.text.method.ScrollingMovementMethod;
|
import android.text.method.ScrollingMovementMethod;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -18,15 +18,15 @@ import androidx.appcompat.widget.Toolbar;
|
|||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
import org.gitnex.tea4j.models.Commits;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.adapters.CommitsAdapter;
|
import org.mian.gitnex.adapters.CommitsAdapter;
|
||||||
import org.mian.gitnex.clients.AppApiService;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityCommitsBinding;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
import org.mian.gitnex.helpers.Constants;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.interfaces.ApiInterface;
|
|
||||||
import org.mian.gitnex.models.Commits;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@@ -39,73 +39,63 @@ import retrofit2.Response;
|
|||||||
|
|
||||||
public class CommitsActivity extends BaseActivity {
|
public class CommitsActivity extends BaseActivity {
|
||||||
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
private TextView noData;
|
private TextView noData;
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
private String TAG = "CommitsActivity";
|
private String TAG = "CommitsActivity";
|
||||||
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
|
private int resultLimit = Constants.resultLimitOldGiteaInstances;
|
||||||
private int pageSize = 1;
|
private int pageSize = 1;
|
||||||
|
|
||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
private List<Commits> commitsList;
|
private List<Commits> commitsList;
|
||||||
private CommitsAdapter adapter;
|
private CommitsAdapter adapter;
|
||||||
private ApiInterface api;
|
|
||||||
private ProgressBar progressLoadMore;
|
private ProgressBar progressLoadMore;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_commits;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
ActivityCommitsBinding activityCommitsBinding = ActivityCommitsBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityCommitsBinding.getRoot());
|
||||||
|
|
||||||
|
Toolbar toolbar = activityCommitsBinding.toolbar;
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
|
|
||||||
String branchName = getIntent().getStringExtra("branchName");
|
String branchName = getIntent().getStringExtra("branchName");
|
||||||
|
|
||||||
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
TextView toolbar_title = activityCommitsBinding.toolbarTitle;
|
||||||
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
|
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
|
||||||
toolbar_title.setText(branchName);
|
toolbar_title.setText(branchName);
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activityCommitsBinding.close;
|
||||||
noData = findViewById(R.id.noDataCommits);
|
noData = activityCommitsBinding.noDataCommits;
|
||||||
progressLoadMore = findViewById(R.id.progressLoadMore);
|
progressLoadMore = activityCommitsBinding.progressLoadMore;
|
||||||
progressBar = findViewById(R.id.progress_bar);
|
progressBar = activityCommitsBinding.progressBar;
|
||||||
SwipeRefreshLayout swipeRefresh = findViewById(R.id.pullToRefresh);
|
SwipeRefreshLayout swipeRefresh = activityCommitsBinding.pullToRefresh;
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
// if gitea is 1.12 or higher use the new limit (resultLimitNewGiteaInstances)
|
// if gitea is 1.12 or higher use the new limit (resultLimitNewGiteaInstances)
|
||||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12")) {
|
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12")) {
|
||||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
|
||||||
|
resultLimit = Constants.resultLimitNewGiteaInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
recyclerView = findViewById(R.id.recyclerView);
|
recyclerView = activityCommitsBinding.recyclerView;
|
||||||
commitsList = new ArrayList<>();
|
commitsList = new ArrayList<>();
|
||||||
|
|
||||||
swipeRefresh.setOnRefreshListener(() -> new Handler().postDelayed(() -> {
|
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
|
|
||||||
swipeRefresh.setRefreshing(false);
|
swipeRefresh.setRefreshing(false);
|
||||||
loadInitial(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, branchName, resultLimit);
|
loadInitial(Authorization.get(ctx), repoOwner, repoName, branchName, resultLimit);
|
||||||
adapter.notifyDataChanged();
|
adapter.notifyDataChanged();
|
||||||
|
|
||||||
}, 200));
|
}, 200));
|
||||||
|
|
||||||
adapter = new CommitsAdapter(ctx, commitsList);
|
adapter = new CommitsAdapter(ctx, commitsList);
|
||||||
@@ -114,31 +104,27 @@ public class CommitsActivity extends BaseActivity {
|
|||||||
if(commitsList.size() == resultLimit || pageSize == resultLimit) {
|
if(commitsList.size() == resultLimit || pageSize == resultLimit) {
|
||||||
|
|
||||||
int page = (commitsList.size() + resultLimit) / resultLimit;
|
int page = (commitsList.size() + resultLimit) / resultLimit;
|
||||||
loadMore(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, page, branchName, resultLimit);
|
loadMore(Authorization.get(ctx), repoOwner, repoName, page, branchName, resultLimit);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
recyclerView.setHasFixedSize(true);
|
recyclerView.setHasFixedSize(true);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
api = AppApiService.createService(ApiInterface.class, instanceUrl, ctx);
|
loadInitial(Authorization.get(ctx), repoOwner, repoName, branchName, resultLimit);
|
||||||
loadInitial(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, branchName, resultLimit);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadInitial(String token, String repoOwner, String repoName, String branchName, int resultLimit) {
|
private void loadInitial(String token, String repoOwner, String repoName, String branchName, int resultLimit) {
|
||||||
|
|
||||||
Call<List<Commits>> call = api.getRepositoryCommits(token, repoOwner, repoName, 1, branchName, resultLimit);
|
Call<List<Commits>> call = RetrofitClient.getApiInterface(ctx).getRepositoryCommits(token, repoOwner, repoName, 1, branchName, resultLimit);
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Commits>>() {
|
call.enqueue(new Callback<List<Commits>>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) {
|
public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.code() == 200) {
|
||||||
|
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
if(response.body().size() > 0) {
|
if(response.body().size() > 0) {
|
||||||
@@ -147,29 +133,30 @@ public class CommitsActivity extends BaseActivity {
|
|||||||
commitsList.addAll(response.body());
|
commitsList.addAll(response.body());
|
||||||
adapter.notifyDataChanged();
|
adapter.notifyDataChanged();
|
||||||
noData.setVisibility(View.GONE);
|
noData.setVisibility(View.GONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
commitsList.clear();
|
commitsList.clear();
|
||||||
adapter.notifyDataChanged();
|
adapter.notifyDataChanged();
|
||||||
noData.setVisibility(View.VISIBLE);
|
noData.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(response.code() == 409) {
|
||||||
|
|
||||||
progressBar.setVisibility(View.GONE);
|
noData.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Log.e(TAG, String.valueOf(response.code()));
|
Log.e(TAG, String.valueOf(response.code()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e(TAG, t.toString());
|
Toasty.error(ctx, getResources().getString(R.string.errorOnLogin));
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -180,7 +167,7 @@ public class CommitsActivity extends BaseActivity {
|
|||||||
|
|
||||||
progressLoadMore.setVisibility(View.VISIBLE);
|
progressLoadMore.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
Call<List<Commits>> call = api.getRepositoryCommits(token, repoOwner, repoName, page, branchName, resultLimit);
|
Call<List<Commits>> call = RetrofitClient.getApiInterface(ctx).getRepositoryCommits(token, repoOwner, repoName, page, branchName, resultLimit);
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Commits>>() {
|
call.enqueue(new Callback<List<Commits>>() {
|
||||||
|
|
||||||
@@ -190,37 +177,32 @@ public class CommitsActivity extends BaseActivity {
|
|||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
List<Commits> result = response.body();
|
List<Commits> result = response.body();
|
||||||
|
|
||||||
assert result != null;
|
assert result != null;
|
||||||
|
|
||||||
if(result.size() > 0) {
|
if(result.size() > 0) {
|
||||||
|
|
||||||
pageSize = result.size();
|
pageSize = result.size();
|
||||||
commitsList.addAll(result);
|
commitsList.addAll(result);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
adapter.setMoreDataAvailable(false);
|
adapter.setMoreDataAvailable(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter.notifyDataChanged();
|
adapter.notifyDataChanged();
|
||||||
progressLoadMore.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Log.e(TAG, String.valueOf(response.code()));
|
Log.e(TAG, String.valueOf(response.code()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progressLoadMore.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e(TAG, t.toString());
|
Toasty.error(ctx, getResources().getString(R.string.errorOnLogin));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -255,7 +237,6 @@ public class CommitsActivity extends BaseActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filter(String text) {
|
private void filter(String text) {
|
||||||
@@ -263,7 +244,9 @@ public class CommitsActivity extends BaseActivity {
|
|||||||
List<Commits> arr = new ArrayList<>();
|
List<Commits> arr = new ArrayList<>();
|
||||||
|
|
||||||
for(Commits d : commitsList) {
|
for(Commits d : commitsList) {
|
||||||
|
|
||||||
if(d.getCommit().getMessage().toLowerCase().contains(text) || d.getSha().toLowerCase().contains(text)) {
|
if(d.getCommit().getMessage().toLowerCase().contains(text) || d.getSha().toLowerCase().contains(text)) {
|
||||||
|
|
||||||
arr.add(d);
|
arr.add(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -274,6 +257,7 @@ public class CommitsActivity extends BaseActivity {
|
|||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
|
|
||||||
onClickListener = view -> {
|
onClickListener = view -> {
|
||||||
|
|
||||||
getIntent().removeExtra("branchName");
|
getIntent().removeExtra("branchName");
|
||||||
finish();
|
finish();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,31 +1,28 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import org.gitnex.tea4j.models.Branches;
|
||||||
|
import org.gitnex.tea4j.models.DeleteFile;
|
||||||
|
import org.gitnex.tea4j.models.EditFile;
|
||||||
|
import org.gitnex.tea4j.models.NewFile;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityCreateFileBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.NetworkStatusObserver;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.Branches;
|
|
||||||
import org.mian.gitnex.models.DeleteFile;
|
|
||||||
import org.mian.gitnex.models.EditFile;
|
|
||||||
import org.mian.gitnex.models.NewFile;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@@ -37,284 +34,190 @@ import retrofit2.Callback;
|
|||||||
|
|
||||||
public class CreateFileActivity extends BaseActivity {
|
public class CreateFileActivity extends BaseActivity {
|
||||||
|
|
||||||
public ImageView closeActivity;
|
private ActivityCreateFileBinding binding;
|
||||||
private View.OnClickListener onClickListener;
|
|
||||||
private Button newFileCreate;
|
public static final int FILE_ACTION_CREATE = 0;
|
||||||
|
public static final int FILE_ACTION_DELETE = 1;
|
||||||
|
public static final int FILE_ACTION_EDIT = 2;
|
||||||
|
|
||||||
|
private int fileAction = FILE_ACTION_CREATE;
|
||||||
|
|
||||||
private EditText newFileName;
|
|
||||||
private EditText newFileContent;
|
|
||||||
private EditText newFileBranchName;
|
|
||||||
private EditText newFileCommitMessage;
|
|
||||||
private Spinner newFileBranchesSpinner;
|
|
||||||
private String filePath;
|
private String filePath;
|
||||||
private String fileSha;
|
private String fileSha;
|
||||||
private int fileAction = 0; // 0 = create, 1 = delete, 2 = edit
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private TinyDB tinyDb;
|
|
||||||
|
|
||||||
List<Branches> branchesList = new ArrayList<>();
|
private final List<String> branches = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
private String repoOwner;
|
||||||
protected int getLayoutResourceId(){
|
private String repoName;
|
||||||
return R.layout.activity_new_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
binding = ActivityCreateFileBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(binding.getRoot());
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
repoName = parts[1];
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
closeActivity = findViewById(R.id.close);
|
TextView toolbarTitle = binding.toolbarTitle;
|
||||||
newFileName = findViewById(R.id.newFileName);
|
|
||||||
newFileContent = findViewById(R.id.newFileContent);
|
|
||||||
newFileBranchName = findViewById(R.id.newFileBranchName);
|
|
||||||
newFileCommitMessage = findViewById(R.id.newFileCommitMessage);
|
|
||||||
TextView branchNameId = findViewById(R.id.branchNameId);
|
|
||||||
TextView branchNameHintText = findViewById(R.id.branchNameHintText);
|
|
||||||
TextView toolbarTitle = findViewById(R.id.toolbarTitle);
|
|
||||||
TextView fileNameHint = findViewById(R.id.fileNameHint);
|
|
||||||
|
|
||||||
newFileName.requestFocus();
|
binding.newFileName.requestFocus();
|
||||||
assert imm != null;
|
|
||||||
imm.showSoftInput(newFileName, InputMethodManager.SHOW_IMPLICIT);
|
|
||||||
|
|
||||||
initCloseListener();
|
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
assert inputMethodManager != null;
|
||||||
|
inputMethodManager.showSoftInput(binding.newFileName, InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
|
||||||
newFileCreate = findViewById(R.id.newFileCreate);
|
binding.close.setOnClickListener(view -> finish());
|
||||||
|
binding.newFileContent.setOnTouchListener((touchView, motionEvent) -> {
|
||||||
|
|
||||||
if(getIntent().getStringExtra("filePath") != null && getIntent().getIntExtra("fileAction", 1) == 1) {
|
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||||
|
|
||||||
fileNameHint.setVisibility(View.GONE);
|
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 &&
|
||||||
fileAction = getIntent().getIntExtra("fileAction", 1);
|
(motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||||
|
|
||||||
|
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
if(getIntent().getStringExtra("filePath") != null && getIntent().getIntExtra("fileAction", FILE_ACTION_DELETE) == FILE_ACTION_DELETE) {
|
||||||
|
|
||||||
|
fileAction = getIntent().getIntExtra("fileAction", FILE_ACTION_DELETE);
|
||||||
filePath = getIntent().getStringExtra("filePath");
|
filePath = getIntent().getStringExtra("filePath");
|
||||||
String fileContents = getIntent().getStringExtra("fileContents");
|
|
||||||
fileSha = getIntent().getStringExtra("fileSha");
|
fileSha = getIntent().getStringExtra("fileSha");
|
||||||
|
|
||||||
toolbarTitle.setText(getString(R.string.deleteFileText, filePath));
|
toolbarTitle.setText(getString(R.string.deleteFileText, filePath));
|
||||||
|
|
||||||
newFileCreate.setText(R.string.deleteFile);
|
binding.newFileCreate.setText(R.string.deleteFile);
|
||||||
newFileName.setText(filePath);
|
|
||||||
newFileName.setEnabled(false);
|
binding.newFileNameLayout.setVisibility(View.GONE);
|
||||||
newFileName.setFocusable(false);
|
binding.newFileContentLayout.setVisibility(View.GONE);
|
||||||
|
|
||||||
newFileContent.setText(fileContents);
|
|
||||||
newFileContent.setEnabled(false);
|
|
||||||
newFileContent.setFocusable(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getIntent().getStringExtra("filePath") != null && getIntent().getIntExtra("fileAction", 2) == 2) {
|
if(getIntent().getStringExtra("filePath") != null && getIntent().getIntExtra("fileAction", FILE_ACTION_EDIT) == FILE_ACTION_EDIT) {
|
||||||
|
|
||||||
fileNameHint.setVisibility(View.GONE);
|
|
||||||
fileAction = getIntent().getIntExtra("fileAction", 2);
|
|
||||||
|
|
||||||
|
fileAction = getIntent().getIntExtra("fileAction", FILE_ACTION_EDIT);
|
||||||
filePath = getIntent().getStringExtra("filePath");
|
filePath = getIntent().getStringExtra("filePath");
|
||||||
String fileContents = getIntent().getStringExtra("fileContents");
|
|
||||||
fileSha = getIntent().getStringExtra("fileSha");
|
fileSha = getIntent().getStringExtra("fileSha");
|
||||||
|
|
||||||
toolbarTitle.setText(getString(R.string.editFileText, filePath));
|
toolbarTitle.setText(getString(R.string.editFileText, filePath));
|
||||||
|
|
||||||
newFileCreate.setText(R.string.editFile);
|
binding.newFileCreate.setText(R.string.editFile);
|
||||||
newFileName.setText(filePath);
|
binding.newFileName.setText(filePath);
|
||||||
newFileName.setEnabled(false);
|
binding.newFileName.setEnabled(false);
|
||||||
newFileName.setFocusable(false);
|
binding.newFileName.setFocusable(false);
|
||||||
|
|
||||||
|
binding.newFileContent.setText(getIntent().getStringExtra("fileContents"));
|
||||||
|
|
||||||
newFileContent.setText(fileContents);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initCloseListener();
|
getBranches(repoOwner, repoName);
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
|
||||||
|
|
||||||
newFileBranchesSpinner = findViewById(R.id.newFileBranchesSpinner);
|
|
||||||
newFileBranchesSpinner.getBackground().setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
|
|
||||||
getBranches(instanceUrl, instanceToken, repoOwner, repoName, loginUid);
|
|
||||||
|
|
||||||
newFileBranchesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
|
|
||||||
{
|
|
||||||
public void onItemSelected(AdapterView<?> arg0,
|
|
||||||
View arg1, int arg2, long arg3)
|
|
||||||
{
|
|
||||||
Branches bModelValue = (Branches) newFileBranchesSpinner.getSelectedItem();
|
|
||||||
|
|
||||||
if(bModelValue.toString().equals("No branch")) {
|
|
||||||
newFileBranchName.setEnabled(true);
|
|
||||||
newFileBranchName.setVisibility(View.VISIBLE);
|
|
||||||
branchNameId.setVisibility(View.VISIBLE);
|
|
||||||
branchNameHintText.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
newFileBranchName.setEnabled(false);
|
|
||||||
newFileBranchName.setVisibility(View.GONE);
|
|
||||||
branchNameId.setVisibility(View.GONE);
|
|
||||||
branchNameHintText.setVisibility(View.GONE);
|
|
||||||
newFileBranchName.setText("");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onNothingSelected(AdapterView<?> arg0) {}
|
|
||||||
});
|
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
|
|
||||||
if(!connToInternet) {
|
NetworkStatusObserver networkStatusObserver = NetworkStatusObserver.getInstance(ctx);
|
||||||
|
networkStatusObserver.registerNetworkStatusListener(binding.newFileCreate::setEnabled);
|
||||||
|
|
||||||
newFileCreate.setEnabled(false);
|
binding.newFileCreate.setOnClickListener(v -> processNewFile());
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
newFileCreate.setOnClickListener(createFileListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener createFileListener = v -> processNewFile();
|
|
||||||
|
|
||||||
private void processNewFile() {
|
private void processNewFile() {
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
String newFileName = binding.newFileName.getText() != null ? binding.newFileName.getText().toString() : "";
|
||||||
AppUtil appUtil = new AppUtil();
|
String newFileContent = binding.newFileContent.getText() != null ? binding.newFileContent.getText().toString() : "";
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
String newFileBranchName = binding.newFileBranches.getText() != null ? binding.newFileBranches.getText().toString() : "";
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
String newFileCommitMessage = binding.newFileCommitMessage.getText() != null ? binding.newFileCommitMessage.getText().toString() : "";
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
|
|
||||||
String newFileName_ = newFileName.getText().toString();
|
|
||||||
String newFileContent_ = newFileContent.getText().toString();
|
|
||||||
String newFileBranchName_ = newFileBranchName.getText().toString();
|
|
||||||
String newFileCommitMessage_ = newFileCommitMessage.getText().toString();
|
|
||||||
|
|
||||||
Branches currentBranch = (Branches) newFileBranchesSpinner.getSelectedItem();
|
|
||||||
|
|
||||||
if(!connToInternet) {
|
|
||||||
|
|
||||||
|
if(!AppUtil.hasNetworkConnection(appCtx)) {
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newFileName_.equals("") || newFileContent_.equals("") || newFileCommitMessage_.equals("")) {
|
if(((newFileName.isEmpty() || newFileContent.isEmpty()) && fileAction != FILE_ACTION_DELETE) || newFileCommitMessage.isEmpty()) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.newFileRequiredFields));
|
Toasty.error(ctx, getString(R.string.newFileRequiredFields));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentBranch.toString().equals("No branch")) {
|
if(!AppUtil.checkStringsWithDash(newFileBranchName)) {
|
||||||
|
Toasty.error(ctx, getString(R.string.newFileInvalidBranchName));
|
||||||
if(newFileBranchName_.equals("")) {
|
return;
|
||||||
Toasty.error(ctx, getString(R.string.newFileRequiredFieldNewBranchName));
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(!appUtil.checkStringsWithDash(newFileBranchName_)) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.newFileInvalidBranchName));
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(appUtil.charactersLength(newFileCommitMessage_) > 255) {
|
|
||||||
|
|
||||||
|
if(newFileCommitMessage.length() > 255) {
|
||||||
Toasty.warning(ctx, getString(R.string.newFileCommitMessageError));
|
Toasty.warning(ctx, getString(R.string.newFileCommitMessageError));
|
||||||
|
return;
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
disableProcessButton();
|
|
||||||
|
|
||||||
if(fileAction == 1) {
|
|
||||||
|
|
||||||
deleteFile(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, filePath,
|
|
||||||
newFileBranchName_, newFileCommitMessage_, currentBranch.toString(), fileSha);
|
|
||||||
}
|
|
||||||
else if(fileAction == 2) {
|
|
||||||
|
|
||||||
editFile(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, filePath,
|
|
||||||
appUtil.encodeBase64(newFileContent_), newFileBranchName_, newFileCommitMessage_, currentBranch.toString(), fileSha);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
createNewFile(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, newFileName_,
|
|
||||||
appUtil.encodeBase64(newFileContent_), newFileBranchName_, newFileCommitMessage_, currentBranch.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disableProcessButton();
|
||||||
|
|
||||||
|
switch(fileAction) {
|
||||||
|
|
||||||
|
case FILE_ACTION_CREATE:
|
||||||
|
createNewFile(repoOwner, repoName, newFileName, AppUtil.encodeBase64(newFileContent), newFileCommitMessage, newFileBranchName);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FILE_ACTION_DELETE:
|
||||||
|
deleteFile(repoOwner, repoName, filePath, newFileCommitMessage, newFileBranchName, fileSha);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FILE_ACTION_EDIT:
|
||||||
|
editFile(repoOwner, repoName, filePath, AppUtil.encodeBase64(newFileContent), newFileCommitMessage, newFileBranchName, fileSha);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewFile(final String instanceUrl, final String token, String repoOwner, String repoName, String fileName, String fileContent, String fileBranchName, String fileCommitMessage, String currentBranch) {
|
private void createNewFile(String repoOwner, String repoName, String fileName, String fileContent, String fileCommitMessage, String branchName) {
|
||||||
|
|
||||||
NewFile createNewFileJsonStr;
|
NewFile createNewFileJsonStr = branches.contains(branchName) ?
|
||||||
if(currentBranch.equals("No branch")) {
|
new NewFile(branchName, fileContent, fileCommitMessage, "") :
|
||||||
createNewFileJsonStr = new NewFile("", fileContent, fileCommitMessage, fileBranchName);
|
new NewFile("", fileContent, fileCommitMessage, branchName);
|
||||||
}
|
|
||||||
else {
|
|
||||||
createNewFileJsonStr = new NewFile(currentBranch, fileContent, fileCommitMessage, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
Call<JsonElement> call = RetrofitClient
|
Call<JsonElement> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
.createNewFile(Authorization.get(ctx), repoOwner, repoName, fileName, createNewFileJsonStr);
|
||||||
.createNewFile(token, repoOwner, repoName, fileName, createNewFileJsonStr);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||||
|
|
||||||
if(response.code() == 201) {
|
switch(response.code()) {
|
||||||
|
|
||||||
enableProcessButton();
|
case 201:
|
||||||
Toasty.success(ctx, getString(R.string.newFileSuccessMessage));
|
enableProcessButton();
|
||||||
finish();
|
Toasty.success(ctx, getString(R.string.newFileSuccessMessage));
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
case 401:
|
||||||
else if(response.code() == 401) {
|
enableProcessButton();
|
||||||
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||||
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
break;
|
||||||
|
|
||||||
enableProcessButton();
|
case 404:
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
enableProcessButton();
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
Toasty.warning(ctx, getString(R.string.apiNotFound));
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
break;
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
|
|
||||||
}
|
default:
|
||||||
else {
|
enableProcessButton();
|
||||||
|
Toasty.error(ctx, getString(R.string.orgCreatedError));
|
||||||
if(response.code() == 404) {
|
break;
|
||||||
enableProcessButton();
|
|
||||||
Toasty.warning(ctx, getString(R.string.apiNotFound));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
enableProcessButton();
|
|
||||||
Toasty.error(ctx, getString(R.string.orgCreatedError));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -322,70 +225,57 @@ public class CreateFileActivity extends BaseActivity {
|
|||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteFile(final String instanceUrl, final String token, String repoOwner, String repoName, String fileName, String fileBranchName, String fileCommitMessage, String currentBranch, String fileSha) {
|
private void deleteFile(String repoOwner, String repoName, String fileName, String fileCommitMessage, String branchName, String fileSha) {
|
||||||
|
|
||||||
String branchName;
|
DeleteFile deleteFileJsonStr = branches.contains(branchName) ?
|
||||||
DeleteFile deleteFileJsonStr;
|
new DeleteFile(branchName, fileCommitMessage, "", fileSha) :
|
||||||
if(currentBranch.equals("No branch")) {
|
new DeleteFile("", fileCommitMessage, branchName, fileSha);
|
||||||
|
|
||||||
branchName = fileBranchName;
|
|
||||||
deleteFileJsonStr = new DeleteFile("", fileCommitMessage, fileBranchName, fileSha);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
branchName = currentBranch;
|
|
||||||
deleteFileJsonStr = new DeleteFile(currentBranch, fileCommitMessage, "", fileSha);
|
|
||||||
}
|
|
||||||
|
|
||||||
Call<JsonElement> call = RetrofitClient
|
Call<JsonElement> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
.deleteFile(Authorization.get(ctx), repoOwner, repoName, fileName, deleteFileJsonStr);
|
||||||
.deleteFile(token, repoOwner, repoName, fileName, deleteFileJsonStr);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||||
|
|
||||||
if(response.code() == 200) {
|
switch(response.code()) {
|
||||||
|
|
||||||
enableProcessButton();
|
case 200:
|
||||||
Toasty.info(ctx, getString(R.string.deleteFileMessage, branchName));
|
enableProcessButton();
|
||||||
getIntent().removeExtra("filePath");
|
Toasty.info(ctx, getString(R.string.deleteFileMessage, tinyDB.getString("repoBranch")));
|
||||||
getIntent().removeExtra("fileSha");
|
getIntent().removeExtra("filePath");
|
||||||
getIntent().removeExtra("fileContents");
|
getIntent().removeExtra("fileSha");
|
||||||
finish();
|
getIntent().removeExtra("fileContents");
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
case 401:
|
||||||
else if(response.code() == 401) {
|
enableProcessButton();
|
||||||
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||||
enableProcessButton();
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
break;
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
if(response.code() == 404) {
|
|
||||||
|
|
||||||
|
case 404:
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.info(ctx, getString(R.string.apiNotFound));
|
Toasty.info(ctx, getString(R.string.apiNotFound));
|
||||||
}
|
break;
|
||||||
else {
|
|
||||||
|
|
||||||
|
default:
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.info(ctx, getString(R.string.genericError));
|
Toasty.info(ctx, getString(R.string.genericError));
|
||||||
}
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -398,66 +288,52 @@ public class CreateFileActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void editFile(final String instanceUrl, final String token, String repoOwner, String repoName, String fileName, String fileContent, String fileBranchName, String fileCommitMessage, String currentBranch, String fileSha) {
|
private void editFile(String repoOwner, String repoName, String fileName, String fileContent, String fileCommitMessage, String branchName, String fileSha) {
|
||||||
|
|
||||||
String branchName;
|
EditFile editFileJsonStr = branches.contains(branchName) ?
|
||||||
EditFile editFileJsonStr;
|
new EditFile(branchName, fileCommitMessage, "", fileSha, fileContent) :
|
||||||
if(currentBranch.equals("No branch")) {
|
new EditFile("", fileCommitMessage, branchName, fileSha, fileContent);
|
||||||
|
|
||||||
branchName = fileBranchName;
|
|
||||||
editFileJsonStr = new EditFile("", fileCommitMessage, fileBranchName, fileSha, fileContent);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
branchName = currentBranch;
|
|
||||||
editFileJsonStr = new EditFile(currentBranch, fileCommitMessage, "", fileSha, fileContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
Call<JsonElement> call = RetrofitClient
|
Call<JsonElement> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
.editFile(Authorization.get(ctx), repoOwner, repoName, fileName, editFileJsonStr);
|
||||||
.editFile(token, repoOwner, repoName, fileName, editFileJsonStr);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||||
|
|
||||||
if(response.code() == 200) {
|
switch(response.code()) {
|
||||||
|
|
||||||
enableProcessButton();
|
case 200:
|
||||||
Toasty.info(ctx, getString(R.string.editFileMessage, branchName));
|
enableProcessButton();
|
||||||
getIntent().removeExtra("filePath");
|
Toasty.info(ctx, getString(R.string.editFileMessage, branchName));
|
||||||
getIntent().removeExtra("fileSha");
|
getIntent().removeExtra("filePath");
|
||||||
getIntent().removeExtra("fileContents");
|
getIntent().removeExtra("fileSha");
|
||||||
tinyDb.putBoolean("fileModified", true);
|
getIntent().removeExtra("fileContents");
|
||||||
finish();
|
tinyDB.putBoolean("fileModified", true);
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
case 401:
|
||||||
else if(response.code() == 401) {
|
enableProcessButton();
|
||||||
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||||
enableProcessButton();
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
break;
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
if(response.code() == 404) {
|
|
||||||
|
|
||||||
|
case 404:
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.info(ctx, getString(R.string.apiNotFound));
|
Toasty.info(ctx, getString(R.string.apiNotFound));
|
||||||
}
|
break;
|
||||||
else {
|
|
||||||
|
|
||||||
|
default:
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.info(ctx, getString(R.string.genericError));
|
Toasty.info(ctx, getString(R.string.genericError));
|
||||||
}
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -465,73 +341,48 @@ public class CreateFileActivity extends BaseActivity {
|
|||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getBranches(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid) {
|
private void getBranches(String repoOwner, String repoName) {
|
||||||
|
|
||||||
Call<List<Branches>> call = RetrofitClient
|
Call<List<Branches>> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
.getBranches(Authorization.get(ctx), repoOwner, repoName);
|
||||||
.getBranches(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Branches>>() {
|
call.enqueue(new Callback<List<Branches>>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<List<Branches>> call, @NonNull retrofit2.Response<List<Branches>> response) {
|
public void onResponse(@NonNull Call<List<Branches>> call, @NonNull retrofit2.Response<List<Branches>> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.code() == 200) {
|
||||||
if(response.code() == 200) {
|
|
||||||
|
|
||||||
List<Branches> branchesList_ = response.body();
|
assert response.body() != null;
|
||||||
|
for(Branches branch : response.body()) branches.add(branch.getName());
|
||||||
|
|
||||||
branchesList.add(new Branches("No branch"));
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(CreateFileActivity.this, R.layout.list_spinner_items, branches);
|
||||||
assert branchesList_ != null;
|
|
||||||
if(branchesList_.size() > 0) {
|
|
||||||
for (int i = 0; i < branchesList_.size(); i++) {
|
|
||||||
|
|
||||||
Branches data = new Branches(
|
binding.newFileBranches.setAdapter(adapter);
|
||||||
branchesList_.get(i).getName()
|
binding.newFileBranches.setText(tinyDB.getString("repoBranch"), false);
|
||||||
);
|
|
||||||
branchesList.add(data);
|
|
||||||
|
|
||||||
}
|
enableProcessButton();
|
||||||
}
|
|
||||||
|
|
||||||
ArrayAdapter<Branches> adapter = new ArrayAdapter<>(CreateFileActivity.this,
|
|
||||||
R.layout.spinner_item, branchesList);
|
|
||||||
|
|
||||||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
|
||||||
newFileBranchesSpinner.setAdapter(adapter);
|
|
||||||
enableProcessButton();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<List<Branches>> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<List<Branches>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void disableProcessButton() { binding.newFileCreate.setEnabled(false); }
|
||||||
onClickListener = view -> finish();
|
private void enableProcessButton() { binding.newFileCreate.setEnabled(true); }
|
||||||
}
|
|
||||||
|
|
||||||
private void disableProcessButton() {
|
|
||||||
|
|
||||||
newFileCreate.setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void enableProcessButton() {
|
|
||||||
|
|
||||||
newFileCreate.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,304 +1,262 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.DatePickerDialog;
|
import android.app.DatePickerDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.DatePicker;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.hendraanggrian.appcompat.socialview.Mention;
|
import org.gitnex.tea4j.models.Collaborators;
|
||||||
import com.hendraanggrian.appcompat.widget.MentionArrayAdapter;
|
import org.gitnex.tea4j.models.CreateIssue;
|
||||||
import com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView;
|
import org.gitnex.tea4j.models.Labels;
|
||||||
|
import org.gitnex.tea4j.models.Milestones;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.actions.AssigneesActions;
|
||||||
|
import org.mian.gitnex.actions.LabelsActions;
|
||||||
|
import org.mian.gitnex.adapters.AssigneesListAdapter;
|
||||||
|
import org.mian.gitnex.adapters.LabelsListAdapter;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityCreateIssueBinding;
|
||||||
|
import org.mian.gitnex.databinding.CustomAssigneesSelectionDialogBinding;
|
||||||
|
import org.mian.gitnex.databinding.CustomLabelsSelectionDialogBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.MultiSelectDialog;
|
import org.mian.gitnex.helpers.Constants;
|
||||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.models.Collaborators;
|
|
||||||
import org.mian.gitnex.models.CreateIssue;
|
|
||||||
import org.mian.gitnex.models.Labels;
|
|
||||||
import org.mian.gitnex.models.Milestones;
|
|
||||||
import org.mian.gitnex.models.MultiSelectModel;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class CreateIssueActivity extends BaseActivity implements View.OnClickListener {
|
public class CreateIssueActivity extends BaseActivity implements View.OnClickListener, LabelsListAdapter.LabelsListAdapterListener, AssigneesListAdapter.AssigneesListAdapterListener {
|
||||||
|
|
||||||
|
private ActivityCreateIssueBinding viewBinding;
|
||||||
|
private CustomLabelsSelectionDialogBinding labelsBinding;
|
||||||
|
private CustomAssigneesSelectionDialogBinding assigneesBinding;
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
MultiSelectDialog multiSelectDialog;
|
private int resultLimit = Constants.resultLimitOldGiteaInstances;
|
||||||
MultiSelectDialog multiSelectDialogLabels;
|
private Dialog dialogLabels;
|
||||||
private TextView assigneesList;
|
private Dialog dialogAssignees;
|
||||||
private TextView newIssueLabels;
|
private String labelsSetter;
|
||||||
private TextView newIssueDueDate;
|
private String assigneesSetter;
|
||||||
private Spinner newIssueMilestoneSpinner;
|
private int milestoneId;
|
||||||
private EditText newIssueTitle;
|
|
||||||
private SocialAutoCompleteTextView newIssueDescription;
|
|
||||||
private Button createNewIssueButton;
|
|
||||||
private TextView labelsIdHolder;
|
|
||||||
private boolean assigneesFlag;
|
|
||||||
private boolean labelsFlag;
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
|
|
||||||
|
|
||||||
List<Milestones> milestonesList = new ArrayList<>();
|
private String loginUid;
|
||||||
ArrayList<MultiSelectModel> listOfAssignees = new ArrayList<>();
|
private String repoOwner;
|
||||||
ArrayList<MultiSelectModel> listOfLabels= new ArrayList<>();
|
private String repoName;
|
||||||
private ArrayAdapter<Mention> defaultMentionAdapter;
|
|
||||||
|
|
||||||
@Override
|
private LabelsListAdapter labelsAdapter;
|
||||||
protected int getLayoutResourceId(){
|
private AssigneesListAdapter assigneesAdapter;
|
||||||
return R.layout.activity_create_issue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private List<Integer> labelsIds = new ArrayList<>();
|
||||||
|
private List<Labels> labelsList = new ArrayList<>();
|
||||||
|
private List<Milestones> milestonesList = new ArrayList<>();
|
||||||
|
private List<Collaborators> assigneesList = new ArrayList<>();
|
||||||
|
private List<String> assigneesListData = new ArrayList<>();
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
viewBinding = ActivityCreateIssueBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(viewBinding.getRoot());
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
loginUid = tinyDB.getString("loginUid");
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String loginFullName = tinyDb.getString("userFullname");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
repoName = parts[1];
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
// if gitea is 1.12 or higher use the new limit
|
// require gitea 1.12 or higher
|
||||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
|
||||||
|
resultLimit = Constants.resultLimitNewGiteaInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
viewBinding.newIssueTitle.requestFocus();
|
||||||
assigneesList = findViewById(R.id.newIssueAssigneesList);
|
|
||||||
newIssueLabels = findViewById(R.id.newIssueLabels);
|
|
||||||
newIssueDueDate = findViewById(R.id.newIssueDueDate);
|
|
||||||
createNewIssueButton = findViewById(R.id.createNewIssueButton);
|
|
||||||
newIssueTitle = findViewById(R.id.newIssueTitle);
|
|
||||||
newIssueDescription = findViewById(R.id.newIssueDescription);
|
|
||||||
labelsIdHolder = findViewById(R.id.labelsIdHolder);
|
|
||||||
|
|
||||||
newIssueTitle.requestFocus();
|
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
imm.showSoftInput(newIssueTitle, InputMethodManager.SHOW_IMPLICIT);
|
imm.showSoftInput(viewBinding.newIssueTitle, InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
|
||||||
defaultMentionAdapter = new MentionArrayAdapter<>(this);
|
viewBinding.newIssueDescription.setOnTouchListener((touchView, motionEvent) -> {
|
||||||
loadCollaboratorsList();
|
|
||||||
|
|
||||||
newIssueDescription.setMentionAdapter(defaultMentionAdapter);
|
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||||
|
|
||||||
|
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||||
|
|
||||||
|
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
labelsAdapter = new LabelsListAdapter(labelsList, CreateIssueActivity.this, labelsIds);
|
||||||
|
assigneesAdapter = new AssigneesListAdapter(ctx, assigneesList, CreateIssueActivity.this, assigneesListData);
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
viewBinding.close.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
assigneesList.setOnClickListener(this);
|
viewBinding.newIssueAssigneesList.setOnClickListener(this);
|
||||||
newIssueLabels.setOnClickListener(this);
|
viewBinding.newIssueLabels.setOnClickListener(this);
|
||||||
newIssueDueDate.setOnClickListener(this);
|
viewBinding.newIssueDueDate.setOnClickListener(this);
|
||||||
|
|
||||||
newIssueMilestoneSpinner = findViewById(R.id.newIssueMilestoneSpinner);
|
getMilestones(repoOwner, repoName, resultLimit);
|
||||||
newIssueMilestoneSpinner.getBackground().setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
|
|
||||||
getMilestones(instanceUrl, instanceToken, repoOwner, repoName, loginUid, resultLimit);
|
|
||||||
|
|
||||||
getLabels(instanceUrl, instanceToken, repoOwner, repoName, loginUid);
|
|
||||||
getCollaborators(instanceUrl, instanceToken, repoOwner, repoName, loginUid, loginFullName);
|
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
|
|
||||||
|
viewBinding.newIssueLabels.setOnClickListener(newIssueLabels -> showLabels());
|
||||||
|
|
||||||
|
viewBinding.newIssueAssigneesList.setOnClickListener(newIssueAssigneesList -> showAssignees());
|
||||||
|
|
||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
|
|
||||||
createNewIssueButton.setEnabled(false);
|
viewBinding.createNewIssueButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
createNewIssueButton.setOnClickListener(this);
|
viewBinding.createNewIssueButton.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void assigneesInterface(List<String> data) {
|
||||||
|
|
||||||
|
assigneesSetter = String.valueOf(data);
|
||||||
|
viewBinding.newIssueAssigneesList.setText(assigneesSetter.replace("]", "").replace("[", ""));
|
||||||
|
assigneesListData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void labelsInterface(List<String> data) {
|
||||||
|
|
||||||
|
labelsSetter = String.valueOf(data);
|
||||||
|
viewBinding.newIssueLabels.setText(labelsSetter.replace("]", "").replace("[", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void labelsIdsInterface(List<Integer> data) {
|
||||||
|
|
||||||
|
labelsIds = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showAssignees() {
|
||||||
|
|
||||||
|
dialogAssignees = new Dialog(ctx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
||||||
|
|
||||||
|
if (dialogAssignees.getWindow() != null) {
|
||||||
|
|
||||||
|
dialogAssignees.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
assigneesBinding = CustomAssigneesSelectionDialogBinding.inflate(LayoutInflater.from(ctx));
|
||||||
|
|
||||||
|
View view = assigneesBinding.getRoot();
|
||||||
|
dialogAssignees.setContentView(view);
|
||||||
|
|
||||||
|
assigneesBinding.cancel.setOnClickListener(assigneesBinding_ -> dialogAssignees.dismiss());
|
||||||
|
|
||||||
|
dialogAssignees.show();
|
||||||
|
AssigneesActions.getRepositoryAssignees(ctx, repoOwner, repoName, assigneesList, dialogAssignees, assigneesAdapter, assigneesBinding);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showLabels() {
|
||||||
|
|
||||||
|
dialogLabels = new Dialog(ctx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
||||||
|
|
||||||
|
if (dialogLabels.getWindow() != null) {
|
||||||
|
|
||||||
|
dialogLabels.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
labelsBinding = CustomLabelsSelectionDialogBinding.inflate(LayoutInflater.from(ctx));
|
||||||
|
|
||||||
|
View view = labelsBinding.getRoot();
|
||||||
|
dialogLabels.setContentView(view);
|
||||||
|
|
||||||
|
labelsBinding.cancel.setOnClickListener(labelsBinding_ -> dialogLabels.dismiss());
|
||||||
|
|
||||||
|
dialogLabels.show();
|
||||||
|
LabelsActions.getRepositoryLabels(ctx, repoOwner, repoName, labelsList, dialogLabels, labelsAdapter, labelsBinding);
|
||||||
|
}
|
||||||
|
|
||||||
private void processNewIssue() {
|
private void processNewIssue() {
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
Milestones mModel = (Milestones) newIssueMilestoneSpinner.getSelectedItem();
|
String newIssueTitleForm = Objects.requireNonNull(viewBinding.newIssueTitle.getText()).toString();
|
||||||
|
String newIssueDescriptionForm = Objects.requireNonNull(viewBinding.newIssueDescription.getText()).toString();
|
||||||
int newIssueMilestoneIdForm = mModel.getId();
|
String newIssueDueDateForm = Objects.requireNonNull(viewBinding.newIssueDueDate.getText()).toString();
|
||||||
String newIssueTitleForm = newIssueTitle.getText().toString();
|
|
||||||
String newIssueDescriptionForm = newIssueDescription.getText().toString();
|
|
||||||
String newIssueAssigneesListForm = assigneesList.getText().toString();
|
|
||||||
//String newIssueLabelsForm = newIssueLabels.getText().toString();
|
|
||||||
String newIssueDueDateForm = newIssueDueDate.getText().toString();
|
|
||||||
String newIssueLabelsIdHolderForm = labelsIdHolder.getText().toString();
|
|
||||||
|
|
||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newIssueTitleForm.equals("")) {
|
if (newIssueTitleForm.equals("")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.issueTitleEmpty));
|
Toasty.error(ctx, getString(R.string.issueTitleEmpty));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if (newIssueDescriptionForm.equals("")) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.issueDescriptionEmpty));
|
|
||||||
return;
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (newIssueDueDateForm.equals("")) {
|
if (newIssueDueDateForm.equals("")) {
|
||||||
|
|
||||||
newIssueDueDateForm = null;
|
newIssueDueDateForm = null;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
newIssueDueDateForm = (AppUtil.customDateCombine(AppUtil.customDateFormat(newIssueDueDateForm)));
|
newIssueDueDateForm = (AppUtil.customDateCombine(AppUtil.customDateFormat(newIssueDueDateForm)));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> newIssueAssigneesListForm_ = new ArrayList<>(Arrays.asList(newIssueAssigneesListForm.split(",")));
|
|
||||||
|
|
||||||
for (int i = 0; i < newIssueAssigneesListForm_.size(); i++) {
|
|
||||||
newIssueAssigneesListForm_.set(i, newIssueAssigneesListForm_.get(i).trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
int[] integers;
|
|
||||||
if (!newIssueLabelsIdHolderForm.equals("")) {
|
|
||||||
|
|
||||||
String[] items = newIssueLabelsIdHolderForm.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\s", "").split(",");
|
|
||||||
integers = new int[items.length];
|
|
||||||
for (int i = 0; i < integers.length; i++) {
|
|
||||||
integers[i] = Integer.parseInt(items[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
integers = new int[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
//Log.i("FormData", String.valueOf(newIssueLabelsForm));
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
createNewIssueFunc(instanceUrl, instanceToken, repoOwner, repoName, loginUid, newIssueDescriptionForm, newIssueDueDateForm, newIssueMilestoneIdForm, newIssueTitleForm, newIssueAssigneesListForm_, integers);
|
createNewIssueFunc(repoOwner, repoName, loginUid, newIssueDescriptionForm, newIssueDueDateForm, milestoneId, newIssueTitleForm);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadCollaboratorsList() {
|
private void createNewIssueFunc(String repoOwner, String repoName, String loginUid, String newIssueDescriptionForm, String newIssueDueDateForm, int newIssueMilestoneIdForm, String newIssueTitleForm) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
CreateIssue createNewIssueJson = new CreateIssue(loginUid, newIssueDescriptionForm, false, newIssueDueDateForm, newIssueMilestoneIdForm, newIssueTitleForm, assigneesListData, labelsIds);
|
||||||
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
|
|
||||||
Call<List<Collaborators>> call = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Collaborators>>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
|
|
||||||
|
|
||||||
if (response.isSuccessful()) {
|
|
||||||
|
|
||||||
assert response.body() != null;
|
|
||||||
String fullName = "";
|
|
||||||
for (int i = 0; i < response.body().size(); i++) {
|
|
||||||
if(!response.body().get(i).getFull_name().equals("")) {
|
|
||||||
fullName = response.body().get(i).getFull_name();
|
|
||||||
}
|
|
||||||
defaultMentionAdapter.add(
|
|
||||||
new Mention(response.body().get(i).getUsername(), fullName, response.body().get(i).getAvatar_url()));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
Log.i("onResponse", String.valueOf(response.code()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
|
|
||||||
Log.i("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createNewIssueFunc(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, String loginUid, String newIssueDescriptionForm, String newIssueDueDateForm, int newIssueMilestoneIdForm, String newIssueTitleForm, List<String> newIssueAssigneesListForm, int[] newIssueLabelsForm) {
|
|
||||||
|
|
||||||
CreateIssue createNewIssueJson = new CreateIssue(loginUid, newIssueDescriptionForm, false, newIssueDueDateForm, newIssueMilestoneIdForm, newIssueTitleForm, newIssueAssigneesListForm, newIssueLabelsForm);
|
|
||||||
|
|
||||||
Call<JsonElement> call3;
|
Call<JsonElement> call3;
|
||||||
|
|
||||||
call3 = RetrofitClient
|
call3 = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
.createNewIssue(Authorization.get(ctx), repoOwner, repoName, createNewIssueJson);
|
||||||
.createNewIssue(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, createNewIssueJson);
|
|
||||||
|
|
||||||
call3.enqueue(new Callback<JsonElement>() {
|
call3.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response2) {
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response2) {
|
||||||
|
|
||||||
if(response2.isSuccessful()) {
|
if(response2.code() == 201) {
|
||||||
if(response2.code() == 201) {
|
|
||||||
|
|
||||||
//Log.i("isSuccessful1", String.valueOf(response2.body()));
|
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
tinyDb.putBoolean("resumeIssues", true);
|
||||||
tinyDb.putBoolean("resumeIssues", true);
|
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.issueCreated));
|
|
||||||
enableProcessButton();
|
|
||||||
finish();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Toasty.success(ctx, getString(R.string.issueCreated));
|
||||||
|
enableProcessButton();
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
else if(response2.code() == 401) {
|
else if(response2.code() == 401) {
|
||||||
|
|
||||||
@@ -307,21 +265,19 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
|||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.issueCreatedError));
|
Toasty.error(ctx, getString(R.string.issueCreatedError));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
//Log.i("isSuccessful2", String.valueOf(response2.body()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -333,13 +289,12 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
|||||||
onClickListener = view -> finish();
|
onClickListener = view -> finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getMilestones(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid, int resultLimit) {
|
private void getMilestones(String repoOwner, String repoName, int resultLimit) {
|
||||||
|
|
||||||
String msState = "open";
|
String msState = "open";
|
||||||
Call<List<Milestones>> call = RetrofitClient
|
Call<List<Milestones>> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
.getMilestones(Authorization.get(ctx), repoOwner, repoName, 1, resultLimit, msState);
|
||||||
.getMilestones(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, 1, resultLimit, msState);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Milestones>>() {
|
call.enqueue(new Callback<List<Milestones>>() {
|
||||||
|
|
||||||
@@ -347,13 +302,16 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
|||||||
public void onResponse(@NonNull Call<List<Milestones>> call, @NonNull retrofit2.Response<List<Milestones>> response) {
|
public void onResponse(@NonNull Call<List<Milestones>> call, @NonNull retrofit2.Response<List<Milestones>> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
if(response.code() == 200) {
|
if(response.code() == 200) {
|
||||||
|
|
||||||
List<Milestones> milestonesList_ = response.body();
|
List<Milestones> milestonesList_ = response.body();
|
||||||
|
|
||||||
milestonesList.add(new Milestones(0,getString(R.string.issueCreatedNoMilestone)));
|
milestonesList.add(new Milestones(0,getString(R.string.issueCreatedNoMilestone)));
|
||||||
assert milestonesList_ != null;
|
assert milestonesList_ != null;
|
||||||
|
|
||||||
if(milestonesList_.size() > 0) {
|
if(milestonesList_.size() > 0) {
|
||||||
|
|
||||||
for (int i = 0; i < milestonesList_.size(); i++) {
|
for (int i = 0; i < milestonesList_.size(); i++) {
|
||||||
|
|
||||||
//Don't translate "open" is a enum
|
//Don't translate "open" is a enum
|
||||||
@@ -364,17 +322,20 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
|||||||
);
|
);
|
||||||
milestonesList.add(data);
|
milestonesList.add(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayAdapter<Milestones> adapter = new ArrayAdapter<>(CreateIssueActivity.this,
|
ArrayAdapter<Milestones> adapter = new ArrayAdapter<>(CreateIssueActivity.this,
|
||||||
R.layout.spinner_item, milestonesList);
|
R.layout.list_spinner_items, milestonesList);
|
||||||
|
|
||||||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
viewBinding.newIssueMilestoneSpinner.setAdapter(adapter);
|
||||||
newIssueMilestoneSpinner.setAdapter(adapter);
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
|
viewBinding.newIssueMilestoneSpinner.setOnItemClickListener ((parent, view, position, id) ->
|
||||||
|
|
||||||
|
milestoneId = milestonesList.get(position).getId()
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,143 +343,8 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<List<Milestones>> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<List<Milestones>> call, @NonNull Throwable t) {
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
||||||
|
|
||||||
private void getCollaborators(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid, String loginFullName) {
|
|
||||||
|
|
||||||
Call<List<Collaborators>> call = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
listOfAssignees.add(new MultiSelectModel(-1, loginFullName));
|
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Collaborators>>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull retrofit2.Response<List<Collaborators>> response) {
|
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
|
||||||
if(response.code() == 200) {
|
|
||||||
|
|
||||||
List<Collaborators> assigneesList_ = response.body();
|
|
||||||
|
|
||||||
assert assigneesList_ != null;
|
|
||||||
if(assigneesList_.size() > 0) {
|
|
||||||
for (int i = 0; i < assigneesList_.size(); i++) {
|
|
||||||
|
|
||||||
/*String assigneesCopy;
|
|
||||||
if(!assigneesList_.get(i).getFull_name().equals("")) {
|
|
||||||
assigneesCopy = getString(R.string.dialogAssignessText, assigneesList_.get(i).getFull_name(), assigneesList_.get(i).getLogin());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
assigneesCopy = assigneesList_.get(i).getLogin();
|
|
||||||
}*/
|
|
||||||
listOfAssignees.add(new MultiSelectModel(assigneesList_.get(i).getId(), assigneesList_.get(i).getLogin().trim()));
|
|
||||||
|
|
||||||
}
|
|
||||||
assigneesFlag = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiSelectDialog = new MultiSelectDialog()
|
|
||||||
.title(getResources().getString(R.string.newIssueSelectAssigneesListTitle))
|
|
||||||
.titleSize(25)
|
|
||||||
.positiveText(getResources().getString(R.string.okButton))
|
|
||||||
.negativeText(getResources().getString(R.string.cancelButton))
|
|
||||||
.setMinSelectionLimit(0)
|
|
||||||
.setMaxSelectionLimit(listOfAssignees.size())
|
|
||||||
.multiSelectList(listOfAssignees)
|
|
||||||
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
|
|
||||||
@Override
|
|
||||||
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
|
|
||||||
|
|
||||||
assigneesList.setText(dataString);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCancel() {
|
|
||||||
//Log.d("multiSelect","Dialog cancelled");
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
|
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getLabels(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid) {
|
|
||||||
|
|
||||||
Call<List<Labels>> call = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.getlabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Labels>>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> response) {
|
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
|
||||||
if(response.code() == 200) {
|
|
||||||
|
|
||||||
List<Labels> labelsList_ = response.body();
|
|
||||||
|
|
||||||
assert labelsList_ != null;
|
|
||||||
if(labelsList_.size() > 0) {
|
|
||||||
for (int i = 0; i < labelsList_.size(); i++) {
|
|
||||||
|
|
||||||
listOfLabels.add(new MultiSelectModel(labelsList_.get(i).getId(), labelsList_.get(i).getName().trim()));
|
|
||||||
|
|
||||||
}
|
|
||||||
labelsFlag = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
multiSelectDialogLabels = new MultiSelectDialog()
|
|
||||||
.title(getResources().getString(R.string.newIssueSelectLabelsListTitle))
|
|
||||||
.titleSize(25)
|
|
||||||
.positiveText(getResources().getString(R.string.okButton))
|
|
||||||
.negativeText(getResources().getString(R.string.cancelButton))
|
|
||||||
.setMinSelectionLimit(0)
|
|
||||||
.setMaxSelectionLimit(listOfLabels.size())
|
|
||||||
.multiSelectList(listOfLabels)
|
|
||||||
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
|
|
||||||
@Override
|
|
||||||
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
|
|
||||||
|
|
||||||
newIssueLabels.setText(dataString.trim());
|
|
||||||
labelsIdHolder.setText(selectedIds.toString());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCancel() {
|
|
||||||
//Log.d("multiSelect","Dialog cancelled");
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<List<Labels>> call, @NonNull Throwable t) {
|
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -526,23 +352,8 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (v == assigneesList) {
|
|
||||||
if(assigneesFlag) {
|
if (v == viewBinding.newIssueDueDate) {
|
||||||
multiSelectDialog.show(getSupportFragmentManager(), "multiSelectDialog");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Toasty.warning(ctx, getResources().getString(R.string.noAssigneesFound));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (v == newIssueLabels) {
|
|
||||||
if(labelsFlag) {
|
|
||||||
multiSelectDialogLabels.show(getSupportFragmentManager(), "multiSelectDialogLabels");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Toasty.warning(ctx, getResources().getString(R.string.noLabelsFound));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (v == newIssueDueDate) {
|
|
||||||
|
|
||||||
final Calendar c = Calendar.getInstance();
|
final Calendar c = Calendar.getInstance();
|
||||||
int mYear = c.get(Calendar.YEAR);
|
int mYear = c.get(Calendar.YEAR);
|
||||||
@@ -550,31 +361,22 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
|||||||
final int mDay = c.get(Calendar.DAY_OF_MONTH);
|
final int mDay = c.get(Calendar.DAY_OF_MONTH);
|
||||||
|
|
||||||
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
|
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
|
||||||
new DatePickerDialog.OnDateSetListener() {
|
(view, year, monthOfYear, dayOfMonth) -> viewBinding.newIssueDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth)), mYear, mMonth, mDay);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDateSet(DatePicker view, int year,
|
|
||||||
int monthOfYear, int dayOfMonth) {
|
|
||||||
|
|
||||||
newIssueDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth));
|
|
||||||
|
|
||||||
}
|
|
||||||
}, mYear, mMonth, mDay);
|
|
||||||
datePickerDialog.show();
|
datePickerDialog.show();
|
||||||
}
|
}
|
||||||
else if(v == createNewIssueButton) {
|
else if(v == viewBinding.createNewIssueButton) {
|
||||||
|
|
||||||
processNewIssue();
|
processNewIssue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableProcessButton() {
|
private void disableProcessButton() {
|
||||||
|
|
||||||
createNewIssueButton.setEnabled(false);
|
viewBinding.createNewIssueButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableProcessButton() {
|
private void enableProcessButton() {
|
||||||
|
|
||||||
createNewIssueButton.setEnabled(true);
|
viewBinding.createNewIssueButton.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,21 +10,21 @@ import android.widget.Button;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.ColorInt;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import com.pes.androidmaterialcolorpickerdialog.ColorPicker;
|
import com.pes.androidmaterialcolorpickerdialog.ColorPicker;
|
||||||
import com.pes.androidmaterialcolorpickerdialog.ColorPickerCallback;
|
import org.gitnex.tea4j.models.CreateLabel;
|
||||||
|
import org.gitnex.tea4j.models.Labels;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityCreateLabelBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.CreateLabel;
|
|
||||||
import org.mian.gitnex.models.Labels;
|
|
||||||
import org.mian.gitnex.viewmodels.LabelsViewModel;
|
import org.mian.gitnex.viewmodels.LabelsViewModel;
|
||||||
|
import org.mian.gitnex.viewmodels.OrganizationLabelsViewModel;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
@@ -39,45 +39,37 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
private TextView colorPicker;
|
private TextView colorPicker;
|
||||||
private EditText labelName;
|
private EditText labelName;
|
||||||
private Button createLabelButton;
|
private Button createLabelButton;
|
||||||
final Context ctx = this;
|
private TinyDB tinyDB;
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_create_label;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
ActivityCreateLabelBinding activityCreateLabelBinding = ActivityCreateLabelBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityCreateLabelBinding.getRoot());
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
tinyDB = TinyDB.getInstance(appCtx);
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
if(getIntent().getStringExtra("labelAction") != null && Objects.requireNonNull(getIntent().getStringExtra("labelAction")).equals("delete")) {
|
if(getIntent().getStringExtra("labelAction") != null && Objects.requireNonNull(getIntent().getStringExtra("labelAction")).equals("delete")) {
|
||||||
|
|
||||||
deleteLabel(instanceUrl, instanceToken, repoOwner, repoName, Integer.parseInt(Objects.requireNonNull(getIntent().getStringExtra("labelId"))), loginUid);
|
deleteLabel(repoOwner, repoName, Integer.parseInt(Objects.requireNonNull(getIntent().getStringExtra("labelId"))));
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activityCreateLabelBinding.close;
|
||||||
colorPicker = findViewById(R.id.colorPicker);
|
colorPicker = activityCreateLabelBinding.colorPicker;
|
||||||
labelName = findViewById(R.id.labelName);
|
labelName = activityCreateLabelBinding.labelName;
|
||||||
createLabelButton = findViewById(R.id.createLabelButton);
|
createLabelButton = activityCreateLabelBinding.createLabelButton;
|
||||||
|
|
||||||
labelName.requestFocus();
|
labelName.requestFocus();
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
@@ -87,22 +79,14 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
colorPicker.setOnClickListener(new View.OnClickListener() {
|
colorPicker.setOnClickListener(v -> cp.show());
|
||||||
public void onClick(View v) {
|
|
||||||
cp.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
cp.setCallback(new ColorPickerCallback() {
|
cp.setCallback(color -> {
|
||||||
@Override
|
|
||||||
public void onColorChosen(@ColorInt int color) {
|
|
||||||
|
|
||||||
//Log.i("#Hex no alpha", String.format("#%06X", (0xFFFFFF & color)));
|
//Log.i("#Hex no alpha", String.format("#%06X", (0xFFFFFF & color)));
|
||||||
colorPicker.setBackgroundColor(color);
|
colorPicker.setBackgroundColor(color);
|
||||||
tinyDb.putString("labelColor", String.format("#%06X", (0xFFFFFF & color)));
|
tinyDB.putString("labelColor", String.format("#%06X", (0xFFFFFF & color)));
|
||||||
cp.dismiss();
|
cp.dismiss();
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if(getIntent().getStringExtra("labelAction") != null && Objects.requireNonNull(getIntent().getStringExtra("labelAction")).equals("edit")) {
|
if(getIntent().getStringExtra("labelAction") != null && Objects.requireNonNull(getIntent().getStringExtra("labelAction")).equals("edit")) {
|
||||||
@@ -110,9 +94,9 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
labelName.setText(getIntent().getStringExtra("labelTitle"));
|
labelName.setText(getIntent().getStringExtra("labelTitle"));
|
||||||
int labelColor_ = Color.parseColor("#" + getIntent().getStringExtra("labelColor"));
|
int labelColor_ = Color.parseColor("#" + getIntent().getStringExtra("labelColor"));
|
||||||
colorPicker.setBackgroundColor(labelColor_);
|
colorPicker.setBackgroundColor(labelColor_);
|
||||||
tinyDb.putString("labelColorDefault", "#" + getIntent().getStringExtra("labelColor"));
|
tinyDB.putString("labelColorDefault", "#" + getIntent().getStringExtra("labelColor"));
|
||||||
|
|
||||||
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
TextView toolbar_title = activityCreateLabelBinding.toolbarTitle;
|
||||||
toolbar_title.setText(getResources().getString(R.string.pageTitleLabelUpdate));
|
toolbar_title.setText(getResources().getString(R.string.pageTitleLabelUpdate));
|
||||||
createLabelButton.setText(getResources().getString(R.string.newUpdateButtonCopy));
|
createLabelButton.setText(getResources().getString(R.string.newUpdateButtonCopy));
|
||||||
|
|
||||||
@@ -131,119 +115,112 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener createLabelListener = v -> processCreateLabel();
|
private final View.OnClickListener createLabelListener = v -> processCreateLabel();
|
||||||
|
|
||||||
private View.OnClickListener updateLabelListener = v -> processUpdateLabel();
|
private final View.OnClickListener updateLabelListener = v -> processUpdateLabel();
|
||||||
|
|
||||||
private void processUpdateLabel() {
|
private void processUpdateLabel() {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
AppUtil appUtil = new AppUtil();
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
String updateLabelName = labelName.getText().toString();
|
String updateLabelName = labelName.getText().toString();
|
||||||
|
|
||||||
String updateLabelColor;
|
String updateLabelColor;
|
||||||
if(tinyDb.getString("labelColor").isEmpty()) {
|
if(tinyDB.getString("labelColor").isEmpty()) {
|
||||||
updateLabelColor = tinyDb.getString("labelColorDefault");
|
|
||||||
|
updateLabelColor = tinyDB.getString("labelColorDefault");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
updateLabelColor = tinyDb.getString("labelColor");
|
|
||||||
|
updateLabelColor = tinyDB.getString("labelColor");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(updateLabelName.equals("")) {
|
if(updateLabelName.equals("")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.labelEmptyError));
|
Toasty.error(ctx, getString(R.string.labelEmptyError));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!appUtil.checkStrings(updateLabelName)) {
|
if(!AppUtil.checkStrings(updateLabelName)) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.labelNameError));
|
Toasty.error(ctx, getString(R.string.labelNameError));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
patchLabel(instanceUrl, instanceToken, repoOwner, repoName, updateLabelName, updateLabelColor, Integer.parseInt(
|
patchLabel(repoOwner, repoName, updateLabelName, updateLabelColor, Integer.parseInt(
|
||||||
Objects.requireNonNull(getIntent().getStringExtra("labelId"))), loginUid);
|
Objects.requireNonNull(getIntent().getStringExtra("labelId"))));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processCreateLabel() {
|
private void processCreateLabel() {
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
AppUtil appUtil = new AppUtil();
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
String newLabelName = labelName.getText().toString();
|
String newLabelName = labelName.getText().toString();
|
||||||
String newLabelColor;
|
String newLabelColor;
|
||||||
if(tinyDb.getString("labelColor").isEmpty()) {
|
|
||||||
|
if(tinyDB.getString("labelColor").isEmpty()) {
|
||||||
|
|
||||||
newLabelColor = String.format("#%06X", (0xFFFFFF & ContextCompat.getColor(ctx, R.color.releasePre)));
|
newLabelColor = String.format("#%06X", (0xFFFFFF & ContextCompat.getColor(ctx, R.color.releasePre)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
newLabelColor = tinyDb.getString("labelColor");
|
|
||||||
|
newLabelColor = tinyDB.getString("labelColor");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newLabelName.equals("")) {
|
if(newLabelName.equals("")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.labelEmptyError));
|
Toasty.error(ctx, getString(R.string.labelEmptyError));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!appUtil.checkStrings(newLabelName)) {
|
if(!AppUtil.checkStrings(newLabelName)) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.labelNameError));
|
Toasty.error(ctx, getString(R.string.labelNameError));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
createNewLabel(instanceUrl, instanceToken, repoOwner, repoName, newLabelName, newLabelColor, loginUid);
|
createNewLabel(repoOwner, repoName, newLabelName, newLabelColor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewLabel(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, String newLabelName, String newLabelColor, String loginUid) {
|
private void createNewLabel(String repoOwner, String repoName, String newLabelName, String newLabelColor) {
|
||||||
|
|
||||||
CreateLabel createLabelFunc = new CreateLabel(newLabelName, newLabelColor);
|
CreateLabel createLabelFunc = new CreateLabel(newLabelName, newLabelColor);
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
Call<CreateLabel> call;
|
Call<CreateLabel> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
call = RetrofitClient.getApiInterface(ctx).createOrganizationLabel(Authorization.get(ctx), getIntent().getStringExtra("orgName"), createLabelFunc);
|
||||||
.createLabel(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, createLabelFunc);
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
call = RetrofitClient.getApiInterface(ctx).createLabel(Authorization.get(ctx), repoOwner, repoName, createLabelFunc);
|
||||||
|
}
|
||||||
|
|
||||||
call.enqueue(new Callback<CreateLabel>() {
|
call.enqueue(new Callback<CreateLabel>() {
|
||||||
|
|
||||||
@@ -253,10 +230,9 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
if(response.code() == 201) {
|
if(response.code() == 201) {
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.labelCreated));
|
Toasty.success(ctx, getString(R.string.labelCreated));
|
||||||
tinyDb.putString("labelColor", "");
|
tinyDB.putString("labelColor", "");
|
||||||
tinyDb.putBoolean("labelsRefresh", true);
|
tinyDB.putBoolean("labelsRefresh", true);
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
@@ -265,22 +241,19 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
tinyDb.putString("labelColor", "");
|
tinyDB.putString("labelColor", "");
|
||||||
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<CreateLabel> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<CreateLabel> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
tinyDb.putString("labelColor", "");
|
tinyDB.putString("labelColor", "");
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
}
|
}
|
||||||
@@ -288,17 +261,20 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void patchLabel(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, String updateLabelName, String updateLabelColor, int labelId, String loginUid) {
|
private void patchLabel(String repoOwner, String repoName, String updateLabelName, String updateLabelColor, int labelId) {
|
||||||
|
|
||||||
CreateLabel createLabelFunc = new CreateLabel(updateLabelName, updateLabelColor);
|
CreateLabel createLabelFunc = new CreateLabel(updateLabelName, updateLabelColor);
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
Call<CreateLabel> call;
|
Call<CreateLabel> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
call = RetrofitClient.getApiInterface(ctx).patchOrganizationLabel(Authorization.get(ctx), getIntent().getStringExtra("orgName"), labelId, createLabelFunc);
|
||||||
.patchLabel(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, labelId, createLabelFunc);
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
call = RetrofitClient.getApiInterface(appCtx).patchLabel(Authorization.get(ctx), repoOwner, repoName, labelId, createLabelFunc);
|
||||||
|
}
|
||||||
|
|
||||||
call.enqueue(new Callback<CreateLabel>() {
|
call.enqueue(new Callback<CreateLabel>() {
|
||||||
|
|
||||||
@@ -306,18 +282,19 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
public void onResponse(@NonNull Call<CreateLabel> call, @NonNull retrofit2.Response<CreateLabel> response) {
|
public void onResponse(@NonNull Call<CreateLabel> call, @NonNull retrofit2.Response<CreateLabel> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
if(response.code() == 200) {
|
if(response.code() == 200) {
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.labelUpdated));
|
Toasty.success(ctx, getString(R.string.labelUpdated));
|
||||||
tinyDb.putString("labelColor", "");
|
tinyDB.putString("labelColor", "");
|
||||||
tinyDb.putBoolean("labelsRefresh", true);
|
tinyDB.putBoolean("labelsRefresh", true);
|
||||||
tinyDb.putString("labelColorDefault", "");
|
tinyDB.putString("labelColorDefault", "");
|
||||||
getIntent().removeExtra("labelAction");
|
getIntent().removeExtra("labelAction");
|
||||||
getIntent().removeExtra("labelId");
|
getIntent().removeExtra("labelId");
|
||||||
getIntent().removeExtra("labelTitle");
|
getIntent().removeExtra("labelTitle");
|
||||||
getIntent().removeExtra("labelColor");
|
getIntent().removeExtra("labelColor");
|
||||||
|
getIntent().removeExtra("type");
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
@@ -327,24 +304,21 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
tinyDb.putString("labelColor", "");
|
tinyDB.putString("labelColor", "");
|
||||||
tinyDb.putString("labelColorDefault", "");
|
tinyDB.putString("labelColorDefault", "");
|
||||||
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<CreateLabel> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<CreateLabel> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
tinyDb.putString("labelColor", "");
|
tinyDB.putString("labelColor", "");
|
||||||
tinyDb.putString("labelColorDefault", "");
|
tinyDB.putString("labelColorDefault", "");
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
}
|
}
|
||||||
@@ -353,26 +327,30 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
onClickListener = new View.OnClickListener() {
|
|
||||||
@Override
|
onClickListener = view -> {
|
||||||
public void onClick(View view) {
|
|
||||||
getIntent().removeExtra("labelAction");
|
getIntent().removeExtra("labelAction");
|
||||||
getIntent().removeExtra("labelId");
|
getIntent().removeExtra("labelId");
|
||||||
getIntent().removeExtra("labelTitle");
|
getIntent().removeExtra("labelTitle");
|
||||||
getIntent().removeExtra("labelColor");
|
getIntent().removeExtra("labelColor");
|
||||||
finish();
|
getIntent().removeExtra("type");
|
||||||
}
|
finish();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteLabel(final String instanceUrl, final String instanceToken, final String repoOwner, final String repoName, int labelId, String loginUid) {
|
private void deleteLabel(final String repoOwner, final String repoName, int labelId) {
|
||||||
|
|
||||||
Call<Labels> call;
|
Call<Labels> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
call = RetrofitClient.getApiInterface(appCtx).deleteOrganizationLabel(Authorization.get(ctx), getIntent().getStringExtra("orgName"), labelId);
|
||||||
.deleteLabel(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, labelId);
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
call = RetrofitClient.getApiInterface(appCtx).deleteLabel(Authorization.get(ctx), repoOwner, repoName, labelId);
|
||||||
|
}
|
||||||
|
|
||||||
call.enqueue(new Callback<Labels>() {
|
call.enqueue(new Callback<Labels>() {
|
||||||
|
|
||||||
@@ -380,13 +358,21 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
public void onResponse(@NonNull Call<Labels> call, @NonNull retrofit2.Response<Labels> response) {
|
public void onResponse(@NonNull Call<Labels> call, @NonNull retrofit2.Response<Labels> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
if(response.code() == 204) {
|
if(response.code() == 204) {
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.labelDeleteText));
|
Toasty.success(ctx, getString(R.string.labelDeleteText));
|
||||||
LabelsViewModel.loadLabelsList(instanceUrl, instanceToken, repoOwner, repoName, ctx);
|
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
|
||||||
|
|
||||||
|
OrganizationLabelsViewModel.loadOrgLabelsList(Authorization.get(ctx), getIntent().getStringExtra("orgName"), ctx, null, null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
LabelsViewModel.loadLabelsList(Authorization.get(ctx), repoOwner, repoName, ctx);
|
||||||
|
}
|
||||||
getIntent().removeExtra("labelAction");
|
getIntent().removeExtra("labelAction");
|
||||||
getIntent().removeExtra("labelId");
|
getIntent().removeExtra("labelId");
|
||||||
|
getIntent().removeExtra("type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
@@ -395,14 +381,11 @@ public class CreateLabelActivity extends BaseActivity {
|
|||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.labelDeleteErrorText));
|
Toasty.error(ctx, getString(R.string.labelDeleteErrorText));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,25 +1,27 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.DatePickerDialog;
|
import android.app.DatePickerDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.DatePicker;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import org.gitnex.tea4j.models.Milestones;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityCreateMilestoneBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.models.Milestones;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
@@ -35,34 +37,41 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
|||||||
private EditText milestoneTitle;
|
private EditText milestoneTitle;
|
||||||
private EditText milestoneDescription;
|
private EditText milestoneDescription;
|
||||||
private Button createNewMilestoneButton;
|
private Button createNewMilestoneButton;
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_new_milestone;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
ActivityCreateMilestoneBinding activityCreateMilestoneBinding = ActivityCreateMilestoneBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityCreateMilestoneBinding.getRoot());
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
milestoneDueDate = findViewById(R.id.milestoneDueDate);
|
milestoneDueDate = activityCreateMilestoneBinding.milestoneDueDate;
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activityCreateMilestoneBinding.close;
|
||||||
createNewMilestoneButton = findViewById(R.id.createNewMilestoneButton);
|
createNewMilestoneButton = activityCreateMilestoneBinding.createNewMilestoneButton;
|
||||||
milestoneTitle = findViewById(R.id.milestoneTitle);
|
milestoneTitle = activityCreateMilestoneBinding.milestoneTitle;
|
||||||
milestoneDescription = findViewById(R.id.milestoneDescription);
|
milestoneDescription = activityCreateMilestoneBinding.milestoneDescription;
|
||||||
|
|
||||||
milestoneTitle.requestFocus();
|
milestoneTitle.requestFocus();
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
imm.showSoftInput(milestoneTitle, InputMethodManager.SHOW_IMPLICIT);
|
imm.showSoftInput(milestoneTitle, InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
|
||||||
|
milestoneDescription.setOnTouchListener((touchView, motionEvent) -> {
|
||||||
|
|
||||||
|
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||||
|
|
||||||
|
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||||
|
|
||||||
|
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
milestoneDueDate.setOnClickListener(this);
|
milestoneDueDate.setOnClickListener(this);
|
||||||
@@ -78,21 +87,17 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener createMilestoneListener = v -> processNewMilestone();
|
private final View.OnClickListener createMilestoneListener = v -> processNewMilestone();
|
||||||
|
|
||||||
private void processNewMilestone() {
|
private void processNewMilestone() {
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
AppUtil appUtil = new AppUtil();
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
//String appLocale = tinyDb.getString("locale");
|
|
||||||
|
|
||||||
String newMilestoneTitle = milestoneTitle.getText().toString();
|
String newMilestoneTitle = milestoneTitle.getText().toString();
|
||||||
String newMilestoneDescription = milestoneDescription.getText().toString();
|
String newMilestoneDescription = milestoneDescription.getText().toString();
|
||||||
@@ -102,26 +107,25 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
|||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newMilestoneTitle.equals("")) {
|
if(newMilestoneTitle.equals("")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.milestoneNameErrorEmpty));
|
Toasty.error(ctx, getString(R.string.milestoneNameErrorEmpty));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!newMilestoneDescription.equals("")) {
|
if(!newMilestoneDescription.equals("")) {
|
||||||
if (appUtil.charactersLength(newMilestoneDescription) > 255) {
|
|
||||||
|
if (newMilestoneDescription.length() > 255) {
|
||||||
|
|
||||||
Toasty.warning(ctx, getString(R.string.milestoneDescError));
|
Toasty.warning(ctx, getString(R.string.milestoneDescError));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String finalMilestoneDueDate = null;
|
String finalMilestoneDueDate = null;
|
||||||
|
|
||||||
if(!newMilestoneDueDate.isEmpty()) {
|
if(!newMilestoneDueDate.isEmpty()) {
|
||||||
|
|
||||||
finalMilestoneDueDate = (AppUtil.customDateCombine(AppUtil.customDateFormat(newMilestoneDueDate)));
|
finalMilestoneDueDate = (AppUtil.customDateCombine(AppUtil.customDateFormat(newMilestoneDueDate)));
|
||||||
@@ -134,19 +138,17 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
|||||||
}
|
}
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
createNewMilestone(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, newMilestoneTitle, newMilestoneDescription, finalMilestoneDueDate);
|
createNewMilestone(Authorization.get(ctx), repoOwner, repoName, newMilestoneTitle, newMilestoneDescription, finalMilestoneDueDate);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewMilestone(final String instanceUrl, final String token, String repoOwner, String repoName, String newMilestoneTitle, String newMilestoneDescription, String newMilestoneDueDate) {
|
private void createNewMilestone(final String token, String repoOwner, String repoName, String newMilestoneTitle, String newMilestoneDescription, String newMilestoneDueDate) {
|
||||||
|
|
||||||
Milestones createMilestone = new Milestones(newMilestoneDescription, newMilestoneTitle, newMilestoneDueDate);
|
Milestones createMilestone = new Milestones(newMilestoneDescription, newMilestoneTitle, newMilestoneDueDate);
|
||||||
|
|
||||||
Call<Milestones> call;
|
Call<Milestones> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(appCtx)
|
||||||
.getApiInterface()
|
|
||||||
.createMilestone(token, repoOwner, repoName, createMilestone);
|
.createMilestone(token, repoOwner, repoName, createMilestone);
|
||||||
|
|
||||||
call.enqueue(new Callback<Milestones>() {
|
call.enqueue(new Callback<Milestones>() {
|
||||||
@@ -155,14 +157,14 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
|||||||
public void onResponse(@NonNull Call<Milestones> call, @NonNull retrofit2.Response<Milestones> response) {
|
public void onResponse(@NonNull Call<Milestones> call, @NonNull retrofit2.Response<Milestones> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
if(response.code() == 201) {
|
if(response.code() == 201) {
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
tinyDb.putBoolean("milestoneCreated", true);
|
tinyDb.putBoolean("milestoneCreated", true);
|
||||||
Toasty.success(ctx, getString(R.string.milestoneCreated));
|
Toasty.success(ctx, getString(R.string.milestoneCreated));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
@@ -172,19 +174,17 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
|||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.error(ctx, getString(R.string.milestoneCreatedError));
|
Toasty.error(ctx, getString(R.string.milestoneCreatedError));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<Milestones> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<Milestones> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
}
|
}
|
||||||
@@ -203,16 +203,7 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
|||||||
final int mDay = c.get(Calendar.DAY_OF_MONTH);
|
final int mDay = c.get(Calendar.DAY_OF_MONTH);
|
||||||
|
|
||||||
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
|
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
|
||||||
new DatePickerDialog.OnDateSetListener() {
|
(view, year, monthOfYear, dayOfMonth) -> milestoneDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth)), mYear, mMonth, mDay);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDateSet(DatePicker view, int year,
|
|
||||||
int monthOfYear, int dayOfMonth) {
|
|
||||||
|
|
||||||
milestoneDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth));
|
|
||||||
|
|
||||||
}
|
|
||||||
}, mYear, mMonth, mDay);
|
|
||||||
datePickerDialog.show();
|
datePickerDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ import android.widget.Button;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import org.gitnex.tea4j.models.UserInfo;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityCreateNewUserBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.UserInfo;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
|
|
||||||
@@ -33,30 +33,25 @@ public class CreateNewUserActivity extends BaseActivity {
|
|||||||
private EditText userEmail;
|
private EditText userEmail;
|
||||||
private EditText userPassword;
|
private EditText userPassword;
|
||||||
private Button createUserButton;
|
private Button createUserButton;
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_create_new_user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
ActivityCreateNewUserBinding activityCreateNewUserBinding = ActivityCreateNewUserBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityCreateNewUserBinding.getRoot());
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activityCreateNewUserBinding.close;
|
||||||
createUserButton = findViewById(R.id.createUserButton);
|
createUserButton = activityCreateNewUserBinding.createUserButton;
|
||||||
fullName = findViewById(R.id.fullName);
|
fullName = activityCreateNewUserBinding.fullName;
|
||||||
userUserName = findViewById(R.id.userUserName);
|
userUserName = activityCreateNewUserBinding.userUserName;
|
||||||
userEmail = findViewById(R.id.userEmail);
|
userEmail = activityCreateNewUserBinding.userEmail;
|
||||||
userPassword = findViewById(R.id.userPassword);
|
userPassword = activityCreateNewUserBinding.userPassword;
|
||||||
|
|
||||||
fullName.requestFocus();
|
fullName.requestFocus();
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
@@ -73,17 +68,11 @@ public class CreateNewUserActivity extends BaseActivity {
|
|||||||
|
|
||||||
createUserButton.setOnClickListener(createNewUserListener);
|
createUserButton.setOnClickListener(createNewUserListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processCreateNewUser() {
|
private void processCreateNewUser() {
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
AppUtil appUtil = new AppUtil();
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
String newFullName = fullName.getText().toString().trim();
|
String newFullName = fullName.getText().toString().trim();
|
||||||
String newUserName = userUserName.getText().toString().trim();
|
String newUserName = userUserName.getText().toString().trim();
|
||||||
@@ -94,51 +83,44 @@ public class CreateNewUserActivity extends BaseActivity {
|
|||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newFullName.equals("") || newUserName.equals("") | newUserEmail.equals("") || newUserPassword.equals("")) {
|
if(newFullName.equals("") || newUserName.equals("") | newUserEmail.equals("") || newUserPassword.equals("")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.emptyFields));
|
Toasty.error(ctx, getString(R.string.emptyFields));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!appUtil.checkStrings(newFullName)) {
|
if(!AppUtil.checkStrings(newFullName)) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.userInvalidFullName));
|
Toasty.error(ctx, getString(R.string.userInvalidFullName));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!appUtil.checkStringsWithAlphaNumeric(newUserName)) {
|
if(!AppUtil.checkStringsWithAlphaNumeric(newUserName)) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.userInvalidUserName));
|
Toasty.error(ctx, getString(R.string.userInvalidUserName));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Patterns.EMAIL_ADDRESS.matcher(newUserEmail).matches()) {
|
if(!Patterns.EMAIL_ADDRESS.matcher(newUserEmail).matches()) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.userInvalidEmail));
|
Toasty.error(ctx, getString(R.string.userInvalidEmail));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
createNewUser(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), newFullName, newUserName, newUserEmail, newUserPassword);
|
createNewUser(Authorization.get(ctx), newFullName, newUserName, newUserEmail, newUserPassword);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewUser(final String instanceUrl, final String instanceToken, String newFullName, String newUserName, String newUserEmail, String newUserPassword) {
|
private void createNewUser(final String instanceToken, String newFullName, String newUserName, String newUserEmail, String newUserPassword) {
|
||||||
|
|
||||||
UserInfo createUser = new UserInfo(newUserEmail, newFullName, newUserName, newUserPassword, newUserName, 0, true);
|
UserInfo createUser = new UserInfo(newUserEmail, newFullName, newUserName, newUserPassword, newUserName, 0, true);
|
||||||
|
|
||||||
Call<UserInfo> call;
|
Call<UserInfo> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(appCtx)
|
||||||
.getApiInterface()
|
|
||||||
.createNewUser(instanceToken, createUser);
|
.createNewUser(instanceToken, createUser);
|
||||||
|
|
||||||
call.enqueue(new Callback<UserInfo>() {
|
call.enqueue(new Callback<UserInfo>() {
|
||||||
@@ -151,7 +133,6 @@ public class CreateNewUserActivity extends BaseActivity {
|
|||||||
Toasty.success(ctx, getString(R.string.userCreatedText));
|
Toasty.success(ctx, getString(R.string.userCreatedText));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
@@ -160,33 +141,27 @@ public class CreateNewUserActivity extends BaseActivity {
|
|||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 403) {
|
else if(response.code() == 403) {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 404) {
|
else if(response.code() == 404) {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 422) {
|
else if(response.code() == 422) {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.userExistsError));
|
Toasty.warning(ctx, ctx.getString(R.string.userExistsError));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.error(ctx, getString(R.string.genericError));
|
Toasty.error(ctx, getString(R.string.genericError));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -199,7 +174,7 @@ public class CreateNewUserActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener createNewUserListener = v -> processCreateNewUser();
|
private final View.OnClickListener createNewUserListener = v -> processCreateNewUser();
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,25 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import org.gitnex.tea4j.models.UserOrganizations;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityCreateOrganizationBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.UserOrganizations;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
|
|
||||||
@@ -32,36 +35,43 @@ public class CreateOrganizationActivity extends BaseActivity {
|
|||||||
|
|
||||||
private EditText orgName;
|
private EditText orgName;
|
||||||
private EditText orgDesc;
|
private EditText orgDesc;
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_new_organization;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
ActivityCreateOrganizationBinding activityCreateOrganizationBinding = ActivityCreateOrganizationBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityCreateOrganizationBinding.getRoot());
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
closeActivity = findViewById(R.id.close);
|
closeActivity = activityCreateOrganizationBinding.close;
|
||||||
orgName = findViewById(R.id.newOrganizationName);
|
orgName = activityCreateOrganizationBinding.newOrganizationName;
|
||||||
orgDesc = findViewById(R.id.newOrganizationDescription);
|
orgDesc = activityCreateOrganizationBinding.newOrganizationDescription;
|
||||||
|
|
||||||
orgName.requestFocus();
|
orgName.requestFocus();
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
imm.showSoftInput(orgName, InputMethodManager.SHOW_IMPLICIT);
|
imm.showSoftInput(orgName, InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
|
||||||
|
orgDesc.setOnTouchListener((touchView, motionEvent) -> {
|
||||||
|
|
||||||
|
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||||
|
|
||||||
|
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||||
|
|
||||||
|
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
createOrganizationButton = findViewById(R.id.createNewOrganizationButton);
|
createOrganizationButton = activityCreateOrganizationBinding.createNewOrganizationButton;
|
||||||
|
|
||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
|
|
||||||
@@ -75,28 +85,15 @@ public class CreateOrganizationActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
onClickListener = new View.OnClickListener() {
|
|
||||||
@Override
|
onClickListener = view -> finish();
|
||||||
public void onClick(View view) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener createOrgListener = new View.OnClickListener() {
|
private final View.OnClickListener createOrgListener = v -> processNewOrganization();
|
||||||
public void onClick(View v) {
|
|
||||||
processNewOrganization();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void processNewOrganization() {
|
private void processNewOrganization() {
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
AppUtil appUtil = new AppUtil();
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
String newOrgName = orgName.getText().toString();
|
String newOrgName = orgName.getText().toString();
|
||||||
String newOrgDesc = orgDesc.getText().toString();
|
String newOrgDesc = orgDesc.getText().toString();
|
||||||
@@ -105,44 +102,39 @@ public class CreateOrganizationActivity extends BaseActivity {
|
|||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!newOrgDesc.equals("")) {
|
if(!newOrgDesc.equals("")) {
|
||||||
if (appUtil.charactersLength(newOrgDesc) > 255) {
|
|
||||||
|
if (newOrgDesc.length() > 255) {
|
||||||
|
|
||||||
Toasty.warning(ctx, getString(R.string.orgDescError));
|
Toasty.warning(ctx, getString(R.string.orgDescError));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newOrgName.equals("")) {
|
if(newOrgName.equals("")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.orgNameErrorEmpty));
|
Toasty.error(ctx, getString(R.string.orgNameErrorEmpty));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(!appUtil.checkStrings(newOrgName)) {
|
else if(!AppUtil.checkStrings(newOrgName)) {
|
||||||
|
|
||||||
Toasty.warning(ctx, getString(R.string.orgNameErrorInvalid));
|
Toasty.warning(ctx, getString(R.string.orgNameErrorInvalid));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
createNewOrganization(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), newOrgName, newOrgDesc);
|
createNewOrganization(Authorization.get(ctx), newOrgName, newOrgDesc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewOrganization(final String instanceUrl, final String token, String orgName, String orgDesc) {
|
private void createNewOrganization(final String token, String orgName, String orgDesc) {
|
||||||
|
|
||||||
UserOrganizations createOrganization = new UserOrganizations(orgName, null, orgDesc, null, null);
|
UserOrganizations createOrganization = new UserOrganizations(orgName, null, orgDesc, null, null);
|
||||||
|
|
||||||
Call<UserOrganizations> call = RetrofitClient
|
Call<UserOrganizations> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(appCtx)
|
||||||
.getApiInterface()
|
|
||||||
.createNewOrganization(token, createOrganization);
|
.createNewOrganization(token, createOrganization);
|
||||||
|
|
||||||
call.enqueue(new Callback<UserOrganizations>() {
|
call.enqueue(new Callback<UserOrganizations>() {
|
||||||
@@ -152,12 +144,11 @@ public class CreateOrganizationActivity extends BaseActivity {
|
|||||||
|
|
||||||
if(response.code() == 201) {
|
if(response.code() == 201) {
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
tinyDb.putBoolean("orgCreated", true);
|
tinyDb.putBoolean("orgCreated", true);
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.success(ctx, getString(R.string.orgCreated));
|
Toasty.success(ctx, getString(R.string.orgCreated));
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
@@ -166,37 +157,35 @@ public class CreateOrganizationActivity extends BaseActivity {
|
|||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 409) {
|
else if(response.code() == 409) {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.warning(ctx, getString(R.string.orgExistsError));
|
Toasty.warning(ctx, getString(R.string.orgExistsError));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 422) {
|
else if(response.code() == 422) {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.warning(ctx, getString(R.string.orgExistsError));
|
Toasty.warning(ctx, getString(R.string.orgExistsError));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
if(response.code() == 404) {
|
if(response.code() == 404) {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.warning(ctx, getString(R.string.apiNotFound));
|
Toasty.warning(ctx, getString(R.string.apiNotFound));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.error(ctx, getString(R.string.orgCreatedError));
|
Toasty.error(ctx, getString(R.string.orgCreatedError));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<UserOrganizations> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<UserOrganizations> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,373 @@
|
|||||||
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.DatePickerDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import org.gitnex.tea4j.models.Branches;
|
||||||
|
import org.gitnex.tea4j.models.CreatePullRequest;
|
||||||
|
import org.gitnex.tea4j.models.Labels;
|
||||||
|
import org.gitnex.tea4j.models.Milestones;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.actions.LabelsActions;
|
||||||
|
import org.mian.gitnex.adapters.LabelsListAdapter;
|
||||||
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityCreatePrBinding;
|
||||||
|
import org.mian.gitnex.databinding.CustomLabelsSelectionDialogBinding;
|
||||||
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
|
import org.mian.gitnex.helpers.Constants;
|
||||||
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import org.mian.gitnex.helpers.Version;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CreatePullRequestActivity extends BaseActivity implements LabelsListAdapter.LabelsListAdapterListener {
|
||||||
|
|
||||||
|
private View.OnClickListener onClickListener;
|
||||||
|
private ActivityCreatePrBinding viewBinding;
|
||||||
|
private CustomLabelsSelectionDialogBinding labelsBinding;
|
||||||
|
private int resultLimit = Constants.resultLimitOldGiteaInstances;
|
||||||
|
private Dialog dialogLabels;
|
||||||
|
private String labelsSetter;
|
||||||
|
private List<Integer> labelsIds = new ArrayList<>();
|
||||||
|
private List<String> assignees = new ArrayList<>();
|
||||||
|
private int milestoneId;
|
||||||
|
|
||||||
|
private String loginUid;
|
||||||
|
private String instanceToken;
|
||||||
|
private String repoOwner;
|
||||||
|
private String repoName;
|
||||||
|
|
||||||
|
private LabelsListAdapter labelsAdapter;
|
||||||
|
|
||||||
|
List<Milestones> milestonesList = new ArrayList<>();
|
||||||
|
List<Branches> branchesList = new ArrayList<>();
|
||||||
|
List<Labels> labelsList = new ArrayList<>();
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
viewBinding = ActivityCreatePrBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(viewBinding.getRoot());
|
||||||
|
|
||||||
|
loginUid = tinyDB.getString("loginUid");
|
||||||
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
|
String[] parts = repoFullName.split("/");
|
||||||
|
repoOwner = parts[0];
|
||||||
|
repoName = parts[1];
|
||||||
|
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||||
|
|
||||||
|
// require gitea 1.12 or higher
|
||||||
|
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||||
|
|
||||||
|
resultLimit = Constants.resultLimitNewGiteaInstances;
|
||||||
|
}
|
||||||
|
|
||||||
|
viewBinding.prBody.setOnTouchListener((touchView, motionEvent) -> {
|
||||||
|
|
||||||
|
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||||
|
|
||||||
|
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||||
|
|
||||||
|
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
labelsAdapter = new LabelsListAdapter(labelsList, CreatePullRequestActivity.this, labelsIds);
|
||||||
|
|
||||||
|
ImageView closeActivity = findViewById(R.id.close);
|
||||||
|
|
||||||
|
initCloseListener();
|
||||||
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
|
viewBinding.prDueDate.setOnClickListener(dueDate ->
|
||||||
|
setDueDate()
|
||||||
|
);
|
||||||
|
|
||||||
|
disableProcessButton();
|
||||||
|
|
||||||
|
getMilestones(repoOwner, repoName, resultLimit);
|
||||||
|
getBranches(repoOwner, repoName);
|
||||||
|
|
||||||
|
viewBinding.prLabels.setOnClickListener(prLabels -> showLabels());
|
||||||
|
|
||||||
|
viewBinding.createPr.setOnClickListener(createPr -> processPullRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processPullRequest() {
|
||||||
|
|
||||||
|
String prTitle = String.valueOf(viewBinding.prTitle.getText());
|
||||||
|
String prDescription = String.valueOf(viewBinding.prBody.getText());
|
||||||
|
String mergeInto = viewBinding.mergeIntoBranchSpinner.getText().toString();
|
||||||
|
String pullFrom = viewBinding.pullFromBranchSpinner.getText().toString();
|
||||||
|
String dueDate = String.valueOf(viewBinding.prDueDate.getText());
|
||||||
|
|
||||||
|
assignees.add("");
|
||||||
|
|
||||||
|
if (labelsIds.size() == 0) {
|
||||||
|
|
||||||
|
labelsIds.add(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dueDate.matches("")) {
|
||||||
|
|
||||||
|
dueDate = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
dueDate = AppUtil.customDateCombine(AppUtil.customDateFormat(dueDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(prTitle.matches("")) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.titleError));
|
||||||
|
}
|
||||||
|
else if(mergeInto.matches("")) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.mergeIntoError));
|
||||||
|
}
|
||||||
|
else if(pullFrom.matches("")) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.pullFromError));
|
||||||
|
}
|
||||||
|
else if(pullFrom.equals(mergeInto)) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.sameBranchesError));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
createPullRequest(prTitle, prDescription, mergeInto, pullFrom, milestoneId, dueDate, assignees);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createPullRequest(String prTitle, String prDescription, String mergeInto, String pullFrom, int milestoneId, String dueDate, List<String> assignees) {
|
||||||
|
|
||||||
|
CreatePullRequest createPullRequest = new CreatePullRequest(prTitle, prDescription, loginUid, mergeInto, pullFrom, milestoneId, dueDate, assignees, labelsIds);
|
||||||
|
|
||||||
|
Call<Void> transferCall = RetrofitClient
|
||||||
|
.getApiInterface(appCtx)
|
||||||
|
.createPullRequest(instanceToken, repoOwner, repoName, createPullRequest);
|
||||||
|
|
||||||
|
transferCall.enqueue(new Callback<Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<Void> call, @NonNull retrofit2.Response<Void> response) {
|
||||||
|
|
||||||
|
disableProcessButton();
|
||||||
|
|
||||||
|
if (response.code() == 201) {
|
||||||
|
|
||||||
|
Toasty.success(ctx, getString(R.string.prCreateSuccess));
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else if (response.code() == 409 && response.message().equals("Conflict")) {
|
||||||
|
|
||||||
|
enableProcessButton();
|
||||||
|
Toasty.error(ctx, getString(R.string.prAlreadyExists));
|
||||||
|
}
|
||||||
|
else if (response.code() == 404) {
|
||||||
|
|
||||||
|
enableProcessButton();
|
||||||
|
Toasty.error(ctx, getString(R.string.apiNotFound));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
enableProcessButton();
|
||||||
|
Toasty.error(ctx, getString(R.string.genericError));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
enableProcessButton();
|
||||||
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void labelsInterface(List<String> data) {
|
||||||
|
|
||||||
|
labelsSetter = String.valueOf(data);
|
||||||
|
viewBinding.prLabels.setText(labelsSetter.replace("]", "").replace("[", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void labelsIdsInterface(List<Integer> data) {
|
||||||
|
|
||||||
|
labelsIds = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showLabels() {
|
||||||
|
|
||||||
|
dialogLabels = new Dialog(ctx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
||||||
|
|
||||||
|
if (dialogLabels.getWindow() != null) {
|
||||||
|
|
||||||
|
dialogLabels.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
labelsBinding = CustomLabelsSelectionDialogBinding.inflate(LayoutInflater.from(ctx));
|
||||||
|
|
||||||
|
View view = labelsBinding.getRoot();
|
||||||
|
dialogLabels.setContentView(view);
|
||||||
|
|
||||||
|
labelsBinding.cancel.setOnClickListener(editProperties -> dialogLabels.dismiss());
|
||||||
|
|
||||||
|
dialogLabels.show();
|
||||||
|
LabelsActions.getRepositoryLabels(ctx, repoOwner, repoName, labelsList, dialogLabels, labelsAdapter, labelsBinding);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getBranches(String repoOwner, String repoName) {
|
||||||
|
|
||||||
|
Call<List<Branches>> call = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.getBranches(Authorization.get(ctx), repoOwner, repoName);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<List<Branches>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<List<Branches>> call, @NonNull retrofit2.Response<List<Branches>> response) {
|
||||||
|
|
||||||
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
|
if(response.code() == 200) {
|
||||||
|
|
||||||
|
List<Branches> branchesList_ = response.body();
|
||||||
|
assert branchesList_ != null;
|
||||||
|
|
||||||
|
if(branchesList_.size() > 0) {
|
||||||
|
|
||||||
|
for (int i = 0; i < branchesList_.size(); i++) {
|
||||||
|
|
||||||
|
Branches data = new Branches(branchesList_.get(i).getName());
|
||||||
|
branchesList.add(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayAdapter<Branches> adapter = new ArrayAdapter<>(CreatePullRequestActivity.this,
|
||||||
|
R.layout.list_spinner_items, branchesList);
|
||||||
|
|
||||||
|
viewBinding.mergeIntoBranchSpinner.setAdapter(adapter);
|
||||||
|
viewBinding.pullFromBranchSpinner.setAdapter(adapter);
|
||||||
|
enableProcessButton();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<List<Branches>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getMilestones(String repoOwner, String repoName, int resultLimit) {
|
||||||
|
|
||||||
|
String msState = "open";
|
||||||
|
Call<List<Milestones>> call = RetrofitClient
|
||||||
|
.getApiInterface(appCtx)
|
||||||
|
.getMilestones(Authorization.get(ctx), repoOwner, repoName, 1, resultLimit, msState);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<List<Milestones>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<List<Milestones>> call, @NonNull retrofit2.Response<List<Milestones>> response) {
|
||||||
|
|
||||||
|
if(response.code() == 200) {
|
||||||
|
|
||||||
|
List<Milestones> milestonesList_ = response.body();
|
||||||
|
|
||||||
|
milestonesList.add(new Milestones(0,getString(R.string.issueCreatedNoMilestone)));
|
||||||
|
assert milestonesList_ != null;
|
||||||
|
|
||||||
|
if(milestonesList_.size() > 0) {
|
||||||
|
|
||||||
|
for (int i = 0; i < milestonesList_.size(); i++) {
|
||||||
|
|
||||||
|
//Don't translate "open" is a enum
|
||||||
|
if(milestonesList_.get(i).getState().equals("open")) {
|
||||||
|
Milestones data = new Milestones(
|
||||||
|
milestonesList_.get(i).getId(),
|
||||||
|
milestonesList_.get(i).getTitle()
|
||||||
|
);
|
||||||
|
milestonesList.add(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayAdapter<Milestones> adapter = new ArrayAdapter<>(CreatePullRequestActivity.this,
|
||||||
|
R.layout.list_spinner_items, milestonesList);
|
||||||
|
|
||||||
|
viewBinding.milestonesSpinner.setAdapter(adapter);
|
||||||
|
enableProcessButton();
|
||||||
|
|
||||||
|
viewBinding.milestonesSpinner.setOnItemClickListener ((parent, view, position, id) ->
|
||||||
|
|
||||||
|
milestoneId = milestonesList.get(position).getId()
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<List<Milestones>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDueDate() {
|
||||||
|
|
||||||
|
final Calendar c = Calendar.getInstance();
|
||||||
|
int mYear = c.get(Calendar.YEAR);
|
||||||
|
final int mMonth = c.get(Calendar.MONTH);
|
||||||
|
final int mDay = c.get(Calendar.DAY_OF_MONTH);
|
||||||
|
|
||||||
|
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
|
||||||
|
(view, year, monthOfYear, dayOfMonth) -> viewBinding.prDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth)), mYear, mMonth, mDay);
|
||||||
|
datePickerDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initCloseListener() {
|
||||||
|
|
||||||
|
onClickListener = view -> finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disableProcessButton() {
|
||||||
|
|
||||||
|
viewBinding.createPr.setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableProcessButton() {
|
||||||
|
|
||||||
|
viewBinding.createPr.setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +1,28 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.Spinner;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import org.gitnex.tea4j.models.Branches;
|
||||||
|
import org.gitnex.tea4j.models.Releases;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityCreateReleaseBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.Branches;
|
|
||||||
import org.mian.gitnex.models.Releases;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@@ -37,71 +37,66 @@ public class CreateReleaseActivity extends BaseActivity {
|
|||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
public ImageView closeActivity;
|
public ImageView closeActivity;
|
||||||
private EditText releaseTagName;
|
private EditText releaseTagName;
|
||||||
private Spinner releaseBranch;
|
private AutoCompleteTextView releaseBranch;
|
||||||
private EditText releaseTitle;
|
private EditText releaseTitle;
|
||||||
private EditText releaseContent;
|
private EditText releaseContent;
|
||||||
private CheckBox releaseType;
|
private CheckBox releaseType;
|
||||||
private CheckBox releaseDraft;
|
private CheckBox releaseDraft;
|
||||||
private Button createNewRelease;
|
private Button createNewRelease;
|
||||||
final Context ctx = this;
|
private String selectedBranch;
|
||||||
private Context appCtx;
|
|
||||||
|
private String repoOwner;
|
||||||
|
private String repoName;
|
||||||
|
|
||||||
List<Branches> branchesList = new ArrayList<>();
|
List<Branches> branchesList = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_create_release;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
ActivityCreateReleaseBinding activityCreateReleaseBinding = ActivityCreateReleaseBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityCreateReleaseBinding.getRoot());
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
repoName = parts[1];
|
||||||
|
|
||||||
closeActivity = findViewById(R.id.close);
|
closeActivity = activityCreateReleaseBinding.close;
|
||||||
releaseTagName = findViewById(R.id.releaseTagName);
|
releaseTagName = activityCreateReleaseBinding.releaseTagName;
|
||||||
releaseTitle = findViewById(R.id.releaseTitle);
|
releaseTitle = activityCreateReleaseBinding.releaseTitle;
|
||||||
releaseContent = findViewById(R.id.releaseContent);
|
releaseContent = activityCreateReleaseBinding.releaseContent;
|
||||||
releaseType = findViewById(R.id.releaseType);
|
releaseType = activityCreateReleaseBinding.releaseType;
|
||||||
releaseDraft = findViewById(R.id.releaseDraft);
|
releaseDraft = activityCreateReleaseBinding.releaseDraft;
|
||||||
|
|
||||||
releaseTagName.requestFocus();
|
releaseTitle.requestFocus();
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
imm.showSoftInput(releaseTagName, InputMethodManager.SHOW_IMPLICIT);
|
imm.showSoftInput(releaseTitle, InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
|
||||||
|
releaseContent.setOnTouchListener((touchView, motionEvent) -> {
|
||||||
|
|
||||||
|
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||||
|
|
||||||
|
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||||
|
|
||||||
|
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
releaseBranch = findViewById(R.id.releaseBranch);
|
releaseBranch = activityCreateReleaseBinding.releaseBranch;
|
||||||
releaseBranch.getBackground().setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
|
getBranches(Authorization.get(ctx), repoOwner, repoName);
|
||||||
getBranches(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
releaseBranch.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
||||||
@Override
|
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
||||||
Branches branch = (Branches) parent.getSelectedItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
createNewRelease = activityCreateReleaseBinding.createNewRelease;
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
createNewRelease = findViewById(R.id.createNewRelease);
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
|
|
||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
@@ -115,25 +110,16 @@ public class CreateReleaseActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener createReleaseListener = v -> processNewRelease();
|
private final View.OnClickListener createReleaseListener = v -> processNewRelease();
|
||||||
|
|
||||||
private void processNewRelease() {
|
private void processNewRelease() {
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
|
|
||||||
String newReleaseTagName = releaseTagName.getText().toString();
|
String newReleaseTagName = releaseTagName.getText().toString();
|
||||||
String newReleaseTitle = releaseTitle.getText().toString();
|
String newReleaseTitle = releaseTitle.getText().toString();
|
||||||
String newReleaseContent = releaseContent.getText().toString();
|
String newReleaseContent = releaseContent.getText().toString();
|
||||||
String newReleaseBranch = releaseBranch.getSelectedItem().toString();
|
String checkBranch = selectedBranch;
|
||||||
boolean newReleaseType = releaseType.isChecked();
|
boolean newReleaseType = releaseType.isChecked();
|
||||||
boolean newReleaseDraft = releaseDraft.isChecked();
|
boolean newReleaseDraft = releaseDraft.isChecked();
|
||||||
|
|
||||||
@@ -141,37 +127,38 @@ public class CreateReleaseActivity extends BaseActivity {
|
|||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(newReleaseTitle.equals("")) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.titleErrorEmpty));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(newReleaseTagName.equals("")) {
|
if(newReleaseTagName.equals("")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.tagNameErrorEmpty));
|
Toasty.error(ctx, getString(R.string.tagNameErrorEmpty));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newReleaseTitle.equals("")) {
|
if(checkBranch == null) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.titleErrorEmpty));
|
Toasty.error(ctx, getString(R.string.selectBranchError));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
createNewReleaseFunc(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, newReleaseTagName, newReleaseTitle, newReleaseContent, newReleaseBranch, newReleaseType, newReleaseDraft);
|
createNewReleaseFunc(Authorization.get(ctx), repoOwner, repoName, newReleaseTagName, newReleaseTitle, newReleaseContent, selectedBranch, newReleaseType, newReleaseDraft);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewReleaseFunc(final String instanceUrl, final String token, String repoOwner, String repoName, String newReleaseTagName, String newReleaseTitle, String newReleaseContent, String newReleaseBranch, boolean newReleaseType, boolean newReleaseDraft) {
|
private void createNewReleaseFunc(final String token, String repoOwner, String repoName, String newReleaseTagName, String newReleaseTitle, String newReleaseContent, String selectedBranch, boolean newReleaseType, boolean newReleaseDraft) {
|
||||||
|
|
||||||
Releases createReleaseJson = new Releases(newReleaseContent, newReleaseDraft, newReleaseTitle, newReleaseType, newReleaseTagName, newReleaseBranch);
|
Releases createReleaseJson = new Releases(newReleaseContent, newReleaseDraft, newReleaseTitle, newReleaseType, newReleaseTagName, selectedBranch);
|
||||||
|
|
||||||
Call<Releases> call;
|
Call<Releases> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
|
||||||
.createNewRelease(token, repoOwner, repoName, createReleaseJson);
|
.createNewRelease(token, repoOwner, repoName, createReleaseJson);
|
||||||
|
|
||||||
call.enqueue(new Callback<Releases>() {
|
call.enqueue(new Callback<Releases>() {
|
||||||
@@ -181,12 +168,10 @@ public class CreateReleaseActivity extends BaseActivity {
|
|||||||
|
|
||||||
if (response.code() == 201) {
|
if (response.code() == 201) {
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
tinyDB.putBoolean("updateReleases", true);
|
||||||
tinyDb.putBoolean("updateReleases", true);
|
|
||||||
Toasty.success(ctx, getString(R.string.releaseCreatedText));
|
Toasty.success(ctx, getString(R.string.releaseCreatedText));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
@@ -195,31 +180,27 @@ public class CreateReleaseActivity extends BaseActivity {
|
|||||||
ctx.getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
ctx.getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 403) {
|
else if(response.code() == 403) {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 404) {
|
else if(response.code() == 404) {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<Releases> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<Releases> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
}
|
}
|
||||||
@@ -227,11 +208,10 @@ public class CreateReleaseActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getBranches(String instanceUrl, String instanceToken, final String repoOwner, final String repoName) {
|
private void getBranches(String instanceToken, final String repoOwner, final String repoName) {
|
||||||
|
|
||||||
Call<List<Branches>> call = RetrofitClient
|
Call<List<Branches>> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
|
||||||
.getBranches(instanceToken, repoOwner, repoName);
|
.getBranches(instanceToken, repoOwner, repoName);
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Branches>>() {
|
call.enqueue(new Callback<List<Branches>>() {
|
||||||
@@ -240,29 +220,27 @@ public class CreateReleaseActivity extends BaseActivity {
|
|||||||
public void onResponse(@NonNull Call<List<Branches>> call, @NonNull retrofit2.Response<List<Branches>> response) {
|
public void onResponse(@NonNull Call<List<Branches>> call, @NonNull retrofit2.Response<List<Branches>> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
if(response.code() == 200) {
|
if(response.code() == 200) {
|
||||||
|
|
||||||
List<Branches> branchesList_ = response.body();
|
List<Branches> branchesList_ = response.body();
|
||||||
|
|
||||||
assert branchesList_ != null;
|
assert branchesList_ != null;
|
||||||
if(branchesList_.size() > 0) {
|
if(branchesList_.size() > 0) {
|
||||||
for (int i = 0; i < branchesList_.size(); i++) {
|
|
||||||
|
|
||||||
Branches data = new Branches(
|
branchesList.addAll(branchesList_);
|
||||||
branchesList_.get(i).getName()
|
|
||||||
);
|
|
||||||
branchesList.add(data);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayAdapter<Branches> adapter = new ArrayAdapter<>(CreateReleaseActivity.this,
|
ArrayAdapter<Branches> adapter = new ArrayAdapter<>(CreateReleaseActivity.this,
|
||||||
R.layout.spinner_item, branchesList);
|
R.layout.list_spinner_items, branchesList);
|
||||||
|
|
||||||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
|
||||||
releaseBranch.setAdapter(adapter);
|
releaseBranch.setAdapter(adapter);
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
|
releaseBranch.setOnItemClickListener ((parent, view, position, id) ->
|
||||||
|
|
||||||
|
selectedBranch = branchesList.get(position).getName()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
@@ -271,13 +249,13 @@ public class CreateReleaseActivity extends BaseActivity {
|
|||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<List<Branches>> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<List<Branches>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -285,12 +263,8 @@ public class CreateReleaseActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
onClickListener = new View.OnClickListener() {
|
|
||||||
@Override
|
onClickListener = view -> finish();
|
||||||
public void onClick(View view) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableProcessButton() {
|
private void disableProcessButton() {
|
||||||
|
|||||||
@@ -1,28 +1,29 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.Spinner;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import org.gitnex.tea4j.models.OrgOwner;
|
||||||
|
import org.gitnex.tea4j.models.OrganizationRepository;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityCreateRepoBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.OrgOwner;
|
|
||||||
import org.mian.gitnex.models.OrganizationRepository;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -38,45 +39,42 @@ public class CreateRepoActivity extends BaseActivity {
|
|||||||
|
|
||||||
public ImageView closeActivity;
|
public ImageView closeActivity;
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
private Spinner spinner;
|
private AutoCompleteTextView spinner;
|
||||||
private Button createRepo;
|
private Button createRepo;
|
||||||
private EditText repoName;
|
private EditText repoName;
|
||||||
private EditText repoDesc;
|
private EditText repoDesc;
|
||||||
private CheckBox repoAccess;
|
private CheckBox repoAccess;
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
List<OrgOwner> organizationsList = new ArrayList<>();
|
private String loginUid;
|
||||||
|
private String userLogin;
|
||||||
|
|
||||||
|
private String selectedOwner;
|
||||||
|
|
||||||
|
List<OrgOwner> organizationsList = new ArrayList<>();
|
||||||
|
|
||||||
//https://github.com/go-gitea/gitea/blob/52cfd2743c0e85b36081cf80a850e6a5901f1865/models/repo.go#L964-L967
|
//https://github.com/go-gitea/gitea/blob/52cfd2743c0e85b36081cf80a850e6a5901f1865/models/repo.go#L964-L967
|
||||||
final List<String> reservedRepoNames = Arrays.asList(".", "..");
|
final List<String> reservedRepoNames = Arrays.asList(".", "..");
|
||||||
final Pattern reservedRepoPatterns = Pattern.compile("\\.(git|wiki)$");
|
final Pattern reservedRepoPatterns = Pattern.compile("\\.(git|wiki)$");
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_new_repo;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
ActivityCreateRepoBinding activityCreateRepoBinding = ActivityCreateRepoBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityCreateRepoBinding.getRoot());
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(ctx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(ctx);
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
loginUid = tinyDB.getString("loginUid");
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
userLogin = tinyDB.getString("userLogin");
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String userLogin = tinyDb.getString("userLogin");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
closeActivity = findViewById(R.id.close);
|
closeActivity = activityCreateRepoBinding.close;
|
||||||
repoName = findViewById(R.id.newRepoName);
|
repoName = activityCreateRepoBinding.newRepoName;
|
||||||
repoDesc = findViewById(R.id.newRepoDescription);
|
repoDesc = activityCreateRepoBinding.newRepoDescription;
|
||||||
repoAccess = findViewById(R.id.newRepoPrivate);
|
repoAccess = activityCreateRepoBinding.newRepoPrivate;
|
||||||
|
|
||||||
repoName.requestFocus();
|
repoName.requestFocus();
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
@@ -85,23 +83,10 @@ public class CreateRepoActivity extends BaseActivity {
|
|||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
spinner = findViewById(R.id.ownerSpinner);
|
spinner = activityCreateRepoBinding.ownerSpinner;
|
||||||
spinner.getBackground().setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
|
getOrganizations(Authorization.get(ctx), userLogin);
|
||||||
getOrganizations(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), userLogin);
|
|
||||||
|
|
||||||
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
||||||
@Override
|
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
||||||
OrgOwner user = (OrgOwner) parent.getSelectedItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
createRepo = activityCreateRepoBinding.createNewRepoButton;
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
createRepo = findViewById(R.id.createNewRepoButton);
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
|
|
||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
@@ -114,24 +99,14 @@ public class CreateRepoActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener createRepoListener = new View.OnClickListener() {
|
private final View.OnClickListener createRepoListener = v -> processNewRepo();
|
||||||
public void onClick(View v) {
|
|
||||||
processNewRepo();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void processNewRepo() {
|
private void processNewRepo() {
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
AppUtil appUtil = new AppUtil();
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
String newRepoName = repoName.getText().toString();
|
String newRepoName = repoName.getText().toString();
|
||||||
String newRepoDesc = repoDesc.getText().toString();
|
String newRepoDesc = repoDesc.getText().toString();
|
||||||
String repoOwner = spinner.getSelectedItem().toString();
|
|
||||||
boolean newRepoAccess = repoAccess.isChecked();
|
boolean newRepoAccess = repoAccess.isChecked();
|
||||||
|
|
||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
@@ -141,7 +116,8 @@ public class CreateRepoActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!newRepoDesc.equals("")) {
|
if(!newRepoDesc.equals("")) {
|
||||||
if (appUtil.charactersLength(newRepoDesc) > 255) {
|
|
||||||
|
if (newRepoDesc.length() > 255) {
|
||||||
|
|
||||||
Toasty.warning(ctx, getString(R.string.repoDescError));
|
Toasty.warning(ctx, getString(R.string.repoDescError));
|
||||||
return;
|
return;
|
||||||
@@ -152,7 +128,7 @@ public class CreateRepoActivity extends BaseActivity {
|
|||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.repoNameErrorEmpty));
|
Toasty.error(ctx, getString(R.string.repoNameErrorEmpty));
|
||||||
}
|
}
|
||||||
else if(!appUtil.checkStrings(newRepoName)) {
|
else if(!AppUtil.checkStrings(newRepoName)) {
|
||||||
|
|
||||||
Toasty.warning(ctx, getString(R.string.repoNameErrorInvalid));
|
Toasty.warning(ctx, getString(R.string.repoNameErrorInvalid));
|
||||||
}
|
}
|
||||||
@@ -163,32 +139,34 @@ public class CreateRepoActivity extends BaseActivity {
|
|||||||
else if (reservedRepoPatterns.matcher(newRepoName).find()) {
|
else if (reservedRepoPatterns.matcher(newRepoName).find()) {
|
||||||
|
|
||||||
Toasty.warning(ctx, getString(R.string.repoNameErrorReservedPatterns));
|
Toasty.warning(ctx, getString(R.string.repoNameErrorReservedPatterns));
|
||||||
|
}
|
||||||
|
else if(selectedOwner == null) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.repoOwnerError));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
createNewRepository(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), loginUid, newRepoName, newRepoDesc, repoOwner, newRepoAccess);
|
createNewRepository(Authorization.get(ctx), loginUid, newRepoName, newRepoDesc, selectedOwner, newRepoAccess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewRepository(final String instanceUrl, final String token, String loginUid, String repoName, String repoDesc, String repoOwner, boolean isPrivate) {
|
private void createNewRepository(final String token, String loginUid, String repoName, String repoDesc, String selectedOwner, boolean isPrivate) {
|
||||||
|
|
||||||
OrganizationRepository createRepository = new OrganizationRepository(true, repoDesc, null, null, repoName, isPrivate, "Default");
|
OrganizationRepository createRepository = new OrganizationRepository(true, repoDesc, null, null, repoName, isPrivate, "Default");
|
||||||
|
|
||||||
Call<OrganizationRepository> call;
|
Call<OrganizationRepository> call;
|
||||||
if(repoOwner.equals(loginUid)) {
|
if(selectedOwner.equals(loginUid)) {
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
|
||||||
.createNewUserRepository(token, createRepository);
|
.createNewUserRepository(token, createRepository);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
.createNewUserOrgRepository(token, selectedOwner, createRepository);
|
||||||
.createNewUserOrgRepository(token, repoOwner, createRepository);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
call.enqueue(new Callback<OrganizationRepository>() {
|
call.enqueue(new Callback<OrganizationRepository>() {
|
||||||
@@ -198,7 +176,7 @@ public class CreateRepoActivity extends BaseActivity {
|
|||||||
|
|
||||||
if(response.code() == 201) {
|
if(response.code() == 201) {
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
tinyDb.putBoolean("repoCreated", true);
|
tinyDb.putBoolean("repoCreated", true);
|
||||||
Toasty.success(ctx, getString(R.string.repoCreated));
|
Toasty.success(ctx, getString(R.string.repoCreated));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
@@ -222,7 +200,6 @@ public class CreateRepoActivity extends BaseActivity {
|
|||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.error(ctx, getString(R.string.repoCreatedError));
|
Toasty.error(ctx, getString(R.string.repoCreatedError));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -234,73 +211,69 @@ public class CreateRepoActivity extends BaseActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getOrganizations(String instanceUrl, String instanceToken, final String userLogin) {
|
private void getOrganizations(String instanceToken, final String userLogin) {
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
Call<List<OrgOwner>> call = RetrofitClient
|
Call<List<OrgOwner>> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
.getOrgOwners(instanceToken, 1, 50);
|
||||||
.getOrgOwners(instanceToken);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<List<OrgOwner>>() {
|
call.enqueue(new Callback<List<OrgOwner>>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<List<OrgOwner>> call, @NonNull retrofit2.Response<List<OrgOwner>> response) {
|
public void onResponse(@NonNull Call<List<OrgOwner>> call, @NonNull retrofit2.Response<List<OrgOwner>> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.code() == 200) {
|
||||||
if(response.code() == 200) {
|
|
||||||
|
|
||||||
int organizationId = 0;
|
int organizationId = 0;
|
||||||
|
|
||||||
List<OrgOwner> organizationsList_ = response.body();
|
List<OrgOwner> organizationsList_ = response.body();
|
||||||
|
|
||||||
organizationsList.add(new OrgOwner(userLogin));
|
organizationsList.add(new OrgOwner(userLogin));
|
||||||
assert organizationsList_ != null;
|
assert organizationsList_ != null;
|
||||||
if(organizationsList_.size() > 0) {
|
|
||||||
|
|
||||||
for (int i = 0; i < organizationsList_.size(); i++) {
|
if(organizationsList_.size() > 0) {
|
||||||
|
|
||||||
if(!tinyDb.getString("organizationId").isEmpty()) {
|
for(int i = 0; i < organizationsList_.size(); i++) {
|
||||||
|
|
||||||
if (Integer.parseInt(tinyDb.getString("organizationId")) == organizationsList_.get(i).getId()) {
|
if(!tinyDB.getString("organizationId").isEmpty()) {
|
||||||
organizationId = i + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OrgOwner data = new OrgOwner(
|
if(Integer.parseInt(tinyDB.getString("organizationId")) == organizationsList_.get(i).getId()) {
|
||||||
organizationsList_.get(i).getUsername()
|
organizationId = i + 1;
|
||||||
);
|
}
|
||||||
organizationsList.add(data);
|
}
|
||||||
|
|
||||||
}
|
OrgOwner data = new OrgOwner(organizationsList_.get(i).getUsername());
|
||||||
}
|
organizationsList.add(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ArrayAdapter<OrgOwner> adapter = new ArrayAdapter<>(CreateRepoActivity.this,
|
ArrayAdapter<OrgOwner> adapter = new ArrayAdapter<>(CreateRepoActivity.this, R.layout.list_spinner_items, organizationsList);
|
||||||
R.layout.spinner_item, organizationsList);
|
|
||||||
|
|
||||||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
spinner.setAdapter(adapter);
|
||||||
spinner.setAdapter(adapter);
|
|
||||||
|
|
||||||
if (tinyDb.getBoolean("organizationAction") & organizationId != 0) {
|
spinner.setOnItemClickListener ((parent, view, position, id) -> selectedOwner = organizationsList.get(position).getUsername());
|
||||||
|
|
||||||
spinner.setSelection(organizationId);
|
if(tinyDB.getBoolean("organizationAction") & organizationId != 0) {
|
||||||
tinyDb.putBoolean("organizationAction", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
enableProcessButton();
|
int selectOwnerById = organizationId;
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
|
|
||||||
}
|
spinner.setText(organizationsList.get(selectOwnerById).getUsername(), false);
|
||||||
}
|
selectedOwner = organizationsList.get(selectOwnerById).getUsername();
|
||||||
else if(response.code() == 401) {
|
}, 500);
|
||||||
|
|
||||||
enableProcessButton();
|
tinyDB.putBoolean("organizationAction", false);
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
}
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
enableProcessButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
|
enableProcessButton();
|
||||||
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -11,14 +11,16 @@ import android.widget.ImageView;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
|
import org.gitnex.tea4j.models.Teams;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityCreateTeamByOrgBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.Teams;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -31,8 +33,6 @@ import retrofit2.Callback;
|
|||||||
|
|
||||||
public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClickListener {
|
public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClickListener {
|
||||||
|
|
||||||
final Context ctx = CreateTeamByOrgActivity.this;
|
|
||||||
private Context appCtx;
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
private TextView teamName;
|
private TextView teamName;
|
||||||
private TextView teamDesc;
|
private TextView teamDesc;
|
||||||
@@ -41,15 +41,10 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
|||||||
private TextView teamAccessControls;
|
private TextView teamAccessControls;
|
||||||
private TextView teamAccessControlsArray;
|
private TextView teamAccessControlsArray;
|
||||||
private Button createTeamButton;
|
private Button createTeamButton;
|
||||||
private String[] permissionList = {"Read", "Write", "Admin"};
|
private final String[] permissionList = {"Read", "Write", "Admin"};
|
||||||
public int permissionSelectedChoice = -1;
|
public int permissionSelectedChoice = -1;
|
||||||
|
|
||||||
@Override
|
private final String[] accessControlsList = new String[] {
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_create_team_by_org;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] accessControlsList = new String[] {
|
|
||||||
"Code",
|
"Code",
|
||||||
"Issues",
|
"Issues",
|
||||||
"Pull Request",
|
"Pull Request",
|
||||||
@@ -61,7 +56,7 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
|||||||
|
|
||||||
private List<String> pushAccessList;
|
private List<String> pushAccessList;
|
||||||
|
|
||||||
private boolean[] selectedAccessControlsTrueFalse = new boolean[]{
|
private final boolean[] selectedAccessControlsTrueFalse = new boolean[]{
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
@@ -75,20 +70,22 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
ActivityCreateTeamByOrgBinding activityCreateTeamByOrgBinding = ActivityCreateTeamByOrgBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityCreateTeamByOrgBinding.getRoot());
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activityCreateTeamByOrgBinding.close;
|
||||||
teamName = findViewById(R.id.teamName);
|
teamName = activityCreateTeamByOrgBinding.teamName;
|
||||||
teamDesc = findViewById(R.id.teamDesc);
|
teamDesc = activityCreateTeamByOrgBinding.teamDesc;
|
||||||
teamPermission = findViewById(R.id.teamPermission);
|
teamPermission = activityCreateTeamByOrgBinding.teamPermission;
|
||||||
teamPermissionDetail = findViewById(R.id.teamPermissionDetail);
|
teamPermissionDetail = activityCreateTeamByOrgBinding.teamPermissionDetail;
|
||||||
teamAccessControls = findViewById(R.id.teamAccessControls);
|
teamAccessControls = activityCreateTeamByOrgBinding.teamAccessControls;
|
||||||
teamAccessControlsArray = findViewById(R.id.teamAccessControlsArray);
|
teamAccessControlsArray = activityCreateTeamByOrgBinding.teamAccessControlsArray;
|
||||||
createTeamButton = findViewById(R.id.createTeamButton);
|
createTeamButton = activityCreateTeamByOrgBinding.createTeamButton;
|
||||||
|
|
||||||
teamName.requestFocus();
|
teamName.requestFocus();
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
@@ -102,12 +99,8 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
|||||||
AlertDialog.Builder pBuilder = new AlertDialog.Builder(ctx);
|
AlertDialog.Builder pBuilder = new AlertDialog.Builder(ctx);
|
||||||
|
|
||||||
pBuilder.setTitle(R.string.newTeamPermission);
|
pBuilder.setTitle(R.string.newTeamPermission);
|
||||||
if(permissionSelectedChoice != -1) {
|
pBuilder.setCancelable(permissionSelectedChoice != -1);
|
||||||
pBuilder.setCancelable(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pBuilder.setCancelable(false);
|
|
||||||
}
|
|
||||||
pBuilder.setSingleChoiceItems(permissionList, permissionSelectedChoice, (dialogInterface, i) -> {
|
pBuilder.setSingleChoiceItems(permissionList, permissionSelectedChoice, (dialogInterface, i) -> {
|
||||||
|
|
||||||
permissionSelectedChoice = i;
|
permissionSelectedChoice = i;
|
||||||
@@ -136,15 +129,12 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
|||||||
}
|
}
|
||||||
|
|
||||||
dialogInterface.dismiss();
|
dialogInterface.dismiss();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
AlertDialog pDialog = pBuilder.create();
|
AlertDialog pDialog = pBuilder.create();
|
||||||
pDialog.show();
|
pDialog.show();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
teamAccessControls.setOnClickListener(v -> {
|
teamAccessControls.setOnClickListener(v -> {
|
||||||
|
|
||||||
teamAccessControls.setText("");
|
teamAccessControls.setText("");
|
||||||
@@ -189,6 +179,7 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(value){
|
if(value){
|
||||||
|
|
||||||
teamAccessControls.setText(getString(R.string.newTeamPermissionValues, teamAccessControls.getText(), pushAccessList.get(selectedVal)));
|
teamAccessControls.setText(getString(R.string.newTeamPermissionValues, teamAccessControls.getText(), pushAccessList.get(selectedVal)));
|
||||||
teamAccessControlsArray.setText(getString(R.string.newTeamPermissionValuesFinal, teamAccessControlsArray.getText(), repoCode));
|
teamAccessControlsArray.setText(getString(R.string.newTeamPermissionValuesFinal, teamAccessControlsArray.getText(), repoCode));
|
||||||
}
|
}
|
||||||
@@ -198,15 +189,16 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
|||||||
|
|
||||||
String data = String.valueOf(teamAccessControls.getText());
|
String data = String.valueOf(teamAccessControls.getText());
|
||||||
if(!data.equals("")) {
|
if(!data.equals("")) {
|
||||||
|
|
||||||
teamAccessControls.setText(data.substring(0, data.length() - 2));
|
teamAccessControls.setText(data.substring(0, data.length() - 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
String dataArray = String.valueOf(teamAccessControlsArray.getText());
|
String dataArray = String.valueOf(teamAccessControlsArray.getText());
|
||||||
|
|
||||||
if(!dataArray.equals("")) {
|
if(!dataArray.equals("")) {
|
||||||
|
|
||||||
teamAccessControlsArray.setText(dataArray.substring(0, dataArray.length() - 2));
|
teamAccessControlsArray.setText(dataArray.substring(0, dataArray.length() - 2));
|
||||||
}
|
}
|
||||||
//Log.i("orgName", String.valueOf(teamAccessControlsArray.getText()));
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
AlertDialog aDialog = aDialogBuilder.create();
|
AlertDialog aDialog = aDialogBuilder.create();
|
||||||
@@ -218,25 +210,21 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
|||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
|
|
||||||
createTeamButton.setEnabled(false);
|
createTeamButton.setEnabled(false);
|
||||||
GradientDrawable shape = new GradientDrawable();
|
GradientDrawable shape = new GradientDrawable();
|
||||||
shape.setCornerRadius( 8 );
|
shape.setCornerRadius(8);
|
||||||
shape.setColor(getResources().getColor(R.color.hintColor));
|
shape.setColor(ResourcesCompat.getColor(getResources(), R.color.hintColor, null));
|
||||||
createTeamButton.setBackground(shape);
|
createTeamButton.setBackground(shape);
|
||||||
|
}
|
||||||
} else {
|
else {
|
||||||
|
|
||||||
createTeamButton.setEnabled(true);
|
createTeamButton.setEnabled(true);
|
||||||
createTeamButton.setOnClickListener(this);
|
createTeamButton.setOnClickListener(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processCreateTeam() {
|
private void processCreateTeam() {
|
||||||
|
|
||||||
AppUtil appUtil = new AppUtil();
|
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
final String loginUid = tinyDb.getString("loginUid");
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||||
final String orgName = tinyDb.getString("orgName");;
|
final String orgName = tinyDb.getString("orgName");;
|
||||||
@@ -251,64 +239,60 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
|||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newTeamName.equals("")) {
|
if (newTeamName.equals("")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.teamNameEmpty));
|
Toasty.error(ctx, getString(R.string.teamNameEmpty));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!appUtil.checkStringsWithAlphaNumericDashDotUnderscore(newTeamName)) {
|
if(!AppUtil.checkStringsWithAlphaNumericDashDotUnderscore(newTeamName)) {
|
||||||
|
|
||||||
Toasty.warning(ctx, getString(R.string.teamNameError));
|
Toasty.warning(ctx, getString(R.string.teamNameError));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!newTeamDesc.equals("")) {
|
if(!newTeamDesc.equals("")) {
|
||||||
|
|
||||||
if(!appUtil.checkStrings(newTeamDesc)) {
|
if(!AppUtil.checkStrings(newTeamDesc)) {
|
||||||
|
|
||||||
Toasty.warning(ctx, getString(R.string.teamDescError));
|
Toasty.warning(ctx, getString(R.string.teamDescError));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newTeamDesc.length() > 100) {
|
if(newTeamDesc.length() > 100) {
|
||||||
|
|
||||||
Toasty.warning(ctx, getString(R.string.teamDescLimit));
|
Toasty.warning(ctx, getString(R.string.teamDescLimit));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newTeamPermission.equals("")) {
|
if (newTeamPermission.equals("")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.teamPermissionEmpty));
|
Toasty.error(ctx, getString(R.string.teamPermissionEmpty));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> newTeamAccessControls_ = new ArrayList<>(Arrays.asList(newTeamAccessControls.split(",")));
|
List<String> newTeamAccessControls_ = new ArrayList<>(Arrays.asList(newTeamAccessControls.split(",")));
|
||||||
|
|
||||||
for (int i = 0; i < newTeamAccessControls_.size(); i++) {
|
for (int i = 0; i < newTeamAccessControls_.size(); i++) {
|
||||||
|
|
||||||
newTeamAccessControls_.set(i, newTeamAccessControls_.get(i).trim());
|
newTeamAccessControls_.set(i, newTeamAccessControls_.get(i).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
createNewTeamCall(instanceUrl, instanceToken, orgName, newTeamName, newTeamDesc, newTeamPermission, newTeamAccessControls_, loginUid);
|
createNewTeamCall(instanceToken, orgName, newTeamName, newTeamDesc, newTeamPermission, newTeamAccessControls_, loginUid);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewTeamCall(final String instanceUrl, final String instanceToken, String orgName, String newTeamName, String newTeamDesc, String newTeamPermission, List<String> newTeamAccessControls, String loginUid) {
|
private void createNewTeamCall(final String instanceToken, String orgName, String newTeamName, String newTeamDesc, String newTeamPermission, List<String> newTeamAccessControls, String loginUid) {
|
||||||
|
|
||||||
Teams createNewTeamJson = new Teams(newTeamName, newTeamDesc, newTeamPermission, newTeamAccessControls);
|
Teams createNewTeamJson = new Teams(newTeamName, newTeamDesc, newTeamPermission, newTeamAccessControls);
|
||||||
|
|
||||||
Call<Teams> call3;
|
Call<Teams> call3;
|
||||||
|
|
||||||
call3 = RetrofitClient
|
call3 = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
.createTeamsByOrg(Authorization.get(ctx), orgName, createNewTeamJson);
|
||||||
.createTeamsByOrg(Authorization.returnAuthentication(ctx, loginUid, instanceToken), orgName, createNewTeamJson);
|
|
||||||
|
|
||||||
call3.enqueue(new Callback<Teams>() {
|
call3.enqueue(new Callback<Teams>() {
|
||||||
|
|
||||||
@@ -316,15 +300,15 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
|||||||
public void onResponse(@NonNull Call<Teams> call, @NonNull retrofit2.Response<Teams> response2) {
|
public void onResponse(@NonNull Call<Teams> call, @NonNull retrofit2.Response<Teams> response2) {
|
||||||
|
|
||||||
if(response2.isSuccessful()) {
|
if(response2.isSuccessful()) {
|
||||||
|
|
||||||
if(response2.code() == 201) {
|
if(response2.code() == 201) {
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
tinyDb.putBoolean("resumeTeams", true);
|
tinyDb.putBoolean("resumeTeams", true);
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.teamCreated));
|
Toasty.success(ctx, getString(R.string.teamCreated));
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response2.code() == 404) {
|
else if(response2.code() == 404) {
|
||||||
|
|
||||||
@@ -341,7 +325,6 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
|||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.teamCreatedError));
|
Toasty.error(ctx, getString(R.string.teamCreatedError));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -356,6 +339,7 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
if(v == createTeamButton) {
|
if(v == createTeamButton) {
|
||||||
|
|
||||||
processCreateTeam();
|
processCreateTeam();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,698 @@
|
|||||||
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.gitnex.tea4j.models.Files;
|
||||||
|
import org.gitnex.tea4j.models.Organization;
|
||||||
|
import org.gitnex.tea4j.models.PullRequests;
|
||||||
|
import org.gitnex.tea4j.models.UserInfo;
|
||||||
|
import org.gitnex.tea4j.models.UserRepositories;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.database.api.BaseApi;
|
||||||
|
import org.mian.gitnex.database.api.RepositoriesApi;
|
||||||
|
import org.mian.gitnex.database.api.UserAccountsApi;
|
||||||
|
import org.mian.gitnex.database.models.Repository;
|
||||||
|
import org.mian.gitnex.database.models.UserAccount;
|
||||||
|
import org.mian.gitnex.databinding.ActivityDeeplinksBinding;
|
||||||
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
|
import org.mian.gitnex.helpers.UrlHelper;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import io.mikael.urlbuilder.UrlBuilder;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DeepLinksActivity extends BaseActivity {
|
||||||
|
|
||||||
|
private ActivityDeeplinksBinding viewBinding;
|
||||||
|
private String currentInstance;
|
||||||
|
private String instanceToken;
|
||||||
|
private boolean accountFound = false;
|
||||||
|
|
||||||
|
private Intent mainIntent;
|
||||||
|
private Intent issueIntent;
|
||||||
|
private Intent repoIntent;
|
||||||
|
private Intent orgIntent;
|
||||||
|
private Intent userIntent;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
viewBinding = ActivityDeeplinksBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(viewBinding.getRoot());
|
||||||
|
|
||||||
|
mainIntent = new Intent(ctx, MainActivity.class);
|
||||||
|
issueIntent = new Intent(ctx, IssueDetailActivity.class);
|
||||||
|
repoIntent = new Intent(ctx, RepoDetailActivity.class);
|
||||||
|
orgIntent = new Intent(ctx, OrganizationDetailActivity.class);
|
||||||
|
userIntent = new Intent(ctx, ProfileActivity.class);
|
||||||
|
|
||||||
|
Intent intent = getIntent();
|
||||||
|
Uri data = intent.getData();
|
||||||
|
assert data != null;
|
||||||
|
|
||||||
|
// check for login
|
||||||
|
if(!tinyDB.getBoolean("loggedInMode")) {
|
||||||
|
Intent loginIntent = new Intent(ctx, LoginActivity.class);
|
||||||
|
loginIntent.putExtra("instanceUrl", data.getHost());
|
||||||
|
ctx.startActivity(loginIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for the links(URI) to be in the db
|
||||||
|
UserAccountsApi userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class);
|
||||||
|
List<UserAccount> userAccounts = userAccountsApi.usersAccounts();
|
||||||
|
|
||||||
|
for(UserAccount userAccount : userAccounts) {
|
||||||
|
|
||||||
|
String hostUri = userAccount.getInstanceUrl();
|
||||||
|
|
||||||
|
currentInstance = userAccount.getInstanceUrl();
|
||||||
|
instanceToken = userAccount.getToken();
|
||||||
|
|
||||||
|
if(hostUri.toLowerCase().contains(Objects.requireNonNull(data.getHost().toLowerCase()))) {
|
||||||
|
|
||||||
|
accountFound = true;
|
||||||
|
|
||||||
|
AppUtil.switchToAccount(ctx, userAccount);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(accountFound) {
|
||||||
|
|
||||||
|
// redirect to proper fragment/activity, if no action is there, show options where user to want to go like repos, profile, notifications etc
|
||||||
|
if(data.getPathSegments().size() == 1) {
|
||||||
|
if(data.getLastPathSegment().equals("notifications")) { // notifications
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else if(data.getLastPathSegment().equals("explore")) { // explore
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else if(data.getLastPathSegment().equals(tinyDB.getString("userLogin"))) { // your user profile
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "profile");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else if(data.getLastPathSegment().equals("admin")) {
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "admin");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
getUserOrOrg(currentInstance, instanceToken, data.getLastPathSegment()), 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().size() == 2) {
|
||||||
|
if(data.getPathSegments().get(0).equals("explore")) { // specific explore tab
|
||||||
|
if(data.getPathSegments().get(1).equals("organizations")) { // orgs
|
||||||
|
mainIntent.putExtra("exploreOrgs", true);
|
||||||
|
}
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(0).equals("user") && data.getPathSegments().get(1).equals("login")) { // open login
|
||||||
|
Intent loginIntent = new Intent(ctx, AddNewAccountActivity.class);
|
||||||
|
loginIntent.putExtra("instanceUrl", data.getHost());
|
||||||
|
loginIntent.putExtra("instanceProtocol", data.getScheme());
|
||||||
|
ctx.startActivity(loginIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(0).equals("admin")) {
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "admin");
|
||||||
|
mainIntent.putExtra("giteaAdminAction", data.getLastPathSegment());
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else if(!data.getPathSegments().get(0).equals("") & !data.getLastPathSegment().equals("")) { // go to repo
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getLastPathSegment(), "repo"), 500);
|
||||||
|
}
|
||||||
|
else { // no action, show options
|
||||||
|
showNoActionButtons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().size() >= 3) {
|
||||||
|
if(data.getPathSegments().get(2).equals("issues")) { // issue
|
||||||
|
|
||||||
|
if(!Objects.requireNonNull(data.getLastPathSegment()).contains("issues") & StringUtils.isNumeric(data.getLastPathSegment())) {
|
||||||
|
|
||||||
|
issueIntent.putExtra("issueNumber", data.getLastPathSegment());
|
||||||
|
issueIntent.putExtra("openedFromLink", "true");
|
||||||
|
|
||||||
|
String[] urlSplitted = data.toString().split("#");
|
||||||
|
if (urlSplitted.length == 2) {
|
||||||
|
issueIntent.putExtra("issueComment", urlSplitted[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
tinyDB.putString("issueNumber", data.getLastPathSegment());
|
||||||
|
tinyDB.putString("issueType", "Issue");
|
||||||
|
|
||||||
|
tinyDB.putString("repoFullName", data.getPathSegments().get(0) + "/" + data.getPathSegments().get(1));
|
||||||
|
|
||||||
|
final String repoOwner = data.getPathSegments().get(0);
|
||||||
|
final String repoName = data.getPathSegments().get(1);
|
||||||
|
|
||||||
|
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
||||||
|
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
|
||||||
|
|
||||||
|
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
|
||||||
|
if(count == 0) {
|
||||||
|
|
||||||
|
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
tinyDB.putLong("repositoryId", id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
Repository dataRepo = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
tinyDB.putLong("repositoryId", dataRepo.getRepositoryId());
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.startActivity(issueIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else if(Objects.requireNonNull(data.getLastPathSegment()).contains("issues")) {
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "issue"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getLastPathSegment().equals("new")) {
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "issueNew"), 500);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(2).equals("pulls")) { // pr
|
||||||
|
|
||||||
|
if(!Objects.requireNonNull(data.getLastPathSegment()).contains("pulls") & StringUtils.isNumeric(data.getLastPathSegment())) {
|
||||||
|
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
|
|
||||||
|
String[] urlSplitted = data.toString().split("#");
|
||||||
|
if (urlSplitted.length == 2) {
|
||||||
|
issueIntent.putExtra("issueComment", urlSplitted[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
getPullRequest(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), Integer.parseInt(data.getLastPathSegment()));
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(Objects.requireNonNull(data.getLastPathSegment()).contains("pulls")) {
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "pull"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getLastPathSegment().equals("files")) { // pr diff
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
|
issueIntent.putExtra("openPrDiff", "true");
|
||||||
|
getPullRequest(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), Integer.parseInt(data.getPathSegments().get(3)));
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if(data.getPathSegments().get(2).equals("compare")) { // new pull request
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "pullNew"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(2).equals("commit")) { // commits (no API yet to properly implement)
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "pull"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(2).equals("commits")) { // commits list
|
||||||
|
String branch = data.getLastPathSegment();
|
||||||
|
repoIntent.putExtra("branchName", branch);
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "commitsList"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(2).equals("milestones") && data.getLastPathSegment().equals("new")) { // new milestone
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "milestonesNew"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(2).equals("milestones")) { // milestones
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "milestones"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(2).equals("milestone")) { // milestone
|
||||||
|
repoIntent.putExtra("milestoneId", data.getLastPathSegment());
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "milestones"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(2).equals("releases") && data.getLastPathSegment().equals("new")) { // new release
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "newRelease"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(2).equals("releases")) { // releases
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "releases"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(2).equals("releases") && data.getPathSegments().get(3).equals("tag") && data.getPathSegments().size() == 5) { // release
|
||||||
|
repoIntent.putExtra("releaseTagName", data.getLastPathSegment());
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "releases"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(2).equals("labels")) { // labels
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "labels"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(2).equals("settings")) { // repo settings
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "settings"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getLastPathSegment().equals("branches")) { // branches list
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "branchesList"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().size() == 5 && data.getPathSegments().get(2).equals("src") && data.getPathSegments().get(3).equals("branch")) { // branch
|
||||||
|
repoIntent.putExtra("selectedBranch", data.getLastPathSegment());
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
goToRepoSection(currentInstance, instanceToken, data.getPathSegments().get(0), data.getPathSegments().get(1), "branch"), 500);
|
||||||
|
}
|
||||||
|
else if(data.getPathSegments().get(2).equals("src") && data.getPathSegments().get(3).equals("branch")) { // file/dir
|
||||||
|
StringBuilder filePath = new StringBuilder();
|
||||||
|
ArrayList<String> segments = new ArrayList<>(data.getPathSegments());
|
||||||
|
segments.subList(0, 5).clear();
|
||||||
|
for (String item : segments) {
|
||||||
|
filePath.append(item);
|
||||||
|
filePath.append("/");
|
||||||
|
}
|
||||||
|
filePath.deleteCharAt(filePath.toString().length() - 1);
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() ->
|
||||||
|
getFile(currentInstance, instanceToken, data.getPathSegments().get(0),
|
||||||
|
data.getPathSegments().get(1), filePath.toString(), data.getPathSegments().get(4)), 500);
|
||||||
|
}
|
||||||
|
else { // no action, show options
|
||||||
|
showNoActionButtons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
viewBinding.progressBar.setVisibility(View.GONE);
|
||||||
|
viewBinding.addNewAccountFrame.setVisibility(View.VISIBLE);
|
||||||
|
viewBinding.noActionFrame.setVisibility(View.GONE);
|
||||||
|
viewBinding.addAccountText.setText(String.format(getResources().getString(R.string.accountDoesNotExist), data.getHost()));
|
||||||
|
|
||||||
|
viewBinding.addNewAccount.setOnClickListener(addNewAccount -> {
|
||||||
|
|
||||||
|
Intent accountIntent = new Intent(ctx, AddNewAccountActivity.class);
|
||||||
|
accountIntent.putExtra("instanceUrl", data.getHost());
|
||||||
|
startActivity(accountIntent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
|
||||||
|
viewBinding.openInBrowser.setOnClickListener(addNewAccount -> {
|
||||||
|
|
||||||
|
Integer port = data.getPort() >= 0 ? data.getPort() : null;
|
||||||
|
|
||||||
|
URI host = UrlBuilder.fromString(UrlHelper.fixScheme(data.getHost(), "https"))
|
||||||
|
.withPort(port)
|
||||||
|
.toUri();
|
||||||
|
|
||||||
|
Intent intentBrowser = new Intent();
|
||||||
|
|
||||||
|
intentBrowser.setAction(Intent.ACTION_VIEW);
|
||||||
|
intentBrowser.addCategory(Intent.CATEGORY_BROWSABLE);
|
||||||
|
intentBrowser.setData(Uri.parse(String.valueOf(host)));
|
||||||
|
|
||||||
|
startActivity(intentBrowser);
|
||||||
|
finish();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
viewBinding.launchApp.setOnClickListener(launchApp -> {
|
||||||
|
|
||||||
|
startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getPullRequest(String url, String token, String repoOwner, String repoName, int index) {
|
||||||
|
|
||||||
|
Call<PullRequests> call = RetrofitClient
|
||||||
|
.getApiInterface(ctx, url)
|
||||||
|
.getPullRequestByIndex(token, repoOwner, repoName, index);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<PullRequests>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<PullRequests> call, @NonNull retrofit2.Response<PullRequests> response) {
|
||||||
|
|
||||||
|
PullRequests prInfo = response.body();
|
||||||
|
|
||||||
|
if (response.code() == 200) {
|
||||||
|
|
||||||
|
assert prInfo != null;
|
||||||
|
|
||||||
|
issueIntent.putExtra("issueNumber", index);
|
||||||
|
issueIntent.putExtra("prMergeable", prInfo.isMergeable());
|
||||||
|
issueIntent.putExtra("openedFromLink", "true");
|
||||||
|
|
||||||
|
if(prInfo.getHead() != null) {
|
||||||
|
|
||||||
|
issueIntent.putExtra("prHeadBranch", prInfo.getHead().getRef());
|
||||||
|
tinyDB.putString("prHeadBranch", prInfo.getHead().getRef());
|
||||||
|
|
||||||
|
if(prInfo.getHead().getRepo() != null) {
|
||||||
|
|
||||||
|
tinyDB.putString("prIsFork", String.valueOf(prInfo.getHead().getRepo().isFork()));
|
||||||
|
tinyDB.putString("prForkFullName", prInfo.getHead().getRepo().getFull_name());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
// pull was done from a deleted fork
|
||||||
|
tinyDB.putString("prIsFork", "true");
|
||||||
|
tinyDB.putString("prForkFullName", ctx.getString(R.string.prDeletedFork));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tinyDB.putString("issueNumber", String.valueOf(index));
|
||||||
|
tinyDB.putString("prMergeable", String.valueOf(prInfo.isMergeable()));
|
||||||
|
tinyDB.putString("issueType", "Pull");
|
||||||
|
|
||||||
|
tinyDB.putString("repoFullName", repoOwner + "/" + repoName);
|
||||||
|
|
||||||
|
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
||||||
|
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
|
||||||
|
|
||||||
|
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
|
||||||
|
if(count == 0) {
|
||||||
|
|
||||||
|
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
tinyDB.putLong("repositoryId", id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
Repository dataRepo = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
tinyDB.putLong("repositoryId", dataRepo.getRepositoryId());
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.startActivity(issueIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
|
||||||
|
ctx.startActivity(issueIntent);
|
||||||
|
finish();
|
||||||
|
Log.e("onFailure-links-pr", String.valueOf(response.code()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<PullRequests> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
ctx.startActivity(issueIntent);
|
||||||
|
finish();
|
||||||
|
Log.e("onFailure-links-pr", t.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void goToRepoSection(String url, String token, String repoOwner, String repoName, String type) {
|
||||||
|
|
||||||
|
Call<UserRepositories> call = RetrofitClient
|
||||||
|
.getApiInterface(ctx, url)
|
||||||
|
.getUserRepository(token, repoOwner, repoName);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<UserRepositories>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<UserRepositories> call, @NonNull retrofit2.Response<UserRepositories> response) {
|
||||||
|
|
||||||
|
UserRepositories repoInfo = response.body();
|
||||||
|
|
||||||
|
if (response.code() == 200) {
|
||||||
|
|
||||||
|
assert repoInfo != null;
|
||||||
|
|
||||||
|
repoIntent.putExtra("repoFullName", repoInfo.getFullName());
|
||||||
|
repoIntent.putExtra("goToSection", "yes");
|
||||||
|
repoIntent.putExtra("goToSectionType", type);
|
||||||
|
|
||||||
|
tinyDB.putString("repoFullName", repoInfo.getFullName());
|
||||||
|
if(repoInfo.getPrivateFlag()) {
|
||||||
|
|
||||||
|
tinyDB.putString("repoType", getResources().getString(R.string.strPrivate));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
tinyDB.putString("repoType", getResources().getString(R.string.strPublic));
|
||||||
|
}
|
||||||
|
tinyDB.putBoolean("isRepoAdmin", repoInfo.getPermissions().isAdmin());
|
||||||
|
tinyDB.putString("repoBranch", repoInfo.getDefault_branch());
|
||||||
|
|
||||||
|
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
||||||
|
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
|
||||||
|
|
||||||
|
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
|
||||||
|
if(count == 0) {
|
||||||
|
|
||||||
|
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
tinyDB.putLong("repositoryId", id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
tinyDB.putLong("repositoryId", data.getRepositoryId());
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.startActivity(repoIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
Log.e("onFailure-goToRepo", String.valueOf(response.code()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<UserRepositories> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
Log.e("onFailure-goToRepo", t.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getUserOrOrg(String url, String instanceToken, String userOrgName) {
|
||||||
|
Call<Organization> call = RetrofitClient.getApiInterface(ctx, url).getOrganization(instanceToken, userOrgName);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<Organization>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NotNull Call<Organization> call, @NotNull Response<Organization> response) {
|
||||||
|
if(response.code() == 404) { // org doesn't exist or it's a user user
|
||||||
|
Log.d("getUserOrOrg-404", String.valueOf(response.code()));
|
||||||
|
getUser(url, instanceToken, userOrgName);
|
||||||
|
}
|
||||||
|
else if(response.code() == 200) { // org
|
||||||
|
assert response.body() != null;
|
||||||
|
orgIntent.putExtra("orgName", response.body().getUsername());
|
||||||
|
|
||||||
|
|
||||||
|
TinyDB tinyDb = TinyDB.getInstance(ctx);
|
||||||
|
tinyDb.putString("orgName", response.body().getUsername());
|
||||||
|
tinyDb.putString("organizationId", String.valueOf(response.body().getId()));
|
||||||
|
tinyDb.putBoolean("organizationAction", true);
|
||||||
|
ctx.startActivity(orgIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log.e("getUserOrOrg-code", String.valueOf(response.code()));
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NotNull Call<Organization> call, @NotNull Throwable t) {
|
||||||
|
Log.e("onFailure-getUserOrOrg", t.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getUser(String url, String instanceToken, String userName) {
|
||||||
|
Call<UserInfo> call = RetrofitClient.getApiInterface(ctx, url).getUserProfile(instanceToken, userName);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<UserInfo>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NotNull Call<UserInfo> call, @NotNull Response<UserInfo> response) {
|
||||||
|
if(response.code() == 200) {
|
||||||
|
assert response.body() != null;
|
||||||
|
userIntent.putExtra("username", response.body().getLogin());
|
||||||
|
ctx.startActivity(userIntent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log.e("getUser-code", String.valueOf(response.code()));
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
}
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NotNull Call<UserInfo> call, @NotNull Throwable t) {
|
||||||
|
Log.e("onFailure-getUser", t.toString());
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getFile(String url, String instanceToken, String owner, String repo, String filePath, String branch) {
|
||||||
|
Call<Files> call = RetrofitClient.getApiInterface(ctx, url).getSingleFileContents(instanceToken, owner, repo, filePath, branch);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<Files>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NotNull Call<Files> call, @NotNull Response<Files> response) {
|
||||||
|
if(response.code() == 200) {
|
||||||
|
// check if file and open file/dir
|
||||||
|
Files file = response.body();
|
||||||
|
assert file != null;
|
||||||
|
if(file.getType().equals("file")) {
|
||||||
|
repoIntent.putExtra("file", file);
|
||||||
|
repoIntent.putExtra("branch", branch);
|
||||||
|
goToRepoSection(url, instanceToken, owner, repo, "file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Log.e("getFile-onFailure", String.valueOf(response.code()));
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NotNull Call<Files> call, @NotNull Throwable t) {
|
||||||
|
Log.e("getFile-onFailure", t.toString());
|
||||||
|
// maybe it's a directory
|
||||||
|
getDir(url, instanceToken, owner, repo, filePath, branch);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getDir(String url, String instanceToken, String owner, String repo, String filePath, String branch) {
|
||||||
|
repoIntent.putExtra("branch", branch);
|
||||||
|
repoIntent.putExtra("dir", filePath);
|
||||||
|
goToRepoSection(url, instanceToken, owner, repo, "dir");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showNoActionButtons() {
|
||||||
|
viewBinding.progressBar.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
if(tinyDB.getInt("defaultScreenId") == 1) { // repos
|
||||||
|
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "repos");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else if(tinyDB.getInt("defaultScreenId") == 2) { // org
|
||||||
|
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "org");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else if(tinyDB.getInt("defaultScreenId") == 3) { // notifications
|
||||||
|
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else if(tinyDB.getInt("defaultScreenId") == 4) { // explore
|
||||||
|
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else if(tinyDB.getInt("defaultScreenId") == 0) { // show options
|
||||||
|
|
||||||
|
viewBinding.noActionFrame.setVisibility(View.VISIBLE);
|
||||||
|
viewBinding.addNewAccountFrame.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
viewBinding.repository.setOnClickListener(repository -> {
|
||||||
|
|
||||||
|
tinyDB.putInt("defaultScreenId", 1);
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "repos");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
|
||||||
|
viewBinding.organization.setOnClickListener(organization -> {
|
||||||
|
|
||||||
|
tinyDB.putInt("defaultScreenId", 2);
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "org");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
|
||||||
|
viewBinding.notification.setOnClickListener(notification -> {
|
||||||
|
|
||||||
|
tinyDB.putInt("defaultScreenId", 3);
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
|
||||||
|
viewBinding.explore.setOnClickListener(explore -> {
|
||||||
|
|
||||||
|
tinyDB.putInt("defaultScreenId", 4);
|
||||||
|
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
|
||||||
|
viewBinding.launchApp2.setOnClickListener(launchApp2 -> {
|
||||||
|
|
||||||
|
tinyDB.putInt("defaultScreenId", 0);
|
||||||
|
ctx.startActivity(mainIntent);
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,36 +3,33 @@ package org.mian.gitnex.activities;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.DatePickerDialog;
|
import android.app.DatePickerDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.DatePicker;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.hendraanggrian.appcompat.socialview.Mention;
|
import org.gitnex.tea4j.models.CreateIssue;
|
||||||
import com.hendraanggrian.appcompat.widget.MentionArrayAdapter;
|
import org.gitnex.tea4j.models.Issues;
|
||||||
import com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView;
|
import org.gitnex.tea4j.models.Milestones;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityEditIssueBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
import org.mian.gitnex.helpers.Constants;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.models.Collaborators;
|
|
||||||
import org.mian.gitnex.models.CreateIssue;
|
|
||||||
import org.mian.gitnex.models.Issues;
|
|
||||||
import org.mian.gitnex.models.Milestones;
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -40,7 +37,6 @@ import java.util.Calendar;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -48,69 +44,74 @@ import retrofit2.Response;
|
|||||||
|
|
||||||
public class EditIssueActivity extends BaseActivity implements View.OnClickListener {
|
public class EditIssueActivity extends BaseActivity implements View.OnClickListener {
|
||||||
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
|
private int resultLimit = Constants.resultLimitOldGiteaInstances;
|
||||||
|
|
||||||
private EditText editIssueTitle;
|
private EditText editIssueTitle;
|
||||||
private SocialAutoCompleteTextView editIssueDescription;
|
private EditText editIssueDescription;
|
||||||
private TextView editIssueDueDate;
|
private TextView editIssueDueDate;
|
||||||
private Button editIssueButton;
|
private Button editIssueButton;
|
||||||
private Spinner editIssueMilestoneSpinner;
|
private AutoCompleteTextView editIssueMilestoneSpinner;
|
||||||
|
|
||||||
private String msState = "open";
|
private String msState = "open";
|
||||||
|
private int milestoneId;
|
||||||
|
|
||||||
List<Milestones> milestonesList = new ArrayList<>();
|
List<Milestones> milestonesList = new ArrayList<>();
|
||||||
private ArrayAdapter<Mention> defaultMentionAdapter;
|
|
||||||
|
|
||||||
@Override
|
private String loginUid;
|
||||||
protected int getLayoutResourceId(){
|
private String instanceToken;
|
||||||
return R.layout.activity_edit_issue;
|
private String repoOwner;
|
||||||
}
|
private String repoName;
|
||||||
|
private int issueIndex;
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
ActivityEditIssueBinding activityEditIssueBinding = ActivityEditIssueBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityEditIssueBinding.getRoot());
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
loginUid = tinyDB.getString("loginUid");
|
||||||
|
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
repoName = parts[1];
|
||||||
final int issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
|
issueIndex = Integer.parseInt(tinyDB.getString("issueNumber"));
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activityEditIssueBinding.close;
|
||||||
editIssueButton = findViewById(R.id.editIssueButton);
|
editIssueButton = activityEditIssueBinding.editIssueButton;
|
||||||
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
TextView toolbar_title = activityEditIssueBinding.toolbarTitle;
|
||||||
editIssueTitle = findViewById(R.id.editIssueTitle);
|
editIssueTitle = activityEditIssueBinding.editIssueTitle;
|
||||||
editIssueDescription = findViewById(R.id.editIssueDescription);
|
editIssueDescription = activityEditIssueBinding.editIssueDescription;
|
||||||
editIssueDueDate = findViewById(R.id.editIssueDueDate);
|
editIssueDueDate = activityEditIssueBinding.editIssueDueDate;
|
||||||
|
|
||||||
// if gitea is 1.12 or higher use the new limit
|
// if gitea is 1.12 or higher use the new limit
|
||||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
|
||||||
|
resultLimit = Constants.resultLimitNewGiteaInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
editIssueTitle.requestFocus();
|
editIssueTitle.requestFocus();
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
imm.showSoftInput(editIssueTitle, InputMethodManager.SHOW_IMPLICIT);
|
imm.showSoftInput(editIssueTitle, InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
|
||||||
defaultMentionAdapter = new MentionArrayAdapter<>(this);
|
editIssueDescription.setOnTouchListener((touchView, motionEvent) -> {
|
||||||
loadCollaboratorsList();
|
|
||||||
|
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||||
|
|
||||||
|
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||||
|
|
||||||
|
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
editIssueMilestoneSpinner = findViewById(R.id.editIssueMilestoneSpinner);
|
editIssueMilestoneSpinner = findViewById(R.id.editIssueMilestoneSpinner);
|
||||||
editIssueMilestoneSpinner.getBackground().setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
|
|
||||||
|
|
||||||
editIssueDescription.setMentionAdapter(defaultMentionAdapter);
|
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
@@ -118,97 +119,30 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
|||||||
editIssueDueDate.setOnClickListener(this);
|
editIssueDueDate.setOnClickListener(this);
|
||||||
editIssueButton.setOnClickListener(this);
|
editIssueButton.setOnClickListener(this);
|
||||||
|
|
||||||
if(!tinyDb.getString("issueNumber").isEmpty()) {
|
if(!tinyDB.getString("issueNumber").isEmpty()) {
|
||||||
|
|
||||||
|
if(tinyDB.getString("issueType").equalsIgnoreCase("Pull")) {
|
||||||
|
|
||||||
if(tinyDb.getString("issueType").equalsIgnoreCase("Pull")) {
|
|
||||||
toolbar_title.setText(getString(R.string.editPrNavHeader, String.valueOf(issueIndex)));
|
toolbar_title.setText(getString(R.string.editPrNavHeader, String.valueOf(issueIndex)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
toolbar_title.setText(getString(R.string.editIssueNavHeader, String.valueOf(issueIndex)));
|
toolbar_title.setText(getString(R.string.editIssueNavHeader, String.valueOf(issueIndex)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
getIssue(instanceUrl, instanceToken, loginUid, repoOwner, repoName, issueIndex, resultLimit);
|
getIssue(instanceToken, loginUid, repoOwner, repoName, issueIndex, resultLimit);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadCollaboratorsList() {
|
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
|
|
||||||
Call<List<Collaborators>> call = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Collaborators>>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
|
|
||||||
|
|
||||||
if (response.isSuccessful()) {
|
|
||||||
|
|
||||||
assert response.body() != null;
|
|
||||||
String fullName = "";
|
|
||||||
for (int i = 0; i < response.body().size(); i++) {
|
|
||||||
if(!response.body().get(i).getFull_name().equals("")) {
|
|
||||||
fullName = response.body().get(i).getFull_name();
|
|
||||||
}
|
|
||||||
defaultMentionAdapter.add(
|
|
||||||
new Mention(response.body().get(i).getUsername(), fullName, response.body().get(i).getAvatar_url()));
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
Log.i("onResponse", String.valueOf(response.code()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
|
|
||||||
Log.i("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
onClickListener = new View.OnClickListener() {
|
|
||||||
@Override
|
onClickListener = view -> finish();
|
||||||
public void onClick(View view) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processEditIssue() {
|
private void processEditIssue() {
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
final int issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
|
|
||||||
|
|
||||||
Milestones mModel = (Milestones) editIssueMilestoneSpinner.getSelectedItem();
|
|
||||||
|
|
||||||
int editIssueMilestoneId = mModel.getId();
|
|
||||||
|
|
||||||
String editIssueTitleForm = editIssueTitle.getText().toString();
|
String editIssueTitleForm = editIssueTitle.getText().toString();
|
||||||
String editIssueDescriptionForm = editIssueDescription.getText().toString();
|
String editIssueDescriptionForm = editIssueDescription.getText().toString();
|
||||||
@@ -218,45 +152,34 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
|||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editIssueTitleForm.equals("")) {
|
if (editIssueTitleForm.equals("")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.issueTitleEmpty));
|
Toasty.error(ctx, getString(R.string.issueTitleEmpty));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if (editIssueDescriptionForm.equals("")) {
|
|
||||||
|
|
||||||
Toasty.info(ctx, getString(R.string.issueDescriptionEmpty));
|
|
||||||
return;
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (editIssueDueDateForm.equals("")) {
|
if (editIssueDueDateForm.equals("")) {
|
||||||
|
|
||||||
editIssueDueDateForm = null;
|
editIssueDueDateForm = null;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
editIssueDueDateForm = (AppUtil.customDateCombine(AppUtil.customDateFormat(editIssueDueDateForm)));
|
editIssueDueDateForm = (AppUtil.customDateCombine(AppUtil.customDateFormat(editIssueDueDateForm)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Log.i("editIssueDueDateForm", String.valueOf(editIssueDueDateForm));
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
editIssue(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid, editIssueTitleForm, editIssueDescriptionForm, editIssueDueDateForm, editIssueMilestoneId);
|
editIssue(instanceToken, repoOwner, repoName, issueIndex, loginUid, editIssueTitleForm, editIssueDescriptionForm, editIssueDueDateForm, milestoneId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void editIssue(String instanceUrl, String instanceToken, String repoOwner, String repoName, int issueIndex, String loginUid, String title, String description, String dueDate, int editIssueMilestoneId) {
|
private void editIssue(String instanceToken, String repoOwner, String repoName, int issueIndex, String loginUid, String title, String description, String dueDate, int milestoneId) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
CreateIssue issueData = new CreateIssue(title, description, dueDate, milestoneId);
|
||||||
|
|
||||||
CreateIssue issueData = new CreateIssue(title, description, dueDate, editIssueMilestoneId);
|
|
||||||
|
|
||||||
Call<JsonElement> call = RetrofitClient
|
Call<JsonElement> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
.patchIssue(Authorization.get(ctx), repoOwner, repoName, issueIndex, issueData);
|
||||||
.patchIssue(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, issueData);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
@@ -265,17 +188,18 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
|||||||
|
|
||||||
if(response.code() == 201) {
|
if(response.code() == 201) {
|
||||||
|
|
||||||
if(tinyDb.getString("issueType").equalsIgnoreCase("Pull")) {
|
if(tinyDB.getString("issueType").equalsIgnoreCase("Pull")) {
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.editPrSuccessMessage));
|
Toasty.success(ctx, getString(R.string.editPrSuccessMessage));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.editIssueSuccessMessage));
|
Toasty.success(ctx, getString(R.string.editIssueSuccessMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
tinyDb.putBoolean("issueEdited", true);
|
tinyDB.putBoolean("issueEdited", true);
|
||||||
tinyDb.putBoolean("resumeIssues", true);
|
tinyDB.putBoolean("resumeIssues", true);
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
@@ -284,19 +208,17 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
|||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.error(ctx, getString(R.string.genericError));
|
Toasty.error(ctx, getString(R.string.genericError));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
}
|
}
|
||||||
@@ -304,7 +226,6 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
@@ -316,31 +237,21 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
|||||||
final int mDay = c.get(Calendar.DAY_OF_MONTH);
|
final int mDay = c.get(Calendar.DAY_OF_MONTH);
|
||||||
|
|
||||||
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
|
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
|
||||||
new DatePickerDialog.OnDateSetListener() {
|
(view, year, monthOfYear, dayOfMonth) -> editIssueDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth)), mYear, mMonth, mDay);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDateSet(DatePicker view, int year,
|
|
||||||
int monthOfYear, int dayOfMonth) {
|
|
||||||
|
|
||||||
editIssueDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth));
|
|
||||||
|
|
||||||
}
|
|
||||||
}, mYear, mMonth, mDay);
|
|
||||||
datePickerDialog.show();
|
datePickerDialog.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(v == editIssueButton) {
|
else if(v == editIssueButton) {
|
||||||
|
|
||||||
processEditIssue();
|
processEditIssue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getIssue(final String instanceUrl, final String instanceToken, final String loginUid, final String repoOwner, final String repoName, int issueIndex, int resultLimit) {
|
private void getIssue(final String instanceToken, final String loginUid, final String repoOwner, final String repoName, int issueIndex, int resultLimit) {
|
||||||
|
|
||||||
Call<Issues> call = RetrofitClient
|
Call<Issues> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
.getIssueByIndex(Authorization.get(ctx), repoOwner, repoName, issueIndex);
|
||||||
.getIssueByIndex(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<Issues>() {
|
call.enqueue(new Callback<Issues>() {
|
||||||
|
|
||||||
@@ -353,27 +264,27 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
|||||||
editIssueTitle.setText(response.body().getTitle());
|
editIssueTitle.setText(response.body().getTitle());
|
||||||
editIssueDescription.setText(response.body().getBody());
|
editIssueDescription.setText(response.body().getBody());
|
||||||
|
|
||||||
int msId = 0;
|
int currentMilestoneId = 0;
|
||||||
if(response.body().getMilestone() != null) {
|
if(response.body().getMilestone() != null) {
|
||||||
msId = response.body().getMilestone().getId();
|
|
||||||
|
currentMilestoneId = response.body().getMilestone().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
// get milestones list
|
// get milestones list
|
||||||
if(response.body().getId() > 0) {
|
if(response.body().getId() > 0) {
|
||||||
|
|
||||||
Call<List<Milestones>> call_ = RetrofitClient
|
Call<List<Milestones>> call_ = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
.getMilestones(Authorization.get(ctx), repoOwner, repoName, 1, resultLimit, msState);
|
||||||
.getMilestones(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, 1, resultLimit, msState);
|
|
||||||
|
|
||||||
final int finalMsId = msId;
|
int checkMilestoneId = currentMilestoneId;
|
||||||
|
|
||||||
call_.enqueue(new Callback<List<Milestones>>() {
|
call_.enqueue(new Callback<List<Milestones>>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<List<Milestones>> call, @NonNull retrofit2.Response<List<Milestones>> response_) {
|
public void onResponse(@NonNull Call<List<Milestones>> call, @NonNull retrofit2.Response<List<Milestones>> response_) {
|
||||||
|
|
||||||
int finalMsId1 = 0;
|
int getSelectedMilestoneId = 0;
|
||||||
|
|
||||||
if (response_.code() == 200) {
|
if (response_.code() == 200) {
|
||||||
|
|
||||||
@@ -381,39 +292,40 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
|||||||
|
|
||||||
milestonesList.add(new Milestones(0, "No milestone"));
|
milestonesList.add(new Milestones(0, "No milestone"));
|
||||||
assert milestonesList_ != null;
|
assert milestonesList_ != null;
|
||||||
|
|
||||||
if (milestonesList_.size() > 0) {
|
if (milestonesList_.size() > 0) {
|
||||||
|
|
||||||
|
milestonesList.addAll(milestonesList_);
|
||||||
|
|
||||||
for (int i = 0; i < milestonesList_.size(); i++) {
|
for (int i = 0; i < milestonesList_.size(); i++) {
|
||||||
|
|
||||||
Milestones data = new Milestones(
|
if(checkMilestoneId == milestonesList_.get(i).getId()) {
|
||||||
milestonesList_.get(i).getId(),
|
getSelectedMilestoneId = i + 1;
|
||||||
milestonesList_.get(i).getTitle()
|
|
||||||
);
|
|
||||||
milestonesList.add(data);
|
|
||||||
|
|
||||||
if(finalMsId == milestonesList_.get(i).getId()) {
|
|
||||||
finalMsId1 = i + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayAdapter<Milestones> adapter_ = new ArrayAdapter<>(EditIssueActivity.this,
|
ArrayAdapter<Milestones> adapter = new ArrayAdapter<>(EditIssueActivity.this,
|
||||||
R.layout.spinner_item, milestonesList);
|
R.layout.list_spinner_items, milestonesList);
|
||||||
|
|
||||||
adapter_.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
editIssueMilestoneSpinner.setAdapter(adapter);
|
||||||
editIssueMilestoneSpinner.setAdapter(adapter_);
|
|
||||||
|
editIssueMilestoneSpinner.setOnItemClickListener ((parent, view, position, id) -> milestoneId = milestonesList.get(position).getId());
|
||||||
|
|
||||||
|
int finalMsId = getSelectedMilestoneId;
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
|
|
||||||
|
editIssueMilestoneSpinner.setText(milestonesList.get(finalMsId).getTitle(),false);
|
||||||
|
milestoneId = milestonesList.get(finalMsId).getId();
|
||||||
|
}, 500);
|
||||||
|
|
||||||
if(milestonesList_.size() > 0) {
|
|
||||||
editIssueMilestoneSpinner.setSelection(finalMsId1);
|
|
||||||
}
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<List<Milestones>> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<List<Milestones>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -441,11 +353,11 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
|||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.genericError));
|
Toasty.error(ctx, getString(R.string.genericError));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<Issues> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<Issues> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,30 +1,28 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import org.gitnex.tea4j.models.FileDiffView;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.adapters.FilesDiffAdapter;
|
import org.mian.gitnex.adapters.FilesDiffAdapter;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityFileDiffBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.ParseDiff;
|
import org.mian.gitnex.helpers.ParseDiff;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.models.FileDiffView;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -36,36 +34,28 @@ public class FileDiffActivity extends BaseActivity {
|
|||||||
private TextView toolbarTitle;
|
private TextView toolbarTitle;
|
||||||
private ListView mListView;
|
private ListView mListView;
|
||||||
private ProgressBar mProgressBar;
|
private ProgressBar mProgressBar;
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_file_diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
ActivityFileDiffBinding activityFileDiffBinding = ActivityFileDiffBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityFileDiffBinding.getRoot());
|
||||||
|
|
||||||
|
Toolbar toolbar = activityFileDiffBinding.toolbar;
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activityFileDiffBinding.close;
|
||||||
toolbarTitle = findViewById(R.id.toolbar_title);
|
toolbarTitle = activityFileDiffBinding.toolbarTitle;
|
||||||
mListView = findViewById(R.id.listView);
|
mListView = activityFileDiffBinding.listView;
|
||||||
mProgressBar = findViewById(R.id.progress_bar);
|
mProgressBar = activityFileDiffBinding.progressBar;
|
||||||
|
|
||||||
mListView.setDivider(null);
|
mListView.setDivider(null);
|
||||||
|
|
||||||
@@ -77,92 +67,70 @@ public class FileDiffActivity extends BaseActivity {
|
|||||||
|
|
||||||
String pullIndex = tinyDb.getString("issueNumber");
|
String pullIndex = tinyDb.getString("issueNumber");
|
||||||
|
|
||||||
boolean apiCall = true;
|
boolean apiCall = !new Version(tinyDb.getString("giteaVersion")).less("1.13.0");
|
||||||
String instanceUrl = tinyDb.getString("instanceUrl");
|
getPullDiffContent(repoOwner, repoName, pullIndex, apiCall);
|
||||||
|
|
||||||
// fallback for old gitea instances
|
|
||||||
if(new Version(tinyDb.getString("giteaVersion")).less("1.13.0")) {
|
|
||||||
|
|
||||||
apiCall = false;
|
|
||||||
instanceUrl = instanceUrl.substring(0, instanceUrl.lastIndexOf("api/v1/"));
|
|
||||||
}
|
|
||||||
|
|
||||||
getPullDiffContent(instanceUrl, repoOwner, repoName, pullIndex, instanceToken, apiCall);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getPullDiffContent(String instanceUrl, String owner, String repo, String pullIndex, String token, boolean apiCall) {
|
private void getPullDiffContent(String owner, String repo, String pullIndex, boolean apiCall) {
|
||||||
|
|
||||||
Call<ResponseBody> call;
|
Thread thread = new Thread(() -> {
|
||||||
if(apiCall) {
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getPullDiffContent(token, owner, repo, pullIndex);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getWebInterface().getPullDiffContent(owner, repo, pullIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
call.enqueue(new Callback<ResponseBody>() {
|
Call<ResponseBody> call = apiCall ?
|
||||||
|
RetrofitClient.getApiInterface(ctx).getPullDiffContent(Authorization.get(ctx), owner, repo, pullIndex) :
|
||||||
|
RetrofitClient.getWebInterface(ctx).getPullDiffContent(Authorization.getWeb(ctx), owner, repo, pullIndex);
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull retrofit2.Response<ResponseBody> response) {
|
|
||||||
|
|
||||||
if(response.code() == 200) {
|
Response<ResponseBody> response = call.execute();
|
||||||
|
assert response.body() != null;
|
||||||
|
|
||||||
try {
|
switch(response.code()) {
|
||||||
assert response.body() != null;
|
|
||||||
|
|
||||||
AppUtil appUtil = new AppUtil();
|
case 200:
|
||||||
List<FileDiffView> fileContentsArray = ParseDiff.getFileDiffViewArray(response.body().string());
|
List<FileDiffView> fileDiffViews = ParseDiff.getFileDiffViewArray(response.body().string());
|
||||||
|
|
||||||
int filesCount = fileContentsArray.size();
|
int filesCount = fileDiffViews.size();
|
||||||
if(filesCount > 1) {
|
|
||||||
toolbarTitle.setText(getResources().getString(R.string.fileDiffViewHeader, Integer.toString(filesCount)));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
toolbarTitle.setText(getResources().getString(R.string.fileDiffViewHeaderSingle, Integer.toString(filesCount)));
|
|
||||||
}
|
|
||||||
|
|
||||||
FilesDiffAdapter adapter = new FilesDiffAdapter(ctx, fileContentsArray);
|
String toolbarTitleText = (filesCount > 1) ?
|
||||||
mListView.setAdapter(adapter);
|
getResources().getString(R.string.fileDiffViewHeader, Integer.toString(filesCount)) :
|
||||||
|
getResources().getString(R.string.fileDiffViewHeaderSingle, Integer.toString(filesCount));
|
||||||
|
|
||||||
mProgressBar.setVisibility(View.GONE);
|
FilesDiffAdapter adapter = new FilesDiffAdapter(ctx, getSupportFragmentManager(), fileDiffViews);
|
||||||
|
|
||||||
}
|
runOnUiThread(() -> {
|
||||||
catch(IOException e) {
|
toolbarTitle.setText(toolbarTitleText);
|
||||||
e.printStackTrace();
|
mListView.setAdapter(adapter);
|
||||||
}
|
mProgressBar.setVisibility(View.GONE);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 401:
|
||||||
|
runOnUiThread(() -> AlertDialogs.authorizationTokenRevokedDialog(ctx,
|
||||||
|
getString(R.string.alertDialogTokenRevokedTitle),
|
||||||
|
getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
|
getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
|
getString(R.string.alertDialogTokenRevokedCopyPositiveButton)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 403:
|
||||||
|
runOnUiThread(() -> Toasty.error(ctx, ctx.getString(R.string.authorizeError)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 404:
|
||||||
|
runOnUiThread(() -> Toasty.warning(ctx, ctx.getString(R.string.apiNotFound)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
runOnUiThread(() -> Toasty.error(ctx, getString(R.string.labelGeneralError)));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
} catch(IOException ignored) {}
|
||||||
|
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 403) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 404) {
|
|
||||||
|
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
|
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
thread.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
@@ -171,8 +139,8 @@ public class FileDiffActivity extends BaseActivity {
|
|||||||
|
|
||||||
getIntent().removeExtra("singleFileName");
|
getIntent().removeExtra("singleFileName");
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,68 +1,41 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Spanned;
|
|
||||||
import android.text.method.ScrollingMovementMethod;
|
import android.text.method.ScrollingMovementMethod;
|
||||||
import android.util.Base64;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
import android.widget.LinearLayout;
|
import androidx.activity.result.contract.ActivityResultContracts;
|
||||||
import android.widget.ProgressBar;
|
import androidx.core.app.NotificationCompat;
|
||||||
import android.widget.TextView;
|
import com.vdurmont.emoji.EmojiParser;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
|
||||||
import com.github.barteksc.pdfviewer.PDFView;
|
|
||||||
import com.github.barteksc.pdfviewer.util.FitPolicy;
|
|
||||||
import com.github.chrisbanes.photoview.PhotoView;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.gitnex.tea4j.models.Files;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityFileViewBinding;
|
||||||
import org.mian.gitnex.fragments.BottomSheetFileViewerFragment;
|
import org.mian.gitnex.fragments.BottomSheetFileViewerFragment;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
|
import org.mian.gitnex.helpers.Constants;
|
||||||
|
import org.mian.gitnex.helpers.Images;
|
||||||
|
import org.mian.gitnex.helpers.Markdown;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.highlightjs.HighlightJsView;
|
import org.mian.gitnex.notifications.Notifications;
|
||||||
import org.mian.gitnex.helpers.highlightjs.models.Theme;
|
|
||||||
import org.mian.gitnex.models.Files;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.util.Arrays;
|
||||||
import java.net.URLDecoder;
|
import okhttp3.ResponseBody;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Objects;
|
|
||||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
|
||||||
import io.noties.markwon.Markwon;
|
|
||||||
import io.noties.markwon.core.CorePlugin;
|
|
||||||
import io.noties.markwon.core.MarkwonTheme;
|
|
||||||
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
|
||||||
import io.noties.markwon.ext.tables.TablePlugin;
|
|
||||||
import io.noties.markwon.ext.tasklist.TaskListPlugin;
|
|
||||||
import io.noties.markwon.html.HtmlPlugin;
|
|
||||||
import io.noties.markwon.image.DefaultMediaDecoder;
|
|
||||||
import io.noties.markwon.image.ImageItem;
|
|
||||||
import io.noties.markwon.image.ImagesPlugin;
|
|
||||||
import io.noties.markwon.image.SchemeHandler;
|
|
||||||
import io.noties.markwon.image.gif.GifMediaDecoder;
|
|
||||||
import io.noties.markwon.image.svg.SvgMediaDecoder;
|
|
||||||
import io.noties.markwon.linkify.LinkifyPlugin;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -70,87 +43,35 @@ import retrofit2.Callback;
|
|||||||
|
|
||||||
public class FileViewActivity extends BaseActivity implements BottomSheetFileViewerFragment.BottomSheetListener {
|
public class FileViewActivity extends BaseActivity implements BottomSheetFileViewerFragment.BottomSheetListener {
|
||||||
|
|
||||||
private View.OnClickListener onClickListener;
|
private ActivityFileViewBinding binding;
|
||||||
private TextView singleFileContents;
|
private Files file;
|
||||||
private LinearLayout singleFileContentsFrame;
|
|
||||||
private HighlightJsView singleCodeContents;
|
|
||||||
private PhotoView imageView;
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private ProgressBar mProgressBar;
|
|
||||||
private byte[] imageData;
|
|
||||||
private PDFView pdfView;
|
|
||||||
private LinearLayout pdfViewFrame;
|
|
||||||
private byte[] decodedPdf;
|
|
||||||
private Boolean pdfNightMode;
|
|
||||||
private String singleFileName;
|
|
||||||
private String fileSha;
|
|
||||||
private AppUtil appUtil;
|
|
||||||
private TinyDB tinyDb;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_file_view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
appUtil = new AppUtil();
|
|
||||||
tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
binding = ActivityFileViewBinding.inflate(getLayoutInflater());
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
setContentView(binding.getRoot());
|
||||||
String repoBranch = tinyDb.getString("repoBranch");
|
setSupportActionBar(binding.toolbar);
|
||||||
|
|
||||||
|
tinyDB.putBoolean("enableMarkdownInFileView", false);
|
||||||
|
|
||||||
|
file = (Files) getIntent().getSerializableExtra("file");
|
||||||
|
|
||||||
|
binding.close.setOnClickListener(view -> finish());
|
||||||
|
|
||||||
|
binding.toolbarTitle.setMovementMethod(new ScrollingMovementMethod());
|
||||||
|
binding.toolbarTitle.setText(file.getPath());
|
||||||
|
|
||||||
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
|
String repoBranch = tinyDB.getString("repoBranch");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
String repoName = parts[1];
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
tinyDb.putBoolean("enableMarkdownInFileView", false);
|
getSingleFileContents(repoOwner, repoName, file.getPath(), repoBranch);
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
|
||||||
singleFileContents = findViewById(R.id.singleFileContents);
|
|
||||||
singleCodeContents = findViewById(R.id.singleCodeContents);
|
|
||||||
imageView = findViewById(R.id.imageView);
|
|
||||||
mProgressBar = findViewById(R.id.progress_bar);
|
|
||||||
pdfView = findViewById(R.id.pdfView);
|
|
||||||
pdfViewFrame = findViewById(R.id.pdfViewFrame);
|
|
||||||
singleFileContentsFrame = findViewById(R.id.singleFileContentsFrame);
|
|
||||||
|
|
||||||
singleFileName = getIntent().getStringExtra("singleFileName");
|
|
||||||
|
|
||||||
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
|
||||||
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
|
|
||||||
|
|
||||||
initCloseListener();
|
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
|
||||||
|
|
||||||
tinyDb.putString("downloadFileContents", "");
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
singleFileName = URLDecoder.decode(singleFileName, "UTF-8");
|
|
||||||
singleFileName = singleFileName.replaceAll("//", "/");
|
|
||||||
singleFileName = singleFileName.startsWith("/") ? singleFileName.substring(1) : singleFileName;
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(UnsupportedEncodingException e) {
|
|
||||||
|
|
||||||
Log.i("singleFileName", singleFileName);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
toolbar_title.setText(singleFileName);
|
|
||||||
|
|
||||||
getSingleFileContents(instanceUrl, instanceToken, repoOwner, repoName, singleFileName, repoBranch);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,161 +80,143 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
|||||||
|
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
if(tinyDB.getBoolean("fileModified")) {
|
||||||
String repoBranch = tinyDb.getString("repoBranch");
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String repoBranch = tinyDB.getString("repoBranch");
|
||||||
String repoOwner = parts[0];
|
String[] parts = repoFullName.split("/");
|
||||||
String repoName = parts[1];
|
String repoOwner = parts[0];
|
||||||
String instanceUrl = tinyDb.getString("instanceUrl");
|
String repoName = parts[1];
|
||||||
String loginUid = tinyDb.getString("loginUid");
|
|
||||||
String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
if(tinyDb.getBoolean("fileModified")) {
|
getSingleFileContents(repoOwner, repoName, file.getPath(), repoBranch);
|
||||||
getSingleFileContents(instanceUrl, instanceToken, repoOwner, repoName, singleFileName, repoBranch);
|
tinyDB.putBoolean("fileModified", false);
|
||||||
tinyDb.putBoolean("fileModified", false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getSingleFileContents(final String owner, String repo, final String filename, String ref) {
|
||||||
|
|
||||||
private void getSingleFileContents(String instanceUrl, String token, final String owner, String repo, final String filename, String ref) {
|
Thread thread = new Thread(() -> {
|
||||||
|
|
||||||
Call<Files> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getSingleFileContents(token, owner, repo, filename, ref);
|
Call<ResponseBody> call = RetrofitClient
|
||||||
|
.getWebInterface(ctx)
|
||||||
|
.getFileContents(Authorization.getWeb(ctx), owner, repo, ref, filename);
|
||||||
|
|
||||||
call.enqueue(new Callback<Files>() {
|
try {
|
||||||
|
|
||||||
@Override
|
Response<ResponseBody> response = call.execute();
|
||||||
public void onResponse(@NonNull Call<Files> call, @NonNull retrofit2.Response<Files> response) {
|
|
||||||
|
|
||||||
if(response.code() == 200) {
|
if(response.code() == 200) {
|
||||||
|
|
||||||
assert response.body() != null;
|
ResponseBody responseBody = response.body();
|
||||||
|
|
||||||
if(!response.body().getContent().equals("")) {
|
if(responseBody != null) {
|
||||||
|
|
||||||
|
runOnUiThread(() -> binding.progressBar.setVisibility(View.GONE));
|
||||||
String fileExtension = FileUtils.getExtension(filename);
|
String fileExtension = FileUtils.getExtension(filename);
|
||||||
mProgressBar.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
fileSha = response.body().getSha();
|
boolean processable = false;
|
||||||
|
|
||||||
// download file meta
|
switch(AppUtil.getFileType(fileExtension)) {
|
||||||
tinyDb.putString("downloadFileName", filename);
|
|
||||||
tinyDb.putString("downloadFileContents", response.body().getContent());
|
|
||||||
|
|
||||||
if(appUtil.imageExtension(fileExtension)) { // file is image
|
case IMAGE:
|
||||||
|
|
||||||
singleFileContentsFrame.setVisibility(View.GONE);
|
// See https://developer.android.com/guide/topics/media/media-formats#core
|
||||||
singleCodeContents.setVisibility(View.GONE);
|
if(Arrays.asList("bmp", "gif", "jpg", "jpeg", "png", "webp", "heic", "heif").contains(fileExtension.toLowerCase())) {
|
||||||
pdfViewFrame.setVisibility(View.GONE);
|
|
||||||
imageView.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
imageData = Base64.decode(response.body().getContent(), Base64.DEFAULT);
|
processable = true;
|
||||||
Drawable imageDrawable = new BitmapDrawable(getResources(), BitmapFactory.decodeByteArray(imageData, 0, imageData.length));
|
|
||||||
imageView.setImageDrawable(imageDrawable);
|
byte[] pictureBytes = responseBody.bytes();
|
||||||
|
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
binding.contents.setVisibility(View.GONE);
|
||||||
|
binding.markdownFrame.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
binding.photoView.setVisibility(View.VISIBLE);
|
||||||
|
binding.photoView.setImageBitmap(Images.scaleImage(pictureBytes, 1920));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UNKNOWN:
|
||||||
|
case TEXT:
|
||||||
|
|
||||||
|
if(file.getSize() > Constants.maximumFileViewerSize) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
processable = true;
|
||||||
|
String text = responseBody.string();
|
||||||
|
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
binding.photoView.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
binding.contents.setContent(text, fileExtension);
|
||||||
|
|
||||||
|
if(tinyDB.getBoolean("enableMarkdownInFileView")) {
|
||||||
|
Markdown.render(ctx, EmojiParser.parseToUnicode(text), binding.markdown);
|
||||||
|
|
||||||
|
binding.contents.setVisibility(View.GONE);
|
||||||
|
binding.markdownFrame.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
binding.markdownFrame.setVisibility(View.GONE);
|
||||||
|
binding.contents.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(appUtil.sourceCodeExtension(fileExtension)) { // file is sourcecode
|
|
||||||
|
|
||||||
imageView.setVisibility(View.GONE);
|
if(!processable) { // While the file could still be non-binary,
|
||||||
singleFileContentsFrame.setVisibility(View.GONE);
|
// it's better we don't show it (to prevent any crashes and/or unwanted behavior) and let the user download it instead.
|
||||||
pdfViewFrame.setVisibility(View.GONE);
|
responseBody.close();
|
||||||
singleCodeContents.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
switch(tinyDb.getInt("fileviewerSourceCodeThemeId")) {
|
runOnUiThread(() -> {
|
||||||
case 1:
|
binding.photoView.setVisibility(View.GONE);
|
||||||
singleCodeContents.setTheme(Theme.ARDUINO_LIGHT);
|
binding.contents.setVisibility(View.GONE);
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
singleCodeContents.setTheme(Theme.GITHUB);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
singleCodeContents.setTheme(Theme.FAR);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
singleCodeContents.setTheme(Theme.IR_BLACK);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
singleCodeContents.setTheme(Theme.ANDROID_STUDIO);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
singleCodeContents.setTheme(Theme.MONOKAI_SUBLIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
singleCodeContents.setSource(appUtil.decodeBase64(response.body().getContent()));
|
|
||||||
|
|
||||||
|
binding.markdownFrame.setVisibility(View.VISIBLE);
|
||||||
|
binding.markdown.setText(getString(R.string.excludeFilesInFileViewer));
|
||||||
|
binding.markdown.setGravity(Gravity.CENTER);
|
||||||
|
binding.markdown.setTypeface(null, Typeface.BOLD);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else if(appUtil.pdfExtension(fileExtension)) { // file is pdf
|
} else {
|
||||||
|
|
||||||
imageView.setVisibility(View.GONE);
|
runOnUiThread(() -> {
|
||||||
singleFileContentsFrame.setVisibility(View.GONE);
|
binding.markdown.setText("");
|
||||||
singleCodeContents.setVisibility(View.GONE);
|
binding.progressBar.setVisibility(View.GONE);
|
||||||
pdfViewFrame.setVisibility(View.VISIBLE);
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
pdfNightMode = tinyDb.getBoolean("enablePdfMode");
|
switch(response.code()) {
|
||||||
|
|
||||||
decodedPdf = Base64.decode(response.body().getContent(), Base64.DEFAULT);
|
case 401:
|
||||||
pdfView.fromBytes(decodedPdf).enableSwipe(true).swipeHorizontal(false).enableDoubletap(true).defaultPage(0).enableAnnotationRendering(false).password(null).scrollHandle(null).enableAntialiasing(true).spacing(0).autoSpacing(true).pageFitPolicy(FitPolicy.WIDTH).fitEachPage(true).pageSnap(false).pageFling(true).nightMode(pdfNightMode).load();
|
runOnUiThread(() -> AlertDialogs.authorizationTokenRevokedDialog(ctx,
|
||||||
|
getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||||
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton)));
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
case 403:
|
||||||
else if(appUtil.excludeFilesInFileViewerExtension(fileExtension)) { // files need to be excluded
|
runOnUiThread(() -> Toasty.error(ctx, ctx.getString(R.string.authorizeError)));
|
||||||
|
break;
|
||||||
|
|
||||||
imageView.setVisibility(View.GONE);
|
case 404:
|
||||||
singleCodeContents.setVisibility(View.GONE);
|
runOnUiThread(() -> Toasty.warning(ctx, ctx.getString(R.string.apiNotFound)));
|
||||||
pdfViewFrame.setVisibility(View.GONE);
|
break;
|
||||||
singleFileContentsFrame.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
singleFileContents.setText(getResources().getString(R.string.excludeFilesInFileviewer));
|
default:
|
||||||
singleFileContents.setGravity(Gravity.CENTER);
|
runOnUiThread(() -> Toasty.error(ctx, getString(R.string.labelGeneralError)));
|
||||||
singleFileContents.setTypeface(null, Typeface.BOLD);
|
|
||||||
|
|
||||||
}
|
|
||||||
else { // file type not known - plain text view
|
|
||||||
|
|
||||||
imageView.setVisibility(View.GONE);
|
|
||||||
singleCodeContents.setVisibility(View.GONE);
|
|
||||||
pdfViewFrame.setVisibility(View.GONE);
|
|
||||||
singleFileContentsFrame.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
singleFileContents.setText(appUtil.decodeBase64(response.body().getContent()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
singleFileContents.setText("");
|
|
||||||
mProgressBar.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
} catch(IOException ignored) {}
|
||||||
|
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 403) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 404) {
|
|
||||||
|
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<Files> call, @NonNull Throwable t) {
|
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
thread.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -323,9 +226,11 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
|||||||
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
||||||
inflater.inflate(R.menu.files_view_menu, menu);
|
inflater.inflate(R.menu.files_view_menu, menu);
|
||||||
|
|
||||||
String fileExtension = FileUtils.getExtension(singleFileName);
|
if(!FileUtils.getExtension(file.getName())
|
||||||
if(!fileExtension.equalsIgnoreCase("md")) {
|
.equalsIgnoreCase("md")) {
|
||||||
menu.getItem(0).setVisible(false);
|
|
||||||
|
menu.getItem(0)
|
||||||
|
.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -336,201 +241,158 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
|||||||
|
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
|
|
||||||
switch(id) {
|
if(id == android.R.id.home) {
|
||||||
case android.R.id.home:
|
|
||||||
|
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
case R.id.genericMenu:
|
|
||||||
|
|
||||||
BottomSheetFileViewerFragment bottomSheet = new BottomSheetFileViewerFragment();
|
} else if(id == R.id.genericMenu) {
|
||||||
bottomSheet.show(getSupportFragmentManager(), "fileViewerBottomSheet");
|
|
||||||
return true;
|
|
||||||
case R.id.markdown:
|
|
||||||
|
|
||||||
final Markwon markwon = Markwon.builder(Objects.requireNonNull(ctx)).usePlugin(CorePlugin.create())
|
BottomSheetFileViewerFragment bottomSheet = new BottomSheetFileViewerFragment();
|
||||||
.usePlugin(ImagesPlugin.create(plugin -> {
|
bottomSheet.show(getSupportFragmentManager(), "fileViewerBottomSheet");
|
||||||
plugin.addSchemeHandler(new SchemeHandler() {
|
return true;
|
||||||
|
|
||||||
@NonNull
|
} else if(id == R.id.markdown) {
|
||||||
@Override
|
|
||||||
public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
|
|
||||||
|
|
||||||
final int resourceId = ctx.getResources().getIdentifier(
|
if(!tinyDB.getBoolean("enableMarkdownInFileView")) {
|
||||||
raw.substring("drawable://".length()),
|
Markdown.render(ctx, EmojiParser.parseToUnicode(binding.contents.getContent()), binding.markdown);
|
||||||
"drawable",
|
|
||||||
ctx.getPackageName());
|
|
||||||
|
|
||||||
final Drawable drawable = ctx.getDrawable(resourceId);
|
binding.contents.setVisibility(View.GONE);
|
||||||
|
binding.markdownFrame.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
assert drawable != null;
|
tinyDB.putBoolean("enableMarkdownInFileView", true);
|
||||||
return ImageItem.withResult(drawable);
|
} else {
|
||||||
}
|
binding.markdownFrame.setVisibility(View.GONE);
|
||||||
|
binding.contents.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
@NonNull
|
tinyDB.putBoolean("enableMarkdownInFileView", false);
|
||||||
@Override
|
}
|
||||||
public Collection<String> supportedSchemes() {
|
|
||||||
|
|
||||||
return Collections.singleton("drawable");
|
return true;
|
||||||
}
|
|
||||||
});
|
|
||||||
plugin.placeholderProvider(drawable -> null);
|
|
||||||
plugin.addMediaDecoder(GifMediaDecoder.create(false));
|
|
||||||
plugin.addMediaDecoder(SvgMediaDecoder.create(ctx.getResources()));
|
|
||||||
plugin.addMediaDecoder(SvgMediaDecoder.create());
|
|
||||||
plugin.defaultMediaDecoder(DefaultMediaDecoder.create(ctx.getResources()));
|
|
||||||
plugin.defaultMediaDecoder(DefaultMediaDecoder.create());
|
|
||||||
}))
|
|
||||||
.usePlugin(new AbstractMarkwonPlugin() {
|
|
||||||
@Override
|
|
||||||
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
|
|
||||||
|
|
||||||
builder.codeTextColor(tinyDb.getInt("codeBlockColor")).codeBackgroundColor(tinyDb.getInt("codeBlockBackground"))
|
} else {
|
||||||
.linkColor(getResources().getColor(R.color.lightBlue));
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
|
||||||
})
|
|
||||||
.usePlugin(TablePlugin.create(ctx))
|
|
||||||
.usePlugin(TaskListPlugin.create(ctx))
|
|
||||||
.usePlugin(HtmlPlugin.create())
|
|
||||||
.usePlugin(StrikethroughPlugin.create())
|
|
||||||
.usePlugin(LinkifyPlugin.create())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
if(!tinyDb.getBoolean("enableMarkdownInFileView")) {
|
|
||||||
|
|
||||||
singleCodeContents.setVisibility(View.GONE);
|
|
||||||
singleFileContentsFrame.setVisibility(View.VISIBLE);
|
|
||||||
singleFileContents.setVisibility(View.VISIBLE);
|
|
||||||
Spanned bodyWithMD = markwon.toMarkdown(appUtil.decodeBase64(tinyDb.getString("downloadFileContents")));
|
|
||||||
markwon.setParsedMarkdown(singleFileContents, bodyWithMD);
|
|
||||||
tinyDb.putBoolean("enableMarkdownInFileView", true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
singleCodeContents.setVisibility(View.VISIBLE);
|
|
||||||
singleFileContentsFrame.setVisibility(View.GONE);
|
|
||||||
singleFileContents.setVisibility(View.GONE);
|
|
||||||
singleCodeContents.setSource(appUtil.decodeBase64(tinyDb.getString("downloadFileContents")));
|
|
||||||
tinyDb.putBoolean("enableMarkdownInFileView", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onButtonClicked(String text) {
|
public void onButtonClicked(String text) {
|
||||||
|
|
||||||
if("downloadFile".equals(text)) {
|
if("downloadFile".equals(text)) {
|
||||||
|
|
||||||
requestFileDownload();
|
requestFileDownload();
|
||||||
}
|
}
|
||||||
|
|
||||||
if("deleteFile".equals(text)) {
|
if("deleteFile".equals(text)) {
|
||||||
|
|
||||||
String fileExtension = FileUtils.getExtension(singleFileName);
|
|
||||||
String data = appUtil.decodeBase64(tinyDb.getString("downloadFileContents"));
|
|
||||||
Intent intent = new Intent(ctx, CreateFileActivity.class);
|
Intent intent = new Intent(ctx, CreateFileActivity.class);
|
||||||
intent.putExtra("fileAction", 1);
|
intent.putExtra("fileAction", CreateFileActivity.FILE_ACTION_DELETE);
|
||||||
intent.putExtra("filePath", singleFileName);
|
intent.putExtra("filePath", file.getPath());
|
||||||
intent.putExtra("fileSha", fileSha);
|
intent.putExtra("fileSha", file.getSha());
|
||||||
if(!appUtil.imageExtension(fileExtension)) {
|
|
||||||
intent.putExtra("fileContents", data);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
intent.putExtra("fileContents", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.startActivity(intent);
|
ctx.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if("editFile".equals(text)) {
|
if("editFile".equals(text)) {
|
||||||
|
|
||||||
String fileExtension = FileUtils.getExtension(singleFileName);
|
if(binding.contents.getContent() != null &&
|
||||||
String data = appUtil.decodeBase64(tinyDb.getString("downloadFileContents"));
|
!binding.contents.getContent().isEmpty()) {
|
||||||
Intent intent = new Intent(ctx, CreateFileActivity.class);
|
|
||||||
intent.putExtra("fileAction", 2);
|
|
||||||
intent.putExtra("filePath", singleFileName);
|
|
||||||
intent.putExtra("fileSha", fileSha);
|
|
||||||
if(!appUtil.imageExtension(fileExtension)) {
|
|
||||||
intent.putExtra("fileContents", data);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
intent.putExtra("fileContents", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.startActivity(intent);
|
Intent intent = new Intent(ctx, CreateFileActivity.class);
|
||||||
|
|
||||||
|
intent.putExtra("fileAction", CreateFileActivity.FILE_ACTION_EDIT);
|
||||||
|
intent.putExtra("filePath", file.getPath());
|
||||||
|
intent.putExtra("fileSha", file.getSha());
|
||||||
|
intent.putExtra("fileContents", binding.contents.getContent());
|
||||||
|
|
||||||
|
ctx.startActivity(intent);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Toasty.error(ctx, getString(R.string.fileTypeCannotBeEdited));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestFileDownload() {
|
private void requestFileDownload() {
|
||||||
|
|
||||||
if(!tinyDb.getString("downloadFileContents").isEmpty()) {
|
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
||||||
|
|
||||||
int CREATE_REQUEST_CODE = 40;
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
|
intent.putExtra(Intent.EXTRA_TITLE, file.getName());
|
||||||
|
intent.setType("*/*");
|
||||||
|
|
||||||
File outputFileName = new File(tinyDb.getString("downloadFileName"));
|
activityResultLauncher.launch(intent);
|
||||||
|
|
||||||
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
|
||||||
|
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
||||||
intent.setType("*/*");
|
|
||||||
intent.putExtra(Intent.EXTRA_TITLE, outputFileName.getName());
|
|
||||||
|
|
||||||
startActivityForResult(intent, CREATE_REQUEST_CODE);
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Toasty.warning(ctx, getString(R.string.waitLoadingDownloadFile));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
ActivityResultLauncher<Intent> activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
||||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
||||||
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
if (result.getResultCode() == Activity.RESULT_OK) {
|
||||||
|
|
||||||
if(requestCode == 40 && resultCode == RESULT_OK) {
|
assert result.getData() != null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
assert data != null;
|
OutputStream outputStream = getContentResolver().openOutputStream(result.getData().getData());
|
||||||
Uri uri = data.getData();
|
|
||||||
|
|
||||||
assert uri != null;
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, ctx.getPackageName())
|
||||||
OutputStream outputStream = getContentResolver().openOutputStream(uri);
|
.setContentTitle(getString(R.string.fileViewerNotificationTitleStarted))
|
||||||
|
.setContentText(getString(R.string.fileViewerNotificationDescriptionStarted, file.getName()))
|
||||||
|
.setSmallIcon(R.drawable.gitnex_transparent)
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||||
|
.setChannelId(Constants.downloadNotificationChannelId)
|
||||||
|
.setProgress(100, 0, false)
|
||||||
|
.setOngoing(true);
|
||||||
|
|
||||||
byte[] dataAsBytes = Base64.decode(tinyDb.getString("downloadFileContents"), 0);
|
int notificationId = Notifications.uniqueNotificationId(ctx);
|
||||||
|
|
||||||
assert outputStream != null;
|
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);;
|
||||||
outputStream.write(dataAsBytes);
|
notificationManager.notify(notificationId, builder.build());
|
||||||
outputStream.close();
|
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.downloadFileSaved));
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
|
String repoBranch = tinyDB.getString("repoBranch");
|
||||||
|
String[] parts = repoFullName.split("/");
|
||||||
|
String repoOwner = parts[0];
|
||||||
|
String repoName = parts[1];
|
||||||
|
|
||||||
}
|
Thread thread = new Thread(() -> {
|
||||||
catch(IOException e) {
|
|
||||||
|
|
||||||
Log.e("errorFileDownloading", Objects.requireNonNull(e.getMessage()));
|
try {
|
||||||
}
|
|
||||||
|
|
||||||
|
Call<ResponseBody> call = RetrofitClient
|
||||||
|
.getWebInterface(ctx)
|
||||||
|
.getFileContents(Authorization.getWeb(ctx), repoOwner, repoName, repoBranch, file.getPath());
|
||||||
|
|
||||||
|
Response<ResponseBody> response = call.execute();
|
||||||
|
|
||||||
|
assert response.body() != null;
|
||||||
|
|
||||||
|
AppUtil.copyProgress(response.body().byteStream(), outputStream, file.getSize(), progress -> {
|
||||||
|
builder.setProgress(100, progress, false);
|
||||||
|
notificationManager.notify(notificationId, builder.build());
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.setContentTitle(getString(R.string.fileViewerNotificationTitleFinished))
|
||||||
|
.setContentText(getString(R.string.fileViewerNotificationDescriptionFinished, file.getName()));
|
||||||
|
|
||||||
|
} catch(IOException ignored) {
|
||||||
|
|
||||||
|
builder.setContentTitle(getString(R.string.fileViewerNotificationTitleFailed))
|
||||||
|
.setContentText(getString(R.string.fileViewerNotificationDescriptionFailed, file.getName()));
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
builder.setProgress(0,0,false)
|
||||||
|
.setOngoing(false);
|
||||||
|
|
||||||
|
notificationManager.notify(notificationId, builder.build());
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
thread.start();
|
||||||
|
|
||||||
|
} catch(IOException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
});
|
||||||
|
|
||||||
private void initCloseListener() {
|
|
||||||
|
|
||||||
onClickListener = view -> {
|
|
||||||
|
|
||||||
getIntent().removeExtra("singleFileName");
|
|
||||||
finish();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,36 +1,33 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import com.tooltip.Tooltip;
|
import org.gitnex.tea4j.models.GiteaVersion;
|
||||||
|
import org.gitnex.tea4j.models.UserInfo;
|
||||||
|
import org.gitnex.tea4j.models.UserTokens;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.database.api.BaseApi;
|
||||||
import org.mian.gitnex.database.api.UserAccountsApi;
|
import org.mian.gitnex.database.api.UserAccountsApi;
|
||||||
import org.mian.gitnex.database.models.UserAccount;
|
import org.mian.gitnex.database.models.UserAccount;
|
||||||
|
import org.mian.gitnex.databinding.ActivityLoginBinding;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.NetworkObserver;
|
import org.mian.gitnex.helpers.NetworkStatusObserver;
|
||||||
import org.mian.gitnex.helpers.PathsHelper;
|
import org.mian.gitnex.helpers.PathsHelper;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.UrlHelper;
|
import org.mian.gitnex.helpers.UrlHelper;
|
||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.models.GiteaVersion;
|
|
||||||
import org.mian.gitnex.models.UserInfo;
|
|
||||||
import org.mian.gitnex.models.UserTokens;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -50,97 +47,93 @@ public class LoginActivity extends BaseActivity {
|
|||||||
|
|
||||||
private enum LoginType {BASIC, TOKEN}
|
private enum LoginType {BASIC, TOKEN}
|
||||||
|
|
||||||
private Context appCtx;
|
|
||||||
private Context ctx = this;
|
|
||||||
private TinyDB tinyDB;
|
|
||||||
|
|
||||||
private Button loginButton;
|
private Button loginButton;
|
||||||
private EditText instanceUrlET, loginUidET, loginPassword, otpCode, loginTokenCode;
|
private EditText instanceUrlET, loginUidET, loginPassword, otpCode, loginTokenCode;
|
||||||
private Spinner protocolSpinner;
|
private AutoCompleteTextView protocolSpinner;
|
||||||
private TextView otpInfo;
|
|
||||||
private RadioGroup loginMethod;
|
private RadioGroup loginMethod;
|
||||||
private String device_id = "token";
|
private String device_id = "token";
|
||||||
|
private String selectedProtocol;
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_login;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
tinyDB = new TinyDB(appCtx);
|
ActivityLoginBinding activityLoginBinding = ActivityLoginBinding.inflate(getLayoutInflater());
|
||||||
NetworkObserver networkMonitor = new NetworkObserver(ctx);
|
setContentView(activityLoginBinding.getRoot());
|
||||||
|
|
||||||
loginButton = findViewById(R.id.login_button);
|
NetworkStatusObserver networkStatusObserver = NetworkStatusObserver.getInstance(ctx);
|
||||||
instanceUrlET = findViewById(R.id.instance_url);
|
|
||||||
loginUidET = findViewById(R.id.login_uid);
|
|
||||||
loginPassword = findViewById(R.id.login_passwd);
|
|
||||||
otpCode = findViewById(R.id.otpCode);
|
|
||||||
otpInfo = findViewById(R.id.otpInfo);
|
|
||||||
ImageView info_button = findViewById(R.id.info);
|
|
||||||
protocolSpinner = findViewById(R.id.httpsSpinner);
|
|
||||||
loginMethod = findViewById(R.id.loginMethod);
|
|
||||||
loginTokenCode = findViewById(R.id.loginTokenCode);
|
|
||||||
|
|
||||||
((TextView) findViewById(R.id.appVersion)).setText(AppUtil.getAppVersion(appCtx));
|
loginButton = activityLoginBinding.loginButton;
|
||||||
|
instanceUrlET = activityLoginBinding.instanceUrl;
|
||||||
|
loginUidET = activityLoginBinding.loginUid;
|
||||||
|
loginPassword = activityLoginBinding.loginPasswd;
|
||||||
|
otpCode = activityLoginBinding.otpCode;
|
||||||
|
protocolSpinner = activityLoginBinding.httpsSpinner;
|
||||||
|
loginMethod = activityLoginBinding.loginMethod;
|
||||||
|
loginTokenCode = activityLoginBinding.loginTokenCode;
|
||||||
|
|
||||||
ArrayAdapter<Protocol> adapterProtocols = new ArrayAdapter<>(LoginActivity.this, R.layout.spinner_item, Protocol.values());
|
activityLoginBinding.appVersion.setText(AppUtil.getAppVersion(appCtx));
|
||||||
adapterProtocols.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
|
||||||
|
ArrayAdapter<Protocol> adapterProtocols = new ArrayAdapter<>(LoginActivity.this, R.layout.list_spinner_items, Protocol.values());
|
||||||
|
|
||||||
|
instanceUrlET.setText(getIntent().getStringExtra("instanceUrl"));
|
||||||
|
|
||||||
protocolSpinner.setAdapter(adapterProtocols);
|
protocolSpinner.setAdapter(adapterProtocols);
|
||||||
protocolSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
protocolSpinner.setSelection(0);
|
||||||
|
protocolSpinner.setOnItemClickListener((parent, view, position, id) -> {
|
||||||
|
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
selectedProtocol = String.valueOf(parent.getItemAtPosition(position));
|
||||||
|
|
||||||
if(protocolSpinner.getSelectedItem() == Protocol.HTTP) {
|
if(selectedProtocol.equals(String.valueOf(Protocol.HTTP))) {
|
||||||
Toasty.warning(ctx, getResources().getString(R.string.protocolError));
|
|
||||||
}
|
Toasty.warning(ctx, getResources().getString(R.string.protocolError));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
info_button.setOnClickListener(
|
if(R.id.loginToken == loginMethod.getCheckedRadioButtonId()) {
|
||||||
view -> new Tooltip.Builder(view).setText(R.string.urlInfoTooltip).setTextColor(getResources().getColor(R.color.colorWhite))
|
|
||||||
.setBackgroundColor(getResources().getColor(R.color.tooltipBackground)).setCancelable(true).setDismissOnClick(true).setPadding(30)
|
AppUtil.setMultiVisibility(View.GONE, findViewById(R.id.login_uidLayout), findViewById(R.id.login_passwdLayout), findViewById(R.id.otpCodeLayout));
|
||||||
.setCornerRadius(R.dimen.tooltipCornor).setGravity(Gravity.BOTTOM).show());
|
findViewById(R.id.loginTokenCodeLayout).setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
AppUtil.setMultiVisibility(View.VISIBLE, findViewById(R.id.login_uidLayout), findViewById(R.id.login_passwdLayout), findViewById(R.id.otpCodeLayout));
|
||||||
|
findViewById(R.id.loginTokenCodeLayout).setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
loginMethod.setOnCheckedChangeListener((group, checkedId) -> {
|
loginMethod.setOnCheckedChangeListener((group, checkedId) -> {
|
||||||
|
|
||||||
if(checkedId == R.id.loginToken) {
|
if(checkedId == R.id.loginToken) {
|
||||||
|
|
||||||
AppUtil.setMultiVisibility(View.GONE, loginUidET, loginPassword, otpCode, otpInfo);
|
AppUtil.setMultiVisibility(View.GONE, findViewById(R.id.login_uidLayout), findViewById(R.id.login_passwdLayout), findViewById(R.id.otpCodeLayout));
|
||||||
loginTokenCode.setVisibility(View.VISIBLE);
|
findViewById(R.id.loginTokenCodeLayout).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
AppUtil.setMultiVisibility(View.VISIBLE, loginUidET, loginPassword, otpCode, otpInfo);
|
AppUtil.setMultiVisibility(View.VISIBLE, findViewById(R.id.login_uidLayout), findViewById(R.id.login_passwdLayout), findViewById(R.id.otpCodeLayout));
|
||||||
loginTokenCode.setVisibility(View.GONE);
|
findViewById(R.id.loginTokenCodeLayout).setVisibility(View.GONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
networkMonitor.onInternetStateListener(isAvailable -> {
|
Handler handler = new Handler(getMainLooper());
|
||||||
|
|
||||||
if(isAvailable) {
|
networkStatusObserver.registerNetworkStatusListener(hasNetworkConnection -> {
|
||||||
|
|
||||||
enableProcessButton();
|
handler.post(() -> {
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
disableProcessButton();
|
if(hasNetworkConnection) {
|
||||||
loginButton.setText(getResources().getString(R.string.btnLogin));
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
enableProcessButton();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
disableProcessButton();
|
||||||
|
loginButton.setText(getResources().getString(R.string.btnLogin));
|
||||||
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
loadDefaults();
|
loadDefaults();
|
||||||
@@ -149,41 +142,40 @@ public class LoginActivity extends BaseActivity {
|
|||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
login();
|
login();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void login() {
|
private void login() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if(selectedProtocol == null) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getResources().getString(R.string.protocolEmptyError));
|
||||||
|
enableProcessButton();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String loginUid = loginUidET.getText().toString();
|
String loginUid = loginUidET.getText().toString();
|
||||||
String loginPass = loginPassword.getText().toString();
|
String loginPass = loginPassword.getText().toString();
|
||||||
String loginToken = loginTokenCode.getText().toString().trim();
|
String loginToken = loginTokenCode.getText().toString().trim();
|
||||||
|
|
||||||
Protocol protocol = (Protocol) protocolSpinner.getSelectedItem();
|
|
||||||
LoginType loginType = (loginMethod.getCheckedRadioButtonId() == R.id.loginUsernamePassword) ? LoginType.BASIC : LoginType.TOKEN;
|
LoginType loginType = (loginMethod.getCheckedRadioButtonId() == R.id.loginUsernamePassword) ? LoginType.BASIC : LoginType.TOKEN;
|
||||||
|
|
||||||
URI rawInstanceUrl = UrlBuilder.fromString(UrlHelper.fixScheme(instanceUrlET.getText().toString(), "http")).toUri();
|
URI rawInstanceUrl = UrlBuilder.fromString(UrlHelper.fixScheme(instanceUrlET.getText().toString(), "http")).toUri();
|
||||||
|
|
||||||
URI instanceUrlWithProtocol = UrlBuilder.fromUri(rawInstanceUrl).withPath(PathsHelper.join(rawInstanceUrl.getPath()))
|
URI instanceUrl = UrlBuilder.fromUri(rawInstanceUrl).withScheme(selectedProtocol.toLowerCase()).withPath(PathsHelper.join(rawInstanceUrl.getPath(), "/api/v1/"))
|
||||||
.withScheme(protocol.name().toLowerCase()).toUri();
|
|
||||||
|
|
||||||
URI instanceUrl = UrlBuilder.fromUri(instanceUrlWithProtocol).withPath(PathsHelper.join(instanceUrlWithProtocol.getPath(), "/api/v1/"))
|
|
||||||
.toUri();
|
.toUri();
|
||||||
|
|
||||||
tinyDB.putString("loginType", loginType.name().toLowerCase());
|
tinyDB.putString("loginType", loginType.name().toLowerCase());
|
||||||
tinyDB.putString("instanceUrlRaw", instanceUrlET.getText().toString());
|
tinyDB.putString("instanceUrlRaw", instanceUrlET.getText().toString());
|
||||||
tinyDB.putString("instanceUrl", instanceUrl.toString());
|
tinyDB.putString("instanceUrl", instanceUrl.toString());
|
||||||
tinyDB.putString("instanceUrlWithProtocol", instanceUrlWithProtocol.toString());
|
|
||||||
|
|
||||||
if(instanceUrlET.getText().toString().equals("")) {
|
if(instanceUrlET.getText().toString().equals("")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.emptyFieldURL));
|
Toasty.error(ctx, getResources().getString(R.string.emptyFieldURL));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(loginType == LoginType.BASIC) {
|
if(loginType == LoginType.BASIC) {
|
||||||
@@ -193,14 +185,12 @@ public class LoginActivity extends BaseActivity {
|
|||||||
Toasty.warning(ctx, getResources().getString(R.string.loginOTPTypeError));
|
Toasty.warning(ctx, getResources().getString(R.string.loginOTPTypeError));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rawInstanceUrl.getUserInfo() != null) {
|
if(rawInstanceUrl.getUserInfo() != null) {
|
||||||
|
|
||||||
tinyDB.putString("basicAuthPassword", loginPass);
|
tinyDB.putString("basicAuthPassword", loginPass);
|
||||||
tinyDB.putBoolean("basicAuthFlag", true);
|
tinyDB.putBoolean("basicAuthFlag", true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(loginUid.equals("")) {
|
if(loginUid.equals("")) {
|
||||||
@@ -208,7 +198,6 @@ public class LoginActivity extends BaseActivity {
|
|||||||
Toasty.error(ctx, getResources().getString(R.string.emptyFieldUsername));
|
Toasty.error(ctx, getResources().getString(R.string.emptyFieldUsername));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(loginPass.equals("")) {
|
if(loginPass.equals("")) {
|
||||||
@@ -216,13 +205,12 @@ public class LoginActivity extends BaseActivity {
|
|||||||
Toasty.error(ctx, getResources().getString(R.string.emptyFieldPassword));
|
Toasty.error(ctx, getResources().getString(R.string.emptyFieldPassword));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int loginOTP = (otpCode.length() > 0) ? Integer.parseInt(otpCode.getText().toString().trim()) : 0;
|
int loginOTP = (otpCode.length() > 0) ? Integer.parseInt(otpCode.getText().toString().trim()) : 0;
|
||||||
tinyDB.putString("loginUid", loginUid);
|
tinyDB.putString("loginUid", loginUid);
|
||||||
|
|
||||||
versionCheck(instanceUrl.toString(), loginUid, loginPass, loginOTP, loginToken, loginType);
|
versionCheck(loginUid, loginPass, loginOTP, loginToken, loginType);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -232,11 +220,9 @@ public class LoginActivity extends BaseActivity {
|
|||||||
Toasty.error(ctx, getResources().getString(R.string.loginTokenError));
|
Toasty.error(ctx, getResources().getString(R.string.loginTokenError));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
versionCheck(instanceUrl.toString(), loginUid, loginPass, 123, loginToken, loginType);
|
versionCheck(loginUid, loginPass, 123, loginToken, loginType);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -245,27 +231,25 @@ public class LoginActivity extends BaseActivity {
|
|||||||
Log.e("onFailure-login", e.toString());
|
Log.e("onFailure-login", e.toString());
|
||||||
Toasty.error(ctx, getResources().getString(R.string.malformedUrl));
|
Toasty.error(ctx, getResources().getString(R.string.malformedUrl));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void versionCheck(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP, final String loginToken,
|
private void versionCheck(final String loginUid, final String loginPass, final int loginOTP, final String loginToken,
|
||||||
final LoginType loginType) {
|
final LoginType loginType) {
|
||||||
|
|
||||||
Call<GiteaVersion> callVersion;
|
Call<GiteaVersion> callVersion;
|
||||||
|
|
||||||
if(!loginToken.equals("")) {
|
if(!loginToken.equals("")) {
|
||||||
|
|
||||||
callVersion = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithToken(loginToken);
|
callVersion = RetrofitClient.getApiInterface(appCtx).getGiteaVersionWithToken("token " + loginToken);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
|
String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
callVersion =
|
callVersion =
|
||||||
(loginOTP != 0) ? RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithOTP(credential, loginOTP) :
|
(loginOTP != 0) ? RetrofitClient.getApiInterface(appCtx).getGiteaVersionWithOTP(credential, loginOTP) :
|
||||||
RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithBasic(credential);
|
RetrofitClient.getApiInterface(appCtx).getGiteaVersionWithBasic(credential);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callVersion.enqueue(new Callback<GiteaVersion>() {
|
callVersion.enqueue(new Callback<GiteaVersion>() {
|
||||||
@@ -276,24 +260,24 @@ public class LoginActivity extends BaseActivity {
|
|||||||
if(responseVersion.code() == 200) {
|
if(responseVersion.code() == 200) {
|
||||||
|
|
||||||
GiteaVersion version = responseVersion.body();
|
GiteaVersion version = responseVersion.body();
|
||||||
Version gitea_version;
|
|
||||||
|
|
||||||
assert version != null;
|
assert version != null;
|
||||||
|
|
||||||
try {
|
if(!Version.valid(version.getVersion())) {
|
||||||
gitea_version = new Version(version.getVersion());
|
|
||||||
}
|
|
||||||
catch(Exception e) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.versionUnknown));
|
Toasty.error(ctx, getResources().getString(R.string.versionUnknown));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tinyDB.putString("giteaVersion", version.getVersion());
|
||||||
|
Version gitea_version = new Version(version.getVersion());
|
||||||
|
|
||||||
if(gitea_version.less(getString(R.string.versionLow))) {
|
if(gitea_version.less(getString(R.string.versionLow))) {
|
||||||
|
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctx).setTitle(getString(R.string.versionAlertDialogHeader))
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctx)
|
||||||
.setMessage(getResources().getString(R.string.versionUnsupportedOld, version.getVersion())).setIcon(R.drawable.ic_warning)
|
.setTitle(getString(R.string.versionAlertDialogHeader))
|
||||||
|
.setMessage(getResources().getString(R.string.versionUnsupportedOld, version.getVersion()))
|
||||||
|
.setIcon(R.drawable.ic_warning)
|
||||||
.setCancelable(true);
|
.setCancelable(true);
|
||||||
|
|
||||||
alertDialogBuilder.setNegativeButton(getString(R.string.cancelButton), (dialog, which) -> {
|
alertDialogBuilder.setNegativeButton(getString(R.string.cancelButton), (dialog, which) -> {
|
||||||
@@ -305,7 +289,7 @@ public class LoginActivity extends BaseActivity {
|
|||||||
alertDialogBuilder.setPositiveButton(getString(R.string.textContinue), (dialog, which) -> {
|
alertDialogBuilder.setPositiveButton(getString(R.string.textContinue), (dialog, which) -> {
|
||||||
|
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
|
login(loginType, loginUid, loginPass, loginOTP, loginToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
alertDialogBuilder.create().show();
|
alertDialogBuilder.create().show();
|
||||||
@@ -313,32 +297,34 @@ public class LoginActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
else if(gitea_version.lessOrEqual(getString(R.string.versionHigh))) {
|
else if(gitea_version.lessOrEqual(getString(R.string.versionHigh))) {
|
||||||
|
|
||||||
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
|
login(loginType, loginUid, loginPass, loginOTP, loginToken);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Toasty.warning(ctx, getResources().getString(R.string.versionUnsupportedNew));
|
Toasty.warning(ctx, getResources().getString(R.string.versionUnsupportedNew));
|
||||||
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
|
login(loginType, loginUid, loginPass, loginOTP, loginToken);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(responseVersion.code() == 403) {
|
else if(responseVersion.code() == 403) {
|
||||||
|
|
||||||
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
|
login(loginType, loginUid, loginPass, loginOTP, loginToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void login(LoginType loginType, String instanceUrl, String loginUid, String loginPass, int loginOTP, String loginToken) {
|
private void login(LoginType loginType, String loginUid, String loginPass, int loginOTP, String loginToken) {
|
||||||
|
|
||||||
// ToDo: before store/create token: get UserInfo to check DB/AccountManager if there already exist a token
|
// ToDo: before store/create token: get UserInfo to check DB/AccountManager if there already exist a token
|
||||||
// the setup methods then can better handle all different cases
|
// the setup methods then can better handle all different cases
|
||||||
|
|
||||||
if(loginType == LoginType.BASIC) {
|
if(loginType == LoginType.BASIC) {
|
||||||
setup(instanceUrl, loginUid, loginPass, loginOTP);
|
|
||||||
|
setup(loginUid, loginPass, loginOTP);
|
||||||
}
|
}
|
||||||
else if(loginType == LoginType.TOKEN) { // Token
|
else if(loginType == LoginType.TOKEN) { // Token
|
||||||
setupUsingExistingToken(instanceUrl, loginToken);
|
|
||||||
|
setupUsingExistingToken(loginToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,9 +338,9 @@ public class LoginActivity extends BaseActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupUsingExistingToken(String instanceUrl, final String loginToken) {
|
private void setupUsingExistingToken(final String loginToken) {
|
||||||
|
|
||||||
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserInfo("token " + loginToken);
|
Call<UserInfo> call = RetrofitClient.getApiInterface(appCtx).getUserInfo("token " + loginToken);
|
||||||
|
|
||||||
call.enqueue(new Callback<UserInfo>() {
|
call.enqueue(new Callback<UserInfo>() {
|
||||||
|
|
||||||
@@ -366,6 +352,7 @@ public class LoginActivity extends BaseActivity {
|
|||||||
switch(response.code()) {
|
switch(response.code()) {
|
||||||
|
|
||||||
case 200:
|
case 200:
|
||||||
|
|
||||||
assert userDetails != null;
|
assert userDetails != null;
|
||||||
tinyDB.putBoolean("loggedInMode", true);
|
tinyDB.putBoolean("loggedInMode", true);
|
||||||
tinyDB.putString(userDetails.getLogin() + "-token", loginToken);
|
tinyDB.putString(userDetails.getLogin() + "-token", loginToken);
|
||||||
@@ -373,20 +360,20 @@ public class LoginActivity extends BaseActivity {
|
|||||||
tinyDB.putString("userLogin", userDetails.getUsername());
|
tinyDB.putString("userLogin", userDetails.getUsername());
|
||||||
|
|
||||||
// insert new account to db if does not exist
|
// insert new account to db if does not exist
|
||||||
String accountName = userDetails.getUsername() + "@" + instanceUrl;
|
String accountName = userDetails.getUsername() + "@" + TinyDB.getInstance(ctx).getString("instanceUrl");
|
||||||
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
|
UserAccountsApi userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class);
|
||||||
int checkAccount = userAccountsApi.getCount(accountName);
|
boolean userAccountExists = userAccountsApi.userAccountExists(accountName);
|
||||||
long accountId;
|
long accountId;
|
||||||
|
|
||||||
if(checkAccount == 0) {
|
if(!userAccountExists) {
|
||||||
|
|
||||||
accountId = userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), loginToken, "");
|
accountId = userAccountsApi.createNewAccount(accountName, TinyDB.getInstance(ctx).getString("instanceUrl"), userDetails.getUsername(), loginToken, "");
|
||||||
tinyDB.putInt("currentActiveAccountId", (int) accountId);
|
tinyDB.putInt("currentActiveAccountId", (int) accountId);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
userAccountsApi.updateTokenByAccountName(accountName, loginToken);
|
userAccountsApi.updateTokenByAccountName(accountName, loginToken);
|
||||||
UserAccount data = userAccountsApi.getAccountData(accountName);
|
UserAccount data = userAccountsApi.getAccountByName(accountName);
|
||||||
tinyDB.putInt("currentActiveAccountId", data.getAccountId());
|
tinyDB.putInt("currentActiveAccountId", data.getAccountId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,18 +381,16 @@ public class LoginActivity extends BaseActivity {
|
|||||||
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
||||||
finish();
|
finish();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 401:
|
case 401:
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.unauthorizedApiError));
|
Toasty.error(ctx, getResources().getString(R.string.unauthorizedApiError));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -414,13 +399,12 @@ public class LoginActivity extends BaseActivity {
|
|||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setup(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP) {
|
private void setup(final String loginUid, final String loginPass, final int loginOTP) {
|
||||||
|
|
||||||
final String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
|
final String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
|
||||||
final String tokenName = "gitnex-app-" + device_id;
|
final String tokenName = "gitnex-app-" + device_id;
|
||||||
@@ -428,11 +412,11 @@ public class LoginActivity extends BaseActivity {
|
|||||||
Call<List<UserTokens>> call;
|
Call<List<UserTokens>> call;
|
||||||
if(loginOTP != 0) {
|
if(loginOTP != 0) {
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserTokensWithOTP(credential, loginOTP, loginUid);
|
call = RetrofitClient.getApiInterface(appCtx).getUserTokensWithOTP(credential, loginOTP, loginUid);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserTokens(credential, loginUid);
|
call = RetrofitClient.getApiInterface(appCtx).getUserTokens(credential, loginUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
call.enqueue(new Callback<List<UserTokens>>() {
|
call.enqueue(new Callback<List<UserTokens>>() {
|
||||||
@@ -445,7 +429,9 @@ public class LoginActivity extends BaseActivity {
|
|||||||
if(response.code() == 200) {
|
if(response.code() == 200) {
|
||||||
|
|
||||||
assert userTokens != null;
|
assert userTokens != null;
|
||||||
|
|
||||||
for(UserTokens t : userTokens) {
|
for(UserTokens t : userTokens) {
|
||||||
|
|
||||||
if(t.getName().equals(tokenName)) {
|
if(t.getName().equals(tokenName)) {
|
||||||
|
|
||||||
// this app had created an token on this instance before
|
// this app had created an token on this instance before
|
||||||
@@ -454,13 +440,14 @@ public class LoginActivity extends BaseActivity {
|
|||||||
Call<Void> delcall;
|
Call<Void> delcall;
|
||||||
if(loginOTP != 0) {
|
if(loginOTP != 0) {
|
||||||
|
|
||||||
delcall = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
|
delcall = RetrofitClient.getApiInterface(ctx)
|
||||||
.deleteTokenWithOTP(credential, loginOTP, loginUid, t.getId());
|
.deleteTokenWithOTP(credential, loginOTP, loginUid, t.getId());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
delcall = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().deleteToken(credential, loginUid, t.getId());
|
delcall = RetrofitClient.getApiInterface(ctx).deleteToken(credential, loginUid, t.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
delcall.enqueue(new Callback<Void>() {
|
delcall.enqueue(new Callback<Void>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -468,13 +455,12 @@ public class LoginActivity extends BaseActivity {
|
|||||||
|
|
||||||
if(response.code() == 204) {
|
if(response.code() == 204) {
|
||||||
|
|
||||||
setupToken(instanceUrl, loginUid, loginPass, loginOTP, tokenName);
|
setupToken(loginUid, loginPass, loginOTP, tokenName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,20 +470,18 @@ public class LoginActivity extends BaseActivity {
|
|||||||
Log.e("onFailure-login", t.toString());
|
Log.e("onFailure-login", t.toString());
|
||||||
Toasty.error(ctx, getResources().getString(R.string.malformedJson));
|
Toasty.error(ctx, getResources().getString(R.string.malformedJson));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupToken(instanceUrl, loginUid, loginPass, loginOTP, tokenName);
|
setupToken(loginUid, loginPass, loginOTP, tokenName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -507,13 +491,12 @@ public class LoginActivity extends BaseActivity {
|
|||||||
Log.e("onFailure-login", t.toString());
|
Log.e("onFailure-login", t.toString());
|
||||||
Toasty.error(ctx, getResources().getString(R.string.malformedJson));
|
Toasty.error(ctx, getResources().getString(R.string.malformedJson));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupToken(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP, final String tokenName) {
|
private void setupToken(final String loginUid, final String loginPass, final int loginOTP, final String tokenName) {
|
||||||
|
|
||||||
final String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
|
final String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
@@ -522,12 +505,13 @@ public class LoginActivity extends BaseActivity {
|
|||||||
|
|
||||||
if(loginOTP != 0) {
|
if(loginOTP != 0) {
|
||||||
|
|
||||||
callCreateToken = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
|
callCreateToken = RetrofitClient.getApiInterface(ctx)
|
||||||
.createNewTokenWithOTP(credential, loginOTP, loginUid, createUserToken);
|
.createNewTokenWithOTP(credential, loginOTP, loginUid, createUserToken);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
callCreateToken = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().createNewToken(credential, loginUid, createUserToken);
|
callCreateToken = RetrofitClient.getApiInterface(ctx)
|
||||||
|
.createNewToken(credential, loginUid, createUserToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
callCreateToken.enqueue(new Callback<UserTokens>() {
|
callCreateToken.enqueue(new Callback<UserTokens>() {
|
||||||
@@ -542,7 +526,7 @@ public class LoginActivity extends BaseActivity {
|
|||||||
|
|
||||||
if(!newToken.getSha1().equals("")) {
|
if(!newToken.getSha1().equals("")) {
|
||||||
|
|
||||||
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
|
Call<UserInfo> call = RetrofitClient.getApiInterface(ctx)
|
||||||
.getUserInfo("token " + newToken.getSha1());
|
.getUserInfo("token " + newToken.getSha1());
|
||||||
|
|
||||||
call.enqueue(new Callback<UserInfo>() {
|
call.enqueue(new Callback<UserInfo>() {
|
||||||
@@ -555,6 +539,7 @@ public class LoginActivity extends BaseActivity {
|
|||||||
switch(response.code()) {
|
switch(response.code()) {
|
||||||
|
|
||||||
case 200:
|
case 200:
|
||||||
|
|
||||||
assert userDetails != null;
|
assert userDetails != null;
|
||||||
tinyDB.remove("loginPass");
|
tinyDB.remove("loginPass");
|
||||||
tinyDB.putBoolean("loggedInMode", true);
|
tinyDB.putBoolean("loggedInMode", true);
|
||||||
@@ -563,38 +548,37 @@ public class LoginActivity extends BaseActivity {
|
|||||||
tinyDB.putString(loginUid + "-token-last-eight", newToken.getToken_last_eight());
|
tinyDB.putString(loginUid + "-token-last-eight", newToken.getToken_last_eight());
|
||||||
|
|
||||||
// insert new account to db if does not exist
|
// insert new account to db if does not exist
|
||||||
String accountName = userDetails.getUsername() + "@" + instanceUrl;
|
String accountName = userDetails.getUsername() + "@" + TinyDB.getInstance(ctx).getString("instanceUrl");
|
||||||
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
|
UserAccountsApi userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class);
|
||||||
int checkAccount = userAccountsApi.getCount(accountName);
|
boolean userAccountExists = userAccountsApi.userAccountExists(accountName);
|
||||||
long accountId;
|
long accountId;
|
||||||
|
|
||||||
if(checkAccount == 0) {
|
if(!userAccountExists) {
|
||||||
|
|
||||||
accountId = userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), newToken.getSha1(), "");
|
accountId = userAccountsApi
|
||||||
|
.createNewAccount(accountName, TinyDB.getInstance(ctx).getString("instanceUrl"), userDetails.getUsername(), newToken.getSha1(), "");
|
||||||
tinyDB.putInt("currentActiveAccountId", (int) accountId);
|
tinyDB.putInt("currentActiveAccountId", (int) accountId);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
userAccountsApi.updateTokenByAccountName(accountName, newToken.getSha1());
|
userAccountsApi.updateTokenByAccountName(accountName, newToken.getSha1());
|
||||||
UserAccount data = userAccountsApi.getAccountData(accountName);
|
UserAccount data = userAccountsApi.getAccountByName(accountName);
|
||||||
tinyDB.putInt("currentActiveAccountId", data.getAccountId());
|
tinyDB.putInt("currentActiveAccountId", data.getAccountId());
|
||||||
}
|
}
|
||||||
|
|
||||||
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
||||||
finish();
|
finish();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 401:
|
case 401:
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.unauthorizedApiError));
|
Toasty.error(ctx, getResources().getString(R.string.unauthorizedApiError));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -603,7 +587,6 @@ public class LoginActivity extends BaseActivity {
|
|||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -612,7 +595,6 @@ public class LoginActivity extends BaseActivity {
|
|||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + responseCreate.code());
|
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + responseCreate.code());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -628,17 +610,21 @@ public class LoginActivity extends BaseActivity {
|
|||||||
private void loadDefaults() {
|
private void loadDefaults() {
|
||||||
|
|
||||||
if(tinyDB.getString("loginType").equals(LoginType.BASIC.name().toLowerCase())) {
|
if(tinyDB.getString("loginType").equals(LoginType.BASIC.name().toLowerCase())) {
|
||||||
|
|
||||||
loginMethod.check(R.id.loginUsernamePassword);
|
loginMethod.check(R.id.loginUsernamePassword);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
loginMethod.check(R.id.loginToken);
|
loginMethod.check(R.id.loginToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!tinyDB.getString("instanceUrlRaw").equals("")) {
|
if(!tinyDB.getString("instanceUrlRaw").equals("")) {
|
||||||
|
|
||||||
instanceUrlET.setText(tinyDB.getString("instanceUrlRaw"));
|
instanceUrlET.setText(tinyDB.getString("instanceUrlRaw"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!tinyDB.getString("loginUid").equals("")) {
|
if(!tinyDB.getString("loginUid").equals("")) {
|
||||||
|
|
||||||
loginUidET.setText(tinyDB.getString("loginUid"));
|
loginUidET.setText(tinyDB.getString("loginUid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -649,9 +635,11 @@ public class LoginActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!tinyDB.getString("uniqueAppId").isEmpty()) {
|
if(!tinyDB.getString("uniqueAppId").isEmpty()) {
|
||||||
|
|
||||||
device_id = tinyDB.getString("uniqueAppId");
|
device_id = tinyDB.getString("uniqueAppId");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
device_id = UUID.randomUUID().toString();
|
device_id = UUID.randomUUID().toString();
|
||||||
tinyDB.putString("uniqueAppId", device_id);
|
tinyDB.putString("uniqueAppId", device_id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.Html;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -20,27 +17,32 @@ import androidx.appcompat.app.ActionBarDrawerToggle;
|
|||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.cardview.widget.CardView;
|
||||||
import androidx.core.view.GravityCompat;
|
import androidx.core.view.GravityCompat;
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.google.android.material.navigation.NavigationView;
|
import com.google.android.material.navigation.NavigationView;
|
||||||
|
import org.gitnex.tea4j.models.GiteaVersion;
|
||||||
|
import org.gitnex.tea4j.models.NotificationCount;
|
||||||
|
import org.gitnex.tea4j.models.UserInfo;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.adapters.UserAccountsNavAdapter;
|
import org.mian.gitnex.adapters.UserAccountsNavAdapter;
|
||||||
import org.mian.gitnex.clients.PicassoService;
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.database.api.BaseApi;
|
||||||
import org.mian.gitnex.database.api.UserAccountsApi;
|
import org.mian.gitnex.database.api.UserAccountsApi;
|
||||||
import org.mian.gitnex.database.models.UserAccount;
|
import org.mian.gitnex.database.models.UserAccount;
|
||||||
import org.mian.gitnex.fragments.AboutFragment;
|
import org.mian.gitnex.databinding.ActivityMainBinding;
|
||||||
import org.mian.gitnex.fragments.AdministrationFragment;
|
import org.mian.gitnex.fragments.AdministrationFragment;
|
||||||
import org.mian.gitnex.fragments.BottomSheetDraftsFragment;
|
import org.mian.gitnex.fragments.BottomSheetDraftsFragment;
|
||||||
import org.mian.gitnex.fragments.DraftsFragment;
|
import org.mian.gitnex.fragments.DraftsFragment;
|
||||||
import org.mian.gitnex.fragments.ExploreRepositoriesFragment;
|
import org.mian.gitnex.fragments.ExploreFragment;
|
||||||
import org.mian.gitnex.fragments.MyRepositoriesFragment;
|
import org.mian.gitnex.fragments.MyRepositoriesFragment;
|
||||||
import org.mian.gitnex.fragments.NotificationsFragment;
|
import org.mian.gitnex.fragments.NotificationsFragment;
|
||||||
import org.mian.gitnex.fragments.OrganizationsFragment;
|
import org.mian.gitnex.fragments.OrganizationsFragment;
|
||||||
import org.mian.gitnex.fragments.ProfileFragment;
|
import org.mian.gitnex.fragments.MyProfileFragment;
|
||||||
import org.mian.gitnex.fragments.RepositoriesFragment;
|
import org.mian.gitnex.fragments.RepositoriesFragment;
|
||||||
import org.mian.gitnex.fragments.SettingsFragment;
|
import org.mian.gitnex.fragments.SettingsFragment;
|
||||||
import org.mian.gitnex.fragments.StarredRepositoriesFragment;
|
import org.mian.gitnex.fragments.StarredRepositoriesFragment;
|
||||||
@@ -54,13 +56,9 @@ import org.mian.gitnex.helpers.RoundedTransformation;
|
|||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.models.GiteaVersion;
|
|
||||||
import org.mian.gitnex.models.UserInfo;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import jp.wasabeef.picasso.transformations.BlurTransformation;
|
||||||
import eightbitlab.com.blurview.BlurView;
|
|
||||||
import eightbitlab.com.blurview.RenderScriptBlur;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
|
|
||||||
@@ -71,71 +69,61 @@ import retrofit2.Callback;
|
|||||||
public class MainActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener, BottomSheetDraftsFragment.BottomSheetListener {
|
public class MainActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener, BottomSheetDraftsFragment.BottomSheetListener {
|
||||||
|
|
||||||
private DrawerLayout drawer;
|
private DrawerLayout drawer;
|
||||||
private BlurView blurView;
|
|
||||||
private TextView userFullName;
|
|
||||||
private TextView userEmail;
|
|
||||||
private ImageView userAvatar;
|
|
||||||
private ImageView userAvatarBackground;
|
|
||||||
private ViewGroup navHeaderFrame;
|
|
||||||
private TextView toolbarTitle;
|
private TextView toolbarTitle;
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private Typeface myTypeface;
|
private Typeface myTypeface;
|
||||||
|
|
||||||
@Override
|
private String loginUid;
|
||||||
protected int getLayoutResourceId() {
|
private String instanceToken;
|
||||||
|
|
||||||
return R.layout.activity_main;
|
private View hView;
|
||||||
}
|
private MenuItem navNotifications;
|
||||||
|
private TextView notificationCounter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
ActivityMainBinding activityMainBinding = ActivityMainBinding.inflate(getLayoutInflater());
|
||||||
tinyDb.putBoolean("noConnection", false);
|
setContentView(activityMainBinding.getRoot());
|
||||||
|
|
||||||
Intent mainIntent = getIntent();
|
Intent mainIntent = getIntent();
|
||||||
String launchFragment = mainIntent.getStringExtra("launchFragment");
|
|
||||||
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
// DO NOT MOVE
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
if(mainIntent.hasExtra("switchAccountId") &&
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
AppUtil.switchToAccount(ctx, BaseApi.getInstance(ctx, UserAccountsApi.class)
|
||||||
|
.getAccountById(mainIntent.getIntExtra("switchAccountId", 0)))) {
|
||||||
|
|
||||||
|
mainIntent.removeExtra("switchAccountId");
|
||||||
|
recreate();
|
||||||
|
return;
|
||||||
|
|
||||||
if(tinyDb.getString("dateFormat").isEmpty()) {
|
|
||||||
tinyDb.putString("dateFormat", "pretty");
|
|
||||||
}
|
}
|
||||||
|
// DO NOT MOVE
|
||||||
|
|
||||||
if(tinyDb.getString("codeBlockStr").isEmpty()) {
|
tinyDB.putBoolean("noConnection", false);
|
||||||
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorLightGreen));
|
|
||||||
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(tinyDb.getString("enableCounterIssueBadgeInit").isEmpty()) {
|
loginUid = tinyDB.getString("loginUid");
|
||||||
tinyDb.putBoolean("enableCounterIssueBadge", true);
|
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||||
}
|
|
||||||
|
|
||||||
if(tinyDb.getString("homeScreenStr").isEmpty()) {
|
|
||||||
tinyDb.putInt("homeScreenId", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
|
|
||||||
if(!tinyDb.getBoolean("loggedInMode")) {
|
if(!tinyDB.getBoolean("loggedInMode")) {
|
||||||
|
|
||||||
logout(this, ctx);
|
logout(this, ctx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tinyDb.getInt("currentActiveAccountId") <= 0) {
|
if(tinyDB.getInt("currentActiveAccountId", -1) <= 0) {
|
||||||
AlertDialogs.forceLogoutDialog(ctx, getResources().getString(R.string.forceLogoutDialogHeader), getResources().getString(R.string.forceLogoutDialogDescription), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
AlertDialogs.forceLogoutDialog(ctx,
|
||||||
|
getResources().getString(R.string.forceLogoutDialogHeader),
|
||||||
|
getResources().getString(R.string.forceLogoutDialogDescription), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
}
|
}
|
||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = activityMainBinding.toolbar;
|
||||||
toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
|
toolbarTitle = activityMainBinding.toolbarTitle;
|
||||||
|
|
||||||
switch(tinyDb.getInt("customFontId", -1)) {
|
switch(tinyDB.getInt("customFontId", -1)) {
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
myTypeface = Typeface.createFromAsset(getAssets(), "fonts/roboto.ttf");
|
myTypeface = Typeface.createFromAsset(getAssets(), "fonts/roboto.ttf");
|
||||||
@@ -169,18 +157,15 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
else if(fragmentById instanceof OrganizationsFragment) {
|
else if(fragmentById instanceof OrganizationsFragment) {
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleOrganizations));
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleOrganizations));
|
||||||
}
|
}
|
||||||
else if(fragmentById instanceof ExploreRepositoriesFragment) {
|
else if(fragmentById instanceof ExploreFragment) {
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
|
||||||
}
|
}
|
||||||
else if(fragmentById instanceof NotificationsFragment) {
|
else if(fragmentById instanceof NotificationsFragment) {
|
||||||
toolbarTitle.setText(R.string.pageTitleNotifications);
|
toolbarTitle.setText(R.string.pageTitleNotifications);
|
||||||
}
|
}
|
||||||
else if(fragmentById instanceof ProfileFragment) {
|
else if(fragmentById instanceof MyProfileFragment) {
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
||||||
}
|
}
|
||||||
else if(fragmentById instanceof AboutFragment) {
|
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleAbout));
|
|
||||||
}
|
|
||||||
else if(fragmentById instanceof DraftsFragment) {
|
else if(fragmentById instanceof DraftsFragment) {
|
||||||
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
|
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
|
||||||
}
|
}
|
||||||
@@ -191,12 +176,17 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleUserAccounts));
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleUserAccounts));
|
||||||
}
|
}
|
||||||
|
|
||||||
drawer = findViewById(R.id.drawer_layout);
|
getNotificationsCount(instanceToken);
|
||||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
|
||||||
navigationView.setNavigationItemSelectedListener(this);
|
|
||||||
final View hView = navigationView.getHeaderView(0);
|
|
||||||
|
|
||||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
drawer = activityMainBinding.drawerLayout;
|
||||||
|
NavigationView navigationView = activityMainBinding.navView;
|
||||||
|
navigationView.setNavigationItemSelectedListener(this);
|
||||||
|
hView = navigationView.getHeaderView(0);
|
||||||
|
|
||||||
|
Menu menu = navigationView.getMenu();
|
||||||
|
navNotifications = menu.findItem(R.id.nav_notifications);
|
||||||
|
|
||||||
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigationDrawerOpen, R.string.navigationDrawerClose);
|
||||||
|
|
||||||
drawer.addDrawerListener(toggle);
|
drawer.addDrawerListener(toggle);
|
||||||
drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
|
drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
|
||||||
@@ -204,45 +194,37 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
@Override
|
@Override
|
||||||
public void onDrawerOpened(@NonNull View drawerView) {
|
public void onDrawerOpened(@NonNull View drawerView) {
|
||||||
|
|
||||||
}
|
if(tinyDB.getBoolean("noConnection")) {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
|
|
||||||
|
|
||||||
if(tinyDb.getBoolean("noConnection")) {
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
tinyDb.putBoolean("noConnection", false);
|
tinyDB.putBoolean("noConnection", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
String userEmailNav = tinyDb.getString("userEmail");
|
String userEmailNav = tinyDB.getString("userEmail");
|
||||||
String userFullNameNav = tinyDb.getString("userFullname");
|
String userFullNameNav = tinyDB.getString("userFullname");
|
||||||
String userAvatarNav = tinyDb.getString("userAvatar");
|
String userAvatarNav = tinyDB.getString("userAvatar");
|
||||||
|
|
||||||
blurView = hView.findViewById(R.id.blurView);
|
TextView userEmail = hView.findViewById(R.id.userEmail);
|
||||||
userEmail = hView.findViewById(R.id.userEmail);
|
TextView userFullName = hView.findViewById(R.id.userFullname);
|
||||||
userFullName = hView.findViewById(R.id.userFullname);
|
ImageView userAvatar = hView.findViewById(R.id.userAvatar);
|
||||||
userAvatar = hView.findViewById(R.id.userAvatar);
|
ImageView userAvatarBackground = hView.findViewById(R.id.userAvatarBackground);
|
||||||
userAvatarBackground = hView.findViewById(R.id.userAvatarBackground);
|
CardView navRecyclerViewFrame = hView.findViewById(R.id.userAccountsFrame);
|
||||||
navHeaderFrame = hView.findViewById(R.id.navHeaderFrame);
|
|
||||||
|
|
||||||
List<UserAccount> userAccountsList;
|
List<UserAccount> userAccountsList = new ArrayList<>();
|
||||||
userAccountsList = new ArrayList<>();
|
|
||||||
UserAccountsApi userAccountsApi;
|
UserAccountsApi userAccountsApi;
|
||||||
userAccountsApi = new UserAccountsApi(ctx);
|
userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class);
|
||||||
|
|
||||||
RecyclerView navRecyclerViewUserAccounts = hView.findViewById(R.id.navRecyclerViewUserAccounts);
|
RecyclerView navRecyclerViewUserAccounts = hView.findViewById(R.id.userAccounts);
|
||||||
UserAccountsNavAdapter adapterUserAccounts;
|
UserAccountsNavAdapter adapterUserAccounts;
|
||||||
|
|
||||||
adapterUserAccounts = new UserAccountsNavAdapter(ctx, userAccountsList, drawer, toolbarTitle);
|
adapterUserAccounts = new UserAccountsNavAdapter(ctx, userAccountsList, drawer, toolbarTitle);
|
||||||
|
|
||||||
userAccountsApi.getAllAccounts().observe((AppCompatActivity) ctx, userAccounts -> {
|
userAccountsApi.getAllAccounts().observe((AppCompatActivity) ctx, userAccounts -> {
|
||||||
|
|
||||||
if(userAccounts.size() > 0) {
|
if(userAccounts.size() > 0) {
|
||||||
|
|
||||||
userAccountsList.addAll(userAccounts);
|
userAccountsList.addAll(userAccounts);
|
||||||
navRecyclerViewUserAccounts.setAdapter(adapterUserAccounts);
|
navRecyclerViewUserAccounts.setAdapter(adapterUserAccounts);
|
||||||
|
navRecyclerViewFrame.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
userEmail.setTypeface(myTypeface);
|
userEmail.setTypeface(myTypeface);
|
||||||
@@ -253,55 +235,55 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!userFullNameNav.equals("")) {
|
if(!userFullNameNav.equals("")) {
|
||||||
userFullName.setText(userFullNameNav);
|
userFullName.setText(Html.fromHtml(userFullNameNav));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!userAvatarNav.equals("")) {
|
if(!userAvatarNav.equals("")) {
|
||||||
|
|
||||||
|
int avatarRadius = AppUtil.getPixelsFromDensity(ctx, 3);
|
||||||
|
|
||||||
PicassoService.getInstance(ctx).get()
|
PicassoService.getInstance(ctx).get()
|
||||||
.load(userAvatarNav)
|
.load(userAvatarNav)
|
||||||
.placeholder(R.drawable.loader_animated)
|
.placeholder(R.drawable.loader_animated)
|
||||||
.transform(new RoundedTransformation(8, 0))
|
.transform(new RoundedTransformation(avatarRadius, 0))
|
||||||
.resize(160, 160)
|
.resize(160, 160)
|
||||||
.centerCrop().into(userAvatar);
|
.centerCrop().into(userAvatar);
|
||||||
|
|
||||||
PicassoService.getInstance(ctx).get()
|
PicassoService.getInstance(ctx).get()
|
||||||
.load(userAvatarNav)
|
.load(userAvatarNav)
|
||||||
|
.transform(new BlurTransformation(ctx))
|
||||||
.into(userAvatarBackground, new com.squareup.picasso.Callback() {
|
.into(userAvatarBackground, new com.squareup.picasso.Callback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
|
|
||||||
int textColor = new ColorInverter().getImageViewContrastColor(userAvatarBackground);
|
int textColor = new ColorInverter().getImageViewContrastColor(userAvatarBackground);
|
||||||
|
|
||||||
userFullName.setTextColor(textColor);
|
userFullName.setTextColor(textColor);
|
||||||
userEmail.setTextColor(textColor);
|
userEmail.setTextColor(textColor);
|
||||||
|
|
||||||
blurView.setupWith(navHeaderFrame)
|
|
||||||
.setBlurAlgorithm(new RenderScriptBlur(ctx))
|
|
||||||
.setBlurRadius(5)
|
|
||||||
.setHasFixedTransformationMatrix(false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void onError(Exception e) {}
|
||||||
public void onError(Exception e) {}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
userAvatar.setOnClickListener(v -> {
|
userAvatar.setOnClickListener(v -> {
|
||||||
|
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ProfileFragment()).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyProfileFragment()).commit();
|
||||||
|
navigationView.setCheckedItem(R.id.nav_profile);
|
||||||
drawer.closeDrawers();
|
drawer.closeDrawers();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
String currentVersion = tinyDb.getString("giteaVersion");
|
getNotificationsCount(instanceToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
|
||||||
|
|
||||||
|
navigationView.getMenu().findItem(R.id.nav_administration).setVisible(tinyDB.getBoolean("userIsAdmin"));
|
||||||
|
navigationView.getMenu().findItem(R.id.nav_notifications).setVisible(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.3"));
|
||||||
|
|
||||||
navigationView.getMenu().findItem(R.id.nav_administration).setVisible(tinyDb.getBoolean("userIsAdmin"));
|
|
||||||
navigationView.getMenu().findItem(R.id.nav_notifications).setVisible(new Version(currentVersion).higherOrEqual("1.12.3"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -315,6 +297,8 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
toggle.syncState();
|
toggle.syncState();
|
||||||
toolbar.setNavigationIcon(R.drawable.ic_menu);
|
toolbar.setNavigationIcon(R.drawable.ic_menu);
|
||||||
|
|
||||||
|
String launchFragment = mainIntent.getStringExtra("launchFragment");
|
||||||
|
|
||||||
if(launchFragment != null) {
|
if(launchFragment != null) {
|
||||||
|
|
||||||
mainIntent.removeExtra("launchFragment");
|
mainIntent.removeExtra("launchFragment");
|
||||||
@@ -332,21 +316,60 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
|
||||||
navigationView.setCheckedItem(R.id.nav_notifications);
|
navigationView.setCheckedItem(R.id.nav_notifications);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String launchFragmentByHandler = mainIntent.getStringExtra("launchFragmentByLinkHandler");
|
||||||
|
|
||||||
|
if(launchFragmentByHandler != null) {
|
||||||
|
|
||||||
|
mainIntent.removeExtra("launchFragmentByLinkHandler");
|
||||||
|
|
||||||
|
switch(launchFragmentByHandler) {
|
||||||
|
|
||||||
|
case "repos":
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new RepositoriesFragment()).commit();
|
||||||
|
navigationView.setCheckedItem(R.id.nav_repositories);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case "org":
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new OrganizationsFragment()).commit();
|
||||||
|
navigationView.setCheckedItem(R.id.nav_organizations);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case "notification":
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
|
||||||
|
navigationView.setCheckedItem(R.id.nav_notifications);
|
||||||
|
setActionBarTitle(getResources().getString(R.string.pageTitleNotifications));
|
||||||
|
return;
|
||||||
|
|
||||||
|
case "explore":
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExploreFragment()).commit();
|
||||||
|
navigationView.setCheckedItem(R.id.nav_explore);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case "profile":
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyProfileFragment()).commit();
|
||||||
|
navigationView.setCheckedItem(R.id.nav_profile);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case "admin":
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AdministrationFragment()).commit();
|
||||||
|
navigationView.setCheckedItem(R.id.nav_administration);
|
||||||
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(savedInstanceState == null) {
|
if(savedInstanceState == null) {
|
||||||
|
|
||||||
if(!new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.3")) {
|
if(!new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.3")) {
|
||||||
|
if(tinyDB.getInt("homeScreenId") == 7) {
|
||||||
if(tinyDb.getInt("homeScreenId") == 7) {
|
tinyDB.putInt("homeScreenId", 0);
|
||||||
|
|
||||||
tinyDb.putInt("homeScreenId", 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(tinyDb.getInt("homeScreenId")) {
|
switch(tinyDB.getInt("homeScreenId")) {
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
||||||
@@ -368,13 +391,13 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ProfileFragment()).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyProfileFragment()).commit();
|
||||||
navigationView.setCheckedItem(R.id.nav_profile);
|
navigationView.setCheckedItem(R.id.nav_profile);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExploreRepositoriesFragment()).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExploreFragment()).commit();
|
||||||
navigationView.setCheckedItem(R.id.nav_explore);
|
navigationView.setCheckedItem(R.id.nav_explore);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -395,54 +418,47 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyRepositoriesFragment()).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyRepositoriesFragment()).commit();
|
||||||
navigationView.setCheckedItem(R.id.nav_home);
|
navigationView.setCheckedItem(R.id.nav_home);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!connToInternet) {
|
if(!connToInternet) {
|
||||||
|
|
||||||
if(!tinyDb.getBoolean("noConnection")) {
|
if(!tinyDB.getBoolean("noConnection")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
}
|
}
|
||||||
|
|
||||||
tinyDb.putBoolean("noConnection", true);
|
tinyDB.putBoolean("noConnection", true);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
loadUserInfo(instanceUrl, instanceToken, loginUid);
|
loadUserInfo(instanceToken, loginUid);
|
||||||
giteaVersion(instanceUrl);
|
giteaVersion();
|
||||||
tinyDb.putBoolean("noConnection", false);
|
tinyDB.putBoolean("noConnection", false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changelog popup
|
// Changelog popup
|
||||||
int versionCode = 0;
|
int versionCode = AppUtil.getAppBuildNo(appCtx);
|
||||||
|
|
||||||
try {
|
if(versionCode > tinyDB.getInt("versionCode")) {
|
||||||
|
|
||||||
PackageInfo packageInfo = appCtx.getPackageManager().getPackageInfo(appCtx.getPackageName(), 0);
|
tinyDB.putInt("versionCode", versionCode);
|
||||||
versionCode = packageInfo.versionCode;
|
tinyDB.putBoolean("versionFlag", true);
|
||||||
}
|
|
||||||
catch(PackageManager.NameNotFoundException e) {
|
|
||||||
|
|
||||||
Log.e("changelogDialog", Objects.requireNonNull(e.getMessage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(versionCode > tinyDb.getInt("versionCode")) {
|
|
||||||
|
|
||||||
tinyDb.putInt("versionCode", versionCode);
|
|
||||||
tinyDb.putBoolean("versionFlag", true);
|
|
||||||
|
|
||||||
ChangeLog changelogDialog = new ChangeLog(this);
|
ChangeLog changelogDialog = new ChangeLog(this);
|
||||||
changelogDialog.showDialog();
|
changelogDialog.showDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setActionBarTitle(String title) {
|
||||||
|
|
||||||
|
toolbarTitle.setText(title);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onButtonClicked(String text) {
|
public void onButtonClicked(String text) {
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(ctx);
|
TinyDB tinyDb = TinyDB.getInstance(ctx);
|
||||||
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
||||||
|
|
||||||
if("deleteDrafts".equals(text)) {
|
if("deleteDrafts".equals(text)) {
|
||||||
@@ -466,14 +482,15 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
|
|
||||||
})
|
})
|
||||||
.setNeutralButton(R.string.cancelButton, null).show();
|
.setNeutralButton(R.string.cancelButton, null).show();
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,109 +502,90 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
|
||||||
if(drawer.isDrawerOpen(GravityCompat.START)) {
|
if(drawer.isDrawerOpen(GravityCompat.START)) {
|
||||||
|
|
||||||
drawer.closeDrawer(GravityCompat.START);
|
drawer.closeDrawer(GravityCompat.START);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
||||||
|
|
||||||
switch(menuItem.getItemId()) {
|
int id = menuItem.getItemId();
|
||||||
|
|
||||||
case R.id.nav_home:
|
if(id == R.id.nav_home) {
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleMyRepos));
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyRepositoriesFragment()).commit();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case R.id.nav_organizations:
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleMyRepos));
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleOrganizations));
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyRepositoriesFragment()).commit();
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new OrganizationsFragment()).commit();
|
}
|
||||||
break;
|
else if(id == R.id.nav_organizations) {
|
||||||
|
|
||||||
case R.id.nav_profile:
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleOrganizations));
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new OrganizationsFragment()).commit();
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ProfileFragment()).commit();
|
}
|
||||||
break;
|
else if(id == R.id.nav_profile) {
|
||||||
|
|
||||||
case R.id.nav_repositories:
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleRepositories));
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyProfileFragment()).commit();
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new RepositoriesFragment()).commit();
|
}
|
||||||
break;
|
else if(id == R.id.nav_repositories) {
|
||||||
|
|
||||||
case R.id.nav_settings:
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleRepositories));
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleSettings));
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new RepositoriesFragment()).commit();
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingsFragment()).commit();
|
}
|
||||||
break;
|
else if(id == R.id.nav_settings) {
|
||||||
|
|
||||||
case R.id.nav_logout:
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleSettings));
|
||||||
logout(this, ctx);
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingsFragment()).commit();
|
||||||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
|
}
|
||||||
break;
|
else if(id == R.id.nav_logout) {
|
||||||
|
|
||||||
case R.id.nav_about:
|
logout(this, ctx);
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleAbout));
|
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AboutFragment()).commit();
|
}
|
||||||
break;
|
else if(id == R.id.nav_starred_repos) {
|
||||||
|
|
||||||
case R.id.nav_rate_app:
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
||||||
rateThisApp();
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new StarredRepositoriesFragment()).commit();
|
||||||
break;
|
}
|
||||||
|
else if(id == R.id.nav_explore) {
|
||||||
|
|
||||||
case R.id.nav_starred_repos:
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExploreFragment()).commit();
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new StarredRepositoriesFragment()).commit();
|
}
|
||||||
break;
|
else if(id == R.id.nav_notifications) {
|
||||||
|
|
||||||
case R.id.nav_explore:
|
toolbarTitle.setText(R.string.pageTitleNotifications);
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExploreRepositoriesFragment()).commit();
|
}
|
||||||
break;
|
else if(id == R.id.nav_comments_draft) {
|
||||||
|
|
||||||
case R.id.nav_notifications:
|
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
|
||||||
toolbarTitle.setText(R.string.pageTitleNotifications);
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new DraftsFragment()).commit();
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
|
}
|
||||||
break;
|
else if(id == R.id.nav_administration) {
|
||||||
|
|
||||||
case R.id.nav_comments_draft:
|
|
||||||
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new DraftsFragment()).commit();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case R.id.nav_administration:
|
|
||||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleAdministration));
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AdministrationFragment()).commit();
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
toolbarTitle.setText(getResources().getString(R.string.pageTitleAdministration));
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AdministrationFragment()).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
drawer.closeDrawer(GravityCompat.START);
|
drawer.closeDrawer(GravityCompat.START);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rateThisApp() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())));
|
|
||||||
}
|
|
||||||
catch(ActivityNotFoundException e) {
|
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void logout(Activity activity, Context ctx) {
|
public static void logout(Activity activity, Context ctx) {
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(ctx.getApplicationContext());
|
TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||||
tinyDb.putBoolean("loggedInMode", false);
|
|
||||||
tinyDb.remove("basicAuthPassword");
|
tinyDB.putBoolean("loggedInMode", false);
|
||||||
tinyDb.putBoolean("basicAuthFlag", false);
|
tinyDB.remove("basicAuthPassword");
|
||||||
|
tinyDB.putBoolean("basicAuthFlag", false);
|
||||||
//tinyDb.clear();
|
//tinyDb.clear();
|
||||||
activity.finish();
|
activity.finish();
|
||||||
ctx.startActivity(new Intent(ctx, LoginActivity.class));
|
ctx.startActivity(new Intent(ctx, LoginActivity.class));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -596,53 +594,43 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
|
|
||||||
if(id == R.id.genericMenu) {
|
if(id == R.id.genericMenu) {
|
||||||
|
|
||||||
BottomSheetDraftsFragment bottomSheet = new BottomSheetDraftsFragment();
|
BottomSheetDraftsFragment bottomSheet = new BottomSheetDraftsFragment();
|
||||||
bottomSheet.show(getSupportFragmentManager(), "draftsBottomSheet");
|
bottomSheet.show(getSupportFragmentManager(), "draftsBottomSheet");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void giteaVersion(final String instanceUrl) {
|
private void giteaVersion() {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
|
||||||
|
|
||||||
Call<GiteaVersion> callVersion = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithToken(token);
|
|
||||||
|
|
||||||
|
Call<GiteaVersion> callVersion = RetrofitClient.getApiInterface(ctx).getGiteaVersionWithToken(Authorization.get(ctx));
|
||||||
callVersion.enqueue(new Callback<GiteaVersion>() {
|
callVersion.enqueue(new Callback<GiteaVersion>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull final Call<GiteaVersion> callVersion, @NonNull retrofit2.Response<GiteaVersion> responseVersion) {
|
public void onResponse(@NonNull final Call<GiteaVersion> callVersion, @NonNull retrofit2.Response<GiteaVersion> responseVersion) {
|
||||||
|
|
||||||
if(responseVersion.code() == 200) {
|
if(responseVersion.code() == 200 && responseVersion.body() != null) {
|
||||||
|
String version = responseVersion.body().getVersion();
|
||||||
GiteaVersion version = responseVersion.body();
|
|
||||||
assert version != null;
|
|
||||||
|
|
||||||
tinyDb.putString("giteaVersion", version.getVersion());
|
|
||||||
|
|
||||||
|
tinyDB.putString("giteaVersion", version);
|
||||||
|
BaseApi.getInstance(ctx, UserAccountsApi.class).updateServerVersion(version, tinyDB.getInt("currentActiveAccountId"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<GiteaVersion> callVersion, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<GiteaVersion> callVersion, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure-version", t.toString());
|
Log.e("onFailure-version", t.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadUserInfo(String instanceUrl, String token, String loginUid) {
|
private void loadUserInfo(String token, String loginUid) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
|
|
||||||
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserInfo(Authorization.returnAuthentication(ctx, loginUid, token));
|
Call<UserInfo> call = RetrofitClient.getApiInterface(ctx).getUserInfo(Authorization.get(ctx));
|
||||||
|
|
||||||
call.enqueue(new Callback<UserInfo>() {
|
call.enqueue(new Callback<UserInfo>() {
|
||||||
|
|
||||||
@@ -658,6 +646,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
assert userDetails != null;
|
assert userDetails != null;
|
||||||
|
|
||||||
if(userDetails.getIs_admin() != null) {
|
if(userDetails.getIs_admin() != null) {
|
||||||
|
|
||||||
tinyDb.putBoolean("userIsAdmin", userDetails.getIs_admin());
|
tinyDb.putBoolean("userIsAdmin", userDetails.getIs_admin());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -665,9 +654,11 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
tinyDb.putInt("userId", userDetails.getId());
|
tinyDb.putInt("userId", userDetails.getId());
|
||||||
|
|
||||||
if(!userDetails.getFullname().equals("")) {
|
if(!userDetails.getFullname().equals("")) {
|
||||||
|
|
||||||
tinyDb.putString("userFullname", userDetails.getFullname());
|
tinyDb.putString("userFullname", userDetails.getFullname());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
tinyDb.putString("userFullname", userDetails.getLogin());
|
tinyDb.putString("userFullname", userDetails.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -675,9 +666,11 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
tinyDb.putString("userAvatar", userDetails.getAvatar());
|
tinyDb.putString("userAvatar", userDetails.getAvatar());
|
||||||
|
|
||||||
if(userDetails.getLang() != null) {
|
if(userDetails.getLang() != null) {
|
||||||
|
|
||||||
tinyDb.putString("userLang", userDetails.getLang());
|
tinyDb.putString("userLang", userDetails.getLang());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
tinyDb.putString("userLang", "");
|
tinyDb.putString("userLang", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -685,15 +678,12 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
String toastError = getResources().getString(R.string.genericApiStatusError) + response.code();
|
String toastError = getResources().getString(R.string.genericApiStatusError) + response.code();
|
||||||
Toasty.error(ctx, toastError);
|
Toasty.error(ctx, toastError);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -705,4 +695,31 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getNotificationsCount(String token) {
|
||||||
|
|
||||||
|
Call<NotificationCount> call = RetrofitClient.getApiInterface(ctx).checkUnreadNotifications(token);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<NotificationCount>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<NotificationCount> call, @NonNull retrofit2.Response<NotificationCount> response) {
|
||||||
|
|
||||||
|
NotificationCount notificationCount = response.body();
|
||||||
|
|
||||||
|
if(response.code() == 200) {
|
||||||
|
|
||||||
|
assert notificationCount != null;
|
||||||
|
notificationCounter = navNotifications.getActionView().findViewById(R.id.counterBadgeNotification);
|
||||||
|
notificationCounter.setText(String.valueOf(notificationCount.getCounter()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<NotificationCount> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
Log.e("onFailure-notification", t.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,30 +6,24 @@ import android.os.Bundle;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.hendraanggrian.appcompat.socialview.Mention;
|
import org.gitnex.tea4j.models.MergePullRequest;
|
||||||
import com.hendraanggrian.appcompat.widget.MentionArrayAdapter;
|
import org.gitnex.tea4j.models.MergePullRequestSpinner;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.actions.PullRequestActions;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
import org.mian.gitnex.databinding.ActivityMergePullRequestBinding;
|
import org.mian.gitnex.databinding.ActivityMergePullRequestBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.models.Collaborators;
|
|
||||||
import org.mian.gitnex.models.MergePullRequest;
|
|
||||||
import org.mian.gitnex.models.MergePullRequestSpinner;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.Objects;
|
||||||
import okhttp3.ResponseBody;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -38,32 +32,31 @@ import retrofit2.Response;
|
|||||||
public class MergePullRequestActivity extends BaseActivity {
|
public class MergePullRequestActivity extends BaseActivity {
|
||||||
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
private String repoOwner;
|
||||||
|
private String repoName;
|
||||||
|
private int prIndex;
|
||||||
|
|
||||||
private ActivityMergePullRequestBinding viewBinding;
|
private ActivityMergePullRequestBinding viewBinding;
|
||||||
|
|
||||||
private ArrayAdapter<Mention> defaultMentionAdapter;
|
|
||||||
private String Do;
|
private String Do;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_merge_pull_request;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
viewBinding = ActivityMergePullRequestBinding.inflate(getLayoutInflater());
|
viewBinding = ActivityMergePullRequestBinding.inflate(getLayoutInflater());
|
||||||
View view = viewBinding.getRoot();
|
setContentView(viewBinding.getRoot());
|
||||||
setContentView(view);
|
|
||||||
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
|
String[] parts = repoFullName.split("/");
|
||||||
|
repoOwner = parts[0];
|
||||||
|
repoName = parts[1];
|
||||||
|
prIndex = Integer.parseInt(tinyDB.getString("issueNumber"));
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
@@ -73,53 +66,37 @@ public class MergePullRequestActivity extends BaseActivity {
|
|||||||
|
|
||||||
setMergeAdapter();
|
setMergeAdapter();
|
||||||
|
|
||||||
viewBinding.mergeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
if(!tinyDB.getString("issueTitle").isEmpty()) {
|
||||||
|
|
||||||
@Override
|
viewBinding.toolbarTitle.setText(tinyDB.getString("issueTitle"));
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
viewBinding.mergeTitle.setText(tinyDB.getString("issueTitle") + " (#" + tinyDB.getString("issueNumber") + ")");
|
||||||
|
|
||||||
MergePullRequestSpinner mergeId = (MergePullRequestSpinner) parent.getSelectedItem();
|
|
||||||
Do = mergeId.getId();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
defaultMentionAdapter = new MentionArrayAdapter<>(this);
|
|
||||||
loadCollaboratorsList();
|
|
||||||
|
|
||||||
viewBinding.mergeDescription.setMentionAdapter(defaultMentionAdapter);
|
|
||||||
|
|
||||||
if(!tinyDb.getString("issueTitle").isEmpty()) {
|
|
||||||
viewBinding.toolbarTitle.setText(tinyDb.getString("issueTitle"));
|
|
||||||
viewBinding.mergeTitle.setText(tinyDb.getString("issueTitle") + " (#" + tinyDb.getString("issueNumber") + ")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
viewBinding.close.setOnClickListener(onClickListener);
|
viewBinding.close.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
// if gitea version is greater/equal(1.12.0) than user installed version (installed.higherOrEqual(compareVer))
|
// if gitea version is greater/equal(1.12.0) than user installed version (installed.higherOrEqual(compareVer))
|
||||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||||
|
|
||||||
viewBinding.deleteBranch.setVisibility(View.VISIBLE);
|
viewBinding.deleteBranch.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tinyDb.getString("prMergeable").equals("false")) {
|
if(tinyDB.getString("prMergeable").equals("false")) {
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
viewBinding.mergeInfoDisabledMessage.setVisibility(View.VISIBLE);
|
viewBinding.mergeInfoDisabledMessage.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
viewBinding.mergeInfoDisabledMessage.setVisibility(View.GONE);
|
viewBinding.mergeInfoDisabledMessage.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tinyDb.getString("prIsFork").equals("true")) {
|
if(tinyDB.getString("prIsFork").equals("true")) {
|
||||||
|
|
||||||
viewBinding.deleteBranchForkInfo.setVisibility(View.VISIBLE);
|
viewBinding.deleteBranchForkInfo.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
viewBinding.deleteBranchForkInfo.setVisibility(View.GONE);
|
viewBinding.deleteBranchForkInfo.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,70 +113,25 @@ public class MergePullRequestActivity extends BaseActivity {
|
|||||||
|
|
||||||
private void setMergeAdapter() {
|
private void setMergeAdapter() {
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
ArrayList<MergePullRequestSpinner> mergeList = new ArrayList<>();
|
ArrayList<MergePullRequestSpinner> mergeList = new ArrayList<>();
|
||||||
|
|
||||||
mergeList.add(new MergePullRequestSpinner("merge", getResources().getString(R.string.mergeOptionMerge)));
|
mergeList.add(new MergePullRequestSpinner("merge", getResources().getString(R.string.mergeOptionMerge)));
|
||||||
mergeList.add(new MergePullRequestSpinner("rebase", getResources().getString(R.string.mergeOptionRebase)));
|
mergeList.add(new MergePullRequestSpinner("rebase", getResources().getString(R.string.mergeOptionRebase)));
|
||||||
mergeList.add(new MergePullRequestSpinner("rebase-merge", getResources().getString(R.string.mergeOptionRebaseCommit)));
|
mergeList.add(new MergePullRequestSpinner("rebase-merge", getResources().getString(R.string.mergeOptionRebaseCommit)));
|
||||||
// squash merge works only on gitea > v1.11.4 due to a bug
|
// squash merge works only on gitea > v1.11.4 due to a bug
|
||||||
if(new Version(tinyDb.getString("giteaVersion")).higher("1.11.4")) {
|
if(new Version(tinyDB.getString("giteaVersion")).higher("1.11.4")) {
|
||||||
|
|
||||||
mergeList.add(new MergePullRequestSpinner("squash", getResources().getString(R.string.mergeOptionSquash)));
|
mergeList.add(new MergePullRequestSpinner("squash", getResources().getString(R.string.mergeOptionSquash)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayAdapter<MergePullRequestSpinner> adapter = new ArrayAdapter<>(MergePullRequestActivity.this, R.layout.spinner_item, mergeList);
|
ArrayAdapter<MergePullRequestSpinner> adapter = new ArrayAdapter<>(MergePullRequestActivity.this, R.layout.list_spinner_items, mergeList);
|
||||||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
|
||||||
viewBinding.mergeSpinner.setAdapter(adapter);
|
viewBinding.mergeSpinner.setAdapter(adapter);
|
||||||
|
|
||||||
}
|
viewBinding.mergeSpinner.setOnItemClickListener ((parent, view, position, id) -> {
|
||||||
|
|
||||||
public void loadCollaboratorsList() {
|
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
|
|
||||||
Call<List<Collaborators>> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Collaborators>>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
|
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
|
||||||
|
|
||||||
assert response.body() != null;
|
|
||||||
String fullName = "";
|
|
||||||
for(int i = 0; i < response.body().size(); i++) {
|
|
||||||
if(!response.body().get(i).getFull_name().equals("")) {
|
|
||||||
fullName = response.body().get(i).getFull_name();
|
|
||||||
}
|
|
||||||
defaultMentionAdapter.add(new Mention(response.body().get(i).getUsername(), fullName, response.body().get(i).getAvatar_url()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Log.i("onResponse", String.valueOf(response.code()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
|
|
||||||
|
|
||||||
Log.i("onFailure", t.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Do = mergeList.get(position).getId();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
@@ -207,12 +139,12 @@ public class MergePullRequestActivity extends BaseActivity {
|
|||||||
onClickListener = view -> finish();
|
onClickListener = view -> finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener mergePullRequest = v -> processMergePullRequest();
|
private final View.OnClickListener mergePullRequest = v -> processMergePullRequest();
|
||||||
|
|
||||||
private void processMergePullRequest() {
|
private void processMergePullRequest() {
|
||||||
|
|
||||||
String mergePRDesc = viewBinding.mergeDescription.getText().toString();
|
String mergePRDesc = Objects.requireNonNull(viewBinding.mergeDescription.getText()).toString();
|
||||||
String mergePRTitle = viewBinding.mergeTitle.getText().toString();
|
String mergePRTitle = Objects.requireNonNull(viewBinding.mergeTitle.getText()).toString();
|
||||||
boolean deleteBranch = viewBinding.deleteBranch.isChecked();
|
boolean deleteBranch = viewBinding.deleteBranch.isChecked();
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
@@ -221,79 +153,70 @@ public class MergePullRequestActivity extends BaseActivity {
|
|||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disableProcessButton();
|
if(Do == null) {
|
||||||
mergeFunction(Do, mergePRDesc, mergePRTitle, deleteBranch);
|
|
||||||
|
|
||||||
|
Toasty.error(ctx, getResources().getString(R.string.selectMergeStrategy));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
disableProcessButton();
|
||||||
|
mergeFunction(Do, mergePRDesc, mergePRTitle, deleteBranch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeFunction(String Do, String mergePRDT, String mergeTitle, boolean deleteBranch) {
|
private void mergeFunction(String Do, String mergePRDT, String mergeTitle, boolean deleteBranch) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
final int prIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
|
|
||||||
|
|
||||||
MergePullRequest mergePR = new MergePullRequest(Do, mergePRDT, mergeTitle);
|
MergePullRequest mergePR = new MergePullRequest(Do, mergePRDT, mergeTitle);
|
||||||
|
|
||||||
Call<ResponseBody> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().mergePullRequest(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, prIndex, mergePR);
|
Call<Void> call = RetrofitClient.getApiInterface(ctx).mergePullRequest(Authorization.get(ctx), repoOwner, repoName, prIndex, mergePR);
|
||||||
|
|
||||||
call.enqueue(new Callback<ResponseBody>() {
|
call.enqueue(new Callback<Void>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull retrofit2.Response<ResponseBody> response) {
|
public void onResponse(@NonNull Call<Void> call, @NonNull retrofit2.Response<Void> response) {
|
||||||
|
|
||||||
if(response.code() == 200) {
|
if(response.code() == 200) {
|
||||||
|
|
||||||
if(deleteBranch) {
|
if(deleteBranch) {
|
||||||
|
|
||||||
if(tinyDb.getString("prIsFork").equals("true")) {
|
if(tinyDB.getString("prIsFork").equals("true")) {
|
||||||
|
|
||||||
String repoFullName = tinyDb.getString("prForkFullName");
|
String repoFullName = tinyDB.getString("prForkFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
|
|
||||||
deleteBranchFunction(repoOwner, repoName);
|
PullRequestActions.deleteHeadBranch(ctx, repoOwner, repoName, tinyDB.getString("prHeadBranch"), false);
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
|
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
|
||||||
tinyDb.putBoolean("prMerged", true);
|
tinyDB.putBoolean("prMerged", true);
|
||||||
tinyDb.putBoolean("resumePullRequests", true);
|
tinyDB.putBoolean("resumePullRequests", true);
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
String[] parts = repoFullName.split("/");
|
String[] parts = repoFullName.split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
|
|
||||||
deleteBranchFunction(repoOwner, repoName);
|
PullRequestActions.deleteHeadBranch(ctx, repoOwner, repoName, tinyDB.getString("prHeadBranch"), false);
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
|
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
|
||||||
tinyDb.putBoolean("prMerged", true);
|
tinyDB.putBoolean("prMerged", true);
|
||||||
tinyDb.putBoolean("resumePullRequests", true);
|
tinyDB.putBoolean("resumePullRequests", true);
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
|
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
|
||||||
tinyDb.putBoolean("prMerged", true);
|
tinyDB.putBoolean("prMerged", true);
|
||||||
tinyDb.putBoolean("resumePullRequests", true);
|
tinyDB.putBoolean("resumePullRequests", true);
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -301,25 +224,27 @@ public class MergePullRequestActivity extends BaseActivity {
|
|||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 404) {
|
else if(response.code() == 404) {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.warning(ctx, getString(R.string.mergePR404ErrorMsg));
|
Toasty.warning(ctx, getString(R.string.mergePR404ErrorMsg));
|
||||||
|
}
|
||||||
|
else if(response.code() == 405) {
|
||||||
|
|
||||||
|
enableProcessButton();
|
||||||
|
Toasty.warning(ctx, getString(R.string.mergeNotAllowed));;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.error(ctx, getString(R.string.genericError));
|
Toasty.error(ctx, getString(R.string.genericError));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
@@ -329,45 +254,6 @@ public class MergePullRequestActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteBranchFunction(String repoOwner, String repoName) {
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
String loginUid = tinyDb.getString("loginUid");
|
|
||||||
String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String branchName = tinyDb.getString("prHeadBranch");
|
|
||||||
|
|
||||||
Call<JsonElement> call = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.deleteBranch(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, branchName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
|
||||||
|
|
||||||
if(response.code() == 204) {
|
|
||||||
|
|
||||||
Log.i("deleteBranch", "Branch deleted successfully");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
|
||||||
enableProcessButton();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void disableProcessButton() {
|
private void disableProcessButton() {
|
||||||
|
|
||||||
viewBinding.mergeButton.setEnabled(false);
|
viewBinding.mergeButton.setEnabled(false);
|
||||||
|
|||||||
@@ -11,14 +11,15 @@ import android.widget.EditText;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import org.gitnex.tea4j.models.AddEmail;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityProfileEmailBinding;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.AddEmail;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -29,32 +30,27 @@ import retrofit2.Callback;
|
|||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ProfileEmailActivity extends BaseActivity {
|
public class MyProfileEmailActivity extends BaseActivity {
|
||||||
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
private EditText userEmail;
|
private EditText userEmail;
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private Button addEmailButton;
|
private Button addEmailButton;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_profile_email;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
ActivityProfileEmailBinding activityProfileEmailBinding = ActivityProfileEmailBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityProfileEmailBinding.getRoot());
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activityProfileEmailBinding.close;
|
||||||
userEmail = findViewById(R.id.userEmail);
|
userEmail = activityProfileEmailBinding.userEmail;
|
||||||
addEmailButton = findViewById(R.id.addEmailButton);
|
addEmailButton = activityProfileEmailBinding.addEmailButton;
|
||||||
|
|
||||||
userEmail.requestFocus();
|
userEmail.requestFocus();
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
@@ -73,19 +69,11 @@ public class ProfileEmailActivity extends BaseActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private View.OnClickListener addEmailListener = new View.OnClickListener() {
|
private final View.OnClickListener addEmailListener = v -> processAddNewEmail();
|
||||||
public void onClick(View v) {
|
|
||||||
processAddNewEmail();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void processAddNewEmail() {
|
private void processAddNewEmail() {
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
String newUserEmail = userEmail.getText().toString().trim();
|
String newUserEmail = userEmail.getText().toString().trim();
|
||||||
|
|
||||||
@@ -93,39 +81,34 @@ public class ProfileEmailActivity extends BaseActivity {
|
|||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newUserEmail.equals("")) {
|
if(newUserEmail.equals("")) {
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.emailErrorEmpty));
|
Toasty.error(ctx, getString(R.string.emailErrorEmpty));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(!Patterns.EMAIL_ADDRESS.matcher(newUserEmail).matches()) {
|
else if(!Patterns.EMAIL_ADDRESS.matcher(newUserEmail).matches()) {
|
||||||
|
|
||||||
Toasty.warning(ctx, getString(R.string.emailErrorInvalid));
|
Toasty.warning(ctx, getString(R.string.emailErrorInvalid));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> newEmailList = new ArrayList<>(Arrays.asList(newUserEmail.split(",")));
|
List<String> newEmailList = new ArrayList<>(Arrays.asList(newUserEmail.split(",")));
|
||||||
|
|
||||||
disableProcessButton();
|
disableProcessButton();
|
||||||
addNewEmail(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), newEmailList);
|
addNewEmail(Authorization.get(ctx), newEmailList);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNewEmail(final String instanceUrl, final String token, List<String> newUserEmail) {
|
private void addNewEmail(final String token, List<String> newUserEmail) {
|
||||||
|
|
||||||
AddEmail addEmailFunc = new AddEmail(newUserEmail);
|
AddEmail addEmailFunc = new AddEmail(newUserEmail);
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
|
|
||||||
Call<JsonElement> call;
|
Call<JsonElement> call;
|
||||||
|
|
||||||
call = RetrofitClient
|
call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(appCtx)
|
||||||
.getApiInterface()
|
|
||||||
.addNewEmail(token, addEmailFunc);
|
.addNewEmail(token, addEmailFunc);
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
@@ -139,7 +122,6 @@ public class ProfileEmailActivity extends BaseActivity {
|
|||||||
tinyDb.putBoolean("emailsRefresh", true);
|
tinyDb.putBoolean("emailsRefresh", true);
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 401) {
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
@@ -148,37 +130,32 @@ public class ProfileEmailActivity extends BaseActivity {
|
|||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 403) {
|
else if(response.code() == 403) {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 404) {
|
else if(response.code() == 404) {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 422) {
|
else if(response.code() == 422) {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.emailErrorInUse));
|
Toasty.warning(ctx, ctx.getString(R.string.emailErrorInUse));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e("onFailure", t.toString());
|
Log.e("onFailure", t.toString());
|
||||||
enableProcessButton();
|
enableProcessButton();
|
||||||
}
|
}
|
||||||
@@ -25,8 +25,9 @@ public class OpenRepoInBrowserActivity extends AppCompatActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
appCtx = getApplicationContext();
|
appCtx = getApplicationContext();
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -46,9 +47,9 @@ public class OpenRepoInBrowserActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
catch(URISyntaxException e) {
|
catch(URISyntaxException e) {
|
||||||
|
|
||||||
Toasty.error(appCtx, getString(R.string.genericError));
|
Toasty.error(appCtx, getString(R.string.genericError));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ import org.mian.gitnex.R;
|
|||||||
import org.mian.gitnex.fragments.BottomSheetOrganizationFragment;
|
import org.mian.gitnex.fragments.BottomSheetOrganizationFragment;
|
||||||
import org.mian.gitnex.fragments.MembersByOrgFragment;
|
import org.mian.gitnex.fragments.MembersByOrgFragment;
|
||||||
import org.mian.gitnex.fragments.OrganizationInfoFragment;
|
import org.mian.gitnex.fragments.OrganizationInfoFragment;
|
||||||
|
import org.mian.gitnex.fragments.OrganizationLabelsFragment;
|
||||||
import org.mian.gitnex.fragments.RepositoriesByOrgFragment;
|
import org.mian.gitnex.fragments.RepositoriesByOrgFragment;
|
||||||
import org.mian.gitnex.fragments.TeamsByOrgFragment;
|
import org.mian.gitnex.fragments.TeamsByOrgFragment;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import io.mikael.urlbuilder.UrlBuilder;
|
import io.mikael.urlbuilder.UrlBuilder;
|
||||||
@@ -36,27 +36,17 @@ import io.mikael.urlbuilder.UrlBuilder;
|
|||||||
|
|
||||||
public class OrganizationDetailActivity extends BaseActivity implements BottomSheetOrganizationFragment.BottomSheetListener {
|
public class OrganizationDetailActivity extends BaseActivity implements BottomSheetOrganizationFragment.BottomSheetListener {
|
||||||
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private TinyDB tinyDb;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_org_detail;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
setContentView(R.layout.activity_org_detail);
|
||||||
String orgName = tinyDb.getString("orgName");
|
|
||||||
|
String orgName = tinyDB.getString("orgName");
|
||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
TextView toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
|
TextView toolbarTitle = findViewById(R.id.toolbar_title);
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
Objects.requireNonNull(getSupportActionBar()).setTitle(orgName);
|
Objects.requireNonNull(getSupportActionBar()).setTitle(orgName);
|
||||||
@@ -71,20 +61,20 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
|||||||
|
|
||||||
Typeface myTypeface;
|
Typeface myTypeface;
|
||||||
|
|
||||||
switch(tinyDb.getInt("customFontId", -1)) {
|
switch(tinyDB.getInt("customFontId", -1)) {
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
|
|
||||||
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/roboto.ttf");
|
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/roboto.ttf");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
|
||||||
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/sourcecodeproregular.ttf");
|
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/sourcecodeproregular.ttf");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/manroperegular.ttf");
|
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/manroperegular.ttf");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toolbarTitle.setTypeface(myTypeface);
|
toolbarTitle.setTypeface(myTypeface);
|
||||||
@@ -92,12 +82,18 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
|||||||
|
|
||||||
ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
|
ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
|
||||||
int tabsCount = vg.getChildCount();
|
int tabsCount = vg.getChildCount();
|
||||||
|
|
||||||
for (int j = 0; j < tabsCount; j++) {
|
for (int j = 0; j < tabsCount; j++) {
|
||||||
|
|
||||||
ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
|
ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
|
||||||
int tabChildCount = vgTab.getChildCount();
|
int tabChildCount = vgTab.getChildCount();
|
||||||
|
|
||||||
for (int i = 0; i < tabChildCount; i++) {
|
for (int i = 0; i < tabChildCount; i++) {
|
||||||
|
|
||||||
View tabViewChild = vgTab.getChildAt(i);
|
View tabViewChild = vgTab.getChildAt(i);
|
||||||
|
|
||||||
if (tabViewChild instanceof TextView) {
|
if (tabViewChild instanceof TextView) {
|
||||||
|
|
||||||
((TextView) tabViewChild).setTypeface(myTypeface);
|
((TextView) tabViewChild).setTypeface(myTypeface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,7 +101,6 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
|||||||
|
|
||||||
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
|
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
|
||||||
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
|
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -122,18 +117,21 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
|||||||
|
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
|
|
||||||
switch (id) {
|
if(id == android.R.id.home) {
|
||||||
case android.R.id.home:
|
|
||||||
finish();
|
|
||||||
return true;
|
|
||||||
case R.id.repoMenu:
|
|
||||||
BottomSheetOrganizationFragment bottomSheet = new BottomSheetOrganizationFragment();
|
|
||||||
bottomSheet.show(getSupportFragmentManager(), "orgBottomSheet");
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(id == R.id.repoMenu) {
|
||||||
|
|
||||||
|
BottomSheetOrganizationFragment bottomSheet = new BottomSheetOrganizationFragment();
|
||||||
|
bottomSheet.show(getSupportFragmentManager(), "orgBottomSheet");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -142,20 +140,27 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
|||||||
switch (text) {
|
switch (text) {
|
||||||
case "repository":
|
case "repository":
|
||||||
|
|
||||||
tinyDb.putBoolean("organizationAction", true);
|
tinyDB.putBoolean("organizationAction", true);
|
||||||
startActivity(new Intent(OrganizationDetailActivity.this, CreateRepoActivity.class));
|
startActivity(new Intent(OrganizationDetailActivity.this, CreateRepoActivity.class));
|
||||||
break;
|
break;
|
||||||
|
case "label":
|
||||||
|
|
||||||
|
Intent intent = new Intent(ctx, CreateLabelActivity.class);
|
||||||
|
intent.putExtra("orgName", getIntent().getStringExtra("orgName"));
|
||||||
|
intent.putExtra("type", "org");
|
||||||
|
ctx.startActivity(intent);
|
||||||
|
break;
|
||||||
case "team":
|
case "team":
|
||||||
|
|
||||||
startActivity(new Intent(OrganizationDetailActivity.this, CreateTeamByOrgActivity.class));
|
startActivity(new Intent(OrganizationDetailActivity.this, CreateTeamByOrgActivity.class));
|
||||||
break;
|
break;
|
||||||
case "copyOrgUrl":
|
case "copyOrgUrl":
|
||||||
|
|
||||||
String url = UrlBuilder.fromString(tinyDb.getString("instanceUrl"))
|
String url = UrlBuilder.fromString(tinyDB.getString("instanceUrl"))
|
||||||
.withPath("/")
|
.withPath("/")
|
||||||
.toString();
|
.toString();
|
||||||
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
ClipData clip = ClipData.newPlainText("orgUrl", url + tinyDb.getString("orgName"));
|
ClipData clip = ClipData.newPlainText("orgUrl", url + tinyDB.getString("orgName"));
|
||||||
assert clipboard != null;
|
assert clipboard != null;
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
Toasty.info(ctx, ctx.getString(R.string.copyIssueUrlToastMsg));
|
Toasty.info(ctx, ctx.getString(R.string.copyIssueUrlToastMsg));
|
||||||
@@ -175,30 +180,39 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
|||||||
|
|
||||||
String orgName;
|
String orgName;
|
||||||
if(getIntent().getStringExtra("orgName") != null || !Objects.equals(getIntent().getStringExtra("orgName"), "")) {
|
if(getIntent().getStringExtra("orgName") != null || !Objects.equals(getIntent().getStringExtra("orgName"), "")) {
|
||||||
|
|
||||||
orgName = getIntent().getStringExtra("orgName");
|
orgName = getIntent().getStringExtra("orgName");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
orgName = tinyDb.getString("orgName");
|
|
||||||
|
orgName = tinyDB.getString("orgName");
|
||||||
}
|
}
|
||||||
|
|
||||||
Fragment fragment = null;
|
Fragment fragment = null;
|
||||||
switch (position) {
|
switch (position) {
|
||||||
|
|
||||||
case 0: // info
|
case 0: // info
|
||||||
|
|
||||||
return OrganizationInfoFragment.newInstance(orgName);
|
return OrganizationInfoFragment.newInstance(orgName);
|
||||||
case 1: // repos
|
case 1: // repos
|
||||||
return RepositoriesByOrgFragment.newInstance(orgName);
|
|
||||||
case 2: // teams
|
return RepositoriesByOrgFragment.newInstance(orgName);
|
||||||
|
case 2: // labels
|
||||||
|
|
||||||
|
return OrganizationLabelsFragment.newInstance(orgName);
|
||||||
|
case 3: // teams
|
||||||
|
|
||||||
return TeamsByOrgFragment.newInstance(orgName);
|
return TeamsByOrgFragment.newInstance(orgName);
|
||||||
case 3: // members
|
case 4: // members
|
||||||
|
|
||||||
return MembersByOrgFragment.newInstance(orgName);
|
return MembersByOrgFragment.newInstance(orgName);
|
||||||
}
|
}
|
||||||
return fragment;
|
return fragment;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return 4;
|
return 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -15,6 +14,7 @@ import androidx.appcompat.widget.Toolbar;
|
|||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.adapters.TeamMembersByOrgAdapter;
|
import org.mian.gitnex.adapters.TeamMembersByOrgAdapter;
|
||||||
|
import org.mian.gitnex.databinding.ActivityOrgTeamMembersBinding;
|
||||||
import org.mian.gitnex.fragments.BottomSheetOrganizationTeamsFragment;
|
import org.mian.gitnex.fragments.BottomSheetOrganizationTeamsFragment;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
@@ -33,85 +33,78 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
|
|||||||
private GridView mGridView;
|
private GridView mGridView;
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
private String teamId;
|
private String teamId;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_org_team_members;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
ActivityOrgTeamMembersBinding activityOrgTeamMembersBinding = ActivityOrgTeamMembersBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityOrgTeamMembersBinding.getRoot());
|
||||||
|
|
||||||
|
Toolbar toolbar = activityOrgTeamMembersBinding.toolbar;
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
ImageView closeActivity = activityOrgTeamMembersBinding.close;
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
TextView toolbarTitle = activityOrgTeamMembersBinding.toolbarTitle;
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
noDataMembers = activityOrgTeamMembersBinding.noDataMembers;
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
mGridView = activityOrgTeamMembersBinding.gridView;
|
||||||
|
progressBar = activityOrgTeamMembersBinding.progressBar;
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
|
||||||
TextView toolbarTitle = findViewById(R.id.toolbar_title);
|
|
||||||
noDataMembers = findViewById(R.id.noDataMembers);
|
|
||||||
mGridView = findViewById(R.id.gridView);
|
|
||||||
progressBar = findViewById(R.id.progressBar);
|
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
if(getIntent().getStringExtra("teamTitle") != null && !Objects.requireNonNull(getIntent().getStringExtra("teamTitle")).equals("")) {
|
if(getIntent().getStringExtra("teamTitle") != null && !Objects.requireNonNull(getIntent().getStringExtra("teamTitle")).equals("")) {
|
||||||
toolbarTitle.setText(getIntent().getStringExtra("teamTitle"));
|
|
||||||
|
toolbarTitle.setText(getIntent().getStringExtra("teamTitle"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
toolbarTitle.setText(R.string.orgTeamMembers);
|
|
||||||
|
toolbarTitle.setText(R.string.orgTeamMembers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getIntent().getStringExtra("teamId") != null && !Objects.requireNonNull(getIntent().getStringExtra("teamId")).equals("")){
|
if(getIntent().getStringExtra("teamId") != null && !Objects.requireNonNull(getIntent().getStringExtra("teamId")).equals("")){
|
||||||
teamId = getIntent().getStringExtra("teamId");
|
|
||||||
|
teamId = getIntent().getStringExtra("teamId");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
teamId = "0";
|
|
||||||
|
teamId = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
assert teamId != null;
|
assert teamId != null;
|
||||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), Integer.parseInt(teamId));
|
fetchDataAsync(Authorization.get(ctx), Integer.parseInt(teamId));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
|
|
||||||
super.onResume();
|
super.onResume();
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
if(tinyDb.getBoolean("teamActionFlag")) {
|
if(tinyDb.getBoolean("teamActionFlag")) {
|
||||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), Integer.parseInt(teamId));
|
|
||||||
|
fetchDataAsync(Authorization.get(ctx), Integer.parseInt(teamId));
|
||||||
tinyDb.putBoolean("teamActionFlag", false);
|
tinyDb.putBoolean("teamActionFlag", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchDataAsync(String instanceUrl, String instanceToken, int teamId) {
|
private void fetchDataAsync(String instanceToken, int teamId) {
|
||||||
|
|
||||||
TeamMembersByOrgViewModel teamMembersModel = new ViewModelProvider(this).get(TeamMembersByOrgViewModel.class);
|
TeamMembersByOrgViewModel teamMembersModel = new ViewModelProvider(this).get(TeamMembersByOrgViewModel.class);
|
||||||
|
|
||||||
teamMembersModel.getMembersByOrgList(instanceUrl, instanceToken, teamId, ctx).observe(this, teamMembersListMain -> {
|
teamMembersModel.getMembersByOrgList(instanceToken, teamId, ctx).observe(this, teamMembersListMain -> {
|
||||||
|
|
||||||
adapter = new TeamMembersByOrgAdapter(ctx, teamMembersListMain);
|
adapter = new TeamMembersByOrgAdapter(ctx, teamMembersListMain);
|
||||||
|
|
||||||
if(adapter.getCount() > 0) {
|
if(adapter.getCount() > 0) {
|
||||||
|
|
||||||
mGridView.setAdapter(adapter);
|
mGridView.setAdapter(adapter);
|
||||||
noDataMembers.setVisibility(View.GONE);
|
noDataMembers.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
mGridView.setAdapter(adapter);
|
mGridView.setAdapter(adapter);
|
||||||
noDataMembers.setVisibility(View.VISIBLE);
|
noDataMembers.setVisibility(View.VISIBLE);
|
||||||
@@ -119,7 +112,6 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
|
|||||||
|
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -128,7 +120,6 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
|
|||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -136,31 +127,32 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
|
|||||||
|
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
|
|
||||||
switch(id) {
|
if(id == android.R.id.home) {
|
||||||
case android.R.id.home:
|
|
||||||
finish();
|
|
||||||
return true;
|
|
||||||
case R.id.genericMenu:
|
|
||||||
BottomSheetOrganizationTeamsFragment bottomSheet = new BottomSheetOrganizationTeamsFragment();
|
|
||||||
bottomSheet.show(getSupportFragmentManager(), "orgTeamsBottomSheet");
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(id == R.id.genericMenu) {
|
||||||
|
|
||||||
|
BottomSheetOrganizationTeamsFragment bottomSheet = new BottomSheetOrganizationTeamsFragment();
|
||||||
|
bottomSheet.show(getSupportFragmentManager(), "orgTeamsBottomSheet");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onButtonClicked(String text) {
|
public void onButtonClicked(String text) {
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
if("newMember".equals(text)) {
|
if("newMember".equals(text)) {
|
||||||
|
|
||||||
Intent intent = new Intent(OrganizationTeamMembersActivity.this, AddNewTeamMemberActivity.class);
|
Intent intent = new Intent(OrganizationTeamMembersActivity.this, AddNewTeamMemberActivity.class);
|
||||||
intent.putExtra("teamId", teamId);
|
intent.putExtra("teamId", teamId);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||||
|
import androidx.viewpager2.widget.ViewPager2;
|
||||||
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
import com.google.android.material.tabs.TabLayoutMediator;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.fragments.profile.DetailFragment;
|
||||||
|
import org.mian.gitnex.fragments.profile.FollowersFragment;
|
||||||
|
import org.mian.gitnex.fragments.profile.FollowingFragment;
|
||||||
|
import org.mian.gitnex.fragments.profile.OrganizationsFragment;
|
||||||
|
import org.mian.gitnex.fragments.profile.RepositoriesFragment;
|
||||||
|
import org.mian.gitnex.fragments.profile.StarredRepositoriesFragment;
|
||||||
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ProfileActivity extends BaseActivity {
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_profile);
|
||||||
|
Intent profileIntent = getIntent();
|
||||||
|
Typeface myTypeface;
|
||||||
|
|
||||||
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
|
TextView toolbarTitle = findViewById(R.id.toolbarTitle);
|
||||||
|
|
||||||
|
if(profileIntent.getStringExtra("username") != null && !Objects.equals(profileIntent.getStringExtra("username"), "")) {
|
||||||
|
username = profileIntent.getStringExtra("username");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Toasty.warning(ctx, ctx.getResources().getString(R.string.userInvalidUserName));
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
Objects.requireNonNull(getSupportActionBar()).setTitle(username);
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
ViewPager2 viewPager = findViewById(R.id.profileContainer);
|
||||||
|
viewPager.setOffscreenPageLimit(1);
|
||||||
|
TabLayout tabLayout = findViewById(R.id.tabs);
|
||||||
|
|
||||||
|
switch(tinyDB.getInt("customFontId", -1)) {
|
||||||
|
case 0:
|
||||||
|
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/roboto.ttf");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/sourcecodeproregular.ttf");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/manroperegular.ttf");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
toolbarTitle.setTypeface(myTypeface);
|
||||||
|
toolbarTitle.setText(username);
|
||||||
|
|
||||||
|
viewPager.setAdapter(new ViewPagerAdapter(this));
|
||||||
|
|
||||||
|
String[] tabTitles = {ctx.getResources().getString(R.string.tabTextInfo), ctx.getResources().getString(R.string.navRepos), ctx.getResources().getString(R.string.navStarredRepos), ctx.getResources().getString(R.string.navOrg), ctx.getResources().getString(R.string.profileTabFollowers), ctx.getResources().getString(R.string.profileTabFollowing)};
|
||||||
|
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> tab.setText(tabTitles[position])).attach();
|
||||||
|
|
||||||
|
ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
|
||||||
|
int tabsCount = vg.getChildCount();
|
||||||
|
|
||||||
|
for (int j = 0; j < tabsCount; j++) {
|
||||||
|
|
||||||
|
ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
|
||||||
|
int tabChildCount = vgTab.getChildCount();
|
||||||
|
|
||||||
|
for (int i = 0; i < tabChildCount; i++) {
|
||||||
|
View tabViewChild = vgTab.getChildAt(i);
|
||||||
|
if (tabViewChild instanceof TextView) {
|
||||||
|
((TextView) tabViewChild).setTypeface(myTypeface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ViewPagerAdapter extends FragmentStateAdapter {
|
||||||
|
|
||||||
|
public ViewPagerAdapter(@NonNull FragmentActivity fa) { super(fa); }
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Fragment createFragment(int position) {
|
||||||
|
switch(position) {
|
||||||
|
case 0: // detail
|
||||||
|
return DetailFragment.newInstance(username);
|
||||||
|
case 1: // repos
|
||||||
|
return RepositoriesFragment.newInstance(username);
|
||||||
|
case 2: // starred repos
|
||||||
|
return StarredRepositoriesFragment.newInstance(username);
|
||||||
|
case 3: // organizations
|
||||||
|
return OrganizationsFragment.newInstance(username);
|
||||||
|
case 4: // followers
|
||||||
|
return FollowersFragment.newInstance(username);
|
||||||
|
case 5: // following
|
||||||
|
return FollowingFragment.newInstance(username);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
|
||||||
|
int id = item.getItemId();
|
||||||
|
|
||||||
|
if(id == android.R.id.home) {
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,426 +0,0 @@
|
|||||||
package org.mian.gitnex.activities;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
|
||||||
import com.hendraanggrian.appcompat.socialview.Mention;
|
|
||||||
import com.hendraanggrian.appcompat.widget.MentionArrayAdapter;
|
|
||||||
import com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView;
|
|
||||||
import org.mian.gitnex.R;
|
|
||||||
import org.mian.gitnex.actions.IssueActions;
|
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
|
||||||
import org.mian.gitnex.database.api.DraftsApi;
|
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
|
||||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
|
||||||
import org.mian.gitnex.models.Collaborators;
|
|
||||||
import org.mian.gitnex.models.Issues;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import retrofit2.Call;
|
|
||||||
import retrofit2.Callback;
|
|
||||||
import retrofit2.Response;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Author M M Arif
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class ReplyToIssueActivity extends BaseActivity {
|
|
||||||
|
|
||||||
public ImageView closeActivity;
|
|
||||||
private View.OnClickListener onClickListener;
|
|
||||||
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
private TextView draftSaved;
|
|
||||||
private SocialAutoCompleteTextView addComment;
|
|
||||||
private ArrayAdapter<Mention> defaultMentionAdapter;
|
|
||||||
private Button replyButton;
|
|
||||||
private String TAG = StaticGlobalVariables.replyToIssueActivity;
|
|
||||||
private long draftIdOnCreate;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_reply_to_issue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
appCtx = getApplicationContext();
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
||||||
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
draftSaved = findViewById(R.id.draftSaved);
|
|
||||||
addComment = findViewById(R.id.addComment);
|
|
||||||
addComment.setShowSoftInputOnFocus(true);
|
|
||||||
|
|
||||||
defaultMentionAdapter = new MentionArrayAdapter<>(ctx);
|
|
||||||
loadCollaboratorsList();
|
|
||||||
|
|
||||||
addComment.setMentionAdapter(defaultMentionAdapter);
|
|
||||||
|
|
||||||
closeActivity = findViewById(R.id.close);
|
|
||||||
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
|
||||||
|
|
||||||
addComment.requestFocus();
|
|
||||||
assert imm != null;
|
|
||||||
imm.showSoftInput(addComment, InputMethodManager.SHOW_IMPLICIT);
|
|
||||||
|
|
||||||
if(!tinyDb.getString("issueTitle").isEmpty()) {
|
|
||||||
toolbar_title.setText(tinyDb.getString("issueTitle"));
|
|
||||||
}
|
|
||||||
|
|
||||||
initCloseListener();
|
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
|
||||||
|
|
||||||
if(getIntent().getStringExtra("draftId") != null) {
|
|
||||||
|
|
||||||
draftIdOnCreate = Long.parseLong(Objects.requireNonNull(getIntent().getStringExtra("draftId")));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
draftIdOnCreate = returnDraftId();
|
|
||||||
}
|
|
||||||
|
|
||||||
replyButton = findViewById(R.id.replyButton);
|
|
||||||
|
|
||||||
if(getIntent().getStringExtra("commentBody") != null) {
|
|
||||||
|
|
||||||
addComment.setText(getIntent().getStringExtra("commentBody"));
|
|
||||||
|
|
||||||
if(getIntent().getBooleanExtra("cursorToEnd", false)) {
|
|
||||||
addComment.setSelection(addComment.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(getIntent().getStringExtra("draftTitle") != null) {
|
|
||||||
|
|
||||||
toolbar_title.setText(getIntent().getStringExtra("draftTitle"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(getIntent().getStringExtra("commentAction") != null && Objects.equals(getIntent().getStringExtra("commentAction"), "edit") && !Objects.equals(getIntent().getStringExtra("commentId"), "new")) {
|
|
||||||
|
|
||||||
final String commentId = getIntent().getStringExtra("commentId");
|
|
||||||
|
|
||||||
toolbar_title.setText(getResources().getString(R.string.editCommentTitle));
|
|
||||||
replyButton.setText(getResources().getString(R.string.editCommentButtonText));
|
|
||||||
|
|
||||||
addComment.addTextChangedListener(new TextWatcher() {
|
|
||||||
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
|
|
||||||
saveDraft(addComment.getText().toString(), commentId, draftIdOnCreate);
|
|
||||||
draftSaved.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
replyButton.setOnClickListener(v -> {
|
|
||||||
|
|
||||||
disableProcessButton();
|
|
||||||
assert commentId != null;
|
|
||||||
IssueActions.editIssueComment(ctx, Integer.parseInt(commentId), addComment.getText().toString(), draftIdOnCreate);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
addComment.addTextChangedListener(new TextWatcher() {
|
|
||||||
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
|
|
||||||
saveDraft(addComment.getText().toString(), "new", draftIdOnCreate);
|
|
||||||
draftSaved.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
if(!connToInternet) {
|
|
||||||
|
|
||||||
disableProcessButton();
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
replyButton.setOnClickListener(replyToIssue);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveDraft(String draftText, String commentId, long draftIdOnCreate) {
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
|
||||||
|
|
||||||
int repositoryId = (int) tinyDb.getLong("repositoryId", 0);
|
|
||||||
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
|
||||||
int issueNumber = Integer.parseInt(tinyDb.getString("issueNumber"));
|
|
||||||
|
|
||||||
DraftsApi draftsApi = new DraftsApi(appCtx);
|
|
||||||
|
|
||||||
if(draftIdOnCreate == 0) {
|
|
||||||
|
|
||||||
draftsApi.insertDraft(repositoryId, currentActiveAccountId, issueNumber, draftText, StaticGlobalVariables.draftTypeComment, commentId);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
DraftsApi.updateDraft(draftText, (int) draftIdOnCreate, commentId); //updateDraftByIssueIdAsyncTask(draftText, issueNumber, repositoryId, commentId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private long returnDraftId() {
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
|
||||||
|
|
||||||
int repositoryId = (int) tinyDb.getLong("repositoryId", 0);
|
|
||||||
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
|
||||||
int issueNumber = Integer.parseInt(tinyDb.getString("issueNumber"));
|
|
||||||
|
|
||||||
DraftsApi draftsApi = new DraftsApi(appCtx);
|
|
||||||
|
|
||||||
return draftsApi.insertDraft(repositoryId, currentActiveAccountId, issueNumber, "", StaticGlobalVariables.draftTypeComment, "");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadCollaboratorsList() {
|
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
|
|
||||||
Call<List<Collaborators>> call = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Collaborators>>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
|
|
||||||
|
|
||||||
if (response.isSuccessful()) {
|
|
||||||
|
|
||||||
assert response.body() != null;
|
|
||||||
String fullName = "";
|
|
||||||
for(int i = 0; i < response.body().size(); i++) {
|
|
||||||
if(!response.body().get(i).getFull_name().equals("")) {
|
|
||||||
fullName = response.body().get(i).getFull_name();
|
|
||||||
}
|
|
||||||
defaultMentionAdapter.add(new Mention(response.body().get(i).getUsername(), fullName, response.body().get(i).getAvatar_url()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Log.i(TAG, String.valueOf(response.code()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
|
|
||||||
|
|
||||||
Log.e(TAG, t.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initCloseListener() {
|
|
||||||
|
|
||||||
onClickListener = view -> finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
private View.OnClickListener replyToIssue = v -> processNewCommentReply();
|
|
||||||
|
|
||||||
private void processNewCommentReply() {
|
|
||||||
|
|
||||||
String newReplyDT = addComment.getText().toString();
|
|
||||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
|
||||||
|
|
||||||
if(!connToInternet) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(newReplyDT.equals("")) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, getString(R.string.commentEmptyError));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
disableProcessButton();
|
|
||||||
replyComment(newReplyDT);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void replyComment(String newReplyDT) {
|
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String repoFullName = tinyDb.getString("repoFullName");
|
|
||||||
String[] parts = repoFullName.split("/");
|
|
||||||
final String repoOwner = parts[0];
|
|
||||||
final String repoName = parts[1];
|
|
||||||
final int issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
|
|
||||||
|
|
||||||
Issues issueComment = new Issues(newReplyDT);
|
|
||||||
|
|
||||||
Call<Issues> call = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.replyCommentToIssue(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, issueComment);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<Issues>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<Issues> call, @NonNull retrofit2.Response<Issues> response) {
|
|
||||||
|
|
||||||
if(response.code() == 201) {
|
|
||||||
|
|
||||||
Toasty.success(ctx, getString(R.string.commentSuccess));
|
|
||||||
tinyDb.putBoolean("commentPosted", true);
|
|
||||||
tinyDb.putBoolean("resumeIssues", true);
|
|
||||||
tinyDb.putBoolean("resumePullRequests", true);
|
|
||||||
|
|
||||||
// delete draft comment
|
|
||||||
if(tinyDb.getBoolean("draftsCommentsDeletionEnabled")) {
|
|
||||||
|
|
||||||
DraftsApi draftsApi = new DraftsApi(appCtx);
|
|
||||||
draftsApi.deleteSingleDraft((int) draftIdOnCreate);
|
|
||||||
}
|
|
||||||
|
|
||||||
finish();
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 401) {
|
|
||||||
|
|
||||||
enableProcessButton();
|
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
|
||||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
enableProcessButton();
|
|
||||||
Toasty.error(ctx, getString(R.string.commentError));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<Issues> call, @NonNull Throwable t) {
|
|
||||||
|
|
||||||
Log.e(TAG, t.toString());
|
|
||||||
enableProcessButton();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
|
|
||||||
MenuInflater inflater = getMenuInflater();
|
|
||||||
inflater.inflate(R.menu.reply_to_issue, menu);
|
|
||||||
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
|
|
||||||
switch(item.getItemId()) {
|
|
||||||
|
|
||||||
case R.id.replyToIssueMenu:
|
|
||||||
Intent fragmentIntent = new Intent(ReplyToIssueActivity.this, MainActivity.class);
|
|
||||||
fragmentIntent.putExtra("launchFragment", "drafts");
|
|
||||||
ReplyToIssueActivity.this.startActivity(fragmentIntent);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void disableProcessButton() {
|
|
||||||
|
|
||||||
replyButton.setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void enableProcessButton() {
|
|
||||||
|
|
||||||
replyButton.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,7 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
@@ -27,13 +28,15 @@ import androidx.fragment.app.FragmentStatePagerAdapter;
|
|||||||
import androidx.viewpager.widget.ViewPager;
|
import androidx.viewpager.widget.ViewPager;
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import org.gitnex.tea4j.models.Branches;
|
||||||
|
import org.gitnex.tea4j.models.UserRepositories;
|
||||||
|
import org.gitnex.tea4j.models.WatchInfo;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
import org.mian.gitnex.fragments.BottomSheetIssuesFilterFragment;
|
import org.mian.gitnex.fragments.BottomSheetIssuesFilterFragment;
|
||||||
import org.mian.gitnex.fragments.BottomSheetMilestonesFilterFragment;
|
import org.mian.gitnex.fragments.BottomSheetMilestonesFilterFragment;
|
||||||
import org.mian.gitnex.fragments.BottomSheetPullRequestFilterFragment;
|
import org.mian.gitnex.fragments.BottomSheetPullRequestFilterFragment;
|
||||||
import org.mian.gitnex.fragments.BottomSheetRepoFragment;
|
import org.mian.gitnex.fragments.BottomSheetRepoFragment;
|
||||||
import org.mian.gitnex.fragments.BranchesFragment;
|
|
||||||
import org.mian.gitnex.fragments.CollaboratorsFragment;
|
import org.mian.gitnex.fragments.CollaboratorsFragment;
|
||||||
import org.mian.gitnex.fragments.FilesFragment;
|
import org.mian.gitnex.fragments.FilesFragment;
|
||||||
import org.mian.gitnex.fragments.IssuesFragment;
|
import org.mian.gitnex.fragments.IssuesFragment;
|
||||||
@@ -43,12 +46,8 @@ import org.mian.gitnex.fragments.PullRequestsFragment;
|
|||||||
import org.mian.gitnex.fragments.ReleasesFragment;
|
import org.mian.gitnex.fragments.ReleasesFragment;
|
||||||
import org.mian.gitnex.fragments.RepoInfoFragment;
|
import org.mian.gitnex.fragments.RepoInfoFragment;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.models.Branches;
|
|
||||||
import org.mian.gitnex.models.UserRepositories;
|
|
||||||
import org.mian.gitnex.models.WatchInfo;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -72,34 +71,18 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
private FragmentRefreshListenerMilestone fragmentRefreshListenerMilestone;
|
private FragmentRefreshListenerMilestone fragmentRefreshListenerMilestone;
|
||||||
private FragmentRefreshListenerFiles fragmentRefreshListenerFiles;
|
private FragmentRefreshListenerFiles fragmentRefreshListenerFiles;
|
||||||
|
|
||||||
private final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
private TinyDB tinyDB;
|
|
||||||
|
|
||||||
private String instanceUrl;
|
|
||||||
private String loginUid;
|
|
||||||
private String instanceToken;
|
|
||||||
|
|
||||||
private String repositoryOwner;
|
private String repositoryOwner;
|
||||||
private String repositoryName;
|
private String repositoryName;
|
||||||
|
|
||||||
public static ViewPager mViewPager;
|
public static ViewPager mViewPager;
|
||||||
private int tabsCount;
|
private int tabsCount;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_repo_detail;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
tinyDB = new TinyDB(appCtx);
|
setContentView(R.layout.activity_repo_detail);
|
||||||
|
|
||||||
String[] repoNameParts = tinyDB.getString("repoFullName").split("/");
|
String[] repoNameParts = tinyDB.getString("repoFullName").split("/");
|
||||||
repositoryOwner = repoNameParts[0];
|
repositoryOwner = repoNameParts[0];
|
||||||
@@ -107,17 +90,21 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
|
|
||||||
TextView toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
|
TextView toolbarTitle = findViewById(R.id.toolbar_title);
|
||||||
|
ImageView repoTypeToolbar = findViewById(R.id.repoTypeToolbar);
|
||||||
|
|
||||||
|
if(tinyDB.getString("repoType").equalsIgnoreCase("private")) {
|
||||||
|
repoTypeToolbar.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
repoTypeToolbar.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
toolbarTitle.setText(repositoryName);
|
toolbarTitle.setText(repositoryName);
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
Objects.requireNonNull(getSupportActionBar()).setTitle(repositoryName);
|
Objects.requireNonNull(getSupportActionBar()).setTitle(repositoryName);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
instanceUrl = tinyDB.getString("instanceUrl");
|
|
||||||
loginUid = tinyDB.getString("loginUid");
|
|
||||||
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
tinyDB.putString("repoIssuesState", "open");
|
tinyDB.putString("repoIssuesState", "open");
|
||||||
tinyDB.putString("repoPrState", "open");
|
tinyDB.putString("repoPrState", "open");
|
||||||
tinyDB.putString("milestoneState", "open");
|
tinyDB.putString("milestoneState", "open");
|
||||||
@@ -127,17 +114,17 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
switch(tinyDB.getInt("customFontId", -1)) {
|
switch(tinyDB.getInt("customFontId", -1)) {
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
|
|
||||||
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/roboto.ttf");
|
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/roboto.ttf");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
|
||||||
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/sourcecodeproregular.ttf");
|
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/sourcecodeproregular.ttf");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/manroperegular.ttf");
|
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/manroperegular.ttf");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toolbarTitle.setTypeface(myTypeface);
|
toolbarTitle.setTypeface(myTypeface);
|
||||||
@@ -157,13 +144,14 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
View tabViewChild = vgTab.getChildAt(i);
|
View tabViewChild = vgTab.getChildAt(i);
|
||||||
|
|
||||||
if(tabViewChild instanceof TextView) {
|
if(tabViewChild instanceof TextView) {
|
||||||
|
|
||||||
((TextView) tabViewChild).setTypeface(myTypeface);
|
((TextView) tabViewChild).setTypeface(myTypeface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only show collaborators tab, if you have permission to
|
// Only show collaborators tab, if you have permission to
|
||||||
View collaboratorTab = viewGroup.getChildAt(8);
|
View collaboratorTab = viewGroup.getChildAt(7);
|
||||||
|
|
||||||
if(tinyDB.getBoolean("isRepoAdmin") || new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
if(tinyDB.getBoolean("isRepoAdmin") || new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||||
|
|
||||||
@@ -173,7 +161,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
|
|
||||||
tabsCount--;
|
tabsCount--;
|
||||||
collaboratorTab.setVisibility(View.GONE);
|
collaboratorTab.setVisibility(View.GONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mViewPager = findViewById(R.id.container);
|
mViewPager = findViewById(R.id.container);
|
||||||
@@ -199,7 +186,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
textViewBadgePull.setVisibility(View.GONE);
|
textViewBadgePull.setVisibility(View.GONE);
|
||||||
textViewBadgeRelease.setVisibility(View.GONE);
|
textViewBadgeRelease.setVisibility(View.GONE);
|
||||||
|
|
||||||
getRepoInfo(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repositoryOwner, repositoryName);
|
getRepoInfo(Authorization.get(ctx), repositoryOwner, repositoryName);
|
||||||
ColorStateList textColor = tabLayout.getTabTextColors();
|
ColorStateList textColor = tabLayout.getTabTextColors();
|
||||||
|
|
||||||
// Issue count
|
// Issue count
|
||||||
@@ -210,7 +197,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
assert tabOpenIssues != null; // FIXME This should be cleaned up
|
assert tabOpenIssues != null; // FIXME This should be cleaned up
|
||||||
TextView openIssueTabView = Objects.requireNonNull(tabOpenIssues.getCustomView()).findViewById(R.id.counterBadgeIssueText);
|
TextView openIssueTabView = Objects.requireNonNull(tabOpenIssues.getCustomView()).findViewById(R.id.counterBadgeIssueText);
|
||||||
openIssueTabView.setTextColor(textColor);
|
openIssueTabView.setTextColor(textColor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pull request count
|
// Pull request count
|
||||||
@@ -221,7 +207,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
assert tabOpenPulls != null; // FIXME This should be cleaned up
|
assert tabOpenPulls != null; // FIXME This should be cleaned up
|
||||||
TextView openPullTabView = Objects.requireNonNull(tabOpenPulls.getCustomView()).findViewById(R.id.counterBadgePullText);
|
TextView openPullTabView = Objects.requireNonNull(tabOpenPulls.getCustomView()).findViewById(R.id.counterBadgePullText);
|
||||||
openPullTabView.setTextColor(textColor);
|
openPullTabView.setTextColor(textColor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release count
|
// Release count
|
||||||
@@ -229,19 +214,107 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
|
|
||||||
if(textViewBadgeRelease.getText() != "") { // only show if API returned a number
|
if(textViewBadgeRelease.getText() != "") { // only show if API returned a number
|
||||||
|
|
||||||
Objects.requireNonNull(tabLayout.getTabAt(5)).setCustomView(tabHeader6);
|
Objects.requireNonNull(tabLayout.getTabAt(4)).setCustomView(tabHeader6);
|
||||||
TabLayout.Tab tabOpenRelease = tabLayout.getTabAt(5);
|
TabLayout.Tab tabOpenRelease = tabLayout.getTabAt(4);
|
||||||
assert tabOpenRelease != null; // FIXME This should be cleaned up
|
assert tabOpenRelease != null; // FIXME This should be cleaned up
|
||||||
TextView openReleaseTabView = Objects.requireNonNull(tabOpenRelease.getCustomView()).findViewById(R.id.counterBadgeReleaseText);
|
TextView openReleaseTabView = Objects.requireNonNull(tabOpenRelease.getCustomView()).findViewById(R.id.counterBadgeReleaseText);
|
||||||
openReleaseTabView.setTextColor(textColor);
|
openReleaseTabView.setTextColor(textColor);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkRepositoryStarStatus(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repositoryOwner, repositoryName);
|
Intent mainIntent = getIntent();
|
||||||
checkRepositoryWatchStatus(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repositoryOwner, repositoryName);
|
String goToSection = mainIntent.getStringExtra("goToSection");
|
||||||
|
String goToSectionType = mainIntent.getStringExtra("goToSectionType");
|
||||||
|
|
||||||
|
if(goToSection != null) {
|
||||||
|
|
||||||
|
mainIntent.removeExtra("goToSection");
|
||||||
|
mainIntent.removeExtra("goToSectionType");
|
||||||
|
|
||||||
|
switch(goToSectionType) {
|
||||||
|
case "branchesList":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(1);
|
||||||
|
chooseBranch();
|
||||||
|
break;
|
||||||
|
case "branch":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(1);
|
||||||
|
String selectedBranch = mainIntent.getStringExtra("selectedBranch");
|
||||||
|
tinyDB.putString("repoBranch", selectedBranch);
|
||||||
|
if(getFragmentRefreshListenerFiles() != null) {
|
||||||
|
getFragmentRefreshListenerFiles().onRefresh(selectedBranch);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "file":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(1);
|
||||||
|
String branch1 = mainIntent.getStringExtra("branch");
|
||||||
|
tinyDB.putString("repoBranch", branch1);
|
||||||
|
if(getFragmentRefreshListenerFiles() != null) {
|
||||||
|
getFragmentRefreshListenerFiles().onRefresh(branch1);
|
||||||
|
}
|
||||||
|
Intent intent = new Intent(ctx, FileViewActivity.class);
|
||||||
|
intent.putExtra("file", mainIntent.getSerializableExtra("file"));
|
||||||
|
startActivity(intent);
|
||||||
|
break;
|
||||||
|
case "dir":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(1);
|
||||||
|
String branch2 = mainIntent.getStringExtra("branch");
|
||||||
|
tinyDB.putString("repoBranch", branch2);
|
||||||
|
if(getFragmentRefreshListenerFiles() != null) {
|
||||||
|
getFragmentRefreshListenerFiles().onRefresh(branch2);
|
||||||
|
}
|
||||||
|
//((SectionsPagerAdapter) Objects.requireNonNull(RepoDetailActivity.mViewPager.getAdapter())).getItem(1);
|
||||||
|
break;
|
||||||
|
case "commitsList":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(1);
|
||||||
|
String branch = mainIntent.getStringExtra("branchName");
|
||||||
|
tinyDB.putString("repoBranch", branch);
|
||||||
|
if(getFragmentRefreshListenerFiles() != null) {
|
||||||
|
getFragmentRefreshListenerFiles().onRefresh(branch);
|
||||||
|
}
|
||||||
|
Intent intent1 = new Intent(ctx, CommitsActivity.class);
|
||||||
|
intent1.putExtra("branchName", branch);
|
||||||
|
ctx.startActivity(intent1);
|
||||||
|
break;
|
||||||
|
case "issue":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(2);
|
||||||
|
break;
|
||||||
|
case "issueNew":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(2);
|
||||||
|
startActivity(new Intent(RepoDetailActivity.this, CreateIssueActivity.class));
|
||||||
|
break;
|
||||||
|
case "pull":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(3);
|
||||||
|
break;
|
||||||
|
case "pullNew":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(3);
|
||||||
|
startActivity(new Intent(RepoDetailActivity.this, CreatePullRequestActivity.class));
|
||||||
|
break;
|
||||||
|
case "releases":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(4);
|
||||||
|
break;
|
||||||
|
case "newRelease":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(4);
|
||||||
|
startActivity(new Intent(RepoDetailActivity.this, CreateReleaseActivity.class));
|
||||||
|
break;
|
||||||
|
case "milestones":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(5);
|
||||||
|
break;
|
||||||
|
case "milestonesNew":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(5);
|
||||||
|
startActivity(new Intent(RepoDetailActivity.this, CreateMilestoneActivity.class));
|
||||||
|
break;
|
||||||
|
case "labels":
|
||||||
|
RepoDetailActivity.mViewPager.setCurrentItem(6);
|
||||||
|
break;
|
||||||
|
case "settings":
|
||||||
|
startActivity(new Intent(RepoDetailActivity.this, RepositorySettingsActivity.class));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkRepositoryStarStatus(Authorization.get(ctx), repositoryOwner, repositoryName);
|
||||||
|
checkRepositoryWatchStatus(Authorization.get(ctx), repositoryOwner, repositoryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -251,9 +324,8 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
|
|
||||||
if(tinyDB.getBoolean("enableCounterIssueBadge")) {
|
if(tinyDB.getBoolean("enableCounterIssueBadge")) {
|
||||||
|
|
||||||
getRepoInfo(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repositoryOwner, repositoryName);
|
getRepoInfo(Authorization.get(ctx), repositoryOwner, repositoryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -262,7 +334,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.repo_dotted_menu, menu);
|
inflater.inflate(R.menu.repo_dotted_menu, menu);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -270,40 +341,49 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
|
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
|
|
||||||
switch(id) {
|
if(id == android.R.id.home) {
|
||||||
|
|
||||||
case android.R.id.home:
|
|
||||||
finish();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case R.id.repoMenu:
|
|
||||||
BottomSheetRepoFragment bottomSheet = new BottomSheetRepoFragment();
|
|
||||||
bottomSheet.show(getSupportFragmentManager(), "repoBottomSheet");
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case R.id.filter:
|
|
||||||
BottomSheetIssuesFilterFragment filterBottomSheet = new BottomSheetIssuesFilterFragment();
|
|
||||||
filterBottomSheet.show(getSupportFragmentManager(), "repoFilterMenuBottomSheet");
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case R.id.filterPr:
|
|
||||||
BottomSheetPullRequestFilterFragment filterPrBottomSheet = new BottomSheetPullRequestFilterFragment();
|
|
||||||
filterPrBottomSheet.show(getSupportFragmentManager(), "repoFilterMenuPrBottomSheet");
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case R.id.filterMilestone:
|
|
||||||
BottomSheetMilestonesFilterFragment filterMilestoneBottomSheet = new BottomSheetMilestonesFilterFragment();
|
|
||||||
filterMilestoneBottomSheet.show(getSupportFragmentManager(), "repoFilterMenuMilestoneBottomSheet");
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case R.id.switchBranches:
|
|
||||||
chooseBranch();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
|
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
else if(id == R.id.repoMenu) {
|
||||||
|
|
||||||
|
BottomSheetRepoFragment bottomSheet = new BottomSheetRepoFragment();
|
||||||
|
bottomSheet.show(getSupportFragmentManager(), "repoBottomSheet");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(id == R.id.filter) {
|
||||||
|
|
||||||
|
BottomSheetIssuesFilterFragment filterBottomSheet = new BottomSheetIssuesFilterFragment();
|
||||||
|
filterBottomSheet.show(getSupportFragmentManager(), "repoFilterMenuBottomSheet");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(id == R.id.filterPr) {
|
||||||
|
|
||||||
|
BottomSheetPullRequestFilterFragment filterPrBottomSheet = new BottomSheetPullRequestFilterFragment();
|
||||||
|
filterPrBottomSheet.show(getSupportFragmentManager(), "repoFilterMenuPrBottomSheet");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(id == R.id.filterMilestone) {
|
||||||
|
|
||||||
|
BottomSheetMilestonesFilterFragment filterMilestoneBottomSheet = new BottomSheetMilestonesFilterFragment();
|
||||||
|
filterMilestoneBottomSheet.show(getSupportFragmentManager(), "repoFilterMenuMilestoneBottomSheet");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(id == R.id.switchBranches) {
|
||||||
|
|
||||||
|
chooseBranch();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(id == R.id.branchCommits) {
|
||||||
|
|
||||||
|
Intent intent = new Intent(ctx, CommitsActivity.class);
|
||||||
|
intent.putExtra("branchName", tinyDB.getString("repoBranch"));
|
||||||
|
ctx.startActivity(intent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,99 +393,112 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
switch(text) {
|
switch(text) {
|
||||||
|
|
||||||
case "label":
|
case "label":
|
||||||
|
|
||||||
startActivity(new Intent(RepoDetailActivity.this, CreateLabelActivity.class));
|
startActivity(new Intent(RepoDetailActivity.this, CreateLabelActivity.class));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "newIssue":
|
case "newIssue":
|
||||||
|
|
||||||
startActivity(new Intent(RepoDetailActivity.this, CreateIssueActivity.class));
|
startActivity(new Intent(RepoDetailActivity.this, CreateIssueActivity.class));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "newMilestone":
|
case "newMilestone":
|
||||||
|
|
||||||
startActivity(new Intent(RepoDetailActivity.this, CreateMilestoneActivity.class));
|
startActivity(new Intent(RepoDetailActivity.this, CreateMilestoneActivity.class));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "addCollaborator":
|
case "addCollaborator":
|
||||||
|
|
||||||
startActivity(new Intent(RepoDetailActivity.this, AddCollaboratorToRepositoryActivity.class));
|
startActivity(new Intent(RepoDetailActivity.this, AddCollaboratorToRepositoryActivity.class));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "chooseBranch":
|
case "chooseBranch":
|
||||||
|
|
||||||
chooseBranch();
|
chooseBranch();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "createRelease":
|
case "createRelease":
|
||||||
|
|
||||||
startActivity(new Intent(RepoDetailActivity.this, CreateReleaseActivity.class));
|
startActivity(new Intent(RepoDetailActivity.this, CreateReleaseActivity.class));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "openWebRepo":
|
case "openWebRepo":
|
||||||
|
|
||||||
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(tinyDB.getString("repoHtmlUrl")));
|
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(tinyDB.getString("repoHtmlUrl")));
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "shareRepo":
|
case "shareRepo":
|
||||||
|
|
||||||
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
|
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
|
||||||
sharingIntent.setType("text/plain");
|
sharingIntent.setType("text/plain");
|
||||||
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, tinyDB.getString("repoHtmlUrl"));
|
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, tinyDB.getString("repoHtmlUrl"));
|
||||||
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, tinyDB.getString("repoHtmlUrl"));
|
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, tinyDB.getString("repoHtmlUrl"));
|
||||||
startActivity(Intent.createChooser(sharingIntent, tinyDB.getString("repoHtmlUrl")));
|
startActivity(Intent.createChooser(sharingIntent, tinyDB.getString("repoHtmlUrl")));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "copyRepoUrl":
|
case "copyRepoUrl":
|
||||||
|
|
||||||
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
ClipData clip = ClipData.newPlainText("repoUrl", tinyDB.getString("repoHtmlUrl"));
|
ClipData clip = ClipData.newPlainText("repoUrl", tinyDB.getString("repoHtmlUrl"));
|
||||||
assert clipboard != null;
|
assert clipboard != null;
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
Toasty.info(ctx, ctx.getString(R.string.copyIssueUrlToastMsg));
|
Toasty.info(ctx, ctx.getString(R.string.copyIssueUrlToastMsg));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "newFile":
|
case "newFile":
|
||||||
|
|
||||||
startActivity(new Intent(RepoDetailActivity.this, CreateFileActivity.class));
|
startActivity(new Intent(RepoDetailActivity.this, CreateFileActivity.class));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "openIssues":
|
case "openIssues":
|
||||||
|
|
||||||
if(getFragmentRefreshListener() != null) {
|
if(getFragmentRefreshListener() != null) {
|
||||||
|
|
||||||
getFragmentRefreshListener().onRefresh("open");
|
getFragmentRefreshListener().onRefresh("open");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "closedIssues":
|
case "closedIssues":
|
||||||
|
|
||||||
if(getFragmentRefreshListener() != null) {
|
if(getFragmentRefreshListener() != null) {
|
||||||
|
|
||||||
getFragmentRefreshListener().onRefresh("closed");
|
getFragmentRefreshListener().onRefresh("closed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "openPr":
|
case "openPr":
|
||||||
|
|
||||||
if(getFragmentRefreshListenerPr() != null) {
|
if(getFragmentRefreshListenerPr() != null) {
|
||||||
|
|
||||||
getFragmentRefreshListenerPr().onRefresh("open");
|
getFragmentRefreshListenerPr().onRefresh("open");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "closedPr":
|
case "closedPr":
|
||||||
|
|
||||||
if(getFragmentRefreshListenerPr() != null) {
|
if(getFragmentRefreshListenerPr() != null) {
|
||||||
|
|
||||||
getFragmentRefreshListenerPr().onRefresh("closed");
|
getFragmentRefreshListenerPr().onRefresh("closed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "openMilestone":
|
case "openMilestone":
|
||||||
|
|
||||||
if(getFragmentRefreshListenerMilestone() != null) {
|
if(getFragmentRefreshListenerMilestone() != null) {
|
||||||
|
|
||||||
getFragmentRefreshListenerMilestone().onRefresh("open");
|
getFragmentRefreshListenerMilestone().onRefresh("open");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "closedMilestone":
|
case "closedMilestone":
|
||||||
|
|
||||||
if(getFragmentRefreshListenerMilestone() != null) {
|
if(getFragmentRefreshListenerMilestone() != null) {
|
||||||
|
|
||||||
getFragmentRefreshListenerMilestone().onRefresh("closed");
|
getFragmentRefreshListenerMilestone().onRefresh("closed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "repoSettings":
|
||||||
|
|
||||||
|
startActivity(new Intent(RepoDetailActivity.this, RepositorySettingsActivity.class));
|
||||||
|
break;
|
||||||
|
case "newPullRequest":
|
||||||
|
|
||||||
|
startActivity(new Intent(RepoDetailActivity.this, CreatePullRequestActivity.class));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void chooseBranch() {
|
private void chooseBranch() {
|
||||||
|
|
||||||
Call<List<Branches>> call = RetrofitClient.getInstance(instanceUrl, ctx)
|
Call<List<Branches>> call = RetrofitClient
|
||||||
.getApiInterface()
|
.getApiInterface(ctx)
|
||||||
.getBranches(instanceToken, repositoryOwner, repositoryName);
|
.getBranches(Authorization.get(ctx), repositoryOwner, repositoryName);
|
||||||
|
|
||||||
call.enqueue(new Callback<List<Branches>>() {
|
call.enqueue(new Callback<List<Branches>>() {
|
||||||
|
|
||||||
@@ -438,7 +531,9 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
|
||||||
tinyDB.putString("repoBranch", branchesList.get(i));
|
tinyDB.putString("repoBranch", branchesList.get(i));
|
||||||
|
|
||||||
if(getFragmentRefreshListenerFiles() != null) {
|
if(getFragmentRefreshListenerFiles() != null) {
|
||||||
|
|
||||||
getFragmentRefreshListenerFiles().onRefresh(branchesList.get(i));
|
getFragmentRefreshListenerFiles().onRefresh(branchesList.get(i));
|
||||||
}
|
}
|
||||||
dialogInterface.dismiss();
|
dialogInterface.dismiss();
|
||||||
@@ -447,9 +542,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
pBuilder.setNeutralButton(R.string.cancelButton, null);
|
pBuilder.setNeutralButton(R.string.cancelButton, null);
|
||||||
|
|
||||||
pBuilder.create().show();
|
pBuilder.create().show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -477,40 +570,36 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
switch(position) {
|
switch(position) {
|
||||||
|
|
||||||
case 0: // Repository details
|
case 0: // Repository details
|
||||||
|
|
||||||
return RepoInfoFragment.newInstance(repositoryOwner, repositoryName);
|
return RepoInfoFragment.newInstance(repositoryOwner, repositoryName);
|
||||||
|
|
||||||
case 1: // Files
|
case 1: // Files
|
||||||
return FilesFragment.newInstance(repositoryOwner, repositoryName, tinyDB.getString("repoBranch"));
|
|
||||||
|
|
||||||
|
return FilesFragment.newInstance(repositoryOwner, repositoryName, tinyDB.getString("repoBranch"));
|
||||||
case 2: // Issues
|
case 2: // Issues
|
||||||
|
|
||||||
fragment = new IssuesFragment();
|
fragment = new IssuesFragment();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: // Pull requests
|
case 3: // Pull requests
|
||||||
|
|
||||||
fragment = new PullRequestsFragment();
|
fragment = new PullRequestsFragment();
|
||||||
break;
|
break;
|
||||||
|
case 4: // Releases
|
||||||
|
|
||||||
case 4: // Branches
|
|
||||||
return BranchesFragment.newInstance(repositoryOwner, repositoryName);
|
|
||||||
|
|
||||||
case 5: // Releases
|
|
||||||
return ReleasesFragment.newInstance(repositoryOwner, repositoryName);
|
return ReleasesFragment.newInstance(repositoryOwner, repositoryName);
|
||||||
|
case 5: // Milestones
|
||||||
|
|
||||||
case 6: // Milestones
|
|
||||||
fragment = new MilestonesFragment();
|
fragment = new MilestonesFragment();
|
||||||
break;
|
break;
|
||||||
|
case 6: // Labels
|
||||||
|
|
||||||
case 7: // Labels
|
|
||||||
return LabelsFragment.newInstance(repositoryOwner, repositoryName);
|
return LabelsFragment.newInstance(repositoryOwner, repositoryName);
|
||||||
|
case 7: // Collaborators
|
||||||
|
|
||||||
case 8: // Collaborators
|
|
||||||
return CollaboratorsFragment.newInstance(repositoryOwner, repositoryName);
|
return CollaboratorsFragment.newInstance(repositoryOwner, repositoryName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert fragment != null;
|
assert fragment != null;
|
||||||
return fragment;
|
return fragment;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -518,12 +607,11 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
|
|
||||||
return tabsCount;
|
return tabsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getRepoInfo(String instanceUrl, String token, final String owner, String repo) {
|
private void getRepoInfo(String token, final String owner, String repo) {
|
||||||
|
|
||||||
Call<UserRepositories> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserRepository(token, owner, repo);
|
Call<UserRepositories> call = RetrofitClient.getApiInterface(ctx).getUserRepository(token, owner, repo);
|
||||||
call.enqueue(new Callback<UserRepositories>() {
|
call.enqueue(new Callback<UserRepositories>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -534,6 +622,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
if(response.code() == 200) {
|
if(response.code() == 200) {
|
||||||
|
|
||||||
if(tinyDB.getBoolean("enableCounterBadges")) {
|
if(tinyDB.getBoolean("enableCounterBadges")) {
|
||||||
|
|
||||||
assert repoInfo != null;
|
assert repoInfo != null;
|
||||||
|
|
||||||
if(repoInfo.getOpen_issues_count() != null) {
|
if(repoInfo.getOpen_issues_count() != null) {
|
||||||
@@ -560,7 +649,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
|
|
||||||
Log.e("onFailure", String.valueOf(response.code()));
|
Log.e("onFailure", String.valueOf(response.code()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -573,16 +661,15 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkRepositoryStarStatus(String instanceUrl, String instanceToken, final String owner, String repo) {
|
private void checkRepositoryStarStatus(String instanceToken, final String owner, String repo) {
|
||||||
|
|
||||||
Call<JsonElement> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().checkRepoStarStatus(instanceToken, owner, repo);
|
Call<JsonElement> call = RetrofitClient.getApiInterface(ctx).checkRepoStarStatus(instanceToken, owner, repo);
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||||
|
|
||||||
tinyDB.putInt("repositoryStarStatus", response.code());
|
tinyDB.putInt("repositoryStarStatus", response.code());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -594,11 +681,11 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkRepositoryWatchStatus(String instanceUrl, String instanceToken, final String owner, String repo) {
|
private void checkRepositoryWatchStatus(String instanceToken, final String owner, String repo) {
|
||||||
|
|
||||||
Call<WatchInfo> call;
|
Call<WatchInfo> call;
|
||||||
|
|
||||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().checkRepoWatchStatus(instanceToken, owner, repo);
|
call = RetrofitClient.getApiInterface(ctx).checkRepoWatchStatus(instanceToken, owner, repo);
|
||||||
call.enqueue(new Callback<WatchInfo>() {
|
call.enqueue(new Callback<WatchInfo>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -609,15 +696,14 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
|||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
|
|
||||||
if(response.body().getSubscribed()) {
|
if(response.body().getSubscribed()) {
|
||||||
|
|
||||||
tinyDB.putBoolean("repositoryWatchStatus", true);
|
tinyDB.putBoolean("repositoryWatchStatus", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
tinyDB.putBoolean("repositoryWatchStatus", false);
|
tinyDB.putBoolean("repositoryWatchStatus", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.text.method.ScrollingMovementMethod;
|
import android.text.method.ScrollingMovementMethod;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -21,14 +21,15 @@ import androidx.recyclerview.widget.DividerItemDecoration;
|
|||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
import org.gitnex.tea4j.models.UserRepositories;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.adapters.RepoForksAdapter;
|
import org.mian.gitnex.adapters.RepoForksAdapter;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.databinding.ActivityRepoForksBinding;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
import org.mian.gitnex.helpers.Constants;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Version;
|
import org.mian.gitnex.helpers.Version;
|
||||||
import org.mian.gitnex.models.UserRepositories;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@@ -41,13 +42,11 @@ import retrofit2.Response;
|
|||||||
|
|
||||||
public class RepoForksActivity extends BaseActivity {
|
public class RepoForksActivity extends BaseActivity {
|
||||||
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
private TextView noData;
|
private TextView noData;
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
private String TAG = "RepositoryForks";
|
private final String TAG = "RepositoryForks";
|
||||||
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
|
private int resultLimit = Constants.resultLimitOldGiteaInstances;
|
||||||
private int pageSize = 1;
|
private int pageSize = 1;
|
||||||
|
|
||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
@@ -55,25 +54,19 @@ public class RepoForksActivity extends BaseActivity {
|
|||||||
private RepoForksAdapter adapter;
|
private RepoForksAdapter adapter;
|
||||||
private ProgressBar progressLoadMore;
|
private ProgressBar progressLoadMore;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_forks;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
@SuppressLint("DefaultLocale")
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
ActivityRepoForksBinding activityRepoForksBinding = ActivityRepoForksBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityRepoForksBinding.getRoot());
|
||||||
|
|
||||||
|
Toolbar toolbar = activityRepoForksBinding.toolbar;
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
String repoFullNameForForks = getIntent().getStringExtra("repoFullNameForForks");
|
String repoFullNameForForks = getIntent().getStringExtra("repoFullNameForForks");
|
||||||
assert repoFullNameForForks != null;
|
assert repoFullNameForForks != null;
|
||||||
@@ -81,35 +74,36 @@ public class RepoForksActivity extends BaseActivity {
|
|||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
|
|
||||||
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
TextView toolbar_title = activityRepoForksBinding.toolbarTitle;
|
||||||
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
|
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
|
||||||
toolbar_title.setText(String.format("%s : %s", ctx.getResources().getString(R.string.infoTabRepoForksCount), repoName));
|
toolbar_title.setText(String.format("%s : %s", ctx.getResources().getString(R.string.infoTabRepoForksCount), repoName));
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activityRepoForksBinding.close;
|
||||||
noData = findViewById(R.id.noData);
|
noData = activityRepoForksBinding.noData;
|
||||||
progressLoadMore = findViewById(R.id.progressLoadMore);
|
progressLoadMore = activityRepoForksBinding.progressLoadMore;
|
||||||
progressBar = findViewById(R.id.progress_bar);
|
progressBar = activityRepoForksBinding.progressBar;
|
||||||
SwipeRefreshLayout swipeRefresh = findViewById(R.id.pullToRefresh);
|
SwipeRefreshLayout swipeRefresh = activityRepoForksBinding.pullToRefresh;
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
// if gitea is 1.12 or higher use the new limit (resultLimitNewGiteaInstances)
|
// if gitea is 1.12 or higher use the new limit (resultLimitNewGiteaInstances)
|
||||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12")) {
|
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12")) {
|
||||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
|
||||||
|
resultLimit = Constants.resultLimitNewGiteaInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
recyclerView = findViewById(R.id.recyclerView);
|
recyclerView = activityRepoForksBinding.recyclerView;
|
||||||
forksList = new ArrayList<>();
|
forksList = new ArrayList<>();
|
||||||
|
|
||||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
|
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
|
||||||
DividerItemDecoration.VERTICAL);
|
DividerItemDecoration.VERTICAL);
|
||||||
recyclerView.addItemDecoration(dividerItemDecoration);
|
recyclerView.addItemDecoration(dividerItemDecoration);
|
||||||
|
|
||||||
swipeRefresh.setOnRefreshListener(() -> new Handler().postDelayed(() -> {
|
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
|
|
||||||
swipeRefresh.setRefreshing(false);
|
swipeRefresh.setRefreshing(false);
|
||||||
loadInitial(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, pageSize, resultLimit);
|
loadInitial(Authorization.get(ctx), repoOwner, repoName, pageSize, resultLimit);
|
||||||
adapter.notifyDataChanged();
|
adapter.notifyDataChanged();
|
||||||
|
|
||||||
}, 200));
|
}, 200));
|
||||||
@@ -120,25 +114,21 @@ public class RepoForksActivity extends BaseActivity {
|
|||||||
if(forksList.size() == resultLimit || pageSize == resultLimit) {
|
if(forksList.size() == resultLimit || pageSize == resultLimit) {
|
||||||
|
|
||||||
int page = (forksList.size() + resultLimit) / resultLimit;
|
int page = (forksList.size() + resultLimit) / resultLimit;
|
||||||
loadMore(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, page, resultLimit);
|
loadMore(Authorization.get(ctx), repoOwner, repoName, page, resultLimit);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
recyclerView.setHasFixedSize(true);
|
recyclerView.setHasFixedSize(true);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
loadInitial(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, pageSize, resultLimit);
|
loadInitial(Authorization.get(ctx), repoOwner, repoName, pageSize, resultLimit);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadInitial(String instanceUrl, String instanceToken, String repoOwner, String repoName, int pageSize, int resultLimit) {
|
private void loadInitial(String instanceToken, String repoOwner, String repoName, int pageSize, int resultLimit) {
|
||||||
|
|
||||||
Call<List<UserRepositories>> call = RetrofitClient
|
Call<List<UserRepositories>> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
|
||||||
.getRepositoryForks(instanceToken, repoOwner, repoName, pageSize, resultLimit);
|
.getRepositoryForks(instanceToken, repoOwner, repoName, pageSize, resultLimit);
|
||||||
|
|
||||||
call.enqueue(new Callback<List<UserRepositories>>() {
|
call.enqueue(new Callback<List<UserRepositories>>() {
|
||||||
@@ -149,29 +139,27 @@ public class RepoForksActivity extends BaseActivity {
|
|||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
|
|
||||||
if(response.body().size() > 0) {
|
if(response.body().size() > 0) {
|
||||||
|
|
||||||
forksList.clear();
|
forksList.clear();
|
||||||
forksList.addAll(response.body());
|
forksList.addAll(response.body());
|
||||||
adapter.notifyDataChanged();
|
adapter.notifyDataChanged();
|
||||||
noData.setVisibility(View.GONE);
|
noData.setVisibility(View.GONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
forksList.clear();
|
forksList.clear();
|
||||||
adapter.notifyDataChanged();
|
adapter.notifyDataChanged();
|
||||||
noData.setVisibility(View.VISIBLE);
|
noData.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Log.e(TAG, String.valueOf(response.code()));
|
Log.e(TAG, String.valueOf(response.code()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -179,18 +167,16 @@ public class RepoForksActivity extends BaseActivity {
|
|||||||
|
|
||||||
Log.e(TAG, t.toString());
|
Log.e(TAG, t.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadMore(String instanceUrl, String instanceToken, String repoOwner, String repoName, int page, int resultLimit) {
|
private void loadMore(String instanceToken, String repoOwner, String repoName, int page, int resultLimit) {
|
||||||
|
|
||||||
progressLoadMore.setVisibility(View.VISIBLE);
|
progressLoadMore.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
Call<List<UserRepositories>> call = RetrofitClient
|
Call<List<UserRepositories>> call = RetrofitClient
|
||||||
.getInstance(instanceUrl, ctx)
|
.getApiInterface(ctx)
|
||||||
.getApiInterface()
|
|
||||||
.getRepositoryForks(instanceToken, repoOwner, repoName, page, resultLimit);
|
.getRepositoryForks(instanceToken, repoOwner, repoName, page, resultLimit);
|
||||||
|
|
||||||
call.enqueue(new Callback<List<UserRepositories>>() {
|
call.enqueue(new Callback<List<UserRepositories>>() {
|
||||||
@@ -204,37 +190,31 @@ public class RepoForksActivity extends BaseActivity {
|
|||||||
forksList.remove(forksList.size() - 1);
|
forksList.remove(forksList.size() - 1);
|
||||||
|
|
||||||
List<UserRepositories> result = response.body();
|
List<UserRepositories> result = response.body();
|
||||||
|
|
||||||
assert result != null;
|
assert result != null;
|
||||||
|
|
||||||
if(result.size() > 0) {
|
if(result.size() > 0) {
|
||||||
|
|
||||||
pageSize = result.size();
|
pageSize = result.size();
|
||||||
forksList.addAll(result);
|
forksList.addAll(result);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
adapter.setMoreDataAvailable(false);
|
adapter.setMoreDataAvailable(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter.notifyDataChanged();
|
adapter.notifyDataChanged();
|
||||||
progressLoadMore.setVisibility(View.GONE);
|
progressLoadMore.setVisibility(View.GONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Log.e(TAG, String.valueOf(response.code()));
|
Log.e(TAG, String.valueOf(response.code()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<List<UserRepositories>> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<List<UserRepositories>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Log.e(TAG, t.toString());
|
Log.e(TAG, t.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -269,7 +249,6 @@ public class RepoForksActivity extends BaseActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filter(String text) {
|
private void filter(String text) {
|
||||||
@@ -277,7 +256,9 @@ public class RepoForksActivity extends BaseActivity {
|
|||||||
List<UserRepositories> arr = new ArrayList<>();
|
List<UserRepositories> arr = new ArrayList<>();
|
||||||
|
|
||||||
for(UserRepositories d : forksList) {
|
for(UserRepositories d : forksList) {
|
||||||
|
|
||||||
if(d.getName().toLowerCase().contains(text) || d.getDescription().toLowerCase().contains(text)) {
|
if(d.getName().toLowerCase().contains(text) || d.getDescription().toLowerCase().contains(text)) {
|
||||||
|
|
||||||
arr.add(d);
|
arr.add(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,6 +269,7 @@ public class RepoForksActivity extends BaseActivity {
|
|||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
|
|
||||||
onClickListener = view -> {
|
onClickListener = view -> {
|
||||||
|
|
||||||
getIntent().removeExtra("repoFullNameForForks");
|
getIntent().removeExtra("repoFullNameForForks");
|
||||||
finish();
|
finish();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,22 +1,17 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.GridView;
|
import android.widget.GridView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.lifecycle.Observer;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.adapters.RepoStargazersAdapter;
|
import org.mian.gitnex.adapters.RepoStargazersAdapter;
|
||||||
|
import org.mian.gitnex.databinding.ActivityRepoStargazersBinding;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.models.UserInfo;
|
|
||||||
import org.mian.gitnex.viewmodels.RepoStargazersViewModel;
|
import org.mian.gitnex.viewmodels.RepoStargazersViewModel;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -30,30 +25,19 @@ public class RepoStargazersActivity extends BaseActivity {
|
|||||||
private GridView mGridView;
|
private GridView mGridView;
|
||||||
private ProgressBar mProgressBar;
|
private ProgressBar mProgressBar;
|
||||||
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_repo_stargazers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
ActivityRepoStargazersBinding activityRepoStargazersBinding = ActivityRepoStargazersBinding.inflate(getLayoutInflater());
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
setContentView(activityRepoStargazersBinding.getRoot());
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activityRepoStargazersBinding.close;
|
||||||
TextView toolbarTitle = findViewById(R.id.toolbar_title);
|
TextView toolbarTitle = activityRepoStargazersBinding.toolbarTitle;
|
||||||
noDataStargazers = findViewById(R.id.noDataStargazers);
|
noDataStargazers = activityRepoStargazersBinding.noDataStargazers;
|
||||||
mGridView = findViewById(R.id.gridView);
|
mGridView = activityRepoStargazersBinding.gridView;
|
||||||
mProgressBar = findViewById(R.id.progress_bar);
|
mProgressBar = activityRepoStargazersBinding.progressBar;
|
||||||
|
|
||||||
String repoFullNameForStars = getIntent().getStringExtra("repoFullNameForStars");
|
String repoFullNameForStars = getIntent().getStringExtra("repoFullNameForStars");
|
||||||
String[] parts = repoFullNameForStars.split("/");
|
String[] parts = repoFullNameForStars.split("/");
|
||||||
@@ -65,29 +49,30 @@ public class RepoStargazersActivity extends BaseActivity {
|
|||||||
|
|
||||||
toolbarTitle.setText(R.string.repoStargazersInMenu);
|
toolbarTitle.setText(R.string.repoStargazersInMenu);
|
||||||
|
|
||||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
fetchDataAsync(Authorization.get(ctx), repoOwner, repoName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchDataAsync(String instanceUrl, String instanceToken, String repoOwner, String repoName) {
|
private void fetchDataAsync(String instanceToken, String repoOwner, String repoName) {
|
||||||
|
|
||||||
RepoStargazersViewModel repoStargazersModel = new ViewModelProvider(this).get(RepoStargazersViewModel.class);
|
RepoStargazersViewModel repoStargazersModel = new ViewModelProvider(this).get(RepoStargazersViewModel.class);
|
||||||
|
|
||||||
repoStargazersModel.getRepoStargazers(instanceUrl, instanceToken, repoOwner, repoName, ctx).observe(this, new Observer<List<UserInfo>>() {
|
repoStargazersModel.getRepoStargazers(instanceToken, repoOwner, repoName, ctx).observe(this, stargazersListMain -> {
|
||||||
@Override
|
|
||||||
public void onChanged(@Nullable List<UserInfo> stargazersListMain) {
|
adapter = new RepoStargazersAdapter(ctx, stargazersListMain);
|
||||||
adapter = new RepoStargazersAdapter(ctx, stargazersListMain);
|
|
||||||
if(adapter.getCount() > 0) {
|
if(adapter.getCount() > 0) {
|
||||||
mGridView.setAdapter(adapter);
|
|
||||||
noDataStargazers.setVisibility(View.GONE);
|
mGridView.setAdapter(adapter);
|
||||||
}
|
noDataStargazers.setVisibility(View.GONE);
|
||||||
else {
|
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
mGridView.setAdapter(adapter);
|
|
||||||
noDataStargazers.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
mProgressBar.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
mGridView.setAdapter(adapter);
|
||||||
|
noDataStargazers.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
mProgressBar.setVisibility(View.GONE);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,17 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.GridView;
|
import android.widget.GridView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.lifecycle.Observer;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.adapters.RepoWatchersAdapter;
|
import org.mian.gitnex.adapters.RepoWatchersAdapter;
|
||||||
|
import org.mian.gitnex.databinding.ActivityRepoWatchersBinding;
|
||||||
import org.mian.gitnex.helpers.Authorization;
|
import org.mian.gitnex.helpers.Authorization;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.models.UserInfo;
|
|
||||||
import org.mian.gitnex.viewmodels.RepoWatchersViewModel;
|
import org.mian.gitnex.viewmodels.RepoWatchersViewModel;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -30,30 +25,19 @@ public class RepoWatchersActivity extends BaseActivity {
|
|||||||
private GridView mGridView;
|
private GridView mGridView;
|
||||||
private ProgressBar mProgressBar;
|
private ProgressBar mProgressBar;
|
||||||
|
|
||||||
final Context ctx = this;
|
|
||||||
private Context appCtx;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId(){
|
|
||||||
return R.layout.activity_repo_watchers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
ActivityRepoWatchersBinding activityRepoWatchersBinding = ActivityRepoWatchersBinding.inflate(getLayoutInflater());
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
setContentView(activityRepoWatchersBinding.getRoot());
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activityRepoWatchersBinding.close;
|
||||||
TextView toolbarTitle = findViewById(R.id.toolbar_title);
|
TextView toolbarTitle = activityRepoWatchersBinding.toolbarTitle;
|
||||||
noDataWatchers = findViewById(R.id.noDataWatchers);
|
noDataWatchers = activityRepoWatchersBinding.noDataWatchers;
|
||||||
mGridView = findViewById(R.id.gridView);
|
mGridView = activityRepoWatchersBinding.gridView;
|
||||||
mProgressBar = findViewById(R.id.progress_bar);
|
mProgressBar = activityRepoWatchersBinding.progressBar;
|
||||||
|
|
||||||
String repoFullNameForWatchers = getIntent().getStringExtra("repoFullNameForWatchers");
|
String repoFullNameForWatchers = getIntent().getStringExtra("repoFullNameForWatchers");
|
||||||
String[] parts = repoFullNameForWatchers.split("/");
|
String[] parts = repoFullNameForWatchers.split("/");
|
||||||
@@ -65,29 +49,30 @@ public class RepoWatchersActivity extends BaseActivity {
|
|||||||
|
|
||||||
toolbarTitle.setText(R.string.repoWatchersInMenu);
|
toolbarTitle.setText(R.string.repoWatchersInMenu);
|
||||||
|
|
||||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
fetchDataAsync(Authorization.get(ctx), repoOwner, repoName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchDataAsync(String instanceUrl, String instanceToken, String repoOwner, String repoName) {
|
private void fetchDataAsync(String instanceToken, String repoOwner, String repoName) {
|
||||||
|
|
||||||
RepoWatchersViewModel repoWatchersModel = new ViewModelProvider(this).get(RepoWatchersViewModel.class);
|
RepoWatchersViewModel repoWatchersModel = new ViewModelProvider(this).get(RepoWatchersViewModel.class);
|
||||||
|
|
||||||
repoWatchersModel.getRepoWatchers(instanceUrl, instanceToken, repoOwner, repoName, ctx).observe(this, new Observer<List<UserInfo>>() {
|
repoWatchersModel.getRepoWatchers(instanceToken, repoOwner, repoName, ctx).observe(this, watchersListMain -> {
|
||||||
@Override
|
|
||||||
public void onChanged(@Nullable List<UserInfo> watchersListMain) {
|
adapter = new RepoWatchersAdapter(ctx, watchersListMain);
|
||||||
adapter = new RepoWatchersAdapter(ctx, watchersListMain);
|
|
||||||
if(adapter.getCount() > 0) {
|
if(adapter.getCount() > 0) {
|
||||||
mGridView.setAdapter(adapter);
|
|
||||||
noDataWatchers.setVisibility(View.GONE);
|
mGridView.setAdapter(adapter);
|
||||||
}
|
noDataWatchers.setVisibility(View.GONE);
|
||||||
else {
|
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
mGridView.setAdapter(adapter);
|
|
||||||
noDataWatchers.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
mProgressBar.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
mGridView.setAdapter(adapter);
|
||||||
|
noDataWatchers.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
mProgressBar.setVisibility(View.GONE);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,414 @@
|
|||||||
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import org.gitnex.tea4j.models.RepositoryTransfer;
|
||||||
|
import org.gitnex.tea4j.models.UserRepositories;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.database.api.BaseApi;
|
||||||
|
import org.mian.gitnex.database.api.RepositoriesApi;
|
||||||
|
import org.mian.gitnex.databinding.ActivityRepositorySettingsBinding;
|
||||||
|
import org.mian.gitnex.databinding.CustomRepositoryDeleteDialogBinding;
|
||||||
|
import org.mian.gitnex.databinding.CustomRepositoryEditPropertiesDialogBinding;
|
||||||
|
import org.mian.gitnex.databinding.CustomRepositoryTransferDialogBinding;
|
||||||
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import org.mian.gitnex.helpers.Version;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class RepositorySettingsActivity extends BaseActivity {
|
||||||
|
|
||||||
|
private ActivityRepositorySettingsBinding viewBinding;
|
||||||
|
private CustomRepositoryEditPropertiesDialogBinding propBinding;
|
||||||
|
private CustomRepositoryDeleteDialogBinding deleteRepoBinding;
|
||||||
|
private CustomRepositoryTransferDialogBinding transferRepoBinding;
|
||||||
|
private Dialog dialogProp;
|
||||||
|
private Dialog dialogDeleteRepository;
|
||||||
|
private Dialog dialogTransferRepository;
|
||||||
|
private View.OnClickListener onClickListener;
|
||||||
|
|
||||||
|
private String loginUid;
|
||||||
|
private String instanceToken;
|
||||||
|
|
||||||
|
private String repositoryOwner;
|
||||||
|
private String repositoryName;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
viewBinding = ActivityRepositorySettingsBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(viewBinding.getRoot());
|
||||||
|
|
||||||
|
loginUid = tinyDB.getString("loginUid");
|
||||||
|
String repoFullName = tinyDB.getString("repoFullName");
|
||||||
|
String[] parts = repoFullName.split("/");
|
||||||
|
repositoryOwner = parts[0];
|
||||||
|
repositoryName = parts[1];
|
||||||
|
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||||
|
|
||||||
|
ImageView closeActivity = findViewById(R.id.close);
|
||||||
|
|
||||||
|
initCloseListener();
|
||||||
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
|
// require gitea 1.12 or higher
|
||||||
|
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||||
|
|
||||||
|
viewBinding.transferOwnerFrame.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
viewBinding.editProperties.setOnClickListener(editProperties -> showRepositoryProperties());
|
||||||
|
|
||||||
|
viewBinding.deleteRepository.setOnClickListener(deleteRepository -> showDeleteRepository());
|
||||||
|
|
||||||
|
viewBinding.transferOwnerFrame.setOnClickListener(transferRepositoryOwnership -> showTransferRepository());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showTransferRepository() {
|
||||||
|
|
||||||
|
dialogTransferRepository = new Dialog(ctx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
||||||
|
|
||||||
|
if (dialogTransferRepository.getWindow() != null) {
|
||||||
|
|
||||||
|
dialogTransferRepository.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
transferRepoBinding = CustomRepositoryTransferDialogBinding.inflate(LayoutInflater.from(ctx));
|
||||||
|
|
||||||
|
View view = transferRepoBinding.getRoot();
|
||||||
|
dialogTransferRepository.setContentView(view);
|
||||||
|
|
||||||
|
transferRepoBinding.cancel.setOnClickListener(editProperties -> dialogTransferRepository.dismiss());
|
||||||
|
|
||||||
|
transferRepoBinding.transfer.setOnClickListener(deleteRepo -> {
|
||||||
|
|
||||||
|
String newOwner = String.valueOf(transferRepoBinding.ownerNameForTransfer.getText());
|
||||||
|
String repoName = String.valueOf(transferRepoBinding.repoNameForTransfer.getText());
|
||||||
|
|
||||||
|
if(!repositoryName.equals(repoName)) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.repoSettingsDeleteError));
|
||||||
|
}
|
||||||
|
else if(newOwner.matches("")) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.repoTransferOwnerError));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
transferRepository(newOwner);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialogTransferRepository.setCancelable(false);
|
||||||
|
dialogTransferRepository.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transferRepository(String newOwner) {
|
||||||
|
|
||||||
|
RepositoryTransfer repositoryTransfer = new RepositoryTransfer(newOwner);
|
||||||
|
|
||||||
|
Call<JsonElement> transferCall = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.transferRepository(instanceToken, repositoryOwner, repositoryName, repositoryTransfer);
|
||||||
|
|
||||||
|
transferCall.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||||
|
|
||||||
|
transferRepoBinding.transfer.setVisibility(View.GONE);
|
||||||
|
transferRepoBinding.processingRequest.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (response.code() == 202) {
|
||||||
|
|
||||||
|
dialogTransferRepository.dismiss();
|
||||||
|
Toasty.success(ctx, getString(R.string.repoTransferSuccess));
|
||||||
|
|
||||||
|
finish();
|
||||||
|
BaseApi.getInstance(ctx, RepositoriesApi.class).deleteRepository((int) tinyDB.getLong("repositoryId", 0));
|
||||||
|
Intent intent = new Intent(RepositorySettingsActivity.this, MainActivity.class);
|
||||||
|
RepositorySettingsActivity.this.startActivity(intent);
|
||||||
|
}
|
||||||
|
else if (response.code() == 404) {
|
||||||
|
|
||||||
|
transferRepoBinding.transfer.setVisibility(View.VISIBLE);
|
||||||
|
transferRepoBinding.processingRequest.setVisibility(View.GONE);
|
||||||
|
Toasty.error(ctx, getString(R.string.repoTransferError));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
transferRepoBinding.transfer.setVisibility(View.VISIBLE);
|
||||||
|
transferRepoBinding.processingRequest.setVisibility(View.GONE);
|
||||||
|
Toasty.error(ctx, getString(R.string.genericError));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
transferRepoBinding.transfer.setVisibility(View.VISIBLE);
|
||||||
|
transferRepoBinding.processingRequest.setVisibility(View.GONE);
|
||||||
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showDeleteRepository() {
|
||||||
|
|
||||||
|
dialogDeleteRepository = new Dialog(ctx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
||||||
|
|
||||||
|
if (dialogDeleteRepository.getWindow() != null) {
|
||||||
|
|
||||||
|
dialogDeleteRepository.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteRepoBinding = CustomRepositoryDeleteDialogBinding.inflate(LayoutInflater.from(ctx));
|
||||||
|
|
||||||
|
View view = deleteRepoBinding.getRoot();
|
||||||
|
dialogDeleteRepository.setContentView(view);
|
||||||
|
|
||||||
|
deleteRepoBinding.cancel.setOnClickListener(editProperties -> dialogDeleteRepository.dismiss());
|
||||||
|
|
||||||
|
deleteRepoBinding.delete.setOnClickListener(deleteRepo -> {
|
||||||
|
|
||||||
|
if(!repositoryName.equals(String.valueOf(deleteRepoBinding.repoNameForDeletion.getText()))) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.repoSettingsDeleteError));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
deleteRepository();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialogDeleteRepository.setCancelable(false);
|
||||||
|
dialogDeleteRepository.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteRepository() {
|
||||||
|
|
||||||
|
Call<JsonElement> deleteCall = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.deleteRepository(instanceToken, repositoryOwner, repositoryName);
|
||||||
|
|
||||||
|
deleteCall.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||||
|
|
||||||
|
deleteRepoBinding.delete.setVisibility(View.GONE);
|
||||||
|
deleteRepoBinding.processingRequest.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (response.code() == 204) {
|
||||||
|
|
||||||
|
dialogDeleteRepository.dismiss();
|
||||||
|
Toasty.success(ctx, getString(R.string.repoDeletionSuccess));
|
||||||
|
|
||||||
|
finish();
|
||||||
|
BaseApi.getInstance(ctx, RepositoriesApi.class).deleteRepository((int) tinyDB.getLong("repositoryId", 0));
|
||||||
|
Intent intent = new Intent(RepositorySettingsActivity.this, MainActivity.class);
|
||||||
|
RepositorySettingsActivity.this.startActivity(intent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
deleteRepoBinding.delete.setVisibility(View.VISIBLE);
|
||||||
|
deleteRepoBinding.processingRequest.setVisibility(View.GONE);
|
||||||
|
Toasty.error(ctx, getString(R.string.genericError));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
deleteRepoBinding.delete.setVisibility(View.VISIBLE);
|
||||||
|
deleteRepoBinding.processingRequest.setVisibility(View.GONE);
|
||||||
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showRepositoryProperties() {
|
||||||
|
|
||||||
|
dialogProp = new Dialog(ctx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
||||||
|
|
||||||
|
if (dialogProp.getWindow() != null) {
|
||||||
|
|
||||||
|
dialogProp.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
propBinding = CustomRepositoryEditPropertiesDialogBinding.inflate(LayoutInflater.from(ctx));
|
||||||
|
|
||||||
|
View view = propBinding.getRoot();
|
||||||
|
dialogProp.setContentView(view);
|
||||||
|
|
||||||
|
propBinding.cancel.setOnClickListener(editProperties -> dialogProp.dismiss());
|
||||||
|
|
||||||
|
Call<UserRepositories> call = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.getUserRepository(instanceToken, repositoryOwner, repositoryName);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<UserRepositories>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<UserRepositories> call, @NonNull retrofit2.Response<UserRepositories> response) {
|
||||||
|
|
||||||
|
UserRepositories repoInfo = response.body();
|
||||||
|
|
||||||
|
propBinding.progressBar.setVisibility(View.GONE);
|
||||||
|
propBinding.mainView.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (response.code() == 200) {
|
||||||
|
|
||||||
|
assert repoInfo != null;
|
||||||
|
propBinding.repoName.setText(repoInfo.getName());
|
||||||
|
propBinding.repoWebsite.setText(repoInfo.getWebsite());
|
||||||
|
propBinding.repoDescription.setText(repoInfo.getDescription());
|
||||||
|
propBinding.repoPrivate.setChecked(repoInfo.getPrivateFlag());
|
||||||
|
propBinding.repoAsTemplate.setChecked(repoInfo.isTemplate());
|
||||||
|
|
||||||
|
propBinding.repoEnableIssues.setChecked(repoInfo.getHas_issues());
|
||||||
|
|
||||||
|
propBinding.repoEnableIssues.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
|
||||||
|
if (isChecked) {
|
||||||
|
|
||||||
|
propBinding.repoEnableTimer.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
propBinding.repoEnableTimer.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if(repoInfo.getInternal_tracker() != null) {
|
||||||
|
|
||||||
|
propBinding.repoEnableTimer.setChecked(repoInfo.getInternal_tracker().isEnable_time_tracker());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
propBinding.repoEnableTimer.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
propBinding.repoEnableWiki.setChecked(repoInfo.isHas_wiki());
|
||||||
|
propBinding.repoEnablePr.setChecked(repoInfo.isHas_pull_requests());
|
||||||
|
propBinding.repoEnableMerge.setChecked(repoInfo.isAllow_merge_commits());
|
||||||
|
propBinding.repoEnableRebase.setChecked(repoInfo.isAllow_rebase());
|
||||||
|
propBinding.repoEnableSquash.setChecked(repoInfo.isAllow_squash_merge());
|
||||||
|
propBinding.repoEnableForceMerge.setChecked(repoInfo.isAllow_rebase_explicit());
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.genericError));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<UserRepositories> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
propBinding.save.setOnClickListener(saveProperties -> saveRepositoryProperties(String.valueOf(propBinding.repoName.getText()),
|
||||||
|
String.valueOf(propBinding.repoWebsite.getText()),
|
||||||
|
String.valueOf(propBinding.repoDescription.getText()),
|
||||||
|
propBinding.repoPrivate.isChecked(), propBinding.repoAsTemplate.isChecked(),
|
||||||
|
propBinding.repoEnableIssues.isChecked(), propBinding.repoEnableWiki.isChecked(),
|
||||||
|
propBinding.repoEnablePr.isChecked(), propBinding.repoEnableTimer.isChecked(),
|
||||||
|
propBinding.repoEnableMerge.isChecked(), propBinding.repoEnableRebase.isChecked(),
|
||||||
|
propBinding.repoEnableSquash.isChecked(), propBinding.repoEnableForceMerge.isChecked()));
|
||||||
|
|
||||||
|
dialogProp.setCancelable(false);
|
||||||
|
dialogProp.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveRepositoryProperties(String repoName, String repoWebsite, String repoDescription,
|
||||||
|
boolean repoPrivate, boolean repoAsTemplate, boolean repoEnableIssues, boolean repoEnableWiki,
|
||||||
|
boolean repoEnablePr, boolean repoEnableTimer, boolean repoEnableMerge, boolean repoEnableRebase,
|
||||||
|
boolean repoEnableSquash, boolean repoEnableForceMerge) {
|
||||||
|
|
||||||
|
UserRepositories.internalTimeTrackerObject repoPropsTimeTracker = new UserRepositories.internalTimeTrackerObject(repoEnableTimer);
|
||||||
|
|
||||||
|
UserRepositories repoProps;
|
||||||
|
|
||||||
|
if(!repoEnableIssues) {
|
||||||
|
|
||||||
|
repoProps = new UserRepositories(repoName, repoWebsite, repoDescription, repoPrivate, repoAsTemplate, repoEnableIssues, repoEnableWiki, repoEnablePr, repoEnableMerge,
|
||||||
|
repoEnableRebase, repoEnableSquash, repoEnableForceMerge);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
repoProps = new UserRepositories(repoName, repoWebsite, repoDescription, repoPrivate, repoAsTemplate, repoEnableIssues, repoEnableWiki, repoEnablePr, repoPropsTimeTracker, repoEnableMerge,
|
||||||
|
repoEnableRebase, repoEnableSquash, repoEnableForceMerge);
|
||||||
|
}
|
||||||
|
|
||||||
|
Call<UserRepositories> propsCall = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.updateRepositoryProperties(instanceToken, repositoryOwner, repositoryName, repoProps);
|
||||||
|
|
||||||
|
propsCall.enqueue(new Callback<UserRepositories>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<UserRepositories> call, @NonNull retrofit2.Response<UserRepositories> response) {
|
||||||
|
|
||||||
|
propBinding.save.setVisibility(View.GONE);
|
||||||
|
propBinding.processingRequest.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (response.code() == 200) {
|
||||||
|
|
||||||
|
tinyDB.putBoolean("hasIssues", repoEnableIssues);
|
||||||
|
tinyDB.putBoolean("hasPullRequests", repoEnablePr);
|
||||||
|
|
||||||
|
dialogProp.dismiss();
|
||||||
|
Toasty.success(ctx, getString(R.string.repoPropertiesSaveSuccess));
|
||||||
|
|
||||||
|
if(!repositoryName.equals(repoName)) {
|
||||||
|
|
||||||
|
finish();
|
||||||
|
BaseApi.getInstance(ctx, RepositoriesApi.class).updateRepositoryOwnerAndName(repositoryOwner, repoName, (int) tinyDB.getLong("repositoryId", 0));
|
||||||
|
Intent intent = new Intent(RepositorySettingsActivity.this, MainActivity.class);
|
||||||
|
RepositorySettingsActivity.this.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
propBinding.save.setVisibility(View.VISIBLE);
|
||||||
|
propBinding.processingRequest.setVisibility(View.GONE);
|
||||||
|
Toasty.error(ctx, getString(R.string.genericError));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<UserRepositories> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
propBinding.save.setVisibility(View.VISIBLE);
|
||||||
|
propBinding.processingRequest.setVisibility(View.GONE);
|
||||||
|
Toasty.error(ctx, getString(R.string.genericServerResponseError));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initCloseListener() {
|
||||||
|
onClickListener = view -> finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,17 +1,21 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.app.Dialog;
|
||||||
|
import android.app.TimePickerDialog;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.format.DateFormat;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Switch;
|
import android.widget.TimePicker;
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
import com.google.android.material.switchmaterial.SwitchMaterial;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.databinding.ActivitySettingsAppearanceBinding;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.Version;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -19,122 +23,80 @@ import org.mian.gitnex.helpers.Version;
|
|||||||
|
|
||||||
public class SettingsAppearanceActivity extends BaseActivity {
|
public class SettingsAppearanceActivity extends BaseActivity {
|
||||||
|
|
||||||
private Context appCtx;
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
|
|
||||||
private static String[] timeList = {"Pretty", "Normal"};
|
private static String[] timeList;
|
||||||
private static int timeSelectedChoice = 0;
|
private static int timeSelectedChoice = 0;
|
||||||
|
|
||||||
private static String[] codeBlockList = {"Green - Black", "White - Black", "Grey - Black", "White - Grey", "Dark - White"};
|
private static String[] customFontList;
|
||||||
private static int codeBlockSelectedChoice = 0;
|
|
||||||
|
|
||||||
private static String[] homeScreenList = {"My Repositories", "Starred Repositories", "Organizations", "Repositories", "Profile", "Explore", "Drafts"};
|
|
||||||
private static String[] homeScreenListNew = {"My Repositories", "Starred Repositories", "Organizations", "Repositories", "Profile", "Explore", "Drafts", "Notifications"};
|
|
||||||
private static int homeScreenSelectedChoice = 0;
|
|
||||||
|
|
||||||
private static String[] customFontList = {"Roboto", "Manrope", "Source Code Pro"};
|
|
||||||
private static int customFontSelectedChoice = 0;
|
private static int customFontSelectedChoice = 0;
|
||||||
|
|
||||||
private static String[] themeList = {"Dark", "Light", "Auto (Day/Night)"};
|
private static String[] themeList;
|
||||||
private static int themeSelectedChoice = 0;
|
private static int themeSelectedChoice = 0;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_settings_appearance;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
ActivitySettingsAppearanceBinding activitySettingsAppearanceBinding = ActivitySettingsAppearanceBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activitySettingsAppearanceBinding.getRoot());
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activitySettingsAppearanceBinding.close;
|
||||||
|
|
||||||
final TextView tvDateTimeSelected = findViewById(R.id.tvDateTimeSelected); // setter for time
|
LinearLayout timeFrame = activitySettingsAppearanceBinding.timeFrame;
|
||||||
final TextView codeBlockSelected = findViewById(R.id.codeBlockSelected); // setter for code block
|
LinearLayout customFontFrame = activitySettingsAppearanceBinding.customFontFrame;
|
||||||
final TextView homeScreenSelected = findViewById(R.id.homeScreenSelected); // setter for home screen
|
LinearLayout themeFrame = activitySettingsAppearanceBinding.themeSelectionFrame;
|
||||||
final TextView customFontSelected = findViewById(R.id.customFontSelected); // setter for custom font
|
LinearLayout lightTimeFrame = activitySettingsAppearanceBinding.lightThemeTimeSelectionFrame;
|
||||||
final TextView themeSelected = findViewById(R.id.themeSelected); // setter for theme
|
LinearLayout darkTimeFrame = activitySettingsAppearanceBinding.darkThemeTimeSelectionFrame;
|
||||||
|
|
||||||
LinearLayout timeFrame = findViewById(R.id.timeFrame);
|
SwitchMaterial counterBadgesSwitch = activitySettingsAppearanceBinding.switchCounterBadge;
|
||||||
LinearLayout codeBlockFrame = findViewById(R.id.codeBlockFrame);
|
|
||||||
LinearLayout homeScreenFrame = findViewById(R.id.homeScreenFrame);
|
|
||||||
LinearLayout customFontFrame = findViewById(R.id.customFontFrame);
|
|
||||||
LinearLayout themeFrame = findViewById(R.id.themeSelectionFrame);
|
|
||||||
|
|
||||||
Switch counterBadgesSwitch = findViewById(R.id.switchCounterBadge);
|
timeList = getResources().getStringArray(R.array.timeFormats);
|
||||||
|
customFontList = getResources().getStringArray(R.array.fonts);
|
||||||
|
themeList = getResources().getStringArray(R.array.themes);
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.3")) {
|
String lightMinute = String.valueOf(tinyDB.getInt("lightThemeTimeMinute"));
|
||||||
|
String lightHour = String.valueOf(tinyDB.getInt("lightThemeTimeHour"));
|
||||||
|
if(lightMinute.length() == 1) lightMinute = "0" + lightMinute;
|
||||||
|
if(lightHour.length() == 1) lightHour = "0" + lightHour;
|
||||||
|
|
||||||
homeScreenList = homeScreenListNew;
|
String darkMinute = String.valueOf(tinyDB.getInt("darkThemeTimeMinute"));
|
||||||
}
|
String darkHour = String.valueOf(tinyDB.getInt("darkThemeTimeHour"));
|
||||||
|
if(darkMinute.length() == 1) darkMinute = "0" + darkMinute;
|
||||||
|
if(darkHour.length() == 1) darkHour = "0" + darkHour;
|
||||||
|
|
||||||
if(!tinyDb.getString("timeStr").isEmpty()) {
|
activitySettingsAppearanceBinding.lightThemeSelectedTime.setText(ctx.getResources().getString(R.string.settingsThemeTimeSelectedHint, lightHour,
|
||||||
tvDateTimeSelected.setText(tinyDb.getString("timeStr"));
|
lightMinute));
|
||||||
}
|
activitySettingsAppearanceBinding.darkThemeSelectedTime.setText(ctx.getResources().getString(R.string.settingsThemeTimeSelectedHint, darkHour,
|
||||||
|
darkMinute));
|
||||||
|
activitySettingsAppearanceBinding.tvDateTimeSelected.setText(tinyDB.getString("timeStr"));
|
||||||
|
activitySettingsAppearanceBinding.customFontSelected.setText(tinyDB.getString("customFontStr", "Manrope"));
|
||||||
|
activitySettingsAppearanceBinding.themeSelected.setText(tinyDB.getString("themeStr", "Dark"));
|
||||||
|
|
||||||
if(!tinyDb.getString("codeBlockStr").isEmpty()) {
|
if(tinyDB.getString("themeStr").startsWith("Auto")) {
|
||||||
codeBlockSelected.setText(tinyDb.getString("codeBlockStr"));
|
darkTimeFrame.setVisibility(View.VISIBLE);
|
||||||
}
|
lightTimeFrame.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if(!tinyDb.getString("homeScreenStr").isEmpty()) {
|
|
||||||
homeScreenSelected.setText(tinyDb.getString("homeScreenStr"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!tinyDb.getString("customFontStr").isEmpty()) {
|
|
||||||
customFontSelected.setText(tinyDb.getString("customFontStr"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!tinyDb.getString("themeStr").isEmpty()) {
|
|
||||||
themeSelected.setText(tinyDb.getString("themeStr"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(timeSelectedChoice == 0) {
|
|
||||||
timeSelectedChoice = tinyDb.getInt("timeId");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(codeBlockSelectedChoice == 0) {
|
|
||||||
codeBlockSelectedChoice = tinyDb.getInt("codeBlockId");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(homeScreenSelectedChoice == 0) {
|
|
||||||
homeScreenSelectedChoice = tinyDb.getInt("homeScreenId");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(customFontSelectedChoice == 0) {
|
|
||||||
customFontSelectedChoice = tinyDb.getInt("customFontId", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(themeSelectedChoice == 0) {
|
|
||||||
themeSelectedChoice = tinyDb.getInt("themeId");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(tinyDb.getBoolean("enableCounterBadges")) {
|
|
||||||
counterBadgesSwitch.setChecked(true);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
counterBadgesSwitch.setChecked(false);
|
darkTimeFrame.setVisibility(View.GONE);
|
||||||
|
lightTimeFrame.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeSelectedChoice = tinyDB.getInt("timeId");
|
||||||
|
customFontSelectedChoice = tinyDB.getInt("customFontId", 1);
|
||||||
|
themeSelectedChoice = tinyDB.getInt("themeId");
|
||||||
|
|
||||||
|
counterBadgesSwitch.setChecked(tinyDB.getBoolean("enableCounterBadges"));
|
||||||
|
|
||||||
// counter badge switcher
|
// counter badge switcher
|
||||||
counterBadgesSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
counterBadgesSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
|
||||||
if (isChecked) {
|
tinyDB.putBoolean("enableCounterBadges", isChecked);
|
||||||
tinyDb.putBoolean("enableCounterBadges", true);
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tinyDb.putBoolean("enableCounterBadges", false);
|
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// theme selection dialog
|
// theme selection dialog
|
||||||
@@ -143,31 +105,34 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
|||||||
AlertDialog.Builder tsBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
AlertDialog.Builder tsBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
||||||
|
|
||||||
tsBuilder.setTitle(getResources().getString(R.string.themeSelectorDialogTitle));
|
tsBuilder.setTitle(getResources().getString(R.string.themeSelectorDialogTitle));
|
||||||
if(themeSelectedChoice != -1) {
|
tsBuilder.setCancelable(themeSelectedChoice != -1);
|
||||||
tsBuilder.setCancelable(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tsBuilder.setCancelable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
tsBuilder.setSingleChoiceItems(themeList, themeSelectedChoice, (dialogInterfaceTheme, i) -> {
|
tsBuilder.setSingleChoiceItems(themeList, themeSelectedChoice, (dialogInterfaceTheme, i) -> {
|
||||||
|
|
||||||
themeSelectedChoice = i;
|
themeSelectedChoice = i;
|
||||||
themeSelected.setText(themeList[i]);
|
activitySettingsAppearanceBinding.themeSelected.setText(themeList[i]);
|
||||||
tinyDb.putString("themeStr", themeList[i]);
|
tinyDB.putString("themeStr", themeList[i]);
|
||||||
tinyDb.putInt("themeId", i);
|
tinyDB.putInt("themeId", i);
|
||||||
|
|
||||||
tinyDb.putBoolean("refreshParent", true);
|
tinyDB.putBoolean("refreshParent", true);
|
||||||
this.recreate();
|
this.recreate();
|
||||||
this.overridePendingTransition(0, 0);
|
this.overridePendingTransition(0, 0);
|
||||||
dialogInterfaceTheme.dismiss();
|
dialogInterfaceTheme.dismiss();
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
AlertDialog cfDialog = tsBuilder.create();
|
AlertDialog cfDialog = tsBuilder.create();
|
||||||
cfDialog.show();
|
cfDialog.show();
|
||||||
|
});
|
||||||
|
|
||||||
|
lightTimeFrame.setOnClickListener(view -> {
|
||||||
|
LightTimePicker timePicker = new LightTimePicker();
|
||||||
|
timePicker.show(getSupportFragmentManager(), "timePicker");
|
||||||
|
});
|
||||||
|
|
||||||
|
darkTimeFrame.setOnClickListener(view -> {
|
||||||
|
DarkTimePicker timePicker = new DarkTimePicker();
|
||||||
|
timePicker.show(getSupportFragmentManager(), "timePicker");
|
||||||
});
|
});
|
||||||
|
|
||||||
// custom font dialog
|
// custom font dialog
|
||||||
@@ -176,114 +141,24 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
|||||||
AlertDialog.Builder cfBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
AlertDialog.Builder cfBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
||||||
|
|
||||||
cfBuilder.setTitle(R.string.settingsCustomFontSelectorDialogTitle);
|
cfBuilder.setTitle(R.string.settingsCustomFontSelectorDialogTitle);
|
||||||
if(customFontSelectedChoice != -1) {
|
cfBuilder.setCancelable(customFontSelectedChoice != -1);
|
||||||
cfBuilder.setCancelable(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cfBuilder.setCancelable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
cfBuilder.setSingleChoiceItems(customFontList, customFontSelectedChoice, (dialogInterfaceCustomFont, i) -> {
|
cfBuilder.setSingleChoiceItems(customFontList, customFontSelectedChoice, (dialogInterfaceCustomFont, i) -> {
|
||||||
|
|
||||||
customFontSelectedChoice = i;
|
customFontSelectedChoice = i;
|
||||||
customFontSelected.setText(customFontList[i]);
|
activitySettingsAppearanceBinding.customFontSelected.setText(customFontList[i]);
|
||||||
tinyDb.putString("customFontStr", customFontList[i]);
|
tinyDB.putString("customFontStr", customFontList[i]);
|
||||||
tinyDb.putInt("customFontId", i);
|
tinyDB.putInt("customFontId", i);
|
||||||
|
|
||||||
tinyDb.putBoolean("refreshParent", true);
|
tinyDB.putBoolean("refreshParent", true);
|
||||||
this.recreate();
|
this.recreate();
|
||||||
this.overridePendingTransition(0, 0);
|
this.overridePendingTransition(0, 0);
|
||||||
dialogInterfaceCustomFont.dismiss();
|
dialogInterfaceCustomFont.dismiss();
|
||||||
Toasty.success(appCtx, appCtx.getResources().getString(R.string.settingsSave));
|
Toasty.success(appCtx, appCtx.getResources().getString(R.string.settingsSave));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
AlertDialog cfDialog = cfBuilder.create();
|
AlertDialog cfDialog = cfBuilder.create();
|
||||||
cfDialog.show();
|
cfDialog.show();
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// home screen dialog
|
|
||||||
homeScreenFrame.setOnClickListener(view -> {
|
|
||||||
|
|
||||||
AlertDialog.Builder hsBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
|
||||||
|
|
||||||
hsBuilder.setTitle(R.string.settingsHomeScreenSelectorDialogTitle);
|
|
||||||
if(homeScreenSelectedChoice != -1) {
|
|
||||||
hsBuilder.setCancelable(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
hsBuilder.setCancelable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
hsBuilder.setSingleChoiceItems(homeScreenList, homeScreenSelectedChoice, (dialogInterfaceHomeScreen, i) -> {
|
|
||||||
|
|
||||||
homeScreenSelectedChoice = i;
|
|
||||||
homeScreenSelected.setText(homeScreenList[i]);
|
|
||||||
tinyDb.putString("homeScreenStr", homeScreenList[i]);
|
|
||||||
tinyDb.putInt("homeScreenId", i);
|
|
||||||
|
|
||||||
dialogInterfaceHomeScreen.dismiss();
|
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
AlertDialog hsDialog = hsBuilder.create();
|
|
||||||
hsDialog.show();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// code block dialog
|
|
||||||
codeBlockFrame.setOnClickListener(view -> {
|
|
||||||
|
|
||||||
AlertDialog.Builder cBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
|
||||||
|
|
||||||
cBuilder.setTitle(R.string.settingsCodeBlockSelectorDialogTitle);
|
|
||||||
if(codeBlockSelectedChoice != -1) {
|
|
||||||
cBuilder.setCancelable(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cBuilder.setCancelable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
cBuilder.setSingleChoiceItems(codeBlockList, codeBlockSelectedChoice, (dialogInterfaceCodeBlock, i) -> {
|
|
||||||
|
|
||||||
codeBlockSelectedChoice = i;
|
|
||||||
codeBlockSelected.setText(codeBlockList[i]);
|
|
||||||
tinyDb.putString("codeBlockStr", codeBlockList[i]);
|
|
||||||
tinyDb.putInt("codeBlockId", i);
|
|
||||||
|
|
||||||
switch(codeBlockList[i]) {
|
|
||||||
case "White - Black":
|
|
||||||
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorWhite));
|
|
||||||
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black));
|
|
||||||
break;
|
|
||||||
case "Grey - Black":
|
|
||||||
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorAccent));
|
|
||||||
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black));
|
|
||||||
break;
|
|
||||||
case "White - Grey":
|
|
||||||
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorWhite));
|
|
||||||
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.colorAccent));
|
|
||||||
break;
|
|
||||||
case "Dark - White":
|
|
||||||
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorPrimary));
|
|
||||||
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.colorWhite));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorLightGreen));
|
|
||||||
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
dialogInterfaceCodeBlock.dismiss();
|
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
AlertDialog cDialog = cBuilder.create();
|
|
||||||
cDialog.show();
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// time and date dialog
|
// time and date dialog
|
||||||
@@ -292,36 +167,30 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
|||||||
AlertDialog.Builder tBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
AlertDialog.Builder tBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
||||||
|
|
||||||
tBuilder.setTitle(R.string.settingsTimeSelectorDialogTitle);
|
tBuilder.setTitle(R.string.settingsTimeSelectorDialogTitle);
|
||||||
if(timeSelectedChoice != -1) {
|
tBuilder.setCancelable(timeSelectedChoice != -1);
|
||||||
tBuilder.setCancelable(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tBuilder.setCancelable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
tBuilder.setSingleChoiceItems(timeList, timeSelectedChoice, (dialogInterfaceTime, i) -> {
|
tBuilder.setSingleChoiceItems(timeList, timeSelectedChoice, (dialogInterfaceTime, i) -> {
|
||||||
|
|
||||||
timeSelectedChoice = i;
|
timeSelectedChoice = i;
|
||||||
tvDateTimeSelected.setText(timeList[i]);
|
activitySettingsAppearanceBinding.tvDateTimeSelected.setText(timeList[i]);
|
||||||
tinyDb.putString("timeStr", timeList[i]);
|
tinyDB.putString("timeStr", timeList[i]);
|
||||||
tinyDb.putInt("timeId", i);
|
tinyDB.putInt("timeId", i);
|
||||||
|
|
||||||
if("Normal".equals(timeList[i])) {
|
switch(i) {
|
||||||
tinyDb.putString("dateFormat", "normal");
|
case 0:
|
||||||
}
|
tinyDB.putString("dateFormat", "pretty");
|
||||||
else {
|
break;
|
||||||
tinyDb.putString("dateFormat", "pretty");
|
case 1:
|
||||||
|
tinyDB.putString("dateFormat", "normal");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dialogInterfaceTime.dismiss();
|
dialogInterfaceTime.dismiss();
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
AlertDialog tDialog = tBuilder.create();
|
AlertDialog tDialog = tBuilder.create();
|
||||||
tDialog.show();
|
tDialog.show();
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -330,4 +199,54 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
|||||||
onClickListener = view -> finish();
|
onClickListener = view -> finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class LightTimePicker extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
|
||||||
|
|
||||||
|
TinyDB db = TinyDB.getInstance(getContext());
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
int hour = db.getInt("lightThemeTimeHour");
|
||||||
|
int minute = db.getInt("lightThemeTimeMinute");
|
||||||
|
|
||||||
|
return new TimePickerDialog(getActivity(), this, hour, minute, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||||
|
db.putInt("lightThemeTimeHour", hourOfDay);
|
||||||
|
db.putInt("lightThemeTimeMinute", minute);
|
||||||
|
db.putBoolean("refreshParent", true);
|
||||||
|
requireActivity().overridePendingTransition(0, 0);
|
||||||
|
this.dismiss();
|
||||||
|
Toasty.success(requireActivity().getApplicationContext(), requireContext().getResources().getString(R.string.settingsSave));
|
||||||
|
requireActivity().recreate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DarkTimePicker extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
|
||||||
|
|
||||||
|
TinyDB db = TinyDB.getInstance(getContext());
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
int hour = db.getInt("darkThemeTimeHour");
|
||||||
|
int minute = db.getInt("darkThemeTimeMinute");
|
||||||
|
|
||||||
|
return new TimePickerDialog(getActivity(), this, hour, minute, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||||
|
db.putInt("darkThemeTimeHour", hourOfDay);
|
||||||
|
db.putInt("darkThemeTimeMinute", minute);
|
||||||
|
db.putBoolean("refreshParent", true);
|
||||||
|
requireActivity().overridePendingTransition(0, 0);
|
||||||
|
this.dismiss();
|
||||||
|
Toasty.success(requireActivity().getApplicationContext(), requireContext().getResources().getString(R.string.settingsSave));
|
||||||
|
requireActivity().recreate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.Switch;
|
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.databinding.ActivitySettingsDraftsBinding;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -15,49 +13,28 @@ import org.mian.gitnex.helpers.TinyDB;
|
|||||||
|
|
||||||
public class SettingsDraftsActivity extends BaseActivity {
|
public class SettingsDraftsActivity extends BaseActivity {
|
||||||
|
|
||||||
private Context appCtx;
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_settings_drafts;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
ActivitySettingsDraftsBinding activitySettingsDraftsBinding = ActivitySettingsDraftsBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activitySettingsDraftsBinding.getRoot());
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activitySettingsDraftsBinding.close;
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
Switch commentsDeletionSwitch = findViewById(R.id.commentsDeletionSwitch);
|
activitySettingsDraftsBinding.commentsDeletionSwitch.setChecked(tinyDB.getBoolean("draftsCommentsDeletionEnabled"));
|
||||||
|
|
||||||
if(tinyDb.getBoolean("draftsCommentsDeletionEnabled")) {
|
|
||||||
commentsDeletionSwitch.setChecked(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
commentsDeletionSwitch.setChecked(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete comments on submit switcher
|
// delete comments on submit switcher
|
||||||
commentsDeletionSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
activitySettingsDraftsBinding.commentsDeletionSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
|
||||||
if(isChecked) {
|
|
||||||
tinyDb.putBoolean("draftsCommentsDeletionEnabled", true);
|
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tinyDb.putBoolean("draftsCommentsDeletionEnabled", false);
|
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
tinyDB.putBoolean("draftsCommentsDeletionEnabled", isChecked);
|
||||||
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,119 +0,0 @@
|
|||||||
package org.mian.gitnex.activities;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.Switch;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import org.mian.gitnex.R;
|
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Author M M Arif
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class SettingsFileViewerActivity extends BaseActivity {
|
|
||||||
|
|
||||||
private Context appCtx;
|
|
||||||
private View.OnClickListener onClickListener;
|
|
||||||
|
|
||||||
private static String[] fileViewerSourceCodeThemesList = {"Sublime", "Arduino Light", "Github", "Far ", "Ir Black", "Android Studio"};
|
|
||||||
private static int fileViewerSourceCodeThemesSelectedChoice = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_settings_fileview;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
|
||||||
|
|
||||||
initCloseListener();
|
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
|
||||||
|
|
||||||
final TextView fileViewerSourceCodeThemesSelected = findViewById(R.id.sourceCodeThemeSelected); // setter for fileviewer theme
|
|
||||||
|
|
||||||
LinearLayout sourceCodeThemeFrame = findViewById(R.id.sourceCodeThemeFrame);
|
|
||||||
|
|
||||||
Switch pdfModeSwitch = findViewById(R.id.switchPdfMode);
|
|
||||||
|
|
||||||
if(!tinyDb.getString("fileviewerSourceCodeThemeStr").isEmpty()) {
|
|
||||||
fileViewerSourceCodeThemesSelected.setText(tinyDb.getString("fileviewerSourceCodeThemeStr"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(fileViewerSourceCodeThemesSelectedChoice == 0) {
|
|
||||||
fileViewerSourceCodeThemesSelectedChoice = tinyDb.getInt("fileviewerThemeId");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(tinyDb.getBoolean("enablePdfMode")) {
|
|
||||||
pdfModeSwitch.setChecked(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pdfModeSwitch.setChecked(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// fileviewer srouce code theme selection dialog
|
|
||||||
sourceCodeThemeFrame.setOnClickListener(view -> {
|
|
||||||
|
|
||||||
AlertDialog.Builder fvtsBuilder = new AlertDialog.Builder(SettingsFileViewerActivity.this);
|
|
||||||
|
|
||||||
fvtsBuilder.setTitle(R.string.fileviewerSourceCodeThemeSelectorDialogTitle);
|
|
||||||
if(fileViewerSourceCodeThemesSelectedChoice != -1) {
|
|
||||||
fvtsBuilder.setCancelable(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fvtsBuilder.setCancelable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
fvtsBuilder.setSingleChoiceItems(fileViewerSourceCodeThemesList, fileViewerSourceCodeThemesSelectedChoice, (dialogInterfaceTheme, i) -> {
|
|
||||||
|
|
||||||
fileViewerSourceCodeThemesSelectedChoice = i;
|
|
||||||
fileViewerSourceCodeThemesSelected.setText(fileViewerSourceCodeThemesList[i]);
|
|
||||||
tinyDb.putString("fileviewerSourceCodeThemeStr", fileViewerSourceCodeThemesList[i]);
|
|
||||||
tinyDb.putInt("fileviewerSourceCodeThemeId", i);
|
|
||||||
|
|
||||||
dialogInterfaceTheme.dismiss();
|
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
AlertDialog cfDialog = fvtsBuilder.create();
|
|
||||||
cfDialog.show();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// pdf night mode switcher
|
|
||||||
pdfModeSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
||||||
|
|
||||||
if(isChecked) {
|
|
||||||
tinyDb.putBoolean("enablePdfMode", true);
|
|
||||||
tinyDb.putString("enablePdfModeInit", "yes");
|
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tinyDb.putBoolean("enablePdfMode", false);
|
|
||||||
tinyDb.putString("enablePdfModeInit", "yes");
|
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initCloseListener() {
|
|
||||||
onClickListener = view -> finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.databinding.ActivitySettingsGeneralBinding;
|
||||||
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import org.mian.gitnex.helpers.Version;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SettingsGeneralActivity extends BaseActivity {
|
||||||
|
|
||||||
|
private ActivitySettingsGeneralBinding viewBinding;
|
||||||
|
private View.OnClickListener onClickListener;
|
||||||
|
|
||||||
|
private List<String> homeScreenList;
|
||||||
|
private static int homeScreenSelectedChoice = 0;
|
||||||
|
|
||||||
|
private List<String> linkHandlerDefaultScreen;
|
||||||
|
private static int defaultLinkHandlerScreenSelectedChoice = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
viewBinding = ActivitySettingsGeneralBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(viewBinding.getRoot());
|
||||||
|
|
||||||
|
initCloseListener();
|
||||||
|
viewBinding.close.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
|
// home screen
|
||||||
|
String[] appHomeDefaultScreen = getResources().getStringArray(R.array.appDefaultHomeScreen);
|
||||||
|
|
||||||
|
String[] appHomeDefaultScreenNew = getResources().getStringArray(R.array.appDefaultHomeScreenNew);
|
||||||
|
|
||||||
|
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.3")) {
|
||||||
|
|
||||||
|
appHomeDefaultScreen = appHomeDefaultScreenNew;
|
||||||
|
}
|
||||||
|
|
||||||
|
homeScreenList = new ArrayList<>(Arrays.asList(appHomeDefaultScreen));
|
||||||
|
String[] homeScreenArray = new String[homeScreenList.size()];
|
||||||
|
homeScreenList.toArray(homeScreenArray);
|
||||||
|
|
||||||
|
if(homeScreenSelectedChoice == 0) {
|
||||||
|
|
||||||
|
homeScreenSelectedChoice = tinyDB.getInt("homeScreenId");
|
||||||
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleMyRepos));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(homeScreenSelectedChoice == 1) {
|
||||||
|
|
||||||
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
||||||
|
}
|
||||||
|
else if(homeScreenSelectedChoice == 2) {
|
||||||
|
|
||||||
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleOrganizations));
|
||||||
|
}
|
||||||
|
else if(homeScreenSelectedChoice == 3) {
|
||||||
|
|
||||||
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleRepositories));
|
||||||
|
}
|
||||||
|
else if(homeScreenSelectedChoice == 4) {
|
||||||
|
|
||||||
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleProfile));
|
||||||
|
}
|
||||||
|
else if(homeScreenSelectedChoice == 5) {
|
||||||
|
|
||||||
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleExplore));
|
||||||
|
}
|
||||||
|
else if(homeScreenSelectedChoice == 6) {
|
||||||
|
|
||||||
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.titleDrafts));
|
||||||
|
}
|
||||||
|
else if(homeScreenSelectedChoice == 7) {
|
||||||
|
|
||||||
|
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleNotifications));
|
||||||
|
}
|
||||||
|
|
||||||
|
viewBinding.homeScreenFrame.setOnClickListener(setDefaultHomeScreen -> {
|
||||||
|
|
||||||
|
AlertDialog.Builder hsBuilder = new AlertDialog.Builder(SettingsGeneralActivity.this);
|
||||||
|
|
||||||
|
hsBuilder.setTitle(R.string.settingsHomeScreenSelectorDialogTitle);
|
||||||
|
hsBuilder.setCancelable(homeScreenSelectedChoice != -1);
|
||||||
|
|
||||||
|
hsBuilder.setSingleChoiceItems(homeScreenArray, homeScreenSelectedChoice, (dialogInterfaceHomeScreen, i) -> {
|
||||||
|
|
||||||
|
homeScreenSelectedChoice = i;
|
||||||
|
viewBinding.homeScreenSelected.setText(homeScreenArray[i]);
|
||||||
|
tinyDB.putInt("homeScreenId", i);
|
||||||
|
|
||||||
|
dialogInterfaceHomeScreen.dismiss();
|
||||||
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
});
|
||||||
|
|
||||||
|
AlertDialog hsDialog = hsBuilder.create();
|
||||||
|
hsDialog.show();
|
||||||
|
});
|
||||||
|
// home screen
|
||||||
|
|
||||||
|
// link handler
|
||||||
|
String[] linkHandlerDefaultScreenList = getResources().getStringArray(R.array.linkHandlerDefaultScreen);
|
||||||
|
linkHandlerDefaultScreen = new ArrayList<>(Arrays.asList(linkHandlerDefaultScreenList));
|
||||||
|
|
||||||
|
String[] linksArray = new String[linkHandlerDefaultScreen.size()];
|
||||||
|
linkHandlerDefaultScreen.toArray(linksArray);
|
||||||
|
|
||||||
|
defaultLinkHandlerScreenSelectedChoice = tinyDB.getInt("defaultScreenId");
|
||||||
|
viewBinding.generalDeepLinkSelected.setText(linksArray[defaultLinkHandlerScreenSelectedChoice]);
|
||||||
|
|
||||||
|
viewBinding.setDefaultLinkHandler.setOnClickListener(setDefaultLinkHandler -> {
|
||||||
|
|
||||||
|
AlertDialog.Builder dlBuilder = new AlertDialog.Builder(SettingsGeneralActivity.this);
|
||||||
|
dlBuilder.setTitle(R.string.linkSelectorDialogTitle);
|
||||||
|
|
||||||
|
dlBuilder.setCancelable(defaultLinkHandlerScreenSelectedChoice != -1);
|
||||||
|
|
||||||
|
dlBuilder.setSingleChoiceItems(linksArray, defaultLinkHandlerScreenSelectedChoice, (dialogInterfaceHomeScreen, i) -> {
|
||||||
|
|
||||||
|
defaultLinkHandlerScreenSelectedChoice = i;
|
||||||
|
viewBinding.generalDeepLinkSelected.setText(linksArray[i]);
|
||||||
|
tinyDB.putInt("defaultScreenId", i);
|
||||||
|
|
||||||
|
dialogInterfaceHomeScreen.dismiss();
|
||||||
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
});
|
||||||
|
|
||||||
|
AlertDialog dlDialog = dlBuilder.create();
|
||||||
|
dlDialog.show();
|
||||||
|
});
|
||||||
|
// link handler
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initCloseListener() { onClickListener = view -> finish(); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.NumberPicker;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import com.pes.androidmaterialcolorpickerdialog.ColorPicker;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.databinding.ActivitySettingsNotificationsBinding;
|
||||||
|
import org.mian.gitnex.helpers.Constants;
|
||||||
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import org.mian.gitnex.notifications.Notifications;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template Author M M Arif
|
||||||
|
* Author opyale
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SettingsNotificationsActivity extends BaseActivity {
|
||||||
|
|
||||||
|
private ActivitySettingsNotificationsBinding viewBinding;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
viewBinding = ActivitySettingsNotificationsBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(viewBinding.getRoot());
|
||||||
|
|
||||||
|
View.OnClickListener onClickListener = viewClose -> finish();
|
||||||
|
|
||||||
|
viewBinding.close.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
|
viewBinding.pollingDelaySelected.setText(String.format(getString(R.string.pollingDelaySelectedText), tinyDB.getInt("pollingDelayMinutes", Constants.defaultPollingDelay)));
|
||||||
|
viewBinding.chooseColorState.setCardBackgroundColor(tinyDB.getInt("notificationsLightColor", Color.GREEN));
|
||||||
|
|
||||||
|
viewBinding.enableNotificationsMode.setChecked(tinyDB.getBoolean("notificationsEnabled", true));
|
||||||
|
viewBinding.enableLightsMode.setChecked(tinyDB.getBoolean("notificationsEnableLights", true));
|
||||||
|
viewBinding.enableVibrationMode.setChecked(tinyDB.getBoolean("notificationsEnableVibration", true));
|
||||||
|
|
||||||
|
viewBinding.enableNotificationsMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
|
||||||
|
tinyDB.putBoolean("notificationsEnabled", isChecked);
|
||||||
|
|
||||||
|
if(isChecked) {
|
||||||
|
Notifications.startWorker(ctx);
|
||||||
|
} else {
|
||||||
|
Notifications.stopWorker(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// polling delay
|
||||||
|
viewBinding.pollingDelayFrame.setOnClickListener(v -> {
|
||||||
|
|
||||||
|
NumberPicker numberPicker = new NumberPicker(ctx);
|
||||||
|
numberPicker.setMinValue(Constants.minimumPollingDelay);
|
||||||
|
numberPicker.setMaxValue(Constants.maximumPollingDelay);
|
||||||
|
numberPicker.setValue(tinyDB.getInt("pollingDelayMinutes", Constants.defaultPollingDelay));
|
||||||
|
numberPicker.setWrapSelectorWheel(true);
|
||||||
|
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
|
||||||
|
builder.setTitle(getString(R.string.pollingDelayDialogHeaderText));
|
||||||
|
builder.setMessage(getString(R.string.pollingDelayDialogDescriptionText));
|
||||||
|
|
||||||
|
builder.setCancelable(true);
|
||||||
|
builder.setPositiveButton(getString(R.string.okButton), (dialog, which) -> {
|
||||||
|
|
||||||
|
tinyDB.putInt("pollingDelayMinutes", numberPicker.getValue());
|
||||||
|
|
||||||
|
Notifications.stopWorker(ctx);
|
||||||
|
Notifications.startWorker(ctx);
|
||||||
|
|
||||||
|
viewBinding.pollingDelaySelected.setText(String.format(getString(R.string.pollingDelaySelectedText), numberPicker.getValue()));
|
||||||
|
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.setNeutralButton(R.string.cancelButton, (dialog, which) -> dialog.dismiss());
|
||||||
|
builder.setView(numberPicker);
|
||||||
|
builder.create().show();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// lights switcher
|
||||||
|
viewBinding.enableLightsMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
|
||||||
|
tinyDB.putBoolean("notificationsEnableLights", isChecked);
|
||||||
|
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// lights color chooser
|
||||||
|
viewBinding.chooseColorFrame.setOnClickListener(v -> {
|
||||||
|
|
||||||
|
ColorPicker colorPicker = new ColorPicker(SettingsNotificationsActivity.this);
|
||||||
|
colorPicker.setColor(tinyDB.getInt("notificationsLightColor", Color.GREEN));
|
||||||
|
colorPicker.setCallback(color -> {
|
||||||
|
|
||||||
|
tinyDB.putInt("notificationsLightColor", color);
|
||||||
|
viewBinding.chooseColorState.setCardBackgroundColor(color);
|
||||||
|
colorPicker.dismiss();
|
||||||
|
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
});
|
||||||
|
|
||||||
|
colorPicker.show();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// vibration switcher
|
||||||
|
viewBinding.enableVibrationMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
|
||||||
|
tinyDB.putBoolean("notificationsEnableVibration", isChecked);
|
||||||
|
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.Switch;
|
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.databinding.ActivitySettingsReportsBinding;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,51 +13,29 @@ import org.mian.gitnex.helpers.Toasty;
|
|||||||
|
|
||||||
public class SettingsReportsActivity extends BaseActivity {
|
public class SettingsReportsActivity extends BaseActivity {
|
||||||
|
|
||||||
private Context appCtx;
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_settings_reporting;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
ActivitySettingsReportsBinding activitySettingsReportsBinding = ActivitySettingsReportsBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activitySettingsReportsBinding.getRoot());
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activitySettingsReportsBinding.close;
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
Switch crashReportsSwitch = findViewById(R.id.crashReportsSwitch);
|
activitySettingsReportsBinding.crashReportsSwitch.setChecked(tinyDB.getBoolean("crashReportingEnabled"));
|
||||||
|
|
||||||
if(tinyDb.getBoolean("crashReportingEnabled")) {
|
|
||||||
crashReportsSwitch.setChecked(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
crashReportsSwitch.setChecked(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// crash reports switcher
|
// crash reports switcher
|
||||||
crashReportsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
activitySettingsReportsBinding.crashReportsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
|
||||||
if(isChecked) {
|
|
||||||
tinyDb.putBoolean("crashReportingEnabled", true);
|
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tinyDb.putBoolean("crashReportingEnabled", false);
|
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
tinyDB.putBoolean("crashReportingEnabled", isChecked);
|
||||||
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.app.KeyguardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.NumberPicker;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.biometric.BiometricManager;
|
||||||
|
import com.google.android.material.switchmaterial.SwitchMaterial;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.databinding.ActivitySettingsSecurityBinding;
|
||||||
import org.mian.gitnex.helpers.FilesData;
|
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.Version;
|
|
||||||
import org.mian.gitnex.helpers.ssl.MemorizingTrustManager;
|
import org.mian.gitnex.helpers.ssl.MemorizingTrustManager;
|
||||||
import org.mian.gitnex.notifications.NotificationsMaster;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashSet;
|
import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
|
||||||
|
import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -29,80 +29,128 @@ import java.util.HashSet;
|
|||||||
|
|
||||||
public class SettingsSecurityActivity extends BaseActivity {
|
public class SettingsSecurityActivity extends BaseActivity {
|
||||||
|
|
||||||
private Context appCtx;
|
|
||||||
private Context ctx = this;
|
|
||||||
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
|
|
||||||
private static String[] cacheSizeDataList = {"50 MB", "100 MB", "250 MB", "500 MB", "1 GB"};
|
private static String[] cacheSizeDataList;
|
||||||
private static int cacheSizeDataSelectedChoice = 0;
|
private static int cacheSizeDataSelectedChoice = 0;
|
||||||
|
|
||||||
private static String[] cacheSizeImagesList = {"50 MB", "100 MB", "250 MB", "500 MB", "1 GB"};
|
private static String[] cacheSizeImagesList;
|
||||||
private static int cacheSizeImagesSelectedChoice = 0;
|
private static int cacheSizeImagesSelectedChoice = 0;
|
||||||
|
|
||||||
private static int MINIMUM_POLLING_DELAY = 1;
|
|
||||||
private static int DEFAULT_POLLING_DELAY = 20;
|
|
||||||
private static int MAXIMUM_POLLING_DELAY = 720;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_settings_security;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
ActivitySettingsSecurityBinding activitySettingsSecurityBinding = ActivitySettingsSecurityBinding.inflate(getLayoutInflater());
|
||||||
String currentVersion = tinyDb.getString("giteaVersion");
|
setContentView(activitySettingsSecurityBinding.getRoot());
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ImageView closeActivity = activitySettingsSecurityBinding.close;
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
TextView cacheSizeDataSelected = findViewById(R.id.cacheSizeDataSelected); // setter for data cache size
|
TextView cacheSizeDataSelected = activitySettingsSecurityBinding.cacheSizeDataSelected; // setter for data cache size
|
||||||
TextView cacheSizeImagesSelected = findViewById(R.id.cacheSizeImagesSelected); // setter for images cache size
|
TextView cacheSizeImagesSelected = activitySettingsSecurityBinding.cacheSizeImagesSelected; // setter for images cache size
|
||||||
TextView clearCacheSelected = findViewById(R.id.clearCacheSelected); // setter for clear cache
|
TextView clearCacheSelected = activitySettingsSecurityBinding.clearCacheSelected; // setter for clear cache
|
||||||
TextView pollingDelaySelected = findViewById(R.id.pollingDelaySelected);
|
|
||||||
|
|
||||||
LinearLayout certsFrame = findViewById(R.id.certsFrame);
|
LinearLayout certsFrame = activitySettingsSecurityBinding.certsFrame;
|
||||||
LinearLayout pollingDelayFrame = findViewById(R.id.pollingDelayFrame);
|
LinearLayout cacheSizeDataFrame = activitySettingsSecurityBinding.cacheSizeDataSelectionFrame;
|
||||||
LinearLayout cacheSizeDataFrame = findViewById(R.id.cacheSizeDataSelectionFrame);
|
LinearLayout cacheSizeImagesFrame = activitySettingsSecurityBinding.cacheSizeImagesSelectionFrame;
|
||||||
LinearLayout cacheSizeImagesFrame = findViewById(R.id.cacheSizeImagesSelectionFrame);
|
LinearLayout clearCacheFrame = activitySettingsSecurityBinding.clearCacheSelectionFrame;
|
||||||
LinearLayout clearCacheFrame = findViewById(R.id.clearCacheSelectionFrame);
|
|
||||||
|
|
||||||
if(!tinyDb.getString("cacheSizeStr").isEmpty()) {
|
SwitchMaterial switchBiometric = activitySettingsSecurityBinding.switchBiometric;
|
||||||
cacheSizeDataSelected.setText(tinyDb.getString("cacheSizeStr"));
|
|
||||||
|
cacheSizeDataList = getResources().getStringArray(R.array.cacheSizeList);
|
||||||
|
cacheSizeImagesList = getResources().getStringArray(R.array.cacheSizeList);
|
||||||
|
|
||||||
|
if(!tinyDB.getString("cacheSizeStr").isEmpty()) {
|
||||||
|
|
||||||
|
cacheSizeDataSelected.setText(tinyDB.getString("cacheSizeStr"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!tinyDb.getString("cacheSizeImagesStr").isEmpty()) {
|
if(!tinyDB.getString("cacheSizeImagesStr").isEmpty()) {
|
||||||
cacheSizeImagesSelected.setText(tinyDb.getString("cacheSizeImagesStr"));
|
|
||||||
|
cacheSizeImagesSelected.setText(tinyDB.getString("cacheSizeImagesStr"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cacheSizeDataSelectedChoice == 0) {
|
if(cacheSizeDataSelectedChoice == 0) {
|
||||||
cacheSizeDataSelectedChoice = tinyDb.getInt("cacheSizeId");
|
|
||||||
|
cacheSizeDataSelectedChoice = tinyDB.getInt("cacheSizeId");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cacheSizeImagesSelectedChoice == 0) {
|
if(cacheSizeImagesSelectedChoice == 0) {
|
||||||
cacheSizeImagesSelectedChoice = tinyDb.getInt("cacheSizeImagesId");
|
|
||||||
|
cacheSizeImagesSelectedChoice = tinyDB.getInt("cacheSizeImagesId");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(new Version(currentVersion).less("1.12.3")) {
|
switchBiometric.setChecked(tinyDB.getBoolean("biometricStatus"));
|
||||||
pollingDelayFrame.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
pollingDelaySelected.setText(String.format(getString(R.string.pollingDelaySelectedText), tinyDb.getInt("pollingDelayMinutes", DEFAULT_POLLING_DELAY)));
|
// biometric switcher
|
||||||
|
switchBiometric.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
|
||||||
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
|
||||||
|
if(isChecked) {
|
||||||
|
|
||||||
|
BiometricManager biometricManager = BiometricManager.from(ctx);
|
||||||
|
KeyguardManager keyguardManager = (KeyguardManager) ctx.getSystemService(Context.KEYGUARD_SERVICE);
|
||||||
|
|
||||||
|
if (!keyguardManager.isDeviceSecure()) {
|
||||||
|
|
||||||
|
switch(biometricManager.canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL)) {
|
||||||
|
|
||||||
|
case BiometricManager.BIOMETRIC_SUCCESS:
|
||||||
|
|
||||||
|
tinyDB.putBoolean("biometricStatus", true);
|
||||||
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
break;
|
||||||
|
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
|
||||||
|
case BiometricManager.BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED:
|
||||||
|
case BiometricManager.BIOMETRIC_ERROR_UNSUPPORTED:
|
||||||
|
case BiometricManager.BIOMETRIC_STATUS_UNKNOWN:
|
||||||
|
|
||||||
|
tinyDB.putBoolean("biometricStatus", false);
|
||||||
|
switchBiometric.setChecked(false);
|
||||||
|
Toasty.error(appCtx, getResources().getString(R.string.biometricNotSupported));
|
||||||
|
break;
|
||||||
|
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
|
||||||
|
|
||||||
|
tinyDB.putBoolean("biometricStatus", false);
|
||||||
|
switchBiometric.setChecked(false);
|
||||||
|
Toasty.error(appCtx, getResources().getString(R.string.biometricNotAvailable));
|
||||||
|
break;
|
||||||
|
case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
|
||||||
|
|
||||||
|
tinyDB.putBoolean("biometricStatus", false);
|
||||||
|
switchBiometric.setChecked(false);
|
||||||
|
Toasty.info(appCtx, getResources().getString(R.string.enrollBiometric));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
tinyDB.putBoolean("biometricStatus", true);
|
||||||
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
tinyDB.putBoolean("biometricStatus", false);
|
||||||
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
tinyDB.putBoolean("biometricStatus", false);
|
||||||
|
Toasty.success(appCtx, getResources().getString(R.string.biometricNotSupported));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
// clear cache setter
|
// clear cache setter
|
||||||
File cacheDir = appCtx.getCacheDir();
|
File cacheDir = appCtx.getCacheDir();
|
||||||
long size__ = FilesData.getFileSizeRecursively(new HashSet<>(), cacheDir);
|
clearCacheSelected.setText(FileUtils.byteCountToDisplaySize((int) FileUtils.sizeOfDirectory(cacheDir)));
|
||||||
if(size__ > 0) {
|
|
||||||
clearCacheSelected.setText(String.valueOf(AppUtil.formatFileSizeInDetail(size__)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// clear cache
|
// clear cache
|
||||||
clearCacheFrame.setOnClickListener(v1 -> {
|
clearCacheFrame.setOnClickListener(v1 -> {
|
||||||
@@ -119,14 +167,11 @@ public class SettingsSecurityActivity extends BaseActivity {
|
|||||||
FileUtils.mkdir(cacheDir.getAbsolutePath());
|
FileUtils.mkdir(cacheDir.getAbsolutePath());
|
||||||
this.recreate();
|
this.recreate();
|
||||||
this.overridePendingTransition(0, 0);
|
this.overridePendingTransition(0, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
|
|
||||||
Log.e("SettingsSecurity", e.toString());
|
Log.e("SettingsSecurity", e.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.setNeutralButton(R.string.cancelButton, (dialog, which) -> dialog.dismiss());
|
builder.setNeutralButton(R.string.cancelButton, (dialog, which) -> dialog.dismiss());
|
||||||
@@ -140,28 +185,21 @@ public class SettingsSecurityActivity extends BaseActivity {
|
|||||||
AlertDialog.Builder tsBuilder = new AlertDialog.Builder(SettingsSecurityActivity.this);
|
AlertDialog.Builder tsBuilder = new AlertDialog.Builder(SettingsSecurityActivity.this);
|
||||||
|
|
||||||
tsBuilder.setTitle(getResources().getString(R.string.cacheSizeImagesDialogHeader));
|
tsBuilder.setTitle(getResources().getString(R.string.cacheSizeImagesDialogHeader));
|
||||||
if(cacheSizeImagesSelectedChoice != -1) {
|
tsBuilder.setCancelable(cacheSizeImagesSelectedChoice != -1);
|
||||||
tsBuilder.setCancelable(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tsBuilder.setCancelable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
tsBuilder.setSingleChoiceItems(cacheSizeImagesList, cacheSizeImagesSelectedChoice, (dialogInterfaceTheme, i) -> {
|
tsBuilder.setSingleChoiceItems(cacheSizeImagesList, cacheSizeImagesSelectedChoice, (dialogInterfaceTheme, i) -> {
|
||||||
|
|
||||||
cacheSizeImagesSelectedChoice = i;
|
cacheSizeImagesSelectedChoice = i;
|
||||||
cacheSizeImagesSelected.setText(cacheSizeImagesList[i]);
|
cacheSizeImagesSelected.setText(cacheSizeImagesList[i]);
|
||||||
tinyDb.putString("cacheSizeImagesStr", cacheSizeImagesList[i]);
|
tinyDB.putString("cacheSizeImagesStr", cacheSizeImagesList[i]);
|
||||||
tinyDb.putInt("cacheSizeImagesId", i);
|
tinyDB.putInt("cacheSizeImagesId", i);
|
||||||
|
|
||||||
dialogInterfaceTheme.dismiss();
|
dialogInterfaceTheme.dismiss();
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
AlertDialog cfDialog = tsBuilder.create();
|
AlertDialog cfDialog = tsBuilder.create();
|
||||||
cfDialog.show();
|
cfDialog.show();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// cache size data selection dialog
|
// cache size data selection dialog
|
||||||
@@ -170,28 +208,21 @@ public class SettingsSecurityActivity extends BaseActivity {
|
|||||||
AlertDialog.Builder tsBuilder = new AlertDialog.Builder(SettingsSecurityActivity.this);
|
AlertDialog.Builder tsBuilder = new AlertDialog.Builder(SettingsSecurityActivity.this);
|
||||||
|
|
||||||
tsBuilder.setTitle(getResources().getString(R.string.cacheSizeDataDialogHeader));
|
tsBuilder.setTitle(getResources().getString(R.string.cacheSizeDataDialogHeader));
|
||||||
if(cacheSizeDataSelectedChoice != -1) {
|
tsBuilder.setCancelable(cacheSizeDataSelectedChoice != -1);
|
||||||
tsBuilder.setCancelable(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tsBuilder.setCancelable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
tsBuilder.setSingleChoiceItems(cacheSizeDataList, cacheSizeDataSelectedChoice, (dialogInterfaceTheme, i) -> {
|
tsBuilder.setSingleChoiceItems(cacheSizeDataList, cacheSizeDataSelectedChoice, (dialogInterfaceTheme, i) -> {
|
||||||
|
|
||||||
cacheSizeDataSelectedChoice = i;
|
cacheSizeDataSelectedChoice = i;
|
||||||
cacheSizeDataSelected.setText(cacheSizeDataList[i]);
|
cacheSizeDataSelected.setText(cacheSizeDataList[i]);
|
||||||
tinyDb.putString("cacheSizeStr", cacheSizeDataList[i]);
|
tinyDB.putString("cacheSizeStr", cacheSizeDataList[i]);
|
||||||
tinyDb.putInt("cacheSizeId", i);
|
tinyDB.putInt("cacheSizeId", i);
|
||||||
|
|
||||||
dialogInterfaceTheme.dismiss();
|
dialogInterfaceTheme.dismiss();
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
AlertDialog cfDialog = tsBuilder.create();
|
AlertDialog cfDialog = tsBuilder.create();
|
||||||
cfDialog.show();
|
cfDialog.show();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// certs deletion
|
// certs deletion
|
||||||
@@ -205,53 +236,18 @@ public class SettingsSecurityActivity extends BaseActivity {
|
|||||||
|
|
||||||
appCtx.getSharedPreferences(MemorizingTrustManager.KEYSTORE_NAME, Context.MODE_PRIVATE).edit().remove(MemorizingTrustManager.KEYSTORE_KEY).apply();
|
appCtx.getSharedPreferences(MemorizingTrustManager.KEYSTORE_NAME, Context.MODE_PRIVATE).edit().remove(MemorizingTrustManager.KEYSTORE_KEY).apply();
|
||||||
|
|
||||||
tinyDb.putBoolean("loggedInMode", false);
|
tinyDB.putBoolean("loggedInMode", false);
|
||||||
tinyDb.remove("basicAuthPassword");
|
tinyDB.remove("basicAuthPassword");
|
||||||
tinyDb.putBoolean("basicAuthFlag", false);
|
tinyDB.putBoolean("basicAuthFlag", false);
|
||||||
|
|
||||||
Intent loginActivityIntent = new Intent().setClass(appCtx, LoginActivity.class);
|
Intent loginActivityIntent = new Intent().setClass(appCtx, LoginActivity.class);
|
||||||
loginActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
loginActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
appCtx.startActivity(loginActivityIntent);
|
appCtx.startActivity(loginActivityIntent);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.setNeutralButton(R.string.cancelButton, (dialog, which) -> dialog.dismiss());
|
builder.setNeutralButton(R.string.cancelButton, (dialog, which) -> dialog.dismiss());
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// polling delay
|
|
||||||
pollingDelayFrame.setOnClickListener(v -> {
|
|
||||||
|
|
||||||
NumberPicker numberPicker = new NumberPicker(ctx);
|
|
||||||
numberPicker.setMinValue(MINIMUM_POLLING_DELAY);
|
|
||||||
numberPicker.setMaxValue(MAXIMUM_POLLING_DELAY);
|
|
||||||
numberPicker.setValue(tinyDb.getInt("pollingDelayMinutes", DEFAULT_POLLING_DELAY));
|
|
||||||
numberPicker.setWrapSelectorWheel(true);
|
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
|
|
||||||
builder.setTitle(getString(R.string.pollingDelayDialogHeaderText));
|
|
||||||
builder.setMessage(getString(R.string.pollingDelayDialogDescriptionText));
|
|
||||||
|
|
||||||
builder.setCancelable(true);
|
|
||||||
builder.setPositiveButton(getString(R.string.okButton), (dialog, which) -> {
|
|
||||||
|
|
||||||
tinyDb.putInt("pollingDelayMinutes", numberPicker.getValue());
|
|
||||||
|
|
||||||
NotificationsMaster.fireWorker(ctx);
|
|
||||||
NotificationsMaster.hireWorker(ctx);
|
|
||||||
|
|
||||||
pollingDelaySelected.setText(String.format(getString(R.string.pollingDelaySelectedText), numberPicker.getValue()));
|
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.setNeutralButton(R.string.cancelButton, null);
|
|
||||||
builder.setView(numberPicker);
|
|
||||||
builder.create().show();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.mian.gitnex.activities;
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -10,8 +9,11 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.databinding.ActivitySettingsTranslationBinding;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -19,36 +21,33 @@ import org.mian.gitnex.helpers.Toasty;
|
|||||||
|
|
||||||
public class SettingsTranslationActivity extends BaseActivity {
|
public class SettingsTranslationActivity extends BaseActivity {
|
||||||
|
|
||||||
private Context appCtx;
|
|
||||||
private View.OnClickListener onClickListener;
|
private View.OnClickListener onClickListener;
|
||||||
|
|
||||||
private static String[] langList = {"English", "Arabic", "Chinese", "Finnish", "French", "German", "Italian", "Latvian", "Persian", "Polish", "Portuguese/Brazilian", "Russian", "Serbian", "Spanish", "Turkish",
|
|
||||||
"Ukrainian"};
|
|
||||||
private static int langSelectedChoice = 0;
|
private static int langSelectedChoice = 0;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
|
|
||||||
return R.layout.activity_settings_translation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
appCtx = getApplicationContext();
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(appCtx);
|
LinkedHashMap<String, String> langs = new LinkedHashMap<>();
|
||||||
|
langs.put("", getString(R.string.settingsLanguageSystem));
|
||||||
|
for(String langCode : getResources().getStringArray(R.array.languages)) {
|
||||||
|
langs.put(langCode, getLanguageDisplayName(langCode));
|
||||||
|
}
|
||||||
|
|
||||||
ImageView closeActivity = findViewById(R.id.close);
|
ActivitySettingsTranslationBinding activitySettingsTranslationBinding = ActivitySettingsTranslationBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activitySettingsTranslationBinding.getRoot());
|
||||||
|
|
||||||
|
ImageView closeActivity = activitySettingsTranslationBinding.close;
|
||||||
|
|
||||||
initCloseListener();
|
initCloseListener();
|
||||||
closeActivity.setOnClickListener(onClickListener);
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
final TextView tvLanguageSelected = findViewById(R.id.tvLanguageSelected); // setter for en, fr
|
final TextView tvLanguageSelected = activitySettingsTranslationBinding.tvLanguageSelected; // setter for en, fr
|
||||||
TextView helpTranslate = findViewById(R.id.helpTranslate);
|
TextView helpTranslate = activitySettingsTranslationBinding.helpTranslate;
|
||||||
|
|
||||||
LinearLayout langFrame = findViewById(R.id.langFrame);
|
LinearLayout langFrame = activitySettingsTranslationBinding.langFrame;
|
||||||
|
|
||||||
helpTranslate.setOnClickListener(v12 -> {
|
helpTranslate.setOnClickListener(v12 -> {
|
||||||
|
|
||||||
@@ -60,13 +59,9 @@ public class SettingsTranslationActivity extends BaseActivity {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if(!tinyDb.getString("localeStr").isEmpty()) {
|
tvLanguageSelected.setText(tinyDB.getString("localeStr"));
|
||||||
tvLanguageSelected.setText(tinyDb.getString("localeStr"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(langSelectedChoice == 0) {
|
langSelectedChoice = tinyDB.getInt("langId");
|
||||||
langSelectedChoice = tinyDb.getInt("langId");
|
|
||||||
}
|
|
||||||
|
|
||||||
// language dialog
|
// language dialog
|
||||||
langFrame.setOnClickListener(view -> {
|
langFrame.setOnClickListener(view -> {
|
||||||
@@ -74,90 +69,38 @@ public class SettingsTranslationActivity extends BaseActivity {
|
|||||||
AlertDialog.Builder lBuilder = new AlertDialog.Builder(SettingsTranslationActivity.this);
|
AlertDialog.Builder lBuilder = new AlertDialog.Builder(SettingsTranslationActivity.this);
|
||||||
|
|
||||||
lBuilder.setTitle(R.string.settingsLanguageSelectorDialogTitle);
|
lBuilder.setTitle(R.string.settingsLanguageSelectorDialogTitle);
|
||||||
if(langSelectedChoice != -1) {
|
lBuilder.setCancelable(langSelectedChoice != -1);
|
||||||
lBuilder.setCancelable(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lBuilder.setCancelable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
lBuilder.setSingleChoiceItems(langList, langSelectedChoice, (dialogInterface, i) -> {
|
lBuilder.setSingleChoiceItems(langs.values().toArray(new String[0]), langSelectedChoice, (dialogInterface, i) -> {
|
||||||
|
|
||||||
langSelectedChoice = i;
|
String selectedLanguage = langs.keySet().toArray(new String[0])[i];
|
||||||
tvLanguageSelected.setText(langList[i]);
|
tinyDB.putString("localeStr", langs.get(selectedLanguage));
|
||||||
tinyDb.putString("localeStr", langList[i]);
|
tinyDB.putInt("langId", i);
|
||||||
tinyDb.putInt("langId", i);
|
tinyDB.putString("locale", selectedLanguage);
|
||||||
|
|
||||||
switch(langList[i]) {
|
tinyDB.putBoolean("refreshParent", true);
|
||||||
case "Arabic":
|
|
||||||
tinyDb.putString("locale", "ar");
|
|
||||||
break;
|
|
||||||
case "Chinese":
|
|
||||||
tinyDb.putString("locale", "zh");
|
|
||||||
break;
|
|
||||||
case "Finnish":
|
|
||||||
tinyDb.putString("locale", "fi");
|
|
||||||
break;
|
|
||||||
case "French":
|
|
||||||
tinyDb.putString("locale", "fr");
|
|
||||||
break;
|
|
||||||
case "German":
|
|
||||||
tinyDb.putString("locale", "de");
|
|
||||||
break;
|
|
||||||
case "Italian":
|
|
||||||
tinyDb.putString("locale", "it");
|
|
||||||
break;
|
|
||||||
case "Latvian":
|
|
||||||
tinyDb.putString("locale", "lv");
|
|
||||||
break;
|
|
||||||
case "Persian":
|
|
||||||
tinyDb.putString("locale", "fa");
|
|
||||||
break;
|
|
||||||
case "Polish":
|
|
||||||
tinyDb.putString("locale", "pl");
|
|
||||||
break;
|
|
||||||
case "Portuguese/Brazilian":
|
|
||||||
tinyDb.putString("locale", "pt");
|
|
||||||
break;
|
|
||||||
case "Russian":
|
|
||||||
tinyDb.putString("locale", "ru");
|
|
||||||
break;
|
|
||||||
case "Serbian":
|
|
||||||
tinyDb.putString("locale", "sr");
|
|
||||||
break;
|
|
||||||
case "Spanish":
|
|
||||||
tinyDb.putString("locale", "es");
|
|
||||||
break;
|
|
||||||
case "Turkish":
|
|
||||||
tinyDb.putString("locale", "tr");
|
|
||||||
break;
|
|
||||||
case "Ukrainian":
|
|
||||||
tinyDb.putString("locale", "uk");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
tinyDb.putString("locale", "en");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
tinyDb.putBoolean("refreshParent", true);
|
|
||||||
this.recreate();
|
|
||||||
this.overridePendingTransition(0, 0);
|
this.overridePendingTransition(0, 0);
|
||||||
dialogInterface.dismiss();
|
dialogInterface.dismiss();
|
||||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||||
|
this.recreate();
|
||||||
});
|
});
|
||||||
|
|
||||||
lBuilder.setNeutralButton(getString(R.string.cancelButton), null);
|
lBuilder.setNeutralButton(getString(R.string.cancelButton), null);
|
||||||
|
|
||||||
AlertDialog lDialog = lBuilder.create();
|
AlertDialog lDialog = lBuilder.create();
|
||||||
lDialog.show();
|
lDialog.show();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initCloseListener() {
|
private void initCloseListener() {
|
||||||
|
|
||||||
onClickListener = view -> finish();
|
onClickListener = view -> finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getLanguageDisplayName(String langCode) {
|
||||||
|
Locale english = new Locale("en");
|
||||||
|
Locale translated = new Locale(langCode);
|
||||||
|
return String.format("%s (%s)", translated.getDisplayName(translated), translated.getDisplayName(english));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,171 @@
|
|||||||
|
package org.mian.gitnex.adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.gitnex.tea4j.models.CronTasks;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
|
import org.mian.gitnex.helpers.TimeHelper;
|
||||||
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AdminCronTasksAdapter extends RecyclerView.Adapter<AdminCronTasksAdapter.CronTasksViewHolder> {
|
||||||
|
|
||||||
|
private final List<CronTasks> tasksList;
|
||||||
|
private static TinyDB tinyDb;
|
||||||
|
|
||||||
|
static class CronTasksViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
private CronTasks cronTasks;
|
||||||
|
|
||||||
|
private final TextView taskName;
|
||||||
|
|
||||||
|
private CronTasksViewHolder(View itemView) {
|
||||||
|
|
||||||
|
super(itemView);
|
||||||
|
Context ctx = itemView.getContext();
|
||||||
|
|
||||||
|
final Locale locale = ctx.getResources().getConfiguration().locale;
|
||||||
|
final String timeFormat = tinyDb.getString("dateFormat");
|
||||||
|
|
||||||
|
ImageView runTask = itemView.findViewById(R.id.runTask);
|
||||||
|
taskName = itemView.findViewById(R.id.taskName);
|
||||||
|
LinearLayout cronTasksInfo = itemView.findViewById(R.id.cronTasksInfo);
|
||||||
|
LinearLayout cronTasksRun = itemView.findViewById(R.id.cronTasksRun);
|
||||||
|
|
||||||
|
cronTasksInfo.setOnClickListener(taskInfo -> {
|
||||||
|
|
||||||
|
String nextRun = "";
|
||||||
|
String lastRun = "";
|
||||||
|
|
||||||
|
if(cronTasks.getNext() != null) {
|
||||||
|
nextRun = TimeHelper.formatTime(cronTasks.getNext(), locale, timeFormat, ctx);
|
||||||
|
}
|
||||||
|
if(cronTasks.getPrev() != null) {
|
||||||
|
lastRun = TimeHelper.formatTime(cronTasks.getPrev(), locale, timeFormat, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
View view = LayoutInflater.from(ctx).inflate(R.layout.layout_cron_task_info, null);
|
||||||
|
|
||||||
|
TextView taskScheduleContent = view.findViewById(R.id.taskScheduleContent);
|
||||||
|
TextView nextRunContent = view.findViewById(R.id.nextRunContent);
|
||||||
|
TextView lastRunContent = view.findViewById(R.id.lastRunContent);
|
||||||
|
TextView execTimeContent = view.findViewById(R.id.execTimeContent);
|
||||||
|
|
||||||
|
taskScheduleContent.setText(cronTasks.getSchedule());
|
||||||
|
nextRunContent.setText(nextRun);
|
||||||
|
lastRunContent.setText(lastRun);
|
||||||
|
execTimeContent.setText(String.valueOf(cronTasks.getExec_times()));
|
||||||
|
|
||||||
|
AlertDialog.Builder alertDialog = new AlertDialog.Builder(ctx);
|
||||||
|
|
||||||
|
alertDialog.setTitle(StringUtils.capitalize(cronTasks.getName().replace("_", " ")));
|
||||||
|
alertDialog.setView(view);
|
||||||
|
alertDialog.setPositiveButton(ctx.getString(R.string.close), null);
|
||||||
|
alertDialog.create().show();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
cronTasksRun.setOnClickListener(taskInfo -> {
|
||||||
|
|
||||||
|
runCronTask(ctx, cronTasks.getName());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AdminCronTasksAdapter(Context ctx, List<CronTasks> tasksListMain) {
|
||||||
|
|
||||||
|
tinyDb = TinyDB.getInstance(ctx);
|
||||||
|
this.tasksList = tasksListMain;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public AdminCronTasksAdapter.CronTasksViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_admin_cron_tasks, parent, false);
|
||||||
|
return new AdminCronTasksAdapter.CronTasksViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull AdminCronTasksAdapter.CronTasksViewHolder holder, int position) {
|
||||||
|
|
||||||
|
CronTasks currentItem = tasksList.get(position);
|
||||||
|
|
||||||
|
holder.cronTasks = currentItem;
|
||||||
|
holder.taskName.setText(StringUtils.capitalize(currentItem.getName().replace("_", " ")));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void runCronTask(final Context ctx, final String taskName) {
|
||||||
|
|
||||||
|
final String loginUid = tinyDb.getString("loginUid");
|
||||||
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||||
|
|
||||||
|
Call<JsonElement> call = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
|
.adminRunCronTask(instanceToken, taskName);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||||
|
|
||||||
|
switch(response.code()) {
|
||||||
|
|
||||||
|
case 204:
|
||||||
|
Toasty.success(ctx, ctx.getString(R.string.adminCronTaskSuccessMsg, taskName));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 401:
|
||||||
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, ctx.getString(R.string.alertDialogTokenRevokedTitle),
|
||||||
|
ctx.getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
|
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
|
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 403:
|
||||||
|
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 404:
|
||||||
|
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
|
Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return tasksList.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package org.mian.gitnex.adapters;
|
package org.mian.gitnex.adapters;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.text.Html;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -9,12 +11,15 @@ import android.widget.Filterable;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.amulyakhare.textdrawable.TextDrawable;
|
import com.amulyakhare.textdrawable.TextDrawable;
|
||||||
|
import org.gitnex.tea4j.models.UserInfo;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.activities.ProfileActivity;
|
||||||
import org.mian.gitnex.clients.PicassoService;
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
import org.mian.gitnex.models.UserInfo;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -24,19 +29,22 @@ import java.util.List;
|
|||||||
|
|
||||||
public class AdminGetUsersAdapter extends RecyclerView.Adapter<AdminGetUsersAdapter.UsersViewHolder> implements Filterable {
|
public class AdminGetUsersAdapter extends RecyclerView.Adapter<AdminGetUsersAdapter.UsersViewHolder> implements Filterable {
|
||||||
|
|
||||||
private List<UserInfo> usersList;
|
private final List<UserInfo> usersList;
|
||||||
private Context mCtx;
|
private final Context context;
|
||||||
private List<UserInfo> usersListFull;
|
private final List<UserInfo> usersListFull;
|
||||||
|
|
||||||
static class UsersViewHolder extends RecyclerView.ViewHolder {
|
class UsersViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private ImageView userAvatar;
|
private String userLoginId;
|
||||||
private TextView userFullName;
|
|
||||||
private TextView userEmail;
|
private final ImageView userAvatar;
|
||||||
private ImageView userRole;
|
private final TextView userFullName;
|
||||||
private TextView userName;
|
private final TextView userEmail;
|
||||||
|
private final ImageView userRole;
|
||||||
|
private final TextView userName;
|
||||||
|
|
||||||
private UsersViewHolder(View itemView) {
|
private UsersViewHolder(View itemView) {
|
||||||
|
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
|
||||||
userAvatar = itemView.findViewById(R.id.userAvatar);
|
userAvatar = itemView.findViewById(R.id.userAvatar);
|
||||||
@@ -45,11 +53,22 @@ public class AdminGetUsersAdapter extends RecyclerView.Adapter<AdminGetUsersAdap
|
|||||||
userEmail = itemView.findViewById(R.id.userEmail);
|
userEmail = itemView.findViewById(R.id.userEmail);
|
||||||
userRole = itemView.findViewById(R.id.userRole);
|
userRole = itemView.findViewById(R.id.userRole);
|
||||||
|
|
||||||
|
itemView.setOnClickListener(loginId -> {
|
||||||
|
Intent intent = new Intent(context, ProfileActivity.class);
|
||||||
|
intent.putExtra("username", userLoginId);
|
||||||
|
context.startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
|
userAvatar.setOnLongClickListener(loginId -> {
|
||||||
|
AppUtil.copyToClipboard(context, userLoginId, context.getString(R.string.copyLoginIdToClipBoard, userLoginId));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AdminGetUsersAdapter(Context mCtx, List<UserInfo> usersListMain) {
|
public AdminGetUsersAdapter(Context ctx, List<UserInfo> usersListMain) {
|
||||||
this.mCtx = mCtx;
|
|
||||||
|
this.context = ctx;
|
||||||
this.usersList = usersListMain;
|
this.usersList = usersListMain;
|
||||||
usersListFull = new ArrayList<>(usersList);
|
usersListFull = new ArrayList<>(usersList);
|
||||||
}
|
}
|
||||||
@@ -57,6 +76,7 @@ public class AdminGetUsersAdapter extends RecyclerView.Adapter<AdminGetUsersAdap
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public AdminGetUsersAdapter.UsersViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public AdminGetUsersAdapter.UsersViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_admin_users, parent, false);
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_admin_users, parent, false);
|
||||||
return new AdminGetUsersAdapter.UsersViewHolder(v);
|
return new AdminGetUsersAdapter.UsersViewHolder(v);
|
||||||
}
|
}
|
||||||
@@ -65,40 +85,49 @@ public class AdminGetUsersAdapter extends RecyclerView.Adapter<AdminGetUsersAdap
|
|||||||
public void onBindViewHolder(@NonNull AdminGetUsersAdapter.UsersViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull AdminGetUsersAdapter.UsersViewHolder holder, int position) {
|
||||||
|
|
||||||
UserInfo currentItem = usersList.get(position);
|
UserInfo currentItem = usersList.get(position);
|
||||||
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||||
|
|
||||||
|
holder.userLoginId = currentItem.getLogin();
|
||||||
|
|
||||||
if(!currentItem.getFullname().equals("")) {
|
if(!currentItem.getFullname().equals("")) {
|
||||||
holder.userFullName.setText(currentItem.getFullname());
|
|
||||||
holder.userName.setText(mCtx.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
holder.userFullName.setText(Html.fromHtml(currentItem.getFullname()));
|
||||||
|
holder.userName.setText(context.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
holder.userFullName.setText(mCtx.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
|
||||||
|
holder.userFullName.setText(context.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||||
holder.userName.setVisibility(View.GONE);
|
holder.userName.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!currentItem.getEmail().equals("")) {
|
if(!currentItem.getEmail().equals("")) {
|
||||||
|
|
||||||
holder.userEmail.setText(currentItem.getEmail());
|
holder.userEmail.setText(currentItem.getEmail());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
holder.userEmail.setVisibility(View.GONE);
|
holder.userEmail.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentItem.getIs_admin()) {
|
if(currentItem.getIs_admin()) {
|
||||||
|
|
||||||
holder.userRole.setVisibility(View.VISIBLE);
|
holder.userRole.setVisibility(View.VISIBLE);
|
||||||
TextDrawable drawable = TextDrawable.builder()
|
TextDrawable drawable = TextDrawable.builder()
|
||||||
.beginConfig()
|
.beginConfig()
|
||||||
.textColor(mCtx.getResources().getColor(R.color.colorWhite))
|
.textColor(ResourcesCompat.getColor(context.getResources(), R.color.colorWhite, null))
|
||||||
.fontSize(44)
|
.fontSize(44)
|
||||||
.width(180)
|
.width(180)
|
||||||
.height(60)
|
.height(60)
|
||||||
.endConfig()
|
.endConfig()
|
||||||
.buildRoundRect(mCtx.getResources().getString(R.string.userRoleAdmin).toLowerCase(), mCtx.getResources().getColor(R.color.releasePre), 8);
|
.buildRoundRect(context.getResources().getString(R.string.userRoleAdmin).toLowerCase(), ResourcesCompat.getColor(context.getResources(), R.color.releasePre, null), 8);
|
||||||
holder.userRole.setImageDrawable(drawable);
|
holder.userRole.setImageDrawable(drawable);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
holder.userRole.setVisibility(View.GONE);
|
holder.userRole.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.userAvatar);
|
PicassoService.getInstance(context).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop().into(holder.userAvatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -111,14 +140,15 @@ public class AdminGetUsersAdapter extends RecyclerView.Adapter<AdminGetUsersAdap
|
|||||||
return usersFilter;
|
return usersFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Filter usersFilter = new Filter() {
|
private final Filter usersFilter = new Filter() {
|
||||||
@Override
|
@Override
|
||||||
protected FilterResults performFiltering(CharSequence constraint) {
|
protected FilterResults performFiltering(CharSequence constraint) {
|
||||||
List<UserInfo> filteredList = new ArrayList<>();
|
List<UserInfo> filteredList = new ArrayList<>();
|
||||||
|
|
||||||
if (constraint == null || constraint.length() == 0) {
|
if (constraint == null || constraint.length() == 0) {
|
||||||
filteredList.addAll(usersListFull);
|
filteredList.addAll(usersListFull);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||||
|
|
||||||
for (UserInfo item : usersListFull) {
|
for (UserInfo item : usersListFull) {
|
||||||
@@ -136,6 +166,7 @@ public class AdminGetUsersAdapter extends RecyclerView.Adapter<AdminGetUsersAdap
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||||
|
|
||||||
usersList.clear();
|
usersList.clear();
|
||||||
usersList.addAll((List) results.values);
|
usersList.addAll((List) results.values);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
|||||||
@@ -0,0 +1,139 @@
|
|||||||
|
package org.mian.gitnex.adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import org.gitnex.tea4j.models.Collaborators;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AssigneesListAdapter extends RecyclerView.Adapter<AssigneesListAdapter.AssigneesViewHolder> {
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
|
private final List<Collaborators> assigneesList;
|
||||||
|
private List<String> assigneesStrings = new ArrayList<>();
|
||||||
|
private List<String> currentAssignees;
|
||||||
|
|
||||||
|
private final AssigneesListAdapterListener assigneesListener;
|
||||||
|
|
||||||
|
public interface AssigneesListAdapterListener {
|
||||||
|
|
||||||
|
void assigneesInterface(List<String> data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AssigneesListAdapter(Context ctx, List<Collaborators> dataMain, AssigneesListAdapterListener assigneesListener, List<String> currentAssignees) {
|
||||||
|
|
||||||
|
this.context = ctx;
|
||||||
|
this.assigneesList = dataMain;
|
||||||
|
this.assigneesListener = assigneesListener;
|
||||||
|
this.currentAssignees = currentAssignees;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class AssigneesViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
private final CheckBox assigneesSelection;
|
||||||
|
private final TextView assigneesName;
|
||||||
|
private final ImageView assigneesAvatar;
|
||||||
|
|
||||||
|
private AssigneesViewHolder(View itemView) {
|
||||||
|
|
||||||
|
super(itemView);
|
||||||
|
this.setIsRecyclable(false);
|
||||||
|
|
||||||
|
assigneesSelection = itemView.findViewById(R.id.assigneesSelection);
|
||||||
|
assigneesName = itemView.findViewById(R.id.assigneesName);
|
||||||
|
assigneesAvatar = itemView.findViewById(R.id.assigneesAvatar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public AssigneesListAdapter.AssigneesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_assignees_list, parent, false);
|
||||||
|
return new AssigneesListAdapter.AssigneesViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull AssigneesListAdapter.AssigneesViewHolder holder, int position) {
|
||||||
|
|
||||||
|
Collaborators currentItem = assigneesList.get(position);
|
||||||
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||||
|
|
||||||
|
if(currentItem.getFull_name().equals("")) {
|
||||||
|
|
||||||
|
holder.assigneesName.setText(currentItem.getLogin());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
holder.assigneesName.setText(Html.fromHtml(currentItem.getFull_name()));
|
||||||
|
}
|
||||||
|
PicassoService
|
||||||
|
.getInstance(context).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(180, 180).centerCrop().into(holder.assigneesAvatar);
|
||||||
|
|
||||||
|
for(int i = 0; i < assigneesList.size(); i++) {
|
||||||
|
|
||||||
|
if(assigneesStrings.contains(currentItem.getLogin())) {
|
||||||
|
|
||||||
|
holder.assigneesSelection.setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentAssignees = new ArrayList<>(new LinkedHashSet<>(currentAssignees));
|
||||||
|
|
||||||
|
for(int i = 0; i < currentAssignees.size(); i++) {
|
||||||
|
|
||||||
|
if(currentAssignees.contains(currentItem.getLogin())) {
|
||||||
|
|
||||||
|
holder.assigneesSelection.setChecked(true);
|
||||||
|
assigneesStrings.add(currentAssignees.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assigneesListener.assigneesInterface(assigneesStrings);
|
||||||
|
|
||||||
|
holder.assigneesSelection.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
|
||||||
|
if(isChecked) {
|
||||||
|
|
||||||
|
assigneesStrings.add(currentItem.getLogin());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
assigneesStrings.remove(currentItem.getLogin());
|
||||||
|
}
|
||||||
|
|
||||||
|
assigneesListener.assigneesInterface(assigneesStrings);
|
||||||
|
});
|
||||||
|
|
||||||
|
assigneesStrings = new ArrayList<>(new LinkedHashSet<>(assigneesStrings));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
|
||||||
|
return assigneesList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateList(List<String> list) {
|
||||||
|
|
||||||
|
currentAssignees = list;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
package org.mian.gitnex.adapters;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import org.mian.gitnex.R;
|
|
||||||
import org.mian.gitnex.activities.CommitsActivity;
|
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
|
||||||
import org.mian.gitnex.models.Branches;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Author M M Arif
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class BranchesAdapter extends RecyclerView.Adapter<BranchesAdapter.BranchesViewHolder> {
|
|
||||||
|
|
||||||
private List<Branches> branchesList;
|
|
||||||
private Context mCtx;
|
|
||||||
|
|
||||||
static class BranchesViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
private TextView branchNameTv;
|
|
||||||
private TextView branchCommitAuthor;
|
|
||||||
|
|
||||||
private BranchesViewHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
|
|
||||||
branchNameTv = itemView.findViewById(R.id.branchName);
|
|
||||||
branchCommitAuthor = itemView.findViewById(R.id.branchCommitAuthor);
|
|
||||||
Button branchCommitHash = itemView.findViewById(R.id.branchCommitHash);
|
|
||||||
|
|
||||||
branchCommitHash.setOnClickListener(new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
|
|
||||||
Intent intent = new Intent(v.getContext(), CommitsActivity.class);
|
|
||||||
intent.putExtra("branchName", String.valueOf(branchNameTv.getText()));
|
|
||||||
Objects.requireNonNull(v.getContext()).startActivity(intent);
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BranchesAdapter(Context mCtx, List<Branches> branchesMain) {
|
|
||||||
this.mCtx = mCtx;
|
|
||||||
this.branchesList = branchesMain;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public BranchesAdapter.BranchesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_branches, parent, false);
|
|
||||||
return new BranchesAdapter.BranchesViewHolder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(@NonNull BranchesAdapter.BranchesViewHolder holder, int position) {
|
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(mCtx);
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
|
|
||||||
Branches currentItem = branchesList.get(position);
|
|
||||||
holder.branchNameTv.setText(currentItem.getName());
|
|
||||||
|
|
||||||
if(currentItem.getCommit().getAuthor().getName() != null || !currentItem.getCommit().getAuthor().getName().equals("")) {
|
|
||||||
holder.branchCommitAuthor.setText(mCtx.getResources().getString(R.string.commitAuthor, currentItem.getCommit().getAuthor().getName()));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
holder.branchCommitAuthor.setText(mCtx.getResources().getString(R.string.commitAuthor, currentItem.getCommit().getAuthor().getUsername()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return branchesList.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -2,15 +2,19 @@ package org.mian.gitnex.adapters;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.text.Html;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import org.gitnex.tea4j.models.Collaborators;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.activities.ProfileActivity;
|
||||||
import org.mian.gitnex.clients.PicassoService;
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
import org.mian.gitnex.models.Collaborators;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -20,22 +24,37 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CollaboratorsAdapter extends BaseAdapter {
|
public class CollaboratorsAdapter extends BaseAdapter {
|
||||||
|
|
||||||
private List<Collaborators> collaboratorsList;
|
private final List<Collaborators> collaboratorsList;
|
||||||
private Context mCtx;
|
private final Context context;
|
||||||
|
|
||||||
private class ViewHolder {
|
private class ViewHolder {
|
||||||
|
|
||||||
private ImageView collaboratorAvatar;
|
private String userLoginId;
|
||||||
private TextView collaboratorName;
|
|
||||||
|
private final ImageView collaboratorAvatar;
|
||||||
|
private final TextView collaboratorName;
|
||||||
|
|
||||||
ViewHolder(View v) {
|
ViewHolder(View v) {
|
||||||
|
|
||||||
collaboratorAvatar = v.findViewById(R.id.collaboratorAvatar);
|
collaboratorAvatar = v.findViewById(R.id.collaboratorAvatar);
|
||||||
collaboratorName = v.findViewById(R.id.collaboratorName);
|
collaboratorName = v.findViewById(R.id.collaboratorName);
|
||||||
|
|
||||||
|
collaboratorAvatar.setOnClickListener(loginId -> {
|
||||||
|
Intent intent = new Intent(context, ProfileActivity.class);
|
||||||
|
intent.putExtra("username", userLoginId);
|
||||||
|
context.startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
|
collaboratorAvatar.setOnLongClickListener(loginId -> {
|
||||||
|
AppUtil.copyToClipboard(context, userLoginId, context.getString(R.string.copyLoginIdToClipBoard, userLoginId));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CollaboratorsAdapter(Context mCtx, List<Collaborators> collaboratorsListMain) {
|
public CollaboratorsAdapter(Context ctx, List<Collaborators> collaboratorsListMain) {
|
||||||
this.mCtx = mCtx;
|
|
||||||
|
this.context = ctx;
|
||||||
this.collaboratorsList = collaboratorsListMain;
|
this.collaboratorsList = collaboratorsListMain;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,28 +80,35 @@ public class CollaboratorsAdapter extends BaseAdapter {
|
|||||||
ViewHolder viewHolder = null;
|
ViewHolder viewHolder = null;
|
||||||
|
|
||||||
if (finalView == null) {
|
if (finalView == null) {
|
||||||
finalView = LayoutInflater.from(mCtx).inflate(R.layout.list_collaborators, null);
|
|
||||||
|
finalView = LayoutInflater.from(context).inflate(R.layout.list_collaborators, null);
|
||||||
viewHolder = new ViewHolder(finalView);
|
viewHolder = new ViewHolder(finalView);
|
||||||
finalView.setTag(viewHolder);
|
finalView.setTag(viewHolder);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
viewHolder = (ViewHolder) finalView.getTag();
|
viewHolder = (ViewHolder) finalView.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
initData(viewHolder, position);
|
initData(viewHolder, position);
|
||||||
return finalView;
|
return finalView;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initData(ViewHolder viewHolder, int position) {
|
private void initData(ViewHolder viewHolder, int position) {
|
||||||
|
|
||||||
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||||
|
|
||||||
Collaborators currentItem = collaboratorsList.get(position);
|
Collaborators currentItem = collaboratorsList.get(position);
|
||||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(180, 180).centerCrop().into(viewHolder.collaboratorAvatar);
|
PicassoService.getInstance(context).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(180, 180).centerCrop().into(viewHolder.collaboratorAvatar);
|
||||||
|
|
||||||
|
viewHolder.userLoginId = currentItem.getLogin();
|
||||||
|
|
||||||
if(!currentItem.getFull_name().equals("")) {
|
if(!currentItem.getFull_name().equals("")) {
|
||||||
viewHolder.collaboratorName.setText(currentItem.getFull_name());
|
|
||||||
|
viewHolder.collaboratorName.setText(Html.fromHtml(currentItem.getFull_name()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
viewHolder.collaboratorName.setText(currentItem.getLogin());
|
viewHolder.collaboratorName.setText(currentItem.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,12 @@ import android.widget.Button;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import com.vdurmont.emoji.EmojiParser;
|
||||||
|
import org.gitnex.tea4j.models.Commits;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.helpers.ClickListener;
|
import org.mian.gitnex.helpers.ClickListener;
|
||||||
import org.mian.gitnex.helpers.TimeHelper;
|
import org.mian.gitnex.helpers.TimeHelper;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.models.Commits;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ import java.util.Locale;
|
|||||||
|
|
||||||
public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
private Context ctx;
|
private final Context context;
|
||||||
private final int TYPE_LOAD = 0;
|
private final int TYPE_LOAD = 0;
|
||||||
private List<Commits> commitsList;
|
private List<Commits> commitsList;
|
||||||
private CommitsAdapter.OnLoadMoreListener loadMoreListener;
|
private CommitsAdapter.OnLoadMoreListener loadMoreListener;
|
||||||
@@ -34,16 +35,15 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||||||
|
|
||||||
public CommitsAdapter(Context ctx, List<Commits> commitsListMain) {
|
public CommitsAdapter(Context ctx, List<Commits> commitsListMain) {
|
||||||
|
|
||||||
this.ctx = ctx;
|
this.context = ctx;
|
||||||
this.commitsList = commitsListMain;
|
this.commitsList = commitsListMain;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
LayoutInflater inflater = LayoutInflater.from(ctx);
|
LayoutInflater inflater = LayoutInflater.from(context);
|
||||||
|
|
||||||
if(viewType == TYPE_LOAD) {
|
if(viewType == TYPE_LOAD) {
|
||||||
return new CommitsHolder(inflater.inflate(R.layout.list_commits, parent, false));
|
return new CommitsHolder(inflater.inflate(R.layout.list_commits, parent, false));
|
||||||
@@ -51,25 +51,19 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||||||
else {
|
else {
|
||||||
return new LoadHolder(inflater.inflate(R.layout.row_load, parent, false));
|
return new LoadHolder(inflater.inflate(R.layout.row_load, parent, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||||
|
|
||||||
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
|
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
|
||||||
|
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
loadMoreListener.onLoadMore();
|
loadMoreListener.onLoadMore();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getItemViewType(position) == TYPE_LOAD) {
|
if(getItemViewType(position) == TYPE_LOAD) {
|
||||||
|
|
||||||
((CommitsHolder) holder).bindData(commitsList.get(position));
|
((CommitsHolder) holder).bindData(commitsList.get(position));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -81,14 +75,12 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||||||
else {
|
else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
|
|
||||||
return commitsList.size();
|
return commitsList.size();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CommitsHolder extends RecyclerView.ViewHolder {
|
class CommitsHolder extends RecyclerView.ViewHolder {
|
||||||
@@ -106,27 +98,23 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||||||
commitCommitter = itemView.findViewById(R.id.commitCommitterVw);
|
commitCommitter = itemView.findViewById(R.id.commitCommitterVw);
|
||||||
commitDate = itemView.findViewById(R.id.commitDateVw);
|
commitDate = itemView.findViewById(R.id.commitDateVw);
|
||||||
commitHtmlUrl = itemView.findViewById(R.id.commitHtmlUrlVw);
|
commitHtmlUrl = itemView.findViewById(R.id.commitHtmlUrlVw);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
void bindData(Commits commitsModel) {
|
void bindData(Commits commitsModel) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(ctx);
|
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
final String locale = tinyDb.getString("locale");
|
Locale locale = context.getResources().getConfiguration().locale;
|
||||||
final String timeFormat = tinyDb.getString("dateFormat");
|
final String timeFormat = tinyDb.getString("dateFormat");
|
||||||
|
|
||||||
commitTitle.setText(commitsModel.getCommit().getMessage());
|
commitTitle.setText(EmojiParser.parseToUnicode(commitsModel.getCommit().getMessage()));
|
||||||
commitCommitter.setText(ctx.getString(R.string.commitCommittedBy, commitsModel.getCommit().getCommitter().getName()));
|
commitCommitter.setText(context.getString(R.string.commitCommittedBy, commitsModel.getCommit().getCommitter().getName()));
|
||||||
|
commitDate.setText(TimeHelper.formatTime(commitsModel.getCommit().getCommitter().getDate(), locale, timeFormat, context));
|
||||||
commitDate.setText(TimeHelper.formatTime(commitsModel.getCommit().getCommitter().getDate(), new Locale(locale), timeFormat, ctx));
|
|
||||||
|
|
||||||
if(timeFormat.equals("pretty")) {
|
if(timeFormat.equals("pretty")) {
|
||||||
commitDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(commitsModel.getCommit().getCommitter().getDate()), ctx));
|
commitDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(commitsModel.getCommit().getCommitter().getDate()), context));
|
||||||
}
|
}
|
||||||
|
commitHtmlUrl.setOnClickListener(v -> context.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(commitsModel.getHtml_url()))));
|
||||||
commitHtmlUrl.setOnClickListener(v -> ctx.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(commitsModel.getHtml_url()))));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -134,41 +122,29 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||||||
static class LoadHolder extends RecyclerView.ViewHolder {
|
static class LoadHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
LoadHolder(View itemView) {
|
LoadHolder(View itemView) {
|
||||||
|
|
||||||
super(itemView);
|
super(itemView);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
||||||
|
|
||||||
isMoreDataAvailable = moreDataAvailable;
|
isMoreDataAvailable = moreDataAvailable;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyDataChanged() {
|
public void notifyDataChanged() {
|
||||||
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnLoadMoreListener {
|
public interface OnLoadMoreListener {
|
||||||
|
|
||||||
void onLoadMore();
|
void onLoadMore();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoadMoreListener(CommitsAdapter.OnLoadMoreListener loadMoreListener) {
|
public void setLoadMoreListener(CommitsAdapter.OnLoadMoreListener loadMoreListener) {
|
||||||
|
|
||||||
this.loadMoreListener = loadMoreListener;
|
this.loadMoreListener = loadMoreListener;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateList(List<Commits> list) {
|
public void updateList(List<Commits> list) {
|
||||||
|
|
||||||
commitsList = list;
|
commitsList = list;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
package org.mian.gitnex.adapters;
|
|
||||||
|
|
||||||
import android.text.SpannableStringBuilder;
|
|
||||||
import android.text.method.LinkMovementMethod;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import org.mian.gitnex.R;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Author M M Arif
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class CreditsAdapter extends RecyclerView.Adapter<CreditsAdapter.CreditsViewHolder> {
|
|
||||||
|
|
||||||
private List<CharSequence> creditsList;
|
|
||||||
|
|
||||||
static class CreditsViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
private TextView creditText;
|
|
||||||
|
|
||||||
private CreditsViewHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
|
|
||||||
creditText = itemView.findViewById(R.id.creditText);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CreditsAdapter(List<CharSequence> creditsListMain) {
|
|
||||||
this.creditsList = creditsListMain;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public CreditsAdapter.CreditsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.credits, parent, false);
|
|
||||||
return new CreditsAdapter.CreditsViewHolder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(@NonNull CreditsAdapter.CreditsViewHolder holder, int position) {
|
|
||||||
|
|
||||||
SpannableStringBuilder strBuilder = new SpannableStringBuilder(creditsList.get(position));
|
|
||||||
holder.creditText.setText((strBuilder));
|
|
||||||
holder.creditText.setMovementMethod(LinkMovementMethod.getInstance());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return creditsList.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@ package org.mian.gitnex.adapters;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.text.Html;
|
import android.os.Bundle;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -11,11 +11,17 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
|
import androidx.core.text.HtmlCompat;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.activities.ReplyToIssueActivity;
|
import org.mian.gitnex.activities.IssueDetailActivity;
|
||||||
|
import org.mian.gitnex.database.api.BaseApi;
|
||||||
import org.mian.gitnex.database.api.DraftsApi;
|
import org.mian.gitnex.database.api.DraftsApi;
|
||||||
import org.mian.gitnex.database.models.DraftWithRepository;
|
import org.mian.gitnex.database.models.DraftWithRepository;
|
||||||
|
import org.mian.gitnex.fragments.BottomSheetReplyFragment;
|
||||||
|
import org.mian.gitnex.helpers.Markdown;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -27,20 +33,16 @@ import java.util.List;
|
|||||||
public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsViewHolder> {
|
public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsViewHolder> {
|
||||||
|
|
||||||
private List<DraftWithRepository> draftsList;
|
private List<DraftWithRepository> draftsList;
|
||||||
private Context mCtx;
|
private final FragmentManager fragmentManager;
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
class DraftsViewHolder extends RecyclerView.ViewHolder {
|
class DraftsViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private TextView draftText;
|
private DraftWithRepository draftWithRepository;
|
||||||
private TextView repoInfo;
|
|
||||||
private TextView repoId;
|
private final TextView draftText;
|
||||||
private TextView draftId;
|
private final TextView repoInfo;
|
||||||
private TextView issueNumber;
|
private final ImageView editCommentStatus;
|
||||||
private TextView issueType;
|
|
||||||
private TextView repoOwner;
|
|
||||||
private TextView repoName;
|
|
||||||
private TextView commentId;
|
|
||||||
private ImageView editCommentStatus;
|
|
||||||
|
|
||||||
private DraftsViewHolder(View itemView) {
|
private DraftsViewHolder(View itemView) {
|
||||||
|
|
||||||
@@ -48,54 +50,53 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
|
|||||||
|
|
||||||
draftText = itemView.findViewById(R.id.draftText);
|
draftText = itemView.findViewById(R.id.draftText);
|
||||||
repoInfo = itemView.findViewById(R.id.repoInfo);
|
repoInfo = itemView.findViewById(R.id.repoInfo);
|
||||||
repoId = itemView.findViewById(R.id.repoId);
|
|
||||||
draftId = itemView.findViewById(R.id.draftId);
|
|
||||||
issueNumber = itemView.findViewById(R.id.issueNumber);
|
|
||||||
issueType = itemView.findViewById(R.id.issueType);
|
|
||||||
repoOwner = itemView.findViewById(R.id.repoOwner);
|
|
||||||
repoName = itemView.findViewById(R.id.repoName);
|
|
||||||
commentId = itemView.findViewById(R.id.commentId);
|
|
||||||
ImageView deleteDraft = itemView.findViewById(R.id.deleteDraft);
|
ImageView deleteDraft = itemView.findViewById(R.id.deleteDraft);
|
||||||
editCommentStatus = itemView.findViewById(R.id.editCommentStatus);
|
editCommentStatus = itemView.findViewById(R.id.editCommentStatus);
|
||||||
|
|
||||||
deleteDraft.setOnClickListener(itemDelete -> {
|
deleteDraft.setOnClickListener(itemDelete -> {
|
||||||
|
|
||||||
int getDraftId = Integer.parseInt(draftId.getText().toString());
|
int getDraftId = draftWithRepository.getDraftId();
|
||||||
deleteDraft(getAdapterPosition());
|
deleteDraft(getAdapterPosition());
|
||||||
DraftsApi draftsApi = new DraftsApi(mCtx);
|
|
||||||
|
DraftsApi draftsApi = BaseApi.getInstance(context, DraftsApi.class);
|
||||||
|
assert draftsApi != null;
|
||||||
draftsApi.deleteSingleDraft(getDraftId);
|
draftsApi.deleteSingleDraft(getDraftId);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
itemView.setOnClickListener(itemEdit -> {
|
itemView.setOnClickListener(itemEdit -> {
|
||||||
|
|
||||||
Intent intent = new Intent(mCtx, ReplyToIssueActivity.class);
|
Bundle bundle = new Bundle();
|
||||||
intent.putExtra("commentBody", draftText.getText().toString());
|
|
||||||
intent.putExtra("issueNumber", issueNumber.getText().toString());
|
|
||||||
intent.putExtra("repositoryId", repoId.getText().toString());
|
|
||||||
intent.putExtra("draftTitle", repoInfo.getText().toString());
|
|
||||||
intent.putExtra("commentId", commentId.getText().toString());
|
|
||||||
intent.putExtra("draftId", draftId.getText().toString());
|
|
||||||
|
|
||||||
if(!commentId.getText().toString().equalsIgnoreCase("")) {
|
bundle.putString("commentBody", draftWithRepository.getDraftText());
|
||||||
intent.putExtra("commentAction", "edit");
|
bundle.putString("issueNumber", String.valueOf(draftWithRepository.getIssueId()));
|
||||||
|
bundle.putString("repositoryId", String.valueOf(draftWithRepository.getRepositoryId()));
|
||||||
|
bundle.putString("draftTitle", repoInfo.getText().toString());
|
||||||
|
bundle.putString("commentId", draftWithRepository.getCommentId());
|
||||||
|
bundle.putString("draftId", String.valueOf(draftWithRepository.getDraftId()));
|
||||||
|
|
||||||
|
if(!draftWithRepository.getCommentId().isEmpty()) {
|
||||||
|
bundle.putString("commentAction", "edit");
|
||||||
}
|
}
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(mCtx);
|
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
tinyDb.putString("issueNumber", issueNumber.getText().toString());
|
tinyDb.putString("issueNumber", String.valueOf(draftWithRepository.getIssueId()));
|
||||||
tinyDb.putLong("repositoryId", Long.parseLong(repoId.getText().toString()));
|
tinyDb.putLong("repositoryId", draftWithRepository.getRepositoryId());
|
||||||
//tinyDb.putString("issueType", issueType.getText().toString());
|
tinyDb.putString("issueType", draftWithRepository.getIssueType());
|
||||||
|
tinyDb.putString("repoFullName", draftWithRepository.getRepositoryOwner() + "/" + draftWithRepository.getRepositoryName());
|
||||||
mCtx.startActivity(intent);
|
|
||||||
|
|
||||||
|
BottomSheetReplyFragment bottomSheetReplyFragment = BottomSheetReplyFragment.newInstance(bundle);
|
||||||
|
bottomSheetReplyFragment.setOnInteractedListener(() -> context.startActivity(new Intent(context, IssueDetailActivity.class)));
|
||||||
|
bottomSheetReplyFragment.show(fragmentManager, "replyBottomSheet");
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DraftsAdapter(Context mCtx, List<DraftWithRepository> draftsListMain) {
|
public DraftsAdapter(Context ctx, FragmentManager fragmentManager, List<DraftWithRepository> draftsListMain) {
|
||||||
this.mCtx = mCtx;
|
this.context = ctx;
|
||||||
|
this.fragmentManager = fragmentManager;
|
||||||
this.draftsList = draftsListMain;
|
this.draftsList = draftsListMain;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,8 +105,7 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
|
|||||||
draftsList.remove(position);
|
draftsList.remove(position);
|
||||||
notifyItemRemoved(position);
|
notifyItemRemoved(position);
|
||||||
notifyItemRangeChanged(position, draftsList.size());
|
notifyItemRangeChanged(position, draftsList.size());
|
||||||
Toasty.success(mCtx, mCtx.getResources().getString(R.string.draftsSingleDeleteSuccess));
|
Toasty.success(context, context.getResources().getString(R.string.draftsSingleDeleteSuccess));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -121,18 +121,14 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
|
|||||||
|
|
||||||
DraftWithRepository currentItem = draftsList.get(position);
|
DraftWithRepository currentItem = draftsList.get(position);
|
||||||
|
|
||||||
holder.repoId.setText(String.valueOf(currentItem.getRepositoryId()));
|
String issueNumber = "<font color='" + ResourcesCompat.getColor(context.getResources(), R.color.lightGray, null) + "'>" + context.getResources().getString(R.string.hash) + currentItem.getIssueId() + "</font>";
|
||||||
holder.draftId.setText(String.valueOf(currentItem.getDraftId()));
|
Spanned headTitle = HtmlCompat
|
||||||
holder.issueNumber.setText(String.valueOf(currentItem.getIssueId()));
|
.fromHtml(issueNumber + " " + currentItem.getRepositoryOwner() + " / " + currentItem.getRepositoryName(), HtmlCompat.FROM_HTML_MODE_LEGACY);
|
||||||
holder.issueType.setText(currentItem.getDraftType());
|
|
||||||
holder.repoOwner.setText(currentItem.getRepositoryOwner());
|
|
||||||
holder.repoName.setText(currentItem.getRepositoryName());
|
|
||||||
holder.draftText.setText(currentItem.getDraftText());
|
|
||||||
holder.commentId.setText(currentItem.getCommentId());
|
|
||||||
|
|
||||||
String issueNumber = "<font color='" + mCtx.getResources().getColor(R.color.lightGray) + "'>" + mCtx.getResources().getString(R.string.hash) + currentItem.getIssueId() + "</font>";
|
|
||||||
Spanned headTitle = Html.fromHtml(issueNumber + " " + currentItem.getRepositoryOwner() + " / " + currentItem.getRepositoryName());
|
|
||||||
holder.repoInfo.setText(headTitle);
|
holder.repoInfo.setText(headTitle);
|
||||||
|
holder.draftWithRepository = currentItem;
|
||||||
|
|
||||||
|
Markdown.render(context, currentItem.getDraftText(), holder.draftText);
|
||||||
|
|
||||||
if(!currentItem.getCommentId().equalsIgnoreCase("new")) {
|
if(!currentItem.getCommentId().equalsIgnoreCase("new")) {
|
||||||
holder.editCommentStatus.setVisibility(View.VISIBLE);
|
holder.editCommentStatus.setVisibility(View.VISIBLE);
|
||||||
@@ -140,7 +136,6 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
|
|||||||
else {
|
else {
|
||||||
holder.editCommentStatus.setVisibility(View.GONE);
|
holder.editCommentStatus.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -153,6 +148,4 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
|
|||||||
draftsList = list;
|
draftsList = list;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,175 @@
|
|||||||
|
package org.mian.gitnex.adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
|
import androidx.core.text.HtmlCompat;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import org.gitnex.tea4j.models.Issues;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.activities.IssueDetailActivity;
|
||||||
|
import org.mian.gitnex.activities.ProfileActivity;
|
||||||
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
|
import org.mian.gitnex.database.api.BaseApi;
|
||||||
|
import org.mian.gitnex.database.api.RepositoriesApi;
|
||||||
|
import org.mian.gitnex.database.models.Repository;
|
||||||
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
|
import org.mian.gitnex.helpers.ClickListener;
|
||||||
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
|
import org.mian.gitnex.helpers.TimeHelper;
|
||||||
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
|
import org.ocpsoft.prettytime.PrettyTime;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ExploreIssuesAdapter extends RecyclerView.Adapter<ExploreIssuesAdapter.SearchViewHolder> {
|
||||||
|
|
||||||
|
private final List<Issues> searchedList;
|
||||||
|
private final Context context;
|
||||||
|
private final TinyDB tinyDb;
|
||||||
|
|
||||||
|
public ExploreIssuesAdapter(List<Issues> dataList, Context ctx) {
|
||||||
|
|
||||||
|
this.context = ctx;
|
||||||
|
this.searchedList = dataList;
|
||||||
|
this.tinyDb = TinyDB.getInstance(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
class SearchViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
private Issues issue;
|
||||||
|
private final ImageView issueAssigneeAvatar;
|
||||||
|
private final TextView issueTitle;
|
||||||
|
private final TextView issueCreatedTime;
|
||||||
|
private final TextView issueCommentsCount;
|
||||||
|
|
||||||
|
private SearchViewHolder(View itemView) {
|
||||||
|
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
issueAssigneeAvatar = itemView.findViewById(R.id.assigneeAvatar);
|
||||||
|
issueTitle = itemView.findViewById(R.id.issueTitle);
|
||||||
|
issueCommentsCount = itemView.findViewById(R.id.issueCommentsCount);
|
||||||
|
issueCreatedTime = itemView.findViewById(R.id.issueCreatedTime);
|
||||||
|
|
||||||
|
itemView.setOnClickListener(v -> {
|
||||||
|
Intent intent = new Intent(context, IssueDetailActivity.class);
|
||||||
|
intent.putExtra("issueNumber", issue.getNumber());
|
||||||
|
|
||||||
|
tinyDb.putString("issueNumber", String.valueOf(issue.getNumber()));
|
||||||
|
tinyDb.putString("issueType", "Issue");
|
||||||
|
|
||||||
|
tinyDb.putString("repoFullName", issue.getRepository().getFull_name());
|
||||||
|
|
||||||
|
String[] parts = issue.getRepository().getFull_name().split("/");
|
||||||
|
final String repoOwner = parts[0];
|
||||||
|
final String repoName = parts[1];
|
||||||
|
|
||||||
|
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
||||||
|
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
|
||||||
|
|
||||||
|
assert repositoryData != null;
|
||||||
|
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
|
||||||
|
if(count == 0) {
|
||||||
|
|
||||||
|
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
tinyDb.putLong("repositoryId", id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
tinyDb.putLong("repositoryId", data.getRepositoryId());
|
||||||
|
}
|
||||||
|
|
||||||
|
context.startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
|
issueAssigneeAvatar.setOnClickListener(v -> {
|
||||||
|
Intent intent = new Intent(context, ProfileActivity.class);
|
||||||
|
intent.putExtra("username", issue.getUser().getLogin());
|
||||||
|
context.startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
|
issueAssigneeAvatar.setOnLongClickListener(loginId -> {
|
||||||
|
AppUtil.copyToClipboard(context, issue.getUser().getLogin(), context.getString(R.string.copyLoginIdToClipBoard, issue.getUser().getLogin()));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public ExploreIssuesAdapter.SearchViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_issues, parent, false);
|
||||||
|
return new ExploreIssuesAdapter.SearchViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull final ExploreIssuesAdapter.SearchViewHolder holder, int position) {
|
||||||
|
|
||||||
|
Issues currentItem = searchedList.get(position);
|
||||||
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||||
|
|
||||||
|
Locale locale = context.getResources().getConfiguration().locale;
|
||||||
|
String timeFormat = tinyDb.getString("dateFormat");
|
||||||
|
|
||||||
|
PicassoService.getInstance(context).get()
|
||||||
|
.load(currentItem.getUser().getAvatar_url())
|
||||||
|
.placeholder(R.drawable.loader_animated)
|
||||||
|
.transform(new RoundedTransformation(imgRadius, 0))
|
||||||
|
.resize(120, 120)
|
||||||
|
.centerCrop()
|
||||||
|
.into(holder.issueAssigneeAvatar);
|
||||||
|
|
||||||
|
String issueNumber_ = "<font color='" + ResourcesCompat.getColor(context.getResources(), R.color.lightGray, null) + "'>" + currentItem.getRepository().getFull_name() + context.getResources().getString(R.string.hash) + currentItem.getNumber() + "</font>";
|
||||||
|
|
||||||
|
holder.issue = currentItem;
|
||||||
|
holder.issueTitle.setText(HtmlCompat.fromHtml(issueNumber_ + " " + currentItem.getTitle(), HtmlCompat.FROM_HTML_MODE_LEGACY));
|
||||||
|
holder.issueCommentsCount.setText(String.valueOf(currentItem.getComments()));
|
||||||
|
|
||||||
|
switch(timeFormat) {
|
||||||
|
case "pretty": {
|
||||||
|
PrettyTime prettyTime = new PrettyTime(locale);
|
||||||
|
String createdTime = prettyTime.format(currentItem.getCreated_at());
|
||||||
|
holder.issueCreatedTime.setText(createdTime);
|
||||||
|
holder.issueCreatedTime.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(currentItem.getCreated_at()), context));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "normal": {
|
||||||
|
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
|
||||||
|
String createdTime = formatter.format(currentItem.getCreated_at());
|
||||||
|
holder.issueCreatedTime.setText(createdTime);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "normal1": {
|
||||||
|
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
|
||||||
|
String createdTime = formatter.format(currentItem.getCreated_at());
|
||||||
|
holder.issueCreatedTime.setText(createdTime);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return searchedList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifyDataChanged() {
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
package org.mian.gitnex.adapters;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import org.gitnex.tea4j.models.Organization;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.activities.OrganizationDetailActivity;
|
||||||
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ExplorePublicOrganizationsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
|
private final int TYPE_LOAD = 0;
|
||||||
|
private List<Organization> organizationsList;
|
||||||
|
private OnLoadMoreListener loadMoreListener;
|
||||||
|
private boolean isLoading = false, isMoreDataAvailable = true;
|
||||||
|
|
||||||
|
public ExplorePublicOrganizationsAdapter(Context ctx, List<Organization> organizationsListMain) {
|
||||||
|
this.context = ctx;
|
||||||
|
this.organizationsList = organizationsListMain;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
LayoutInflater inflater = LayoutInflater.from(context);
|
||||||
|
if(viewType == TYPE_LOAD) {
|
||||||
|
return new ExplorePublicOrganizationsAdapter.OrganizationsHolder(inflater.inflate(R.layout.list_organizations, parent, false));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return new ExplorePublicOrganizationsAdapter.LoadHolder(inflater.inflate(R.layout.row_load, parent, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||||
|
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
|
||||||
|
isLoading = true;
|
||||||
|
loadMoreListener.onLoadMore();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getItemViewType(position) == TYPE_LOAD) {
|
||||||
|
((ExplorePublicOrganizationsAdapter.OrganizationsHolder) holder).bindData(organizationsList.get(position));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
if(organizationsList.get(position).getFull_name() != null) {
|
||||||
|
return TYPE_LOAD;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return organizationsList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
class OrganizationsHolder extends RecyclerView.ViewHolder {
|
||||||
|
private Organization organization;
|
||||||
|
private final ImageView image;
|
||||||
|
private final TextView orgName;
|
||||||
|
private final TextView orgDescription;
|
||||||
|
|
||||||
|
OrganizationsHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
image = itemView.findViewById(R.id.imageAvatar);
|
||||||
|
orgName = itemView.findViewById(R.id.orgName);
|
||||||
|
orgDescription = itemView.findViewById(R.id.orgDescription);
|
||||||
|
|
||||||
|
itemView.setOnClickListener(v -> {
|
||||||
|
Context context = v.getContext();
|
||||||
|
Intent intent = new Intent(context, OrganizationDetailActivity.class);
|
||||||
|
intent.putExtra("orgName", organization.getUsername());
|
||||||
|
|
||||||
|
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
|
tinyDb.putString("orgName", organization.getUsername());
|
||||||
|
tinyDb.putString("organizationId", String.valueOf(organization.getId()));
|
||||||
|
tinyDb.putBoolean("organizationAction", true);
|
||||||
|
context.startActivity(intent);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
void bindData(Organization organization) {
|
||||||
|
this.organization = organization;
|
||||||
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||||
|
orgName.setText(organization.getUsername());
|
||||||
|
PicassoService.getInstance(context).get()
|
||||||
|
.load(organization.getAvatar_url())
|
||||||
|
.placeholder(R.drawable.loader_animated)
|
||||||
|
.transform(new RoundedTransformation(imgRadius, 0))
|
||||||
|
.resize(120, 120)
|
||||||
|
.centerCrop()
|
||||||
|
.into(image);
|
||||||
|
if (!organization.getDescription().equals("")) {
|
||||||
|
orgDescription.setText(organization.getDescription());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class LoadHolder extends RecyclerView.ViewHolder {
|
||||||
|
LoadHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
||||||
|
isMoreDataAvailable = moreDataAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifyDataChanged() {
|
||||||
|
notifyDataSetChanged();
|
||||||
|
isLoading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnLoadMoreListener {
|
||||||
|
void onLoadMore();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoadMoreListener(OnLoadMoreListener loadMoreListener) {
|
||||||
|
this.loadMoreListener = loadMoreListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateList(List<Organization> list) {
|
||||||
|
organizationsList = list;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
package org.mian.gitnex.adapters;
|
package org.mian.gitnex.adapters;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.ClipData;
|
|
||||||
import android.content.ClipboardManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
@@ -11,30 +8,31 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.amulyakhare.textdrawable.TextDrawable;
|
import com.amulyakhare.textdrawable.TextDrawable;
|
||||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
import org.gitnex.tea4j.models.UserRepositories;
|
||||||
|
import org.gitnex.tea4j.models.WatchInfo;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.activities.OpenRepoInBrowserActivity;
|
|
||||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||||
import org.mian.gitnex.activities.RepoForksActivity;
|
|
||||||
import org.mian.gitnex.activities.RepoStargazersActivity;
|
|
||||||
import org.mian.gitnex.activities.RepoWatchersActivity;
|
|
||||||
import org.mian.gitnex.clients.PicassoService;
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.database.api.BaseApi;
|
||||||
import org.mian.gitnex.database.api.RepositoriesApi;
|
import org.mian.gitnex.database.api.RepositoriesApi;
|
||||||
import org.mian.gitnex.database.models.Repository;
|
import org.mian.gitnex.database.models.Repository;
|
||||||
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
|
import org.mian.gitnex.helpers.ClickListener;
|
||||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
|
import org.mian.gitnex.helpers.TimeHelper;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.models.UserRepositories;
|
import org.ocpsoft.prettytime.PrettyTime;
|
||||||
import org.mian.gitnex.models.WatchInfo;
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Locale;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
|
|
||||||
@@ -44,205 +42,115 @@ import retrofit2.Callback;
|
|||||||
|
|
||||||
public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepositoriesAdapter.ReposSearchViewHolder> {
|
public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepositoriesAdapter.ReposSearchViewHolder> {
|
||||||
|
|
||||||
private List<UserRepositories> searchedReposList;
|
private final List<UserRepositories> reposList;
|
||||||
private Context mCtx;
|
private final Context context;
|
||||||
|
|
||||||
public ExploreRepositoriesAdapter(List<UserRepositories> dataList, Context mCtx) {
|
public ExploreRepositoriesAdapter(List<UserRepositories> dataList, Context ctx) {
|
||||||
|
|
||||||
this.mCtx = mCtx;
|
this.context = ctx;
|
||||||
this.searchedReposList = dataList;
|
this.reposList = dataList;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ReposSearchViewHolder extends RecyclerView.ViewHolder {
|
static class ReposSearchViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private ImageView image;
|
private UserRepositories userRepositories;
|
||||||
private TextView repoName;
|
|
||||||
private TextView repoDescription;
|
private final ImageView image;
|
||||||
private TextView fullName;
|
private final TextView repoName;
|
||||||
|
private final TextView orgName;
|
||||||
|
private final TextView repoDescription;
|
||||||
private CheckBox isRepoAdmin;
|
private CheckBox isRepoAdmin;
|
||||||
private ImageView repoPrivatePublic;
|
private final TextView repoStars;
|
||||||
private TextView repoStars;
|
private final TextView repoLastUpdated;
|
||||||
private TextView repoForks;
|
|
||||||
private TextView repoOpenIssuesCount;
|
|
||||||
private TextView repoType;
|
|
||||||
private LinearLayout archiveRepo;
|
|
||||||
private TextView repoBranch;
|
|
||||||
private TextView htmlUrl;
|
|
||||||
|
|
||||||
private ReposSearchViewHolder(View itemView) {
|
private ReposSearchViewHolder(View itemView) {
|
||||||
|
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
|
||||||
repoName = itemView.findViewById(R.id.repoName);
|
repoName = itemView.findViewById(R.id.repoName);
|
||||||
|
orgName = itemView.findViewById(R.id.orgName);
|
||||||
repoDescription = itemView.findViewById(R.id.repoDescription);
|
repoDescription = itemView.findViewById(R.id.repoDescription);
|
||||||
image = itemView.findViewById(R.id.imageAvatar);
|
|
||||||
fullName = itemView.findViewById(R.id.repoFullName);
|
|
||||||
isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin);
|
isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin);
|
||||||
repoPrivatePublic = itemView.findViewById(R.id.imageRepoType);
|
image = itemView.findViewById(R.id.imageAvatar);
|
||||||
repoStars = itemView.findViewById(R.id.repoStars);
|
repoStars = itemView.findViewById(R.id.repoStars);
|
||||||
repoForks = itemView.findViewById(R.id.repoForks);
|
repoLastUpdated = itemView.findViewById(R.id.repoLastUpdated);
|
||||||
repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount);
|
|
||||||
ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
|
|
||||||
repoType = itemView.findViewById(R.id.repoType);
|
|
||||||
archiveRepo = itemView.findViewById(R.id.archiveRepoFrame);
|
|
||||||
repoBranch = itemView.findViewById(R.id.repoBranch);
|
|
||||||
htmlUrl = itemView.findViewById(R.id.htmlUrl);
|
|
||||||
|
|
||||||
itemView.setOnClickListener(v -> {
|
itemView.setOnClickListener(v -> {
|
||||||
|
|
||||||
Context context = v.getContext();
|
Context context = v.getContext();
|
||||||
TextView repoFullName = v.findViewById(R.id.repoFullName);
|
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
|
|
||||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||||
intent.putExtra("repoFullName", repoFullName.getText().toString());
|
intent.putExtra("repoFullName", userRepositories.getFullName());
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(context);
|
tinyDb.putString("repoFullName", userRepositories.getFullName());
|
||||||
tinyDb.putString("repoFullName", repoFullName.getText().toString());
|
|
||||||
tinyDb.putBoolean("resumeIssues", true);
|
tinyDb.putBoolean("resumeIssues", true);
|
||||||
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
|
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
|
||||||
tinyDb.putString("repoBranch", repoBranch.getText().toString());
|
tinyDb.putString("repoBranch", userRepositories.getDefault_branch());
|
||||||
|
|
||||||
String[] parts = fullName.getText().toString().split("/");
|
if(userRepositories.getPrivateFlag()) {
|
||||||
|
tinyDb.putString("repoType", context.getResources().getString(R.string.strPrivate));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tinyDb.putString("repoType", context.getResources().getString(R.string.strPublic));
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] parts = userRepositories.getFullName().split("/");
|
||||||
final String repoOwner = parts[0];
|
final String repoOwner = parts[0];
|
||||||
final String repoName = parts[1];
|
final String repoName = parts[1];
|
||||||
|
|
||||||
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
||||||
RepositoriesApi repositoryData = new RepositoriesApi(context);
|
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
|
||||||
|
|
||||||
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
|
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
|
||||||
|
assert repositoryData != null;
|
||||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
|
|
||||||
if(count == 0) {
|
if(count == 0) {
|
||||||
|
|
||||||
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
tinyDb.putLong("repositoryId", id);
|
tinyDb.putLong("repositoryId", id);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
||||||
tinyDb.putLong("repositoryId", data.getRepositoryId());
|
tinyDb.putLong("repositoryId", data.getRepositoryId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//store if user is watching this repo
|
//store if user is watching this repo
|
||||||
{
|
{
|
||||||
|
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
||||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
||||||
|
|
||||||
WatchInfo watch = new WatchInfo();
|
WatchInfo watch = new WatchInfo();
|
||||||
|
|
||||||
Call<WatchInfo> call;
|
Call<WatchInfo> call;
|
||||||
|
call = RetrofitClient.getApiInterface(context).checkRepoWatchStatus(token, repoOwner, repoName);
|
||||||
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
|
||||||
|
|
||||||
call.enqueue(new Callback<WatchInfo>() {
|
call.enqueue(new Callback<WatchInfo>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull retrofit2.Response<WatchInfo> response) {
|
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull retrofit2.Response<WatchInfo> response) {
|
||||||
|
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
|
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
tinyDb.putBoolean("repoWatch", response.body().getSubscribed());
|
tinyDb.putBoolean("repoWatch", response.body().getSubscribed());
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
tinyDb.putBoolean("repoWatch", false);
|
|
||||||
|
|
||||||
if(response.code() != 404) {
|
|
||||||
|
|
||||||
Toasty.error(context, context.getString(R.string.genericApiStatusError));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
tinyDb.putBoolean("repoWatch", false);
|
||||||
|
if(response.code() != 404) {
|
||||||
|
Toasty.error(context, context.getString(R.string.genericApiStatusError));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
tinyDb.putBoolean("repoWatch", false);
|
tinyDb.putBoolean("repoWatch", false);
|
||||||
Toasty.error(context, context.getString(R.string.genericApiStatusError));
|
Toasty.error(context, context.getString(R.string.genericApiStatusError));
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
reposDropdownMenu.setOnClickListener(v -> {
|
|
||||||
|
|
||||||
final Context context = v.getContext();
|
|
||||||
|
|
||||||
@SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null);
|
|
||||||
|
|
||||||
TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser);
|
|
||||||
TextView repoStargazers = view.findViewById(R.id.repoStargazers);
|
|
||||||
TextView repoWatchers = view.findViewById(R.id.repoWatchers);
|
|
||||||
TextView repoForksList = view.findViewById(R.id.repoForksList);
|
|
||||||
TextView repoCopyUrl = view.findViewById(R.id.repoCopyUrl);
|
|
||||||
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
|
|
||||||
|
|
||||||
bottomSheetHeader.setText(String.format("%s / %s", fullName.getText().toString().split("/")[0], fullName.getText().toString().split("/")[1]));
|
|
||||||
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
|
||||||
dialog.setContentView(view);
|
|
||||||
dialog.show();
|
|
||||||
|
|
||||||
repoCopyUrl.setOnClickListener(openInBrowser -> {
|
|
||||||
|
|
||||||
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
ClipData clip = ClipData.newPlainText("repoUrl", htmlUrl.getText().toString());
|
|
||||||
assert clipboard != null;
|
|
||||||
clipboard.setPrimaryClip(clip);
|
|
||||||
|
|
||||||
Toasty.info(context, context.getString(R.string.copyIssueUrlToastMsg));
|
|
||||||
dialog.dismiss();
|
|
||||||
});
|
|
||||||
|
|
||||||
repoOpenInBrowser.setOnClickListener(openInBrowser -> {
|
|
||||||
|
|
||||||
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
|
|
||||||
intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText());
|
|
||||||
context.startActivity(intentOpenInBrowser);
|
|
||||||
dialog.dismiss();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
repoStargazers.setOnClickListener(stargazers -> {
|
|
||||||
|
|
||||||
Intent intent = new Intent(context, RepoStargazersActivity.class);
|
|
||||||
intent.putExtra("repoFullNameForStars", fullName.getText());
|
|
||||||
context.startActivity(intent);
|
|
||||||
dialog.dismiss();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
repoWatchers.setOnClickListener(watchers -> {
|
|
||||||
|
|
||||||
Intent intentW = new Intent(context, RepoWatchersActivity.class);
|
|
||||||
intentW.putExtra("repoFullNameForWatchers", fullName.getText());
|
|
||||||
context.startActivity(intentW);
|
|
||||||
dialog.dismiss();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
repoForksList.setOnClickListener(forks -> {
|
|
||||||
|
|
||||||
Intent intentW = new Intent(context, RepoForksActivity.class);
|
|
||||||
intentW.putExtra("repoFullNameForForks", fullName.getText());
|
|
||||||
context.startActivity(intentW);
|
|
||||||
dialog.dismiss();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -258,20 +166,26 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull final ExploreRepositoriesAdapter.ReposSearchViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull final ExploreRepositoriesAdapter.ReposSearchViewHolder holder, int position) {
|
||||||
|
|
||||||
UserRepositories currentItem = searchedReposList.get(position);
|
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
holder.repoDescription.setVisibility(View.GONE);
|
UserRepositories currentItem = reposList.get(position);
|
||||||
holder.repoBranch.setText(currentItem.getDefault_branch());
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||||
holder.htmlUrl.setText(currentItem.getHtml_url());
|
|
||||||
|
Locale locale = context.getResources().getConfiguration().locale;
|
||||||
|
String timeFormat = tinyDb.getString("dateFormat");
|
||||||
|
holder.userRepositories = currentItem;
|
||||||
|
holder.orgName.setText(currentItem.getFullName().split("/")[0]);
|
||||||
|
holder.repoName.setText(currentItem.getFullName().split("/")[1]);
|
||||||
|
holder.repoStars.setText(currentItem.getStars_count());
|
||||||
|
|
||||||
ColorGenerator generator = ColorGenerator.MATERIAL;
|
ColorGenerator generator = ColorGenerator.MATERIAL;
|
||||||
int color = generator.getColor(currentItem.getName());
|
int color = generator.getColor(currentItem.getName());
|
||||||
String firstCharacter = String.valueOf(currentItem.getName().charAt(0));
|
String firstCharacter = String.valueOf(currentItem.getFullName().charAt(0));
|
||||||
|
|
||||||
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).fontSize(18).toUpperCase().width(28).height(28).endConfig().buildRoundRect(firstCharacter, color, 3);
|
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).fontSize(18).toUpperCase().width(28).height(28).endConfig().buildRoundRect(firstCharacter, color, 3);
|
||||||
|
|
||||||
if(currentItem.getAvatar_url() != null) {
|
if(currentItem.getAvatar_url() != null) {
|
||||||
if(!currentItem.getAvatar_url().equals("")) {
|
if(!currentItem.getAvatar_url().equals("")) {
|
||||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.image);
|
PicassoService.getInstance(context).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop().into(holder.image);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
holder.image.setImageDrawable(drawable);
|
holder.image.setImageDrawable(drawable);
|
||||||
@@ -281,41 +195,56 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
|
|||||||
holder.image.setImageDrawable(drawable);
|
holder.image.setImageDrawable(drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.repoName.setText(currentItem.getName());
|
if(currentItem.getUpdated_at() != null) {
|
||||||
|
|
||||||
|
switch(timeFormat) {
|
||||||
|
case "pretty": {
|
||||||
|
PrettyTime prettyTime = new PrettyTime(locale);
|
||||||
|
String createdTime = prettyTime.format(currentItem.getUpdated_at());
|
||||||
|
holder.repoLastUpdated.setText(context.getString(R.string.lastUpdatedAt, createdTime));
|
||||||
|
holder.repoLastUpdated.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(currentItem.getUpdated_at()), context));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "normal": {
|
||||||
|
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
|
||||||
|
String createdTime = formatter.format(currentItem.getUpdated_at());
|
||||||
|
holder.repoLastUpdated.setText(context.getString(R.string.lastUpdatedAt, createdTime));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "normal1": {
|
||||||
|
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
|
||||||
|
String createdTime = formatter.format(currentItem.getUpdated_at());
|
||||||
|
holder.repoLastUpdated.setText(context.getString(R.string.lastUpdatedAt, createdTime));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
holder.repoLastUpdated.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
if(!currentItem.getDescription().equals("")) {
|
if(!currentItem.getDescription().equals("")) {
|
||||||
holder.repoDescription.setVisibility(View.VISIBLE);
|
|
||||||
holder.repoDescription.setText(currentItem.getDescription());
|
holder.repoDescription.setText(currentItem.getDescription());
|
||||||
}
|
}
|
||||||
holder.fullName.setText(currentItem.getFullname());
|
|
||||||
if(currentItem.getPrivateFlag()) {
|
|
||||||
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock);
|
|
||||||
holder.repoType.setText(R.string.strPrivate);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
holder.repoPrivatePublic.setVisibility(View.GONE);
|
holder.repoDescription.setText(context.getString(R.string.noDataDescription));
|
||||||
holder.repoType.setText(R.string.strPublic);
|
|
||||||
}
|
}
|
||||||
holder.repoStars.setText(currentItem.getStars_count());
|
|
||||||
holder.repoForks.setText(currentItem.getForks_count());
|
|
||||||
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
|
|
||||||
if(holder.isRepoAdmin == null) {
|
if(holder.isRepoAdmin == null) {
|
||||||
holder.isRepoAdmin = new CheckBox(mCtx);
|
holder.isRepoAdmin = new CheckBox(context);
|
||||||
}
|
}
|
||||||
holder.isRepoAdmin.setChecked(currentItem.getPermissions().isAdmin());
|
holder.isRepoAdmin.setChecked(currentItem.getPermissions().isAdmin());
|
||||||
|
|
||||||
if(currentItem.isArchived()) {
|
|
||||||
holder.archiveRepo.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
holder.archiveRepo.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
|
|
||||||
return searchedReposList.size();
|
return reposList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifyDataChanged() {
|
||||||
|
|
||||||
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.Filter;
|
import android.widget.Filter;
|
||||||
import android.widget.Filterable;
|
import android.widget.Filterable;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.content.res.AppCompatResources;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.gitnex.tea4j.models.Files;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
|
||||||
import org.mian.gitnex.models.Files;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -23,51 +24,39 @@ import java.util.List;
|
|||||||
|
|
||||||
public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHolder> implements Filterable {
|
public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHolder> implements Filterable {
|
||||||
|
|
||||||
private List<Files> filesList;
|
private final List<Files> originalFiles = new ArrayList<>();
|
||||||
private Context mCtx;
|
private final List<Files> alteredFiles = new ArrayList<>();
|
||||||
private List<Files> filesListFull;
|
|
||||||
|
|
||||||
private FilesAdapterListener filesListener;
|
private final Context context;
|
||||||
|
|
||||||
|
private final FilesAdapterListener filesListener;
|
||||||
|
|
||||||
public interface FilesAdapterListener {
|
public interface FilesAdapterListener {
|
||||||
void onClickDir(String str);
|
|
||||||
void onClickFile(String str);
|
void onClickFile(Files file);
|
||||||
}
|
}
|
||||||
|
|
||||||
class FilesViewHolder extends RecyclerView.ViewHolder {
|
class FilesViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private ImageView fileTypeImage;
|
private Files file;
|
||||||
private TextView fileName;
|
|
||||||
private TextView fileType;
|
private final ImageView fileTypeIs;
|
||||||
private TextView fileInfo;
|
private final TextView fileName;
|
||||||
|
private final TextView fileInfo;
|
||||||
|
|
||||||
private FilesViewHolder(View itemView) {
|
private FilesViewHolder(View itemView) {
|
||||||
|
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
|
||||||
|
LinearLayout fileFrame = itemView.findViewById(R.id.fileFrame);
|
||||||
fileName = itemView.findViewById(R.id.fileName);
|
fileName = itemView.findViewById(R.id.fileName);
|
||||||
fileTypeImage = itemView.findViewById(R.id.fileImage);
|
fileTypeIs = itemView.findViewById(R.id.fileTypeIs);
|
||||||
fileType = itemView.findViewById(R.id.fileType);
|
|
||||||
fileInfo = itemView.findViewById(R.id.fileInfo);
|
fileInfo = itemView.findViewById(R.id.fileInfo);
|
||||||
|
|
||||||
|
fileFrame.setOnClickListener(v -> filesListener.onClickFile(file));
|
||||||
|
|
||||||
//ImageView filesDropdownMenu = itemView.findViewById(R.id.filesDropdownMenu);
|
//ImageView filesDropdownMenu = itemView.findViewById(R.id.filesDropdownMenu);
|
||||||
|
|
||||||
fileName.setOnClickListener(v -> {
|
|
||||||
|
|
||||||
Context context = v.getContext();
|
|
||||||
|
|
||||||
if(fileType.getText().toString().equals("file")) {
|
|
||||||
filesListener.onClickFile(fileName.getText().toString());
|
|
||||||
}
|
|
||||||
else if(fileType.getText().toString().equals("dir")) {
|
|
||||||
filesListener.onClickDir(fileName.getText().toString());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Toasty.warning(context, context.getString(R.string.filesGenericError));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/*filesDropdownMenu.setOnClickListener(new View.OnClickListener() {
|
/*filesDropdownMenu.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@@ -134,13 +123,24 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FilesAdapter(Context mCtx, List<Files> filesListMain, FilesAdapterListener filesListener) {
|
public FilesAdapter(Context ctx, FilesAdapterListener filesListener) {
|
||||||
this.mCtx = mCtx;
|
|
||||||
this.filesList = filesListMain;
|
this.context = ctx;
|
||||||
filesListFull = new ArrayList<>(filesList);
|
|
||||||
this.filesListener = filesListener;
|
this.filesListener = filesListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Files> getOriginalFiles() {
|
||||||
|
return originalFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifyOriginalDataSetChanged() {
|
||||||
|
|
||||||
|
alteredFiles.clear();
|
||||||
|
alteredFiles.addAll(originalFiles);
|
||||||
|
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public FilesAdapter.FilesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public FilesAdapter.FilesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
@@ -151,29 +151,43 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull FilesAdapter.FilesViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull FilesAdapter.FilesViewHolder holder, int position) {
|
||||||
|
|
||||||
Files currentItem = filesList.get(position);
|
Files currentItem = alteredFiles.get(position);
|
||||||
|
|
||||||
holder.fileType.setText(currentItem.getType());
|
holder.file = currentItem;
|
||||||
holder.fileName.setText(currentItem.getName());
|
holder.fileName.setText(currentItem.getName());
|
||||||
|
|
||||||
if(currentItem.getType().equals("file")) {
|
switch(currentItem.getType()) {
|
||||||
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_file));
|
|
||||||
holder.fileInfo.setVisibility(View.VISIBLE);
|
|
||||||
holder.fileInfo.setText(AppUtil.formatFileSizeInDetail(currentItem.getSize()));
|
|
||||||
}
|
|
||||||
else if(currentItem.getType().equals("dir")) {
|
|
||||||
holder.fileInfo.setVisibility(View.GONE);
|
|
||||||
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_directory));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_question));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
case "file":
|
||||||
|
holder.fileTypeIs.setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.ic_file));
|
||||||
|
holder.fileInfo.setVisibility(View.VISIBLE);
|
||||||
|
holder.fileInfo.setText(FileUtils.byteCountToDisplaySize(currentItem.getSize()));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "dir":
|
||||||
|
holder.fileTypeIs.setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.ic_directory));
|
||||||
|
holder.fileInfo.setVisibility(View.GONE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "submodule":
|
||||||
|
holder.fileTypeIs.setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.ic_submodule));
|
||||||
|
holder.fileInfo.setVisibility(View.GONE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "symlink":
|
||||||
|
holder.fileTypeIs.setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.ic_symlink));
|
||||||
|
holder.fileInfo.setVisibility(View.GONE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
holder.fileTypeIs.setImageDrawable(AppCompatResources.getDrawable(context, R.drawable.ic_question));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return filesList.size();
|
return alteredFiles.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -181,17 +195,19 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
|
|||||||
return filesFilter;
|
return filesFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Filter filesFilter = new Filter() {
|
private final Filter filesFilter = new Filter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FilterResults performFiltering(CharSequence constraint) {
|
protected FilterResults performFiltering(CharSequence constraint) {
|
||||||
|
|
||||||
List<Files> filteredList = new ArrayList<>();
|
List<Files> filteredList = new ArrayList<>();
|
||||||
|
|
||||||
if (constraint == null || constraint.length() == 0) {
|
if (constraint == null || constraint.length() == 0) {
|
||||||
filteredList.addAll(filesListFull);
|
filteredList.addAll(originalFiles);
|
||||||
} else {
|
} else {
|
||||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||||
|
|
||||||
for (Files item : filesListFull) {
|
for (Files item : originalFiles) {
|
||||||
if (item.getName().toLowerCase().contains(filterPattern) || item.getPath().toLowerCase().contains(filterPattern)) {
|
if (item.getName().toLowerCase().contains(filterPattern) || item.getPath().toLowerCase().contains(filterPattern)) {
|
||||||
filteredList.add(item);
|
filteredList.add(item);
|
||||||
}
|
}
|
||||||
@@ -202,14 +218,19 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
|
|||||||
results.values = filteredList;
|
results.values = filteredList;
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||||
filesList.clear();
|
|
||||||
filesList.addAll((List) results.values);
|
alteredFiles.clear();
|
||||||
|
alteredFiles.addAll((List) results.values);
|
||||||
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package org.mian.gitnex.adapters;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -12,10 +12,12 @@ import android.widget.BaseAdapter;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import org.gitnex.tea4j.models.FileDiffView;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.activities.ReplyToIssueActivity;
|
import org.mian.gitnex.fragments.BottomSheetReplyFragment;
|
||||||
import org.mian.gitnex.helpers.DiffTextView;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.models.FileDiffView;
|
import org.mian.gitnex.views.DiffTextView;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
import java.util.concurrent.ConcurrentSkipListMap;
|
||||||
@@ -35,22 +37,23 @@ public class FilesDiffAdapter extends BaseAdapter {
|
|||||||
private static int COLOR_SELECTED;
|
private static int COLOR_SELECTED;
|
||||||
private static int COLOR_FONT;
|
private static int COLOR_FONT;
|
||||||
|
|
||||||
private Context context;
|
private final Context context;
|
||||||
private List<FileDiffView> fileDiffViews;
|
private final FragmentManager fragmentManager;
|
||||||
|
private final List<FileDiffView> fileDiffViews;
|
||||||
|
|
||||||
public FilesDiffAdapter(Context context, List<FileDiffView> fileDiffViews) {
|
public FilesDiffAdapter(Context context, FragmentManager fragmentManager, List<FileDiffView> fileDiffViews) {
|
||||||
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.fragmentManager = fragmentManager;
|
||||||
this.fileDiffViews = fileDiffViews;
|
this.fileDiffViews = fileDiffViews;
|
||||||
|
|
||||||
selectedViews = new ConcurrentSkipListMap<>();
|
selectedViews = new ConcurrentSkipListMap<>();
|
||||||
|
|
||||||
COLOR_ADDED = getColorFromAttribute(R.attr.diffAddedColor);
|
COLOR_ADDED = AppUtil.getColorFromAttribute(context, R.attr.diffAddedColor);
|
||||||
COLOR_REMOVED = getColorFromAttribute(R.attr.diffRemovedColor);
|
COLOR_REMOVED = AppUtil.getColorFromAttribute(context, R.attr.diffRemovedColor);
|
||||||
COLOR_NORMAL = getColorFromAttribute(R.attr.primaryBackgroundColor);
|
COLOR_NORMAL = AppUtil.getColorFromAttribute(context, R.attr.primaryBackgroundColor);
|
||||||
COLOR_SELECTED = getColorFromAttribute(R.attr.diffSelectedColor);
|
COLOR_SELECTED = AppUtil.getColorFromAttribute(context, R.attr.diffSelectedColor);
|
||||||
COLOR_FONT = getColorFromAttribute(R.attr.inputTextColor);
|
COLOR_FONT = AppUtil.getColorFromAttribute(context, R.attr.inputTextColor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -90,7 +93,6 @@ public class FilesDiffAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
diffStats.setVisibility(View.GONE);
|
diffStats.setVisibility(View.GONE);
|
||||||
diffLines.addView(getMessageView(context.getResources().getString(R.string.binaryFileError)));
|
diffLines.addView(getMessageView(context.getResources().getString(R.string.binaryFileError)));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
@@ -164,7 +166,6 @@ public class FilesDiffAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
diffTextView.setOnClickListener(v -> {
|
diffTextView.setOnClickListener(v -> {
|
||||||
|
|
||||||
if(((DiffTextView) v).getCurrentBackgroundColor() != COLOR_SELECTED) {
|
if(((DiffTextView) v).getCurrentBackgroundColor() != COLOR_SELECTED) {
|
||||||
@@ -182,7 +183,6 @@ public class FilesDiffAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
diffTextView.setOnLongClickListener(v -> {
|
diffTextView.setOnLongClickListener(v -> {
|
||||||
|
|
||||||
if(((DiffTextView) v).getCurrentBackgroundColor() == COLOR_SELECTED) {
|
if(((DiffTextView) v).getCurrentBackgroundColor() == COLOR_SELECTED) {
|
||||||
@@ -194,20 +194,17 @@ public class FilesDiffAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
stringBuilder.append(((DiffTextView) view).getText());
|
stringBuilder.append(((DiffTextView) view).getText());
|
||||||
stringBuilder.append("\n");
|
stringBuilder.append("\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stringBuilder.append("```\n\n");
|
stringBuilder.append("```\n\n");
|
||||||
|
|
||||||
selectedViews.clear();
|
selectedViews.clear();
|
||||||
|
|
||||||
Intent intent = new Intent(context, ReplyToIssueActivity.class);
|
Bundle bundle = new Bundle();
|
||||||
intent.putExtra("commentBody", stringBuilder.toString());
|
bundle.putString("commentBody", stringBuilder.toString());
|
||||||
intent.putExtra("cursorToEnd", true);
|
bundle.putBoolean("cursorToEnd", true);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
|
|
||||||
context.startActivity(intent);
|
|
||||||
|
|
||||||
|
BottomSheetReplyFragment.newInstance(bundle).show(fragmentManager, "replyBottomSheet");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -224,7 +221,6 @@ public class FilesDiffAdapter extends BaseAdapter {
|
|||||||
else {
|
else {
|
||||||
|
|
||||||
diffLines.addView(getMessageView(context.getResources().getString(R.string.fileTooLarge)));
|
diffLines.addView(getMessageView(context.getResources().getString(R.string.fileTooLarge)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -246,22 +242,11 @@ public class FilesDiffAdapter extends BaseAdapter {
|
|||||||
textView.setText(message);
|
textView.setText(message);
|
||||||
|
|
||||||
return textView;
|
return textView;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] getLines(String content) {
|
private String[] getLines(String content) {
|
||||||
|
|
||||||
return content.split("\\R");
|
return content.split("\\R");
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getColorFromAttribute(int resid) {
|
|
||||||
|
|
||||||
TypedValue typedValue = new TypedValue();
|
|
||||||
context.getTheme().resolveAttribute(resid, typedValue, true);
|
|
||||||
|
|
||||||
return typedValue.data;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,51 +5,37 @@ import android.content.ClipData;
|
|||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.os.Bundle;
|
||||||
import android.net.Uri;
|
|
||||||
import android.text.Spanned;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.vdurmont.emoji.EmojiParser;
|
import com.vdurmont.emoji.EmojiParser;
|
||||||
|
import org.gitnex.tea4j.models.IssueComments;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.activities.ReplyToIssueActivity;
|
import org.mian.gitnex.activities.ProfileActivity;
|
||||||
import org.mian.gitnex.clients.PicassoService;
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
import org.mian.gitnex.clients.RetrofitClient;
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.fragments.BottomSheetReplyFragment;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.ClickListener;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
|
import org.mian.gitnex.helpers.Markdown;
|
||||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
import org.mian.gitnex.helpers.TimeHelper;
|
import org.mian.gitnex.helpers.TimeHelper;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.UserMentions;
|
import org.mian.gitnex.views.ReactionList;
|
||||||
import org.mian.gitnex.models.IssueComments;
|
import org.mian.gitnex.views.ReactionSpinner;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
|
||||||
import io.noties.markwon.Markwon;
|
|
||||||
import io.noties.markwon.core.CorePlugin;
|
|
||||||
import io.noties.markwon.core.MarkwonTheme;
|
|
||||||
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
|
||||||
import io.noties.markwon.ext.tables.TablePlugin;
|
|
||||||
import io.noties.markwon.ext.tasklist.TaskListPlugin;
|
|
||||||
import io.noties.markwon.html.HtmlPlugin;
|
|
||||||
import io.noties.markwon.image.DefaultMediaDecoder;
|
|
||||||
import io.noties.markwon.image.ImageItem;
|
|
||||||
import io.noties.markwon.image.ImagesPlugin;
|
|
||||||
import io.noties.markwon.image.SchemeHandler;
|
|
||||||
import io.noties.markwon.image.gif.GifMediaDecoder;
|
|
||||||
import io.noties.markwon.image.svg.SvgMediaDecoder;
|
|
||||||
import io.noties.markwon.linkify.LinkifyPlugin;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
|
|
||||||
@@ -59,151 +45,184 @@ import retrofit2.Callback;
|
|||||||
|
|
||||||
public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdapter.IssueCommentViewHolder> {
|
public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdapter.IssueCommentViewHolder> {
|
||||||
|
|
||||||
private List<IssueComments> issuesComments;
|
private final Context context;
|
||||||
private Context mCtx;
|
private final TinyDB tinyDB;
|
||||||
|
private final Bundle bundle;
|
||||||
|
private final List<IssueComments> issuesComments;
|
||||||
|
private final FragmentManager fragmentManager;
|
||||||
|
private final BottomSheetReplyFragment.OnInteractedListener onInteractedListener;
|
||||||
|
private final Locale locale;
|
||||||
|
|
||||||
public IssueCommentsAdapter(Context mCtx, List<IssueComments> issuesCommentsMain) {
|
public IssueCommentsAdapter(Context ctx, Bundle bundle, List<IssueComments> issuesCommentsMain, FragmentManager fragmentManager, BottomSheetReplyFragment.OnInteractedListener onInteractedListener) {
|
||||||
|
|
||||||
this.mCtx = mCtx;
|
this.context = ctx;
|
||||||
|
this.bundle = bundle;
|
||||||
this.issuesComments = issuesCommentsMain;
|
this.issuesComments = issuesCommentsMain;
|
||||||
|
this.fragmentManager = fragmentManager;
|
||||||
|
this.onInteractedListener = onInteractedListener;
|
||||||
|
tinyDB = TinyDB.getInstance(ctx);
|
||||||
|
locale = ctx.getResources().getConfiguration().locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
class IssueCommentViewHolder extends RecyclerView.ViewHolder {
|
class IssueCommentViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private TextView issueNumber;
|
private String userLoginId;
|
||||||
private TextView commendId;
|
private IssueComments issueComment;
|
||||||
private ImageView issueCommenterAvatar;
|
|
||||||
private TextView issueComment;
|
|
||||||
private TextView issueCommentDate;
|
|
||||||
private TextView commendBodyRaw;
|
|
||||||
private TextView commentModified;
|
|
||||||
private TextView commenterUsername;
|
|
||||||
private TextView htmlUrl;
|
|
||||||
|
|
||||||
private IssueCommentViewHolder(View itemView) {
|
private final ImageView avatar;
|
||||||
|
private final TextView author;
|
||||||
|
private final TextView information;
|
||||||
|
private final TextView comment;
|
||||||
|
private final LinearLayout commentReactionBadges;
|
||||||
|
|
||||||
super(itemView);
|
private IssueCommentViewHolder(View view) {
|
||||||
|
|
||||||
issueNumber = itemView.findViewById(R.id.issueNumber);
|
super(view);
|
||||||
commendId = itemView.findViewById(R.id.commendId);
|
|
||||||
issueCommenterAvatar = itemView.findViewById(R.id.issueCommenterAvatar);
|
|
||||||
issueComment = itemView.findViewById(R.id.issueComment);
|
|
||||||
issueCommentDate = itemView.findViewById(R.id.issueCommentDate);
|
|
||||||
ImageView commentsOptionsMenu = itemView.findViewById(R.id.commentsOptionsMenu);
|
|
||||||
commendBodyRaw = itemView.findViewById(R.id.commendBodyRaw);
|
|
||||||
commentModified = itemView.findViewById(R.id.commentModified);
|
|
||||||
commenterUsername = itemView.findViewById(R.id.commenterUsername);
|
|
||||||
htmlUrl = itemView.findViewById(R.id.htmlUrl);
|
|
||||||
|
|
||||||
commentsOptionsMenu.setOnClickListener(v -> {
|
avatar = view.findViewById(R.id.avatar);
|
||||||
|
author = view.findViewById(R.id.author);
|
||||||
|
information = view.findViewById(R.id.information);
|
||||||
|
ImageView menu = view.findViewById(R.id.menu);
|
||||||
|
comment = view.findViewById(R.id.comment);
|
||||||
|
commentReactionBadges = view.findViewById(R.id.commentReactionBadges);
|
||||||
|
|
||||||
final Context ctx = v.getContext();
|
menu.setOnClickListener(v -> {
|
||||||
final TinyDB tinyDb = new TinyDB(ctx);
|
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
|
||||||
|
|
||||||
@SuppressLint("InflateParams") View view = LayoutInflater.from(ctx).inflate(R.layout.bottom_sheet_issue_comments, null);
|
final String loginUid = tinyDB.getString("loginUid");
|
||||||
|
|
||||||
TextView commentMenuEdit = view.findViewById(R.id.commentMenuEdit);
|
@SuppressLint("InflateParams") View vw = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_issue_comments, null);
|
||||||
TextView commentShare = view.findViewById(R.id.issueCommentShare);
|
|
||||||
TextView commentMenuQuote = view.findViewById(R.id.commentMenuQuote);
|
|
||||||
TextView commentMenuCopy = view.findViewById(R.id.commentMenuCopy);
|
|
||||||
TextView commentMenuDelete = view.findViewById(R.id.commentMenuDelete);
|
|
||||||
|
|
||||||
if(!loginUid.contentEquals(commenterUsername.getText())) {
|
TextView commentMenuEdit = vw.findViewById(R.id.commentMenuEdit);
|
||||||
|
TextView commentShare = vw.findViewById(R.id.issueCommentShare);
|
||||||
|
TextView commentMenuQuote = vw.findViewById(R.id.commentMenuQuote);
|
||||||
|
TextView commentMenuCopy = vw.findViewById(R.id.commentMenuCopy);
|
||||||
|
TextView commentMenuDelete = vw.findViewById(R.id.commentMenuDelete);
|
||||||
|
TextView issueCommentCopyUrl = vw.findViewById(R.id.issueCommentCopyUrl);
|
||||||
|
|
||||||
|
if(!loginUid.contentEquals(issueComment.getUser().getUsername())) {
|
||||||
commentMenuEdit.setVisibility(View.GONE);
|
commentMenuEdit.setVisibility(View.GONE);
|
||||||
commentMenuDelete.setVisibility(View.GONE);
|
commentMenuDelete.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(issueComment.getText().toString().isEmpty()) {
|
if(issueComment.getBody().isEmpty()) {
|
||||||
commentMenuCopy.setVisibility(View.GONE);
|
commentMenuCopy.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
BottomSheetDialog dialog = new BottomSheetDialog(ctx);
|
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
||||||
dialog.setContentView(view);
|
dialog.setContentView(vw);
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
commentMenuEdit.setOnClickListener(ediComment -> {
|
LinearLayout linearLayout = vw.findViewById(R.id.commentReactionButtons);
|
||||||
|
|
||||||
Intent intent = new Intent(ctx, ReplyToIssueActivity.class);
|
Bundle bundle1 = new Bundle();
|
||||||
intent.putExtra("commentId", commendId.getText());
|
bundle1.putAll(bundle);
|
||||||
intent.putExtra("commentAction", "edit");
|
bundle1.putInt("commentId", issueComment.getId());
|
||||||
intent.putExtra("commentBody", commendBodyRaw.getText());
|
|
||||||
ctx.startActivity(intent);
|
ReactionSpinner reactionSpinner = new ReactionSpinner(context, bundle1);
|
||||||
|
reactionSpinner.setOnInteractedListener(() -> {
|
||||||
|
tinyDB.putBoolean("commentEdited", true);
|
||||||
|
|
||||||
|
onInteractedListener.onInteracted();
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
commentShare.setOnClickListener(ediComment -> {
|
linearLayout.addView(reactionSpinner);
|
||||||
|
|
||||||
|
commentMenuEdit.setOnClickListener(v1 -> {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putInt("commentId", issueComment.getId());
|
||||||
|
bundle.putString("commentAction", "edit");
|
||||||
|
bundle.putString("commentBody", issueComment.getBody());
|
||||||
|
|
||||||
|
BottomSheetReplyFragment bottomSheetReplyFragment = BottomSheetReplyFragment.newInstance(bundle);
|
||||||
|
bottomSheetReplyFragment.setOnInteractedListener(onInteractedListener);
|
||||||
|
bottomSheetReplyFragment.show(fragmentManager, "replyBottomSheet");
|
||||||
|
|
||||||
|
dialog.dismiss();
|
||||||
|
});
|
||||||
|
|
||||||
|
commentShare.setOnClickListener(v1 -> {
|
||||||
// get comment Url
|
// get comment Url
|
||||||
CharSequence commentUrl = htmlUrl.getText();
|
CharSequence commentUrl = issueComment.getHtml_url();
|
||||||
|
|
||||||
// share issue comment
|
// share issue comment
|
||||||
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
|
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
|
||||||
sharingIntent.setType("text/plain");
|
sharingIntent.setType("text/plain");
|
||||||
String intentHeader = tinyDb.getString("issueNumber") + ctx.getResources().getString(R.string.hash) + "issuecomment-" + commendId.getText() + " " + tinyDb.getString("issueTitle");
|
String intentHeader = tinyDB.getString("issueNumber") + context.getResources().getString(R.string.hash) + "issuecomment-" + issueComment.getId() + " " + tinyDB.getString("issueTitle");
|
||||||
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, intentHeader);
|
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, intentHeader);
|
||||||
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, commentUrl);
|
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, commentUrl);
|
||||||
ctx.startActivity(Intent.createChooser(sharingIntent, intentHeader));
|
context.startActivity(Intent.createChooser(sharingIntent, intentHeader));
|
||||||
|
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
});
|
||||||
|
|
||||||
|
issueCommentCopyUrl.setOnClickListener(v1 -> {
|
||||||
|
// comment Url
|
||||||
|
CharSequence commentUrl = issueComment.getHtml_url();
|
||||||
|
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
assert clipboard != null;
|
||||||
|
|
||||||
|
ClipData clip = ClipData.newPlainText(commentUrl, commentUrl);
|
||||||
|
clipboard.setPrimaryClip(clip);
|
||||||
|
|
||||||
|
dialog.dismiss();
|
||||||
|
Toasty.success(context, context.getString(R.string.copyIssueUrlToastMsg));
|
||||||
});
|
});
|
||||||
|
|
||||||
commentMenuQuote.setOnClickListener(v1 -> {
|
commentMenuQuote.setOnClickListener(v1 -> {
|
||||||
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
String commenterName = commenterUsername.getText().toString();
|
String commenterName = issueComment.getUser().getUsername();
|
||||||
|
|
||||||
if(!commenterName.equals(tinyDb.getString("userLogin"))) {
|
|
||||||
|
|
||||||
|
if(!commenterName.equals(tinyDB.getString("userLogin"))) {
|
||||||
stringBuilder.append("@").append(commenterName).append("\n\n");
|
stringBuilder.append("@").append(commenterName).append("\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] lines = commendBodyRaw.getText().toString().split("\\R");
|
String[] lines = issueComment.getBody().split("\\R");
|
||||||
|
|
||||||
for(String line : lines) {
|
for(String line : lines) {
|
||||||
|
|
||||||
stringBuilder.append(">").append(line).append("\n");
|
stringBuilder.append(">").append(line).append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
stringBuilder.append("\n");
|
stringBuilder.append("\n");
|
||||||
|
|
||||||
Intent intent = new Intent(ctx, ReplyToIssueActivity.class);
|
Bundle bundle = new Bundle();
|
||||||
intent.putExtra("commentBody", stringBuilder.toString());
|
bundle.putString("commentBody", stringBuilder.toString());
|
||||||
intent.putExtra("cursorToEnd", true);
|
bundle.putBoolean("cursorToEnd", true);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
|
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
ctx.startActivity(intent);
|
BottomSheetReplyFragment.newInstance(bundle).show(fragmentManager, "replyBottomSheet");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
commentMenuCopy.setOnClickListener(view1 -> {
|
commentMenuCopy.setOnClickListener(v1 -> {
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
assert clipboard != null;
|
assert clipboard != null;
|
||||||
|
|
||||||
ClipData clip = ClipData.newPlainText("Comment on issue #" + issueNumber.getText().toString(), issueComment.getText().toString());
|
ClipData clip = ClipData.newPlainText("Comment on issue #" + tinyDB.getString("issueNumber"), issueComment.getBody());
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
|
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
Toasty.info(ctx, ctx.getString(R.string.copyIssueCommentToastMsg));
|
Toasty.success(context, context.getString(R.string.copyIssueCommentToastMsg));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
commentMenuDelete.setOnClickListener(deleteComment -> {
|
commentMenuDelete.setOnClickListener(v1 -> {
|
||||||
|
deleteIssueComment(context, issueComment.getId(), getAdapterPosition());
|
||||||
deleteIssueComment(ctx, Integer.parseInt(commendId.getText().toString()), getAdapterPosition());
|
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
avatar.setOnClickListener(loginId -> {
|
||||||
|
Intent intent = new Intent(context, ProfileActivity.class);
|
||||||
|
intent.putExtra("username", userLoginId);
|
||||||
|
context.startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
|
avatar.setOnLongClickListener(loginId -> {
|
||||||
|
AppUtil.copyToClipboard(context, userLoginId, context.getString(R.string.copyLoginIdToClipBoard, userLoginId));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAdapter(int position) {
|
private void updateAdapter(int position) {
|
||||||
@@ -211,27 +230,23 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
|
|||||||
issuesComments.remove(position);
|
issuesComments.remove(position);
|
||||||
notifyItemRemoved(position);
|
notifyItemRemoved(position);
|
||||||
notifyItemRangeChanged(position, issuesComments.size());
|
notifyItemRangeChanged(position, issuesComments.size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteIssueComment(final Context ctx, final int commentId, int position) {
|
private void deleteIssueComment(final Context ctx, final int commentId, int position) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(ctx);
|
final String loginUid = tinyDB.getString("loginUid");
|
||||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
final String instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||||
final String loginUid = tinyDb.getString("loginUid");
|
String[] repoFullName = tinyDB.getString("repoFullName").split("/");
|
||||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
||||||
String[] repoFullName = tinyDb.getString("repoFullName").split("/");
|
|
||||||
if (repoFullName.length != 2) {
|
if (repoFullName.length != 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String repoOwner = repoFullName[0];
|
final String repoOwner = repoFullName[0];
|
||||||
final String repoName = repoFullName[1];
|
final String repoName = repoFullName[1];
|
||||||
|
|
||||||
Call<JsonElement> call;
|
Call<JsonElement> call = RetrofitClient
|
||||||
|
.getApiInterface(ctx)
|
||||||
call = RetrofitClient
|
|
||||||
.getInstance(instanceUrl, ctx)
|
|
||||||
.getApiInterface()
|
|
||||||
.deleteComment(instanceToken, repoOwner, repoName, commentId);
|
.deleteComment(instanceToken, repoOwner, repoName, commentId);
|
||||||
|
|
||||||
call.enqueue(new Callback<JsonElement>() {
|
call.enqueue(new Callback<JsonElement>() {
|
||||||
@@ -239,47 +254,40 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
|
|||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||||
|
|
||||||
if(response.code() == 204) {
|
switch(response.code()) {
|
||||||
|
|
||||||
updateAdapter(position);
|
case 204:
|
||||||
Toasty.success(ctx, ctx.getResources().getString(R.string.deleteCommentSuccess));
|
updateAdapter(position);
|
||||||
|
Toasty.success(ctx, ctx.getResources().getString(R.string.deleteCommentSuccess));
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
case 401:
|
||||||
else if(response.code() == 401) {
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, ctx.getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||||
|
|
||||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, ctx.getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
|
||||||
ctx.getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
ctx.getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 403:
|
||||||
|
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 404:
|
||||||
|
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(response.code() == 403) {
|
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(response.code() == 404) {
|
|
||||||
|
|
||||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getResources().getString(R.string.genericServerResponseError));
|
Toasty.error(ctx, ctx.getResources().getString(R.string.genericServerResponseError));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -288,111 +296,68 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
|
|||||||
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_issue_comments, parent, false);
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_issue_comments, parent, false);
|
||||||
return new IssueCommentsAdapter.IssueCommentViewHolder(v);
|
return new IssueCommentsAdapter.IssueCommentViewHolder(v);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull IssueCommentsAdapter.IssueCommentViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull IssueCommentsAdapter.IssueCommentViewHolder holder, int position) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(mCtx);
|
String timeFormat = tinyDB.getString("dateFormat");
|
||||||
final String locale = tinyDb.getString("locale");
|
IssueComments issueComment = issuesComments.get(position);
|
||||||
final String timeFormat = tinyDb.getString("dateFormat");
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||||
|
|
||||||
IssueComments currentItem = issuesComments.get(position);
|
holder.userLoginId = issueComment.getUser().getLogin();
|
||||||
|
|
||||||
holder.htmlUrl.setText(currentItem.getHtml_url());
|
holder.issueComment = issueComment;
|
||||||
holder.commenterUsername.setText(currentItem.getUser().getUsername());
|
holder.author.setText(issueComment.getUser().getUsername());
|
||||||
holder.commendId.setText(String.valueOf(currentItem.getId()));
|
|
||||||
holder.commendBodyRaw.setText(currentItem.getBody());
|
|
||||||
|
|
||||||
if(!currentItem.getUser().getFull_name().equals("")) {
|
PicassoService.getInstance(context).get()
|
||||||
holder.issueCommenterAvatar.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.issueCommenter) + currentItem.getUser().getFull_name(), mCtx));
|
.load(issueComment.getUser().getAvatar_url())
|
||||||
}
|
.placeholder(R.drawable.loader_animated)
|
||||||
else {
|
.transform(new RoundedTransformation(imgRadius, 0))
|
||||||
holder.issueCommenterAvatar.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.issueCommenter) + currentItem.getUser().getLogin(), mCtx));
|
.resize(AppUtil.getPixelsFromDensity(context, 35), AppUtil.getPixelsFromDensity(context, 35))
|
||||||
}
|
.centerCrop()
|
||||||
|
.into(holder.avatar);
|
||||||
|
|
||||||
PicassoService.getInstance(mCtx).get().load(currentItem.getUser().getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.issueCommenterAvatar);
|
Markdown.render(context, EmojiParser.parseToUnicode(issueComment.getBody()), holder.comment);
|
||||||
|
|
||||||
String cleanIssueComments = currentItem.getBody().trim();
|
StringBuilder informationBuilder = null;
|
||||||
|
if(issueComment.getCreated_at() != null) {
|
||||||
final Markwon markwon = Markwon.builder(Objects.requireNonNull(mCtx)).usePlugin(CorePlugin.create()).usePlugin(ImagesPlugin.create(new ImagesPlugin.ImagesConfigure() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void configureImages(@NonNull ImagesPlugin plugin) {
|
|
||||||
|
|
||||||
plugin.addSchemeHandler(new SchemeHandler() {
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
|
|
||||||
|
|
||||||
final int resourceId = mCtx.getResources().getIdentifier(raw.substring("drawable://".length()), "drawable", mCtx.getPackageName());
|
|
||||||
|
|
||||||
final Drawable drawable = mCtx.getDrawable(resourceId);
|
|
||||||
|
|
||||||
assert drawable != null;
|
|
||||||
return ImageItem.withResult(drawable);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Collection<String> supportedSchemes() {
|
|
||||||
|
|
||||||
return Collections.singleton("drawable");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
plugin.placeholderProvider(drawable -> null);
|
|
||||||
plugin.addMediaDecoder(GifMediaDecoder.create(false));
|
|
||||||
plugin.addMediaDecoder(SvgMediaDecoder.create(mCtx.getResources()));
|
|
||||||
plugin.addMediaDecoder(SvgMediaDecoder.create());
|
|
||||||
plugin.defaultMediaDecoder(DefaultMediaDecoder.create(mCtx.getResources()));
|
|
||||||
plugin.defaultMediaDecoder(DefaultMediaDecoder.create());
|
|
||||||
|
|
||||||
|
if(timeFormat.equals("pretty")) {
|
||||||
|
informationBuilder = new StringBuilder(TimeHelper.formatTime(issueComment.getCreated_at(), locale, "pretty", context));
|
||||||
|
holder.information.setOnClickListener(v -> TimeHelper.customDateFormatForToastDateFormat(issueComment.getCreated_at()));
|
||||||
}
|
}
|
||||||
})).usePlugin(new AbstractMarkwonPlugin() {
|
else if(timeFormat.equals("normal")) {
|
||||||
|
informationBuilder = new StringBuilder(TimeHelper.formatTime(issueComment.getCreated_at(), locale, "normal", context));
|
||||||
@Override
|
|
||||||
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
|
|
||||||
|
|
||||||
builder.codeTextColor(tinyDb.getInt("codeBlockColor")).codeBackgroundColor(tinyDb.getInt("codeBlockBackground")).linkColor(mCtx.getResources().getColor(R.color.lightBlue));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}).usePlugin(TablePlugin.create(mCtx)).usePlugin(TaskListPlugin.create(mCtx)).usePlugin(HtmlPlugin.create()).usePlugin(StrikethroughPlugin.create()).usePlugin(LinkifyPlugin.create()).build();
|
if(!issueComment.getCreated_at().equals(issueComment.getUpdated_at())) {
|
||||||
|
if(informationBuilder != null) {
|
||||||
Spanned bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(cleanIssueComments));
|
informationBuilder.append(context.getString(R.string.colorfulBulletSpan)).append(context.getString(R.string.modifiedText));
|
||||||
markwon.setParsedMarkdown(holder.issueComment, UserMentions.UserMentionsFunc(mCtx, bodyWithMD, cleanIssueComments));
|
}
|
||||||
|
}
|
||||||
String edited;
|
|
||||||
|
|
||||||
if(!currentItem.getUpdated_at().equals(currentItem.getCreated_at())) {
|
|
||||||
|
|
||||||
edited = mCtx.getResources().getString(R.string.colorfulBulletSpan) + mCtx.getResources().getString(R.string.modifiedText);
|
|
||||||
holder.commentModified.setVisibility(View.VISIBLE);
|
|
||||||
holder.commentModified.setText(edited);
|
|
||||||
holder.commentModified.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(currentItem.getUpdated_at()), mCtx));
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
holder.commentModified.setVisibility(View.INVISIBLE);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.issueCommentDate.setText(TimeHelper.formatTime(currentItem.getCreated_at(), new Locale(locale), timeFormat, mCtx));
|
holder.information.setText(informationBuilder);
|
||||||
|
|
||||||
|
Bundle bundle1 = new Bundle();
|
||||||
|
bundle1.putAll(bundle);
|
||||||
|
bundle1.putInt("commentId", issueComment.getId());
|
||||||
|
|
||||||
|
ReactionList reactionList = new ReactionList(context, bundle1);
|
||||||
|
|
||||||
|
holder.commentReactionBadges.addView(reactionList);
|
||||||
|
reactionList.setOnReactionAddedListener(() -> {
|
||||||
|
|
||||||
|
if(holder.commentReactionBadges.getVisibility() != View.VISIBLE) {
|
||||||
|
holder.commentReactionBadges.post(() -> holder.commentReactionBadges.setVisibility(View.VISIBLE));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if(timeFormat.equals("pretty")) {
|
|
||||||
holder.issueCommentDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(currentItem.getCreated_at()), mCtx));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
|
|
||||||
return issuesComments.size();
|
return issuesComments.size();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,23 +3,26 @@ package org.mian.gitnex.adapters;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.text.Html;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
|
import androidx.core.text.HtmlCompat;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import com.vdurmont.emoji.EmojiParser;
|
||||||
|
import org.gitnex.tea4j.models.Issues;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.activities.IssueDetailActivity;
|
import org.mian.gitnex.activities.IssueDetailActivity;
|
||||||
|
import org.mian.gitnex.activities.ProfileActivity;
|
||||||
import org.mian.gitnex.clients.PicassoService;
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.ClickListener;
|
import org.mian.gitnex.helpers.ClickListener;
|
||||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
import org.mian.gitnex.helpers.TimeHelper;
|
import org.mian.gitnex.helpers.TimeHelper;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.models.Issues;
|
|
||||||
import org.ocpsoft.prettytime.PrettyTime;
|
import org.ocpsoft.prettytime.PrettyTime;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@@ -32,17 +35,16 @@ import java.util.Locale;
|
|||||||
|
|
||||||
public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
private Context context;
|
private final Context context;
|
||||||
private final int TYPE_LOAD = 0;
|
private final int TYPE_LOAD = 0;
|
||||||
private List<Issues> issuesList;
|
private List<Issues> issuesList;
|
||||||
private OnLoadMoreListener loadMoreListener;
|
private OnLoadMoreListener loadMoreListener;
|
||||||
private boolean isLoading = false, isMoreDataAvailable = true;
|
private boolean isLoading = false, isMoreDataAvailable = true;
|
||||||
|
|
||||||
public IssuesAdapter(Context context, List<Issues> issuesListMain) {
|
public IssuesAdapter(Context ctx, List<Issues> issuesListMain) {
|
||||||
|
|
||||||
this.context = context;
|
this.context = ctx;
|
||||||
this.issuesList = issuesListMain;
|
this.issuesList = issuesListMain;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -57,7 +59,6 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||||||
else {
|
else {
|
||||||
return new LoadHolder(inflater.inflate(R.layout.row_load, parent, false));
|
return new LoadHolder(inflater.inflate(R.layout.row_load, parent, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -67,15 +68,12 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||||||
|
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
loadMoreListener.onLoadMore();
|
loadMoreListener.onLoadMore();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getItemViewType(position) == TYPE_LOAD) {
|
if(getItemViewType(position) == TYPE_LOAD) {
|
||||||
|
|
||||||
((IssuesHolder) holder).bindData(issuesList.get(position));
|
((IssuesHolder) holder).bindData(issuesList.get(position));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -87,104 +85,94 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||||||
else {
|
else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
|
|
||||||
return issuesList.size();
|
return issuesList.size();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class IssuesHolder extends RecyclerView.ViewHolder {
|
class IssuesHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private TextView issueNumber;
|
private Issues issue;
|
||||||
private ImageView issueAssigneeAvatar;
|
|
||||||
private TextView issueTitle;
|
private final ImageView issueAssigneeAvatar;
|
||||||
private TextView issueCreatedTime;
|
private final TextView issueTitle;
|
||||||
private TextView issueCommentsCount;
|
private final TextView issueCreatedTime;
|
||||||
|
private final TextView issueCommentsCount;
|
||||||
|
|
||||||
IssuesHolder(View itemView) {
|
IssuesHolder(View itemView) {
|
||||||
|
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
|
||||||
issueNumber = itemView.findViewById(R.id.issueNumber);
|
|
||||||
issueAssigneeAvatar = itemView.findViewById(R.id.assigneeAvatar);
|
issueAssigneeAvatar = itemView.findViewById(R.id.assigneeAvatar);
|
||||||
issueTitle = itemView.findViewById(R.id.issueTitle);
|
issueTitle = itemView.findViewById(R.id.issueTitle);
|
||||||
issueCommentsCount = itemView.findViewById(R.id.issueCommentsCount);
|
issueCommentsCount = itemView.findViewById(R.id.issueCommentsCount);
|
||||||
LinearLayout frameCommentsCount = itemView.findViewById(R.id.frameCommentsCount);
|
|
||||||
issueCreatedTime = itemView.findViewById(R.id.issueCreatedTime);
|
issueCreatedTime = itemView.findViewById(R.id.issueCreatedTime);
|
||||||
|
|
||||||
issueTitle.setOnClickListener(v -> {
|
itemView.setOnClickListener(layoutView -> {
|
||||||
|
|
||||||
Context context = v.getContext();
|
|
||||||
|
|
||||||
Intent intent = new Intent(context, IssueDetailActivity.class);
|
Intent intent = new Intent(context, IssueDetailActivity.class);
|
||||||
intent.putExtra("issueNumber", issueNumber.getText());
|
intent.putExtra("issueNumber", issue.getNumber());
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(context);
|
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
tinyDb.putString("issueNumber", issueNumber.getText().toString());
|
tinyDb.putString("issueNumber", String.valueOf(issue.getNumber()));
|
||||||
tinyDb.putString("issueType", "Issue");
|
tinyDb.putString("issueType", "Issue");
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
|
|
||||||
});
|
});
|
||||||
frameCommentsCount.setOnClickListener(v -> {
|
|
||||||
|
|
||||||
Context context = v.getContext();
|
issueAssigneeAvatar.setOnClickListener(v -> {
|
||||||
|
Intent intent = new Intent(context, ProfileActivity.class);
|
||||||
Intent intent = new Intent(context, IssueDetailActivity.class);
|
intent.putExtra("username", issue.getUser().getLogin());
|
||||||
intent.putExtra("issueNumber", issueNumber.getText());
|
|
||||||
|
|
||||||
TinyDB tinyDb = new TinyDB(context);
|
|
||||||
tinyDb.putString("issueNumber", issueNumber.getText().toString());
|
|
||||||
tinyDb.putString("issueType", "Issue");
|
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
issueAssigneeAvatar.setOnLongClickListener(loginId -> {
|
||||||
|
AppUtil.copyToClipboard(context, issue.getUser().getLogin(), context.getString(R.string.copyLoginIdToClipBoard, issue.getUser().getLogin()));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
void bindData(Issues issuesModel) {
|
void bindData(Issues issue) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(context);
|
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
final String locale = tinyDb.getString("locale");
|
Locale locale = context.getResources().getConfiguration().locale;
|
||||||
final String timeFormat = tinyDb.getString("dateFormat");
|
String timeFormat = tinyDb.getString("dateFormat");
|
||||||
|
|
||||||
if(!issuesModel.getUser().getFull_name().equals("")) {
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||||
issueAssigneeAvatar.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueCreator) + issuesModel.getUser().getFull_name(), context));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
issueAssigneeAvatar.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueCreator) + issuesModel.getUser().getLogin(), context));
|
|
||||||
}
|
|
||||||
|
|
||||||
PicassoService.getInstance(context).get().load(issuesModel.getUser().getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(issueAssigneeAvatar);
|
PicassoService.getInstance(context).get()
|
||||||
|
.load(issue.getUser().getAvatar_url())
|
||||||
|
.placeholder(R.drawable.loader_animated)
|
||||||
|
.transform(new RoundedTransformation(imgRadius, 0))
|
||||||
|
.resize(120, 120)
|
||||||
|
.centerCrop()
|
||||||
|
.into(issueAssigneeAvatar);
|
||||||
|
|
||||||
String issueNumber_ = "<font color='" + context.getResources().getColor(R.color.lightGray) + "'>" + context.getResources().getString(R.string.hash) + issuesModel.getNumber() + "</font>";
|
String issueNumber_ = "<font color='" + ResourcesCompat.getColor(context.getResources(), R.color.lightGray, null) + "'>" + context.getResources().getString(R.string.hash) + issue.getNumber() + "</font>";
|
||||||
issueTitle.setText(Html.fromHtml(issueNumber_ + " " + issuesModel.getTitle()));
|
issueTitle.setText(HtmlCompat.fromHtml(issueNumber_ + " " + EmojiParser.parseToUnicode(issue.getTitle()), HtmlCompat.FROM_HTML_MODE_LEGACY));
|
||||||
|
|
||||||
issueNumber.setText(String.valueOf(issuesModel.getNumber()));
|
this.issue = issue;
|
||||||
issueCommentsCount.setText(String.valueOf(issuesModel.getComments()));
|
this.issueCommentsCount.setText(String.valueOf(issue.getComments()));
|
||||||
|
|
||||||
switch(timeFormat) {
|
switch(timeFormat) {
|
||||||
case "pretty": {
|
case "pretty": {
|
||||||
PrettyTime prettyTime = new PrettyTime(new Locale(locale));
|
PrettyTime prettyTime = new PrettyTime(locale);
|
||||||
String createdTime = prettyTime.format(issuesModel.getCreated_at());
|
String createdTime = prettyTime.format(issue.getCreated_at());
|
||||||
issueCreatedTime.setText(createdTime);
|
this.issueCreatedTime.setText(createdTime);
|
||||||
issueCreatedTime.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(issuesModel.getCreated_at()), context));
|
this.issueCreatedTime.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(issue.getCreated_at()), context));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "normal": {
|
case "normal": {
|
||||||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale));
|
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
|
||||||
String createdTime = formatter.format(issuesModel.getCreated_at());
|
String createdTime = formatter.format(issue.getCreated_at());
|
||||||
issueCreatedTime.setText(createdTime);
|
this.issueCreatedTime.setText(createdTime);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "normal1": {
|
case "normal1": {
|
||||||
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale));
|
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
|
||||||
String createdTime = formatter.format(issuesModel.getCreated_at());
|
String createdTime = formatter.format(issue.getCreated_at());
|
||||||
issueCreatedTime.setText(createdTime);
|
this.issueCreatedTime.setText(createdTime);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,32 +187,27 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||||||
|
|
||||||
super(itemView);
|
super(itemView);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
||||||
|
|
||||||
isMoreDataAvailable = moreDataAvailable;
|
isMoreDataAvailable = moreDataAvailable;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyDataChanged() {
|
public void notifyDataChanged() {
|
||||||
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnLoadMoreListener {
|
public interface OnLoadMoreListener {
|
||||||
|
|
||||||
void onLoadMore();
|
void onLoadMore();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoadMoreListener(OnLoadMoreListener loadMoreListener) {
|
public void setLoadMoreListener(OnLoadMoreListener loadMoreListener) {
|
||||||
|
|
||||||
this.loadMoreListener = loadMoreListener;
|
this.loadMoreListener = loadMoreListener;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateList(List<Issues> list) {
|
public void updateList(List<Issues> list) {
|
||||||
|
|||||||
@@ -15,12 +15,11 @@ import androidx.cardview.widget.CardView;
|
|||||||
import androidx.core.widget.ImageViewCompat;
|
import androidx.core.widget.ImageViewCompat;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||||
|
import org.gitnex.tea4j.models.Labels;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.activities.CreateLabelActivity;
|
import org.mian.gitnex.activities.CreateLabelActivity;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.ColorInverter;
|
import org.mian.gitnex.helpers.ColorInverter;
|
||||||
import org.mian.gitnex.models.Labels;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,19 +28,17 @@ import java.util.List;
|
|||||||
|
|
||||||
public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsViewHolder> {
|
public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsViewHolder> {
|
||||||
|
|
||||||
private List<Labels> labelsList;
|
private final List<Labels> labelsList;
|
||||||
final private Context mCtx;
|
private static String type;
|
||||||
private ArrayList<Integer> labelsArray = new ArrayList<>();
|
private static String orgName;
|
||||||
|
|
||||||
static class LabelsViewHolder extends RecyclerView.ViewHolder {
|
static class LabelsViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private TextView labelTitle;
|
private Labels labels;
|
||||||
private TextView labelId;
|
|
||||||
private TextView labelColor;
|
|
||||||
|
|
||||||
private CardView labelView;
|
private final CardView labelView;
|
||||||
private ImageView labelIcon;
|
private final ImageView labelIcon;
|
||||||
private TextView labelName;
|
private final TextView labelName;
|
||||||
|
|
||||||
private LabelsViewHolder(View itemView) {
|
private LabelsViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
@@ -50,9 +47,6 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
|||||||
labelIcon = itemView.findViewById(R.id.labelIcon);
|
labelIcon = itemView.findViewById(R.id.labelIcon);
|
||||||
labelName = itemView.findViewById(R.id.labelName);
|
labelName = itemView.findViewById(R.id.labelName);
|
||||||
ImageView labelsOptionsMenu = itemView.findViewById(R.id.labelsOptionsMenu);
|
ImageView labelsOptionsMenu = itemView.findViewById(R.id.labelsOptionsMenu);
|
||||||
labelTitle = itemView.findViewById(R.id.labelTitle);
|
|
||||||
labelId = itemView.findViewById(R.id.labelId);
|
|
||||||
labelColor = itemView.findViewById(R.id.labelColor);
|
|
||||||
|
|
||||||
labelsOptionsMenu.setOnClickListener(v -> {
|
labelsOptionsMenu.setOnClickListener(v -> {
|
||||||
|
|
||||||
@@ -65,7 +59,7 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
|||||||
TextView labelMenuDelete = view.findViewById(R.id.labelMenuDelete);
|
TextView labelMenuDelete = view.findViewById(R.id.labelMenuDelete);
|
||||||
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
|
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
|
||||||
|
|
||||||
bottomSheetHeader.setText(labelTitle.getText());
|
bottomSheetHeader.setText(labels.getName());
|
||||||
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
||||||
dialog.setContentView(view);
|
dialog.setContentView(view);
|
||||||
dialog.show();
|
dialog.show();
|
||||||
@@ -73,24 +67,25 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
|||||||
labelMenuEdit.setOnClickListener(editLabel -> {
|
labelMenuEdit.setOnClickListener(editLabel -> {
|
||||||
|
|
||||||
Intent intent = new Intent(context, CreateLabelActivity.class);
|
Intent intent = new Intent(context, CreateLabelActivity.class);
|
||||||
intent.putExtra("labelId", labelId.getText());
|
intent.putExtra("labelId", String.valueOf(labels.getId()));
|
||||||
intent.putExtra("labelTitle", labelTitle.getText());
|
intent.putExtra("labelTitle", labels.getName());
|
||||||
intent.putExtra("labelColor", labelColor.getText());
|
intent.putExtra("labelColor", labels.getColor());
|
||||||
intent.putExtra("labelAction", "edit");
|
intent.putExtra("labelAction", "edit");
|
||||||
|
intent.putExtra("type", type);
|
||||||
|
intent.putExtra("orgName", orgName);
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
labelMenuDelete.setOnClickListener(deleteLabel -> {
|
labelMenuDelete.setOnClickListener(deleteLabel -> {
|
||||||
|
|
||||||
AlertDialogs.labelDeleteDialog(context, labelTitle.getText().toString(), labelId.getText().toString(),
|
AlertDialogs.labelDeleteDialog(context, labels.getName(), String.valueOf(labels.getId()),
|
||||||
context.getResources().getString(R.string.labelDeleteTitle),
|
context.getResources().getString(R.string.labelDeleteTitle),
|
||||||
context.getResources().getString(R.string.labelDeleteMessage),
|
context.getResources().getString(R.string.labelDeleteMessage),
|
||||||
context.getResources().getString(R.string.labelDeletePositiveButton),
|
context.getResources().getString(R.string.labelDeleteTitle),
|
||||||
context.getResources().getString(R.string.labelDeleteNegativeButton));
|
context.getResources().getString(R.string.labelDeleteNegativeButton),
|
||||||
|
type, orgName);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -98,9 +93,11 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LabelsAdapter(Context mCtx, List<Labels> labelsMain) {
|
public LabelsAdapter(Context ctx, List<Labels> labelsMain, String type, String orgName) {
|
||||||
this.mCtx = mCtx;
|
|
||||||
this.labelsList = labelsMain;
|
this.labelsList = labelsMain;
|
||||||
|
LabelsAdapter.type = type;
|
||||||
|
LabelsAdapter.orgName = orgName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -114,10 +111,7 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
|||||||
public void onBindViewHolder(@NonNull LabelsAdapter.LabelsViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull LabelsAdapter.LabelsViewHolder holder, int position) {
|
||||||
|
|
||||||
Labels currentItem = labelsList.get(position);
|
Labels currentItem = labelsList.get(position);
|
||||||
|
holder.labels = currentItem;
|
||||||
holder.labelTitle.setText(currentItem.getName());
|
|
||||||
holder.labelId.setText(String.valueOf(currentItem.getId()));
|
|
||||||
holder.labelColor.setText(currentItem.getColor());
|
|
||||||
|
|
||||||
String labelColor = currentItem.getColor();
|
String labelColor = currentItem.getColor();
|
||||||
String labelName = currentItem.getName();
|
String labelName = currentItem.getName();
|
||||||
@@ -130,7 +124,6 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
|||||||
holder.labelName.setTextColor(contrastColor);
|
holder.labelName.setTextColor(contrastColor);
|
||||||
holder.labelName.setText(labelName);
|
holder.labelName.setText(labelName);
|
||||||
holder.labelView.setCardBackgroundColor(color);
|
holder.labelView.setCardBackgroundColor(color);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
package org.mian.gitnex.adapters;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import org.gitnex.tea4j.models.Labels;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class LabelsListAdapter extends RecyclerView.Adapter<LabelsListAdapter.LabelsViewHolder> {
|
||||||
|
|
||||||
|
private List<Integer> currentLabelsIds;
|
||||||
|
private final List<Labels> labels;
|
||||||
|
private final List<String> labelsStrings = new ArrayList<>();
|
||||||
|
private List<Integer> labelsIds = new ArrayList<>();
|
||||||
|
|
||||||
|
private final LabelsListAdapterListener labelsListener;
|
||||||
|
|
||||||
|
public interface LabelsListAdapterListener {
|
||||||
|
|
||||||
|
void labelsInterface(List<String> data);
|
||||||
|
void labelsIdsInterface(List<Integer> data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LabelsListAdapter(List<Labels> labelsMain, LabelsListAdapterListener labelsListener, List<Integer> currentLabelsIds) {
|
||||||
|
|
||||||
|
this.labels = labelsMain;
|
||||||
|
this.labelsListener = labelsListener;
|
||||||
|
this.currentLabelsIds = currentLabelsIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class LabelsViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
private final CheckBox labelSelection;
|
||||||
|
private final TextView labelText;
|
||||||
|
private final ImageView labelColor;
|
||||||
|
|
||||||
|
private LabelsViewHolder(View itemView) {
|
||||||
|
|
||||||
|
super(itemView);
|
||||||
|
this.setIsRecyclable(false);
|
||||||
|
|
||||||
|
labelSelection = itemView.findViewById(R.id.labelSelection);
|
||||||
|
labelText = itemView.findViewById(R.id.labelText);
|
||||||
|
labelColor = itemView.findViewById(R.id.labelColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public LabelsListAdapter.LabelsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_labels_list, parent, false);
|
||||||
|
return new LabelsListAdapter.LabelsViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull LabelsListAdapter.LabelsViewHolder holder, int position) {
|
||||||
|
|
||||||
|
Labels currentItem = labels.get(position);
|
||||||
|
|
||||||
|
String labelColor = currentItem.getColor();
|
||||||
|
int color = Color.parseColor("#" + labelColor);
|
||||||
|
|
||||||
|
holder.labelText.setText(currentItem.getName());
|
||||||
|
holder.labelColor.setBackgroundColor(color);
|
||||||
|
|
||||||
|
for(int i = 0; i < labelsIds.size(); i++) {
|
||||||
|
|
||||||
|
if(labelsStrings.contains(currentItem.getName())) {
|
||||||
|
|
||||||
|
holder.labelSelection.setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentLabelsIds = new ArrayList<>(new LinkedHashSet<>(currentLabelsIds));
|
||||||
|
|
||||||
|
for(int i = 0; i < currentLabelsIds.size(); i++) {
|
||||||
|
|
||||||
|
if(currentLabelsIds.contains(currentItem.getId())) {
|
||||||
|
|
||||||
|
holder.labelSelection.setChecked(true);
|
||||||
|
labelsIds.add(currentLabelsIds.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
labelsListener.labelsIdsInterface(labelsIds);
|
||||||
|
|
||||||
|
holder.labelSelection.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
|
||||||
|
if(isChecked) {
|
||||||
|
|
||||||
|
labelsStrings.add(currentItem.getName());
|
||||||
|
labelsIds.add(currentItem.getId());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
labelsStrings.remove(currentItem.getName());
|
||||||
|
labelsIds.remove(Integer.valueOf(currentItem.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
labelsListener.labelsInterface(labelsStrings);
|
||||||
|
labelsListener.labelsIdsInterface(labelsIds);
|
||||||
|
});
|
||||||
|
|
||||||
|
labelsIds = new ArrayList<>(new LinkedHashSet<>(labelsIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
|
||||||
|
return labels.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateList(List<Integer> list) {
|
||||||
|
|
||||||
|
currentLabelsIds = list;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ package org.mian.gitnex.adapters;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.text.Html;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -10,10 +12,12 @@ import android.widget.Filter;
|
|||||||
import android.widget.Filterable;
|
import android.widget.Filterable;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import org.gitnex.tea4j.models.UserInfo;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.activities.ProfileActivity;
|
||||||
import org.mian.gitnex.clients.PicassoService;
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
import org.mian.gitnex.models.UserInfo;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -23,26 +27,40 @@ import java.util.List;
|
|||||||
|
|
||||||
public class MembersByOrgAdapter extends BaseAdapter implements Filterable {
|
public class MembersByOrgAdapter extends BaseAdapter implements Filterable {
|
||||||
|
|
||||||
private List<UserInfo> membersList;
|
private final List<UserInfo> membersList;
|
||||||
private Context mCtx;
|
private final Context context;
|
||||||
private List<UserInfo> membersListFull;
|
private final List<UserInfo> membersListFull;
|
||||||
|
|
||||||
private class ViewHolder {
|
private class ViewHolder {
|
||||||
|
|
||||||
private ImageView memberAvatar;
|
private String userLoginId;
|
||||||
private TextView memberName;
|
|
||||||
|
private final ImageView memberAvatar;
|
||||||
|
private final TextView memberName;
|
||||||
|
|
||||||
ViewHolder(View v) {
|
ViewHolder(View v) {
|
||||||
|
|
||||||
memberAvatar = v.findViewById(R.id.memberAvatar);
|
memberAvatar = v.findViewById(R.id.memberAvatar);
|
||||||
memberName = v.findViewById(R.id.memberName);
|
memberName = v.findViewById(R.id.memberName);
|
||||||
|
|
||||||
|
memberAvatar.setOnClickListener(loginId -> {
|
||||||
|
Intent intent = new Intent(context, ProfileActivity.class);
|
||||||
|
intent.putExtra("username", userLoginId);
|
||||||
|
context.startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
|
memberAvatar.setOnLongClickListener(loginId -> {
|
||||||
|
AppUtil.copyToClipboard(context, userLoginId, context.getString(R.string.copyLoginIdToClipBoard, userLoginId));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MembersByOrgAdapter(Context mCtx, List<UserInfo> membersListMain) {
|
public MembersByOrgAdapter(Context ctx, List<UserInfo> membersListMain) {
|
||||||
this.mCtx = mCtx;
|
|
||||||
|
this.context = ctx;
|
||||||
this.membersList = membersListMain;
|
this.membersList = membersListMain;
|
||||||
membersListFull = new ArrayList<>(membersList);
|
membersListFull = new ArrayList<>(membersList);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -67,31 +85,37 @@ public class MembersByOrgAdapter extends BaseAdapter implements Filterable {
|
|||||||
MembersByOrgAdapter.ViewHolder viewHolder = null;
|
MembersByOrgAdapter.ViewHolder viewHolder = null;
|
||||||
|
|
||||||
if (finalView == null) {
|
if (finalView == null) {
|
||||||
finalView = LayoutInflater.from(mCtx).inflate(R.layout.list_members_by_org, null);
|
|
||||||
viewHolder = new MembersByOrgAdapter.ViewHolder(finalView);
|
finalView = LayoutInflater.from(context).inflate(R.layout.list_members_by_org, null);
|
||||||
|
viewHolder = new ViewHolder(finalView);
|
||||||
finalView.setTag(viewHolder);
|
finalView.setTag(viewHolder);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
viewHolder = (MembersByOrgAdapter.ViewHolder) finalView.getTag();
|
viewHolder = (MembersByOrgAdapter.ViewHolder) finalView.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
initData(viewHolder, position);
|
initData(viewHolder, position);
|
||||||
return finalView;
|
return finalView;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initData(MembersByOrgAdapter.ViewHolder viewHolder, int position) {
|
private void initData(MembersByOrgAdapter.ViewHolder viewHolder, int position) {
|
||||||
|
|
||||||
UserInfo currentItem = membersList.get(position);
|
UserInfo currentItem = membersList.get(position);
|
||||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(viewHolder.memberAvatar);
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||||
|
|
||||||
|
PicassoService.getInstance(context).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop().into(viewHolder.memberAvatar);
|
||||||
|
|
||||||
|
viewHolder.userLoginId = currentItem.getLogin();
|
||||||
|
|
||||||
if(!currentItem.getFullname().equals("")) {
|
if(!currentItem.getFullname().equals("")) {
|
||||||
viewHolder.memberName.setText(currentItem.getFullname());
|
|
||||||
|
viewHolder.memberName.setText(Html.fromHtml(currentItem.getFullname()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
viewHolder.memberName.setText(currentItem.getLogin());
|
viewHolder.memberName.setText(currentItem.getLogin());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,14 +123,17 @@ public class MembersByOrgAdapter extends BaseAdapter implements Filterable {
|
|||||||
return membersFilter;
|
return membersFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Filter membersFilter = new Filter() {
|
private final Filter membersFilter = new Filter() {
|
||||||
@Override
|
@Override
|
||||||
protected FilterResults performFiltering(CharSequence constraint) {
|
protected FilterResults performFiltering(CharSequence constraint) {
|
||||||
List<UserInfo> filteredList = new ArrayList<>();
|
List<UserInfo> filteredList = new ArrayList<>();
|
||||||
|
|
||||||
if (constraint == null || constraint.length() == 0) {
|
if (constraint == null || constraint.length() == 0) {
|
||||||
|
|
||||||
filteredList.addAll(membersListFull);
|
filteredList.addAll(membersListFull);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||||
|
|
||||||
for (UserInfo item : membersListFull) {
|
for (UserInfo item : membersListFull) {
|
||||||
@@ -124,6 +151,7 @@ public class MembersByOrgAdapter extends BaseAdapter implements Filterable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||||
|
|
||||||
membersList.clear();
|
membersList.clear();
|
||||||
membersList.addAll((List) results.values);
|
membersList.addAll((List) results.values);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
|||||||
@@ -2,9 +2,6 @@ package org.mian.gitnex.adapters;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.text.Spanned;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -13,40 +10,24 @@ import android.widget.ImageView;
|
|||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||||
import com.vdurmont.emoji.EmojiParser;
|
import com.vdurmont.emoji.EmojiParser;
|
||||||
|
import org.gitnex.tea4j.models.Milestones;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
import org.mian.gitnex.actions.MilestoneActions;
|
import org.mian.gitnex.actions.MilestoneActions;
|
||||||
import org.mian.gitnex.helpers.ClickListener;
|
import org.mian.gitnex.helpers.ClickListener;
|
||||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
import org.mian.gitnex.helpers.Constants;
|
||||||
|
import org.mian.gitnex.helpers.Markdown;
|
||||||
import org.mian.gitnex.helpers.TimeHelper;
|
import org.mian.gitnex.helpers.TimeHelper;
|
||||||
import org.mian.gitnex.helpers.TinyDB;
|
import org.mian.gitnex.helpers.TinyDB;
|
||||||
import org.mian.gitnex.models.Milestones;
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
|
||||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
|
||||||
import io.noties.markwon.Markwon;
|
|
||||||
import io.noties.markwon.core.CorePlugin;
|
|
||||||
import io.noties.markwon.core.MarkwonTheme;
|
|
||||||
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
|
||||||
import io.noties.markwon.ext.tables.TablePlugin;
|
|
||||||
import io.noties.markwon.ext.tasklist.TaskListPlugin;
|
|
||||||
import io.noties.markwon.html.HtmlPlugin;
|
|
||||||
import io.noties.markwon.image.DefaultMediaDecoder;
|
|
||||||
import io.noties.markwon.image.ImageItem;
|
|
||||||
import io.noties.markwon.image.ImagesPlugin;
|
|
||||||
import io.noties.markwon.image.SchemeHandler;
|
|
||||||
import io.noties.markwon.image.gif.GifMediaDecoder;
|
|
||||||
import io.noties.markwon.image.svg.SvgMediaDecoder;
|
|
||||||
import io.noties.markwon.linkify.LinkifyPlugin;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
@@ -54,19 +35,17 @@ import io.noties.markwon.linkify.LinkifyPlugin;
|
|||||||
|
|
||||||
public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
private Context context;
|
private final Context context;
|
||||||
private final int TYPE_LOAD = 0;
|
private final int TYPE_LOAD = 0;
|
||||||
private List<Milestones> dataList;
|
private List<Milestones> dataList;
|
||||||
private OnLoadMoreListener loadMoreListener;
|
private OnLoadMoreListener loadMoreListener;
|
||||||
private boolean isLoading = false;
|
private boolean isLoading = false;
|
||||||
private boolean isMoreDataAvailable = true;
|
private boolean isMoreDataAvailable = true;
|
||||||
private String TAG = StaticGlobalVariables.tagMilestonesAdapter;
|
|
||||||
|
|
||||||
public MilestonesAdapter(Context context, List<Milestones> dataListMain) {
|
public MilestonesAdapter(Context ctx, List<Milestones> dataListMain) {
|
||||||
|
|
||||||
this.context = context;
|
this.context = ctx;
|
||||||
this.dataList = dataListMain;
|
this.dataList = dataListMain;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -81,7 +60,6 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
else {
|
else {
|
||||||
return new MilestonesAdapter.LoadHolder(inflater.inflate(R.layout.row_load, parent, false));
|
return new MilestonesAdapter.LoadHolder(inflater.inflate(R.layout.row_load, parent, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -91,33 +69,29 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
|
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
loadMoreListener.onLoadMore();
|
loadMoreListener.onLoadMore();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getItemViewType(position) == TYPE_LOAD) {
|
if(getItemViewType(position) == TYPE_LOAD) {
|
||||||
|
|
||||||
((MilestonesAdapter.DataHolder) holder).bindData(dataList.get(position));
|
((MilestonesAdapter.DataHolder) holder).bindData(dataList.get(position));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class DataHolder extends RecyclerView.ViewHolder {
|
class DataHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private TextView milestoneId;
|
private Milestones milestones;
|
||||||
private TextView msTitle;
|
|
||||||
private TextView msDescription;
|
private final TextView msTitle;
|
||||||
private TextView msOpenIssues;
|
private final TextView msDescription;
|
||||||
private TextView msClosedIssues;
|
private final TextView msOpenIssues;
|
||||||
private TextView msDueDate;
|
private final TextView msClosedIssues;
|
||||||
private ProgressBar msProgress;
|
private final TextView msDueDate;
|
||||||
private TextView milestoneStatus;
|
private final ProgressBar msProgress;
|
||||||
|
|
||||||
DataHolder(View itemView) {
|
DataHolder(View itemView) {
|
||||||
|
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
|
||||||
milestoneId = itemView.findViewById(R.id.milestoneId);
|
|
||||||
msTitle = itemView.findViewById(R.id.milestoneTitle);
|
msTitle = itemView.findViewById(R.id.milestoneTitle);
|
||||||
msDescription = itemView.findViewById(R.id.milestoneDescription);
|
msDescription = itemView.findViewById(R.id.milestoneDescription);
|
||||||
msOpenIssues = itemView.findViewById(R.id.milestoneIssuesOpen);
|
msOpenIssues = itemView.findViewById(R.id.milestoneIssuesOpen);
|
||||||
@@ -125,12 +99,11 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
msDueDate = itemView.findViewById(R.id.milestoneDueDate);
|
msDueDate = itemView.findViewById(R.id.milestoneDueDate);
|
||||||
msProgress = itemView.findViewById(R.id.milestoneProgress);
|
msProgress = itemView.findViewById(R.id.milestoneProgress);
|
||||||
ImageView milestonesMenu = itemView.findViewById(R.id.milestonesMenu);
|
ImageView milestonesMenu = itemView.findViewById(R.id.milestonesMenu);
|
||||||
milestoneStatus = itemView.findViewById(R.id.milestoneStatus);
|
|
||||||
|
|
||||||
milestonesMenu.setOnClickListener(v -> {
|
milestonesMenu.setOnClickListener(v -> {
|
||||||
|
|
||||||
Context ctx = v.getContext();
|
Context ctx = v.getContext();
|
||||||
int milestoneId_ = Integer.parseInt(milestoneId.getText().toString());
|
int milestoneId_ = Integer.parseInt(String.valueOf(milestones.getId()));
|
||||||
|
|
||||||
@SuppressLint("InflateParams") View view = LayoutInflater.from(ctx).inflate(R.layout.bottom_sheet_milestones_in_list, null);
|
@SuppressLint("InflateParams") View view = LayoutInflater.from(ctx).inflate(R.layout.bottom_sheet_milestones_in_list, null);
|
||||||
|
|
||||||
@@ -141,17 +114,15 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
dialog.setContentView(view);
|
dialog.setContentView(view);
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
if(milestoneStatus.getText().toString().equals("open")) {
|
if(milestones.getState().equals("open")) {
|
||||||
|
|
||||||
closeMilestone.setVisibility(View.VISIBLE);
|
closeMilestone.setVisibility(View.VISIBLE);
|
||||||
openMilestone.setVisibility(View.GONE);
|
openMilestone.setVisibility(View.GONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
closeMilestone.setVisibility(View.GONE);
|
closeMilestone.setVisibility(View.GONE);
|
||||||
openMilestone.setVisibility(View.VISIBLE);
|
openMilestone.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closeMilestone.setOnClickListener(v12 -> {
|
closeMilestone.setOnClickListener(v12 -> {
|
||||||
@@ -159,7 +130,6 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
MilestoneActions.closeMilestone(ctx, milestoneId_);
|
MilestoneActions.closeMilestone(ctx, milestoneId_);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
updateAdapter(getAdapterPosition());
|
updateAdapter(getAdapterPosition());
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
openMilestone.setOnClickListener(v12 -> {
|
openMilestone.setOnClickListener(v12 -> {
|
||||||
@@ -167,7 +137,6 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
MilestoneActions.openMilestone(ctx, milestoneId_);
|
MilestoneActions.openMilestone(ctx, milestoneId_);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
updateAdapter(getAdapterPosition());
|
updateAdapter(getAdapterPosition());
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -177,71 +146,16 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
void bindData(Milestones dataModel) {
|
void bindData(Milestones dataModel) {
|
||||||
|
|
||||||
final TinyDB tinyDb = new TinyDB(context);
|
this.milestones = dataModel;
|
||||||
final String locale = tinyDb.getString("locale");
|
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||||
|
final String locale = context.getResources().getConfiguration().locale.getLanguage();
|
||||||
final String timeFormat = tinyDb.getString("dateFormat");
|
final String timeFormat = tinyDb.getString("dateFormat");
|
||||||
|
|
||||||
milestoneId.setText(String.valueOf(dataModel.getId()));
|
Markdown.render(context, dataModel.getTitle(), msTitle);
|
||||||
milestoneStatus.setText(dataModel.getState());
|
|
||||||
|
|
||||||
Markwon markwon = Markwon.builder(Objects.requireNonNull(context)).usePlugin(CorePlugin.create()).usePlugin(ImagesPlugin.create(plugin -> {
|
|
||||||
plugin.addSchemeHandler(new SchemeHandler() {
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
|
|
||||||
|
|
||||||
final int resourceId = context.getResources().getIdentifier(
|
|
||||||
raw.substring("drawable://".length()),
|
|
||||||
"drawable",
|
|
||||||
context.getPackageName());
|
|
||||||
|
|
||||||
final Drawable drawable = context.getDrawable(resourceId);
|
|
||||||
|
|
||||||
assert drawable != null;
|
|
||||||
return ImageItem.withResult(drawable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Collection<String> supportedSchemes() {
|
|
||||||
return Collections.singleton("drawable");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
plugin.placeholderProvider(drawable -> null);
|
|
||||||
plugin.addMediaDecoder(GifMediaDecoder.create(false));
|
|
||||||
plugin.addMediaDecoder(SvgMediaDecoder.create(context.getResources()));
|
|
||||||
plugin.addMediaDecoder(SvgMediaDecoder.create());
|
|
||||||
plugin.defaultMediaDecoder(DefaultMediaDecoder.create(context.getResources()));
|
|
||||||
plugin.defaultMediaDecoder(DefaultMediaDecoder.create());
|
|
||||||
|
|
||||||
}))
|
|
||||||
|
|
||||||
.usePlugin(new AbstractMarkwonPlugin() {
|
|
||||||
@Override
|
|
||||||
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
|
|
||||||
builder
|
|
||||||
.codeTextColor(tinyDb.getInt("codeBlockColor"))
|
|
||||||
.codeBackgroundColor(tinyDb.getInt("codeBlockBackground"))
|
|
||||||
.linkColor(context.getResources().getColor(R.color.lightBlue));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.usePlugin(TablePlugin.create(context))
|
|
||||||
.usePlugin(TaskListPlugin.create(context))
|
|
||||||
.usePlugin(HtmlPlugin.create())
|
|
||||||
.usePlugin(StrikethroughPlugin.create())
|
|
||||||
.usePlugin(LinkifyPlugin.create())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Spanned msTitle_ = markwon.toMarkdown(dataModel.getTitle());
|
|
||||||
markwon.setParsedMarkdown(msTitle, msTitle_);
|
|
||||||
|
|
||||||
if(!dataModel.getDescription().equals("")) {
|
if(!dataModel.getDescription().equals("")) {
|
||||||
|
|
||||||
CharSequence bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(dataModel.getDescription()));
|
Markdown.render(context, EmojiParser.parseToUnicode(dataModel.getDescription()), msDescription);
|
||||||
msDescription.setText(bodyWithMD);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
@@ -257,14 +171,12 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
|
|
||||||
msProgress.setProgress(100);
|
msProgress.setProgress(100);
|
||||||
msProgress.setOnClickListener(new ClickListener(context.getResources().getString(R.string.milestoneCompletion, 100), context));
|
msProgress.setOnClickListener(new ClickListener(context.getResources().getString(R.string.milestoneCompletion, 100), context));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
int msCompletion = 100 * dataModel.getClosed_issues() / (dataModel.getOpen_issues() + dataModel.getClosed_issues());
|
int msCompletion = 100 * dataModel.getClosed_issues() / (dataModel.getOpen_issues() + dataModel.getClosed_issues());
|
||||||
msProgress.setOnClickListener(new ClickListener(context.getResources().getString(R.string.milestoneCompletion, msCompletion), context));
|
msProgress.setOnClickListener(new ClickListener(context.getResources().getString(R.string.milestoneCompletion, msCompletion), context));
|
||||||
msProgress.setProgress(msCompletion);
|
msProgress.setProgress(msCompletion);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -272,11 +184,11 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
|
|
||||||
msProgress.setProgress(0);
|
msProgress.setProgress(0);
|
||||||
msProgress.setOnClickListener(new ClickListener(context.getResources().getString(R.string.milestoneCompletion, 0), context));
|
msProgress.setOnClickListener(new ClickListener(context.getResources().getString(R.string.milestoneCompletion, 0), context));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dataModel.getDue_on() != null) {
|
if(dataModel.getDue_on() != null) {
|
||||||
|
|
||||||
|
String TAG = Constants.tagMilestonesAdapter;
|
||||||
if(timeFormat.equals("normal") || timeFormat.equals("pretty")) {
|
if(timeFormat.equals("normal") || timeFormat.equals("pretty")) {
|
||||||
|
|
||||||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", new Locale(locale));
|
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", new Locale(locale));
|
||||||
@@ -293,12 +205,11 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
String dueDate = formatter.format(date);
|
String dueDate = formatter.format(date);
|
||||||
|
|
||||||
if(date.before(new Date())) {
|
if(date.before(new Date())) {
|
||||||
msDueDate.setTextColor(context.getResources().getColor(R.color.darkRed));
|
msDueDate.setTextColor(ResourcesCompat.getColor(context.getResources(), R.color.darkRed, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
msDueDate.setText(dueDate);
|
msDueDate.setText(dueDate);
|
||||||
msDueDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToast(dataModel.getDue_on()), context));
|
msDueDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToast(dataModel.getDue_on()), context));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(timeFormat.equals("normal1")) {
|
else if(timeFormat.equals("normal1")) {
|
||||||
|
|
||||||
@@ -316,7 +227,6 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
assert date1 != null;
|
assert date1 != null;
|
||||||
String dueDate = formatter.format(date1);
|
String dueDate = formatter.format(date1);
|
||||||
msDueDate.setText(dueDate);
|
msDueDate.setText(dueDate);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -334,7 +244,6 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
dataList.remove(position);
|
dataList.remove(position);
|
||||||
notifyItemRemoved(position);
|
notifyItemRemoved(position);
|
||||||
notifyItemRangeChanged(position, dataList.size());
|
notifyItemRangeChanged(position, dataList.size());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -346,14 +255,12 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
else {
|
else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
|
|
||||||
return dataList.size();
|
return dataList.size();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class LoadHolder extends RecyclerView.ViewHolder {
|
static class LoadHolder extends RecyclerView.ViewHolder {
|
||||||
@@ -362,32 +269,27 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
|
|
||||||
super(itemView);
|
super(itemView);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
||||||
|
|
||||||
isMoreDataAvailable = moreDataAvailable;
|
isMoreDataAvailable = moreDataAvailable;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyDataChanged() {
|
public void notifyDataChanged() {
|
||||||
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnLoadMoreListener {
|
public interface OnLoadMoreListener {
|
||||||
|
|
||||||
void onLoadMore();
|
void onLoadMore();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoadMoreListener(OnLoadMoreListener loadMoreListener) {
|
public void setLoadMoreListener(OnLoadMoreListener loadMoreListener) {
|
||||||
|
|
||||||
this.loadMoreListener = loadMoreListener;
|
this.loadMoreListener = loadMoreListener;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateList(List<Milestones> list) {
|
public void updateList(List<Milestones> list) {
|
||||||
|
|||||||
@@ -1,190 +0,0 @@
|
|||||||
package org.mian.gitnex.adapters;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.ColorStateList;
|
|
||||||
import android.graphics.Typeface;
|
|
||||||
import android.text.Spannable;
|
|
||||||
import android.text.SpannableString;
|
|
||||||
import android.text.style.TextAppearanceSpan;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.appcompat.widget.AppCompatCheckBox;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import org.mian.gitnex.R;
|
|
||||||
import org.mian.gitnex.helpers.MultiSelectDialog;
|
|
||||||
import org.mian.gitnex.models.MultiSelectModel;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Author com.github.abumoallim, modified by M M Arif
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class MutliSelectAdapter extends RecyclerView.Adapter<MutliSelectAdapter.MultiSelectDialogViewHolder> {
|
|
||||||
|
|
||||||
private List<MultiSelectModel> mDataSet;
|
|
||||||
private String mSearchQuery = "";
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
public MutliSelectAdapter(List<MultiSelectModel> dataSet, Context context) {
|
|
||||||
this.mDataSet = dataSet;
|
|
||||||
this.mContext = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public MultiSelectDialogViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
||||||
|
|
||||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.multi_select_item, parent, false);
|
|
||||||
return new MultiSelectDialogViewHolder(view);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(@NonNull final MultiSelectDialogViewHolder holder, int position) {
|
|
||||||
|
|
||||||
if (!mSearchQuery.equals("") && mSearchQuery.length() > 1) {
|
|
||||||
setHighlightedText(position, holder.dialog_name_item);
|
|
||||||
} else {
|
|
||||||
holder.dialog_name_item.setText(mDataSet.get(position).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mDataSet.get(position).getSelected()) {
|
|
||||||
|
|
||||||
if (!MultiSelectDialog.selectedIdsForCallback.contains(mDataSet.get(position).getId())) {
|
|
||||||
MultiSelectDialog.selectedIdsForCallback.add(mDataSet.get(position).getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (checkForSelection(mDataSet.get(position).getId())) {
|
|
||||||
holder.dialog_item_checkbox.setChecked(true);
|
|
||||||
} else {
|
|
||||||
holder.dialog_item_checkbox.setChecked(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*holder.dialog_item_checkbox.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
if (holder.dialog_item_checkbox.isChecked()) {
|
|
||||||
MultiSelectDialog.selectedIdsForCallback.add(mDataSet.get(holder.getAdapterPosition()).getId());
|
|
||||||
holder.dialog_item_checkbox.setChecked(true);
|
|
||||||
} else {
|
|
||||||
removeFromSelection(mDataSet.get(holder.getAdapterPosition()).getId());
|
|
||||||
holder.dialog_item_checkbox.setChecked(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
|
|
||||||
holder.main_container.setOnClickListener(new View.OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
if (!holder.dialog_item_checkbox.isChecked()) {
|
|
||||||
MultiSelectDialog.selectedIdsForCallback.add(mDataSet.get(holder.getAdapterPosition()).getId());
|
|
||||||
holder.dialog_item_checkbox.setChecked(true);
|
|
||||||
mDataSet.get(holder.getAdapterPosition()).setSelected(true);
|
|
||||||
notifyItemChanged(holder.getAdapterPosition());
|
|
||||||
} else {
|
|
||||||
removeFromSelection(mDataSet.get(holder.getAdapterPosition()).getId());
|
|
||||||
holder.dialog_item_checkbox.setChecked(false);
|
|
||||||
mDataSet.get(holder.getAdapterPosition()).setSelected(false);
|
|
||||||
notifyItemChanged(holder.getAdapterPosition());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setHighlightedText(int position, TextView textview) {
|
|
||||||
|
|
||||||
String name = mDataSet.get(position).getName();
|
|
||||||
SpannableString str = new SpannableString(name);
|
|
||||||
int endLength = name.toLowerCase().indexOf(mSearchQuery) + mSearchQuery.length();
|
|
||||||
ColorStateList highlightedColor = new ColorStateList(new int[][]{new int[]{}}, new int[]{ContextCompat.getColor(mContext, R.color.colorAccent)});
|
|
||||||
TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(null, Typeface.NORMAL, -1, highlightedColor, null);
|
|
||||||
str.setSpan(textAppearanceSpan, name.toLowerCase().indexOf(mSearchQuery), endLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
textview.setText(str);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeFromSelection(Integer id) {
|
|
||||||
|
|
||||||
for (int i = 0; i < MultiSelectDialog.selectedIdsForCallback.size(); i++) {
|
|
||||||
if (id.equals(MultiSelectDialog.selectedIdsForCallback.get(i))) {
|
|
||||||
MultiSelectDialog.selectedIdsForCallback.remove(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkForSelection(Integer id) {
|
|
||||||
|
|
||||||
for (int i = 0; i < MultiSelectDialog.selectedIdsForCallback.size(); i++) {
|
|
||||||
if (id.equals(MultiSelectDialog.selectedIdsForCallback.get(i))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*//get selected name string separated by coma
|
|
||||||
public String getDataString() {
|
|
||||||
String data = "";
|
|
||||||
for (int i = 0; i < mDataSet.size(); i++) {
|
|
||||||
if (checkForSelection(mDataSet.get(i).getId())) {
|
|
||||||
data = data + ", " + mDataSet.get(i).getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (data.length() > 0) {
|
|
||||||
return data.substring(1);
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//get selected name ararylist
|
|
||||||
public ArrayList<String> getSelectedNameList() {
|
|
||||||
ArrayList<String> names = new ArrayList<>();
|
|
||||||
for (int i = 0; i < mDataSet.size(); i++) {
|
|
||||||
if (checkForSelection(mDataSet.get(i).getId())) {
|
|
||||||
names.add(mDataSet.get(i).getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// return names.toArray(new String[names.size()]);
|
|
||||||
return names;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return mDataSet.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(List<MultiSelectModel> data, String query, MutliSelectAdapter mutliSelectAdapter) {
|
|
||||||
|
|
||||||
this.mDataSet = data;
|
|
||||||
this.mSearchQuery = query;
|
|
||||||
mutliSelectAdapter.notifyDataSetChanged();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class MultiSelectDialogViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
private TextView dialog_name_item;
|
|
||||||
private AppCompatCheckBox dialog_item_checkbox;
|
|
||||||
private LinearLayout main_container;
|
|
||||||
|
|
||||||
MultiSelectDialogViewHolder(View view) {
|
|
||||||
|
|
||||||
super(view);
|
|
||||||
dialog_name_item = view.findViewById(R.id.dialog_item_name);
|
|
||||||
dialog_item_checkbox = view.findViewById(R.id.dialog_item_checkbox);
|
|
||||||
main_container = view.findViewById(R.id.main_container);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,26 +6,27 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import com.amulyakhare.textdrawable.TextDrawable;
|
|
||||||
import org.mian.gitnex.R;
|
|
||||||
import org.mian.gitnex.models.Emails;
|
|
||||||
import java.util.List;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import com.amulyakhare.textdrawable.TextDrawable;
|
||||||
|
import org.gitnex.tea4j.models.Emails;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author M M Arif
|
* Author M M Arif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class ProfileEmailsAdapter extends RecyclerView.Adapter<ProfileEmailsAdapter.EmailsViewHolder> {
|
public class MyProfileEmailsAdapter extends RecyclerView.Adapter<MyProfileEmailsAdapter.EmailsViewHolder> {
|
||||||
|
|
||||||
private List<Emails> emailsList;
|
private final List<Emails> emailsList;
|
||||||
private Context mCtx;
|
private final Context context;
|
||||||
|
|
||||||
static class EmailsViewHolder extends RecyclerView.ViewHolder {
|
static class EmailsViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private ImageView emailPrimary;
|
private final ImageView emailPrimary;
|
||||||
private TextView userEmail;
|
private final TextView userEmail;
|
||||||
|
|
||||||
private EmailsViewHolder(View itemView) {
|
private EmailsViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
@@ -36,20 +37,20 @@ public class ProfileEmailsAdapter extends RecyclerView.Adapter<ProfileEmailsAdap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileEmailsAdapter(Context mCtx, List<Emails> emailsListMain) {
|
public MyProfileEmailsAdapter(Context ctx, List<Emails> emailsListMain) {
|
||||||
this.mCtx = mCtx;
|
this.context = ctx;
|
||||||
this.emailsList = emailsListMain;
|
this.emailsList = emailsListMain;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ProfileEmailsAdapter.EmailsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public MyProfileEmailsAdapter.EmailsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_profile_emails, parent, false);
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_profile_emails, parent, false);
|
||||||
return new ProfileEmailsAdapter.EmailsViewHolder(v);
|
return new MyProfileEmailsAdapter.EmailsViewHolder(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ProfileEmailsAdapter.EmailsViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull MyProfileEmailsAdapter.EmailsViewHolder holder, int position) {
|
||||||
|
|
||||||
Emails currentItem = emailsList.get(position);
|
Emails currentItem = emailsList.get(position);
|
||||||
|
|
||||||
@@ -58,12 +59,12 @@ public class ProfileEmailsAdapter extends RecyclerView.Adapter<ProfileEmailsAdap
|
|||||||
if(currentItem.getPrimary()) {
|
if(currentItem.getPrimary()) {
|
||||||
TextDrawable drawable = TextDrawable.builder()
|
TextDrawable drawable = TextDrawable.builder()
|
||||||
.beginConfig()
|
.beginConfig()
|
||||||
.textColor(mCtx.getResources().getColor(R.color.colorWhite))
|
.textColor(ResourcesCompat.getColor(context.getResources(), R.color.colorWhite, null))
|
||||||
.fontSize(36)
|
.fontSize(36)
|
||||||
.width(220)
|
.width(220)
|
||||||
.height(60)
|
.height(60)
|
||||||
.endConfig()
|
.endConfig()
|
||||||
.buildRoundRect(mCtx.getResources().getString(R.string.emailTypeText), mCtx.getResources().getColor(R.color.tooltipBackground), 8);
|
.buildRoundRect(context.getResources().getString(R.string.emailTypeText), ResourcesCompat.getColor(context.getResources(), R.color.tooltipBackground, null), 8);
|
||||||
holder.emailPrimary.setImageDrawable(drawable);
|
holder.emailPrimary.setImageDrawable(drawable);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package org.mian.gitnex.adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import org.gitnex.tea4j.models.UserInfo;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.activities.ProfileActivity;
|
||||||
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class MyProfileFollowersAdapter extends RecyclerView.Adapter<MyProfileFollowersAdapter.FollowersViewHolder> {
|
||||||
|
|
||||||
|
private final List<UserInfo> followersList;
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
class FollowersViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
private String userLoginId;
|
||||||
|
|
||||||
|
private final ImageView userAvatar;
|
||||||
|
private final TextView userFullName;
|
||||||
|
private final TextView userName;
|
||||||
|
|
||||||
|
private FollowersViewHolder(View itemView) {
|
||||||
|
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
userAvatar = itemView.findViewById(R.id.userAvatar);
|
||||||
|
userFullName = itemView.findViewById(R.id.userFullName);
|
||||||
|
userName = itemView.findViewById(R.id.userName);
|
||||||
|
|
||||||
|
itemView.setOnClickListener(loginId -> {
|
||||||
|
Intent intent = new Intent(context, ProfileActivity.class);
|
||||||
|
intent.putExtra("username", userLoginId);
|
||||||
|
context.startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
|
itemView.setOnLongClickListener(loginId -> {
|
||||||
|
AppUtil.copyToClipboard(context, userLoginId, context.getString(R.string.copyLoginIdToClipBoard, userLoginId));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MyProfileFollowersAdapter(Context ctx, List<UserInfo> followersListMain) {
|
||||||
|
|
||||||
|
this.context = ctx;
|
||||||
|
this.followersList = followersListMain;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public MyProfileFollowersAdapter.FollowersViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_profile_followers_following, parent, false);
|
||||||
|
return new FollowersViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull MyProfileFollowersAdapter.FollowersViewHolder holder, int position) {
|
||||||
|
|
||||||
|
UserInfo currentItem = followersList.get(position);
|
||||||
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||||
|
|
||||||
|
holder.userLoginId = currentItem.getLogin();
|
||||||
|
|
||||||
|
if(!currentItem.getFullname().equals("")) {
|
||||||
|
holder.userFullName.setText(Html.fromHtml(currentItem.getFullname()));
|
||||||
|
holder.userName.setText(context.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
holder.userFullName.setText(currentItem.getUsername());
|
||||||
|
holder.userName.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
PicassoService.getInstance(context).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop().into(holder.userAvatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return followersList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package org.mian.gitnex.adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import org.gitnex.tea4j.models.UserInfo;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.activities.ProfileActivity;
|
||||||
|
import org.mian.gitnex.clients.PicassoService;
|
||||||
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
|
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class MyProfileFollowingAdapter extends RecyclerView.Adapter<MyProfileFollowingAdapter.FollowingViewHolder> {
|
||||||
|
|
||||||
|
private final List<UserInfo> followingList;
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
class FollowingViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
private String userLoginId;
|
||||||
|
|
||||||
|
private final ImageView userAvatar;
|
||||||
|
private final TextView userFullName;
|
||||||
|
private final TextView userName;
|
||||||
|
|
||||||
|
private FollowingViewHolder(View itemView) {
|
||||||
|
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
userAvatar = itemView.findViewById(R.id.userAvatar);
|
||||||
|
userFullName = itemView.findViewById(R.id.userFullName);
|
||||||
|
userName = itemView.findViewById(R.id.userName);
|
||||||
|
|
||||||
|
itemView.setOnClickListener(loginId -> {
|
||||||
|
Intent intent = new Intent(context, ProfileActivity.class);
|
||||||
|
intent.putExtra("username", userLoginId);
|
||||||
|
context.startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
|
itemView.setOnLongClickListener(loginId -> {
|
||||||
|
AppUtil.copyToClipboard(context, userLoginId, context.getString(R.string.copyLoginIdToClipBoard, userLoginId));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MyProfileFollowingAdapter(Context ctx, List<UserInfo> followingListMain) {
|
||||||
|
|
||||||
|
this.context = ctx;
|
||||||
|
this.followingList = followingListMain;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public MyProfileFollowingAdapter.FollowingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_profile_followers_following, parent, false);
|
||||||
|
return new FollowingViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull MyProfileFollowingAdapter.FollowingViewHolder holder, int position) {
|
||||||
|
|
||||||
|
UserInfo currentItem = followingList.get(position);
|
||||||
|
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||||
|
|
||||||
|
holder.userLoginId = currentItem.getLogin();
|
||||||
|
|
||||||
|
if(!currentItem.getFullname().equals("")) {
|
||||||
|
holder.userFullName.setText(Html.fromHtml(currentItem.getFullname()));
|
||||||
|
holder.userName.setText(context.getResources().getString(R.string.usernameWithAt, currentItem.getUsername()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
holder.userFullName.setText(currentItem.getUsername());
|
||||||
|
holder.userName.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
PicassoService.getInstance(context).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop().into(holder.userAvatar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return followingList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user