Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1b8044aa0 | ||
|
|
a92d1ee5ff | ||
|
|
663c0beda5 | ||
|
|
eedb5008bb | ||
|
|
29a0c138c7 | ||
|
|
0976f7abe2 | ||
|
|
f7d886037a | ||
|
|
c9c0ae9e46 | ||
|
|
e02b9adf8a | ||
|
|
fdb4489e38 | ||
|
|
130503a6e3 | ||
|
|
af924761b7 | ||
|
|
e7cd9ce6bc | ||
|
|
ddd7b901da | ||
|
|
0a062ea937 | ||
|
|
ef1aaead0c | ||
|
|
8f1d7b5b95 | ||
|
|
774beec484 | ||
|
|
6b6e7c7f2c | ||
|
|
4c547c2de2 | ||
|
|
d1bd1dd16e | ||
|
|
a514ad81a0 | ||
|
|
ed229267d2 | ||
|
|
080dc4047f | ||
|
|
f744a2351d | ||
|
|
7d14c90b7d | ||
|
|
6c8d52119f | ||
|
|
76c20b22db | ||
|
|
3bba95365c | ||
|
|
81654379f9 | ||
|
|
376ad933fb | ||
|
|
c981833bc1 | ||
|
|
cdf0c97001 | ||
|
|
cb27c7b413 | ||
|
|
49612f91f7 | ||
|
|
919539846f | ||
|
|
17a19bd4be | ||
|
|
0be925f00e | ||
|
|
1000c9b83f | ||
|
|
53710cad77 | ||
|
|
2bd5b1cb27 | ||
|
|
55f11313d8 | ||
|
|
e1bb072588 | ||
|
|
675e6dc4d5 | ||
|
|
3a324f11e6 | ||
|
|
681263cc7f | ||
|
|
10580c9579 | ||
|
|
7a9cf103b4 | ||
|
|
2248911da0 | ||
|
|
e8ca3b9a2a | ||
|
|
3a5baf8a29 | ||
|
|
6fda99a633 | ||
|
|
eed4293c43 | ||
|
|
d6890111bb | ||
|
|
a3487adbdf | ||
|
|
57919b63c7 | ||
|
|
5dfeb14412 | ||
|
|
10b5113299 | ||
|
|
e0c15717f7 | ||
|
|
ed94dfb139 | ||
|
|
623a0e9c59 | ||
|
|
4dc69acc6c | ||
|
|
721f3824df | ||
|
|
907e9f0b26 | ||
|
|
1bf3425ab2 | ||
|
|
933c61d0c9 | ||
|
|
b39d3d4182 | ||
|
|
d852aff107 | ||
|
|
8e97d363fe | ||
|
|
cb6ccbe650 | ||
|
|
37fa5dbf6c | ||
|
|
779b179025 | ||
|
|
121c6c1f23 | ||
|
|
4d040fba86 | ||
|
|
2dfde203c8 | ||
|
|
c5e624f1e2 | ||
|
|
f4684f15c1 | ||
|
|
14cec7d029 | ||
|
|
4fad4403fc | ||
|
|
95c2db021f | ||
|
|
85632d6721 | ||
|
|
1561f1415d | ||
|
|
8cf7ba60b5 | ||
|
|
a8db8ef38f | ||
|
|
7861eb787e | ||
|
|
196b16d1d3 | ||
|
|
4f97110ab3 | ||
|
|
2150295acc | ||
|
|
de0467381c | ||
|
|
5a9d578018 | ||
|
|
75b9fa8551 | ||
|
|
72b9dd069a | ||
|
|
51f48549c3 | ||
|
|
1b1823db0a | ||
|
|
65a2b895f5 | ||
|
|
81bb72344c | ||
|
|
633c82de93 | ||
|
|
e85cf54640 | ||
|
|
9a64fe7aff | ||
|
|
2afbf11f73 | ||
|
|
3b2fd340d3 | ||
|
|
225f133341 | ||
|
|
ef5362f877 | ||
|
|
d7b9d5df07 | ||
|
|
d27dd7c4c6 | ||
|
|
5e8a2b714c | ||
|
|
77c76bd10f | ||
|
|
062151a248 | ||
|
|
9c139e5186 | ||
|
|
ff823480c9 | ||
|
|
a7182dc7ae | ||
|
|
867b3c25d7 | ||
|
|
dd52045b4d | ||
|
|
40ab5cffa1 | ||
|
|
371160b479 | ||
|
|
ce4e1c15f5 | ||
|
|
75650bcfe8 | ||
|
|
2f7597cc68 | ||
|
|
d31a83c426 | ||
|
|
b630abe052 | ||
|
|
07a2106d45 | ||
|
|
cbfa9ff6cb | ||
|
|
6db7c79962 | ||
|
|
21f2ce7425 | ||
|
|
8ba7eb619e | ||
|
|
7140340c59 | ||
|
|
360f9dab90 | ||
|
|
86ebd24f2d | ||
|
|
99d6c1c5fd | ||
|
|
a04f52915a | ||
|
|
0de60103b1 | ||
|
|
94dfdd88a6 | ||
|
|
33d5826337 | ||
|
|
b65fd5bd46 | ||
|
|
6d3c96c8f3 | ||
|
|
fbb3a339bc | ||
|
|
5d9d094f42 | ||
|
|
49a93485c4 | ||
|
|
a2487ff457 | ||
|
|
b633ebd86b | ||
|
|
77ab8116cc | ||
|
|
75ce22d2db | ||
|
|
9801bbef76 | ||
|
|
45ef15cd66 | ||
|
|
36eaee63b6 | ||
|
|
6bd0fd9eb6 | ||
|
|
5adef2978a | ||
|
|
9016b98cb1 | ||
|
|
389b0efe14 | ||
|
|
b0ac12f933 | ||
|
|
d968dc20b3 | ||
|
|
e9734ffb00 | ||
|
|
89eaa947e1 | ||
|
|
134286eff1 | ||
|
|
fe20249af3 | ||
|
|
af14a5ae95 | ||
|
|
9ed8713503 | ||
|
|
bb83592db3 | ||
|
|
2d3aef36f6 | ||
|
|
74e7b13968 | ||
|
|
df6256edd4 | ||
|
|
5843499d7a | ||
|
|
46c410cad6 | ||
|
|
016fa1373a | ||
|
|
2c1c49076c | ||
|
|
d9f2d996bf | ||
|
|
13f071a721 | ||
|
|
3963a0dec1 | ||
|
|
b417d6eae9 | ||
|
|
561c5f4b94 | ||
|
|
40c2de359f | ||
|
|
2c2a07de46 | ||
|
|
7f00d2b018 | ||
|
|
2b0f55982e | ||
|
|
f53b16a48c | ||
|
|
bfc054f38a | ||
|
|
08ed7a971e | ||
|
|
1bc187ec48 | ||
|
|
93e0fef71b | ||
|
|
cbe99d978e | ||
|
|
0734102c4c | ||
|
|
4e1ef91f8c | ||
|
|
25adbd4f47 | ||
|
|
c3f015b695 | ||
|
|
f0c09bdd7b | ||
|
|
abaecc3bcc | ||
|
|
b12671234a | ||
|
|
5e6beb78ff | ||
|
|
834ad8018a | ||
|
|
84d740c231 | ||
|
|
bbdeec4d9e | ||
|
|
5858f68878 | ||
|
|
c1396fd3b8 | ||
|
|
46f0880b83 | ||
|
|
8b9147ac4a | ||
|
|
4653f10957 | ||
|
|
894b4b0977 | ||
|
|
1a473b6f6e | ||
|
|
fde2de08e0 | ||
|
|
f53e509085 | ||
|
|
d37e0e8254 | ||
|
|
c0e80d5ebd | ||
|
|
f22a7c70b3 | ||
|
|
8a5d4bec67 | ||
|
|
766b7c755a | ||
|
|
6c889e62cb | ||
|
|
7f3ca4fa9f | ||
|
|
e53d40a4e3 | ||
|
|
bf7e13efbf | ||
|
|
7a9e67e788 | ||
|
|
fbfefd5235 | ||
|
|
535624264c | ||
|
|
a7bf4aa581 | ||
|
|
67e2fee514 | ||
|
|
7d2d48f1c6 | ||
|
|
7f47effb34 | ||
|
|
7651a9df83 | ||
|
|
d66a60e6af | ||
|
|
697d660d42 | ||
|
|
c45ae25414 | ||
|
|
14d6e473a3 | ||
|
|
46051694fe | ||
|
|
44793c2ba7 | ||
|
|
9caa4ab460 | ||
|
|
42f5469afc | ||
|
|
0b19e2129d | ||
|
|
796db9d195 | ||
|
|
bc2a0725ac | ||
|
|
78f1289cd5 | ||
|
|
1227572edd | ||
|
|
f8428a0d1f | ||
|
|
5f30815410 | ||
|
|
e568054e94 | ||
|
|
0c051fd72b | ||
|
|
3f1dfed3a8 | ||
|
|
0c7bec049f | ||
|
|
f36ac479a8 | ||
|
|
510c6c26e8 | ||
|
|
909c9606ce | ||
|
|
4923a8efa7 | ||
|
|
3e741eee31 | ||
|
|
99e3843427 | ||
|
|
3996901d7c | ||
|
|
c09264bc0f | ||
|
|
4f7fd16470 | ||
|
|
d19e9e0556 | ||
|
|
56d7169ca2 | ||
|
|
3a77d8071d | ||
|
|
a65b208355 | ||
|
|
0f0173ccf3 | ||
|
|
8c2c38d916 | ||
|
|
4f0bf90433 | ||
|
|
bd01843be7 | ||
|
|
d5fe7679da | ||
|
|
be11180ca9 | ||
|
|
9938f2e421 | ||
|
|
3facd6c200 | ||
|
|
97c53b38ce | ||
|
|
d7febee4fa | ||
|
|
68d6fe5557 | ||
|
|
f782e3d9fd | ||
|
|
1cc383df2a | ||
|
|
84cef3bafc | ||
|
|
de4fc2cd2b | ||
|
|
9b3f00c12d | ||
|
|
26bbfa3538 | ||
|
|
3f62afabf6 | ||
|
|
d178cde220 | ||
|
|
2b26a5176a | ||
|
|
60295480b5 | ||
|
|
020e5a2c3b | ||
|
|
2d82f80e9c | ||
|
|
706ae93a32 | ||
|
|
57ce989a5a | ||
|
|
23fea78a96 | ||
|
|
1dd355ddec | ||
|
|
e1d6842552 | ||
|
|
644b91dce0 | ||
|
|
92ddf10d07 | ||
|
|
a906a14b15 | ||
|
|
66c25fa255 | ||
|
|
6fbe0b5952 | ||
|
|
ad21ad34cd | ||
|
|
f18b9363ad | ||
|
|
ac971ae36d | ||
|
|
a5d0fe9362 | ||
|
|
4ce26101b0 | ||
|
|
55f6aebabf | ||
|
|
c9d3605ec2 | ||
|
|
489b5e0514 | ||
|
|
158d061127 | ||
|
|
a8409b3aa8 | ||
|
|
d93f893b6b | ||
|
|
613c242205 | ||
|
|
edc6198f29 | ||
|
|
0c3c286c0a | ||
|
|
7aab6137be |
No files matched your search
@@ -56,6 +56,8 @@ steps:
|
||||
services:
|
||||
- name: server
|
||||
image: nextcloudci/server:server-17 # also change in updateScreenshots.sh
|
||||
environment:
|
||||
EVAL: true
|
||||
commands:
|
||||
- BRANCH='stable18' /usr/local/bin/initnc.sh
|
||||
- echo 127.0.0.1 server >> /etc/hosts
|
||||
@@ -138,6 +140,8 @@ steps:
|
||||
services:
|
||||
- name: server
|
||||
image: nextcloudci/server:server-17 # also change in updateScreenshots.sh
|
||||
environment:
|
||||
EVAL: true
|
||||
commands:
|
||||
- /usr/local/bin/initnc.sh
|
||||
- echo 127.0.0.1 server >> /etc/hosts
|
||||
@@ -188,7 +192,7 @@ steps:
|
||||
- ./gradlew assembleGplayDebug
|
||||
- scripts/wait_for_emulator.sh
|
||||
- ./gradlew installGplayDebugAndroidTest
|
||||
- ./gradlew gplayDebugExecuteScreenshotTests -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest && scripts/deleteOutdatedComments.sh "stable" "Screenshot" $DRONE_PULL_REQUEST $GIT_USERNAME $GIT_TOKEN || scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "stable" "Screenshot" $DRONE_PULL_REQUEST $GIT_USERNAME $GIT_TOKEN
|
||||
- scripts/runAllScreenshotCombinations "stable" false
|
||||
- name: notify
|
||||
image: drillster/drone-email
|
||||
settings:
|
||||
@@ -243,7 +247,7 @@ steps:
|
||||
- scripts/wait_for_emulator.sh
|
||||
- ./gradlew installGplayDebugAndroidTest
|
||||
- sed -i s"#5#1#" ./src/androidTest/java/com/nextcloud/client/RetryTestRule.kt
|
||||
- ./gradlew gplayDebugExecuteScreenshotTests -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest && scripts/deleteOutdatedComments.sh "master" "Screenshot" $DRONE_PULL_REQUEST $GIT_USERNAME $GIT_TOKEN || scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "master" "Screenshot" $DRONE_PULL_REQUEST $GIT_USERNAME $GIT_TOKEN
|
||||
- scripts/runAllScreenshotCombinations "master" false
|
||||
- name: notify
|
||||
image: drillster/drone-email
|
||||
settings:
|
||||
|
||||
@@ -47,3 +47,5 @@ fastlane/Fastfile
|
||||
|
||||
# scan temporary files
|
||||
**/fastlane/test_output
|
||||
/fastlane/vendor/
|
||||
/.bundle/
|
||||
@@ -379,6 +379,7 @@ Generally, whenever you need:
|
||||
* media playback
|
||||
* networking
|
||||
* logging
|
||||
* notifications management
|
||||
|
||||
we have something more suitable.
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# Autogenerated by fastlane
|
||||
#
|
||||
# Ensure this file is checked in to source control!
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem 'fastlane'
|
||||
|
||||
plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
|
||||
eval_gemfile(plugins_path) if File.exist?(plugins_path)
|
||||
@@ -0,0 +1,180 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
CFPropertyList (3.0.2)
|
||||
addressable (2.7.0)
|
||||
public_suffix (>= 2.0.2, < 5.0)
|
||||
atomos (0.1.3)
|
||||
aws-eventstream (1.1.0)
|
||||
aws-partitions (1.343.0)
|
||||
aws-sdk-core (3.104.1)
|
||||
aws-eventstream (~> 1, >= 1.0.2)
|
||||
aws-partitions (~> 1, >= 1.239.0)
|
||||
aws-sigv4 (~> 1.1)
|
||||
jmespath (~> 1.0)
|
||||
aws-sdk-kms (1.36.0)
|
||||
aws-sdk-core (~> 3, >= 3.99.0)
|
||||
aws-sigv4 (~> 1.1)
|
||||
aws-sdk-s3 (1.75.0)
|
||||
aws-sdk-core (~> 3, >= 3.104.1)
|
||||
aws-sdk-kms (~> 1)
|
||||
aws-sigv4 (~> 1.1)
|
||||
aws-sigv4 (1.2.1)
|
||||
aws-eventstream (~> 1, >= 1.0.2)
|
||||
babosa (1.0.3)
|
||||
claide (1.0.3)
|
||||
colored (1.2)
|
||||
colored2 (3.1.2)
|
||||
commander-fastlane (4.4.6)
|
||||
highline (~> 1.7.2)
|
||||
declarative (0.0.20)
|
||||
declarative-option (0.1.0)
|
||||
digest-crc (0.6.1)
|
||||
rake (~> 13.0)
|
||||
domain_name (0.5.20190701)
|
||||
unf (>= 0.0.5, < 1.0.0)
|
||||
dotenv (2.7.6)
|
||||
emoji_regex (3.0.0)
|
||||
excon (0.75.0)
|
||||
faraday (0.17.3)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
faraday-cookie_jar (0.0.6)
|
||||
faraday (>= 0.7.4)
|
||||
http-cookie (~> 1.0.0)
|
||||
faraday_middleware (0.14.0)
|
||||
faraday (>= 0.7.4, < 1.0)
|
||||
fastimage (2.1.7)
|
||||
fastlane (2.152.0)
|
||||
CFPropertyList (>= 2.3, < 4.0.0)
|
||||
addressable (>= 2.3, < 3.0.0)
|
||||
aws-sdk-s3 (~> 1.0)
|
||||
babosa (>= 1.0.3, < 2.0.0)
|
||||
bundler (>= 1.12.0, < 3.0.0)
|
||||
colored
|
||||
commander-fastlane (>= 4.4.6, < 5.0.0)
|
||||
dotenv (>= 2.1.1, < 3.0.0)
|
||||
emoji_regex (>= 0.1, < 4.0)
|
||||
excon (>= 0.71.0, < 1.0.0)
|
||||
faraday (>= 0.17, < 1.0)
|
||||
faraday-cookie_jar (~> 0.0.6)
|
||||
faraday_middleware (>= 0.13.1, < 2.0)
|
||||
fastimage (>= 2.1.0, < 3.0.0)
|
||||
gh_inspector (>= 1.1.2, < 2.0.0)
|
||||
google-api-client (>= 0.37.0, < 0.39.0)
|
||||
google-cloud-storage (>= 1.15.0, < 2.0.0)
|
||||
highline (>= 1.7.2, < 2.0.0)
|
||||
json (< 3.0.0)
|
||||
jwt (>= 2.1.0, < 3)
|
||||
mini_magick (>= 4.9.4, < 5.0.0)
|
||||
multipart-post (~> 2.0.0)
|
||||
plist (>= 3.1.0, < 4.0.0)
|
||||
rubyzip (>= 2.0.0, < 3.0.0)
|
||||
security (= 0.1.3)
|
||||
simctl (~> 1.6.3)
|
||||
slack-notifier (>= 2.0.0, < 3.0.0)
|
||||
terminal-notifier (>= 2.0.0, < 3.0.0)
|
||||
terminal-table (>= 1.4.5, < 2.0.0)
|
||||
tty-screen (>= 0.6.3, < 1.0.0)
|
||||
tty-spinner (>= 0.8.0, < 1.0.0)
|
||||
word_wrap (~> 1.0.0)
|
||||
xcodeproj (>= 1.13.0, < 2.0.0)
|
||||
xcpretty (~> 0.3.0)
|
||||
xcpretty-travis-formatter (>= 0.0.3)
|
||||
fastlane-plugin-huawei_appgallery_connect (1.0.9)
|
||||
gh_inspector (1.1.3)
|
||||
google-api-client (0.38.0)
|
||||
addressable (~> 2.5, >= 2.5.1)
|
||||
googleauth (~> 0.9)
|
||||
httpclient (>= 2.8.1, < 3.0)
|
||||
mini_mime (~> 1.0)
|
||||
representable (~> 3.0)
|
||||
retriable (>= 2.0, < 4.0)
|
||||
signet (~> 0.12)
|
||||
google-cloud-core (1.5.0)
|
||||
google-cloud-env (~> 1.0)
|
||||
google-cloud-errors (~> 1.0)
|
||||
google-cloud-env (1.3.3)
|
||||
faraday (>= 0.17.3, < 2.0)
|
||||
google-cloud-errors (1.0.1)
|
||||
google-cloud-storage (1.26.2)
|
||||
addressable (~> 2.5)
|
||||
digest-crc (~> 0.4)
|
||||
google-api-client (~> 0.33)
|
||||
google-cloud-core (~> 1.2)
|
||||
googleauth (~> 0.9)
|
||||
mini_mime (~> 1.0)
|
||||
googleauth (0.13.0)
|
||||
faraday (>= 0.17.3, < 2.0)
|
||||
jwt (>= 1.4, < 3.0)
|
||||
memoist (~> 0.16)
|
||||
multi_json (~> 1.11)
|
||||
os (>= 0.9, < 2.0)
|
||||
signet (~> 0.14)
|
||||
highline (1.7.10)
|
||||
http-cookie (1.0.3)
|
||||
domain_name (~> 0.5)
|
||||
httpclient (2.8.3)
|
||||
jmespath (1.4.0)
|
||||
json (2.3.1)
|
||||
jwt (2.2.1)
|
||||
memoist (0.16.2)
|
||||
mini_magick (4.10.1)
|
||||
mini_mime (1.0.2)
|
||||
multi_json (1.15.0)
|
||||
multipart-post (2.0.0)
|
||||
nanaimo (0.3.0)
|
||||
naturally (2.2.0)
|
||||
os (1.1.0)
|
||||
plist (3.5.0)
|
||||
public_suffix (4.0.5)
|
||||
rake (13.0.1)
|
||||
representable (3.0.4)
|
||||
declarative (< 0.1.0)
|
||||
declarative-option (< 0.2.0)
|
||||
uber (< 0.2.0)
|
||||
retriable (3.1.2)
|
||||
rouge (2.0.7)
|
||||
rubyzip (2.3.0)
|
||||
security (0.1.3)
|
||||
signet (0.14.0)
|
||||
addressable (~> 2.3)
|
||||
faraday (>= 0.17.3, < 2.0)
|
||||
jwt (>= 1.5, < 3.0)
|
||||
multi_json (~> 1.10)
|
||||
simctl (1.6.8)
|
||||
CFPropertyList
|
||||
naturally
|
||||
slack-notifier (2.3.2)
|
||||
terminal-notifier (2.0.0)
|
||||
terminal-table (1.8.0)
|
||||
unicode-display_width (~> 1.1, >= 1.1.1)
|
||||
tty-cursor (0.7.1)
|
||||
tty-screen (0.8.1)
|
||||
tty-spinner (0.9.3)
|
||||
tty-cursor (~> 0.7)
|
||||
uber (0.1.0)
|
||||
unf (0.1.4)
|
||||
unf_ext
|
||||
unf_ext (0.0.7.7)
|
||||
unicode-display_width (1.7.0)
|
||||
word_wrap (1.0.0)
|
||||
xcodeproj (1.17.1)
|
||||
CFPropertyList (>= 2.3.3, < 4.0)
|
||||
atomos (~> 0.1.3)
|
||||
claide (>= 1.0.2, < 2.0)
|
||||
colored2 (~> 3.1)
|
||||
nanaimo (~> 0.3.0)
|
||||
xcpretty (0.3.0)
|
||||
rouge (~> 2.0.7)
|
||||
xcpretty-travis-formatter (1.0.0)
|
||||
xcpretty (~> 0.2, >= 0.0.7)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
fastlane
|
||||
fastlane-plugin-huawei_appgallery_connect
|
||||
|
||||
BUNDLED WITH
|
||||
2.1.4
|
||||
@@ -59,10 +59,10 @@ configurations {
|
||||
|
||||
ext {
|
||||
jacocoVersion = "0.8.2"
|
||||
daggerVersion = "2.28.1"
|
||||
daggerVersion = "2.28.3"
|
||||
markwonVersion = "4.4.0"
|
||||
prismVersion = "2.0.0"
|
||||
androidLibraryVersion = "master-SNAPSHOT"
|
||||
androidLibraryVersion ="b313e2708597dfbcc1733277450d23831821f649"
|
||||
|
||||
travisBuild = System.getenv("TRAVIS") == "true"
|
||||
|
||||
@@ -171,8 +171,8 @@ android {
|
||||
versionDev {
|
||||
applicationId "com.nextcloud.android.beta"
|
||||
dimension "default"
|
||||
versionCode 20200129
|
||||
versionName "20200129"
|
||||
versionCode 20200730
|
||||
versionName "20200730"
|
||||
}
|
||||
|
||||
qa {
|
||||
@@ -293,8 +293,8 @@ dependencies {
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
implementation 'androidx.exifinterface:exifinterface:1.2.0'
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
|
||||
implementation "androidx.work:work-runtime:2.3.4"
|
||||
implementation "androidx.work:work-runtime-ktx:2.3.4"
|
||||
implementation "androidx.work:work-runtime:2.4.0"
|
||||
implementation "androidx.work:work-runtime-ktx:2.4.0"
|
||||
implementation "androidx.fragment:fragment:1.2.5"
|
||||
implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
|
||||
compileOnly 'com.google.code.findbugs:annotations:2.0.1'
|
||||
@@ -320,7 +320,8 @@ dependencies {
|
||||
implementation 'androidx.annotation:annotation:1.1.0'
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
|
||||
implementation 'com.github.cotechde.hwsecurity:hwsecurity-fido:2.5.1'
|
||||
implementation 'com.github.cotechde.hwsecurity:hwsecurity-fido:4.1.0'
|
||||
implementation 'com.github.cotechde.hwsecurity:hwsecurity-fido2:4.1.0'
|
||||
|
||||
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1'
|
||||
spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
|
||||
@@ -350,14 +351,16 @@ dependencies {
|
||||
|
||||
// dependencies for local unit tests
|
||||
testImplementation 'junit:junit:4.13'
|
||||
testImplementation 'org.mockito:mockito-core:3.4.2'
|
||||
testImplementation 'org.mockito:mockito-core:3.4.4'
|
||||
testImplementation 'androidx.test:core:1.2.0'
|
||||
testImplementation 'org.powermock:powermock-core:2.0.7'
|
||||
testImplementation 'org.powermock:powermock-module-junit4:2.0.7'
|
||||
testImplementation 'org.powermock:powermock-api-mockito2:2.0.7'
|
||||
testImplementation 'org.json:json:20200518'
|
||||
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
|
||||
testImplementation "androidx.arch.core:core-testing:2.1.0"
|
||||
testImplementation 'androidx.arch.core:core-testing:2.1.0'
|
||||
testImplementation 'io.mockk:mockk:1.10.0'
|
||||
testImplementation 'io.mockk:mockk-android:1.10.0'
|
||||
|
||||
// dependencies for instrumented tests
|
||||
// JUnit4 Rules
|
||||
@@ -370,7 +373,20 @@ dependencies {
|
||||
// Espresso core
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
|
||||
androidTestImplementation 'org.mockito:mockito-core:3.4.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
|
||||
|
||||
// Mocking support
|
||||
androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
|
||||
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
|
||||
androidTestImplementation 'org.mockito:mockito-core:3.4.4'
|
||||
androidTestImplementation("org.mockito:mockito-android:3.4.4") {
|
||||
exclude group: "net.bytebuddy", module: "byte-buddy-android"
|
||||
}
|
||||
androidTestImplementation 'net.bytebuddy:byte-buddy:1.10.13'
|
||||
androidTestImplementation "net.bytebuddy:byte-buddy-android:1.10.13"
|
||||
androidTestImplementation "io.mockk:mockk-android:1.10.0"
|
||||
androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'
|
||||
|
||||
// UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
|
||||
// androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
|
||||
// fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
|
||||
@@ -388,9 +404,6 @@ dependencies {
|
||||
// androidJacocoAnt "org.jacoco:org.jacoco.agent:${jacocoVersion}"
|
||||
|
||||
implementation "com.github.stateless4j:stateless4j:2.6.0"
|
||||
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
|
||||
androidTestImplementation "org.mockito:mockito-android:3.4.2"
|
||||
androidTestImplementation 'net.bytebuddy:byte-buddy:1.10.13'
|
||||
}
|
||||
|
||||
spotbugs {
|
||||
|
||||
@@ -83,14 +83,14 @@ complexity:
|
||||
ignoreStringsRegex: '$^'
|
||||
TooManyFunctions:
|
||||
active: true
|
||||
thresholdInFiles: 11
|
||||
thresholdInClasses: 11
|
||||
thresholdInInterfaces: 11
|
||||
thresholdInObjects: 11
|
||||
thresholdInFiles: 15
|
||||
thresholdInClasses: 15
|
||||
thresholdInInterfaces: 15
|
||||
thresholdInObjects: 15
|
||||
thresholdInEnums: 11
|
||||
ignoreDeprecated: false
|
||||
ignoreDeprecated: true
|
||||
ignorePrivate: false
|
||||
ignoreOverridden: false
|
||||
ignoreOverridden: true
|
||||
|
||||
empty-blocks:
|
||||
active: true
|
||||
|
||||
@@ -8,6 +8,9 @@ fastlane_version "2.58.0"
|
||||
# export FASTLANE_NEXTCLOUD_KEY_ALIAS=""
|
||||
# export FASTLANE_NEXTCLOUD_KEY_PASSWORD=""
|
||||
# export FASTLANE_NEXTCLOUD_GITHUB_API_TOKEN=""
|
||||
# export FASTLANE_NEXTCLOUD_HUAWEI_CLIENT_ID=""
|
||||
# export FASTLANE_NEXTCLOUD_HUAWEI_CLIENT_SECRET=""
|
||||
# export FASTLANE_NEXTCLOUD_HUAWEI_APP_ID=""
|
||||
|
||||
skip_docs
|
||||
|
||||
@@ -70,6 +73,7 @@ lane :releasePhase2_Final do |options|
|
||||
checkIfAPKexists()
|
||||
tag(info)
|
||||
uploadToPlaystore_Final(info)
|
||||
uploadToHuawei_Final(info)
|
||||
createGithubRelease_Final(info)
|
||||
fdroidMergeRequest_Final(info)
|
||||
createChangelogPullRequest_Final(info)
|
||||
@@ -116,6 +120,19 @@ lane :beautifyPhone do
|
||||
sh("adb shell am broadcast -a com.android.systemui.demo -e command battery -e plugged false -e level 100")
|
||||
end
|
||||
|
||||
# to install
|
||||
# bundle exec fastlane add_plugin huawei_appgallery_connect
|
||||
# bundle install --path build/vendor/bundle
|
||||
private_lane :uploadToHuawei_Final do |options|
|
||||
huawei_appgallery_connect(
|
||||
client_id: ENV["FASTLANE_NEXTCLOUD_HUAWEI_CLIENT_ID"],
|
||||
client_secret: ENV["FASTLANE_NEXTCLOUD_HUAWEI_CLIENT_SECRET"],
|
||||
app_id: ENV["FASTLANE_NEXTCLOUD_HUAWEI_APP_ID"],
|
||||
apk_path: "release/nextcloud-" + options["versionCode"] + ".apk",
|
||||
submit_for_review: true,
|
||||
)
|
||||
end
|
||||
|
||||
## private lanes
|
||||
|
||||
desc "Build debug and test APK for screenshots"
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
# Autogenerated by fastlane
|
||||
#
|
||||
# Ensure this file is checked in to source control!
|
||||
|
||||
gem 'fastlane-plugin-huawei_appgallery_connect'
|
||||
gem 'fastlane-plugin-huawei_appgallery_connect'
|
||||
@@ -58,8 +58,8 @@
|
||||
|
||||
<issue id="ObsoleteLintCustomCheck" severity="warning">
|
||||
<ignore path="**/fragment-1.2.5/**/lint.jar" />
|
||||
<ignore path="**/work-runtime-2.3.4/**/lint.jar" />
|
||||
<ignore path="**/work-runtime-2.**/**/lint.jar" />
|
||||
<ignore path="**/jetified-butterknife-runtime-10.2.1/**/lint.jar" />
|
||||
<ignore path="**/jetified-dagger-lint-aar-2.28.1/**/lint.jar" />
|
||||
<ignore path="**/jetified-dagger-lint-aar-2.28.**/**/lint.jar" />
|
||||
</issue>
|
||||
</lint>
|
||||
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 30 KiB |
@@ -1,2 +1,2 @@
|
||||
DO NOT TOUCH; GENERATED BY DRONE
|
||||
<span class="mdl-layout-title">Lint Report: 83 warnings</span>
|
||||
<span class="mdl-layout-title">Lint Report: 81 warnings</span>
|
||||
@@ -3,7 +3,9 @@
|
||||
if [ $# -lt 2 ]; then
|
||||
echo "1: record: true/false
|
||||
2: class name
|
||||
3: method name"
|
||||
3: method name
|
||||
4: darkMode / \"all\" to run all screenshot combinations
|
||||
5: color"
|
||||
|
||||
exit
|
||||
fi
|
||||
@@ -14,7 +16,12 @@ emulator -writable-system -avd uiComparison -no-snapshot -gpu swiftshader_indire
|
||||
|
||||
cd src/androidTest/java
|
||||
|
||||
class=$(find | grep $2 | grep java | head -n1|sed s'/\//\./'g | sed s'#^\.\.##' | sed s'#\.java##')
|
||||
class=$(find | grep $2 | grep -E "java$|kt$" | head -n1|sed s'/\//\./'g | sed s'#^\.\.##' | sed s'#\.java##'| sed s'#\.kt##')
|
||||
|
||||
if [[ -z $class ]]; then
|
||||
echo "Class not found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd ../../../
|
||||
|
||||
@@ -28,10 +35,35 @@ if [ -e $3 ] ; then
|
||||
method=""
|
||||
else
|
||||
method="#$3"
|
||||
|
||||
# check if method exists
|
||||
if [[ $(grep -c $3 $(find | grep $2 | grep -E "java$|kt$" | head -n1)) -eq 0 ]]; then
|
||||
echo "Method not found!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e $4 ] ; then
|
||||
darkMode=""
|
||||
else
|
||||
darkMode="-Pandroid.testInstrumentationRunnerArguments.DARKMODE=$4"
|
||||
fi
|
||||
|
||||
if [ -e $5 ] ; then
|
||||
color=""
|
||||
else
|
||||
color="-Pandroid.testInstrumentationRunnerArguments.COLOR=$5"
|
||||
fi
|
||||
|
||||
if [[ $4 = "all" ]]; then
|
||||
scripts/runAllScreenshotCombinations "noCI" "$1" "-Pandroid.testInstrumentationRunnerArguments.class=$class$method"
|
||||
else
|
||||
./gradlew gplayDebugExecuteScreenshotTests $record \
|
||||
-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \
|
||||
-Pandroid.testInstrumentationRunnerArguments.class=$class$method \
|
||||
$darkMode \
|
||||
$color
|
||||
fi
|
||||
|
||||
./gradlew gplayDebugExecuteScreenshotTests $record \
|
||||
-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \
|
||||
-Pandroid.testInstrumentationRunnerArguments.class=$class$method
|
||||
|
||||
sed -i s'#<bool name="is_beta">true</bool>#<bool name="is_beta">false</bool>#'g src/main/res/values/setup.xml
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
|
||||
## $1 noCI/stable/master: wether to run deleteOutdatedComments.sh or uploadReport.sh
|
||||
## $2 true/false: record or verify screenshots
|
||||
## $3 classMethod: piped from androidScreenshotTest
|
||||
|
||||
if [[ $2 = "true" ]]; then
|
||||
record="-Precord"
|
||||
else
|
||||
record=""
|
||||
fi
|
||||
|
||||
classMethod=$3
|
||||
|
||||
while read line
|
||||
do
|
||||
darkMode=$(echo "$line" | cut -d" " -f1)
|
||||
color=$(echo "$line" | cut -d" " -f2)
|
||||
|
||||
echo "Run $color on $darkMode mode"
|
||||
|
||||
if [[ $1 = "noCI" ]]; then
|
||||
./gradlew --console plain gplayDebugExecuteScreenshotTests \
|
||||
$record \
|
||||
-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \
|
||||
-Pandroid.testInstrumentationRunnerArguments.COLOR="$color" \
|
||||
-Pandroid.testInstrumentationRunnerArguments.DARKMODE="$darkMode" \
|
||||
$classMethod </dev/null > /dev/null
|
||||
if [[ $? -ne 0 ]]; then
|
||||
exit
|
||||
fi
|
||||
else
|
||||
./gradlew gplayDebugExecuteScreenshotTests \
|
||||
$record \
|
||||
-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest \
|
||||
-Pandroid.testInstrumentationRunnerArguments.COLOR="$color" \
|
||||
-Pandroid.testInstrumentationRunnerArguments.DARKMODE="$darkMode" \
|
||||
&& scripts/deleteOutdatedComments.sh "$1-$darkMode-$color" "Screenshot" "$DRONE_PULL_REQUEST" \
|
||||
"$GIT_USERNAME" "$GIT_TOKEN" \
|
||||
|| scripts/uploadReport.sh "$LOG_USERNAME" "$LOG_PASSWORD" "$DRONE_BUILD_NUMBER" \
|
||||
"$1-$darkMode-$color" "Screenshot" "$DRONE_PULL_REQUEST" "$GIT_USERNAME" "$GIT_TOKEN"
|
||||
fi
|
||||
done < scripts/screenshotCombinations
|
||||
@@ -0,0 +1 @@
|
||||
light blue
|
||||
@@ -25,7 +25,6 @@ package com.nextcloud.client;
|
||||
import android.Manifest;
|
||||
import android.view.View;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.ui.activities.ActivitiesActivity;
|
||||
@@ -60,16 +59,13 @@ public class ActivitiesActivityIT extends AbstractIT {
|
||||
|
||||
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
|
||||
|
||||
sut.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sut.emptyContentContainer.setVisibility(View.VISIBLE);
|
||||
sut.recyclerView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
sut.runOnUiThread(() -> {
|
||||
sut.emptyContentContainer.setVisibility(View.VISIBLE);
|
||||
sut.recyclerView.setVisibility(View.INVISIBLE);
|
||||
});
|
||||
|
||||
waitForIdleSync();
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
screenshot(sut);
|
||||
}
|
||||
}
|
||||
@@ -32,10 +32,13 @@ import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation;
|
||||
import com.owncloud.android.lib.resources.status.OCCapability;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
import com.owncloud.android.lib.resources.users.GetPrivateKeyOperation;
|
||||
import com.owncloud.android.lib.resources.users.GetPublicKeyOperation;
|
||||
import com.owncloud.android.lib.resources.users.SendCSROperation;
|
||||
import com.owncloud.android.lib.resources.users.StorePrivateKeyOperation;
|
||||
import com.owncloud.android.operations.GetCapabilitiesOperation;
|
||||
import com.owncloud.android.operations.RemoveFileOperation;
|
||||
import com.owncloud.android.utils.CsrHelper;
|
||||
import com.owncloud.android.utils.EncryptionUtils;
|
||||
@@ -52,9 +55,11 @@ import java.io.IOException;
|
||||
import java.security.KeyPair;
|
||||
import java.security.PrivateKey;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import static com.owncloud.android.lib.resources.status.OwnCloudVersion.nextcloud_19;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
@@ -80,6 +85,12 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
OCCapability capability = getStorageManager().getCapability(account.name);
|
||||
|
||||
if (capability.getVersion().equals(new OwnCloudVersion("0.0.0"))) {
|
||||
// fetch new one
|
||||
assertTrue(new GetCapabilitiesOperation().execute(client, getStorageManager()).isSuccess());
|
||||
}
|
||||
// tests only for NC19+
|
||||
assumeTrue(getStorageManager()
|
||||
.getCapability(account.name)
|
||||
@@ -282,6 +293,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
|
||||
}
|
||||
|
||||
OCFile fileToDelete = files.get(new Random().nextInt(files.size()));
|
||||
assertNotNull(fileToDelete.getRemoteId());
|
||||
|
||||
Log_OC.d(this,
|
||||
"[" + i + "/" + actionCount + "] " +
|
||||
@@ -395,4 +407,58 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
|
||||
private String generateMnemonicString() {
|
||||
return "1 2 3 4 5 6";
|
||||
}
|
||||
|
||||
public void after() {
|
||||
// remove all encrypted files
|
||||
OCFile root = fileDataStorageManager.getFileByDecryptedRemotePath("/");
|
||||
removeFolder(root);
|
||||
|
||||
// List<OCFile> files = fileDataStorageManager.getFolderContent(root, false);
|
||||
//
|
||||
// for (OCFile child : files) {
|
||||
// removeFolder(child);
|
||||
// }
|
||||
|
||||
assertEquals(0, fileDataStorageManager.getFolderContent(root, false).size());
|
||||
|
||||
super.after();
|
||||
}
|
||||
|
||||
private void removeFolder(OCFile folder) {
|
||||
Log_OC.d(this, "Start removing content of folder: " + folder.getDecryptedRemotePath());
|
||||
|
||||
List<OCFile> children = fileDataStorageManager.getFolderContent(folder, false);
|
||||
|
||||
// remove children
|
||||
for (OCFile child : children) {
|
||||
if (child.isFolder()) {
|
||||
removeFolder(child);
|
||||
|
||||
// remove folder
|
||||
Log_OC.d(this, "Remove folder: " + child.getDecryptedRemotePath());
|
||||
if (!folder.isEncrypted() && child.isEncrypted()) {
|
||||
assertTrue(new ToggleEncryptionRemoteOperation(child.getLocalId(),
|
||||
child.getRemotePath(),
|
||||
false)
|
||||
.execute(client)
|
||||
.isSuccess());
|
||||
|
||||
OCFile f = getStorageManager().getFileByEncryptedRemotePath(child.getRemotePath());
|
||||
f.setEncrypted(false);
|
||||
getStorageManager().saveFile(f);
|
||||
|
||||
child.setEncrypted(false);
|
||||
}
|
||||
} else {
|
||||
Log_OC.d(this, "Remove file: " + child.getDecryptedRemotePath());
|
||||
}
|
||||
|
||||
assertTrue(new RemoveFileOperation(child, false, account, false, targetContext)
|
||||
.execute(client, getStorageManager())
|
||||
.isSuccess()
|
||||
);
|
||||
}
|
||||
|
||||
Log_OC.d(this, "Finished removing content of folder: " + folder.getDecryptedRemotePath());
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ package com.nextcloud.client;
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.owncloud.android.AbstractOnServerIT;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
@@ -126,7 +125,7 @@ public class FileDisplayActivityIT extends AbstractOnServerIT {
|
||||
shortSleep();
|
||||
shortSleep();
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
screenshot(sut);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,7 +24,6 @@ package com.nextcloud.client;
|
||||
|
||||
import android.Manifest;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
@@ -57,7 +56,7 @@ public class FileDisplayActivityScreenshotIT extends AbstractIT {
|
||||
sut.getListOfFilesFragment().setFabEnabled(false);
|
||||
sut.getListOfFilesFragment().setEmptyListLoadingMessage();
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
screenshot(sut);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,6 +69,6 @@ public class FileDisplayActivityScreenshotIT extends AbstractIT {
|
||||
sut.getListOfFilesFragment().setFabEnabled(false);
|
||||
sut.getListOfFilesFragment().setEmptyListLoadingMessage();
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
screenshot(sut);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ package com.nextcloud.client;
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.nextcloud.client.onboarding.FirstRunActivity;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.utils.ScreenshotTest;
|
||||
@@ -51,7 +50,7 @@ public class FirstRunActivityIT extends AbstractIT {
|
||||
public void open() {
|
||||
Activity sut = activityRule.launchActivity(null);
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
screenshot(sut);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.client;
|
||||
|
||||
import android.Manifest;
|
||||
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.ui.activity.NotificationsActivity;
|
||||
import com.owncloud.android.utils.ScreenshotTest;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
|
||||
public class NotificationsActivityIT extends AbstractIT {
|
||||
@Rule public IntentsTestRule<NotificationsActivity> activityRule = new IntentsTestRule<>(NotificationsActivity.class,
|
||||
true,
|
||||
false);
|
||||
|
||||
@Rule
|
||||
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
public void openDrawer() {
|
||||
super.openDrawer(activityRule);
|
||||
}
|
||||
}
|
||||
@@ -22,14 +22,33 @@
|
||||
|
||||
package com.nextcloud.client;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.facebook.testing.screenshot.ScreenshotRunner;
|
||||
import com.github.tmurakami.dexopener.DexOpener;
|
||||
|
||||
import androidx.test.runner.AndroidJUnitRunner;
|
||||
|
||||
public class ScreenshotTestRunner extends AndroidJUnitRunner {
|
||||
|
||||
@Override
|
||||
public Application newApplication(ClassLoader cl, String className, Context context)
|
||||
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
|
||||
|
||||
/*
|
||||
* Initialize DexOpener only on API below 28 to enable mocking of Kotlin classes.
|
||||
* On API 28+ the platform supports mocking natively.
|
||||
*/
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||
DexOpener.install(this);
|
||||
}
|
||||
|
||||
return super.newApplication(cl, className, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle args) {
|
||||
super.onCreate(args);
|
||||
|
||||
@@ -25,7 +25,6 @@ package com.nextcloud.client;
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.ui.activity.SettingsActivity;
|
||||
import com.owncloud.android.utils.ScreenshotTest;
|
||||
@@ -49,8 +48,8 @@ public class SettingsActivityIT extends AbstractIT {
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
public void open() {
|
||||
Activity test = activityRule.launchActivity(null);
|
||||
Activity sut = activityRule.launchActivity(null);
|
||||
|
||||
Screenshot.snapActivity(test).record();
|
||||
screenshot(sut);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ package com.nextcloud.client;
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.datamodel.MediaFolderType;
|
||||
import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
|
||||
@@ -87,6 +86,6 @@ public class SyncedFoldersActivityIT extends AbstractIT {
|
||||
getInstrumentation().waitForIdleSync();
|
||||
shortSleep();
|
||||
|
||||
Screenshot.snap(Objects.requireNonNull(sut.requireDialog().getWindow()).getDecorView()).record();
|
||||
screenshot(Objects.requireNonNull(sut.requireDialog().getWindow()).getDecorView());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz <[email protected]>
|
||||
* Copyright (C) 2020 Chris Narkiewicz
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.account
|
||||
|
||||
import android.os.Parcel
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotSame
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class MockUserTest {
|
||||
|
||||
private companion object {
|
||||
const val ACCOUNT_NAME = "test_account_name"
|
||||
const val ACCOUNT_TYPE = "test_account_type"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mock_user_is_parcelable() {
|
||||
// GIVEN
|
||||
// mock user instance
|
||||
val original = MockUser(ACCOUNT_NAME, ACCOUNT_TYPE)
|
||||
|
||||
// WHEN
|
||||
// instance is serialized into Parcel
|
||||
// instance is retrieved from Parcel
|
||||
val parcel = Parcel.obtain()
|
||||
parcel.setDataPosition(0)
|
||||
parcel.writeParcelable(original, 0)
|
||||
parcel.setDataPosition(0)
|
||||
val retrieved = parcel.readParcelable<User>(User::class.java.classLoader)
|
||||
|
||||
// THEN
|
||||
// retrieved instance in distinct
|
||||
// instances are equal
|
||||
assertNotSame(original, retrieved)
|
||||
assertTrue(retrieved is MockUser)
|
||||
assertEquals(original, retrieved)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mock_user_has_platform_account() {
|
||||
// GIVEN
|
||||
// mock user instance
|
||||
val mock = MockUser(ACCOUNT_NAME, ACCOUNT_TYPE)
|
||||
|
||||
// THEN
|
||||
// can convert to platform account
|
||||
val account = mock.toPlatformAccount()
|
||||
assertEquals(ACCOUNT_NAME, account.name)
|
||||
assertEquals(ACCOUNT_TYPE, account.type)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import com.nextcloud.client.account.MockUser
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
class DownloaderConnectionTest {
|
||||
|
||||
lateinit var connection: DownloaderConnection
|
||||
|
||||
@MockK
|
||||
lateinit var context: Context
|
||||
|
||||
@MockK
|
||||
lateinit var firstDownloadListener: (Download) -> Unit
|
||||
|
||||
@MockK
|
||||
lateinit var secondDownloadListener: (Download) -> Unit
|
||||
|
||||
@MockK
|
||||
lateinit var firstStatusListener: (Downloader.Status) -> Unit
|
||||
|
||||
@MockK
|
||||
lateinit var secondStatusListener: (Downloader.Status) -> Unit
|
||||
|
||||
@MockK
|
||||
lateinit var binder: DownloaderService.Binder
|
||||
|
||||
val file get() = OCFile("/path")
|
||||
val componentName = ComponentName("", DownloaderService::class.java.simpleName)
|
||||
val user = MockUser()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockKAnnotations.init(this, relaxed = true)
|
||||
connection = DownloaderConnection(context, user)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listeners_are_set_after_connection() {
|
||||
// GIVEN
|
||||
// not connected
|
||||
// listener is added
|
||||
connection.registerDownloadListener(firstDownloadListener)
|
||||
connection.registerDownloadListener(secondDownloadListener)
|
||||
|
||||
// WHEN
|
||||
// service is bound
|
||||
connection.onServiceConnected(componentName, binder)
|
||||
|
||||
// THEN
|
||||
// all listeners are passed to the service
|
||||
val listeners = mutableListOf<(Download) -> Unit>()
|
||||
verify { binder.registerDownloadListener(capture(listeners)) }
|
||||
assertEquals(listOf(firstDownloadListener, secondDownloadListener), listeners)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listeners_are_set_immediately_when_connected() {
|
||||
// GIVEN
|
||||
// service is bound
|
||||
connection.onServiceConnected(componentName, binder)
|
||||
|
||||
// WHEN
|
||||
// listeners are added
|
||||
connection.registerDownloadListener(firstDownloadListener)
|
||||
|
||||
// THEN
|
||||
// listener is forwarded to service
|
||||
verify { binder.registerDownloadListener(firstDownloadListener) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listeners_are_removed_when_unbinding() {
|
||||
// GIVEN
|
||||
// service is bound
|
||||
// service has some listeners
|
||||
connection.onServiceConnected(componentName, binder)
|
||||
connection.registerDownloadListener(firstDownloadListener)
|
||||
connection.registerDownloadListener(secondDownloadListener)
|
||||
|
||||
// WHEN
|
||||
// service unbound
|
||||
connection.unbind()
|
||||
|
||||
// THEN
|
||||
// listeners removed from service
|
||||
verify { binder.removeDownloadListener(firstDownloadListener) }
|
||||
verify { binder.removeDownloadListener(secondDownloadListener) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun missed_updates_are_delivered_on_connection() {
|
||||
// GIVEN
|
||||
// not bound
|
||||
// has listeners
|
||||
// download is scheduled and is progressing
|
||||
connection.registerDownloadListener(firstDownloadListener)
|
||||
connection.registerDownloadListener(secondDownloadListener)
|
||||
|
||||
val request1 = Request(user, file)
|
||||
connection.download(request1)
|
||||
val download1 = Download(request1.uuid, DownloadState.RUNNING, 50, request1.file, request1)
|
||||
|
||||
val request2 = Request(user, file)
|
||||
connection.download(request2)
|
||||
val download2 = Download(request2.uuid, DownloadState.RUNNING, 50, request2.file, request1)
|
||||
|
||||
every { binder.getDownload(request1.uuid) } returns download1
|
||||
every { binder.getDownload(request2.uuid) } returns download2
|
||||
|
||||
// WHEN
|
||||
// service is bound
|
||||
connection.onServiceConnected(componentName, binder)
|
||||
|
||||
// THEN
|
||||
// listeners receive current download state for pending downloads
|
||||
val firstListenerNotifications = mutableListOf<Download>()
|
||||
verify { firstDownloadListener(capture(firstListenerNotifications)) }
|
||||
assertEquals(listOf(download1, download2), firstListenerNotifications)
|
||||
|
||||
val secondListenerNotifications = mutableListOf<Download>()
|
||||
verify { secondDownloadListener(capture(secondListenerNotifications)) }
|
||||
assertEquals(listOf(download1, download2), secondListenerNotifications)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun downloader_status_updates_are_delivered_on_connection() {
|
||||
// GIVEN
|
||||
// not bound
|
||||
// has status listeners
|
||||
val mockStatus: Downloader.Status = mockk()
|
||||
every { binder.status } returns mockStatus
|
||||
connection.registerStatusListener(firstStatusListener)
|
||||
connection.registerStatusListener(secondStatusListener)
|
||||
|
||||
// WHEN
|
||||
// service is bound
|
||||
connection.onServiceConnected(componentName, binder)
|
||||
|
||||
// THEN
|
||||
// downloader status is delivered
|
||||
verify { firstStatusListener(mockStatus) }
|
||||
verify { secondStatusListener(mockStatus) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun downloader_status_not_requested_if_no_listeners() {
|
||||
// GIVEN
|
||||
// not bound
|
||||
// no status listeners
|
||||
|
||||
// WHEN
|
||||
// service is bound
|
||||
connection.onServiceConnected(componentName, binder)
|
||||
|
||||
// THEN
|
||||
// downloader status is not requested
|
||||
verify(exactly = 0) { binder.status }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun not_running_if_not_connected() {
|
||||
// GIVEN
|
||||
// downloader is running
|
||||
// connection not bound
|
||||
every { binder.isRunning } returns true
|
||||
|
||||
// THEN
|
||||
// not running
|
||||
assertFalse(connection.isRunning)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun is_running_from_binder_if_connected() {
|
||||
// GIVEN
|
||||
// service bound
|
||||
every { binder.isRunning } returns true
|
||||
connection.onServiceConnected(componentName, binder)
|
||||
|
||||
// WHEN
|
||||
// is runnign flag accessed
|
||||
val isRunning = connection.isRunning
|
||||
|
||||
// THEN
|
||||
// call delegated to binder
|
||||
assertTrue(isRunning)
|
||||
verify(exactly = 1) { binder.isRunning }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun missed_updates_not_tracked_before_listeners_registered() {
|
||||
// GIVEN
|
||||
// not bound
|
||||
// some downloads requested without listener
|
||||
val request = Request(user, file)
|
||||
connection.download(request)
|
||||
val download = Download(request.uuid, DownloadState.RUNNING, 50, request.file, request)
|
||||
connection.registerDownloadListener(firstDownloadListener)
|
||||
every { binder.getDownload(request.uuid) } returns download
|
||||
|
||||
// WHEN
|
||||
// service is bound
|
||||
connection.onServiceConnected(componentName, binder)
|
||||
|
||||
// THEN
|
||||
// missed updates not redelivered
|
||||
verify(exactly = 0) { firstDownloadListener(any()) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider.getApplicationContext
|
||||
import androidx.test.rule.ServiceTestRule
|
||||
import com.nextcloud.client.account.MockUser
|
||||
import io.mockk.MockKAnnotations
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.TimeoutException
|
||||
|
||||
class DownloaderServiceTest {
|
||||
|
||||
@get:Rule
|
||||
val service = ServiceTestRule.withTimeout(3, TimeUnit.SECONDS)
|
||||
|
||||
val user = MockUser()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockKAnnotations.init(this, relaxed = true)
|
||||
}
|
||||
|
||||
@Test(expected = TimeoutException::class)
|
||||
fun cannot_bind_to_service_without_user() {
|
||||
val intent = DownloaderService.createBindIntent(getApplicationContext(), user)
|
||||
intent.removeExtra(DownloaderService.EXTRA_USER)
|
||||
service.bindService(intent)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bind_with_user() {
|
||||
val intent = DownloaderService.createBindIntent(getApplicationContext(), user)
|
||||
val binder = service.bindService(intent)
|
||||
assertTrue(binder is DownloaderService.Binder)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import com.nextcloud.client.account.User
|
||||
import com.nextcloud.client.core.ManualAsyncRunner
|
||||
import com.nextcloud.client.core.OnProgressCallback
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.mockk
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Suite
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
@RunWith(Suite::class)
|
||||
@Suite.SuiteClasses(
|
||||
DownloaderTest.Enqueue::class,
|
||||
DownloaderTest.DownloadStatusUpdates::class
|
||||
)
|
||||
class DownloaderTest {
|
||||
|
||||
abstract class Base {
|
||||
|
||||
companion object {
|
||||
const val MAX_DOWNLOAD_THREADS = 4
|
||||
}
|
||||
|
||||
@MockK
|
||||
lateinit var user: User
|
||||
|
||||
@MockK
|
||||
lateinit var client: OwnCloudClient
|
||||
|
||||
@MockK
|
||||
lateinit var mockTaskFactory: DownloadTask.Factory
|
||||
|
||||
/**
|
||||
* All task mock functions created during test run are
|
||||
* stored here.
|
||||
*/
|
||||
lateinit var downloadTaskMocks: MutableList<DownloadTask>
|
||||
lateinit var runner: ManualAsyncRunner
|
||||
lateinit var downloader: DownloaderImpl
|
||||
|
||||
/**
|
||||
* Response value for all download tasks
|
||||
*/
|
||||
var downloadTaskResult: Boolean = true
|
||||
|
||||
/**
|
||||
* Progress values posted by all download task mocks before
|
||||
* returning result value
|
||||
*/
|
||||
var taskProgress = listOf<Int>()
|
||||
|
||||
@Before
|
||||
fun setUpBase() {
|
||||
MockKAnnotations.init(this, relaxed = true)
|
||||
MockitoAnnotations.initMocks(this)
|
||||
downloadTaskMocks = mutableListOf()
|
||||
runner = ManualAsyncRunner()
|
||||
downloader = DownloaderImpl(
|
||||
runner = runner,
|
||||
taskFactory = mockTaskFactory,
|
||||
threads = MAX_DOWNLOAD_THREADS
|
||||
)
|
||||
downloadTaskResult = true
|
||||
every { mockTaskFactory.create() } answers { createMockTask() }
|
||||
}
|
||||
|
||||
private fun createMockTask(): DownloadTask {
|
||||
val task = mockk<DownloadTask>()
|
||||
every { task.download(any(), any(), any()) } answers {
|
||||
taskProgress.forEach {
|
||||
arg<OnProgressCallback<Int>>(1).invoke(it)
|
||||
}
|
||||
val request = arg<Request>(0)
|
||||
DownloadTask.Result(request.file, downloadTaskResult)
|
||||
}
|
||||
downloadTaskMocks.add(task)
|
||||
return task
|
||||
}
|
||||
}
|
||||
|
||||
class Enqueue : Base() {
|
||||
|
||||
@Test
|
||||
fun enqueued_download_is_started_immediately() {
|
||||
// GIVEN
|
||||
// downloader has no running downloads
|
||||
|
||||
// WHEN
|
||||
// download is enqueued
|
||||
val file = OCFile("/path")
|
||||
val request = Request(user, file)
|
||||
downloader.download(request)
|
||||
|
||||
// THEN
|
||||
// download is started immediately
|
||||
val download = downloader.getDownload(request.uuid)
|
||||
assertEquals(DownloadState.RUNNING, download?.state)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun enqueued_downloads_are_pending_if_running_queue_is_full() {
|
||||
// GIVEN
|
||||
// downloader is downloading max simultaneous files
|
||||
for (i in 0 until MAX_DOWNLOAD_THREADS) {
|
||||
val file = OCFile("/running/download/path/$i")
|
||||
val request = Request(user, file)
|
||||
downloader.download(request)
|
||||
val runningDownload = downloader.getDownload(request.uuid)
|
||||
assertEquals(runningDownload?.state, DownloadState.RUNNING)
|
||||
}
|
||||
|
||||
// WHEN
|
||||
// another download is enqueued
|
||||
val file = OCFile("/path")
|
||||
val request = Request(user, file)
|
||||
downloader.download(request)
|
||||
|
||||
// THEN
|
||||
// download is pending
|
||||
val download = downloader.getDownload(request.uuid)
|
||||
assertEquals(DownloadState.PENDING, download?.state)
|
||||
}
|
||||
}
|
||||
|
||||
class DownloadStatusUpdates : Base() {
|
||||
|
||||
@get:Rule
|
||||
val rule = InstantTaskExecutorRule()
|
||||
|
||||
val file = OCFile("/path")
|
||||
|
||||
@Test
|
||||
fun download_task_completes() {
|
||||
// GIVEN
|
||||
// download is running
|
||||
// download is being observed
|
||||
val downloadUpdates = mutableListOf<Download>()
|
||||
downloader.registerDownloadListener { downloadUpdates.add(it) }
|
||||
downloader.download(Request(user, file))
|
||||
|
||||
// WHEN
|
||||
// download task finishes successfully
|
||||
runner.runOne()
|
||||
|
||||
// THEN
|
||||
// listener is notified about status change
|
||||
assertEquals(DownloadState.RUNNING, downloadUpdates[0].state)
|
||||
assertEquals(DownloadState.COMPLETED, downloadUpdates[1].state)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun download_task_fails() {
|
||||
// GIVEN
|
||||
// download is running
|
||||
// download is being observed
|
||||
val downloadUpdates = mutableListOf<Download>()
|
||||
downloader.registerDownloadListener { downloadUpdates.add(it) }
|
||||
downloader.download(Request(user, file))
|
||||
|
||||
// WHEN
|
||||
// download task fails
|
||||
downloadTaskResult = false
|
||||
runner.runOne()
|
||||
|
||||
// THEN
|
||||
// listener is notified about status change
|
||||
assertEquals(DownloadState.RUNNING, downloadUpdates[0].state)
|
||||
assertEquals(DownloadState.FAILED, downloadUpdates[1].state)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun download_progress_is_updated() {
|
||||
// GIVEN
|
||||
// download is running
|
||||
val downloadUpdates = mutableListOf<Download>()
|
||||
downloader.registerDownloadListener { downloadUpdates.add(it) }
|
||||
downloader.download(Request(user, file))
|
||||
|
||||
// WHEN
|
||||
// download progress updated 4 times before completion
|
||||
taskProgress = listOf(25, 50, 75, 100)
|
||||
runner.runOne()
|
||||
|
||||
// THEN
|
||||
// listener receives 6 status updates
|
||||
// transition to running
|
||||
// 4 progress updates
|
||||
// completion
|
||||
assertEquals(6, downloadUpdates.size)
|
||||
if (downloadUpdates.size >= 6) {
|
||||
assertEquals(DownloadState.RUNNING, downloadUpdates[0].state)
|
||||
assertEquals(25, downloadUpdates[1].progress)
|
||||
assertEquals(50, downloadUpdates[2].progress)
|
||||
assertEquals(75, downloadUpdates[3].progress)
|
||||
assertEquals(100, downloadUpdates[4].progress)
|
||||
assertEquals(DownloadState.COMPLETED, downloadUpdates[5].state)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun download_task_is_created_only_for_running_downloads() {
|
||||
// WHEN
|
||||
// multiple downloads are enqueued
|
||||
for (i in 0 until MAX_DOWNLOAD_THREADS * 2) {
|
||||
downloader.download(Request(user, file))
|
||||
}
|
||||
|
||||
// THEN
|
||||
// download task is created only for running downloads
|
||||
assertEquals(MAX_DOWNLOAD_THREADS, downloadTaskMocks.size)
|
||||
}
|
||||
}
|
||||
|
||||
class RunningStatusUpdates : Base() {
|
||||
|
||||
@get:Rule
|
||||
val rule = InstantTaskExecutorRule()
|
||||
|
||||
@Test
|
||||
fun is_running_flag_on_enqueue() {
|
||||
// WHEN
|
||||
// download is enqueued
|
||||
val file = OCFile("/path/to/file")
|
||||
val request = Request(user, file)
|
||||
downloader.download(request)
|
||||
|
||||
// THEN
|
||||
// is running changes
|
||||
assertTrue(downloader.isRunning)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun is_running_flag_on_completion() {
|
||||
// GIVEN
|
||||
// a download is in progress
|
||||
val file = OCFile("/path/to/file")
|
||||
val request = Request(user, file)
|
||||
downloader.download(request)
|
||||
assertTrue(downloader.isRunning)
|
||||
|
||||
// WHEN
|
||||
// download is processed
|
||||
runner.runOne()
|
||||
|
||||
// THEN
|
||||
// downloader is not running
|
||||
assertFalse(downloader.isRunning)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,519 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
import com.nextcloud.client.account.User
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import io.mockk.CapturingSlot
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.clearAllMocks
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.verify
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertSame
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Suite
|
||||
import java.util.UUID
|
||||
|
||||
@RunWith(Suite::class)
|
||||
@Suite.SuiteClasses(
|
||||
RegistryTest.Pending::class,
|
||||
RegistryTest.Start::class,
|
||||
RegistryTest.Progress::class,
|
||||
RegistryTest.Complete::class,
|
||||
RegistryTest.GetDownloads::class,
|
||||
RegistryTest.IsRunning::class
|
||||
)
|
||||
class RegistryTest {
|
||||
|
||||
abstract class Base {
|
||||
companion object {
|
||||
const val MAX_DOWNLOAD_THREADS = 4
|
||||
const val PROGRESS_FULL = 100
|
||||
const val PROGRESS_HALF = 50
|
||||
}
|
||||
|
||||
@MockK
|
||||
lateinit var user: User
|
||||
|
||||
lateinit var file: OCFile
|
||||
|
||||
@MockK
|
||||
lateinit var onDownloadStart: (UUID, Request) -> Unit
|
||||
|
||||
@MockK
|
||||
lateinit var onDownloadChanged: (Download) -> Unit
|
||||
|
||||
internal lateinit var registry: Registry
|
||||
|
||||
@Before
|
||||
fun setUpBase() {
|
||||
MockKAnnotations.init(this, relaxed = true)
|
||||
file = OCFile("/test/path")
|
||||
registry = Registry(onDownloadStart, onDownloadChanged, MAX_DOWNLOAD_THREADS)
|
||||
resetMocks()
|
||||
}
|
||||
|
||||
fun resetMocks() {
|
||||
clearAllMocks()
|
||||
every { onDownloadStart(any(), any()) } answers {}
|
||||
every { onDownloadChanged(any()) } answers {}
|
||||
}
|
||||
}
|
||||
|
||||
class Pending : Base() {
|
||||
|
||||
@Test
|
||||
fun inserting_pending_download() {
|
||||
// GIVEN
|
||||
// registry has no pending downloads
|
||||
assertEquals(0, registry.pending.size)
|
||||
|
||||
// WHEN
|
||||
// new download requests added
|
||||
val addedDownloadsCount = 10
|
||||
for (i in 0 until addedDownloadsCount) {
|
||||
val request = Request(user, file)
|
||||
registry.add(request)
|
||||
}
|
||||
|
||||
// THEN
|
||||
// download is added to the pending queue
|
||||
assertEquals(addedDownloadsCount, registry.pending.size)
|
||||
}
|
||||
}
|
||||
|
||||
class Start : Base() {
|
||||
|
||||
companion object {
|
||||
const val ENQUEUED_REQUESTS_COUNT = 10
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
for (i in 0 until ENQUEUED_REQUESTS_COUNT) {
|
||||
registry.add(Request(user, file))
|
||||
}
|
||||
assertEquals(ENQUEUED_REQUESTS_COUNT, registry.pending.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun starting_download() {
|
||||
// WHEN
|
||||
// started
|
||||
registry.startNext()
|
||||
|
||||
// THEN
|
||||
// up to max threads requests are started
|
||||
// start callback is triggered
|
||||
// update callback is triggered on download transition
|
||||
// started downloads are in running state
|
||||
assertEquals(
|
||||
"Downloads not moved to running queue",
|
||||
MAX_DOWNLOAD_THREADS,
|
||||
registry.running.size
|
||||
)
|
||||
assertEquals(
|
||||
"Downloads not moved from pending queue",
|
||||
ENQUEUED_REQUESTS_COUNT - MAX_DOWNLOAD_THREADS,
|
||||
registry.pending.size
|
||||
)
|
||||
verify(exactly = MAX_DOWNLOAD_THREADS) { onDownloadStart(any(), any()) }
|
||||
val startedDownloads = mutableListOf<Download>()
|
||||
verify(exactly = MAX_DOWNLOAD_THREADS) { onDownloadChanged(capture(startedDownloads)) }
|
||||
assertEquals(
|
||||
"Callbacks not invoked for running downloads",
|
||||
MAX_DOWNLOAD_THREADS,
|
||||
startedDownloads.size
|
||||
)
|
||||
startedDownloads.forEach {
|
||||
assertEquals("Download not placed into running state", DownloadState.RUNNING, it.state)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun start_is_ignored_if_no_more_free_threads() {
|
||||
// WHEN
|
||||
// max number of running downloads
|
||||
registry.startNext()
|
||||
assertEquals(MAX_DOWNLOAD_THREADS, registry.running.size)
|
||||
clearAllMocks()
|
||||
|
||||
// WHEN
|
||||
// starting more downloads
|
||||
registry.startNext()
|
||||
|
||||
// THEN
|
||||
// no more downloads can be started
|
||||
assertEquals(MAX_DOWNLOAD_THREADS, registry.running.size)
|
||||
verify(exactly = 0) { onDownloadStart(any(), any()) }
|
||||
}
|
||||
}
|
||||
|
||||
class Progress : Base() {
|
||||
|
||||
var uuid: UUID = UUID.randomUUID()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
val request = Request(user, file)
|
||||
uuid = registry.add(request)
|
||||
registry.startNext()
|
||||
assertEquals(uuid, request.uuid)
|
||||
assertEquals(1, registry.running.size)
|
||||
resetMocks()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun download_progress_is_updated() {
|
||||
// GIVEN
|
||||
// a download is running
|
||||
|
||||
// WHEN
|
||||
// download progress is updated
|
||||
val progressHalf = 50
|
||||
registry.progress(uuid, progressHalf)
|
||||
|
||||
// THEN
|
||||
// progress is updated
|
||||
// update callback is invoked
|
||||
val download = mutableListOf<Download>()
|
||||
verify { onDownloadChanged(capture(download)) }
|
||||
assertEquals(1, download.size)
|
||||
assertEquals(progressHalf, download.first().progress)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun updates_for_non_running_downloads_are_ignored() {
|
||||
// GIVEN
|
||||
// download is not running
|
||||
registry.complete(uuid, true)
|
||||
assertEquals(0, registry.running.size)
|
||||
resetMocks()
|
||||
|
||||
// WHEN
|
||||
// progress for a non-running download is updated
|
||||
registry.progress(uuid, PROGRESS_HALF)
|
||||
|
||||
// THEN
|
||||
// progress update is ignored
|
||||
verify(exactly = 0) { onDownloadChanged(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun updates_for_non_existing_downloads_are_ignored() {
|
||||
// GIVEN
|
||||
// some download is running
|
||||
|
||||
// WHEN
|
||||
// progress is updated for non-existing download
|
||||
val nonExistingDownloadId = UUID.randomUUID()
|
||||
registry.progress(nonExistingDownloadId, PROGRESS_HALF)
|
||||
|
||||
// THEN
|
||||
// progress uppdate is ignored
|
||||
verify(exactly = 0) { onDownloadChanged(any()) }
|
||||
}
|
||||
}
|
||||
|
||||
class Complete : Base() {
|
||||
|
||||
lateinit var uuid: UUID
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
uuid = registry.add(Request(user, file))
|
||||
registry.startNext()
|
||||
registry.progress(uuid, PROGRESS_FULL)
|
||||
resetMocks()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun complete_successful_download_with_updated_file() {
|
||||
// GIVEN
|
||||
// a download is running
|
||||
|
||||
// WHEN
|
||||
// download is completed
|
||||
// file has been updated
|
||||
val updatedFile = OCFile("/updated/file")
|
||||
registry.complete(uuid, true, updatedFile)
|
||||
|
||||
// THEN
|
||||
// download is completed successfully
|
||||
// status carries updated file
|
||||
val slot = CapturingSlot<Download>()
|
||||
verify { onDownloadChanged(capture(slot)) }
|
||||
assertEquals(DownloadState.COMPLETED, slot.captured.state)
|
||||
assertSame(slot.captured.file, updatedFile)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun complete_successful_download() {
|
||||
// GIVEN
|
||||
// a download is running
|
||||
|
||||
// WHEN
|
||||
// download is completed
|
||||
// file is not updated
|
||||
registry.complete(uuid = uuid, success = true, file = null)
|
||||
|
||||
// THEN
|
||||
// download is completed successfully
|
||||
// status carries previous file
|
||||
val slot = CapturingSlot<Download>()
|
||||
verify { onDownloadChanged(capture(slot)) }
|
||||
assertEquals(DownloadState.COMPLETED, slot.captured.state)
|
||||
assertSame(slot.captured.file, file)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun complete_failed_download() {
|
||||
// GIVEN
|
||||
// a download is running
|
||||
|
||||
// WHEN
|
||||
// download is failed
|
||||
registry.complete(uuid, false)
|
||||
|
||||
// THEN
|
||||
// download is completed successfully
|
||||
val slot = CapturingSlot<Download>()
|
||||
verify { onDownloadChanged(capture(slot)) }
|
||||
assertEquals(DownloadState.FAILED, slot.captured.state)
|
||||
}
|
||||
}
|
||||
|
||||
class GetDownloads : Base() {
|
||||
|
||||
val pendingDownloadFile = OCFile("/pending")
|
||||
val runningDownloadFile = OCFile("/running")
|
||||
val completedDownloadFile = OCFile("/completed")
|
||||
|
||||
lateinit var pendingDownloadId: UUID
|
||||
lateinit var runningDownloadId: UUID
|
||||
lateinit var completedDownloadId: UUID
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
completedDownloadId = registry.add(Request(user, completedDownloadFile))
|
||||
registry.startNext()
|
||||
registry.complete(completedDownloadId, true)
|
||||
|
||||
runningDownloadId = registry.add(Request(user, runningDownloadFile))
|
||||
registry.startNext()
|
||||
|
||||
pendingDownloadId = registry.add(Request(user, pendingDownloadFile))
|
||||
resetMocks()
|
||||
|
||||
assertEquals(1, registry.pending.size)
|
||||
assertEquals(1, registry.running.size)
|
||||
assertEquals(1, registry.completed.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun get_by_path_searches_pending_queue() {
|
||||
// GIVEN
|
||||
// file download is pending
|
||||
|
||||
// WHEN
|
||||
// download status is retrieved
|
||||
val download = registry.getDownload(pendingDownloadFile)
|
||||
|
||||
// THEN
|
||||
// download from pending queue is returned
|
||||
assertNotNull(download)
|
||||
assertEquals(pendingDownloadId, download?.uuid)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun get_by_id_searches_pending_queue() {
|
||||
// GIVEN
|
||||
// file download is pending
|
||||
|
||||
// WHEN
|
||||
// download status is retrieved
|
||||
val download = registry.getDownload(pendingDownloadId)
|
||||
|
||||
// THEN
|
||||
// download from pending queue is returned
|
||||
assertNotNull(download)
|
||||
assertEquals(pendingDownloadId, download?.uuid)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun get_by_path_searches_running_queue() {
|
||||
// GIVEN
|
||||
// file download is running
|
||||
|
||||
// WHEN
|
||||
// download status is retrieved
|
||||
val download = registry.getDownload(runningDownloadFile)
|
||||
|
||||
// THEN
|
||||
// download from pending queue is returned
|
||||
assertNotNull(download)
|
||||
assertEquals(runningDownloadId, download?.uuid)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun get_by_id_searches_running_queue() {
|
||||
// GIVEN
|
||||
// file download is running
|
||||
|
||||
// WHEN
|
||||
// download status is retrieved
|
||||
val download = registry.getDownload(runningDownloadId)
|
||||
|
||||
// THEN
|
||||
// download from pending queue is returned
|
||||
assertNotNull(download)
|
||||
assertEquals(runningDownloadId, download?.uuid)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun get_by_path_searches_completed_queue() {
|
||||
// GIVEN
|
||||
// file download is pending
|
||||
|
||||
// WHEN
|
||||
// download status is retrieved
|
||||
val download = registry.getDownload(completedDownloadFile)
|
||||
|
||||
// THEN
|
||||
// download from pending queue is returned
|
||||
assertNotNull(download)
|
||||
assertEquals(completedDownloadId, download?.uuid)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun get_by_id_searches_completed_queue() {
|
||||
// GIVEN
|
||||
// file download is pending
|
||||
|
||||
// WHEN
|
||||
// download status is retrieved
|
||||
val download = registry.getDownload(completedDownloadId)
|
||||
|
||||
// THEN
|
||||
// download from pending queue is returned
|
||||
assertNotNull(download)
|
||||
assertEquals(completedDownloadId, download?.uuid)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun not_found_by_path() {
|
||||
// GIVEN
|
||||
// no download for a file
|
||||
val nonExistingDownloadFile = OCFile("/non-nexisting/download")
|
||||
|
||||
// WHEN
|
||||
// download status is retrieved for a file
|
||||
val download = registry.getDownload(nonExistingDownloadFile)
|
||||
|
||||
// THEN
|
||||
// no download is found
|
||||
assertNull(download)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun not_found_by_id() {
|
||||
// GIVEN
|
||||
// no download for an id
|
||||
val nonExistingId = UUID.randomUUID()
|
||||
|
||||
// WHEN
|
||||
// download status is retrieved for a file
|
||||
val download = registry.getDownload(nonExistingId)
|
||||
|
||||
// THEN
|
||||
// no download is found
|
||||
assertNull(download)
|
||||
}
|
||||
}
|
||||
|
||||
class IsRunning : Base() {
|
||||
|
||||
@Test
|
||||
fun no_requests() {
|
||||
// WHEN
|
||||
// all queues empty
|
||||
assertEquals(0, registry.pending.size)
|
||||
assertEquals(0, registry.running.size)
|
||||
assertEquals(0, registry.completed.size)
|
||||
|
||||
// THEN
|
||||
// not running
|
||||
assertFalse(registry.isRunning)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun request_pending() {
|
||||
// WHEN
|
||||
// request is enqueued
|
||||
registry.add(Request(user, OCFile("/path/alpha/1")))
|
||||
assertEquals(1, registry.pending.size)
|
||||
assertEquals(0, registry.running.size)
|
||||
assertEquals(0, registry.completed.size)
|
||||
|
||||
// THEN
|
||||
// is running
|
||||
assertTrue(registry.isRunning)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun request_running() {
|
||||
// WHEN
|
||||
// request is running
|
||||
registry.add(Request(user, OCFile("/path/alpha/1")))
|
||||
registry.startNext()
|
||||
assertEquals(0, registry.pending.size)
|
||||
assertEquals(1, registry.running.size)
|
||||
assertEquals(0, registry.completed.size)
|
||||
|
||||
// THEN
|
||||
// is running
|
||||
assertTrue(registry.isRunning)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun request_completed() {
|
||||
// WHEN
|
||||
// request is running
|
||||
val id = registry.add(Request(user, OCFile("/path/alpha/1")))
|
||||
registry.startNext()
|
||||
registry.complete(id, true)
|
||||
assertEquals(0, registry.pending.size)
|
||||
assertEquals(0, registry.running.size)
|
||||
assertEquals(1, registry.completed.size)
|
||||
|
||||
// THEN
|
||||
// is not running
|
||||
assertFalse(registry.isRunning)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,12 @@ import android.accounts.OperationCanceledException;
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.nextcloud.client.RetryTestRule;
|
||||
import com.facebook.testing.screenshot.internal.TestNameDetector;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||
@@ -17,6 +20,8 @@ import com.nextcloud.client.device.BatteryStatus;
|
||||
import com.nextcloud.client.device.PowerManagementService;
|
||||
import com.nextcloud.client.network.Connectivity;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
import com.nextcloud.client.preferences.AppPreferencesImpl;
|
||||
import com.nextcloud.client.preferences.DarkMode;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
@@ -27,6 +32,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.resources.status.OCCapability;
|
||||
import com.owncloud.android.operations.CreateFolderOperation;
|
||||
import com.owncloud.android.operations.UploadFileOperation;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
@@ -35,7 +41,6 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
@@ -61,12 +66,14 @@ import static org.junit.Assert.assertTrue;
|
||||
*/
|
||||
|
||||
public abstract class AbstractIT {
|
||||
@Rule public RetryTestRule retryTestRule = new RetryTestRule();
|
||||
//@Rule public RetryTestRule retryTestRule = new RetryTestRule();
|
||||
|
||||
protected static OwnCloudClient client;
|
||||
protected static Account account;
|
||||
protected static User user;
|
||||
protected static Context targetContext;
|
||||
protected static String DARK_MODE = "";
|
||||
protected static String COLOR = "";
|
||||
|
||||
protected Activity currentActivity;
|
||||
|
||||
@@ -109,6 +116,63 @@ public abstract class AbstractIT {
|
||||
} catch (AccountUtils.AccountNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments();
|
||||
|
||||
// color
|
||||
String colorParameter = arguments.getString("COLOR");
|
||||
if (!TextUtils.isEmpty(colorParameter)) {
|
||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(account,
|
||||
targetContext.getContentResolver());
|
||||
|
||||
String colorHex = null;
|
||||
COLOR = colorParameter;
|
||||
switch (colorParameter) {
|
||||
case "red":
|
||||
colorHex = "#7c0000";
|
||||
break;
|
||||
|
||||
case "green":
|
||||
colorHex = "#00ff00";
|
||||
break;
|
||||
|
||||
case "white":
|
||||
colorHex = "#ffffff";
|
||||
break;
|
||||
|
||||
case "black":
|
||||
colorHex = "#000000";
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (colorHex != null) {
|
||||
OCCapability capability = fileDataStorageManager.getCapability(account.name);
|
||||
capability.setServerColor(colorHex);
|
||||
fileDataStorageManager.saveCapabilities(capability);
|
||||
}
|
||||
}
|
||||
|
||||
// dark / light
|
||||
String darkModeParameter = arguments.getString("DARKMODE");
|
||||
|
||||
if (darkModeParameter != null) {
|
||||
if (darkModeParameter.equalsIgnoreCase("dark")) {
|
||||
DARK_MODE = "dark";
|
||||
AppPreferencesImpl.fromContext(targetContext).setDarkThemeMode(DarkMode.DARK);
|
||||
MainApp.setAppTheme(DarkMode.DARK);
|
||||
} else {
|
||||
DARK_MODE = "light";
|
||||
}
|
||||
}
|
||||
|
||||
if (DARK_MODE.equalsIgnoreCase("light") && COLOR.equalsIgnoreCase("blue")) {
|
||||
// use already existing names
|
||||
DARK_MODE = "";
|
||||
COLOR = "";
|
||||
}
|
||||
}
|
||||
|
||||
protected FileDataStorageManager getStorageManager() {
|
||||
@@ -153,7 +217,7 @@ public abstract class AbstractIT {
|
||||
|
||||
waitForIdleSync();
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
screenshot(sut);
|
||||
}
|
||||
|
||||
protected Activity getCurrentActivity() {
|
||||
@@ -251,4 +315,26 @@ public abstract class AbstractIT {
|
||||
RemoteOperationResult result = newUpload.execute(client, getStorageManager());
|
||||
assertTrue(result.getLogMessage(), result.isSuccess());
|
||||
}
|
||||
|
||||
protected void screenshot(View view) {
|
||||
Screenshot.snap(view).setName(createName()).record();
|
||||
}
|
||||
|
||||
protected void screenshot(Activity sut) {
|
||||
Screenshot.snapActivity(sut).setName(createName()).record();
|
||||
}
|
||||
|
||||
private String createName() {
|
||||
String name = TestNameDetector.getTestClass() + "_" + TestNameDetector.getTestName();
|
||||
|
||||
if (!DARK_MODE.isEmpty()) {
|
||||
name = name + "_" + DARK_MODE;
|
||||
}
|
||||
|
||||
if (!COLOR.isEmpty()) {
|
||||
name = name + "_" + COLOR;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -236,5 +236,10 @@ public abstract class AbstractOnServerIT extends AbstractIT {
|
||||
|
||||
RemoteOperationResult result = newUpload.execute(client, getStorageManager());
|
||||
assertTrue(result.getLogMessage(), result.isSuccess());
|
||||
//
|
||||
// shortSleep();
|
||||
// shortSleep();
|
||||
//
|
||||
// assertNotNull(getStorageManager().getFileByDecryptedRemotePath(ocUpload.getRemotePath()).getRemoteId());
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,6 @@ import com.owncloud.android.datamodel.UploadsStorageManager;
|
||||
import com.owncloud.android.db.OCUpload;
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
|
||||
import com.owncloud.android.lib.resources.files.model.RemoteFile;
|
||||
import com.owncloud.android.operations.RefreshFolderOperation;
|
||||
import com.owncloud.android.operations.RemoveFileOperation;
|
||||
import com.owncloud.android.operations.UploadFileOperation;
|
||||
@@ -40,14 +38,8 @@ import com.owncloud.android.utils.FileStorageUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
@@ -318,23 +310,4 @@ public class UploadIT extends AbstractOnServerIT {
|
||||
targetContext)
|
||||
.execute(client, getStorageManager());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUploadSameModificationDate() throws IOException {
|
||||
File file = new File(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt");
|
||||
BasicFileAttributes attributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
|
||||
long modifiedDate = attributes.lastModifiedTime().toMillis();
|
||||
|
||||
OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
|
||||
FOLDER + "nonEmpty.txt",
|
||||
account.name);
|
||||
|
||||
shortSleep();
|
||||
uploadOCUpload(ocUpload);
|
||||
|
||||
RemoteOperationResult readFileResult = new ReadFileRemoteOperation(FOLDER + "nonEmpty.txt").execute(client);
|
||||
RemoteFile remoteFile = (RemoteFile) readFileResult.getData().get(0);
|
||||
|
||||
assertEquals(modifiedDate, remoteFile.getModifiedTimestamp());
|
||||
}
|
||||
}
|
||||
@@ -26,5 +26,7 @@ public class FileDataStorageManagerContentResolverTest extends FileDataStorageMa
|
||||
@Override
|
||||
public void before() {
|
||||
sut = new FileDataStorageManager(account, targetContext.getContentResolver());
|
||||
|
||||
super.before();
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,13 @@ abstract public class FileDataStorageManagerTest extends AbstractOnServerIT {
|
||||
protected FileDataStorageManager sut;
|
||||
|
||||
@Before
|
||||
abstract public void before();
|
||||
public void before() {
|
||||
// make sure everything is removed
|
||||
sut.deleteAllFiles();
|
||||
sut.deleteVirtuals(VirtualFolderType.PHOTOS);
|
||||
|
||||
assertEquals(0, sut.getAllFiles().size());
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
|
||||
@@ -28,9 +28,9 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -49,7 +49,7 @@ public class UploadStorageManagerTest extends AbstractIT {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Context instrumentationCtx = InstrumentationRegistry.getTargetContext();
|
||||
Context instrumentationCtx = ApplicationProvider.getApplicationContext();
|
||||
ContentResolver contentResolver = instrumentationCtx.getContentResolver();
|
||||
uploadsStorageManager = new UploadsStorageManager(currentAccountProvider, contentResolver);
|
||||
|
||||
@@ -94,6 +94,7 @@ public class UploadStorageManagerTest extends AbstractIT {
|
||||
int size = 3000;
|
||||
ArrayList<OCUpload> uploads = new ArrayList<>();
|
||||
|
||||
deleteAllUploads();
|
||||
assertEquals(0, uploadsStorageManager.getAllStoredUploads().length);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
@@ -156,8 +157,14 @@ public class UploadStorageManagerTest extends AbstractIT {
|
||||
}
|
||||
|
||||
private OCUpload createUpload(Account account) {
|
||||
OCUpload upload = new OCUpload(File.separator + "very long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long LocalPath",
|
||||
OCFile.PATH_SEPARATOR + "very long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long RemotePath",
|
||||
OCUpload upload = new OCUpload(File.separator + "very long long long long long long long long long long long " +
|
||||
"long long long long long long long long long long long long long long " +
|
||||
"long long long long long long long long long long long long long long " +
|
||||
"long long long long long long long LocalPath",
|
||||
OCFile.PATH_SEPARATOR + "very long long long long long long long long long " +
|
||||
"long long long long long long long long long long long long long long " +
|
||||
"long long long long long long long long long long long long long long " +
|
||||
"long long long long long long long long long long long long RemotePath",
|
||||
account.name);
|
||||
|
||||
upload.setFileSize(new Random().nextInt(20000) * 10000);
|
||||
@@ -175,11 +182,15 @@ public class UploadStorageManagerTest extends AbstractIT {
|
||||
return upload;
|
||||
}
|
||||
|
||||
private void deleteAllUploads() {
|
||||
uploadsStorageManager.removeAllUploads();
|
||||
|
||||
assertEquals(0, uploadsStorageManager.getAllStoredUploads().length);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
for (Account account : getAllAccounts()) {
|
||||
uploadsStorageManager.removeAccountUploads(account);
|
||||
}
|
||||
deleteAllUploads();
|
||||
|
||||
AccountManager platformAccountManager = AccountManager.get(targetContext);
|
||||
platformAccountManager.removeAccountExplicitly(account2);
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.operations;
|
||||
|
||||
import com.owncloud.android.AbstractOnServerIT;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.db.OCUpload;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
public class RemoveFileOperationIT extends AbstractOnServerIT {
|
||||
@Test
|
||||
public void deleteFolder() {
|
||||
String parent = "/test/";
|
||||
String path = parent + "folder1/";
|
||||
assertTrue(new CreateFolderOperation(path, user, targetContext).execute(client, getStorageManager())
|
||||
.isSuccess());
|
||||
|
||||
OCFile folder = getStorageManager().getFileByPath(path);
|
||||
|
||||
assertNotNull(folder);
|
||||
|
||||
assertTrue(new RemoveFileOperation(folder,
|
||||
false,
|
||||
account,
|
||||
false,
|
||||
targetContext)
|
||||
.execute(client, getStorageManager())
|
||||
.isSuccess());
|
||||
|
||||
OCFile parentFolder = getStorageManager().getFileByPath(parent);
|
||||
|
||||
assertNotNull(parentFolder);
|
||||
assertTrue(new RemoveFileOperation(parentFolder,
|
||||
false,
|
||||
account,
|
||||
false,
|
||||
targetContext)
|
||||
.execute(client, getStorageManager())
|
||||
.isSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteFile() {
|
||||
String parent = "/test/";
|
||||
String path = parent + "empty.txt";
|
||||
OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt", path, account.name);
|
||||
|
||||
uploadOCUpload(ocUpload);
|
||||
|
||||
OCFile file = getStorageManager().getFileByPath(path);
|
||||
|
||||
assertNotNull(file);
|
||||
|
||||
assertTrue(new RemoveFileOperation(file,
|
||||
false,
|
||||
account,
|
||||
false,
|
||||
targetContext)
|
||||
.execute(client, getStorageManager())
|
||||
.isSuccess());
|
||||
|
||||
OCFile parentFolder = getStorageManager().getFileByPath(parent);
|
||||
|
||||
assertNotNull(parentFolder);
|
||||
assertTrue(new RemoveFileOperation(parentFolder,
|
||||
false,
|
||||
account,
|
||||
false,
|
||||
targetContext)
|
||||
.execute(client, getStorageManager())
|
||||
.isSuccess());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui;
|
||||
|
||||
import android.Manifest;
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import androidx.test.core.app.ActivityScenario;
|
||||
import androidx.test.espresso.web.webdriver.DriverAtoms;
|
||||
import androidx.test.espresso.web.webdriver.Locator;
|
||||
import androidx.test.filters.LargeTest;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.action.ViewActions.typeText;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static androidx.test.espresso.web.sugar.Web.onWebView;
|
||||
import static androidx.test.espresso.web.webdriver.DriverAtoms.findElement;
|
||||
import static androidx.test.espresso.web.webdriver.DriverAtoms.webClick;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
@LargeTest
|
||||
public class LoginIT {
|
||||
@Rule
|
||||
public GrantPermissionRule permissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
tearDown();
|
||||
|
||||
ActivityScenario.launch(AuthenticatorActivity.class);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
|
||||
|
||||
if (accountManager.getAccounts().length > 0) {
|
||||
accountManager.removeAllAccounts();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void login() throws InterruptedException {
|
||||
Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments();
|
||||
|
||||
String baseUrl = arguments.getString("TEST_SERVER_URL");
|
||||
String loginName = arguments.getString("TEST_SERVER_USERNAME");
|
||||
String password = arguments.getString("TEST_SERVER_PASSWORD");
|
||||
|
||||
onView(withId(R.id.login)).perform(click());
|
||||
onView(withId(R.id.host_url_input)).perform(typeText(baseUrl));
|
||||
onView(withId(R.id.test_server_button)).perform(click());
|
||||
|
||||
Thread.sleep(3000);
|
||||
|
||||
onWebView().forceJavascriptEnabled();
|
||||
|
||||
// click on login
|
||||
onWebView()
|
||||
.withElement(findElement(Locator.XPATH, "//p[@id='redirect-link']/a"))
|
||||
.perform(webClick());
|
||||
|
||||
// username
|
||||
onWebView()
|
||||
.withElement(findElement(Locator.XPATH, "//input[@id='user']"))
|
||||
.perform(DriverAtoms.webKeys(loginName));
|
||||
|
||||
// password
|
||||
onWebView()
|
||||
.withElement(findElement(Locator.XPATH, "//input[@id='password']"))
|
||||
.perform(DriverAtoms.webKeys(password));
|
||||
|
||||
// click login
|
||||
onWebView()
|
||||
.withElement(findElement(Locator.XPATH, "//input[@id='submit-form']"))
|
||||
.perform(webClick());
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
// grant access
|
||||
onWebView()
|
||||
.withElement(findElement(Locator.XPATH, "//input[@type='submit']"))
|
||||
.perform(webClick());
|
||||
|
||||
Thread.sleep(5 * 1000);
|
||||
|
||||
// check for account
|
||||
Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
|
||||
|
||||
assertEquals(1, accountManager.getAccounts().length);
|
||||
|
||||
Account account = accountManager.getAccounts()[0];
|
||||
|
||||
// account.name is loginName@baseUrl (without protocol)
|
||||
assertEquals(loginName, account.name.split("@")[0]);
|
||||
assertEquals(baseUrl.split("//")[1], account.name.split("@")[1]);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.R;
|
||||
@@ -38,6 +37,8 @@ import com.owncloud.android.utils.ScreenshotTest;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
|
||||
@@ -87,7 +88,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
||||
|
||||
shortSleep();
|
||||
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
|
||||
}
|
||||
|
||||
// @Test
|
||||
@@ -141,7 +142,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
||||
// getInstrumentation().waitForIdleSync();
|
||||
// shortSleep();
|
||||
//
|
||||
// Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
// screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
|
||||
// }
|
||||
|
||||
@Test
|
||||
@@ -222,7 +223,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
||||
onView(withId(R.id.existing_checkbox)).perform(click());
|
||||
|
||||
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
|
||||
|
||||
onView(withText("OK")).perform(click());
|
||||
|
||||
@@ -267,7 +268,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
||||
onView(withId(R.id.new_checkbox)).perform(click());
|
||||
|
||||
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
|
||||
|
||||
onView(withText("OK")).perform(click());
|
||||
|
||||
@@ -313,7 +314,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
|
||||
onView(withId(R.id.new_checkbox)).perform(click());
|
||||
|
||||
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
|
||||
|
||||
onView(withText("OK")).perform(click());
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.utils.ScreenshotTest;
|
||||
@@ -47,7 +46,7 @@ public class ManageAccountsActivityIT extends AbstractIT {
|
||||
|
||||
shortSleep();
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
screenshot(sut);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,6 +60,6 @@ public class ManageAccountsActivityIT extends AbstractIT {
|
||||
shortSleep();
|
||||
shortSleep();
|
||||
|
||||
Screenshot.snapActivity(getCurrentActivity()).record();
|
||||
screenshot(getCurrentActivity());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.activity
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import com.facebook.testing.screenshot.Screenshot
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.lib.resources.notifications.models.Action
|
||||
import com.owncloud.android.lib.resources.notifications.models.Notification
|
||||
import com.owncloud.android.lib.resources.notifications.models.RichObject
|
||||
import com.owncloud.android.utils.ScreenshotTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.util.GregorianCalendar
|
||||
|
||||
class NotificationsActivityIT : AbstractIT() {
|
||||
@get:Rule
|
||||
var activityRule = IntentsTestRule(NotificationsActivity::class.java, true, false)
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun loading() {
|
||||
val sut: NotificationsActivity = activityRule.launchActivity(null)
|
||||
|
||||
Screenshot.snapActivity(sut).record()
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun empty() {
|
||||
val sut: NotificationsActivity = activityRule.launchActivity(null)
|
||||
|
||||
sut.runOnUiThread { sut.populateList(ArrayList<Notification>()) }
|
||||
|
||||
shortSleep()
|
||||
|
||||
screenshot(sut)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showNotifications() {
|
||||
val sut: NotificationsActivity = activityRule.launchActivity(null)
|
||||
|
||||
val date = GregorianCalendar()
|
||||
date.set(2005, 4, 17, 10, 35, 30)
|
||||
|
||||
val notifications = ArrayList<Notification>()
|
||||
notifications.add(
|
||||
Notification(
|
||||
1,
|
||||
"files",
|
||||
"user",
|
||||
date.time,
|
||||
"objectType",
|
||||
"objectId",
|
||||
"App recommendation: Tasks",
|
||||
"SubjectRich",
|
||||
HashMap<String, RichObject>(),
|
||||
"Sync tasks from various devices with your Nextcloud and edit them online.",
|
||||
"MessageRich",
|
||||
HashMap<String, RichObject>(),
|
||||
"link",
|
||||
"icon",
|
||||
ArrayList<Action>()
|
||||
)
|
||||
)
|
||||
|
||||
val actions = ArrayList<Action>()
|
||||
actions.add(Action("Send usage", "link", "url", true))
|
||||
actions.add(Action("Not now", "link", "url", false))
|
||||
|
||||
notifications.add(
|
||||
Notification(
|
||||
1,
|
||||
"files",
|
||||
"user",
|
||||
date.time,
|
||||
"objectType",
|
||||
"objectId",
|
||||
"Help improve Nextcloud",
|
||||
"SubjectRich",
|
||||
HashMap<String, RichObject>(),
|
||||
"Do you want to help us to improve Nextcloud" +
|
||||
" by providing some anonymize data about your setup and usage?",
|
||||
"MessageRich",
|
||||
HashMap<String, RichObject>(),
|
||||
"link",
|
||||
"icon",
|
||||
actions
|
||||
)
|
||||
)
|
||||
|
||||
sut.runOnUiThread { sut.populateList(notifications) }
|
||||
|
||||
shortSleep()
|
||||
|
||||
screenshot(sut)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun error() {
|
||||
val sut: NotificationsActivity = activityRule.launchActivity(null)
|
||||
|
||||
shortSleep()
|
||||
|
||||
sut.runOnUiThread { sut.setEmptyContent("Error", "Error! Please try again later!") }
|
||||
|
||||
screenshot(sut)
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import android.accounts.AccountManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.nextcloud.client.account.RegisteredUser;
|
||||
import com.nextcloud.client.account.Server;
|
||||
import com.nextcloud.ui.ChooseAccountDialogFragment;
|
||||
@@ -162,6 +161,6 @@ public class DialogFragmentIT extends AbstractIT {
|
||||
getInstrumentation().waitForIdleSync();
|
||||
shortSleep();
|
||||
|
||||
Screenshot.snap(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView()).record();
|
||||
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ package com.owncloud.android.ui.dialog;
|
||||
|
||||
import android.Manifest;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
@@ -32,6 +31,8 @@ import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.rule.GrantPermissionRule;
|
||||
|
||||
@@ -58,7 +59,7 @@ public class SyncFileNotEnoughSpaceDialogFragmentTest extends AbstractIT {
|
||||
|
||||
getInstrumentation().waitForIdleSync();
|
||||
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,6 +73,6 @@ public class SyncFileNotEnoughSpaceDialogFragmentTest extends AbstractIT {
|
||||
|
||||
getInstrumentation().waitForIdleSync();
|
||||
|
||||
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
|
||||
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ package com.owncloud.android.ui.preview;
|
||||
|
||||
import android.Manifest;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
@@ -64,7 +63,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT {
|
||||
|
||||
shortSleep();
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
screenshot(sut);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,6 +81,6 @@ public class PreviewTextFileFragmentTest extends AbstractIT {
|
||||
|
||||
shortSleep();
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
screenshot(sut);
|
||||
}
|
||||
}
|
||||
@@ -325,6 +325,7 @@
|
||||
|
||||
<service android:name=".services.OperationsService" />
|
||||
<service android:name=".files.services.FileDownloader" />
|
||||
<service android:name="com.nextcloud.client.files.downloader.DownloaderService" />
|
||||
<service android:name=".files.services.FileUploader" />
|
||||
<service android:name="com.nextcloud.client.media.PlayerService"/>
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz <[email protected]>
|
||||
* Copyright (C) 2020 Chris Narkiewicz
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.account
|
||||
|
||||
import android.accounts.Account
|
||||
import android.net.Uri
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.owncloud.android.MainApp
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount
|
||||
import com.owncloud.android.lib.common.OwnCloudBasicCredentials
|
||||
import java.net.URI
|
||||
|
||||
/**
|
||||
* This is a mock user object suitable for integration tests. Mocks obtained from code generators
|
||||
* such as Mockito or MockK cannot be transported in Intent extras.
|
||||
*/
|
||||
data class MockUser(override val accountName: String, val accountType: String) : User, Parcelable {
|
||||
|
||||
constructor() : this(DEFAULT_MOCK_ACCOUNT_NAME, DEFAULT_MOCK_ACCOUNT_TYPE)
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<MockUser> = object : Parcelable.Creator<MockUser> {
|
||||
override fun createFromParcel(source: Parcel): MockUser = MockUser(source)
|
||||
override fun newArray(size: Int): Array<MockUser?> = arrayOfNulls(size)
|
||||
}
|
||||
const val DEFAULT_MOCK_ACCOUNT_NAME = "mock_account_name"
|
||||
const val DEFAULT_MOCK_ACCOUNT_TYPE = "mock_account_type"
|
||||
}
|
||||
|
||||
private constructor(source: Parcel) : this(
|
||||
source.readString() as String,
|
||||
source.readString() as String
|
||||
)
|
||||
|
||||
override val server = Server(URI.create(""), MainApp.MINIMUM_SUPPORTED_SERVER_VERSION)
|
||||
override val isAnonymous = false
|
||||
|
||||
override fun toPlatformAccount(): Account {
|
||||
return Account(accountName, accountType)
|
||||
}
|
||||
|
||||
override fun toOwnCloudAccount(): OwnCloudAccount {
|
||||
return OwnCloudAccount(Uri.EMPTY, OwnCloudBasicCredentials("", ""))
|
||||
}
|
||||
|
||||
override fun nameEquals(user: User?): Boolean {
|
||||
return user?.accountName.equals(accountName, true)
|
||||
}
|
||||
|
||||
override fun nameEquals(accountName: CharSequence?): Boolean {
|
||||
return accountName?.toString().equals(this.accountType, true)
|
||||
}
|
||||
|
||||
override fun describeContents() = 0
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) {
|
||||
writeString(accountName)
|
||||
writeString(accountType)
|
||||
}
|
||||
}
|
||||
@@ -19,23 +19,53 @@
|
||||
*/
|
||||
package com.nextcloud.client.core
|
||||
|
||||
typealias OnResultCallback<T> = (T) -> Unit
|
||||
typealias OnErrorCallback = (Throwable) -> Unit
|
||||
typealias OnResultCallback<T> = (result: T) -> Unit
|
||||
typealias OnErrorCallback = (error: Throwable) -> Unit
|
||||
typealias OnProgressCallback<P> = (progress: P) -> Unit
|
||||
typealias IsCancelled = () -> Boolean
|
||||
typealias TaskFunction<RESULT, PROGRESS> = (
|
||||
onProgress: OnProgressCallback<PROGRESS>,
|
||||
isCancelled: IsCancelled
|
||||
) -> RESULT
|
||||
|
||||
/**
|
||||
* This interface allows to post background tasks that report results via callbacks invoked on main thread.
|
||||
*
|
||||
* It is provided as an alternative for heavy, platform specific and virtually untestable [android.os.AsyncTask]
|
||||
*
|
||||
* Please note that as of Android R, [android.os.AsyncTask] is deprecated and [java.util.concurrent] is a recommended
|
||||
* alternative.
|
||||
*/
|
||||
interface AsyncRunner {
|
||||
|
||||
/**
|
||||
* Post a quick background task and return immediately returning task cancellation interface.
|
||||
*
|
||||
* Quick task is a short piece of code that does not support interruption nor progress monitoring.
|
||||
*
|
||||
* @param task Task function returning result T; error shall be signalled by throwing an exception.
|
||||
* @param onResult Callback called when task function returns a result.
|
||||
* @param onError Callback called when task function throws an exception.
|
||||
* @return Cancellable interface, allowing cancellation of a running task.
|
||||
*/
|
||||
fun <RESULT> postQuickTask(
|
||||
task: () -> RESULT,
|
||||
onResult: OnResultCallback<RESULT>? = null,
|
||||
onError: OnErrorCallback? = null
|
||||
): Cancellable
|
||||
|
||||
/**
|
||||
* Post a background task and return immediately returning task cancellation interface.
|
||||
*
|
||||
* @param task Task function returning result T; error shall be signalled by throwing an exception.
|
||||
* @param onResult Callback called when task function returns a result
|
||||
* @param onError Callback called when task function throws an exception
|
||||
* @return Cancellable interface, allowing to cancel running task.
|
||||
* @param onResult Callback called when task function returns a result,
|
||||
* @param onError Callback called when task function throws an exception.
|
||||
* @param onProgress Callback called when task function reports progress update.
|
||||
* @return Cancellable interface, allowing cancellation of a running task.
|
||||
*/
|
||||
fun <T> post(task: () -> T, onResult: OnResultCallback<T>? = null, onError: OnErrorCallback? = null): Cancellable
|
||||
fun <RESULT, PROGRESS> postTask(
|
||||
task: TaskFunction<RESULT, PROGRESS>,
|
||||
onResult: OnResultCallback<RESULT>? = null,
|
||||
onError: OnErrorCallback? = null,
|
||||
onProgress: OnProgressCallback<PROGRESS>? = null
|
||||
): Cancellable
|
||||
}
|
||||
@@ -31,8 +31,8 @@ package com.nextcloud.client.core
|
||||
interface Cancellable {
|
||||
|
||||
/**
|
||||
* Cancel running task. Task termination is not guaranteed, but the result
|
||||
* shall not be delivered.
|
||||
* Cancel running task. Task termination is not guaranteed, as some
|
||||
* tasks cannot be interrupted, but the result will not be delivered.
|
||||
*/
|
||||
fun cancel()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.core
|
||||
|
||||
import android.app.Service
|
||||
import android.os.Binder
|
||||
|
||||
/**
|
||||
* This is a generic binder that provides access to a locally bound service instance.
|
||||
*/
|
||||
abstract class LocalBinder<S : Service>(val service: S) : Binder()
|
||||
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.core
|
||||
|
||||
import android.app.Service
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import android.os.IBinder
|
||||
|
||||
/**
|
||||
* This is a local service connection providing a foundation for service
|
||||
* communication logic.
|
||||
*
|
||||
* One can subclass it to create own service interaction API.
|
||||
*/
|
||||
abstract class LocalConnection<S : Service>(
|
||||
protected val context: Context
|
||||
) : ServiceConnection {
|
||||
|
||||
private var serviceBinder: LocalBinder<S>? = null
|
||||
val service: S? get() = serviceBinder?.service
|
||||
val isConnected: Boolean get() {
|
||||
return serviceBinder != null
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to create custom binding intent.
|
||||
* Default implementation returns null, which disables binding.
|
||||
*
|
||||
* @see [bind]
|
||||
*/
|
||||
protected open fun createBindIntent(): Intent? {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind local service. If [createBindIntent] returns null, it no-ops.
|
||||
*/
|
||||
fun bind() {
|
||||
createBindIntent()?.let {
|
||||
context.bindService(it, this, Context.BIND_AUTO_CREATE)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbind service if it is bound.
|
||||
* If service is not bound, it no-ops.
|
||||
*/
|
||||
fun unbind() {
|
||||
if (isConnected) {
|
||||
onUnbind()
|
||||
context.unbindService(this)
|
||||
serviceBinder = null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when connection binds to a service.
|
||||
* Any actions taken on service connection can be taken here.
|
||||
*/
|
||||
protected open fun onBound(binder: IBinder) {
|
||||
// default no-op
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called when service is about to be unbound.
|
||||
* Binder is still valid at this stage and can be used to
|
||||
* perform cleanups. After exiting this method, service will
|
||||
* no longer be available.
|
||||
*/
|
||||
protected open fun onUnbind() {
|
||||
// default no-op
|
||||
}
|
||||
|
||||
final override fun onServiceConnected(name: ComponentName, binder: IBinder) {
|
||||
if (binder !is LocalBinder<*>) {
|
||||
throw IllegalStateException("Binder is not extending ${LocalBinder::class.java.name}")
|
||||
}
|
||||
serviceBinder = binder as LocalBinder<S>
|
||||
onBound(binder)
|
||||
}
|
||||
|
||||
final override fun onServiceDisconnected(name: ComponentName) {
|
||||
serviceBinder = null
|
||||
}
|
||||
}
|
||||
@@ -27,14 +27,35 @@ import java.util.ArrayDeque
|
||||
*/
|
||||
class ManualAsyncRunner : AsyncRunner {
|
||||
|
||||
private val queue: ArrayDeque<Task<*>> = ArrayDeque()
|
||||
private val queue: ArrayDeque<Runnable> = ArrayDeque()
|
||||
|
||||
override fun <T> post(task: () -> T, onResult: OnResultCallback<T>?, onError: OnErrorCallback?): Cancellable {
|
||||
override fun <T> postQuickTask(
|
||||
task: () -> T,
|
||||
onResult: OnResultCallback<T>?,
|
||||
onError: OnErrorCallback?
|
||||
): Cancellable {
|
||||
return postTask(
|
||||
task = { _: OnProgressCallback<Any>, _: IsCancelled -> task.invoke() },
|
||||
onResult = onResult,
|
||||
onError = onError,
|
||||
onProgress = null
|
||||
)
|
||||
}
|
||||
|
||||
override fun <T, P> postTask(
|
||||
task: TaskFunction<T, P>,
|
||||
onResult: OnResultCallback<T>?,
|
||||
onError: OnErrorCallback?,
|
||||
onProgress: OnProgressCallback<P>?
|
||||
): Cancellable {
|
||||
val remove: Function1<Runnable, Boolean> = queue::remove
|
||||
val taskWrapper = Task(
|
||||
postResult = { it.run() },
|
||||
postResult = { it.run(); true },
|
||||
removeFromQueue = remove,
|
||||
taskBody = task,
|
||||
onSuccess = onResult,
|
||||
onError = onError
|
||||
onError = onError,
|
||||
onProgress = onProgress
|
||||
)
|
||||
queue.push(taskWrapper)
|
||||
return taskWrapper
|
||||
|
||||
@@ -22,23 +22,32 @@ package com.nextcloud.client.core
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
/**
|
||||
* This is a wrapper for a function run in background.
|
||||
*
|
||||
* Runs task function and posts result if task is not cancelled.
|
||||
* This is a wrapper for a task function runing in background.
|
||||
* It executes task function and handles result or error delivery.
|
||||
*/
|
||||
internal class Task<T>(
|
||||
private val postResult: (Runnable) -> Unit,
|
||||
private val taskBody: () -> T,
|
||||
@Suppress("LongParameterList")
|
||||
internal class Task<T, P>(
|
||||
private val postResult: (Runnable) -> Boolean,
|
||||
private val removeFromQueue: (Runnable) -> Boolean,
|
||||
private val taskBody: TaskFunction<T, P>,
|
||||
private val onSuccess: OnResultCallback<T>?,
|
||||
private val onError: OnErrorCallback?
|
||||
private val onError: OnErrorCallback?,
|
||||
private val onProgress: OnProgressCallback<P>?
|
||||
) : Runnable, Cancellable {
|
||||
|
||||
val isCancelled: Boolean
|
||||
get() = cancelled.get()
|
||||
|
||||
private val cancelled = AtomicBoolean(false)
|
||||
|
||||
private fun postProgress(p: P) {
|
||||
postResult(Runnable { onProgress?.invoke(p) })
|
||||
}
|
||||
|
||||
@Suppress("TooGenericExceptionCaught") // this is exactly what we want here
|
||||
override fun run() {
|
||||
@Suppress("TooGenericExceptionCaught") // this is exactly what we want here
|
||||
try {
|
||||
val result = taskBody.invoke()
|
||||
val result = taskBody.invoke({ postProgress(it) }, this::isCancelled)
|
||||
if (!cancelled.get()) {
|
||||
postResult.invoke(
|
||||
Runnable {
|
||||
@@ -51,9 +60,11 @@ internal class Task<T>(
|
||||
postResult(Runnable { onError?.invoke(t) })
|
||||
}
|
||||
}
|
||||
removeFromQueue(this)
|
||||
}
|
||||
|
||||
override fun cancel() {
|
||||
cancelled.set(true)
|
||||
removeFromQueue(this)
|
||||
}
|
||||
}
|
||||
@@ -28,17 +28,44 @@ import java.util.concurrent.ScheduledThreadPoolExecutor
|
||||
*
|
||||
* Tasks are run on multi-threaded pool. If serialized execution is desired, set [corePoolSize] to 1.
|
||||
*/
|
||||
internal class ThreadPoolAsyncRunner(private val uiThreadHandler: Handler, corePoolSize: Int) : AsyncRunner {
|
||||
internal class ThreadPoolAsyncRunner(
|
||||
private val uiThreadHandler: Handler,
|
||||
corePoolSize: Int,
|
||||
val tag: String = "default"
|
||||
) : AsyncRunner {
|
||||
|
||||
private val executor = ScheduledThreadPoolExecutor(corePoolSize)
|
||||
|
||||
override fun <T> post(task: () -> T, onResult: OnResultCallback<T>?, onError: OnErrorCallback?): Cancellable {
|
||||
val taskWrapper = Task(this::postResult, task, onResult, onError)
|
||||
override fun <T> postQuickTask(
|
||||
task: () -> T,
|
||||
onResult: OnResultCallback<T>?,
|
||||
onError: OnErrorCallback?
|
||||
): Cancellable {
|
||||
val taskAdapter = { _: OnProgressCallback<Void>, _: IsCancelled -> task.invoke() }
|
||||
return postTask(
|
||||
taskAdapter,
|
||||
onResult,
|
||||
onError,
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
override fun <T, P> postTask(
|
||||
task: TaskFunction<T, P>,
|
||||
onResult: OnResultCallback<T>?,
|
||||
onError: OnErrorCallback?,
|
||||
onProgress: OnProgressCallback<P>?
|
||||
): Cancellable {
|
||||
val remove: Function1<Runnable, Boolean> = executor::remove
|
||||
val taskWrapper = Task(
|
||||
postResult = uiThreadHandler::post,
|
||||
removeFromQueue = remove,
|
||||
taskBody = task,
|
||||
onSuccess = onResult,
|
||||
onError = onError,
|
||||
onProgress = onProgress
|
||||
)
|
||||
executor.execute(taskWrapper)
|
||||
return taskWrapper
|
||||
}
|
||||
|
||||
private fun postResult(r: Runnable) {
|
||||
uiThreadHandler.post(r)
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,8 @@ import com.nextcloud.client.migrations.MigrationsDb;
|
||||
import com.nextcloud.client.migrations.MigrationsManager;
|
||||
import com.nextcloud.client.migrations.MigrationsManagerImpl;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.nextcloud.client.notifications.AppNotificationManager;
|
||||
import com.nextcloud.client.notifications.AppNotificationManagerImpl;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.datamodel.UploadsStorageManager;
|
||||
import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository;
|
||||
@@ -63,6 +65,7 @@ import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
@@ -164,9 +167,17 @@ class AppModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
AsyncRunner asyncRunner() {
|
||||
AsyncRunner uiAsyncRunner() {
|
||||
Handler uiHandler = new Handler();
|
||||
return new ThreadPoolAsyncRunner(uiHandler, 4);
|
||||
return new ThreadPoolAsyncRunner(uiHandler, 4, "ui");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("io")
|
||||
AsyncRunner ioAsyncRunner() {
|
||||
Handler uiHandler = new Handler();
|
||||
return new ThreadPoolAsyncRunner(uiHandler, 8, "io");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@@ -200,4 +211,10 @@ class AppModule {
|
||||
Migrations migrations) {
|
||||
return new MigrationsManagerImpl(appInfo, migrationsDb, asyncRunner, migrations.getSteps());
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
AppNotificationManager notificationsManager(Context context, NotificationManager platformNotificationsManager) {
|
||||
return new AppNotificationManagerImpl(context, context.getResources(), platformNotificationsManager);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ package com.nextcloud.client.di;
|
||||
|
||||
import com.nextcloud.client.etm.EtmActivity;
|
||||
import com.nextcloud.client.jobs.NotificationWork;
|
||||
import com.nextcloud.client.files.downloader.DownloaderService;
|
||||
import com.nextcloud.client.logger.ui.LogsActivity;
|
||||
import com.nextcloud.client.media.PlayerService;
|
||||
import com.nextcloud.client.onboarding.FirstRunActivity;
|
||||
@@ -168,4 +169,5 @@ abstract class ComponentsModule {
|
||||
@ContributesAndroidInjector abstract AccountManagerService accountManagerService();
|
||||
@ContributesAndroidInjector abstract OperationsService operationsService();
|
||||
@ContributesAndroidInjector abstract PlayerService playerService();
|
||||
@ContributesAndroidInjector abstract DownloaderService fileDownloaderService();
|
||||
}
|
||||
@@ -21,15 +21,21 @@ package com.nextcloud.client.etm
|
||||
|
||||
import android.accounts.Account
|
||||
import android.accounts.AccountManager
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Resources
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.nextcloud.client.account.User
|
||||
import com.nextcloud.client.account.UserAccountManager
|
||||
import com.nextcloud.client.etm.pages.EtmAccountsFragment
|
||||
import com.nextcloud.client.etm.pages.EtmBackgroundJobsFragment
|
||||
import com.nextcloud.client.etm.pages.EtmDownloaderFragment
|
||||
import com.nextcloud.client.etm.pages.EtmMigrations
|
||||
import com.nextcloud.client.etm.pages.EtmPreferencesFragment
|
||||
import com.nextcloud.client.files.downloader.DownloaderConnection
|
||||
import com.nextcloud.client.jobs.BackgroundJobManager
|
||||
import com.nextcloud.client.jobs.JobInfo
|
||||
import com.nextcloud.client.migrations.MigrationInfo
|
||||
@@ -40,9 +46,12 @@ import com.owncloud.android.lib.common.accounts.AccountUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
@Suppress("LongParameterList") // Dependencies Injection
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
class EtmViewModel @Inject constructor(
|
||||
private val context: Context,
|
||||
private val defaultPreferences: SharedPreferences,
|
||||
private val platformAccountManager: AccountManager,
|
||||
private val accountManager: UserAccountManager,
|
||||
private val resources: Resources,
|
||||
private val backgroundJobManager: BackgroundJobManager,
|
||||
private val migrationsManager: MigrationsManager,
|
||||
@@ -71,6 +80,7 @@ class EtmViewModel @Inject constructor(
|
||||
*/
|
||||
data class AccountData(val account: Account, val userData: Map<String, String?>)
|
||||
|
||||
val currentUser: User get() = accountManager.user
|
||||
val currentPage: LiveData<EtmMenuEntry?> = MutableLiveData()
|
||||
val pages: List<EtmMenuEntry> = listOf(
|
||||
EtmMenuEntry(
|
||||
@@ -92,8 +102,14 @@ class EtmViewModel @Inject constructor(
|
||||
iconRes = R.drawable.ic_arrow_up,
|
||||
titleRes = R.string.etm_migrations,
|
||||
pageClass = EtmMigrations::class
|
||||
),
|
||||
EtmMenuEntry(
|
||||
iconRes = R.drawable.ic_download_grey600,
|
||||
titleRes = R.string.etm_downloader,
|
||||
pageClass = EtmDownloaderFragment::class
|
||||
)
|
||||
)
|
||||
val downloaderConnection = DownloaderConnection(context, accountManager.user)
|
||||
|
||||
val preferences: Map<String, String> get() {
|
||||
return defaultPreferences.all
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.nextcloud.client.etm.pages
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.nextcloud.client.etm.EtmBaseFragment
|
||||
import com.nextcloud.client.files.downloader.Download
|
||||
import com.nextcloud.client.files.downloader.Downloader
|
||||
import com.nextcloud.client.files.downloader.Request
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
|
||||
class EtmDownloaderFragment : EtmBaseFragment() {
|
||||
|
||||
companion object {
|
||||
private const val TEST_DOWNLOAD_DUMMY_PATH = "/test/dummy_file.txt"
|
||||
}
|
||||
|
||||
class Adapter(private val inflater: LayoutInflater) : RecyclerView.Adapter<Adapter.ViewHolder>() {
|
||||
|
||||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val uuid = view.findViewById<TextView>(R.id.etm_download_uuid)
|
||||
val path = view.findViewById<TextView>(R.id.etm_download_path)
|
||||
val user = view.findViewById<TextView>(R.id.etm_download_user)
|
||||
val state = view.findViewById<TextView>(R.id.etm_download_state)
|
||||
val progress = view.findViewById<TextView>(R.id.etm_download_progress)
|
||||
private val progressRow = view.findViewById<View>(R.id.etm_download_progress_row)
|
||||
|
||||
var progressEnabled: Boolean = progressRow.visibility == View.VISIBLE
|
||||
get() {
|
||||
return progressRow.visibility == View.VISIBLE
|
||||
}
|
||||
set(value) {
|
||||
field = value
|
||||
progressRow.visibility = if (value) {
|
||||
View.VISIBLE
|
||||
} else {
|
||||
View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var downloads = listOf<Download>()
|
||||
|
||||
fun setStatus(status: Downloader.Status) {
|
||||
downloads = listOf(status.pending, status.running, status.completed).flatten().reversed()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = inflater.inflate(R.layout.etm_download_list_item, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return downloads.size
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(vh: ViewHolder, position: Int) {
|
||||
val download = downloads[position]
|
||||
vh.uuid.text = download.uuid.toString()
|
||||
vh.path.text = download.request.file.remotePath
|
||||
vh.user.text = download.request.user.accountName
|
||||
vh.state.text = download.state.toString()
|
||||
if (download.progress >= 0) {
|
||||
vh.progressEnabled = true
|
||||
vh.progress.text = download.progress.toString()
|
||||
} else {
|
||||
vh.progressEnabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var adapter: Adapter
|
||||
private lateinit var list: RecyclerView
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val view = inflater.inflate(R.layout.fragment_etm_downloader, container, false)
|
||||
adapter = Adapter(inflater)
|
||||
list = view.findViewById(R.id.etm_download_list)
|
||||
list.layoutManager = LinearLayoutManager(context)
|
||||
list.addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
|
||||
list.adapter = adapter
|
||||
return view
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
vm.downloaderConnection.bind()
|
||||
vm.downloaderConnection.registerStatusListener(this::onDownloaderStatusChanged)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
vm.downloaderConnection.unbind()
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
inflater.inflate(R.menu.fragment_etm_downloader, menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.etm_test_download -> {
|
||||
scheduleTestDownload(); true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
private fun scheduleTestDownload() {
|
||||
val request = Request(user = vm.currentUser, file = OCFile(TEST_DOWNLOAD_DUMMY_PATH), test = true)
|
||||
vm.downloaderConnection.download(request)
|
||||
}
|
||||
|
||||
private fun onDownloaderStatusChanged(status: Downloader.Status) {
|
||||
adapter.setStatus(status)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import java.util.UUID
|
||||
|
||||
/**
|
||||
* This class represents current download process state.
|
||||
* This object is immutable by design.
|
||||
*
|
||||
* NOTE: Although [OCFile] object is mutable, it is caused by shortcomings
|
||||
* of legacy design; please behave like an adult and treat it as immutable value.
|
||||
*
|
||||
* @property uuid Unique download process id
|
||||
* @property state current download state
|
||||
* @property progress download progress, 0-100 percent
|
||||
* @property file downloaded file, if download is in progress or failed, it is remote; if finished successfully - local
|
||||
* @property request initial download request
|
||||
*/
|
||||
data class Download(
|
||||
val uuid: UUID,
|
||||
val state: DownloadState,
|
||||
val progress: Int,
|
||||
val file: OCFile,
|
||||
val request: Request
|
||||
) {
|
||||
/**
|
||||
* True if download is no longer running, false if it is still being processed.
|
||||
*/
|
||||
val isFinished: Boolean get() = state == DownloadState.COMPLETED || state == DownloadState.FAILED
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
enum class DownloadState {
|
||||
PENDING,
|
||||
RUNNING,
|
||||
COMPLETED,
|
||||
FAILED
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import com.nextcloud.client.core.IsCancelled
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.common.OwnCloudClient
|
||||
import com.owncloud.android.operations.DownloadFileOperation
|
||||
import com.owncloud.android.utils.MimeTypeUtil
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* This runnable object encapsulates file download logic. It has been extracted to wrap
|
||||
* network operation and storage manager interactions, as those pose testing challenges
|
||||
* that cannot be addressed due to large number of dependencies.
|
||||
*
|
||||
* This design can be regarded as intermediary refactoring step.
|
||||
*/
|
||||
class DownloadTask(
|
||||
val context: Context,
|
||||
val contentResolver: ContentResolver,
|
||||
val clientProvider: () -> OwnCloudClient
|
||||
) {
|
||||
|
||||
data class Result(val file: OCFile, val success: Boolean)
|
||||
|
||||
/**
|
||||
* This class is a helper factory to to keep static dependencies
|
||||
* injection out of the downloader instance.
|
||||
*
|
||||
* @param context Context
|
||||
* @param clientProvider Provide client - this must be called on background thread
|
||||
* @param contentResolver content resovler used to access file storage
|
||||
*/
|
||||
class Factory(
|
||||
private val context: Context,
|
||||
private val clientProvider: () -> OwnCloudClient,
|
||||
private val contentResolver: ContentResolver
|
||||
) {
|
||||
fun create(): DownloadTask {
|
||||
return DownloadTask(context, contentResolver, clientProvider)
|
||||
}
|
||||
}
|
||||
|
||||
fun download(request: Request, progress: (Int) -> Unit, isCancelled: IsCancelled): Result {
|
||||
val op = DownloadFileOperation(request.user.toPlatformAccount(), request.file, context)
|
||||
val client = clientProvider.invoke()
|
||||
val result = op.execute(client)
|
||||
if (result.isSuccess) {
|
||||
val storageManager = FileDataStorageManager(
|
||||
request.user.toPlatformAccount(),
|
||||
contentResolver
|
||||
)
|
||||
val file = saveDownloadedFile(op, storageManager)
|
||||
return Result(file, true)
|
||||
} else {
|
||||
return Result(request.file, false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveDownloadedFile(op: DownloadFileOperation, storageManager: FileDataStorageManager): OCFile {
|
||||
val file = storageManager.getFileById(op.getFile().getFileId()) as OCFile
|
||||
val syncDate = System.currentTimeMillis()
|
||||
file.lastSyncDateForProperties = syncDate
|
||||
file.lastSyncDateForData = syncDate
|
||||
file.isUpdateThumbnailNeeded = true
|
||||
file.modificationTimestamp = op.getModificationTimestamp()
|
||||
file.modificationTimestampAtLastSyncForData = op.getModificationTimestamp()
|
||||
file.etag = op.getEtag()
|
||||
file.mimeType = op.getMimeType()
|
||||
file.storagePath = op.getSavePath()
|
||||
file.fileLength = File(op.getSavePath()).length()
|
||||
file.remoteId = op.getFile().getRemoteId()
|
||||
storageManager.saveFile(file)
|
||||
if (MimeTypeUtil.isMedia(op.getMimeType())) {
|
||||
FileDataStorageManager.triggerMediaScan(file.storagePath)
|
||||
}
|
||||
return file
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import java.util.UUID
|
||||
|
||||
interface Downloader {
|
||||
|
||||
/**
|
||||
* Snapshot of downloader status. All data is immutable and can be safely shared.
|
||||
*/
|
||||
data class Status(
|
||||
val pending: List<Download>,
|
||||
val running: List<Download>,
|
||||
val completed: List<Download>
|
||||
) {
|
||||
companion object {
|
||||
val EMPTY = Status(emptyList(), emptyList(), emptyList())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True if downloader has any pending or running downloads.
|
||||
*/
|
||||
val isRunning: Boolean
|
||||
|
||||
/**
|
||||
* Status snapshot of all downloads.
|
||||
*/
|
||||
val status: Status
|
||||
|
||||
/**
|
||||
* Register download progress listener. Registration is idempotent - listener can be registered only once.
|
||||
*/
|
||||
fun registerDownloadListener(listener: (Download) -> Unit)
|
||||
|
||||
/**
|
||||
* Removes registered listener if exists.
|
||||
*/
|
||||
fun removeDownloadListener(listener: (Download) -> Unit)
|
||||
|
||||
/**
|
||||
* Register downloader status listener. Registration is idempotent - listener can be registered only once.
|
||||
*/
|
||||
fun registerStatusListener(listener: (Status) -> Unit)
|
||||
|
||||
/**
|
||||
* Removes registered listener if exists.
|
||||
*/
|
||||
fun removeStatusListener(listener: (Status) -> Unit)
|
||||
|
||||
/**
|
||||
* Adds download request to pending queue and returns immediately.
|
||||
*
|
||||
* @param request Download request
|
||||
*/
|
||||
fun download(request: Request)
|
||||
|
||||
/**
|
||||
* Find download status by UUID.
|
||||
*
|
||||
* @param uuid Download process uuid
|
||||
* @return download status or null if not found
|
||||
*/
|
||||
fun getDownload(uuid: UUID): Download?
|
||||
|
||||
/**
|
||||
* Query user's downloader for a download status. It performs linear search
|
||||
* of all queues and returns first download matching [OCFile.remotePath].
|
||||
*
|
||||
* Since there can be multiple downloads with identical file in downloader's queues,
|
||||
* order of search matters.
|
||||
*
|
||||
* It looks for pending downloads first, then running and completed queue last.
|
||||
*
|
||||
* @param file Downloaded file
|
||||
* @return download status or null, if download does not exist
|
||||
*/
|
||||
fun getDownload(file: OCFile): Download?
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.IBinder
|
||||
import com.nextcloud.client.account.User
|
||||
import com.nextcloud.client.core.LocalConnection
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import java.util.UUID
|
||||
|
||||
class DownloaderConnection(context: Context, val user: User) : LocalConnection<DownloaderService>(context), Downloader {
|
||||
|
||||
private var downloadListeners: MutableSet<(Download) -> Unit> = mutableSetOf()
|
||||
private var statusListeners: MutableSet<(Downloader.Status) -> Unit> = mutableSetOf()
|
||||
private var binder: DownloaderService.Binder? = null
|
||||
private val downloadsRequiringStatusRedelivery: MutableSet<UUID> = mutableSetOf()
|
||||
|
||||
override val isRunning: Boolean
|
||||
get() = binder?.isRunning ?: false
|
||||
|
||||
override val status: Downloader.Status
|
||||
get() = binder?.status ?: Downloader.Status.EMPTY
|
||||
|
||||
override fun getDownload(uuid: UUID): Download? = binder?.getDownload(uuid)
|
||||
|
||||
override fun getDownload(file: OCFile): Download? = binder?.getDownload(file)
|
||||
|
||||
override fun download(request: Request) {
|
||||
val intent = DownloaderService.createDownloadIntent(context, request)
|
||||
context.startService(intent)
|
||||
if (!isConnected && downloadListeners.size > 0) {
|
||||
downloadsRequiringStatusRedelivery.add(request.uuid)
|
||||
}
|
||||
}
|
||||
|
||||
override fun registerDownloadListener(listener: (Download) -> Unit) {
|
||||
downloadListeners.add(listener)
|
||||
binder?.registerDownloadListener(listener)
|
||||
}
|
||||
|
||||
override fun removeDownloadListener(listener: (Download) -> Unit) {
|
||||
downloadListeners.remove(listener)
|
||||
binder?.removeDownloadListener(listener)
|
||||
}
|
||||
|
||||
override fun registerStatusListener(listener: (Downloader.Status) -> Unit) {
|
||||
statusListeners.add(listener)
|
||||
binder?.registerStatusListener(listener)
|
||||
}
|
||||
|
||||
override fun removeStatusListener(listener: (Downloader.Status) -> Unit) {
|
||||
statusListeners.remove(listener)
|
||||
binder?.removeStatusListener(listener)
|
||||
}
|
||||
|
||||
override fun createBindIntent(): Intent {
|
||||
return DownloaderService.createBindIntent(context, user)
|
||||
}
|
||||
|
||||
override fun onBound(binder: IBinder) {
|
||||
super.onBound(binder)
|
||||
this.binder = binder as DownloaderService.Binder
|
||||
downloadListeners.forEach { listener ->
|
||||
binder.registerDownloadListener(listener)
|
||||
}
|
||||
statusListeners.forEach { listener ->
|
||||
binder.registerStatusListener(listener)
|
||||
}
|
||||
deliverMissedUpdates()
|
||||
}
|
||||
|
||||
/**
|
||||
* Since binding and download start are both asynchronous and the order
|
||||
* is not guaranteed, some downloads might already finish when service is bound,
|
||||
* resulting in lost notifications.
|
||||
*
|
||||
* Deliver all updates for pending downloads that were scheduled
|
||||
* before service has been bound.
|
||||
*/
|
||||
private fun deliverMissedUpdates() {
|
||||
val downloadUpdates = downloadsRequiringStatusRedelivery.mapNotNull { uuid ->
|
||||
binder?.getDownload(uuid)
|
||||
}
|
||||
downloadListeners.forEach { listener ->
|
||||
downloadUpdates.forEach { update ->
|
||||
listener.invoke(update)
|
||||
}
|
||||
}
|
||||
downloadsRequiringStatusRedelivery.clear()
|
||||
|
||||
if (statusListeners.isNotEmpty()) {
|
||||
binder?.status?.let { status ->
|
||||
statusListeners.forEach { it.invoke(status) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onUnbind() {
|
||||
super.onUnbind()
|
||||
downloadListeners.forEach { binder?.removeDownloadListener(it) }
|
||||
statusListeners.forEach { binder?.removeStatusListener(it) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
import com.nextcloud.client.core.AsyncRunner
|
||||
import com.nextcloud.client.core.IsCancelled
|
||||
import com.nextcloud.client.core.OnProgressCallback
|
||||
import com.nextcloud.client.core.TaskFunction
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import java.util.UUID
|
||||
|
||||
/**
|
||||
* Per-user file downloader.
|
||||
*
|
||||
* All notifications are performed on main thread. All download processes are run
|
||||
* in the background.
|
||||
*
|
||||
* @param runner Background task runner. It is important to provide runner that is not shared with UI code.
|
||||
* @param taskFactory Download task factory
|
||||
* @param threads maximum number of concurrent download processes
|
||||
*/
|
||||
@Suppress("LongParameterList") // download operations requires those resources
|
||||
class DownloaderImpl(
|
||||
private val runner: AsyncRunner,
|
||||
private val taskFactory: DownloadTask.Factory,
|
||||
threads: Int = 1
|
||||
) : Downloader {
|
||||
|
||||
companion object {
|
||||
const val PROGRESS_PERCENTAGE_MAX = 100
|
||||
const val PROGRESS_PERCENTAGE_MIN = 0
|
||||
const val TEST_DOWNLOAD_PROGRESS_UPDATE_PERIOD_MS = 200L
|
||||
}
|
||||
|
||||
private val registry = Registry(
|
||||
onStartDownload = this::onStartDownload,
|
||||
onDownloadChanged = this::onDownloadUpdate,
|
||||
maxRunning = threads
|
||||
)
|
||||
private val downloadListeners: MutableSet<(Download) -> Unit> = mutableSetOf()
|
||||
private val statusListeners: MutableSet<(Downloader.Status) -> Unit> = mutableSetOf()
|
||||
|
||||
override val isRunning: Boolean get() = registry.isRunning
|
||||
|
||||
override val status: Downloader.Status
|
||||
get() = Downloader.Status(
|
||||
pending = registry.pending,
|
||||
running = registry.running,
|
||||
completed = registry.completed
|
||||
)
|
||||
|
||||
override fun registerDownloadListener(listener: (Download) -> Unit) {
|
||||
downloadListeners.add(listener)
|
||||
}
|
||||
|
||||
override fun removeDownloadListener(listener: (Download) -> Unit) {
|
||||
downloadListeners.remove(listener)
|
||||
}
|
||||
|
||||
override fun registerStatusListener(listener: (Downloader.Status) -> Unit) {
|
||||
statusListeners.add(listener)
|
||||
}
|
||||
|
||||
override fun removeStatusListener(listener: (Downloader.Status) -> Unit) {
|
||||
statusListeners.remove(listener)
|
||||
}
|
||||
|
||||
override fun download(request: Request) {
|
||||
registry.add(request)
|
||||
registry.startNext()
|
||||
}
|
||||
|
||||
override fun getDownload(uuid: UUID): Download? = registry.getDownload(uuid)
|
||||
|
||||
override fun getDownload(file: OCFile): Download? = registry.getDownload(file)
|
||||
|
||||
private fun onStartDownload(uuid: UUID, request: Request) {
|
||||
val downloadTask = createDownloadTask(request)
|
||||
runner.postTask(
|
||||
task = downloadTask,
|
||||
onProgress = { progress: Int -> registry.progress(uuid, progress) },
|
||||
onResult = { result -> registry.complete(uuid, result.success, result.file); registry.startNext() },
|
||||
onError = { registry.complete(uuid, false); registry.startNext() }
|
||||
)
|
||||
}
|
||||
|
||||
private fun createDownloadTask(request: Request): TaskFunction<DownloadTask.Result, Int> {
|
||||
return if (request.test) {
|
||||
{ progress: OnProgressCallback<Int>, isCancelled: IsCancelled ->
|
||||
testDownloadTask(request.file, progress, isCancelled)
|
||||
}
|
||||
} else {
|
||||
val downloadTask = taskFactory.create()
|
||||
val wrapper: TaskFunction<DownloadTask.Result, Int> = { progress: ((Int) -> Unit), isCancelled ->
|
||||
downloadTask.download(request, progress, isCancelled)
|
||||
}
|
||||
wrapper
|
||||
}
|
||||
}
|
||||
|
||||
private fun onDownloadUpdate(download: Download) {
|
||||
downloadListeners.forEach { it.invoke(download) }
|
||||
if (statusListeners.isNotEmpty()) {
|
||||
val status = this.status
|
||||
statusListeners.forEach { it.invoke(status) }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test download task is used only to simulate download process without
|
||||
* any network traffic. It is used for development.
|
||||
*/
|
||||
private fun testDownloadTask(
|
||||
file: OCFile,
|
||||
onProgress: OnProgressCallback<Int>,
|
||||
isCancelled: IsCancelled
|
||||
): DownloadTask.Result {
|
||||
for (i in PROGRESS_PERCENTAGE_MIN..PROGRESS_PERCENTAGE_MAX) {
|
||||
onProgress(i)
|
||||
if (isCancelled()) {
|
||||
return DownloadTask.Result(file, false)
|
||||
}
|
||||
Thread.sleep(TEST_DOWNLOAD_PROGRESS_UPDATE_PERIOD_MS)
|
||||
}
|
||||
return DownloadTask.Result(file, true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.IBinder
|
||||
import com.nextcloud.client.account.User
|
||||
import com.nextcloud.client.core.AsyncRunner
|
||||
import com.nextcloud.client.core.LocalBinder
|
||||
import com.nextcloud.client.logger.Logger
|
||||
import com.nextcloud.client.network.ClientFactory
|
||||
import com.nextcloud.client.notifications.AppNotificationManager
|
||||
import dagger.android.AndroidInjection
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
|
||||
class DownloaderService : Service() {
|
||||
|
||||
companion object {
|
||||
const val TAG = "DownloaderService"
|
||||
const val ACTION_DOWNLOAD = "download"
|
||||
const val EXTRA_REQUEST = "request"
|
||||
const val EXTRA_USER = "user"
|
||||
|
||||
fun createBindIntent(context: Context, user: User): Intent {
|
||||
return Intent(context, DownloaderService::class.java).apply {
|
||||
putExtra(EXTRA_USER, user)
|
||||
}
|
||||
}
|
||||
|
||||
fun createDownloadIntent(context: Context, request: Request): Intent {
|
||||
return Intent(context, DownloaderService::class.java).apply {
|
||||
action = ACTION_DOWNLOAD
|
||||
putExtra(EXTRA_REQUEST, request)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Binder forwards [Downloader] API calls to selected instance of downloader.
|
||||
*/
|
||||
class Binder(
|
||||
downloader: DownloaderImpl,
|
||||
service: DownloaderService
|
||||
) : LocalBinder<DownloaderService>(service),
|
||||
Downloader by downloader
|
||||
|
||||
@Inject
|
||||
lateinit var notificationsManager: AppNotificationManager
|
||||
|
||||
@Inject
|
||||
lateinit var clientFactory: ClientFactory
|
||||
|
||||
@Inject
|
||||
@Named("io")
|
||||
lateinit var runner: AsyncRunner
|
||||
|
||||
@Inject
|
||||
lateinit var logger: Logger
|
||||
|
||||
val isRunning: Boolean get() = downloaders.any { it.value.isRunning }
|
||||
|
||||
private val downloaders: MutableMap<String, DownloaderImpl> = mutableMapOf()
|
||||
|
||||
override fun onCreate() {
|
||||
AndroidInjection.inject(this)
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
||||
if (intent.action != ACTION_DOWNLOAD) {
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
if (!isRunning) {
|
||||
startForeground(
|
||||
AppNotificationManager.DOWNLOAD_NOTIFICATION_ID,
|
||||
notificationsManager.buildDownloadServiceForegroundNotification()
|
||||
)
|
||||
}
|
||||
|
||||
val request = intent.getParcelableExtra(EXTRA_REQUEST) as Request
|
||||
val downloader = getDownloader(request.user)
|
||||
downloader.download(request)
|
||||
|
||||
logger.d(TAG, "Enqueued new download: ${request.uuid} ${request.file.remotePath}")
|
||||
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
val user = intent?.getParcelableExtra<User>(EXTRA_USER)
|
||||
if (user != null) {
|
||||
return Binder(getDownloader(user), this)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private fun onDownloadUpdate(download: Download) {
|
||||
if (!isRunning) {
|
||||
logger.d(TAG, "All downloads completed")
|
||||
notificationsManager.cancelDownloadProgress()
|
||||
stopForeground(true)
|
||||
stopSelf()
|
||||
} else {
|
||||
notificationsManager.postDownloadProgress(
|
||||
fileOwner = download.request.user,
|
||||
file = download.request.file,
|
||||
progress = download.progress,
|
||||
allowPreview = !download.request.test
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
logger.d(TAG, "Stopping downloader service")
|
||||
}
|
||||
|
||||
private fun getDownloader(user: User): DownloaderImpl {
|
||||
val existingDownloader = downloaders[user.accountName]
|
||||
return if (existingDownloader != null) {
|
||||
existingDownloader
|
||||
} else {
|
||||
val downloadTaskFactory = DownloadTask.Factory(
|
||||
applicationContext,
|
||||
{ clientFactory.create(user) },
|
||||
contentResolver
|
||||
)
|
||||
val newDownloader = DownloaderImpl(runner, downloadTaskFactory)
|
||||
newDownloader.registerDownloadListener(this::onDownloadUpdate)
|
||||
downloaders[user.accountName] = newDownloader
|
||||
newDownloader
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import java.lang.IllegalStateException
|
||||
import java.util.TreeMap
|
||||
import java.util.UUID
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* This class tracks status of all downloads. It serves as a state
|
||||
* machine and drives the download background task scheduler via callbacks.
|
||||
* Download status updates are triggering change callbacks that should be used
|
||||
* to notify listeners.
|
||||
*
|
||||
* No listener registration mechanism is provided at this level.
|
||||
*
|
||||
* This class is not thread-safe. All access from multiple threads shall
|
||||
* be lock protected.
|
||||
*
|
||||
* @property onStartDownload callback triggered when download is switched into running state
|
||||
* @property onDownloadChanged callback triggered whenever download status update
|
||||
* @property maxRunning maximum number of allowed simultaneous downloads
|
||||
*/
|
||||
internal class Registry(
|
||||
private val onStartDownload: (UUID, Request) -> Unit,
|
||||
private val onDownloadChanged: (Download) -> Unit,
|
||||
private val maxRunning: Int = 2
|
||||
) {
|
||||
private val pendingQueue = TreeMap<UUID, Download>()
|
||||
private val runningQueue = TreeMap<UUID, Download>()
|
||||
private val completedQueue = TreeMap<UUID, Download>()
|
||||
|
||||
val isRunning: Boolean get() = pendingQueue.size > 0 || runningQueue.size > 0
|
||||
|
||||
val pending: List<Download> get() = pendingQueue.map { it.value }
|
||||
val running: List<Download> get() = runningQueue.map { it.value }
|
||||
val completed: List<Download> get() = completedQueue.map { it.value }
|
||||
|
||||
/**
|
||||
* Insert new download into a pending queue.
|
||||
*
|
||||
* @return scheduled download id
|
||||
*/
|
||||
fun add(request: Request): UUID {
|
||||
val download = Download(
|
||||
uuid = request.uuid,
|
||||
state = DownloadState.PENDING,
|
||||
progress = 0,
|
||||
file = request.file,
|
||||
request = request
|
||||
)
|
||||
pendingQueue[download.uuid] = download
|
||||
return download.uuid
|
||||
}
|
||||
|
||||
/**
|
||||
* Move pending downloads into a running queue up
|
||||
* to max allowed simultaneous downloads.
|
||||
*/
|
||||
fun startNext() {
|
||||
val freeThreads = max(0, maxRunning - runningQueue.size)
|
||||
for (i in 0 until min(freeThreads, pendingQueue.size)) {
|
||||
val key = pendingQueue.firstKey()
|
||||
val pendingDownload = pendingQueue.remove(key) ?: throw IllegalStateException("Download $key not exist.")
|
||||
val runningDownload = pendingDownload.copy(state = DownloadState.RUNNING)
|
||||
runningQueue[key] = runningDownload
|
||||
onStartDownload.invoke(key, runningDownload.request)
|
||||
onDownloadChanged(runningDownload)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update progress for a given download. If no download of a given id is currently running,
|
||||
* update is ignored.
|
||||
*
|
||||
* @param uuid ID of the download to update
|
||||
* @param progress progress 0-100%
|
||||
*/
|
||||
fun progress(uuid: UUID, progress: Int) {
|
||||
val download = runningQueue[uuid]
|
||||
if (download != null) {
|
||||
val runningDownload = download.copy(progress = progress)
|
||||
runningQueue[uuid] = runningDownload
|
||||
onDownloadChanged(runningDownload)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete currently running download. If no download of a given id is currently running,
|
||||
* update is ignored.
|
||||
*
|
||||
* @param uuid of the download to complete
|
||||
* @param success if true, download will be marked as completed; if false - as failed
|
||||
* @param file if provided, update file in download status; if null, existing value is retained
|
||||
*/
|
||||
fun complete(uuid: UUID, success: Boolean, file: OCFile? = null) {
|
||||
val download = runningQueue.remove(uuid)
|
||||
if (download != null) {
|
||||
val status = if (success) {
|
||||
DownloadState.COMPLETED
|
||||
} else {
|
||||
DownloadState.FAILED
|
||||
}
|
||||
val completedDownload = download.copy(state = status, file = file ?: download.file)
|
||||
completedQueue[uuid] = completedDownload
|
||||
onDownloadChanged(completedDownload)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a download by file path. It traverses
|
||||
* through all queues in order of pending, running and completed
|
||||
* downloads and returns first download status matching
|
||||
* file path.
|
||||
*
|
||||
* @param file Search for a file download
|
||||
* @return download status if found, null otherwise
|
||||
*/
|
||||
fun getDownload(file: OCFile): Download? {
|
||||
arrayOf(pendingQueue, runningQueue, completedQueue).forEach { queue ->
|
||||
queue.forEach { entry ->
|
||||
if (entry.value.request.file.remotePath == file.remotePath) {
|
||||
return entry.value
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get download status by id. It traverses
|
||||
* through all queues in order of pending, running and completed
|
||||
* downloads and returns first download status matching
|
||||
* file path.
|
||||
*
|
||||
* @param id download id
|
||||
* @return download status if found, null otherwise
|
||||
*/
|
||||
fun getDownload(uuid: UUID): Download? {
|
||||
return pendingQueue[uuid] ?: runningQueue[uuid] ?: completedQueue[uuid]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.nextcloud.client.files.downloader
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.nextcloud.client.account.User
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import java.util.UUID
|
||||
|
||||
/**
|
||||
* Download request. This class should collect all information
|
||||
* required to trigger download operation.
|
||||
*
|
||||
* Class is immutable by design, although [OCFile] or other
|
||||
* types might not be immutable. Clients should no modify
|
||||
* contents of this object.
|
||||
*
|
||||
* @property user Download will be triggered for a given user
|
||||
* @property file Remote file to download
|
||||
* @property uuid Unique request identifier; this identifier can be set in [Download]
|
||||
* @property dummy if true, this requests a dummy test download; no real file transfer will occur
|
||||
*/
|
||||
class Request internal constructor(
|
||||
val user: User,
|
||||
val file: OCFile,
|
||||
val uuid: UUID,
|
||||
val test: Boolean = false
|
||||
) : Parcelable {
|
||||
|
||||
constructor(user: User, file: OCFile) : this(user, file, UUID.randomUUID())
|
||||
|
||||
constructor(user: User, file: OCFile, test: Boolean) : this(user, file, UUID.randomUUID(), test)
|
||||
|
||||
constructor(parcel: Parcel) : this(
|
||||
user = parcel.readParcelable<User>(User::class.java.classLoader) as User,
|
||||
file = parcel.readParcelable<OCFile>(OCFile::class.java.classLoader) as OCFile,
|
||||
uuid = parcel.readSerializable() as UUID,
|
||||
test = parcel.readInt() != 0
|
||||
)
|
||||
|
||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||
parcel.writeParcelable(user, flags)
|
||||
parcel.writeParcelable(file, flags)
|
||||
parcel.writeSerializable(uuid)
|
||||
parcel.writeInt(if (test) 1 else 0)
|
||||
}
|
||||
|
||||
override fun describeContents(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<Request> {
|
||||
override fun createFromParcel(parcel: Parcel): Request {
|
||||
return Request(parcel)
|
||||
}
|
||||
|
||||
override fun newArray(size: Int): Array<Request?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,10 +62,8 @@ class AsyncFilter(private val asyncRunner: AsyncRunner, private val time: () ->
|
||||
|
||||
private fun <T> filterAsync(collection: Iterable<T>, predicate: (T) -> Boolean, onResult: (List<T>, Long) -> Unit) {
|
||||
startTime = time.invoke()
|
||||
filterTask = asyncRunner.post(
|
||||
task = {
|
||||
collection.filter { predicate.invoke(it) }
|
||||
},
|
||||
filterTask = asyncRunner.postQuickTask(
|
||||
task = { collection.filter { predicate.invoke(it) } },
|
||||
onResult = { filtered: List<T> ->
|
||||
onFilterCompleted(filtered, onResult)
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class LogsEmailSender(private val context: Context, private val clock: Clock, pr
|
||||
fun send(logs: List<LogEntry>) {
|
||||
if (task == null) {
|
||||
val outFile = File(context.cacheDir, "attachments/logs.txt")
|
||||
task = runner.post(Task(context, logs, outFile, clock.tz), onResult = { task = null; send(it) })
|
||||
task = runner.postQuickTask(Task(context, logs, outFile, clock.tz), onResult = { task = null; send(it) })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ internal class MigrationsManagerImpl(
|
||||
return 0
|
||||
}
|
||||
(status as MutableLiveData<Status>).value = Status.RUNNING
|
||||
asyncRunner.post(
|
||||
asyncRunner.postQuickTask(
|
||||
task = { asyncApplyMigrations(toApply) },
|
||||
onResult = { onMigrationSuccess() },
|
||||
onError = { onMigrationFailed(it) }
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.nextcloud.client.notifications
|
||||
|
||||
import android.app.Notification
|
||||
import com.nextcloud.client.account.User
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
|
||||
/**
|
||||
* Application-specific notification manager interface.
|
||||
* Contrary to the platform [android.app.NotificationManager],
|
||||
* it offer high-level, use-case oriented API.
|
||||
*/
|
||||
interface AppNotificationManager {
|
||||
|
||||
companion object {
|
||||
const val DOWNLOAD_NOTIFICATION_ID = 1_000_000
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds notification to be set when downloader starts in foreground.
|
||||
*
|
||||
* @return foreground downloader service notification
|
||||
*/
|
||||
fun buildDownloadServiceForegroundNotification(): Notification
|
||||
|
||||
/**
|
||||
* Post download progress notification.
|
||||
* @param fileOwner User owning the downloaded file
|
||||
* @param file File being downloaded
|
||||
* @param progress Progress as percentage (0-100)
|
||||
* @param allowPreview if true, pending intent with preview action is added to the notification
|
||||
*/
|
||||
fun postDownloadProgress(fileOwner: User, file: OCFile, progress: Int, allowPreview: Boolean = true)
|
||||
|
||||
/**
|
||||
* Removes download progress notification.
|
||||
*/
|
||||
fun cancelDownloadProgress()
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.nextcloud.client.notifications
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Build
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.nextcloud.client.account.User
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity
|
||||
import com.owncloud.android.ui.notifications.NotificationUtils
|
||||
import com.owncloud.android.ui.preview.PreviewImageActivity
|
||||
import com.owncloud.android.ui.preview.PreviewImageFragment
|
||||
import com.owncloud.android.utils.ThemeUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
class AppNotificationManagerImpl @Inject constructor(
|
||||
private val context: Context,
|
||||
private val resources: Resources,
|
||||
private val platformNotificationsManager: NotificationManager
|
||||
) : AppNotificationManager {
|
||||
|
||||
companion object {
|
||||
const val PROGRESS_PERCENTAGE_MAX = 100
|
||||
const val PROGRESS_PERCENTAGE_MIN = 0
|
||||
}
|
||||
|
||||
private fun builder(channelId: String): NotificationCompat.Builder {
|
||||
val color = ThemeUtils.primaryColor(context, true)
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationCompat.Builder(context, channelId).setColor(color)
|
||||
} else {
|
||||
NotificationCompat.Builder(context).setColor(color)
|
||||
}
|
||||
}
|
||||
|
||||
override fun buildDownloadServiceForegroundNotification(): Notification {
|
||||
val icon = BitmapFactory.decodeResource(resources, R.drawable.notification_icon)
|
||||
return builder(NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD)
|
||||
.setContentTitle(resources.getString(R.string.app_name))
|
||||
.setContentText(resources.getString(R.string.foreground_service_download))
|
||||
.setSmallIcon(R.drawable.notification_icon)
|
||||
.setLargeIcon(icon)
|
||||
.build()
|
||||
}
|
||||
|
||||
override fun postDownloadProgress(fileOwner: User, file: OCFile, progress: Int, allowPreview: Boolean) {
|
||||
val builder = builder(NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD)
|
||||
val content = resources.getString(
|
||||
R.string.downloader_download_in_progress_content,
|
||||
progress,
|
||||
file.fileName
|
||||
)
|
||||
builder
|
||||
.setSmallIcon(R.drawable.notification_icon)
|
||||
.setTicker(resources.getString(R.string.downloader_download_in_progress_ticker))
|
||||
.setContentTitle(resources.getString(R.string.downloader_download_in_progress_ticker))
|
||||
.setOngoing(true)
|
||||
.setProgress(PROGRESS_PERCENTAGE_MAX, progress, progress <= PROGRESS_PERCENTAGE_MIN)
|
||||
.setContentText(content)
|
||||
|
||||
if (allowPreview) {
|
||||
val openFileIntent = if (PreviewImageFragment.canBePreviewed(file)) {
|
||||
PreviewImageActivity.previewFileIntent(context, fileOwner, file)
|
||||
} else {
|
||||
FileDisplayActivity.openFileIntent(context, fileOwner, file)
|
||||
}
|
||||
openFileIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
val pendingOpenFileIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
System.currentTimeMillis().toInt(),
|
||||
openFileIntent,
|
||||
0
|
||||
)
|
||||
builder.setContentIntent(pendingOpenFileIntent)
|
||||
}
|
||||
platformNotificationsManager.notify(AppNotificationManager.DOWNLOAD_NOTIFICATION_ID, builder.build())
|
||||
}
|
||||
|
||||
override fun cancelDownloadProgress() {
|
||||
platformNotificationsManager.cancel(AppNotificationManager.DOWNLOAD_NOTIFICATION_ID)
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ import static com.owncloud.android.ui.activity.ContactsPreferenceActivity.PREFER
|
||||
*/
|
||||
public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
||||
|
||||
public static final OwnCloudVersion OUTDATED_SERVER_VERSION = OwnCloudVersion.nextcloud_15;
|
||||
public static final OwnCloudVersion OUTDATED_SERVER_VERSION = OwnCloudVersion.nextcloud_16;
|
||||
public static final OwnCloudVersion MINIMUM_SUPPORTED_SERVER_VERSION = OwnCloudVersion.nextcloud_13;
|
||||
|
||||
private static final String TAG = MainApp.class.getSimpleName();
|
||||
|
||||
@@ -147,6 +147,9 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import de.cotech.hw.fido.WebViewFidoBridge;
|
||||
import de.cotech.hw.fido.ui.FidoDialogOptions;
|
||||
import de.cotech.hw.fido2.WebViewWebauthnBridge;
|
||||
import de.cotech.hw.fido2.ui.WebauthnDialogOptions;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
/**
|
||||
@@ -219,7 +222,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
private TextView mAuthStatusView;
|
||||
private WebView mLoginWebView;
|
||||
|
||||
private WebViewFidoBridge webViewFidoBridge;
|
||||
private WebViewFidoBridge webViewFidoU2fBridge;
|
||||
private WebViewWebauthnBridge webViewWebauthnBridge;
|
||||
|
||||
private String mAuthStatusText = EMPTY_STRING;
|
||||
private int mAuthStatusIcon;
|
||||
@@ -361,7 +365,16 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
mLoginWebView.getSettings().setSaveFormData(false);
|
||||
mLoginWebView.getSettings().setSavePassword(false);
|
||||
|
||||
webViewFidoBridge = WebViewFidoBridge.createInstanceForWebView(this, mLoginWebView);
|
||||
FidoDialogOptions.Builder dialogOptionsBuilder = FidoDialogOptions.builder();
|
||||
dialogOptionsBuilder.setShowSdkLogo(true);
|
||||
dialogOptionsBuilder.setTheme(R.style.FidoDialog);
|
||||
webViewFidoU2fBridge = WebViewFidoBridge.createInstanceForWebView(this, mLoginWebView, dialogOptionsBuilder);
|
||||
|
||||
WebauthnDialogOptions.Builder webauthnOptionsBuilder = WebauthnDialogOptions.builder();
|
||||
webauthnOptionsBuilder.setShowSdkLogo(true);
|
||||
webauthnOptionsBuilder.setAllowSkipPin(true);
|
||||
webauthnOptionsBuilder.setTheme(R.style.FidoDialog);
|
||||
webViewWebauthnBridge = WebViewWebauthnBridge.createInstanceForWebView(this, mLoginWebView, webauthnOptionsBuilder);
|
||||
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE);
|
||||
@@ -396,14 +409,16 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
mLoginWebView.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
||||
webViewFidoBridge.delegateShouldInterceptRequest(view, request);
|
||||
webViewFidoU2fBridge.delegateShouldInterceptRequest(view, request);
|
||||
webViewWebauthnBridge.delegateShouldInterceptRequest(view, request);
|
||||
return super.shouldInterceptRequest(view, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
||||
super.onPageStarted(view, url, favicon);
|
||||
webViewFidoBridge.delegateOnPageStarted(view, url, favicon);
|
||||
webViewFidoU2fBridge.delegateOnPageStarted(view, url, favicon);
|
||||
webViewWebauthnBridge.delegateOnPageStarted(view, url, favicon);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,6 +46,7 @@ import java.util.Locale;
|
||||
import java.util.Observable;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
/**
|
||||
* Database helper for storing list of files to be uploaded, including status
|
||||
@@ -581,17 +582,17 @@ public class UploadsStorageManager extends Observable {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.UPLOADS_STATUS, UploadStatus.UPLOAD_FAILED.getValue());
|
||||
cv.put(
|
||||
ProviderTableMeta.UPLOADS_LAST_RESULT,
|
||||
fail != null ? fail.getValue() : UploadResult.UNKNOWN.getValue()
|
||||
);
|
||||
ProviderTableMeta.UPLOADS_LAST_RESULT,
|
||||
fail != null ? fail.getValue() : UploadResult.UNKNOWN.getValue()
|
||||
);
|
||||
cv.put(ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP, Calendar.getInstance().getTimeInMillis());
|
||||
|
||||
int result = getDB().update(
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
cv,
|
||||
ProviderTableMeta.UPLOADS_STATUS + "=?",
|
||||
new String[]{String.valueOf(UploadStatus.UPLOAD_IN_PROGRESS.getValue())}
|
||||
);
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
cv,
|
||||
ProviderTableMeta.UPLOADS_STATUS + "=?",
|
||||
new String[]{String.valueOf(UploadStatus.UPLOAD_IN_PROGRESS.getValue())}
|
||||
);
|
||||
|
||||
if (result == 0) {
|
||||
Log_OC.v(TAG, "No upload was killed");
|
||||
@@ -603,12 +604,21 @@ public class UploadsStorageManager extends Observable {
|
||||
return result;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public int removeAllUploads() {
|
||||
Log_OC.v(TAG, "Delete all uploads!");
|
||||
return getDB().delete(
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
"",
|
||||
new String[]{});
|
||||
}
|
||||
|
||||
public int removeAccountUploads(Account account) {
|
||||
Log_OC.v(TAG, "Delete all uploads for account " + account.name);
|
||||
return getDB().delete(
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=?",
|
||||
new String[]{account.name});
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "=?",
|
||||
new String[]{account.name});
|
||||
}
|
||||
|
||||
public enum UploadStatus {
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
package com.owncloud.android.operations;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.Pair;
|
||||
@@ -159,31 +158,6 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
|
||||
.execute(client);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
RemoteOperationResult remoteFolderOperationResult = new ReadFolderRemoteOperation(encryptedRemotePath)
|
||||
.execute(client);
|
||||
|
||||
createdRemoteFolder = (RemoteFile) remoteFolderOperationResult.getData().get(0);
|
||||
OCFile newDir = new OCFile(createdRemoteFolder.getRemotePath());
|
||||
newDir.setMimeType(MimeType.DIRECTORY);
|
||||
|
||||
newDir.setParentId(parent.getFileId());
|
||||
newDir.setRemoteId(createdRemoteFolder.getRemoteId());
|
||||
newDir.setModificationTimestamp(System.currentTimeMillis());
|
||||
newDir.setEncrypted(true);
|
||||
newDir.setPermissions(createdRemoteFolder.getPermissions());
|
||||
newDir.setDecryptedRemotePath(parent.getDecryptedRemotePath() + filename + "/");
|
||||
getStorageManager().saveFile(newDir);
|
||||
|
||||
RemoteOperationResult encryptionOperationResult = new ToggleEncryptionRemoteOperation(
|
||||
newDir.getLocalId(),
|
||||
newDir.getRemotePath(),
|
||||
true)
|
||||
.execute(client);
|
||||
|
||||
if (!encryptionOperationResult.isSuccess()) {
|
||||
throw new RuntimeException("Error creating encrypted subfolder!");
|
||||
}
|
||||
|
||||
// Key, always generate new one
|
||||
byte[] key = EncryptionUtils.generateKey();
|
||||
|
||||
@@ -212,6 +186,43 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
|
||||
token,
|
||||
client,
|
||||
metadataExists);
|
||||
|
||||
// unlock folder
|
||||
if (token != null) {
|
||||
RemoteOperationResult unlockFolderResult = EncryptionUtils.unlockFolder(parent, client, token);
|
||||
|
||||
if (unlockFolderResult.isSuccess()) {
|
||||
token = null;
|
||||
} else {
|
||||
// TODO do better
|
||||
throw new RuntimeException("Could not unlock folder!");
|
||||
}
|
||||
}
|
||||
|
||||
RemoteOperationResult remoteFolderOperationResult = new ReadFolderRemoteOperation(encryptedRemotePath)
|
||||
.execute(client);
|
||||
|
||||
createdRemoteFolder = (RemoteFile) remoteFolderOperationResult.getData().get(0);
|
||||
OCFile newDir = new OCFile(createdRemoteFolder.getRemotePath());
|
||||
newDir.setMimeType(MimeType.DIRECTORY);
|
||||
|
||||
newDir.setParentId(parent.getFileId());
|
||||
newDir.setRemoteId(createdRemoteFolder.getRemoteId());
|
||||
newDir.setModificationTimestamp(System.currentTimeMillis());
|
||||
newDir.setEncrypted(true);
|
||||
newDir.setPermissions(createdRemoteFolder.getPermissions());
|
||||
newDir.setDecryptedRemotePath(parent.getDecryptedRemotePath() + filename + "/");
|
||||
getStorageManager().saveFile(newDir);
|
||||
|
||||
RemoteOperationResult encryptionOperationResult = new ToggleEncryptionRemoteOperation(
|
||||
newDir.getLocalId(),
|
||||
newDir.getRemotePath(),
|
||||
true)
|
||||
.execute(client);
|
||||
|
||||
if (!encryptionOperationResult.isSuccess()) {
|
||||
throw new RuntimeException("Error creating encrypted subfolder!");
|
||||
}
|
||||
} else {
|
||||
// revert to sane state in case of any error
|
||||
Log_OC.e(TAG, remotePath + " hasn't been created");
|
||||
@@ -249,7 +260,6 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
|
||||
// TODO do better
|
||||
return new RemoteOperationResult(e);
|
||||
} finally {
|
||||
|
||||
// unlock folder
|
||||
if (token != null) {
|
||||
RemoteOperationResult unlockFolderResult = EncryptionUtils.unlockFolder(parent, client, token);
|
||||
|
||||
@@ -85,6 +85,10 @@ public class DownloadFileOperation extends RemoteOperation {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public DownloadFileOperation(Account account, OCFile file, Context context) {
|
||||
this(account, file, null, null, null, context);
|
||||
}
|
||||
|
||||
public String getSavePath() {
|
||||
if (file.getStoragePath() != null) {
|
||||
File parentFile = new File(file.getStoragePath()).getParentFile();
|
||||
|
||||
@@ -106,7 +106,7 @@ public class RemoveFileOperation extends SyncOperation {
|
||||
context,
|
||||
fileToRemove.getEncryptedFileName());
|
||||
} else {
|
||||
operation = new RemoveFileRemoteOperation(fileToRemove.getDecryptedRemotePath());
|
||||
operation = new RemoveFileRemoteOperation(fileToRemove.getRemotePath());
|
||||
}
|
||||
result = operation.execute(client);
|
||||
if (result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND) {
|
||||
|
||||
@@ -604,7 +604,7 @@ public class UploadFileOperation extends SyncOperation {
|
||||
metadata.getFiles().put(encryptedFileName, decryptedFile);
|
||||
|
||||
EncryptedFolderMetadata encryptedFolderMetadata = EncryptionUtils.encryptFolderMetadata(metadata,
|
||||
privateKey);
|
||||
privateKey);
|
||||
String serializedFolderMetadata = EncryptionUtils.serializeJSON(encryptedFolderMetadata);
|
||||
|
||||
// upload metadata
|
||||
@@ -613,6 +613,13 @@ public class UploadFileOperation extends SyncOperation {
|
||||
token,
|
||||
client,
|
||||
metadataExists);
|
||||
|
||||
// unlock
|
||||
result = EncryptionUtils.unlockFolder(parentFile, client, token);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
token = null;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Log_OC.d(TAG, mFile.getStoragePath() + " not exists anymore");
|
||||
@@ -650,13 +657,14 @@ public class UploadFileOperation extends SyncOperation {
|
||||
}
|
||||
|
||||
// unlock must be done always
|
||||
// TODO check if in good state
|
||||
RemoteOperationResult unlockFolderResult = EncryptionUtils.unlockFolder(parentFile,
|
||||
client,
|
||||
token);
|
||||
if (token != null) {
|
||||
RemoteOperationResult unlockFolderResult = EncryptionUtils.unlockFolder(parentFile,
|
||||
client,
|
||||
token);
|
||||
|
||||
if (!unlockFolderResult.isSuccess()) {
|
||||
return unlockFolderResult;
|
||||
if (!unlockFolderResult.isSuccess()) {
|
||||
return unlockFolderResult;
|
||||
}
|
||||
}
|
||||
|
||||
// delete temporal file
|
||||
|
||||
@@ -52,7 +52,6 @@ import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
@@ -78,7 +78,6 @@ public class ContactsPreferenceActivity extends FileActivity implements FileFrag
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.contacts_preference);
|
||||
|
||||
// setup toolbar
|
||||
|
||||
@@ -218,6 +218,13 @@ public class FileDisplayActivity extends FileActivity
|
||||
@Inject
|
||||
ConnectivityService connectivityService;
|
||||
|
||||
public static Intent openFileIntent(Context context, User user, OCFile file) {
|
||||
final Intent intent = new Intent(context, PreviewImageActivity.class);
|
||||
intent.putExtra(FileActivity.EXTRA_FILE, file);
|
||||
intent.putExtra(FileActivity.EXTRA_ACCOUNT, user.toPlatformAccount());
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Log_OC.v(TAG, "onCreate() start");
|
||||
@@ -2137,6 +2144,7 @@ public class FileDisplayActivity extends FileActivity
|
||||
return; // not reachable under normal conditions
|
||||
}
|
||||
if (showPreview && file.isDown() && !file.isDownloading() || streamMedia) {
|
||||
showSortListGroup(false);
|
||||
Fragment mediaFragment = PreviewMediaFragment.newInstance(file, user.get(), startPlaybackPosition, autoplay);
|
||||
setSecondFragment(mediaFragment);
|
||||
updateFragmentsVisibility(true);
|
||||
@@ -2190,6 +2198,7 @@ public class FileDisplayActivity extends FileActivity
|
||||
* @param folder {@link OCFile} to preview its rich workspace.
|
||||
*/
|
||||
public void startRichWorkspacePreview(OCFile folder) {
|
||||
showSortListGroup(false);
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(EXTRA_FILE, folder);
|
||||
Fragment textPreviewFragment = Fragment.instantiate(getApplicationContext(),
|
||||
|
||||
@@ -60,6 +60,7 @@ import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
@@ -239,7 +240,7 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
||||
private void setupContent() {
|
||||
emptyContentIcon.setImageResource(R.drawable.ic_notification);
|
||||
emptyContentProgressBar.getIndeterminateDrawable().setColorFilter(ThemeUtils.primaryAccentColor(this),
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
setLoadingMessage();
|
||||
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
@@ -249,8 +250,18 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
||||
fetchAndSetData();
|
||||
}
|
||||
|
||||
private void populateList(List<Notification> notifications) {
|
||||
@VisibleForTesting
|
||||
public void populateList(List<Notification> notifications) {
|
||||
adapter.setNotificationItems(notifications);
|
||||
|
||||
if (notifications.size() > 0) {
|
||||
swipeEmptyListRefreshLayout.setVisibility(View.GONE);
|
||||
swipeListRefreshLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
setEmptyContent(noResultsHeadline, noResultsMessage);
|
||||
swipeListRefreshLayout.setVisibility(View.GONE);
|
||||
swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchAndSetData() {
|
||||
@@ -275,17 +286,7 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
||||
if (result.isSuccess() && result.getNotificationData() != null) {
|
||||
final List<Notification> notifications = result.getNotificationData();
|
||||
|
||||
runOnUiThread(() -> {
|
||||
populateList(notifications);
|
||||
if (notifications.size() > 0) {
|
||||
swipeEmptyListRefreshLayout.setVisibility(View.GONE);
|
||||
swipeListRefreshLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
setEmptyContent(noResultsHeadline, noResultsMessage);
|
||||
swipeListRefreshLayout.setVisibility(View.GONE);
|
||||
swipeEmptyListRefreshLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
runOnUiThread(() -> populateList(notifications));
|
||||
} else {
|
||||
Log_OC.d(TAG, result.getLogMessage());
|
||||
// show error
|
||||
@@ -344,7 +345,8 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
||||
emptyContentProgressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void setEmptyContent(String headline, String message) {
|
||||
@VisibleForTesting
|
||||
public void setEmptyContent(String headline, String message) {
|
||||
if (emptyContentContainer != null && emptyContentMessage != null) {
|
||||
emptyContentHeadline.setText(headline);
|
||||
emptyContentMessage.setText(message);
|
||||
|
||||
@@ -53,7 +53,7 @@ import androidx.core.content.ContextCompat;
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
||||
/**
|
||||
* Base class providing toolbar registration functionality, see {@link #setupToolbar(boolean)}.
|
||||
* Base class providing toolbar registration functionality, see {@link #setupToolbar(boolean, boolean)}.
|
||||
*/
|
||||
public abstract class ToolbarActivity extends BaseActivity {
|
||||
protected MaterialButton mMenuButton;
|
||||
|
||||
@@ -234,7 +234,10 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
for (PreviewObject previewObject : activity.getPreviews()) {
|
||||
if (!isDetailView || MimeTypeUtil.isImageOrVideo(previewObject.getMimeType()) ||
|
||||
MimeTypeUtil.isVideo(previewObject.getMimeType())) {
|
||||
ImageView imageView = createThumbnailNew(previewObject);
|
||||
ImageView imageView = createThumbnailNew(previewObject,
|
||||
activity
|
||||
.getRichSubjectElement()
|
||||
.getRichObjectList());
|
||||
activityViewHolder.list.addView(imageView);
|
||||
}
|
||||
}
|
||||
@@ -256,14 +259,26 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
}
|
||||
}
|
||||
|
||||
private ImageView createThumbnailNew(PreviewObject previewObject) {
|
||||
private ImageView createThumbnailNew(PreviewObject previewObject, List<RichObject> richObjectList) {
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(px, px);
|
||||
params.setMargins(10, 10, 10, 10);
|
||||
ImageView imageView = new ImageView(context);
|
||||
imageView.setLayoutParams(params);
|
||||
|
||||
for (RichObject object : richObjectList) {
|
||||
if (Integer.parseInt(object.getId()) == previewObject.getFileId()) {
|
||||
imageView.setOnClickListener(v -> activityListInterface.onActivityClicked(object));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (MimeTypeUtil.isImageOrVideo(previewObject.getMimeType())) {
|
||||
int placeholder = R.drawable.file;
|
||||
int placeholder;
|
||||
if (MimeTypeUtil.isImage(previewObject.getMimeType())) {
|
||||
placeholder = R.drawable.file_image;
|
||||
} else {
|
||||
placeholder = R.drawable.file_movie;
|
||||
}
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider, clientFactory))
|
||||
.load(previewObject.getSource())
|
||||
.placeholder(placeholder)
|
||||
@@ -271,8 +286,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
.into(imageView);
|
||||
} else {
|
||||
if (MimeTypeUtil.isFolder(previewObject.getMimeType())) {
|
||||
imageView.setImageDrawable(
|
||||
MimeTypeUtil.getDefaultFolderIcon(context));
|
||||
imageView.setImageDrawable(MimeTypeUtil.getDefaultFolderIcon(context));
|
||||
} else {
|
||||
imageView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(previewObject.getMimeType(), "", context));
|
||||
}
|
||||
|
||||
@@ -20,8 +20,10 @@
|
||||
package com.owncloud.android.ui.adapter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.PictureDrawable;
|
||||
import android.net.Uri;
|
||||
@@ -136,11 +138,17 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
||||
|
||||
holder.message.setText(notification.getMessage());
|
||||
|
||||
// Todo set proper action icon (to be clarified how to pick)
|
||||
if (!TextUtils.isEmpty(notification.getIcon())) {
|
||||
downloadIcon(notification.getIcon(), holder.icon);
|
||||
}
|
||||
|
||||
int nightModeFlag = notificationsActivity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
if (Configuration.UI_MODE_NIGHT_YES == nightModeFlag) {
|
||||
holder.icon.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
|
||||
} else {
|
||||
holder.icon.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
setButtons(holder, notification);
|
||||
|
||||
holder.dismiss.setOnClickListener(v -> new DeleteNotificationTask(client, notification, holder,
|
||||
@@ -154,8 +162,13 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
||||
|
||||
Resources resources = notificationsActivity.getResources();
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
params.setMargins(20, 0, 20, 0);
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
params.setMargins(
|
||||
resources.getDimensionPixelOffset(R.dimen.standard_half_margin),
|
||||
0,
|
||||
resources.getDimensionPixelOffset(R.dimen.standard_half_margin),
|
||||
0
|
||||
);
|
||||
|
||||
for (Action action : notification.getActions()) {
|
||||
button = new MaterialButton(notificationsActivity);
|
||||
@@ -164,21 +177,19 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
||||
|
||||
if (action.primary) {
|
||||
ThemeUtils.colorPrimaryButton(button, notificationsActivity);
|
||||
button.setTypeface(button.getTypeface(), Typeface.BOLD);
|
||||
} else {
|
||||
button.setBackgroundColor(resources.getColor(R.color.grey_200));
|
||||
button.setTextColor(primaryColor);
|
||||
button.setTypeface(button.getTypeface(), Typeface.BOLD);
|
||||
}
|
||||
|
||||
button.setAllCaps(false);
|
||||
|
||||
button.setText(action.label);
|
||||
button.setCornerRadiusResource(R.dimen.button_corner_radius);
|
||||
|
||||
button.setLayoutParams(params);
|
||||
button.setGravity(Gravity.CENTER);
|
||||
|
||||
button.setPadding(40, 40, 40, 40);
|
||||
|
||||
button.setOnClickListener(v -> {
|
||||
setButtonEnabled(holder, false);
|
||||
|
||||
|
||||
@@ -433,30 +433,53 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
avatar.setImageResource(R.drawable.ic_people);
|
||||
ThemeUtils.setIconColor(avatar.getDrawable());
|
||||
} else {
|
||||
if (sharee.getShareType().equals(ShareType.GROUP)) {
|
||||
try {
|
||||
avatar.setImageDrawable(
|
||||
TextDrawable.createAvatarByUserId(sharee.getUserId(), avatarRadius));
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
|
||||
avatar.setImageResource(R.drawable.ic_people);
|
||||
switch (sharee.getShareType()) {
|
||||
case GROUP:
|
||||
try {
|
||||
avatar.setImageDrawable(TextDrawable.createAvatarByUserId(sharee.getUserId(),
|
||||
avatarRadius));
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
|
||||
avatar.setImageResource(R.drawable.ic_people);
|
||||
ThemeUtils.setIconColor(avatar.getDrawable());
|
||||
}
|
||||
break;
|
||||
|
||||
case ROOM:
|
||||
try {
|
||||
if (!TextUtils.isEmpty(sharee.getDisplayName())) {
|
||||
avatar.setImageDrawable(
|
||||
TextDrawable.createNamedAvatar(sharee.getDisplayName(), avatarRadius));
|
||||
} else {
|
||||
avatar.setImageDrawable(
|
||||
TextDrawable.createAvatarByUserId(sharee.getUserId(), avatarRadius));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
|
||||
avatar.setImageResource(R.drawable.ic_people);
|
||||
ThemeUtils.setIconColor(avatar.getDrawable());
|
||||
}
|
||||
break;
|
||||
|
||||
case CIRCLE:
|
||||
avatar.setImageResource(R.drawable.ic_circles);
|
||||
ThemeUtils.setIconColor(avatar.getDrawable());
|
||||
}
|
||||
} else if (sharee.getShareType().equals(ShareType.CIRCLE)) {
|
||||
avatar.setImageResource(R.drawable.ic_circles);
|
||||
ThemeUtils.setIconColor(avatar.getDrawable());
|
||||
} else if (sharee.getUserId().contains("@")) {
|
||||
showFederatedShareAvatar(sharee.getUserId(), avatarRadius, resources, avatar);
|
||||
} else {
|
||||
avatar.setTag(sharee);
|
||||
DisplayUtils.setAvatar(user,
|
||||
sharee.getUserId(),
|
||||
sharee.getDisplayName(),
|
||||
this,
|
||||
avatarRadius,
|
||||
resources,
|
||||
avatar,
|
||||
activity);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (sharee.getUserId().contains("@")) {
|
||||
showFederatedShareAvatar(sharee.getUserId(), avatarRadius, resources, avatar);
|
||||
} else {
|
||||
avatar.setTag(sharee);
|
||||
DisplayUtils.setAvatar(user,
|
||||
sharee.getUserId(),
|
||||
sharee.getDisplayName(),
|
||||
this,
|
||||
avatarRadius,
|
||||
resources,
|
||||
avatar,
|
||||
activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,7 +604,9 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
placeholder = TextDrawable.createAvatarByUserId(userId, avatarRadius);
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
|
||||
placeholder = ResourcesCompat.getDrawable(resources, R.drawable.account_circle_white, null);
|
||||
placeholder = ThemeUtils.tintDrawable(ResourcesCompat.getDrawable(resources,
|
||||
R.drawable.account_circle_white, null),
|
||||
R.color.black);
|
||||
}
|
||||
|
||||
avatar.setTag(null);
|
||||
|
||||
@@ -41,6 +41,7 @@ public class PhotoSearchTask extends AsyncTask<Void, Void, RemoteOperationResult
|
||||
private WeakReference<PhotoFragment> photoFragmentWeakReference;
|
||||
private SearchRemoteOperation searchRemoteOperation;
|
||||
private FileDataStorageManager storageManager;
|
||||
private int limit;
|
||||
|
||||
public PhotoSearchTask(int columnsCount,
|
||||
PhotoFragment photoFragment,
|
||||
@@ -76,7 +77,7 @@ public class PhotoSearchTask extends AsyncTask<Void, Void, RemoteOperationResult
|
||||
if (isCancelled()) {
|
||||
return new RemoteOperationResult(new Exception("Cancelled"));
|
||||
} else {
|
||||
int limit = 15 * columnCount;
|
||||
limit = 15 * columnCount;
|
||||
|
||||
long timestamp = -1;
|
||||
if (adapter.getLastTimestamp() > 0) {
|
||||
@@ -105,6 +106,11 @@ public class PhotoSearchTask extends AsyncTask<Void, Void, RemoteOperationResult
|
||||
} else {
|
||||
OCFileListAdapter adapter = photoFragment.getAdapter();
|
||||
|
||||
if (result.getData().size() < limit) {
|
||||
// stop loading spinner
|
||||
photoFragment.setSearchDidNotFindNewPhotos(true);
|
||||
}
|
||||
|
||||
adapter.setData(result.getData(),
|
||||
ExtendedListFragment.SearchType.PHOTO_SEARCH,
|
||||
storageManager,
|
||||
|
||||
@@ -44,6 +44,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.PopupMenu;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
@@ -419,12 +420,15 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
||||
*/
|
||||
private void registerFabListener() {
|
||||
FileActivity activity = (FileActivity) getActivity();
|
||||
mFabMain.setOnClickListener(v -> new OCFileListBottomSheetDialog(activity,
|
||||
this,
|
||||
deviceInfo,
|
||||
accountManager.getUser(),
|
||||
getCurrentFile())
|
||||
.show());
|
||||
|
||||
if (mFabMain != null) { // is not available in FolderPickerActivity
|
||||
mFabMain.setOnClickListener(v -> new OCFileListBottomSheetDialog(activity,
|
||||
this,
|
||||
deviceInfo,
|
||||
accountManager.getUser(),
|
||||
getCurrentFile())
|
||||
.show());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -899,11 +903,13 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
||||
int position = mAdapter.getItemPosition(file);
|
||||
|
||||
if (file.isFolder()) {
|
||||
resetHeaderScrollingState();
|
||||
|
||||
if (file.isEncrypted()) {
|
||||
// check if API >= 19
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
|
||||
Snackbar.make(getRecyclerView(), R.string.end_to_end_encryption_not_supported,
|
||||
Snackbar.LENGTH_LONG).show();
|
||||
Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -914,13 +920,14 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
||||
.getCapability(user.getAccountName());
|
||||
|
||||
if (ocCapability.getEndToEndEncryption().isFalse() ||
|
||||
ocCapability.getEndToEndEncryption().isUnknown()) {
|
||||
ocCapability.getEndToEndEncryption().isUnknown()) {
|
||||
Snackbar.make(getRecyclerView(), R.string.end_to_end_encryption_not_enabled,
|
||||
Snackbar.LENGTH_LONG).show();
|
||||
Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}// check if keys are stored
|
||||
}
|
||||
// check if keys are stored
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(
|
||||
getContext().getContentResolver());
|
||||
getContext().getContentResolver());
|
||||
|
||||
|
||||
String publicKey = arbitraryDataProvider.getValue(user.toPlatformAccount(),
|
||||
@@ -994,10 +1001,13 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
||||
((FileDisplayActivity) mContainerActivity).startContactListFragment(file);
|
||||
} else if (PreviewTextFileFragment.canBePreviewed(file)) {
|
||||
setFabVisible(false);
|
||||
resetHeaderScrollingState();
|
||||
((FileDisplayActivity) mContainerActivity).startTextPreview(file, false);
|
||||
} else if (file.isDown()) {
|
||||
if (PreviewMediaFragment.canBePreviewed(file)) {
|
||||
// media preview
|
||||
setFabVisible(false);
|
||||
resetHeaderScrollingState();
|
||||
((FileDisplayActivity) mContainerActivity).startMediaPreview(file, 0, true, true, false);
|
||||
} else {
|
||||
mContainerActivity.getFileOperationsHelper().openFile(file);
|
||||
@@ -1011,6 +1021,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
||||
if (PreviewMediaFragment.canBePreviewed(file) && account.getServer().getVersion()
|
||||
.isMediaStreamingSupported() && !file.isEncrypted()) {
|
||||
// stream media preview on >= NC14
|
||||
setFabVisible(false);
|
||||
resetHeaderScrollingState();
|
||||
((FileDisplayActivity) mContainerActivity).startMediaPreview(file, 0, true, true, true);
|
||||
} else if (FileMenuFilter.isEditorAvailable(requireContext().getContentResolver(),
|
||||
accountManager.getUser(),
|
||||
@@ -1111,6 +1123,9 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
||||
if (mActiveActionMode != null) {
|
||||
mActiveActionMode.finish();
|
||||
}
|
||||
|
||||
resetHeaderScrollingState();
|
||||
|
||||
mContainerActivity.showDetails(singleFile);
|
||||
setFabVisible(false);
|
||||
mContainerActivity.showSortListGroup(false);
|
||||
@@ -1598,19 +1613,46 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.BACKGROUND)
|
||||
public void onMessageEvent(EncryptionEvent event) {
|
||||
final User user = accountManager.getUser();
|
||||
|
||||
try {
|
||||
final User user = accountManager.getUser();
|
||||
final OwnCloudClient client = clientFactory.create(user);
|
||||
final ToggleEncryptionRemoteOperation toggleEncryptionOperation = new ToggleEncryptionRemoteOperation(
|
||||
event.localId, event.remotePath, event.shouldBeEncrypted);
|
||||
final RemoteOperationResult remoteOperationResult = toggleEncryptionOperation.execute(client);
|
||||
OwnCloudClient client = clientFactory.create(user);
|
||||
RemoteOperationResult remoteOperationResult = new ToggleEncryptionRemoteOperation(event.localId,
|
||||
event.remotePath,
|
||||
event.shouldBeEncrypted)
|
||||
.execute(client);
|
||||
|
||||
if (remoteOperationResult.isSuccess()) {
|
||||
mAdapter.setEncryptionAttributeForItemID(event.remoteId, event.shouldBeEncrypted);
|
||||
|
||||
// check if keys are stored
|
||||
ArbitraryDataProvider arbitraryDataProvider =
|
||||
new ArbitraryDataProvider(requireContext().getContentResolver());
|
||||
|
||||
|
||||
String publicKey = arbitraryDataProvider.getValue(user.toPlatformAccount(),
|
||||
EncryptionUtils.PUBLIC_KEY);
|
||||
String privateKey = arbitraryDataProvider.getValue(user.toPlatformAccount(),
|
||||
EncryptionUtils.PRIVATE_KEY);
|
||||
|
||||
if (publicKey.isEmpty() || privateKey.isEmpty()) {
|
||||
Log_OC.d(TAG, "no public key for " + user.getAccountName());
|
||||
|
||||
|
||||
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
|
||||
int position = mAdapter.getItemPosition(storageManager.getFileByRemoteId(event.remoteId));
|
||||
SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position);
|
||||
dialog.setTargetFragment(this, SetupEncryptionDialogFragment.SETUP_ENCRYPTION_REQUEST_CODE);
|
||||
dialog.show(getParentFragmentManager(), SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG);
|
||||
}
|
||||
} else if (remoteOperationResult.getHttpCode() == HttpStatus.SC_FORBIDDEN) {
|
||||
Snackbar.make(getRecyclerView(), R.string.end_to_end_encryption_folder_not_empty, Snackbar.LENGTH_LONG).show();
|
||||
Snackbar.make(getRecyclerView(),
|
||||
R.string.end_to_end_encryption_folder_not_empty,
|
||||
Snackbar.LENGTH_LONG).show();
|
||||
} else {
|
||||
Snackbar.make(getRecyclerView(), R.string.common_error_unknown, Snackbar.LENGTH_LONG).show();
|
||||
Snackbar.make(getRecyclerView(),
|
||||
R.string.common_error_unknown,
|
||||
Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
@@ -1820,4 +1862,12 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void resetHeaderScrollingState() {
|
||||
AppBarLayout appBarLayout = ((FileDisplayActivity) requireActivity()).findViewById(R.id.appbar);
|
||||
|
||||
if (appBarLayout != null) {
|
||||
appBarLayout.setExpanded(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2017 Tobias Kaminsky
|
||||
* Copyright (C) 2017 Nextcloud GmbH.
|
||||
* Copyright (C) 2020 Chris Narkiewicz <hello@ezaquarii.com>
|
||||
* <p>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
@@ -22,11 +23,9 @@
|
||||
package com.owncloud.android.ui.fragment.contactsbackup;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
@@ -58,12 +57,15 @@ import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.files.downloader.Download;
|
||||
import com.nextcloud.client.files.downloader.DownloadState;
|
||||
import com.nextcloud.client.files.downloader.DownloaderConnection;
|
||||
import com.nextcloud.client.files.downloader.Request;
|
||||
import com.nextcloud.client.jobs.BackgroundJobManager;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.files.services.FileDownloader;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.TextDrawable;
|
||||
import com.owncloud.android.ui.activity.ContactsPreferenceActivity;
|
||||
@@ -101,6 +103,7 @@ import butterknife.ButterKnife;
|
||||
import ezvcard.Ezvcard;
|
||||
import ezvcard.VCard;
|
||||
import ezvcard.property.Photo;
|
||||
import kotlin.Unit;
|
||||
|
||||
import static com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment.getDisplayName;
|
||||
|
||||
@@ -148,6 +151,7 @@ public class ContactListFragment extends FileFragment implements Injectable {
|
||||
@Inject UserAccountManager accountManager;
|
||||
@Inject ClientFactory clientFactory;
|
||||
@Inject BackgroundJobManager backgroundJobManager;
|
||||
private DownloaderConnection fileDownloader;
|
||||
|
||||
public static ContactListFragment newInstance(OCFile file, User user) {
|
||||
ContactListFragment frag = new ContactListFragment();
|
||||
@@ -209,18 +213,12 @@ public class ContactListFragment extends FileFragment implements Injectable {
|
||||
ocFile = getArguments().getParcelable(FILE_NAME);
|
||||
setFile(ocFile);
|
||||
user = getArguments().getParcelable(USER);
|
||||
|
||||
fileDownloader = new DownloaderConnection(getActivity(), user);
|
||||
fileDownloader.registerDownloadListener(this::onDownloadUpdate);
|
||||
fileDownloader.bind();
|
||||
if (!ocFile.isDown()) {
|
||||
Intent i = new Intent(getContext(), FileDownloader.class);
|
||||
i.putExtra(FileDownloader.EXTRA_USER, user);
|
||||
i.putExtra(FileDownloader.EXTRA_FILE, ocFile);
|
||||
getContext().startService(i);
|
||||
|
||||
// Listen for download messages
|
||||
IntentFilter downloadIntentFilter = new IntentFilter(FileDownloader.getDownloadAddedMessage());
|
||||
downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage());
|
||||
DownloadFinishReceiver mDownloadFinishReceiver = new DownloadFinishReceiver();
|
||||
getContext().registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
|
||||
Request request = new Request(user, ocFile);
|
||||
fileDownloader.download(request);
|
||||
} else {
|
||||
loadContactsTask.execute();
|
||||
}
|
||||
@@ -240,6 +238,14 @@ public class ContactListFragment extends FileFragment implements Injectable {
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
if (fileDownloader != null) {
|
||||
fileDownloader.unbind();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
@@ -497,19 +503,13 @@ public class ContactListFragment extends FileFragment implements Injectable {
|
||||
}
|
||||
}
|
||||
|
||||
private class DownloadFinishReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (FileDownloader.getDownloadFinishMessage().equalsIgnoreCase(intent.getAction())) {
|
||||
String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
|
||||
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(user.toPlatformAccount(),
|
||||
context.getContentResolver());
|
||||
ocFile = storageManager.getFileByPath(downloadedRemotePath);
|
||||
loadContactsTask.execute();
|
||||
}
|
||||
private Unit onDownloadUpdate(Download download) {
|
||||
final Activity activity = getActivity();
|
||||
if (download.getState() == DownloadState.COMPLETED && activity != null) {
|
||||
ocFile = download.getFile();
|
||||
loadContactsTask.execute();
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
|
||||
public static class VCardComparator implements Comparator<VCard> {
|
||||
|
||||
@@ -864,7 +864,9 @@ public class FileOperationsHelper {
|
||||
|
||||
public void toggleEncryption(OCFile file, boolean shouldBeEncrypted) {
|
||||
if (file.isEncrypted() != shouldBeEncrypted) {
|
||||
EventBus.getDefault().post(new EncryptionEvent(file.getLocalId(), file.getRemoteId(), file.getRemotePath(),
|
||||
EventBus.getDefault().post(new EncryptionEvent(file.getLocalId(),
|
||||
file.getRemoteId(),
|
||||
file.getRemotePath(),
|
||||
shouldBeEncrypted));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,12 +80,17 @@ public class PreviewImageActivity extends FileActivity implements
|
||||
Injectable {
|
||||
|
||||
public static final String TAG = PreviewImageActivity.class.getSimpleName();
|
||||
|
||||
private static final String KEY_WAITING_FOR_BINDER = "WAITING_FOR_BINDER";
|
||||
private static final String KEY_SYSTEM_VISIBLE = "TRUE";
|
||||
|
||||
public static final String EXTRA_VIRTUAL_TYPE = "EXTRA_VIRTUAL_TYPE";
|
||||
|
||||
public static Intent previewFileIntent(Context context, User user, OCFile file) {
|
||||
final Intent intent = new Intent(context, PreviewImageActivity.class);
|
||||
intent.putExtra(FileActivity.EXTRA_FILE, file);
|
||||
intent.putExtra(FileActivity.EXTRA_ACCOUNT, user.toPlatformAccount());
|
||||
return intent;
|
||||
}
|
||||
|
||||
private ViewPager mViewPager;
|
||||
private PreviewImagePagerAdapter mPreviewImagePagerAdapter;
|
||||
private int mSavedPosition;
|
||||
|
||||
@@ -655,13 +655,13 @@ public class PreviewImageFragment extends FileFragment implements Injectable {
|
||||
}
|
||||
|
||||
private LayerDrawable generateCheckerboardLayeredDrawable(LoadImage result, Bitmap bitmap) {
|
||||
Resources r = getResources();
|
||||
Resources resources = getResources();
|
||||
Drawable[] layers = new Drawable[2];
|
||||
layers[0] = r.getDrawable(R.color.bg_default);
|
||||
layers[0] = ResourcesCompat.getDrawable(resources, R.color.bg_default, null);
|
||||
Drawable bitmapDrawable;
|
||||
|
||||
if (MIME_TYPE_PNG.equalsIgnoreCase(result.ocFile.getMimeType())) {
|
||||
bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
|
||||
bitmapDrawable = new BitmapDrawable(resources, bitmap);
|
||||
} else if (MIME_TYPE_SVG.equalsIgnoreCase(result.ocFile.getMimeType())) {
|
||||
bitmapDrawable = result.drawable;
|
||||
} else if (MIME_TYPE_GIF.equalsIgnoreCase(result.ocFile.getMimeType())) {
|
||||
@@ -671,7 +671,7 @@ public class PreviewImageFragment extends FileFragment implements Injectable {
|
||||
bitmapDrawable = result.drawable;
|
||||
}
|
||||
} else {
|
||||
bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
|
||||
bitmapDrawable = new BitmapDrawable(resources, bitmap);
|
||||
}
|
||||
|
||||
layers[1] = bitmapDrawable;
|
||||
|
||||
@@ -69,10 +69,16 @@ import static com.owncloud.android.utils.DisplayUtils.openSortingOrderDialogFrag
|
||||
* Presenting trashbin data, received from presenter
|
||||
*/
|
||||
public class TrashbinActivity extends FileActivity implements
|
||||
TrashbinActivityInterface,
|
||||
SortingOrderDialogFragment.OnSortingOrderListener,
|
||||
TrashbinContract.View,
|
||||
Injectable {
|
||||
TrashbinActivityInterface,
|
||||
SortingOrderDialogFragment.OnSortingOrderListener,
|
||||
TrashbinContract.View,
|
||||
Injectable {
|
||||
|
||||
@BindView(R.id.empty_list_progress)
|
||||
public View emptyListProgress;
|
||||
|
||||
@BindView(R.id.empty_list_view)
|
||||
public View emptyListView;
|
||||
|
||||
@BindView(R.id.empty_list_view_text)
|
||||
public TextView emptyContentMessage;
|
||||
@@ -131,8 +137,8 @@ public class TrashbinActivity extends FileActivity implements
|
||||
|
||||
private void setupContent() {
|
||||
recyclerView = findViewById(android.R.id.list);
|
||||
recyclerView.setEmptyView(findViewById(R.id.empty_list_view));
|
||||
findViewById(R.id.empty_list_progress).setVisibility(View.GONE);
|
||||
recyclerView.setEmptyView(emptyListView);
|
||||
emptyListView.setVisibility(View.GONE);
|
||||
emptyContentIcon.setImageResource(R.drawable.ic_delete);
|
||||
emptyContentIcon.setVisibility(View.VISIBLE);
|
||||
emptyContentHeadline.setText(noResultsHeadline);
|
||||
@@ -276,6 +282,7 @@ public class TrashbinActivity extends FileActivity implements
|
||||
if (active) {
|
||||
trashbinListAdapter.setTrashbinFiles(trashbinFiles, true);
|
||||
swipeListRefreshLayout.setRefreshing(false);
|
||||
emptyListProgress.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,6 +321,8 @@ public class TrashbinActivity extends FileActivity implements
|
||||
|
||||
emptyContentMessage.setVisibility(View.VISIBLE);
|
||||
emptyContentIcon.setVisibility(View.VISIBLE);
|
||||
emptyListView.setVisibility(View.VISIBLE);
|
||||
emptyListProgress.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Nextcloud Android client application
|
||||
|
||||
@author Chris Narkiewicz
|
||||
Copyright (C) 2020 Chris Narkiewicz <hello@ezaquarii.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:stretchColumns="1">
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:text="@string/etm_download_uuid" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/etm_download_uuid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="d7edb387-0b61-4e4e-a728-ffab3055d700" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:text="@string/etm_download_path" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/etm_download_path"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="file path" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:text="@string/etm_download_user" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/etm_download_user"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="[email protected]" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:text="@string/etm_download_state" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/etm_download_state"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="PENDING" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/etm_download_progress_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:text="@string/etm_download_progress" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/etm_download_progress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="50%" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
||||