Compare commits
244
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30f96aa984 | ||
|
|
2c57e37097 | ||
|
|
5257fb236c | ||
|
|
aa431815aa | ||
|
|
1f4e857681 | ||
|
|
d17c853493 | ||
|
|
74bfe473c4 | ||
|
|
3e872df68c | ||
|
|
4e0b40517c | ||
|
|
7c62ad6b06 | ||
|
|
bedc2b48ee | ||
|
|
ca6918f9fc | ||
|
|
23e44243da | ||
|
|
540c649efe | ||
|
|
f34ba2cdca | ||
|
|
48038d564e | ||
|
|
83e0ebc463 | ||
|
|
21c0de3cdd | ||
|
|
e92daa2fc4 | ||
|
|
99d9a6923e | ||
|
|
10960bf3a2 | ||
|
|
9f24b254f9 | ||
|
|
b7876c4252 | ||
|
|
11687c65cb | ||
|
|
80fb800ef1 | ||
|
|
b91136c362 | ||
|
|
a7eb7148fa | ||
|
|
4f26261bf8 | ||
|
|
0691786fb8 | ||
|
|
6249a06a8d | ||
|
|
c8eba1d5ad | ||
|
|
609b99666f | ||
|
|
44220d73fe | ||
|
|
6e5d7a89c1 | ||
|
|
16c220e7af | ||
|
|
b9ff6cecfc | ||
|
|
0977c9d2e1 | ||
|
|
26c5c5e015 | ||
|
|
21ef006544 | ||
|
|
0223085a8d | ||
|
|
8879179cff | ||
|
|
94502f66b5 | ||
|
|
21109375c3 | ||
|
|
f1a0ac5c26 | ||
|
|
a00677cd63 | ||
|
|
dbe12e6d20 | ||
|
|
77b6b178a9 | ||
|
|
b561f68834 | ||
|
|
b59d96ace0 | ||
|
|
b6d682683c | ||
|
|
9ae550731e | ||
|
|
bfdaba8bde | ||
|
|
c82c08059a | ||
|
|
65da616f81 | ||
|
|
5273e1e7fc | ||
|
|
bd503a86c7 | ||
|
|
20c9ce361a | ||
|
|
3943e1c753 | ||
|
|
75de7b88d4 | ||
|
|
693f408276 | ||
|
|
ed8b9cbb72 | ||
|
|
f38900d989 | ||
|
|
e43ef8e062 | ||
|
|
f245b72ded | ||
|
|
d30b574ff6 | ||
|
|
fb615ef279 | ||
|
|
df6d847f29 | ||
|
|
4343c3d67f | ||
|
|
86027dd091 | ||
|
|
4690042b06 | ||
|
|
ff646aa3d0 | ||
|
|
403fc87562 | ||
|
|
142c79bc03 | ||
|
|
890789f0a7 | ||
|
|
180bdee721 | ||
|
|
039adc0a18 | ||
|
|
b59938d960 | ||
|
|
2e13212752 | ||
|
|
c2ea4de802 | ||
|
|
7f4db3fdd0 | ||
|
|
9e15f5ea39 | ||
|
|
d208681fed | ||
|
|
25aaf4b907 | ||
|
|
6b01382e7f | ||
|
|
7a8aee3e22 | ||
|
|
a3ae32129d | ||
|
|
b0563b9310 | ||
|
|
207f8947cf | ||
|
|
1ec09848b6 | ||
|
|
5131514917 | ||
|
|
38a83bb361 | ||
|
|
62fc6fa53d | ||
|
|
71264e19b8 | ||
|
|
bd3ce60985 | ||
|
|
327817c047 | ||
|
|
a39022fbbe | ||
|
|
d3d0df46f1 | ||
|
|
e3280b0bb7 | ||
|
|
575cd014d2 | ||
|
|
946e5c2c1e | ||
|
|
78ed97ca07 | ||
|
|
f77b5bd4b8 | ||
|
|
fe353a7561 | ||
|
|
c4e20a652d | ||
|
|
af63eed654 | ||
|
|
a9fcc7b03a | ||
|
|
2a43da6bdf | ||
|
|
f8d7ddd9de | ||
|
|
bee8770ce0 | ||
|
|
cc710b09cb | ||
|
|
c1aa005db9 | ||
|
|
c801a2c7bb | ||
|
|
12fe91a6dd | ||
|
|
8b4481f7fd | ||
|
|
2ea1f4e593 | ||
|
|
ee10f7c0d9 | ||
|
|
3de5e8fa52 | ||
|
|
ae2dcbea33 | ||
|
|
48e1384219 | ||
|
|
cabe2fcff0 | ||
|
|
2021da0a8b | ||
|
|
48b43581cc | ||
|
|
8e3931edf6 | ||
|
|
9a9e0e6c42 | ||
|
|
853d7cd113 | ||
|
|
4ce4027250 | ||
|
|
b5d1de3601 | ||
|
|
1615130093 | ||
|
|
a518885612 | ||
|
|
f5a1a9a9cc | ||
|
|
284bbf34e6 | ||
|
|
57db615a33 | ||
|
|
cc2593cbdb | ||
|
|
44020dcc76 | ||
|
|
1e3f86cfe1 | ||
|
|
375fb97c06 | ||
|
|
cf839eac08 | ||
|
|
9a88ee24d3 | ||
|
|
110ce5e951 | ||
|
|
5554585348 | ||
|
|
1bdccebce8 | ||
|
|
e14dc52fa7 | ||
|
|
6bb9a70603 | ||
|
|
6eb0744986 | ||
|
|
8f8b67f57f | ||
|
|
e32ec7a192 | ||
|
|
dc4cbb71e2 | ||
|
|
689a0a216b | ||
|
|
b7e9d3f954 | ||
|
|
8d0ff8fecc | ||
|
|
c6218a0e5f | ||
|
|
c7049788f7 | ||
|
|
30a5ec6ee1 | ||
|
|
562338cad1 | ||
|
|
913d8276e1 | ||
|
|
790e3fa2f8 | ||
|
|
3d60c83ba2 | ||
|
|
55a32df928 | ||
|
|
27b8ed4327 | ||
|
|
98487b501d | ||
|
|
bf0779a3ed | ||
|
|
17709cc692 | ||
|
|
2bb13a1545 | ||
|
|
a098a5cf22 | ||
|
|
a6fdec8656 | ||
|
|
1d3fca653f | ||
|
|
816991c172 | ||
|
|
ba3c2ca8bc | ||
|
|
4f8fc49d15 | ||
|
|
ea77b4497e | ||
|
|
1ecd563b53 | ||
|
|
0444d07b02 | ||
|
|
44fefe9064 | ||
|
|
5ec79a9ff5 | ||
|
|
01c480f01f | ||
|
|
460b5a75cd | ||
|
|
272f6203b9 | ||
|
|
75dd657ba8 | ||
|
|
8a3ea78a55 | ||
|
|
d5ff4f9a4f | ||
|
|
7f0e6beb83 | ||
|
|
0e90952b5b | ||
|
|
669ad540e5 | ||
|
|
93f3848172 | ||
|
|
f5ebba9eff | ||
|
|
587c8f74a1 | ||
|
|
9eb77178e8 | ||
|
|
1ef6f58204 | ||
|
|
bf43a798df | ||
|
|
622cc45e72 | ||
|
|
ccd6dfaec0 | ||
|
|
71bb3124f4 | ||
|
|
99368fa3f7 | ||
|
|
16d1946205 | ||
|
|
62f7c479fa | ||
|
|
332e67c72d | ||
|
|
8d24d80fdc | ||
|
|
5de451fa98 | ||
|
|
fa5e5dd8cd | ||
|
|
cfd3aab952 | ||
|
|
a2350598da | ||
|
|
b2eacc46b4 | ||
|
|
a14747623d | ||
|
|
65655c5753 | ||
|
|
3693ad88c1 | ||
|
|
fbff63bb02 | ||
|
|
dddffce2a1 | ||
|
|
e62879ac91 | ||
|
|
fe43e503a3 | ||
|
|
7f157a9ff1 | ||
|
|
2911a86263 | ||
|
|
25f58cd259 | ||
|
|
f5aa60bae9 | ||
|
|
8aaf29a7c3 | ||
|
|
9eb6fe838e | ||
|
|
f6680a3375 | ||
|
|
a2963d9fc3 | ||
|
|
2d0f4e83a6 | ||
|
|
01642564ed | ||
|
|
ff9795d421 | ||
|
|
196e33998a | ||
|
|
4a808ab15c | ||
|
|
916580cb19 | ||
|
|
21fb11d79b | ||
|
|
e54db7c7c5 | ||
|
|
691ee27cc5 | ||
|
|
dc0ca5cc84 | ||
|
|
c43633ebb9 | ||
|
|
01cfd0ad33 | ||
|
|
eff6a5bed9 | ||
|
|
f53f246f6e | ||
|
|
5a4df84fc4 | ||
|
|
f459cd2c98 | ||
|
|
55d5f2f41a | ||
|
|
66144bb8b6 | ||
|
|
d1f1e6cff7 | ||
|
|
9f7fa6b6b6 | ||
|
|
b0734f5768 | ||
|
|
34cef89ce8 | ||
|
|
c4b5d8f2e9 | ||
|
|
1930e5dc74 | ||
|
|
cab2b12594 | ||
|
|
df15340fc2 | ||
|
|
44099c0792 |
No files matched your search
Generated
+15
-1
@@ -27,6 +27,11 @@
|
||||
<emptyLine />
|
||||
</value>
|
||||
</option>
|
||||
<option name="RIGHT_MARGIN" value="120" />
|
||||
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" />
|
||||
<AndroidXmlCodeStyleSettings>
|
||||
<option name="ARRANGEMENT_SETTINGS_MIGRATED_TO_191" value="true" />
|
||||
</AndroidXmlCodeStyleSettings>
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
@@ -86,6 +91,7 @@
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
@@ -96,6 +102,7 @@
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
@@ -107,6 +114,7 @@
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
@@ -117,6 +125,7 @@
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
@@ -127,6 +136,7 @@
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
@@ -137,6 +147,7 @@
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
@@ -147,6 +158,7 @@
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
@@ -158,6 +170,7 @@
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
@@ -169,6 +182,7 @@
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
@@ -179,4 +193,4 @@
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
</component>
|
||||
@@ -1,3 +1,16 @@
|
||||
3.9.0 (November, 12, 2019)
|
||||
|
||||
- preview Markdown with syntax highlighting @AndyScherzinger
|
||||
- improved DavX5 integration @bitfireAT
|
||||
- AutoUpload: allow files to upload into subfolder
|
||||
- new media player service @ezaquarii
|
||||
- Remote wipe integration
|
||||
- Print from within Collabora
|
||||
- enhanced SingleSignOn
|
||||
- outdated server warning set to NC14
|
||||
|
||||
For a full list, please see https://github.com/nextcloud/android/milestone/38
|
||||
|
||||
## 3.8.1 (October, 11, 2019)
|
||||
|
||||
- upload images into subfolder, if source folder also has subfolder
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
1. Backport pull request
|
||||
1. Pull requests that also need changes on library
|
||||
1. Adding new files
|
||||
1. File naming
|
||||
1. Menu files
|
||||
1. Translations
|
||||
1. Releases
|
||||
1. Types
|
||||
@@ -236,6 +238,24 @@ Source code of app:
|
||||
-->
|
||||
```
|
||||
|
||||
## File naming
|
||||
|
||||
The file naming patterns are inspired and based on [Ribot's Android Project And Code Guidelines](https://github.com/ribot/android-guidelines/blob/c1d8c9c904eb31bf01fe24aadb963b74281fe79a/project_and_code_guidelines.md).
|
||||
|
||||
### Menu files
|
||||
|
||||
Similar to layout files, menu files should match the name of the component. For example, if we are defining a menu file that is going to be used in the `UserProfileActivity`, then the name of the file should be `activity_user_profile.xml`. Same pattern applies for menus used in adapter view items, dialogs, etc.
|
||||
|
||||
| Component | Class Name | Menu Name |
|
||||
| ---------------- | ---------------------- | ----------------------------- |
|
||||
| Activity | `UserProfileActivity` | `activity_user_profile.xml` |
|
||||
| Fragment | `SignUpFragment` | `fragment_sign_up.xml` |
|
||||
| Dialog | `ChangePasswordDialog` | `dialog_change_password.xml` |
|
||||
| AdapterView item | --- | `item_person.xml` |
|
||||
| Partial layout | --- | `partial_stats_bar.xml` |
|
||||
|
||||
A good practice is to not include the word `menu` as part of the name because these files are already located in the `menu` directory. In case a component uses several menus in different places (via popup menus) then the resource name would be extended. For example, if the user profile activity has two popup menus for configuring the users settings and one for the handling group assignments then the file names for the menus would be: `activity_user_profile_user_settings.xml` and `activity_user_profile_group_assignments.xml`.
|
||||
|
||||
## Translations
|
||||
We manage translations via [Transifex](https://www.transifex.com/nextcloud/nextcloud/android/). So just request joining the translation team for Android on the site and start translating. All translations will then be automatically pushed to this repository, there is no need for any pull request for translations.
|
||||
|
||||
|
||||
+31
-22
@@ -7,7 +7,7 @@
|
||||
import com.github.spotbugs.SpotBugsTask
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.50'
|
||||
ext.kotlin_version = '1.3.61'
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
@@ -20,13 +20,13 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.1'
|
||||
classpath 'com.android.tools.build:gradle:3.5.2'
|
||||
classpath('com.dicedmelon.gradle:jacoco-android:0.1.4') {
|
||||
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
|
||||
}
|
||||
classpath 'gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.6'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.1.1"
|
||||
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ configurations {
|
||||
exclude group: 'com.google.firebase', module: 'firebase-core'
|
||||
exclude group: 'com.google.firebase', module: 'firebase-analytics'
|
||||
exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
|
||||
exclude group: 'org.jetbrains', module: 'annotations-java5' // via prism4j, already using annotations explicitely
|
||||
|
||||
// check for updates every build
|
||||
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
|
||||
@@ -56,8 +57,9 @@ configurations {
|
||||
|
||||
ext {
|
||||
jacocoVersion = "0.8.2"
|
||||
daggerVersion = "2.25"
|
||||
markwonVersion = '4.1.2'
|
||||
daggerVersion = "2.25.2"
|
||||
markwonVersion = "4.2.0"
|
||||
prismVersion = "2.0.0"
|
||||
androidLibraryVersion = "master-SNAPSHOT"
|
||||
|
||||
travisBuild = System.getenv("TRAVIS") == "true"
|
||||
@@ -79,7 +81,7 @@ repositories {
|
||||
|
||||
// semantic versioning for version code
|
||||
def versionMajor = 3
|
||||
def versionMinor = 9
|
||||
def versionMinor = 10
|
||||
def versionPatch = 0
|
||||
def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
|
||||
|
||||
@@ -103,7 +105,12 @@ android {
|
||||
abortOnError false
|
||||
htmlReport true
|
||||
htmlOutput file("$project.buildDir/reports/lint/lint.html")
|
||||
disable 'MissingTranslation', 'GradleDependency', 'VectorPath', 'IconMissingDensityFolder', 'IconDensities'
|
||||
disable 'MissingTranslation',
|
||||
'GradleDependency',
|
||||
'VectorPath',
|
||||
'IconMissingDensityFolder',
|
||||
'IconDensities',
|
||||
'GoogleAppIndexingWarning'
|
||||
}
|
||||
|
||||
dexOptions {
|
||||
@@ -113,7 +120,7 @@ android {
|
||||
compileSdkVersion 28
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 14
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 28
|
||||
|
||||
// arguments to be passed to functional tests
|
||||
@@ -160,8 +167,8 @@ android {
|
||||
versionDev {
|
||||
applicationId "com.nextcloud.android.beta"
|
||||
dimension "default"
|
||||
versionCode 20191024
|
||||
versionName "20191024"
|
||||
versionCode 20191129
|
||||
versionName "20191129"
|
||||
}
|
||||
|
||||
qa {
|
||||
@@ -267,11 +274,11 @@ dependencies {
|
||||
qaImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.1.0-beta01'
|
||||
implementation 'com.jakewharton:disklrucache:2.0.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
implementation 'androidx.exifinterface:exifinterface:1.0.0'
|
||||
implementation 'androidx.exifinterface:exifinterface:1.1.0'
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0"
|
||||
implementation "androidx.work:work-runtime:2.2.0"
|
||||
implementation "androidx.work:work-runtime-ktx:2.2.0"
|
||||
@@ -290,7 +297,7 @@ dependencies {
|
||||
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
|
||||
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
|
||||
implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
|
||||
implementation 'com.google.android:flexbox:1.1.1'
|
||||
implementation 'com.google.android:flexbox:2.0.0'
|
||||
implementation 'org.parceler:parceler-api:1.1.12'
|
||||
kapt 'org.parceler:parceler:1.1.12'
|
||||
implementation('com.github.bumptech.glide:glide:3.8.0') {
|
||||
@@ -299,11 +306,11 @@ dependencies {
|
||||
implementation 'com.caverock:androidsvg:1.4'
|
||||
implementation 'androidx.annotation:annotation:1.1.0'
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
implementation 'org.jetbrains:annotations:17.0.0'
|
||||
implementation 'org.jetbrains:annotations:18.0.0'
|
||||
|
||||
implementation 'com.github.cotechde.hwsecurity:hwsecurity-fido:2.5.1'
|
||||
|
||||
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.0'
|
||||
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1'
|
||||
spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
|
||||
|
||||
implementation "com.google.dagger:dagger:$daggerVersion"
|
||||
@@ -319,13 +326,15 @@ dependencies {
|
||||
implementation 'org.conscrypt:conscrypt-android:2.2.1'
|
||||
|
||||
// dependencies for markdown rendering
|
||||
implementation ("io.noties.markwon:core:$markwonVersion")
|
||||
implementation ("io.noties.markwon:ext-latex:$markwonVersion")
|
||||
implementation ("io.noties.markwon:ext-strikethrough:$markwonVersion")
|
||||
implementation ("io.noties.markwon:ext-tables:$markwonVersion")
|
||||
implementation ("io.noties.markwon:ext-tasklist:$markwonVersion")
|
||||
implementation ("io.noties.markwon:html:$markwonVersion")
|
||||
implementation ("io.noties.markwon:linkify:$markwonVersion")
|
||||
implementation "io.noties.markwon:core:$markwonVersion"
|
||||
implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
|
||||
implementation "io.noties.markwon:ext-tables:$markwonVersion"
|
||||
implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
|
||||
implementation "io.noties.markwon:html:$markwonVersion"
|
||||
|
||||
implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
|
||||
implementation "io.noties:prism4j:$prismVersion"
|
||||
kapt "io.noties:prism4j-bundler:$prismVersion"
|
||||
|
||||
// dependencies for local unit tests
|
||||
testImplementation 'junit:junit:4.12'
|
||||
|
||||
@@ -1 +1 @@
|
||||
421
|
||||
407
|
||||
+18
-2
@@ -17,7 +17,8 @@
|
||||
<Match>
|
||||
<Or>
|
||||
<Class name="~.*\.Dagger.*" />
|
||||
<Class name="~com.nextcloud.client.di\..*_.*" />
|
||||
<Class name="~com\.nextcloud\.client\.di\..*_.*" />
|
||||
<Class name="~dagger\.android\..*" />
|
||||
</Or>
|
||||
</Match>
|
||||
<!-- Dagger generated code uses internal APIs -->
|
||||
@@ -30,10 +31,25 @@
|
||||
<Match>
|
||||
<Or>
|
||||
<Class name="~.*BindingImpl"/>
|
||||
<Class name="~.*\.DataBinderMapperImpl"/>
|
||||
<Class name="~.*\.DataBinderMapperImpl"/>
|
||||
</Or>
|
||||
</Match>
|
||||
|
||||
<!-- Third-party library code -->
|
||||
<Match>
|
||||
<Or>
|
||||
<Package name="~io\.noties\..*" />
|
||||
<Package name="~third_parties\.ezvcard_android\..*" />
|
||||
<Package name="~com\.afollestad\.sectionedrecyclerview\..*" />
|
||||
<Package name="~butterknife\..*" />
|
||||
<Package name="~de\.cotech\..*" />
|
||||
<Package name="~pl\.droidsonroids\..*" />
|
||||
</Or>
|
||||
</Match>
|
||||
<Match>
|
||||
<Class name="~com\.owncloud\.android\.ui\.preview\.MarkwonGrammarLocator.*" />
|
||||
</Match>
|
||||
|
||||
<Bug pattern="PATH_TRAVERSAL_IN" />
|
||||
<Bug pattern="ANDROID_EXTERNAL_FILE_ACCESS" />
|
||||
<Bug pattern="BAS_BLOATED_ASSIGNMENT_SCOPE" />
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
Svobodně licencovaná Nexcloud Android aplikace, dávající vám mobilní svobodu.
|
||||
|
||||
Software, který můžete nasadit na vlastní server a ten organizuje ukládání a synchronizaci souborů. Díky doplňkům jde o kompletní groupwarové řešení.
|
||||
Funkce:
|
||||
* Snadno použitelné moderní rozhraní, přizpůsobené vzhledu, používaném na vašem serveru
|
||||
* Nahrávejte soubory na svůj Nextcloud server
|
||||
* Sdílejte je s ostatními
|
||||
* Udržujte své oblíbené soubory a složky synchronizované
|
||||
* Hledejte napříč všemi složkami na svém serveru
|
||||
* Automaticky nahrávejte své fotky a videa, pořízená zařízením
|
||||
* Udržujte si přehled pomocí oznámení
|
||||
* Podporuje vícero účtů
|
||||
* Zabezpečený přístup k vašim datům pomocí otisku prstu nebo PIN kódu
|
||||
* Napojení na DAVx5 (dříve známé pod názvem DAVdroid) pro snadné nastavení synchronizace kalendáře a kontaktů
|
||||
* Soubory nahrané do nexcloudu lze snadno sdílet s ostatními.
|
||||
* Přístup odkudkoli přes webové a mobilní rozhraní.
|
||||
* Synchronizace s počítačem umožňující offline práci.
|
||||
* Vaše data jsou na vašem serveru a máte nad nimi plnou kontrolu.
|
||||
* Jde o svobodný software, který snadno můžete sami hostovat a volně si ho přizplsobit. V případě potřeby je ale k dispozici komerční podpora.
|
||||
* Vyhledávání napříč soubory.
|
||||
* Synchronizace kontaktů a zpráv.
|
||||
* Sdílení kalendářů do mobilu (DAVx5/DAVdroid)
|
||||
* Neomezený počet uživatelů, autoupload fotek přímo z mobilu, oznámení,
|
||||
* Klienti pro WIndows, MacOS, iOS, Android, web.
|
||||
* Mnoho dalších doplňků s dalšími funkcemi.
|
||||
|
||||
Veškeré nalezené problémy hlaste na https://github.com/nextcloud/android/issues a diskutujte o aplikaci na https://help.nextcloud.com/c/clients/android
|
||||
Díky Nextcloudu budete mít kompletní privátní řešení pro všechy vaše soubory, fotky, kalendáře a kontakty.
|
||||
|
||||
Noví v Nextcloud? Nextcloud je soukromý server pro synchronizaci souborů a jejich sdílení, dále pro komunikaci. Jedná se o svobodný software a můžete ho hostovat svými silami nebo za to zaplatit nějaké společnosti. Tím máte pod kontrolou své fotky, kalendář a kontakty, dokumenty a vše ostatní.
|
||||
|
||||
Podívejte se na Nextcloud na https://nextcloud.com
|
||||
Připomínky zasílejte na https://github.com/nextcloud/android/issues, diskutovat lze na https://help.nextcloud.com/c/clients a vše ostatní najdete na https://nextcloud.com
|
||||
@@ -1 +1 @@
|
||||
Produktivní platforma hostovaná u vás, kde vaše data jsou opravdu vaše
|
||||
Platforma pro produktivitu hostovaná u vás, kde vaše data jsou opravdu vaše
|
||||
@@ -1 +1 @@
|
||||
Nextcloud Android 앱으로 내 Nextcloud에 있는 모든 파일을 사용하십시오.
|
||||
컨트롤 가능한 자체 호스팅 생산성 플랫폼
|
||||
@@ -24,4 +24,9 @@ interface IInputStreamService {
|
||||
in ParcelFileDescriptor requestBodyParcelFileDescriptor);
|
||||
|
||||
ParcelFileDescriptor performNextcloudRequest(in ParcelFileDescriptor input);
|
||||
|
||||
ParcelFileDescriptor performNextcloudRequestAndBodyStreamV2(in ParcelFileDescriptor input,
|
||||
in ParcelFileDescriptor requestBodyParcelFileDescriptor);
|
||||
|
||||
ParcelFileDescriptor performNextcloudRequestV2(in ParcelFileDescriptor input);
|
||||
}
|
||||
@@ -94,6 +94,7 @@ public class InputStreamBinder extends IInputStreamService.Stub {
|
||||
private static final int HTTP_STATUS_CODE_MULTIPLE_CHOICES = 300;
|
||||
|
||||
private static final char PATH_SEPARATOR = '/';
|
||||
private static final int ZERO_LENGTH = 0;
|
||||
private Context context;
|
||||
private UserAccountManager accountManager;
|
||||
|
||||
@@ -112,6 +113,42 @@ public class InputStreamBinder extends IInputStreamService.Stub {
|
||||
return nvp;
|
||||
}
|
||||
|
||||
public ParcelFileDescriptor performNextcloudRequestV2(ParcelFileDescriptor input) {
|
||||
return performNextcloudRequestAndBodyStreamV2(input, null);
|
||||
}
|
||||
|
||||
public ParcelFileDescriptor performNextcloudRequestAndBodyStreamV2(
|
||||
ParcelFileDescriptor input,
|
||||
ParcelFileDescriptor requestBodyParcelFileDescriptor) {
|
||||
// read the input
|
||||
final InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(input);
|
||||
|
||||
final InputStream requestBodyInputStream = requestBodyParcelFileDescriptor != null ?
|
||||
new ParcelFileDescriptor.AutoCloseInputStream(requestBodyParcelFileDescriptor) : null;
|
||||
Exception exception = null;
|
||||
Response response = new Response();
|
||||
|
||||
try {
|
||||
// Start request and catch exceptions
|
||||
NextcloudRequest request = deserializeObjectAndCloseStream(is);
|
||||
response = processRequestV2(request, requestBodyInputStream);
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, "Error during Nextcloud request", e);
|
||||
exception = e;
|
||||
}
|
||||
|
||||
try {
|
||||
// Write exception to the stream followed by the actual network stream
|
||||
InputStream exceptionStream = serializeObjectToInputStreamV2(exception, response.getPlainHeadersString());
|
||||
InputStream resultStream = new java.io.SequenceInputStream(exceptionStream, response.getBody());
|
||||
|
||||
return ParcelFileDescriptorUtil.pipeFrom(resultStream, thread -> Log.d(TAG, "Done sending result"));
|
||||
} catch (IOException e) {
|
||||
Log_OC.e(TAG, "Error while sending response back to client app", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ParcelFileDescriptor performNextcloudRequest(ParcelFileDescriptor input) {
|
||||
return performNextcloudRequestAndBodyStream(input, null);
|
||||
}
|
||||
@@ -128,7 +165,7 @@ public class InputStreamBinder extends IInputStreamService.Stub {
|
||||
InputStream httpStream = new InputStream() {
|
||||
@Override
|
||||
public int read() {
|
||||
return 0;
|
||||
return ZERO_LENGTH;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -157,6 +194,23 @@ public class InputStreamBinder extends IInputStreamService.Stub {
|
||||
return null;
|
||||
}
|
||||
|
||||
private ByteArrayInputStream serializeObjectToInputStreamV2(Exception exception, String headers) {
|
||||
byte[] baosByteArray = new byte[0];
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
|
||||
oos.writeObject(exception);
|
||||
oos.writeObject(headers);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
baosByteArray = baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
Log_OC.e(TAG, "Error while sending response back to client app", e);
|
||||
}
|
||||
|
||||
return new ByteArrayInputStream(baosByteArray);
|
||||
}
|
||||
|
||||
private <T extends Serializable> ByteArrayInputStream serializeObjectToInputStream(T obj) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
@@ -315,6 +369,71 @@ public class InputStreamBinder extends IInputStreamService.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
private Response processRequestV2(final NextcloudRequest request, final InputStream requestBodyInputStream)
|
||||
throws UnsupportedOperationException,
|
||||
com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException,
|
||||
OperationCanceledException, AuthenticatorException, IOException {
|
||||
Account account = accountManager.getAccountByName(request.getAccountName());
|
||||
if (account == null) {
|
||||
throw new IllegalStateException(EXCEPTION_ACCOUNT_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Validate token
|
||||
if (!isValid(request)) {
|
||||
throw new IllegalStateException(EXCEPTION_INVALID_TOKEN);
|
||||
}
|
||||
|
||||
// Validate URL
|
||||
if (request.getUrl().length() == 0 || request.getUrl().charAt(0) != PATH_SEPARATOR) {
|
||||
throw new IllegalStateException(EXCEPTION_INVALID_REQUEST_URL,
|
||||
new IllegalStateException("URL need to start with a /"));
|
||||
}
|
||||
|
||||
OwnCloudClientManager ownCloudClientManager = OwnCloudClientManagerFactory.getDefaultSingleton();
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
|
||||
OwnCloudClient client = ownCloudClientManager.getClientFor(ocAccount, context);
|
||||
|
||||
HttpMethodBase method = buildMethod(request, client.getBaseUri(), requestBodyInputStream);
|
||||
|
||||
method.setQueryString(convertMapToNVP(request.getParameter()));
|
||||
method.addRequestHeader("OCS-APIREQUEST", "true");
|
||||
|
||||
for (Map.Entry<String, List<String>> header : request.getHeader().entrySet()) {
|
||||
// https://stackoverflow.com/a/3097052
|
||||
method.addRequestHeader(header.getKey(), TextUtils.join(",", header.getValue()));
|
||||
|
||||
if ("OCS-APIREQUEST".equalsIgnoreCase(header.getKey())) {
|
||||
throw new IllegalStateException(
|
||||
"The 'OCS-APIREQUEST' header will be automatically added by the Nextcloud SSO Library. " +
|
||||
"Please remove the header before making a request");
|
||||
}
|
||||
}
|
||||
|
||||
client.setFollowRedirects(request.isFollowRedirects());
|
||||
int status = client.executeMethod(method);
|
||||
|
||||
// Check if status code is 2xx --> https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success
|
||||
if (status >= HTTP_STATUS_CODE_OK && status < HTTP_STATUS_CODE_MULTIPLE_CHOICES) {
|
||||
return new Response(method.getResponseBodyAsStream(), method.getResponseHeaders());
|
||||
} else {
|
||||
StringBuilder total = new StringBuilder();
|
||||
InputStream inputStream = method.getResponseBodyAsStream();
|
||||
// If response body is available
|
||||
if (inputStream != null) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String line = reader.readLine();
|
||||
while (line != null) {
|
||||
total.append(line).append('\n');
|
||||
line = reader.readLine();
|
||||
}
|
||||
Log_OC.e(TAG, total.toString());
|
||||
}
|
||||
throw new IllegalStateException(EXCEPTION_HTTP_REQUEST_FAILED,
|
||||
new IllegalStateException(String.valueOf(status),
|
||||
new IllegalStateException(total.toString())));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValid(NextcloudRequest request) {
|
||||
String callingPackageName = context.getPackageManager().getNameForUid(Binder.getCallingUid());
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2019 Tobias Kaminsky
|
||||
* Copyright (C) 2019 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.android.sso;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public class PlainHeader implements Serializable {
|
||||
private static final long serialVersionUID = 3284979177401282512L;
|
||||
|
||||
@Getter
|
||||
private String name;
|
||||
@Getter
|
||||
private String value;
|
||||
|
||||
PlainHeader(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream oos) throws IOException {
|
||||
oos.writeObject(name);
|
||||
oos.writeObject(value);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
name = (String) in.readObject();
|
||||
value = (String) in.readObject();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2019 Tobias Kaminsky
|
||||
* Copyright (C) 2019 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.android.sso;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.apache.commons.httpclient.Header;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public class Response {
|
||||
@Getter
|
||||
private InputStream body;
|
||||
private Header[] headers;
|
||||
|
||||
public Response() {
|
||||
headers = new Header[0];
|
||||
body = new InputStream() {
|
||||
@Override
|
||||
public int read() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Response(InputStream inputStream, Header[] headers) {
|
||||
this.body = inputStream;
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
public String getPlainHeadersString() {
|
||||
List<PlainHeader> arrayList = new ArrayList<>(headers.length);
|
||||
|
||||
for (Header header : headers) {
|
||||
arrayList.add(new PlainHeader(header.getName(), header.getValue()));
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
return gson.toJson(arrayList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz <[email protected]>
|
||||
* Copyright (C) 2019 Chris Narkiewicz
|
||||
* Copyright (C) 2019 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.content.Context
|
||||
import android.net.Uri
|
||||
import com.owncloud.android.MainApp
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount
|
||||
import com.owncloud.android.lib.common.OwnCloudBasicCredentials
|
||||
import java.net.URI
|
||||
|
||||
/**
|
||||
* This object represents anonymous user, ie. user that did not log in the Nextcloud server.
|
||||
* It serves as a semantically correct "empty value", allowing simplification of logic
|
||||
* in various components requiring user data, such as DB queries.
|
||||
*/
|
||||
internal class AnonymousUser(private val accountType: String) : User {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun fromContext(context: Context): AnonymousUser {
|
||||
val type = context.getString(R.string.account_type)
|
||||
return AnonymousUser(type)
|
||||
}
|
||||
}
|
||||
|
||||
override val accountName: String = "anonymous"
|
||||
override val server = Server(URI.create(""), MainApp.MINIMUM_SUPPORTED_SERVER_VERSION)
|
||||
override val isAnonymous = true
|
||||
|
||||
override fun toPlatformAccount(): Account {
|
||||
return Account(accountName, accountType)
|
||||
}
|
||||
|
||||
override fun toOwnCloudAccount(): OwnCloudAccount {
|
||||
return OwnCloudAccount(Uri.EMPTY, OwnCloudBasicCredentials("", ""))
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,31 @@ package com.nextcloud.client.account;
|
||||
|
||||
import android.accounts.Account;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This interface provides access to currently selected user Account.
|
||||
* This interface provides access to currently selected user.
|
||||
*
|
||||
* @see UserAccountManager
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface CurrentAccountProvider {
|
||||
/**
|
||||
* Get currently active account.
|
||||
* Get currently active account.
|
||||
*
|
||||
* @return Currently selected {@link Account} or first valid {@link Account} registered in OS or null, if not available at all.
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
Account getCurrentAccount();
|
||||
|
||||
/**
|
||||
* Get currently active user profile. If there is no actice user, anonymous user is returned.
|
||||
*
|
||||
* @return User profile. Profile is never null.
|
||||
*/
|
||||
@NonNull
|
||||
default User getUser() {
|
||||
return new AnonymousUser("dummy");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz <[email protected]>
|
||||
* Copyright (C) 2019 Chris Narkiewicz
|
||||
* Copyright (C) 2019 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 com.owncloud.android.lib.common.OwnCloudAccount
|
||||
|
||||
/**
|
||||
* This class represents normal user logged into the Nextcloud server.
|
||||
*/
|
||||
internal class RegisteredUser(
|
||||
private val account: Account,
|
||||
private val ownCloudAccount: OwnCloudAccount,
|
||||
override val server: Server
|
||||
) : User {
|
||||
override val isAnonymous = false
|
||||
|
||||
override val accountName: String get() {
|
||||
return account.name
|
||||
}
|
||||
|
||||
override fun toPlatformAccount(): Account {
|
||||
return account
|
||||
}
|
||||
|
||||
override fun toOwnCloudAccount(): OwnCloudAccount {
|
||||
return ownCloudAccount
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz <[email protected]>
|
||||
* Copyright (C) 2019 Chris Narkiewicz
|
||||
* Copyright (C) 2019 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 com.owncloud.android.lib.resources.status.OwnCloudVersion
|
||||
import java.net.URI
|
||||
|
||||
/**
|
||||
* This object provides all information necessary to interact
|
||||
* with backend server.
|
||||
*/
|
||||
data class Server(val uri: URI, val version: OwnCloudVersion)
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz <[email protected]>
|
||||
* Copyright (C) 2019 Chris Narkiewicz
|
||||
* Copyright (C) 2019 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 com.owncloud.android.lib.common.OwnCloudAccount
|
||||
|
||||
interface User {
|
||||
val accountName: String
|
||||
val server: Server
|
||||
val isAnonymous: Boolean
|
||||
|
||||
/**
|
||||
* This is temporary helper method created to facilitate incremental refactoring.
|
||||
* Code using legacy platform Account can be partially converted to instantiate User
|
||||
* object and use account instance when required.
|
||||
*
|
||||
* This method calls will allow tracing code awaiting further refactoring.
|
||||
*
|
||||
* @return Account instance that is associated with this User object.
|
||||
*/
|
||||
@Deprecated("Temporary workaround")
|
||||
fun toPlatformAccount(): Account
|
||||
|
||||
/**
|
||||
* This is temporary helper method created to facilitate incremental refactoring.
|
||||
* Code using legacy ownCloud account can be partially converted to instantiate User
|
||||
* object and use account instance when required.
|
||||
*
|
||||
* This method calls will allow tracing code awaiting further refactoring.
|
||||
*
|
||||
* @return OwnCloudAccount instance that is associated with this User object.
|
||||
*/
|
||||
@Deprecated("Temporary workaround")
|
||||
fun toOwnCloudAccount(): OwnCloudAccount
|
||||
}
|
||||
@@ -21,10 +21,13 @@ package com.nextcloud.client.account;
|
||||
|
||||
import android.accounts.Account;
|
||||
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
@@ -51,6 +54,22 @@ public interface UserAccountManager extends CurrentAccountProvider {
|
||||
@NonNull
|
||||
Account[] getAccounts();
|
||||
|
||||
/**
|
||||
* Get configured nextcloud user accounts
|
||||
* @return List of users or empty list, if users are not registered.
|
||||
*/
|
||||
@NonNull
|
||||
List<User> getAllUsers();
|
||||
|
||||
/**
|
||||
* Get user with a specific account name.
|
||||
*
|
||||
* @param accountName Account name of the requested user
|
||||
* @return User or empty optional if user does not exist.
|
||||
*/
|
||||
@NonNull
|
||||
Optional<User> getUser(CharSequence accountName);
|
||||
|
||||
/**
|
||||
* Check if Nextcloud account is registered in {@link android.accounts.AccountManager}
|
||||
*
|
||||
@@ -78,10 +97,24 @@ public interface UserAccountManager extends CurrentAccountProvider {
|
||||
* @return Version of the OC server corresponding to account, according to the data saved
|
||||
* in the system AccountManager
|
||||
*/
|
||||
@Deprecated
|
||||
@NonNull
|
||||
OwnCloudVersion getServerVersion(Account account);
|
||||
|
||||
@Deprecated
|
||||
boolean isSearchSupported(@Nullable Account account);
|
||||
|
||||
/**
|
||||
* Check if user's account supports media streaming. This is a property of server where user has his account.
|
||||
*
|
||||
* @deprecated Please use {@link OwnCloudVersion#isMediaStreamingSupported()} directly,
|
||||
* obtainable from {@link User#getServer()} and {@link Server#getVersion()}
|
||||
*
|
||||
* @param account Account used to perform {@link android.accounts.AccountManager} lookup.
|
||||
*
|
||||
* @return true is server supports media streaming, false otherwise
|
||||
*/
|
||||
@Deprecated
|
||||
boolean isMediaStreamingSupported(@Nullable Account account);
|
||||
|
||||
void resetOwnCloudAccount();
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
@@ -35,11 +36,18 @@ import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.UserInfo;
|
||||
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.status.OwnCloudVersion;
|
||||
import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -80,6 +88,20 @@ public class UserAccountManagerImpl implements UserAccountManager {
|
||||
return accountManager.getAccountsByType(getAccountType());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public List<User> getAllUsers() {
|
||||
Account[] accounts = getAccounts();
|
||||
List<User> users = new ArrayList<>(accounts.length);
|
||||
for (Account account : accounts) {
|
||||
User user = createUserFromAccount(account);
|
||||
if (user != null) {
|
||||
users.add(user);
|
||||
}
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(Account account) {
|
||||
Account[] nextcloudAccounts = getAccounts();
|
||||
@@ -103,6 +125,7 @@ public class UserAccountManagerImpl implements UserAccountManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Account getCurrentAccount() {
|
||||
Account[] ocAccounts = getAccounts();
|
||||
@@ -139,6 +162,76 @@ public class UserAccountManagerImpl implements UserAccountManager {
|
||||
return defaultAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporary solution to convert platform account to user instance.
|
||||
* It takes null and returns null on error to ease error handling
|
||||
* in legacy code.
|
||||
*
|
||||
* @param account Account instance
|
||||
* @return User instance or null, if conversion failed
|
||||
*/
|
||||
@Nullable
|
||||
private User createUserFromAccount(@Nullable Account account) {
|
||||
if (account == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
OwnCloudAccount ownCloudAccount = null;
|
||||
try {
|
||||
ownCloudAccount = new OwnCloudAccount(account, context);
|
||||
} catch (AccountUtils.AccountNotFoundException ex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Server version
|
||||
*/
|
||||
String serverVersionStr = accountManager.getUserData(account, AccountUtils.Constants.KEY_OC_VERSION);
|
||||
OwnCloudVersion serverVersion;
|
||||
if (serverVersionStr != null) {
|
||||
serverVersion = new OwnCloudVersion(serverVersionStr);
|
||||
} else {
|
||||
serverVersion = MainApp.MINIMUM_SUPPORTED_SERVER_VERSION;
|
||||
}
|
||||
|
||||
/*
|
||||
* Server address
|
||||
*/
|
||||
String serverAddressStr = accountManager.getUserData(account, AccountUtils.Constants.KEY_OC_BASE_URL);
|
||||
if (serverAddressStr == null || serverAddressStr.isEmpty()) {
|
||||
return AnonymousUser.fromContext(context);
|
||||
}
|
||||
URI serverUri = URI.create(serverAddressStr); // TODO: validate
|
||||
|
||||
return new RegisteredUser(
|
||||
account,
|
||||
ownCloudAccount,
|
||||
new Server(serverUri, serverVersion)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user. If user cannot be retrieved due to data error, anonymous user is returned instead.
|
||||
*
|
||||
*
|
||||
* @return User instance
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public User getUser() {
|
||||
Account account = getCurrentAccount();
|
||||
User user = createUserFromAccount(account);
|
||||
return user != null ? user : AnonymousUser.fromContext(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Optional<User> getUser(CharSequence accountName) {
|
||||
Account account = getAccountByName(accountName.toString());
|
||||
User user = createUserFromAccount(account);
|
||||
return Optional.of(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public OwnCloudAccount getCurrentOwnCloudAccount() {
|
||||
@@ -197,6 +290,7 @@ public class UserAccountManagerImpl implements UserAccountManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
@NonNull
|
||||
public OwnCloudVersion getServerVersion(Account account) {
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.nextcloud.client.logger.FileLogHandler;
|
||||
import com.nextcloud.client.logger.Logger;
|
||||
import com.nextcloud.client.logger.LoggerImpl;
|
||||
import com.nextcloud.client.logger.LogsRepository;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.datamodel.UploadsStorageManager;
|
||||
import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository;
|
||||
@@ -106,8 +107,8 @@ class AppModule {
|
||||
}
|
||||
|
||||
@Provides
|
||||
FilesRepository filesRepository(UserAccountManager accountManager) {
|
||||
return new RemoteFilesRepository(new FilesServiceApiImpl(accountManager));
|
||||
FilesRepository filesRepository(UserAccountManager accountManager, ClientFactory clientFactory) {
|
||||
return new RemoteFilesRepository(new FilesServiceApiImpl(accountManager, clientFactory));
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.owncloud.android.files.services.FileDownloader;
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
import com.owncloud.android.jobs.NotificationJob;
|
||||
import com.owncloud.android.providers.DiskLruImageCacheFileProvider;
|
||||
import com.owncloud.android.providers.FileContentProvider;
|
||||
import com.owncloud.android.providers.UsersAndGroupsSearchProvider;
|
||||
import com.owncloud.android.services.AccountManagerService;
|
||||
import com.owncloud.android.services.OperationsService;
|
||||
@@ -148,6 +149,7 @@ abstract class ComponentsModule {
|
||||
@ContributesAndroidInjector abstract BootupBroadcastReceiver bootupBroadcastReceiver();
|
||||
@ContributesAndroidInjector abstract NotificationJob.NotificationReceiver notificationJobBroadcastReceiver();
|
||||
|
||||
@ContributesAndroidInjector abstract FileContentProvider fileContentProvider();
|
||||
@ContributesAndroidInjector abstract UsersAndGroupsSearchProvider usersAndGroupsSearchProvider();
|
||||
@ContributesAndroidInjector abstract DiskLruImageCacheFileProvider diskLruImageCacheFileProvider();
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class ShowErrorActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.activity_error_show, menu)
|
||||
menuInflater.inflate(R.menu.activity_show_error, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ class EtmPreferencesFragment : EtmBaseFragment() {
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater)
|
||||
inflater.inflate(R.menu.etm_preferences, menu)
|
||||
inflater.inflate(R.menu.fragment_etm_preferences, menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
|
||||
@@ -26,6 +26,7 @@ import androidx.annotation.RequiresApi
|
||||
import androidx.work.ListenableWorker
|
||||
import androidx.work.WorkerFactory
|
||||
import androidx.work.WorkerParameters
|
||||
import com.nextcloud.client.core.Clock
|
||||
import com.nextcloud.client.device.DeviceInfo
|
||||
import com.nextcloud.client.device.PowerManagementService
|
||||
import com.nextcloud.client.preferences.AppPreferences
|
||||
@@ -40,6 +41,7 @@ import javax.inject.Provider
|
||||
class BackgroundJobFactory @Inject constructor(
|
||||
private val preferences: AppPreferences,
|
||||
private val contentResolver: ContentResolver,
|
||||
private val clock: Clock,
|
||||
private val powerManagerService: PowerManagementService,
|
||||
private val backgroundJobManager: Provider<BackgroundJobManager>,
|
||||
private val deviceInfo: DeviceInfo
|
||||
@@ -58,13 +60,14 @@ class BackgroundJobFactory @Inject constructor(
|
||||
}
|
||||
|
||||
return when (workerClass) {
|
||||
ContentObserverWork::class -> createContentObserverJob(context, workerParameters)
|
||||
ContentObserverWork::class -> createContentObserverJob(context, workerParameters, clock)
|
||||
else -> null // falls back to default factory
|
||||
}
|
||||
}
|
||||
|
||||
private fun createContentObserverJob(context: Context, workerParameters: WorkerParameters): ListenableWorker? {
|
||||
val folderResolver = SyncedFolderProvider(contentResolver, preferences)
|
||||
private fun createContentObserverJob(context: Context, workerParameters: WorkerParameters, clock: Clock):
|
||||
ListenableWorker? {
|
||||
val folderResolver = SyncedFolderProvider(contentResolver, preferences, clock)
|
||||
@RequiresApi(Build.VERSION_CODES.N)
|
||||
if (deviceInfo.apiLevel >= Build.VERSION_CODES.N) {
|
||||
return ContentObserverWork(
|
||||
|
||||
@@ -84,7 +84,7 @@ class LogsActivity : ToolbarActivity() {
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.logs_menu, menu)
|
||||
menuInflater.inflate(R.menu.activity_logs, menu)
|
||||
(menu.findItem(R.id.action_search).actionView as SearchView).apply {
|
||||
setOnQueryTextListener(searchBoxListener)
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.accounts.OperationCanceledException;
|
||||
import android.app.Activity;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
|
||||
@@ -35,10 +36,31 @@ import java.io.IOException;
|
||||
|
||||
public interface ClientFactory {
|
||||
|
||||
/**
|
||||
* This exception wraps all possible errors thrown by trigger-happy
|
||||
* OwnCloudClient constructor, making try-catch blocks manageable.
|
||||
*
|
||||
* This is a temporary refactoring measure, until a better
|
||||
* error handling method can be procured.
|
||||
*/
|
||||
@Deprecated
|
||||
class CreationException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
CreationException(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
}
|
||||
|
||||
OwnCloudClient create(User user) throws CreationException;
|
||||
|
||||
@Deprecated
|
||||
OwnCloudClient create(Account account)
|
||||
throws OperationCanceledException, AuthenticatorException, IOException,
|
||||
AccountUtils.AccountNotFoundException;
|
||||
|
||||
@Deprecated
|
||||
OwnCloudClient create(Account account, Activity currentActivity)
|
||||
throws OperationCanceledException, AuthenticatorException, IOException,
|
||||
AccountUtils.AccountNotFoundException;
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
@@ -41,6 +42,18 @@ class ClientFactoryImpl implements ClientFactory {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OwnCloudClient create(User user) throws CreationException {
|
||||
try {
|
||||
return OwnCloudClientFactory.createOwnCloudClient(user.toPlatformAccount(), context);
|
||||
} catch (OperationCanceledException|
|
||||
AuthenticatorException|
|
||||
IOException|
|
||||
AccountUtils.AccountNotFoundException e) {
|
||||
throw new CreationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OwnCloudClient create(Account account)
|
||||
throws OperationCanceledException, AuthenticatorException, IOException,
|
||||
|
||||
@@ -20,14 +20,13 @@
|
||||
|
||||
package com.nextcloud.client.network;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
import com.evernote.android.job.JobRequest;
|
||||
import com.nextcloud.client.account.Server;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.nextcloud.client.logger.Logger;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
@@ -44,10 +43,11 @@ class ConnectivityServiceImpl implements ConnectivityService {
|
||||
|
||||
private final static String TAG = ConnectivityServiceImpl.class.getName();
|
||||
|
||||
private ConnectivityManager connectivityManager;
|
||||
private UserAccountManager accountManager;
|
||||
private ClientFactory clientFactory;
|
||||
private GetRequestBuilder requestBuilder;
|
||||
private final ConnectivityManager connectivityManager;
|
||||
private final UserAccountManager accountManager;
|
||||
private final ClientFactory clientFactory;
|
||||
private final GetRequestBuilder requestBuilder;
|
||||
private final Logger logger;
|
||||
|
||||
static class GetRequestBuilder implements Function1<String, GetMethod> {
|
||||
@Override
|
||||
@@ -59,55 +59,55 @@ class ConnectivityServiceImpl implements ConnectivityService {
|
||||
ConnectivityServiceImpl(ConnectivityManager connectivityManager,
|
||||
UserAccountManager accountManager,
|
||||
ClientFactory clientFactory,
|
||||
GetRequestBuilder requestBuilder) {
|
||||
GetRequestBuilder requestBuilder,
|
||||
Logger logger) {
|
||||
this.connectivityManager = connectivityManager;
|
||||
this.accountManager = accountManager;
|
||||
this.clientFactory = clientFactory;
|
||||
this.requestBuilder = requestBuilder;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInternetWalled() {
|
||||
if (isOnlineWithWifi()) {
|
||||
try {
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
OwnCloudAccount ocAccount = accountManager.getCurrentOwnCloudAccount();
|
||||
if (account != null && ocAccount != null) {
|
||||
OwnCloudVersion serverVersion = accountManager.getServerVersion(account);
|
||||
Server server = accountManager.getUser().getServer();
|
||||
String baseServerAddress = server.getUri().toString();
|
||||
if (baseServerAddress.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
String url;
|
||||
if (server.getVersion().compareTo(OwnCloudVersion.nextcloud_13) > 0) {
|
||||
url = baseServerAddress + "/index.php/204";
|
||||
} else {
|
||||
url = baseServerAddress + "/status.php";
|
||||
}
|
||||
|
||||
String url;
|
||||
if (serverVersion.compareTo(OwnCloudVersion.nextcloud_13) > 0) {
|
||||
url = ocAccount.getBaseUri() + "/index.php/204";
|
||||
} else {
|
||||
url = ocAccount.getBaseUri() + "/status.php";
|
||||
}
|
||||
GetMethod get = requestBuilder.invoke(url);
|
||||
HttpClient client = clientFactory.createPlainClient();
|
||||
|
||||
GetMethod get = requestBuilder.invoke(url);
|
||||
HttpClient client = clientFactory.createPlainClient();
|
||||
int status = client.executeMethod(get);
|
||||
|
||||
int status = client.executeMethod(get);
|
||||
|
||||
if (serverVersion.compareTo(OwnCloudVersion.nextcloud_13) > 0) {
|
||||
return !(status == HttpStatus.SC_NO_CONTENT &&
|
||||
(get.getResponseContentLength() == -1 || get.getResponseContentLength() == 0));
|
||||
} else {
|
||||
if (status == HttpStatus.SC_OK) {
|
||||
try {
|
||||
// try parsing json to verify response
|
||||
// check if json contains maintenance and it should be false
|
||||
|
||||
String json = get.getResponseBodyAsString();
|
||||
return new JSONObject(json).getBoolean("maintenance");
|
||||
} catch (Exception e) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (server.getVersion().compareTo(OwnCloudVersion.nextcloud_13) > 0) {
|
||||
return !(status == HttpStatus.SC_NO_CONTENT &&
|
||||
(get.getResponseContentLength() == -1 || get.getResponseContentLength() == 0));
|
||||
} else {
|
||||
if (status == HttpStatus.SC_OK) {
|
||||
try {
|
||||
// try parsing json to verify response
|
||||
// check if json contains maintenance and it should be false
|
||||
String json = get.getResponseBodyAsString();
|
||||
return new JSONObject(json).getBoolean("maintenance");
|
||||
} catch (Exception e) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log_OC.e(TAG, "Error checking internet connection", e);
|
||||
logger.e(TAG, "Error checking internet connection", e);
|
||||
}
|
||||
} else {
|
||||
return getActiveNetworkType() == JobRequest.NetworkType.ANY;
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.logger.Logger;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@@ -36,11 +37,13 @@ public class NetworkModule {
|
||||
@Provides
|
||||
ConnectivityService connectivityService(ConnectivityManager connectivityManager,
|
||||
UserAccountManager accountManager,
|
||||
ClientFactory clientFactory) {
|
||||
ClientFactory clientFactory,
|
||||
Logger logger) {
|
||||
return new ConnectivityServiceImpl(connectivityManager,
|
||||
accountManager,
|
||||
clientFactory,
|
||||
new ConnectivityServiceImpl.GetRequestBuilder());
|
||||
new ConnectivityServiceImpl.GetRequestBuilder(),
|
||||
logger);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -28,7 +28,6 @@ import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
@@ -81,7 +80,7 @@ public class FirstRunActivity extends BaseActivity implements ViewPager.OnPageCh
|
||||
setSlideshowSize(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);
|
||||
|
||||
Button loginButton = findViewById(R.id.login);
|
||||
loginButton.setBackgroundColor(Color.WHITE);
|
||||
loginButton.setBackgroundColor(getResources().getColor(R.color.login_btn_tint));
|
||||
loginButton.setTextColor(getResources().getColor(R.color.primary));
|
||||
|
||||
loginButton.setOnClickListener(v -> {
|
||||
@@ -95,7 +94,7 @@ public class FirstRunActivity extends BaseActivity implements ViewPager.OnPageCh
|
||||
});
|
||||
|
||||
Button providerButton = findViewById(R.id.signup);
|
||||
providerButton.setBackgroundColor(getResources().getColor(R.color.primary_dark));
|
||||
providerButton.setBackgroundColor(getResources().getColor(R.color.primary));
|
||||
providerButton.setTextColor(getResources().getColor(R.color.login_text_color));
|
||||
providerButton.setVisibility(isProviderOrOwnInstallationVisible ? View.VISIBLE : View.GONE);
|
||||
providerButton.setOnClickListener(v -> {
|
||||
@@ -218,17 +217,19 @@ public class FirstRunActivity extends BaseActivity implements ViewPager.OnPageCh
|
||||
return;
|
||||
}
|
||||
|
||||
setAccount(account);
|
||||
userAccountManager.setCurrentOwnCloudAccount(account.name);
|
||||
onAccountSet();
|
||||
|
||||
Intent i = new Intent(this, FileDisplayActivity.class);
|
||||
i.setAction(FileDisplayActivity.RESTART);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(i);
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static FeatureItem[] getFirstRun() {
|
||||
return new FeatureItem[]{
|
||||
new FeatureItem(R.drawable.logo, R.string.first_run_1_text, R.string.empty, true, false),
|
||||
|
||||
@@ -23,8 +23,42 @@ package com.nextcloud.client.preferences;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.utils.FileSortOrder;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This interface provides single point of entry for access to all application
|
||||
* preferences and allows clients to subscribe for specific configuration
|
||||
* changes.
|
||||
*/
|
||||
public interface AppPreferences {
|
||||
|
||||
/**
|
||||
* Preferences listener. Callbacks should be invoked on main thread.
|
||||
*
|
||||
* Miantainers should extend this interface with callbacks for specific
|
||||
* events.
|
||||
*/
|
||||
interface Listener {
|
||||
default void onDarkThemeEnabledChanged(boolean enabled) {
|
||||
/* default empty implementation */
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers preferences listener. It no-ops if listener
|
||||
* is already registered.
|
||||
*
|
||||
* @param listener application preferences listener
|
||||
*/
|
||||
void addListener(@Nullable Listener listener);
|
||||
|
||||
/**
|
||||
* Unregister listener. It no-ops if listener is not registered.
|
||||
*
|
||||
* @param listener application preferences listener
|
||||
*/
|
||||
void removeListener(@Nullable Listener listener);
|
||||
|
||||
void setKeysReInitEnabled();
|
||||
boolean isKeysReInitEnabled();
|
||||
|
||||
@@ -239,6 +273,20 @@ public interface AppPreferences {
|
||||
*/
|
||||
int getUploaderBehaviour();
|
||||
|
||||
/**
|
||||
* Enable dark theme.
|
||||
*
|
||||
* This is reactive property. Listeners will be invoked if registered.
|
||||
*
|
||||
* @param enabled true to turn dark theme on, false to turn it off
|
||||
*/
|
||||
void setDarkThemeEnabled(boolean enabled);
|
||||
|
||||
/**
|
||||
* @return true if application uses dark UI theme, false otherwise
|
||||
*/
|
||||
boolean isDarkThemeEnabled();
|
||||
|
||||
/**
|
||||
* Saves the uploader behavior which the user has set last.
|
||||
*
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
@@ -35,12 +36,21 @@ import com.owncloud.android.ui.activity.PassCodeActivity;
|
||||
import com.owncloud.android.ui.activity.SettingsActivity;
|
||||
import com.owncloud.android.utils.FileSortOrder;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import static com.owncloud.android.ui.fragment.OCFileListFragment.FOLDER_LAYOUT_LIST;
|
||||
|
||||
/**
|
||||
* Helper to simplify reading of Preferences all around the app
|
||||
* Implementation of application-wide preferences using {@link SharedPreferences}.
|
||||
*
|
||||
* Users should not use this class directly. Please use {@link AppPreferences} interafce
|
||||
* instead.
|
||||
*/
|
||||
public final class AppPreferencesImpl implements AppPreferences {
|
||||
|
||||
/**
|
||||
* Constant to access value of last path selected by the user to upload a file shared from other app.
|
||||
* Value handled by the app without direct access in the UI.
|
||||
@@ -48,6 +58,7 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||
public static final String AUTO_PREF__LAST_SEEN_VERSION_CODE = "lastSeenVersionCode";
|
||||
public static final String STORAGE_PATH = "storage_path";
|
||||
public static final float DEFAULT_GRID_COLUMN = 4.0f;
|
||||
|
||||
private static final String AUTO_PREF__LAST_UPLOAD_PATH = "last_upload_path";
|
||||
private static final String AUTO_PREF__UPLOAD_FROM_LOCAL_LAST_PATH = "upload_from_local_last_path";
|
||||
private static final String AUTO_PREF__UPLOAD_FILE_EXTENSION_MAP_URL = "prefs_upload_file_extension_map_url";
|
||||
@@ -68,6 +79,8 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||
private static final String PREF__AUTO_UPLOAD_INIT = "autoUploadInit";
|
||||
private static final String PREF__FOLDER_SORT_ORDER = "folder_sort_order";
|
||||
private static final String PREF__FOLDER_LAYOUT = "folder_layout";
|
||||
static final String PREF__DARK_THEME_ENABLED = "dark_theme_enabled";
|
||||
|
||||
private static final String PREF__LOCK_TIMESTAMP = "lock_timestamp";
|
||||
private static final String PREF__SHOW_MEDIA_SCAN_NOTIFICATIONS = "show_media_scan_notifications";
|
||||
private static final String PREF__LOCK = SettingsActivity.PREFERENCE_LOCK;
|
||||
@@ -79,7 +92,54 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||
private final Context context;
|
||||
private final SharedPreferences preferences;
|
||||
private final CurrentAccountProvider currentAccountProvider;
|
||||
private final ListenerRegistry listeners;
|
||||
|
||||
/**
|
||||
* Adapter delegating raw {@link SharedPreferences.OnSharedPreferenceChangeListener} calls
|
||||
* with key-value pairs to respective {@link com.nextcloud.client.preferences.AppPreferences.Listener} method.
|
||||
*/
|
||||
static class ListenerRegistry implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private final AppPreferences preferences;
|
||||
private final Set<Listener> listeners;
|
||||
|
||||
ListenerRegistry(AppPreferences preferences) {
|
||||
this.preferences = preferences;
|
||||
this.listeners = new CopyOnWriteArraySet<>();
|
||||
}
|
||||
|
||||
void add(@Nullable final Listener listener) {
|
||||
if (listener != null) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
void remove(@Nullable final Listener listener) {
|
||||
if (listener != null) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if(PREF__DARK_THEME_ENABLED.equals(key)) {
|
||||
boolean enabled = preferences.isDarkThemeEnabled();
|
||||
for(Listener l : listeners) {
|
||||
l.onDarkThemeEnabledChanged(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a temporary workaround to access app preferences in places that cannot use
|
||||
* dependency injection yet. Use injected component via {@link AppPreferences} interface.
|
||||
*
|
||||
* WARNING: this creates new instance! it does not return app-wide singleton
|
||||
*
|
||||
* @param context Context used to create shared preferences
|
||||
* @return New instance of app preferences component
|
||||
*/
|
||||
@Deprecated
|
||||
public static AppPreferences fromContext(Context context) {
|
||||
final CurrentAccountProvider currentAccountProvider = UserAccountManagerImpl.fromContext(context);
|
||||
final SharedPreferences prefs = android.preference.PreferenceManager.getDefaultSharedPreferences(context);
|
||||
@@ -90,6 +150,18 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||
this.context = appContext;
|
||||
this.preferences = preferences;
|
||||
this.currentAccountProvider = currentAccountProvider;
|
||||
this.listeners = new ListenerRegistry(this);
|
||||
this.preferences.registerOnSharedPreferenceChangeListener(listeners);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(@Nullable AppPreferences.Listener listener) {
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(@Nullable AppPreferences.Listener listener) {
|
||||
this.listeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -211,7 +283,7 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||
@Override
|
||||
public String getFolderLayout(OCFile folder) {
|
||||
return getFolderPreference(context,
|
||||
currentAccountProvider.getCurrentAccount(),
|
||||
currentAccountProvider.getUser(),
|
||||
PREF__FOLDER_LAYOUT,
|
||||
folder,
|
||||
FOLDER_LAYOUT_LIST);
|
||||
@@ -220,7 +292,7 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||
@Override
|
||||
public void setFolderLayout(OCFile folder, String layout_name) {
|
||||
setFolderPreference(context,
|
||||
currentAccountProvider.getCurrentAccount(),
|
||||
currentAccountProvider.getUser(),
|
||||
PREF__FOLDER_LAYOUT,
|
||||
folder,
|
||||
layout_name);
|
||||
@@ -229,7 +301,7 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||
@Override
|
||||
public FileSortOrder getSortOrderByFolder(OCFile folder) {
|
||||
return FileSortOrder.sortOrders.get(getFolderPreference(context,
|
||||
currentAccountProvider.getCurrentAccount(),
|
||||
currentAccountProvider.getUser(),
|
||||
PREF__FOLDER_SORT_ORDER,
|
||||
folder,
|
||||
FileSortOrder.sort_a_to_z.name));
|
||||
@@ -238,7 +310,7 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||
@Override
|
||||
public void setSortOrder(OCFile folder, FileSortOrder sortOrder) {
|
||||
setFolderPreference(context,
|
||||
currentAccountProvider.getCurrentAccount(),
|
||||
currentAccountProvider.getUser(),
|
||||
PREF__FOLDER_SORT_ORDER,
|
||||
folder,
|
||||
sortOrder.name);
|
||||
@@ -251,28 +323,23 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||
|
||||
@Override
|
||||
public FileSortOrder getSortOrderByType(FileSortOrder.Type type, FileSortOrder defaultOrder) {
|
||||
Account account = currentAccountProvider.getCurrentAccount();
|
||||
if (account == null) {
|
||||
User user = currentAccountProvider.getUser();
|
||||
if (user.isAnonymous()) {
|
||||
return defaultOrder;
|
||||
}
|
||||
|
||||
ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
|
||||
|
||||
String value = dataProvider.getValue(account.name, PREF__FOLDER_SORT_ORDER + "_" + type);
|
||||
String value = dataProvider.getValue(user.getAccountName(), PREF__FOLDER_SORT_ORDER + "_" + type);
|
||||
|
||||
return value.isEmpty() ? defaultOrder : FileSortOrder.sortOrders.get(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSortOrder(FileSortOrder.Type type, FileSortOrder sortOrder) {
|
||||
Account account = currentAccountProvider.getCurrentAccount();
|
||||
|
||||
if (account == null) {
|
||||
throw new IllegalArgumentException("Account may not be null!");
|
||||
}
|
||||
|
||||
User user = currentAccountProvider.getUser();
|
||||
ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
|
||||
dataProvider.storeOrUpdateKeyValue(account.name, PREF__FOLDER_SORT_ORDER + "_" + type, sortOrder.name);
|
||||
dataProvider.storeOrUpdateKeyValue(user.getAccountName(), PREF__FOLDER_SORT_ORDER + "_" + type, sortOrder.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -340,6 +407,16 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||
return preferences.getInt(AUTO_PREF__UPLOADER_BEHAVIOR, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDarkThemeEnabled(boolean enabled) {
|
||||
preferences.edit().putBoolean(PREF__DARK_THEME_ENABLED, enabled).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDarkThemeEnabled() {
|
||||
return preferences.getBoolean(PREF__DARK_THEME_ENABLED, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUploaderBehaviour(int uploaderBehaviour) {
|
||||
preferences.edit().putInt(AUTO_PREF__UPLOADER_BEHAVIOR, uploaderBehaviour).apply();
|
||||
@@ -495,22 +572,22 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||
* @return Preference value
|
||||
*/
|
||||
private static String getFolderPreference(final Context context,
|
||||
final Account account,
|
||||
final User user,
|
||||
final String preferenceName,
|
||||
final OCFile folder,
|
||||
final String defaultValue) {
|
||||
if (account == null) {
|
||||
if (user.isAnonymous()) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver());
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(user.toPlatformAccount(), context.getContentResolver());
|
||||
|
||||
String value = dataProvider.getValue(account.name, getKeyFromFolder(preferenceName, folder));
|
||||
String value = dataProvider.getValue(user.getAccountName(), getKeyFromFolder(preferenceName, folder));
|
||||
OCFile prefFolder = folder;
|
||||
while (prefFolder != null && value.isEmpty()) {
|
||||
prefFolder = storageManager.getFileById(prefFolder.getParentId());
|
||||
value = dataProvider.getValue(account.name, getKeyFromFolder(preferenceName, prefFolder));
|
||||
value = dataProvider.getValue(user.getAccountName(), getKeyFromFolder(preferenceName, prefFolder));
|
||||
}
|
||||
return value.isEmpty() ? defaultValue : value;
|
||||
}
|
||||
@@ -524,16 +601,12 @@ public final class AppPreferencesImpl implements AppPreferences {
|
||||
* @param value Preference value to set.
|
||||
*/
|
||||
private static void setFolderPreference(final Context context,
|
||||
final Account account,
|
||||
final User user,
|
||||
final String preferenceName,
|
||||
final OCFile folder,
|
||||
final String value) {
|
||||
if (account == null) {
|
||||
throw new IllegalArgumentException("Account may not be null!");
|
||||
}
|
||||
|
||||
ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
|
||||
dataProvider.storeOrUpdateKeyValue(account.name, getKeyFromFolder(preferenceName, folder), value);
|
||||
dataProvider.storeOrUpdateKeyValue(user.getAccountName(), getKeyFromFolder(preferenceName, folder), value);
|
||||
}
|
||||
|
||||
private static String getKeyFromFolder(String preferenceName, OCFile folder) {
|
||||
|
||||
@@ -0,0 +1,366 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.nextcloud.java.util;
|
||||
|
||||
import com.nextcloud.java.util.function.Predicate;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import androidx.core.util.Consumer;
|
||||
import androidx.core.util.ObjectsCompat;
|
||||
import androidx.core.util.Supplier;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
|
||||
/**
|
||||
* This class is backported from Java 8 to be used on older Android API levels.
|
||||
* It uses available interfaces from Kotlin and androidx. It is semantically
|
||||
* identical with Java 8 API, allowing smooth migration when those APIs become
|
||||
* available.
|
||||
*
|
||||
* A container object which may or may not contain a non-null value.
|
||||
* If a value is present, {@code isPresent()} will return {@code true} and
|
||||
* {@code get()} will return the value.
|
||||
*
|
||||
* <p>Additional methods that depend on the presence or absence of a contained
|
||||
* value are provided, such as {@link #orElse(java.lang.Object) orElse()}
|
||||
* (return a default value if value not present) and
|
||||
* {@link #ifPresent(Consumer) ifPresent()} (execute a block
|
||||
* of code if the value is present).
|
||||
*/
|
||||
public final class Optional<T> {
|
||||
/**
|
||||
* Common instance for {@code empty()}.
|
||||
*/
|
||||
private static final Optional<?> EMPTY = new Optional<>();
|
||||
|
||||
/**
|
||||
* If non-null, the value; if null, indicates no value is present
|
||||
*/
|
||||
private final T value;
|
||||
|
||||
/**
|
||||
* Constructs an empty instance.
|
||||
*
|
||||
* @implNote Generally only one empty instance, {@link Optional#EMPTY},
|
||||
* should exist per VM.
|
||||
*/
|
||||
private Optional() {
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty {@code Optional} instance. No value is present for this
|
||||
* Optional.
|
||||
*
|
||||
* @apiNote Though it may be tempting to do so, avoid testing if an object
|
||||
* is empty by comparing with {@code ==} against instances returned by
|
||||
* {@code Option.empty()}. There is no guarantee that it is a singleton.
|
||||
* Instead, use {@link #isPresent()}.
|
||||
*
|
||||
* @param <T> Type of the non-existent value
|
||||
* @return an empty {@code Optional}
|
||||
*/
|
||||
public static<T> Optional<T> empty() {
|
||||
@SuppressWarnings("unchecked")
|
||||
Optional<T> t = (Optional<T>) EMPTY;
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance with the value present.
|
||||
*
|
||||
* @param value the non-null value to be present
|
||||
* @throws NullPointerException if value is null
|
||||
*/
|
||||
private Optional(T value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an {@code Optional} with the specified present non-null value.
|
||||
*
|
||||
* @param <T> the class of the value
|
||||
* @param value the value to be present, which must be non-null
|
||||
* @return an {@code Optional} with the value present
|
||||
* @throws NullPointerException if value is null
|
||||
*/
|
||||
public static <T> Optional<T> of(T value) {
|
||||
return new Optional<>(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an {@code Optional} describing the specified value, if non-null,
|
||||
* otherwise returns an empty {@code Optional}.
|
||||
*
|
||||
* @param <T> the class of the value
|
||||
* @param value the possibly-null value to describe
|
||||
* @return an {@code Optional} with a present value if the specified value
|
||||
* is non-null, otherwise an empty {@code Optional}
|
||||
*/
|
||||
public static <T> Optional<T> ofNullable(T value) {
|
||||
return value == null ? empty() : of(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* If a value is present in this {@code Optional}, returns the value,
|
||||
* otherwise throws {@code NoSuchElementException}.
|
||||
*
|
||||
* @return the non-null value held by this {@code Optional}
|
||||
* @throws NoSuchElementException if there is no value present
|
||||
*
|
||||
* @see Optional#isPresent()
|
||||
*/
|
||||
public T get() {
|
||||
if (value == null) {
|
||||
throw new NoSuchElementException("No value present");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code true} if there is a value present, otherwise {@code false}.
|
||||
*
|
||||
* @return {@code true} if there is a value present, otherwise {@code false}
|
||||
*/
|
||||
public boolean isPresent() {
|
||||
return value != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a value is present, invoke the specified consumer with the value,
|
||||
* otherwise do nothing.
|
||||
*
|
||||
* @param consumer block to be executed if a value is present
|
||||
* @throws NullPointerException if value is present and {@code consumer} is
|
||||
* null
|
||||
*/
|
||||
public void ifPresent(Consumer<? super T> consumer) {
|
||||
if (value != null) {
|
||||
consumer.accept(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If a value is present, and the value matches the given predicate,
|
||||
* return an {@code Optional} describing the value, otherwise return an
|
||||
* empty {@code Optional}.
|
||||
*
|
||||
* @param predicate a predicate to apply to the value, if present
|
||||
* @return an {@code Optional} describing the value of this {@code Optional}
|
||||
* if a value is present and the value matches the given predicate,
|
||||
* otherwise an empty {@code Optional}
|
||||
* @throws NullPointerException if the predicate is null
|
||||
*/
|
||||
public Optional<T> filter(Predicate<? super T> predicate) {
|
||||
if (predicate == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (!isPresent()) {
|
||||
return this;
|
||||
} else {
|
||||
return predicate.test(value) ? this : empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If a value is present, apply the provided mapping function to it,
|
||||
* and if the result is non-null, return an {@code Optional} describing the
|
||||
* result. Otherwise return an empty {@code Optional}.
|
||||
*
|
||||
* @apiNote This method supports post-processing on optional values, without
|
||||
* the need to explicitly check for a return status. For example, the
|
||||
* following code traverses a stream of file names, selects one that has
|
||||
* not yet been processed, and then opens that file, returning an
|
||||
* {@code Optional<FileInputStream>}:
|
||||
*
|
||||
* <pre>{@code
|
||||
* Optional<FileInputStream> fis =
|
||||
* names.stream().filter(name -> !isProcessedYet(name))
|
||||
* .findFirst()
|
||||
* .map(name -> new FileInputStream(name));
|
||||
* }</pre>
|
||||
*
|
||||
* Here, {@code findFirst} returns an {@code Optional<String>}, and then
|
||||
* {@code map} returns an {@code Optional<FileInputStream>} for the desired
|
||||
* file if one exists.
|
||||
*
|
||||
* @param <U> The type of the result of the mapping function
|
||||
* @param mapper a mapping function to apply to the value, if present
|
||||
* @return an {@code Optional} describing the result of applying a mapping
|
||||
* function to the value of this {@code Optional}, if a value is present,
|
||||
* otherwise an empty {@code Optional}
|
||||
* @throws NullPointerException if the mapping function is null
|
||||
*/
|
||||
public<U> Optional<U> map(Function1<? super T, ? extends U> mapper) {
|
||||
if (mapper == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (!isPresent()) {
|
||||
return empty();
|
||||
} else {
|
||||
return Optional.ofNullable(mapper.invoke(value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If a value is present, apply the provided {@code Optional}-bearing
|
||||
* mapping function to it, return that result, otherwise return an empty
|
||||
* {@code Optional}. This method is similar to {@link #map(Function1)},
|
||||
* but the provided mapper is one whose result is already an {@code Optional},
|
||||
* and if invoked, {@code flatMap} does not wrap it with an additional
|
||||
* {@code Optional}.
|
||||
*
|
||||
* @param <U> The type parameter to the {@code Optional} returned by
|
||||
* @param mapper a mapping function to apply to the value, if present
|
||||
* the mapping function
|
||||
* @return the result of applying an {@code Optional}-bearing mapping
|
||||
* function to the value of this {@code Optional}, if a value is present,
|
||||
* otherwise an empty {@code Optional}
|
||||
* @throws NullPointerException if the mapping function is null or returns
|
||||
* a null result
|
||||
*/
|
||||
public<U> Optional<U> flatMap(Function1<? super T, Optional<U>> mapper) {
|
||||
if(mapper == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (!isPresent()) {
|
||||
return empty();
|
||||
} else {
|
||||
Optional<U> u = mapper.invoke(value);
|
||||
if (u == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return u;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value if present, otherwise return {@code other}.
|
||||
*
|
||||
* @param other the value to be returned if there is no value present, may
|
||||
* be null
|
||||
* @return the value, if present, otherwise {@code other}
|
||||
*/
|
||||
public T orElse(T other) {
|
||||
return value != null ? value : other;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value if present, otherwise invoke {@code other} and return
|
||||
* the result of that invocation.
|
||||
*
|
||||
* @param other a {@code Supplier} whose result is returned if no value
|
||||
* is present
|
||||
* @return the value if present otherwise the result of {@code other.get()}
|
||||
* @throws NullPointerException if value is not present and {@code other} is
|
||||
* null
|
||||
*/
|
||||
public T orElseGet(Supplier<? extends T> other) {
|
||||
return value != null ? value : other.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the contained value, if present, otherwise throw an exception
|
||||
* to be created by the provided supplier.
|
||||
*
|
||||
* @apiNote A method reference to the exception constructor with an empty
|
||||
* argument list can be used as the supplier. For example,
|
||||
* {@code IllegalStateException::new}
|
||||
*
|
||||
* @param <X> Type of the exception to be thrown
|
||||
* @param exceptionSupplier The supplier which will return the exception to
|
||||
* be thrown
|
||||
* @return the present value
|
||||
* @throws X if there is no value present
|
||||
* @throws NullPointerException if no value is present and
|
||||
* {@code exceptionSupplier} is null
|
||||
*/
|
||||
public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
|
||||
if (value != null) {
|
||||
return value;
|
||||
} else {
|
||||
throw exceptionSupplier.get();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether some other object is "equal to" this Optional. The
|
||||
* other object is considered equal if:
|
||||
* <ul>
|
||||
* <li>it is also an {@code Optional} and;
|
||||
* <li>both instances have no value present or;
|
||||
* <li>the present values are "equal to" each other via {@code equals()}.
|
||||
* </ul>
|
||||
*
|
||||
* @param obj an object to be tested for equality
|
||||
* @return {code true} if the other object is "equal to" this object
|
||||
* otherwise {@code false}
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof Optional)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Optional<?> other = (Optional<?>) obj;
|
||||
return ObjectsCompat.equals(value, other.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash code value of the present value, if any, or 0 (zero) if
|
||||
* no value is present.
|
||||
*
|
||||
* @return hash code value of the present value or 0 if no value is present
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ObjectsCompat.hashCode(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a non-empty string representation of this Optional suitable for
|
||||
* debugging. The exact presentation format is unspecified and may vary
|
||||
* between implementations and versions.
|
||||
*
|
||||
* @implSpec If a value is present the result must include its string
|
||||
* representation in the result. Empty and present Optionals must be
|
||||
* unambiguously differentiable.
|
||||
*
|
||||
* @return the string representation of this instance
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return value != null
|
||||
? String.format("Optional[%s]", value)
|
||||
: "Optional.empty";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.nextcloud.java.util.function;
|
||||
|
||||
/**
|
||||
* This class is backported from Java 8 to be used on older Android API levels.
|
||||
*
|
||||
* Represents a predicate (boolean-valued function) of one argument.
|
||||
*
|
||||
* <p>This is a <a href="package-summary.html">functional interface</a>
|
||||
* whose functional method is {@link #test(Object)}.
|
||||
*
|
||||
* @param <T> the type of the input to the predicate
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Predicate<T> {
|
||||
|
||||
/**
|
||||
* Evaluates this predicate on the given argument.
|
||||
*
|
||||
* @param t the input argument
|
||||
* @return {@code true} if the input argument matches the predicate,
|
||||
* otherwise {@code false}
|
||||
*/
|
||||
boolean test(T t);
|
||||
|
||||
/**
|
||||
* Returns a composed predicate that represents a short-circuiting logical
|
||||
* AND of this predicate and another. When evaluating the composed
|
||||
* predicate, if this predicate is {@code false}, then the {@code other}
|
||||
* predicate is not evaluated.
|
||||
*
|
||||
* <p>Any exceptions thrown during evaluation of either predicate are relayed
|
||||
* to the caller; if evaluation of this predicate throws an exception, the
|
||||
* {@code other} predicate will not be evaluated.
|
||||
*
|
||||
* @param other a predicate that will be logically-ANDed with this
|
||||
* predicate
|
||||
* @return a composed predicate that represents the short-circuiting logical
|
||||
* AND of this predicate and the {@code other} predicate
|
||||
* @throws NullPointerException if other is null
|
||||
*/
|
||||
default Predicate<T> and(Predicate<? super T> other) {
|
||||
if (other == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return (t) -> test(t) && other.test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a predicate that represents the logical negation of this
|
||||
* predicate.
|
||||
*
|
||||
* @return a predicate that represents the logical negation of this
|
||||
* predicate
|
||||
*/
|
||||
default Predicate<T> negate() {
|
||||
return (t) -> !test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a composed predicate that represents a short-circuiting logical
|
||||
* OR of this predicate and another. When evaluating the composed
|
||||
* predicate, if this predicate is {@code true}, then the {@code other}
|
||||
* predicate is not evaluated.
|
||||
*
|
||||
* <p>Any exceptions thrown during evaluation of either predicate are relayed
|
||||
* to the caller; if evaluation of this predicate throws an exception, the
|
||||
* {@code other} predicate will not be evaluated.
|
||||
*
|
||||
* @param other a predicate that will be logically-ORed with this
|
||||
* predicate
|
||||
* @return a composed predicate that represents the short-circuiting logical
|
||||
* OR of this predicate and the {@code other} predicate
|
||||
* @throws NullPointerException if other is null
|
||||
*/
|
||||
default Predicate<T> or(Predicate<? super T> other) {
|
||||
if (other == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return (t) -> test(t) || other.test(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a predicate that tests if two arguments are equal according
|
||||
* to {@link androidx.core.util.ObjectsCompat#equals(Object, Object)}.
|
||||
*
|
||||
* @param <T> the type of arguments to the predicate
|
||||
* @param targetRef the object reference with which to compare for equality,
|
||||
* which may be {@code null}
|
||||
* @return a predicate that tests if two arguments are equal according
|
||||
* to {@link androidx.core.util.ObjectsCompat#equals(Object, Object)}
|
||||
*/
|
||||
static <T> Predicate<T> isEqual(Object targetRef) {
|
||||
return (null == targetRef)
|
||||
? object -> object == null
|
||||
: object -> targetRef.equals(object);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz <[email protected]>
|
||||
* Copyright (C) 2019 Chris Narkiewicz
|
||||
* Copyright (C) 2019 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a compatibility package providing some backported Java 8 classes
|
||||
* not available in some older Android runtimes.
|
||||
*/
|
||||
package com.nextcloud.java.util;
|
||||
@@ -45,6 +45,7 @@ import com.evernote.android.job.JobManager;
|
||||
import com.evernote.android.job.JobRequest;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.appinfo.AppInfo;
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.nextcloud.client.device.PowerManagementService;
|
||||
import com.nextcloud.client.di.ActivityInjector;
|
||||
import com.nextcloud.client.di.DaggerAppComponent;
|
||||
@@ -100,6 +101,7 @@ import javax.net.ssl.SSLEngine;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.core.util.Pair;
|
||||
import androidx.multidex.MultiDexApplication;
|
||||
import dagger.android.AndroidInjector;
|
||||
@@ -160,6 +162,9 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
||||
@Inject
|
||||
BackgroundJobManager backgroundJobManager;
|
||||
|
||||
@Inject
|
||||
Clock clock;
|
||||
|
||||
private PassCodeManager passCodeManager;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -242,6 +247,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
||||
@SuppressFBWarnings("ST")
|
||||
@Override
|
||||
public void onCreate() {
|
||||
setAppTheme(preferences.isDarkThemeEnabled());
|
||||
super.onCreate();
|
||||
|
||||
insertConscrypt();
|
||||
@@ -266,7 +272,8 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
||||
preferences,
|
||||
uploadsStorageManager,
|
||||
connectivityService,
|
||||
powerManagementService
|
||||
powerManagementService,
|
||||
clock
|
||||
)
|
||||
);
|
||||
|
||||
@@ -302,7 +309,8 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
||||
accountManager,
|
||||
connectivityService,
|
||||
powerManagementService,
|
||||
backgroundJobManager);
|
||||
backgroundJobManager,
|
||||
clock);
|
||||
initContactsBackup(accountManager);
|
||||
notificationChannels();
|
||||
|
||||
@@ -460,23 +468,24 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
||||
final UserAccountManager accountManager,
|
||||
final ConnectivityService connectivityService,
|
||||
final PowerManagementService powerManagementService,
|
||||
final BackgroundJobManager jobManager
|
||||
final BackgroundJobManager jobManager,
|
||||
final Clock clock
|
||||
) {
|
||||
updateToAutoUpload();
|
||||
cleanOldEntries();
|
||||
updateAutoUploadEntries();
|
||||
cleanOldEntries(clock);
|
||||
updateAutoUploadEntries(clock);
|
||||
|
||||
if (getAppContext() != null) {
|
||||
if (PermissionUtil.checkSelfPermission(getAppContext(),
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
splitOutAutoUploadEntries();
|
||||
splitOutAutoUploadEntries(clock);
|
||||
} else {
|
||||
AppPreferences preferences = AppPreferencesImpl.fromContext(getAppContext());
|
||||
preferences.setAutoUploadSplitEntriesEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
initiateExistingAutoUploadEntries();
|
||||
initiateExistingAutoUploadEntries(clock);
|
||||
|
||||
FilesSyncHelper.scheduleFilesSyncIfNeeded(mContext, jobManager);
|
||||
FilesSyncHelper.restartJobsIfNeeded(
|
||||
@@ -683,18 +692,18 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateAutoUploadEntries() {
|
||||
private static void updateAutoUploadEntries(Clock clock) {
|
||||
// updates entries to reflect their true paths
|
||||
Context context = getAppContext();
|
||||
AppPreferences preferences = AppPreferencesImpl.fromContext(context);
|
||||
if (!preferences.isAutoUploadPathsUpdateEnabled()) {
|
||||
SyncedFolderProvider syncedFolderProvider =
|
||||
new SyncedFolderProvider(MainApp.getAppContext().getContentResolver(), preferences);
|
||||
new SyncedFolderProvider(MainApp.getAppContext().getContentResolver(), preferences, clock);
|
||||
syncedFolderProvider.updateAutoUploadPaths(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
private static void splitOutAutoUploadEntries() {
|
||||
private static void splitOutAutoUploadEntries(Clock clock) {
|
||||
Context context = getAppContext();
|
||||
AppPreferences preferences = AppPreferencesImpl.fromContext(context);
|
||||
if (!preferences.isAutoUploadSplitEntriesEnabled()) {
|
||||
@@ -703,7 +712,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
||||
Log_OC.i(TAG, "Migrate synced_folders records for image/video split");
|
||||
ContentResolver contentResolver = context.getContentResolver();
|
||||
|
||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver, preferences);
|
||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver, preferences, clock);
|
||||
|
||||
final List<MediaFolder> imageMediaFolders = MediaProvider.getImageFolders(contentResolver, 1, null, true);
|
||||
final List<MediaFolder> videoMediaFolders = MediaProvider.getVideoFolders(contentResolver, 1, null, true);
|
||||
@@ -749,12 +758,12 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
||||
}
|
||||
}
|
||||
|
||||
private static void initiateExistingAutoUploadEntries() {
|
||||
private static void initiateExistingAutoUploadEntries(Clock clock) {
|
||||
new Thread(() -> {
|
||||
AppPreferences preferences = AppPreferencesImpl.fromContext(getAppContext());
|
||||
if (!preferences.isAutoUploadInitialized()) {
|
||||
SyncedFolderProvider syncedFolderProvider =
|
||||
new SyncedFolderProvider(MainApp.getAppContext().getContentResolver(), preferences);
|
||||
new SyncedFolderProvider(MainApp.getAppContext().getContentResolver(), preferences, clock);
|
||||
|
||||
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
|
||||
if (syncedFolder.isEnabled()) {
|
||||
@@ -768,7 +777,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
||||
}).start();
|
||||
}
|
||||
|
||||
private static void cleanOldEntries() {
|
||||
private static void cleanOldEntries(Clock clock) {
|
||||
// previous versions of application created broken entries in the SyncedFolderProvider
|
||||
// database, and this cleans all that and leaves 1 (newest) entry per synced folder
|
||||
|
||||
@@ -777,7 +786,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
||||
|
||||
if (!preferences.isLegacyClean()) {
|
||||
SyncedFolderProvider syncedFolderProvider =
|
||||
new SyncedFolderProvider(context.getContentResolver(), preferences);
|
||||
new SyncedFolderProvider(context.getContentResolver(), preferences, clock);
|
||||
|
||||
List<SyncedFolder> syncedFolderList = syncedFolderProvider.getSyncedFolders();
|
||||
Map<Pair<String, String>, Long> syncedFolders = new HashMap<>();
|
||||
@@ -811,4 +820,12 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
|
||||
return dispatchingAndroidInjector;
|
||||
}
|
||||
|
||||
|
||||
public static void setAppTheme(Boolean darkTheme) {
|
||||
if (darkTheme) {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
||||
} else {
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
@@ -91,6 +92,7 @@ import android.widget.Toast;
|
||||
|
||||
import com.blikoon.qrcodescanner.QrCodeActivity;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.device.DeviceInfo;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
@@ -189,7 +191,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
private static final String KEY_USERNAME = "USERNAME";
|
||||
private static final String KEY_PASSWORD = "PASSWORD";
|
||||
private static final String KEY_ASYNC_TASK_IN_PROGRESS = "AUTH_IN_PROGRESS";
|
||||
private static final String WEB_LOGIN = "/index.php/login/flow";
|
||||
public static final String WEB_LOGIN = "/index.php/login/flow";
|
||||
public static final String PROTOCOL_SUFFIX = "://";
|
||||
public static final String LOGIN_URL_DATA_KEY_VALUE_SEPARATOR = ":";
|
||||
public static final String HTTPS_PROTOCOL = "https://";
|
||||
@@ -401,12 +403,14 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
setClient(progressBar);
|
||||
|
||||
// show snackbar after 60s to switch back to old login method
|
||||
if (showLegacyLogin) {
|
||||
if (showLegacyLogin && getResources().getBoolean(R.bool.show_old_login)) {
|
||||
final String finalBaseURL = baseURL;
|
||||
new Handler().postDelayed(() -> DisplayUtils.createSnackbar(mLoginWebView,
|
||||
R.string.fallback_weblogin_text,
|
||||
Snackbar.LENGTH_INDEFINITE)
|
||||
.setActionTextColor(getResources().getColor(R.color.white))
|
||||
.setActionTextColor(getResources().getColor(R.color.themed_fg))
|
||||
.setBackgroundTint(getResources().getColor(R.color.themed_bg))
|
||||
.setTextColor(getResources().getColor(R.color.themed_fg))
|
||||
.setAction(R.string.fallback_weblogin_back, v -> {
|
||||
mLoginWebView.setVisibility(View.INVISIBLE);
|
||||
webViewLoginMethod = false;
|
||||
@@ -1732,8 +1736,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
}
|
||||
|
||||
/// add the new account as default in preferences, if there is none already
|
||||
Account defaultAccount = accountManager.getCurrentAccount();
|
||||
if (defaultAccount == null) {
|
||||
User defaultAccount = accountManager.getUser();
|
||||
if (defaultAccount.isAnonymous()) {
|
||||
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
|
||||
editor.putString("select_oc_account", accountName);
|
||||
editor.apply();
|
||||
@@ -1768,6 +1772,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
||||
setAccountAuthenticatorResult(intent.getExtras());
|
||||
setResult(RESULT_OK, intent);
|
||||
|
||||
// notify Document Provider
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
String authority = getResources().getString(R.string.document_provider_authority);
|
||||
Uri rootsUri = DocumentsContract.buildRootsUri(authority);
|
||||
getContentResolver().notifyChange(rootsUri, null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1259,8 +1259,8 @@ public class FileDataStorageManager {
|
||||
|
||||
private void resetShareFlagsInAllFiles() {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
|
||||
String[] whereArgs = new String[]{account.name};
|
||||
@@ -1279,8 +1279,8 @@ public class FileDataStorageManager {
|
||||
|
||||
private void resetShareFlagsInFolder(OCFile folder) {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PARENT + "=?";
|
||||
String[] whereArgs = new String[]{account.name, String.valueOf(folder.getFileId())};
|
||||
@@ -1299,8 +1299,8 @@ public class FileDataStorageManager {
|
||||
|
||||
private void resetShareFlagInAFile(String filePath) {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + "=?";
|
||||
String[] whereArgs = new String[]{account.name, filePath};
|
||||
|
||||
@@ -23,30 +23,29 @@ package com.owncloud.android.datamodel;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Synced folder entity containing all information per synced folder.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class SyncedFolder implements Serializable, Cloneable {
|
||||
public static final long UNPERSISTED_ID = Long.MIN_VALUE;
|
||||
public static final long EMPTY_ENABLED_TIMESTAMP_MS = -1;
|
||||
private static final long serialVersionUID = -793476118299906429L;
|
||||
|
||||
private long id = UNPERSISTED_ID;
|
||||
private String localPath;
|
||||
private String remotePath;
|
||||
private Boolean wifiOnly;
|
||||
private Boolean chargingOnly;
|
||||
private Boolean subfolderByDate;
|
||||
private String account;
|
||||
private Integer uploadAction;
|
||||
private boolean enabled;
|
||||
private MediaFolderType type;
|
||||
@Getter @Setter private long id;
|
||||
@Getter @Setter private String localPath;
|
||||
@Getter @Setter private String remotePath;
|
||||
@Getter @Setter private boolean wifiOnly;
|
||||
@Getter @Setter private boolean chargingOnly;
|
||||
@Getter @Setter private boolean subfolderByDate;
|
||||
@Getter @Setter private String account;
|
||||
@Getter @Setter private int uploadAction;
|
||||
@Getter private boolean enabled;
|
||||
@Getter private long enabledTimestampMs;
|
||||
@Getter @Setter private MediaFolderType type;
|
||||
@Getter @Setter private boolean hidden;
|
||||
|
||||
/**
|
||||
* constructor for new, to be persisted entity.
|
||||
@@ -59,11 +58,43 @@ public class SyncedFolder implements Serializable, Cloneable {
|
||||
* @param account the account owning the synced folder
|
||||
* @param uploadAction the action to be done after the upload
|
||||
* @param enabled flag if synced folder config is active
|
||||
* @param timestampMs the current timestamp in milliseconds
|
||||
* @param type the type of the folder
|
||||
* @param hidden hide item flag
|
||||
*/
|
||||
public SyncedFolder(String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
|
||||
Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
|
||||
MediaFolderType type) {
|
||||
public SyncedFolder(String localPath,
|
||||
String remotePath,
|
||||
boolean wifiOnly,
|
||||
boolean chargingOnly,
|
||||
boolean subfolderByDate,
|
||||
String account,
|
||||
int uploadAction,
|
||||
boolean enabled,
|
||||
long timestampMs,
|
||||
MediaFolderType type,
|
||||
boolean hidden) {
|
||||
this(UNPERSISTED_ID, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction,
|
||||
enabled, timestampMs, type, hidden);
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor for wrapping existing folders.
|
||||
*
|
||||
* @param id id
|
||||
*/
|
||||
protected SyncedFolder(long id,
|
||||
String localPath,
|
||||
String remotePath,
|
||||
boolean wifiOnly,
|
||||
boolean chargingOnly,
|
||||
boolean subfolderByDate,
|
||||
String account,
|
||||
int uploadAction,
|
||||
boolean enabled,
|
||||
long timestampMs,
|
||||
MediaFolderType type,
|
||||
boolean hidden) {
|
||||
this.id = id;
|
||||
this.localPath = localPath;
|
||||
this.remotePath = remotePath;
|
||||
this.wifiOnly = wifiOnly;
|
||||
@@ -71,8 +102,17 @@ public class SyncedFolder implements Serializable, Cloneable {
|
||||
this.subfolderByDate = subfolderByDate;
|
||||
this.account = account;
|
||||
this.uploadAction = uploadAction;
|
||||
this.enabled = enabled;
|
||||
this.setEnabled(enabled, timestampMs);
|
||||
this.type = type;
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timestampMs the current timestamp in milliseconds
|
||||
*/
|
||||
public void setEnabled(boolean enabled, long timestampMs) {
|
||||
this.enabled = enabled;
|
||||
this.enabledTimestampMs = enabled ? timestampMs : EMPTY_ENABLED_TIMESTAMP_MS;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
|
||||
@@ -53,21 +53,43 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
|
||||
* @param folderName the UI info for the folder's name
|
||||
* @param numberOfFiles the UI info for number of files within the folder
|
||||
* @param type the type of the folder
|
||||
* @param hidden hide item flag
|
||||
*/
|
||||
public SyncedFolderDisplayItem(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
|
||||
Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
|
||||
List<String> filePaths, String folderName, long numberOfFiles, MediaFolderType type)
|
||||
{
|
||||
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled, type);
|
||||
public SyncedFolderDisplayItem(long id,
|
||||
String localPath,
|
||||
String remotePath,
|
||||
boolean wifiOnly,
|
||||
boolean chargingOnly,
|
||||
boolean subfolderByDate,
|
||||
String account,
|
||||
int uploadAction,
|
||||
boolean enabled,
|
||||
long timestampMs,
|
||||
List<String> filePaths,
|
||||
String folderName,
|
||||
long numberOfFiles,
|
||||
MediaFolderType type,
|
||||
boolean hidden) {
|
||||
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled,
|
||||
timestampMs, type, hidden);
|
||||
this.filePaths = filePaths;
|
||||
this.folderName = folderName;
|
||||
this.numberOfFiles = numberOfFiles;
|
||||
}
|
||||
|
||||
public SyncedFolderDisplayItem(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
|
||||
Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
|
||||
String folderName, MediaFolderType type) {
|
||||
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled, type);
|
||||
public SyncedFolderDisplayItem(long id,
|
||||
String localPath,
|
||||
String remotePath,
|
||||
boolean wifiOnly,
|
||||
boolean chargingOnly,
|
||||
boolean subfolderByDate,
|
||||
String account,
|
||||
int uploadAction,
|
||||
boolean enabled,
|
||||
long timestampMs,
|
||||
String folderName, MediaFolderType type, boolean hidden) {
|
||||
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled,
|
||||
timestampMs, type, hidden);
|
||||
this.folderName = folderName;
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.client.preferences.AppPreferencesImpl;
|
||||
import com.owncloud.android.db.ProviderMeta;
|
||||
@@ -47,20 +48,22 @@ import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
|
||||
public class SyncedFolderProvider extends Observable {
|
||||
static private final String TAG = SyncedFolderProvider.class.getSimpleName();
|
||||
|
||||
private ContentResolver mContentResolver;
|
||||
private AppPreferences preferences;
|
||||
private final ContentResolver mContentResolver;
|
||||
private final AppPreferences preferences;
|
||||
private final Clock clock;
|
||||
|
||||
/**
|
||||
* constructor.
|
||||
*
|
||||
* @param contentResolver the ContentResolver to work with.
|
||||
*/
|
||||
public SyncedFolderProvider(ContentResolver contentResolver, AppPreferences preferences) {
|
||||
public SyncedFolderProvider(ContentResolver contentResolver, AppPreferences preferences, Clock clock) {
|
||||
if (contentResolver == null) {
|
||||
throw new IllegalArgumentException("Cannot create an instance with a NULL contentResolver");
|
||||
}
|
||||
mContentResolver = contentResolver;
|
||||
this.preferences = preferences;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +165,7 @@ public class SyncedFolderProvider extends Observable {
|
||||
// read sync folder object and update
|
||||
SyncedFolder syncedFolder = createSyncedFolderFromCursor(cursor);
|
||||
|
||||
syncedFolder.setEnabled(enabled);
|
||||
syncedFolder.setEnabled(enabled, clock.getCurrentTime());
|
||||
|
||||
// update sync folder object in db
|
||||
result = updateSyncFolder(syncedFolder);
|
||||
@@ -335,23 +338,27 @@ public class SyncedFolderProvider extends Observable {
|
||||
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH));
|
||||
String remotePath = cursor.getString(cursor.getColumnIndex(
|
||||
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_REMOTE_PATH));
|
||||
Boolean wifiOnly = cursor.getInt(cursor.getColumnIndex(
|
||||
boolean wifiOnly = cursor.getInt(cursor.getColumnIndex(
|
||||
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY)) == 1;
|
||||
Boolean chargingOnly = cursor.getInt(cursor.getColumnIndex(
|
||||
boolean chargingOnly = cursor.getInt(cursor.getColumnIndex(
|
||||
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY)) == 1;
|
||||
Boolean subfolderByDate = cursor.getInt(cursor.getColumnIndex(
|
||||
boolean subfolderByDate = cursor.getInt(cursor.getColumnIndex(
|
||||
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE)) == 1;
|
||||
String accountName = cursor.getString(cursor.getColumnIndex(
|
||||
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT));
|
||||
Integer uploadAction = cursor.getInt(cursor.getColumnIndex(
|
||||
int uploadAction = cursor.getInt(cursor.getColumnIndex(
|
||||
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION));
|
||||
Boolean enabled = cursor.getInt(cursor.getColumnIndex(
|
||||
boolean enabled = cursor.getInt(cursor.getColumnIndex(
|
||||
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED)) == 1;
|
||||
long enabledTimestampMs = cursor.getLong(cursor.getColumnIndex(
|
||||
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS));
|
||||
MediaFolderType type = MediaFolderType.getById(cursor.getInt(cursor.getColumnIndex(
|
||||
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE)));
|
||||
boolean hidden = cursor.getInt(cursor.getColumnIndex(
|
||||
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN)) == 1;
|
||||
|
||||
syncedFolder = new SyncedFolder(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate,
|
||||
accountName, uploadAction, enabled, type);
|
||||
accountName, uploadAction, enabled, enabledTimestampMs, type, hidden);
|
||||
}
|
||||
return syncedFolder;
|
||||
}
|
||||
@@ -367,13 +374,15 @@ public class SyncedFolderProvider extends Observable {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH, syncedFolder.getLocalPath());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_REMOTE_PATH, syncedFolder.getRemotePath());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY, syncedFolder.getWifiOnly());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY, syncedFolder.getChargingOnly());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY, syncedFolder.isWifiOnly());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY, syncedFolder.isChargingOnly());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED, syncedFolder.isEnabled());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE, syncedFolder.getSubfolderByDate());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS, syncedFolder.getEnabledTimestampMs());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE, syncedFolder.isSubfolderByDate());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT, syncedFolder.getAccount());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION, syncedFolder.getUploadAction());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE, syncedFolder.getType().getId());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN, syncedFolder.isHidden());
|
||||
|
||||
return cv;
|
||||
}
|
||||
|
||||
@@ -1173,7 +1173,8 @@ public final class ThumbnailsCacheManager {
|
||||
Bitmap resultBitmap = Bitmap.createBitmap(pxW, pxH, Bitmap.Config.ARGB_8888);
|
||||
Canvas c = new Canvas(resultBitmap);
|
||||
|
||||
c.drawColor(MainApp.getAppContext().getResources().getColor(R.color.background_color));
|
||||
// TODO check based on https://github.com/nextcloud/android/pull/3459#discussion_r339935975
|
||||
c.drawColor(MainApp.getAppContext().getResources().getColor(R.color.background_color_png));
|
||||
c.drawBitmap(bitmap, 0, 0, null);
|
||||
|
||||
return resultBitmap;
|
||||
|
||||
@@ -30,6 +30,7 @@ import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.db.OCUpload;
|
||||
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
|
||||
import com.owncloud.android.db.UploadResult;
|
||||
@@ -345,24 +346,19 @@ public class UploadsStorageManager extends Observable {
|
||||
}
|
||||
|
||||
public OCUpload[] getCurrentAndPendingUploadsForCurrentAccount() {
|
||||
Account account = currentAccountProvider.getCurrentAccount();
|
||||
User user = currentAccountProvider.getUser();
|
||||
|
||||
if (account != null) {
|
||||
return getUploads(
|
||||
ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_IN_PROGRESS.value +
|
||||
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"==" + UploadResult.DELAYED_FOR_WIFI.getValue() +
|
||||
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"==" + UploadResult.LOCK_FAILED.getValue() +
|
||||
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"==" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
|
||||
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"==" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue() +
|
||||
" AND " + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
|
||||
account.name);
|
||||
} else {
|
||||
return new OCUpload[0];
|
||||
}
|
||||
return getUploads(ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_IN_PROGRESS.value +
|
||||
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"==" + UploadResult.DELAYED_FOR_WIFI.getValue() +
|
||||
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"==" + UploadResult.LOCK_FAILED.getValue() +
|
||||
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"==" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
|
||||
" OR " + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"==" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue() +
|
||||
" AND " + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
|
||||
user.getAccountName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -384,14 +380,10 @@ public class UploadsStorageManager extends Observable {
|
||||
}
|
||||
|
||||
public OCUpload[] getFinishedUploadsForCurrentAccount() {
|
||||
Account account = currentAccountProvider.getCurrentAccount();
|
||||
User user = currentAccountProvider.getUser();
|
||||
|
||||
if (account != null) {
|
||||
return getUploads(ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_SUCCEEDED.value + AND +
|
||||
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?", account.name);
|
||||
} else {
|
||||
return new OCUpload[0];
|
||||
}
|
||||
return getUploads(ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_SUCCEEDED.value + AND +
|
||||
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?", user.getAccountName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -403,23 +395,19 @@ public class UploadsStorageManager extends Observable {
|
||||
}
|
||||
|
||||
public OCUpload[] getFailedButNotDelayedUploadsForCurrentAccount() {
|
||||
Account account = currentAccountProvider.getCurrentAccount();
|
||||
User user = currentAccountProvider.getUser();
|
||||
|
||||
if (account != null) {
|
||||
return getUploads(ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_FAILED.value +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_WIFI.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.LOCK_FAILED.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
|
||||
account.name);
|
||||
} else {
|
||||
return new OCUpload[0];
|
||||
}
|
||||
return getUploads(ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_FAILED.value +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_WIFI.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.LOCK_FAILED.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
|
||||
user.getAccountName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -446,50 +434,41 @@ public class UploadsStorageManager extends Observable {
|
||||
}
|
||||
|
||||
public long clearFailedButNotDelayedUploads() {
|
||||
Account account = currentAccountProvider.getCurrentAccount();
|
||||
|
||||
long result = 0;
|
||||
if (account != null) {
|
||||
result = getDB().delete(
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_FAILED.value +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.LOCK_FAILED.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_WIFI.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
|
||||
new String[]{account.name}
|
||||
);
|
||||
}
|
||||
|
||||
User user = currentAccountProvider.getUser();
|
||||
final long deleted = getDB().delete(
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_FAILED.value +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.LOCK_FAILED.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_WIFI.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_FOR_CHARGING.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_LAST_RESULT +
|
||||
"<>" + UploadResult.DELAYED_IN_POWER_SAVE_MODE.getValue() +
|
||||
AND + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?",
|
||||
new String[]{user.getAccountName()}
|
||||
);
|
||||
Log_OC.d(TAG, "delete all failed uploads but those delayed for Wifi");
|
||||
if (result > 0) {
|
||||
if (deleted > 0) {
|
||||
notifyObserversNow();
|
||||
}
|
||||
return result;
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public long clearSuccessfulUploads() {
|
||||
Account account = currentAccountProvider.getCurrentAccount();
|
||||
|
||||
long result = 0;
|
||||
if (account != null) {
|
||||
result = getDB().delete(
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_SUCCEEDED.value + AND +
|
||||
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?", new String[]{account.name}
|
||||
);
|
||||
}
|
||||
User user = currentAccountProvider.getUser();
|
||||
final long deleted = getDB().delete(
|
||||
ProviderTableMeta.CONTENT_URI_UPLOADS,
|
||||
ProviderTableMeta.UPLOADS_STATUS + "==" + UploadStatus.UPLOAD_SUCCEEDED.value + AND +
|
||||
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + "== ?", new String[]{user.getAccountName()}
|
||||
);
|
||||
|
||||
Log_OC.d(TAG, "delete all successful uploads");
|
||||
if (result > 0) {
|
||||
if (deleted > 0) {
|
||||
notifyObserversNow();
|
||||
}
|
||||
return result;
|
||||
return deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,7 @@ import com.owncloud.android.MainApp;
|
||||
*/
|
||||
public class ProviderMeta {
|
||||
public static final String DB_NAME = "filelist";
|
||||
public static final int DB_VERSION = 49;
|
||||
public static final int DB_VERSION = 51;
|
||||
|
||||
private ProviderMeta() {
|
||||
// No instance
|
||||
@@ -220,10 +220,12 @@ public class ProviderMeta {
|
||||
public static final String SYNCED_FOLDER_WIFI_ONLY = "wifi_only";
|
||||
public static final String SYNCED_FOLDER_CHARGING_ONLY = "charging_only";
|
||||
public static final String SYNCED_FOLDER_ENABLED = "enabled";
|
||||
public static final String SYNCED_FOLDER_ENABLED_TIMESTAMP_MS = "enabled_timestamp_ms";
|
||||
public static final String SYNCED_FOLDER_TYPE = "type";
|
||||
public static final String SYNCED_FOLDER_SUBFOLDER_BY_DATE = "subfolder_by_date";
|
||||
public static final String SYNCED_FOLDER_ACCOUNT = "account";
|
||||
public static final String SYNCED_FOLDER_UPLOAD_ACTION = "upload_option";
|
||||
public static final String SYNCED_FOLDER_HIDDEN = "hidden";
|
||||
|
||||
// Columns of external links table
|
||||
public static final String EXTERNAL_LINKS_ICON_URL = "icon_url";
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.nextcloud.client.device.PowerManagementService;
|
||||
import com.nextcloud.client.jobs.BackgroundJobManager;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
@@ -53,6 +54,7 @@ public class BootupBroadcastReceiver extends BroadcastReceiver {
|
||||
@Inject ConnectivityService connectivityService;
|
||||
@Inject PowerManagementService powerManagementService;
|
||||
@Inject BackgroundJobManager backgroundJobManager;
|
||||
@Inject Clock clock;
|
||||
|
||||
/**
|
||||
* Receives broadcast intent reporting that the system was just boot up.
|
||||
@@ -69,7 +71,8 @@ public class BootupBroadcastReceiver extends BroadcastReceiver {
|
||||
accountManager,
|
||||
connectivityService,
|
||||
powerManagementService,
|
||||
backgroundJobManager);
|
||||
backgroundJobManager,
|
||||
clock);
|
||||
MainApp.initContactsBackup(accountManager);
|
||||
} else {
|
||||
Log_OC.d(TAG, "Getting wrong intent: " + intent.getAction());
|
||||
|
||||
@@ -28,14 +28,17 @@ import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AccountManagerCallback;
|
||||
import android.accounts.AccountManagerFuture;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.evernote.android.job.Job;
|
||||
import com.evernote.android.job.util.support.PersistableBundleCompat;
|
||||
import com.google.gson.Gson;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.nextcloud.client.preferences.AppPreferencesImpl;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
@@ -55,7 +58,6 @@ import com.owncloud.android.ui.activity.ContactsPreferenceActivity;
|
||||
import com.owncloud.android.ui.events.AccountRemovedEvent;
|
||||
import com.owncloud.android.utils.EncryptionUtils;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
import com.owncloud.android.utils.FilesSyncHelper;
|
||||
import com.owncloud.android.utils.PushUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
@@ -79,12 +81,14 @@ public class AccountRemovalJob extends Job implements AccountManagerCallback<Boo
|
||||
public static final String ACCOUNT = "account";
|
||||
public static final String REMOTE_WIPE = "remote_wipe";
|
||||
|
||||
private UploadsStorageManager uploadsStorageManager;
|
||||
private UserAccountManager userAccountManager;
|
||||
private final UploadsStorageManager uploadsStorageManager;
|
||||
private final UserAccountManager userAccountManager;
|
||||
private final Clock clock;
|
||||
|
||||
public AccountRemovalJob(UploadsStorageManager uploadStorageManager, UserAccountManager accountManager) {
|
||||
public AccountRemovalJob(UploadsStorageManager uploadStorageManager, UserAccountManager accountManager, Clock clock) {
|
||||
this.uploadsStorageManager = uploadStorageManager;
|
||||
this.userAccountManager = accountManager;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -127,7 +131,7 @@ public class AccountRemovalJob extends Job implements AccountManagerCallback<Boo
|
||||
arbitraryDataProvider.deleteKeyForAccount(account.name, PENDING_FOR_REMOVAL);
|
||||
|
||||
// remove synced folders set for account
|
||||
remoceSyncedFolders(context, account, arbitraryDataProvider);
|
||||
remoceSyncedFolders(context, account, clock);
|
||||
|
||||
// delete all uploads for account
|
||||
uploadsStorageManager.removeAccountUploads(account);
|
||||
@@ -142,6 +146,13 @@ public class AccountRemovalJob extends Job implements AccountManagerCallback<Boo
|
||||
new RemoteWipeSuccessRemoteOperation(authToken).execute(client);
|
||||
}
|
||||
|
||||
// notify Document Provider
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
String authority = context.getResources().getString(R.string.document_provider_authority);
|
||||
Uri rootsUri = DocumentsContract.buildRootsUri(authority);
|
||||
context.getContentResolver().notifyChange(rootsUri, null);
|
||||
}
|
||||
|
||||
return Result.SUCCESS;
|
||||
} else {
|
||||
return Result.FAILURE;
|
||||
@@ -165,17 +176,16 @@ public class AccountRemovalJob extends Job implements AccountManagerCallback<Boo
|
||||
}
|
||||
}
|
||||
|
||||
private void remoceSyncedFolders(Context context, Account account, ArbitraryDataProvider arbitraryDataProvider) {
|
||||
private void remoceSyncedFolders(Context context, Account account, Clock clock) {
|
||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver(),
|
||||
AppPreferencesImpl.fromContext(context));
|
||||
AppPreferencesImpl.fromContext(context),
|
||||
clock);
|
||||
List<SyncedFolder> syncedFolders = syncedFolderProvider.getSyncedFolders();
|
||||
|
||||
List<Long> syncedFolderIds = new ArrayList<>();
|
||||
|
||||
for (SyncedFolder syncedFolder : syncedFolders) {
|
||||
if (syncedFolder.getAccount().equals(account.name)) {
|
||||
arbitraryDataProvider.deleteKeyForAccount(FilesSyncHelper.GLOBAL,
|
||||
FilesSyncHelper.SYNCEDFOLDERINITIATED + syncedFolder.getId());
|
||||
syncedFolderIds.add(syncedFolder.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.text.TextUtils;
|
||||
import com.evernote.android.job.Job;
|
||||
import com.evernote.android.job.util.support.PersistableBundleCompat;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.nextcloud.client.device.PowerManagementService;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
@@ -76,22 +77,25 @@ public class FilesSyncJob extends Job {
|
||||
public static final String OVERRIDE_POWER_SAVING = "overridePowerSaving";
|
||||
private static final String WAKELOCK_TAG_SEPARATION = ":";
|
||||
|
||||
private UserAccountManager userAccountManager;
|
||||
private AppPreferences preferences;
|
||||
private UploadsStorageManager uploadsStorageManager;
|
||||
private ConnectivityService connectivityService;
|
||||
private PowerManagementService powerManagementService;
|
||||
private final UserAccountManager userAccountManager;
|
||||
private final AppPreferences preferences;
|
||||
private final UploadsStorageManager uploadsStorageManager;
|
||||
private final ConnectivityService connectivityService;
|
||||
private final PowerManagementService powerManagementService;
|
||||
private final Clock clock;
|
||||
|
||||
FilesSyncJob(final UserAccountManager userAccountManager,
|
||||
final AppPreferences preferences,
|
||||
final UploadsStorageManager uploadsStorageManager,
|
||||
final ConnectivityService connectivityService,
|
||||
final PowerManagementService powerManagementService) {
|
||||
final PowerManagementService powerManagementService,
|
||||
final Clock clock) {
|
||||
this.userAccountManager = userAccountManager;
|
||||
this.preferences = preferences;
|
||||
this.uploadsStorageManager = uploadsStorageManager;
|
||||
this.connectivityService = connectivityService;
|
||||
this.powerManagementService = powerManagementService;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -126,13 +130,12 @@ public class FilesSyncJob extends Job {
|
||||
userAccountManager,
|
||||
connectivityService,
|
||||
powerManagementService);
|
||||
FilesSyncHelper.insertAllDBEntries(preferences, skipCustom);
|
||||
FilesSyncHelper.insertAllDBEntries(preferences, clock, skipCustom);
|
||||
|
||||
// Create all the providers we'll need
|
||||
final ContentResolver contentResolver = context.getContentResolver();
|
||||
final FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
|
||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver,
|
||||
preferences);
|
||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver, preferences, clock);
|
||||
|
||||
Locale currentLocale = context.getResources().getConfiguration().locale;
|
||||
SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", currentLocale);
|
||||
@@ -189,10 +192,10 @@ public class FilesSyncJob extends Job {
|
||||
|
||||
remotePath = resources.getString(R.string.syncedFolder_remote_folder);
|
||||
} else {
|
||||
needsCharging = syncedFolder.getChargingOnly();
|
||||
needsWifi = syncedFolder.getWifiOnly();
|
||||
needsCharging = syncedFolder.isChargingOnly();
|
||||
needsWifi = syncedFolder.isWifiOnly();
|
||||
uploadAction = syncedFolder.getUploadAction();
|
||||
subfolderByDate = syncedFolder.getSubfolderByDate();
|
||||
subfolderByDate = syncedFolder.isSubfolderByDate();
|
||||
remotePath = syncedFolder.getRemotePath();
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import android.text.TextUtils;
|
||||
import com.evernote.android.job.Job;
|
||||
import com.google.gson.Gson;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.client.preferences.AppPreferencesImpl;
|
||||
import com.owncloud.android.R;
|
||||
@@ -74,11 +75,13 @@ public class MediaFoldersDetectionJob extends Job {
|
||||
|
||||
private static final String DISABLE_DETECTION_CLICK = "DISABLE_DETECTION_CLICK";
|
||||
|
||||
private UserAccountManager userAccountManager;
|
||||
private Random randomId = new Random();
|
||||
private final UserAccountManager userAccountManager;
|
||||
private final Clock clock;
|
||||
private final Random randomId = new Random();
|
||||
|
||||
MediaFoldersDetectionJob(UserAccountManager accountManager) {
|
||||
MediaFoldersDetectionJob(UserAccountManager accountManager, Clock clock) {
|
||||
this.userAccountManager = accountManager;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -88,7 +91,8 @@ public class MediaFoldersDetectionJob extends Job {
|
||||
ContentResolver contentResolver = context.getContentResolver();
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(contentResolver);
|
||||
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver,
|
||||
AppPreferencesImpl.fromContext(context));
|
||||
AppPreferencesImpl.fromContext(context),
|
||||
clock);
|
||||
Gson gson = new Gson();
|
||||
String arbitraryDataString;
|
||||
MediaFoldersModel mediaFoldersModel;
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.content.Context;
|
||||
import com.evernote.android.job.Job;
|
||||
import com.evernote.android.job.JobCreator;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.nextcloud.client.device.PowerManagementService;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
@@ -48,6 +49,7 @@ public class NCJobCreator implements JobCreator {
|
||||
private final UploadsStorageManager uploadsStorageManager;
|
||||
private final ConnectivityService connectivityService;
|
||||
private final PowerManagementService powerManagementService;
|
||||
private final Clock clock;
|
||||
|
||||
public NCJobCreator(
|
||||
Context context,
|
||||
@@ -55,7 +57,8 @@ public class NCJobCreator implements JobCreator {
|
||||
AppPreferences preferences,
|
||||
UploadsStorageManager uploadsStorageManager,
|
||||
ConnectivityService connectivityServices,
|
||||
PowerManagementService powerManagementService
|
||||
PowerManagementService powerManagementService,
|
||||
Clock clock
|
||||
) {
|
||||
this.context = context;
|
||||
this.accountManager = accountManager;
|
||||
@@ -63,6 +66,7 @@ public class NCJobCreator implements JobCreator {
|
||||
this.uploadsStorageManager = uploadsStorageManager;
|
||||
this.connectivityService = connectivityServices;
|
||||
this.powerManagementService = powerManagementService;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,19 +77,20 @@ public class NCJobCreator implements JobCreator {
|
||||
case ContactsImportJob.TAG:
|
||||
return new ContactsImportJob();
|
||||
case AccountRemovalJob.TAG:
|
||||
return new AccountRemovalJob(uploadsStorageManager, accountManager);
|
||||
return new AccountRemovalJob(uploadsStorageManager, accountManager, clock);
|
||||
case FilesSyncJob.TAG:
|
||||
return new FilesSyncJob(accountManager,
|
||||
preferences,
|
||||
uploadsStorageManager,
|
||||
connectivityService,
|
||||
powerManagementService);
|
||||
powerManagementService,
|
||||
clock);
|
||||
case OfflineSyncJob.TAG:
|
||||
return new OfflineSyncJob(accountManager, connectivityService, powerManagementService);
|
||||
case NotificationJob.TAG:
|
||||
return new NotificationJob(context, accountManager);
|
||||
case MediaFoldersDetectionJob.TAG:
|
||||
return new MediaFoldersDetectionJob(accountManager);
|
||||
return new MediaFoldersDetectionJob(accountManager, clock);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.net.Uri;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.OpenableColumns;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
@@ -61,8 +62,8 @@ public class DiskLruImageCacheFileProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
private OCFile getFile(Uri uri) {
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(account,
|
||||
User user = accountManager.getUser();
|
||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user.toPlatformAccount(),
|
||||
MainApp.getAppContext().getContentResolver());
|
||||
|
||||
return fileDataStorageManager.getFileByPath(uri.getPath());
|
||||
|
||||
@@ -34,17 +34,19 @@ import android.content.res.AssetFileDescriptor;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Point;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.DocumentsProvider;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.evernote.android.job.JobRequest;
|
||||
import com.evernote.android.job.util.Device;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
@@ -55,12 +57,12 @@ import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||
import com.owncloud.android.files.services.FileDownloader;
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation;
|
||||
import com.owncloud.android.operations.CopyFileOperation;
|
||||
import com.owncloud.android.operations.CreateFolderOperation;
|
||||
import com.owncloud.android.operations.MoveFileOperation;
|
||||
@@ -68,7 +70,6 @@ import com.owncloud.android.operations.RefreshFolderOperation;
|
||||
import com.owncloud.android.operations.RemoveFileOperation;
|
||||
import com.owncloud.android.operations.RenameFileOperation;
|
||||
import com.owncloud.android.operations.SynchronizeFileOperation;
|
||||
import com.owncloud.android.operations.UploadFileOperation;
|
||||
import com.owncloud.android.ui.activity.ConflictsResolveActivity;
|
||||
import com.owncloud.android.ui.activity.SettingsActivity;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
@@ -81,9 +82,11 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
|
||||
import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
|
||||
@@ -91,16 +94,25 @@ import static com.owncloud.android.datamodel.OCFile.ROOT_PATH;
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
|
||||
private static final String TAG = "DocumentsStorageProvider";
|
||||
private static final String TAG = DocumentsStorageProvider.class.getSimpleName();
|
||||
|
||||
private FileDataStorageManager currentStorageManager;
|
||||
private Map<Long, FileDataStorageManager> rootIdToStorageManager;
|
||||
private OwnCloudClient client;
|
||||
private static final long CACHE_EXPIRATION = TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES);
|
||||
|
||||
UserAccountManager accountManager;
|
||||
|
||||
private static final String DOCUMENTID_SEPARATOR = "/";
|
||||
private static final int DOCUMENTID_PARTS = 2;
|
||||
private final SparseArray<FileDataStorageManager> rootIdToStorageManager = new SparseArray<>();
|
||||
|
||||
private final Executor executor = Executors.newCachedThreadPool();
|
||||
|
||||
@Override
|
||||
public Cursor queryRoots(String[] projection) throws FileNotFoundException {
|
||||
public Cursor queryRoots(String[] projection) {
|
||||
|
||||
// always recreate storage manager collection, as it will change after account creation/removal
|
||||
// and we need to serve document(tree)s with persist permissions
|
||||
initiateStorageMap();
|
||||
|
||||
Context context = MainApp.getAppContext();
|
||||
AppPreferences preferences = AppPreferencesImpl.fromContext(context);
|
||||
if (SettingsActivity.LOCK_PASSCODE.equals(preferences.getLockPreference()) ||
|
||||
@@ -108,12 +120,9 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
return new FileCursor();
|
||||
}
|
||||
|
||||
initiateStorageMap();
|
||||
|
||||
final RootCursor result = new RootCursor(projection);
|
||||
|
||||
for (Account account : accountManager.getAccounts()) {
|
||||
result.addRoot(account, getContext());
|
||||
for(int i = 0; i < rootIdToStorageManager.size(); i++) {
|
||||
result.addRoot(new Document(rootIdToStorageManager.valueAt(i), ROOT_PATH), getContext());
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -121,28 +130,12 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
|
||||
@Override
|
||||
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException {
|
||||
final long docId = Long.parseLong(documentId);
|
||||
updateCurrentStorageManagerIfNeeded(docId);
|
||||
Log.d(TAG, "queryDocument(), id=" + documentId);
|
||||
|
||||
if (currentStorageManager == null) {
|
||||
|
||||
for (Map.Entry<Long, FileDataStorageManager> entry : rootIdToStorageManager.entrySet()) {
|
||||
if (entry.getValue().getFileById(docId) != null) {
|
||||
currentStorageManager = entry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentStorageManager == null) {
|
||||
throw new FileNotFoundException("File with id " + documentId + " not found");
|
||||
}
|
||||
Document document = toDocument(documentId);
|
||||
|
||||
final FileCursor result = new FileCursor(projection);
|
||||
OCFile file = currentStorageManager.getFileById(docId);
|
||||
if (file != null) {
|
||||
result.addFile(file);
|
||||
}
|
||||
result.addFile(document);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -151,34 +144,37 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
@Override
|
||||
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder)
|
||||
throws FileNotFoundException {
|
||||
|
||||
final long folderId = Long.parseLong(parentDocumentId);
|
||||
updateCurrentStorageManagerIfNeeded(folderId);
|
||||
Log.d(TAG, "queryChildDocuments(), id=" + parentDocumentId);
|
||||
|
||||
Context context = getContext();
|
||||
|
||||
if (context == null) {
|
||||
throw new FileNotFoundException("Context may not be null");
|
||||
}
|
||||
|
||||
Account account = currentStorageManager.getAccount();
|
||||
final OCFile browsedDir = currentStorageManager.getFileById(folderId);
|
||||
if (Device.getNetworkType(context).equals(JobRequest.NetworkType.UNMETERED)) {
|
||||
RemoteOperationResult result = new RefreshFolderOperation(browsedDir, System.currentTimeMillis(), false,
|
||||
false, true, currentStorageManager, account,
|
||||
getContext()).execute(client);
|
||||
Document parentFolder = toDocument(parentDocumentId);
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
throw new FileNotFoundException("Failed to update document " + parentDocumentId);
|
||||
}
|
||||
}
|
||||
FileDataStorageManager storageManager = parentFolder.getStorageManager();
|
||||
|
||||
final FileCursor resultCursor = new FileCursor(projection);
|
||||
|
||||
for (OCFile file : currentStorageManager.getFolderContent(browsedDir, false)) {
|
||||
resultCursor.addFile(file);
|
||||
for (OCFile file : storageManager.getFolderContent(parentFolder.getFile(), false)) {
|
||||
resultCursor.addFile(new Document(storageManager, file));
|
||||
}
|
||||
|
||||
boolean isLoading = false;
|
||||
if (parentFolder.isExpired()) {
|
||||
final ReloadFolderDocumentTask task = new ReloadFolderDocumentTask(parentFolder, result -> {
|
||||
getContext().getContentResolver().notifyChange(toNotifyUri(parentFolder), null, false);
|
||||
});
|
||||
task.executeOnExecutor(executor);
|
||||
resultCursor.setLoadingTask(task);
|
||||
isLoading = true;
|
||||
}
|
||||
|
||||
final Bundle extra = new Bundle();
|
||||
extra.putBoolean(DocumentsContract.EXTRA_LOADING, isLoading);
|
||||
resultCursor.setExtras(extra);
|
||||
resultCursor.setNotificationUri(getContext().getContentResolver(), toNotifyUri(parentFolder));
|
||||
return resultCursor;
|
||||
}
|
||||
|
||||
@@ -186,22 +182,18 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
@Override
|
||||
public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal cancellationSignal)
|
||||
throws FileNotFoundException {
|
||||
final long docId = Long.parseLong(documentId);
|
||||
updateCurrentStorageManagerIfNeeded(docId);
|
||||
Log.d(TAG, "openDocument(), id=" + documentId);
|
||||
|
||||
OCFile ocFile = currentStorageManager.getFileById(docId);
|
||||
|
||||
if (ocFile == null) {
|
||||
throw new FileNotFoundException("File not found: " + documentId);
|
||||
}
|
||||
Document document = toDocument(documentId);
|
||||
|
||||
Context context = getContext();
|
||||
|
||||
if (context == null) {
|
||||
throw new FileNotFoundException("Context may not be null!");
|
||||
}
|
||||
|
||||
Account account = currentStorageManager.getAccount();
|
||||
OCFile ocFile = document.getFile();
|
||||
Account account = document.getAccount();
|
||||
|
||||
if (!ocFile.isDown()) {
|
||||
Intent i = new Intent(getContext(), FileDownloader.class);
|
||||
i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
|
||||
@@ -216,7 +208,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
if (!waitOrGetCancelled(cancellationSignal)) {
|
||||
throw new FileNotFoundException("File with id " + documentId + " not found!");
|
||||
}
|
||||
ocFile = currentStorageManager.getFileById(docId);
|
||||
ocFile = document.getFile();
|
||||
|
||||
if (ocFile == null) {
|
||||
throw new FileNotFoundException("File with id " + documentId + " not found!");
|
||||
@@ -226,11 +218,10 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
OCFile finalFile = ocFile;
|
||||
Thread syncThread = new Thread(() -> {
|
||||
try {
|
||||
FileDataStorageManager storageManager =
|
||||
new FileDataStorageManager(account, context.getContentResolver());
|
||||
SynchronizeFileOperation sfo =
|
||||
new SynchronizeFileOperation(finalFile, null, account, true, context);
|
||||
RemoteOperationResult result = sfo.execute(storageManager, context);
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver());
|
||||
RemoteOperationResult result = new SynchronizeFileOperation(finalFile, null, account,
|
||||
true, context)
|
||||
.execute(storageManager, context);
|
||||
if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) {
|
||||
// ISSUE 5: if the user is not running the app (this is a service!),
|
||||
// this can be very intrusive; a notification should be preferred
|
||||
@@ -271,7 +262,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
return ParcelFileDescriptor.open(file, accessMode, handler, l -> {
|
||||
RemoteOperationResult result = new SynchronizeFileOperation(newFile, oldFile, account, true,
|
||||
context)
|
||||
.execute(client, currentStorageManager);
|
||||
.execute(document.getClient(), document.getStorageManager());
|
||||
|
||||
boolean success = result.isSuccess();
|
||||
|
||||
@@ -297,6 +288,11 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
accountManager = UserAccountManagerImpl.fromContext(getContext());
|
||||
|
||||
// initiate storage manager collection, because we need to serve document(tree)s
|
||||
// with persist permissions
|
||||
initiateStorageMap();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -305,141 +301,140 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
Point sizeHint,
|
||||
CancellationSignal signal)
|
||||
throws FileNotFoundException {
|
||||
long docId = Long.parseLong(documentId);
|
||||
updateCurrentStorageManagerIfNeeded(docId);
|
||||
|
||||
OCFile file = currentStorageManager.getFileById(docId);
|
||||
|
||||
if (file == null) {
|
||||
throw new FileNotFoundException("File with id " + documentId + " not found!");
|
||||
}
|
||||
Log.d(TAG, "openDocumentThumbnail(), id=" + documentId);
|
||||
|
||||
Context context = getContext();
|
||||
|
||||
if (context == null) {
|
||||
throw new FileNotFoundException("Context may not be null!");
|
||||
}
|
||||
|
||||
Document document = toDocument(documentId);
|
||||
|
||||
boolean exists = ThumbnailsCacheManager.containsBitmap(ThumbnailsCacheManager.PREFIX_THUMBNAIL
|
||||
+ file.getRemoteId());
|
||||
+ document.getFile().getRemoteId());
|
||||
|
||||
if (!exists) {
|
||||
ThumbnailsCacheManager.generateThumbnailFromOCFile(file);
|
||||
ThumbnailsCacheManager.generateThumbnailFromOCFile(document.getFile());
|
||||
}
|
||||
|
||||
Uri uri = Uri.parse(UriUtils.URI_CONTENT_SCHEME + context.getResources().getString(
|
||||
R.string.image_cache_provider_authority) + file.getRemotePath());
|
||||
R.string.image_cache_provider_authority) + document.getRemotePath());
|
||||
Log.d(TAG, "open thumbnail, uri=" + uri);
|
||||
return context.getContentResolver().openAssetFileDescriptor(uri, "r");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String renameDocument(String documentId, String displayName) throws FileNotFoundException {
|
||||
long docId = Long.parseLong(documentId);
|
||||
updateCurrentStorageManagerIfNeeded(docId);
|
||||
Log.d(TAG, "renameDocument(), id=" + documentId);
|
||||
|
||||
OCFile file = currentStorageManager.getFileById(docId);
|
||||
|
||||
if (file == null) {
|
||||
throw new FileNotFoundException("File " + documentId + " not found!");
|
||||
Context context = getContext();
|
||||
if (context == null) {
|
||||
throw new FileNotFoundException("Context may not be null!");
|
||||
}
|
||||
|
||||
RemoteOperationResult result = new RenameFileOperation(file.getRemotePath(), displayName)
|
||||
.execute(client, currentStorageManager);
|
||||
Document document = toDocument(documentId);
|
||||
|
||||
RemoteOperationResult result = new RenameFileOperation(document.getRemotePath(), displayName)
|
||||
.execute(document.getClient(), document.getStorageManager());
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
throw new FileNotFoundException("Failed to rename document with documentId " + documentId + ": " +
|
||||
result.getException());
|
||||
}
|
||||
|
||||
context.getContentResolver().notifyChange(toNotifyUri(document.getParent()), null, false);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String copyDocument(String sourceDocumentId, String targetParentDocumentId) throws FileNotFoundException {
|
||||
long sourceId = Long.parseLong(sourceDocumentId);
|
||||
Log.d(TAG, "copyDocument(), id=" + sourceDocumentId);
|
||||
|
||||
updateCurrentStorageManagerIfNeeded(sourceId);
|
||||
|
||||
OCFile file = currentStorageManager.getFileById(sourceId);
|
||||
if (file == null) {
|
||||
throw new FileNotFoundException("File " + sourceDocumentId + " not found!");
|
||||
Context context = getContext();
|
||||
if (context == null) {
|
||||
throw new FileNotFoundException("Context may not be null!");
|
||||
}
|
||||
|
||||
long targetId = Long.parseLong(targetParentDocumentId);
|
||||
OCFile targetFolder = currentStorageManager.getFileById(targetId);
|
||||
if (targetFolder == null) {
|
||||
throw new FileNotFoundException("File " + targetParentDocumentId + " not found!");
|
||||
}
|
||||
Document document = toDocument(sourceDocumentId);
|
||||
|
||||
RemoteOperationResult result = new CopyFileOperation(file.getRemotePath(), targetFolder.getRemotePath())
|
||||
.execute(client, currentStorageManager);
|
||||
FileDataStorageManager storageManager = document.getStorageManager();
|
||||
Document targetFolder = toDocument(targetParentDocumentId);
|
||||
|
||||
RemoteOperationResult result = new CopyFileOperation(document.getRemotePath(), targetFolder.getRemotePath())
|
||||
.execute(document.getClient(), storageManager);
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
throw new FileNotFoundException("Failed to copy document with documentId " + sourceDocumentId
|
||||
+ " to " + targetParentDocumentId);
|
||||
}
|
||||
|
||||
Account account = currentStorageManager.getAccount();
|
||||
Account account = document.getAccount();
|
||||
|
||||
RemoteOperationResult updateParent = new RefreshFolderOperation(targetFolder, System.currentTimeMillis(),
|
||||
false, false, true, currentStorageManager,
|
||||
account, getContext()).execute(client);
|
||||
RemoteOperationResult updateParent = new RefreshFolderOperation(targetFolder.getFile(), System.currentTimeMillis(),
|
||||
false, false, true, storageManager,
|
||||
account, context)
|
||||
.execute(targetFolder.getClient());
|
||||
|
||||
if (!updateParent.isSuccess()) {
|
||||
throw new FileNotFoundException("Failed to copy document with documentId " + sourceDocumentId
|
||||
+ " to " + targetParentDocumentId);
|
||||
}
|
||||
|
||||
String newPath = targetFolder.getRemotePath() + file.getFileName();
|
||||
String newPath = targetFolder.getRemotePath() + document.getFile().getFileName();
|
||||
|
||||
if (file.isFolder()) {
|
||||
if (document.getFile().isFolder()) {
|
||||
newPath = newPath + PATH_SEPARATOR;
|
||||
}
|
||||
OCFile newFile = currentStorageManager.getFileByPath(newPath);
|
||||
Document newFile = new Document(storageManager, newPath);
|
||||
|
||||
return String.valueOf(newFile.getFileId());
|
||||
context.getContentResolver().notifyChange(toNotifyUri(targetFolder), null, false);
|
||||
|
||||
return newFile.getDocumentId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String moveDocument(String sourceDocumentId, String sourceParentDocumentId, String targetParentDocumentId)
|
||||
throws FileNotFoundException {
|
||||
long sourceId = Long.parseLong(sourceDocumentId);
|
||||
Log.d(TAG, "moveDocument(), id=" + sourceDocumentId);
|
||||
|
||||
updateCurrentStorageManagerIfNeeded(sourceId);
|
||||
|
||||
OCFile file = currentStorageManager.getFileById(sourceId);
|
||||
|
||||
if (file == null) {
|
||||
throw new FileNotFoundException("File " + sourceDocumentId + " not found!");
|
||||
Context context = getContext();
|
||||
if (context == null) {
|
||||
throw new FileNotFoundException("Context may not be null!");
|
||||
}
|
||||
|
||||
long targetId = Long.parseLong(targetParentDocumentId);
|
||||
OCFile targetFolder = currentStorageManager.getFileById(targetId);
|
||||
Document document = toDocument(sourceDocumentId);
|
||||
Document targetFolder = toDocument(targetParentDocumentId);
|
||||
|
||||
if (targetFolder == null) {
|
||||
throw new FileNotFoundException("File " + targetParentDocumentId + " not found!");
|
||||
}
|
||||
|
||||
RemoteOperationResult result = new MoveFileOperation(file.getRemotePath(), targetFolder.getRemotePath())
|
||||
.execute(client, currentStorageManager);
|
||||
RemoteOperationResult result = new MoveFileOperation(document.getRemotePath(), targetFolder.getRemotePath())
|
||||
.execute(document.getClient(), document.getStorageManager());
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
throw new FileNotFoundException("Failed to move document with documentId " + sourceDocumentId
|
||||
+ " to " + targetParentDocumentId);
|
||||
}
|
||||
|
||||
return String.valueOf(file.getFileId());
|
||||
Document sourceFolder = toDocument(sourceParentDocumentId);
|
||||
|
||||
getContext().getContentResolver().notifyChange(toNotifyUri(sourceFolder), null, false);
|
||||
getContext().getContentResolver().notifyChange(toNotifyUri(targetFolder), null, false);
|
||||
|
||||
return sourceDocumentId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor querySearchDocuments(String rootId, String query, String[] projection) {
|
||||
updateCurrentStorageManagerIfNeeded(rootId);
|
||||
Log.d(TAG, "querySearchDocuments(), rootId=" + rootId);
|
||||
|
||||
OCFile root = currentStorageManager.getFileByPath(ROOT_PATH);
|
||||
FileCursor result = new FileCursor(projection);
|
||||
|
||||
for (OCFile f : findFiles(root, query)) {
|
||||
result.addFile(f);
|
||||
FileDataStorageManager storageManager = getStorageManager(rootId);
|
||||
if (storageManager == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
for (Document d : findFiles(new Document(storageManager, ROOT_PATH), query)) {
|
||||
result.addFile(d);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -447,53 +442,73 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
|
||||
@Override
|
||||
public String createDocument(String documentId, String mimeType, String displayName) throws FileNotFoundException {
|
||||
long docId = Long.parseLong(documentId);
|
||||
updateCurrentStorageManagerIfNeeded(docId);
|
||||
Log.d(TAG, "createDocument(), id=" + documentId);
|
||||
|
||||
OCFile parent = currentStorageManager.getFileById(docId);
|
||||
Document folderDocument = toDocument(documentId);
|
||||
|
||||
if (parent == null) {
|
||||
throw new FileNotFoundException("Parent file not found");
|
||||
}
|
||||
|
||||
if ("vnd.android.document/directory".equalsIgnoreCase(mimeType)) {
|
||||
return createFolder(parent, displayName, documentId);
|
||||
if (DocumentsContract.Document.MIME_TYPE_DIR.equalsIgnoreCase(mimeType)) {
|
||||
return createFolder(folderDocument, displayName);
|
||||
} else {
|
||||
return createFile(parent, displayName, documentId);
|
||||
return createFile(folderDocument, displayName);
|
||||
}
|
||||
}
|
||||
|
||||
private String createFolder(OCFile parent, String displayName, String documentId) throws FileNotFoundException {
|
||||
private String createFolder(Document targetFolder, String displayName) throws FileNotFoundException {
|
||||
|
||||
CreateFolderOperation createFolderOperation = new CreateFolderOperation(parent.getRemotePath() + displayName
|
||||
+ PATH_SEPARATOR, true);
|
||||
RemoteOperationResult result = createFolderOperation.execute(client, currentStorageManager);
|
||||
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
throw new FileNotFoundException("Failed to create document with name " +
|
||||
displayName + " and documentId " + documentId);
|
||||
}
|
||||
|
||||
|
||||
String newDirPath = parent.getRemotePath() + displayName + PATH_SEPARATOR;
|
||||
OCFile newFolder = currentStorageManager.getFileByPath(newDirPath);
|
||||
|
||||
return String.valueOf(newFolder.getFileId());
|
||||
}
|
||||
|
||||
private String createFile(OCFile parent, String displayName, String documentId) throws FileNotFoundException {
|
||||
Context context = getContext();
|
||||
|
||||
if (context == null) {
|
||||
throw new FileNotFoundException("Context may not be null!");
|
||||
}
|
||||
|
||||
Account account = currentStorageManager.getAccount();
|
||||
String newDirPath = targetFolder.getRemotePath() + displayName + PATH_SEPARATOR;
|
||||
FileDataStorageManager storageManager = targetFolder.getStorageManager();
|
||||
|
||||
RemoteOperationResult result = new CreateFolderOperation(newDirPath, true)
|
||||
.execute(targetFolder.getClient(), storageManager);
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
throw new FileNotFoundException("Failed to create document with name " +
|
||||
displayName + " and documentId " + targetFolder.getDocumentId());
|
||||
}
|
||||
|
||||
RemoteOperationResult updateParent = new RefreshFolderOperation(targetFolder.getFile(), System.currentTimeMillis(),
|
||||
false, false, true, storageManager,
|
||||
targetFolder.getAccount(), context)
|
||||
.execute(targetFolder.getClient());
|
||||
|
||||
if (!updateParent.isSuccess()) {
|
||||
throw new FileNotFoundException("Failed to create document with documentId " + targetFolder.getDocumentId());
|
||||
}
|
||||
|
||||
Document newFolder = new Document(storageManager, newDirPath);
|
||||
|
||||
context.getContentResolver().notifyChange(toNotifyUri(targetFolder), null, false);
|
||||
|
||||
return newFolder.getDocumentId();
|
||||
}
|
||||
|
||||
private String createFile(Document targetFolder, String displayName) throws FileNotFoundException {
|
||||
Context context = getContext();
|
||||
if (context == null) {
|
||||
throw new FileNotFoundException("Context may not be null!");
|
||||
}
|
||||
|
||||
Account account = targetFolder.getAccount();
|
||||
|
||||
// create dummy file
|
||||
File tempDir = new File(FileStorageUtils.getTemporalPath(account.name));
|
||||
|
||||
if (!tempDir.exists() && !tempDir.mkdirs()) {
|
||||
throw new FileNotFoundException("Temp folder could not be created: " + tempDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
File emptyFile = new File(tempDir, displayName);
|
||||
|
||||
if (emptyFile.exists() && !emptyFile.delete()) {
|
||||
throw new FileNotFoundException("Previous file could not be deleted");
|
||||
}
|
||||
|
||||
try {
|
||||
if (!emptyFile.createNewFile()) {
|
||||
throw new FileNotFoundException("File could not be created");
|
||||
@@ -502,30 +517,40 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
throw new FileNotFoundException("File could not be created");
|
||||
}
|
||||
|
||||
FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
|
||||
requester.uploadNewFile(getContext(), account, new String[]{emptyFile.getAbsolutePath()},
|
||||
new String[]{parent.getRemotePath() + displayName}, null,
|
||||
FileUploader.LOCAL_BEHAVIOUR_MOVE, true, UploadFileOperation.CREATED_BY_USER, false,
|
||||
false);
|
||||
String newFilePath = targetFolder.getRemotePath() + displayName;
|
||||
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
Log_OC.e(TAG, "Thread interruption error");
|
||||
// perform the upload, no need for chunked operation as we have a empty file
|
||||
OwnCloudClient client = targetFolder.getClient();
|
||||
RemoteOperationResult result = new UploadFileRemoteOperation(emptyFile.getAbsolutePath(),
|
||||
newFilePath,
|
||||
null,
|
||||
"",
|
||||
String.valueOf(System.currentTimeMillis() / 1000))
|
||||
.execute(client);
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
throw new FileNotFoundException("Failed to upload document with path " + newFilePath);
|
||||
}
|
||||
|
||||
RemoteOperationResult updateParent = new RefreshFolderOperation(parent, System.currentTimeMillis(),
|
||||
false, false, true, currentStorageManager,
|
||||
account, getContext()).execute(client);
|
||||
RemoteOperationResult updateParent = new RefreshFolderOperation(targetFolder.getFile(),
|
||||
System.currentTimeMillis(),
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
targetFolder.getStorageManager(),
|
||||
account,
|
||||
context)
|
||||
.execute(client);
|
||||
|
||||
if (!updateParent.isSuccess()) {
|
||||
throw new FileNotFoundException("Failed to create document with documentId " + documentId);
|
||||
throw new FileNotFoundException("Failed to create document with documentId " + targetFolder.getDocumentId());
|
||||
}
|
||||
|
||||
String newFilePath = parent.getRemotePath() + displayName;
|
||||
OCFile newFile = currentStorageManager.getFileByPath(newFilePath);
|
||||
Document newFile = new Document(targetFolder.getStorageManager(), newFilePath);
|
||||
|
||||
return String.valueOf(newFile.getFileId());
|
||||
context.getContentResolver().notifyChange(toNotifyUri(targetFolder), null, false);
|
||||
|
||||
return newFile.getDocumentId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -535,76 +560,84 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
|
||||
@Override
|
||||
public void deleteDocument(String documentId) throws FileNotFoundException {
|
||||
long docId = Long.parseLong(documentId);
|
||||
updateCurrentStorageManagerIfNeeded(docId);
|
||||
|
||||
OCFile file = currentStorageManager.getFileById(docId);
|
||||
|
||||
if (file == null) {
|
||||
throw new FileNotFoundException("File " + documentId + " not found!");
|
||||
}
|
||||
Account account = currentStorageManager.getAccount();
|
||||
|
||||
RemoveFileOperation removeFileOperation = new RemoveFileOperation(file.getRemotePath(), false, account, true,
|
||||
getContext());
|
||||
|
||||
RemoteOperationResult result = removeFileOperation.execute(client, currentStorageManager);
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
throw new FileNotFoundException("Failed to delete document with documentId " + documentId);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
private void updateCurrentStorageManagerIfNeeded(long docId) {
|
||||
if (rootIdToStorageManager == null) {
|
||||
try {
|
||||
queryRoots(FileCursor.DEFAULT_DOCUMENT_PROJECTION);
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(TAG, "Failed to query roots");
|
||||
}
|
||||
}
|
||||
|
||||
if (currentStorageManager == null ||
|
||||
rootIdToStorageManager.containsKey(docId) && currentStorageManager != rootIdToStorageManager.get(docId)) {
|
||||
currentStorageManager = rootIdToStorageManager.get(docId);
|
||||
}
|
||||
|
||||
try {
|
||||
Account account = currentStorageManager.getAccount();
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(account, MainApp.getAppContext());
|
||||
client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, getContext());
|
||||
} catch (OperationCanceledException | IOException | AuthenticatorException |
|
||||
com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
|
||||
Log_OC.e(TAG, "Failed to set client", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCurrentStorageManagerIfNeeded(String rootId) {
|
||||
for (FileDataStorageManager data : rootIdToStorageManager.values()) {
|
||||
if (data.getAccount().name.equals(rootId)) {
|
||||
currentStorageManager = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("UseSparseArrays")
|
||||
private void initiateStorageMap() throws FileNotFoundException {
|
||||
Log.d(TAG, "deleteDocument(), id=" + documentId);
|
||||
|
||||
Context context = getContext();
|
||||
|
||||
final Account[] allAccounts = accountManager.getAccounts();
|
||||
rootIdToStorageManager = new HashMap<>(allAccounts.length);
|
||||
|
||||
if (context == null) {
|
||||
throw new FileNotFoundException("Context may not be null!");
|
||||
}
|
||||
|
||||
final ContentResolver contentResolver = context.getContentResolver();
|
||||
for (Account account : allAccounts) {
|
||||
Document document = toDocument(documentId);
|
||||
|
||||
recursiveRevokePermission(document);
|
||||
|
||||
RemoteOperationResult result = new RemoveFileOperation(document.getRemotePath(), false,
|
||||
document.getAccount(), true, context)
|
||||
.execute(document.getClient(), document.getStorageManager());
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
throw new FileNotFoundException("Failed to delete document with documentId " + documentId);
|
||||
}
|
||||
|
||||
Document parentFolder = document.getParent();
|
||||
context.getContentResolver().notifyChange(toNotifyUri(parentFolder), null, false);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private void recursiveRevokePermission(Document document) {
|
||||
FileDataStorageManager storageManager = document.getStorageManager();
|
||||
OCFile file = document.getFile();
|
||||
if (file.isFolder()) {
|
||||
for (OCFile child : storageManager.getFolderContent(file, false)) {
|
||||
recursiveRevokePermission(new Document(storageManager, child));
|
||||
}
|
||||
}
|
||||
|
||||
revokeDocumentPermission(document.getDocumentId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildDocument(String parentDocumentId, String documentId) {
|
||||
Log.d(TAG, "isChildDocument(), parent=" + parentDocumentId + ", id=" + documentId);
|
||||
|
||||
try {
|
||||
Document currentDocument = toDocument(documentId);
|
||||
Document parentDocument = toDocument(parentDocumentId);
|
||||
|
||||
while (!ROOT_PATH.equals(currentDocument.getRemotePath())) {
|
||||
currentDocument = currentDocument.getParent();
|
||||
if (parentDocument.getFile().equals(currentDocument.getFile())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(TAG, "failed to check for child document", e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private FileDataStorageManager getStorageManager(String rootId) {
|
||||
for(int i = 0; i < rootIdToStorageManager.size(); i++) {
|
||||
FileDataStorageManager storageManager = rootIdToStorageManager.valueAt(i);
|
||||
if (storageManager.getAccount().name.equals(rootId)) {
|
||||
return storageManager;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void initiateStorageMap() {
|
||||
|
||||
rootIdToStorageManager.clear();
|
||||
|
||||
ContentResolver contentResolver = getContext().getContentResolver();
|
||||
|
||||
for (Account account : accountManager.getAccounts()) {
|
||||
final FileDataStorageManager storageManager = new FileDataStorageManager(account, contentResolver);
|
||||
final OCFile rootDir = storageManager.getFileByPath(ROOT_PATH);
|
||||
rootIdToStorageManager.put(rootDir.getFileId(), storageManager);
|
||||
rootIdToStorageManager.put(account.hashCode(), storageManager);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,15 +651,136 @@ public class DocumentsStorageProvider extends DocumentsProvider {
|
||||
return !(cancellationSignal != null && cancellationSignal.isCanceled());
|
||||
}
|
||||
|
||||
List<OCFile> findFiles(OCFile root, String query) {
|
||||
List<OCFile> result = new ArrayList<>();
|
||||
for (OCFile f : currentStorageManager.getFolderContent(root, false)) {
|
||||
private List<Document> findFiles(Document root, String query) {
|
||||
FileDataStorageManager storageManager = root.getStorageManager();
|
||||
List<Document> result = new ArrayList<>();
|
||||
for (OCFile f : storageManager.getFolderContent(root.getFile(), false)) {
|
||||
if (f.isFolder()) {
|
||||
result.addAll(findFiles(f, query));
|
||||
result.addAll(findFiles(new Document(storageManager, f), query));
|
||||
} else if (f.getFileName().contains(query)) {
|
||||
result.add(f);
|
||||
result.add(new Document(storageManager, f));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Uri toNotifyUri(Document document) {
|
||||
return DocumentsContract.buildDocumentUri(
|
||||
getContext().getString(R.string.document_provider_authority),
|
||||
document.getDocumentId());
|
||||
}
|
||||
|
||||
private Document toDocument(String documentId) throws FileNotFoundException {
|
||||
String[] separated = documentId.split(DOCUMENTID_SEPARATOR, DOCUMENTID_PARTS);
|
||||
if (separated.length != DOCUMENTID_PARTS) {
|
||||
throw new FileNotFoundException("Invalid documentID " + documentId + "!");
|
||||
}
|
||||
|
||||
FileDataStorageManager storageManager = rootIdToStorageManager.get(Integer.parseInt(separated[0]));
|
||||
if (storageManager == null) {
|
||||
throw new FileNotFoundException("No storage manager associated for " + documentId + "!");
|
||||
}
|
||||
|
||||
return new Document(storageManager, Long.parseLong(separated[1]));
|
||||
}
|
||||
|
||||
public interface OnTaskFinishedCallback {
|
||||
void onTaskFinished(RemoteOperationResult result);
|
||||
}
|
||||
|
||||
static class ReloadFolderDocumentTask extends AsyncTask<Void, Void, RemoteOperationResult> {
|
||||
|
||||
private final Document folder;
|
||||
private final OnTaskFinishedCallback callback;
|
||||
|
||||
ReloadFolderDocumentTask(Document folder, OnTaskFinishedCallback callback) {
|
||||
this.folder = folder;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final RemoteOperationResult doInBackground(Void... params) {
|
||||
Log.d(TAG, "run ReloadFolderDocumentTask(), id=" + folder.getDocumentId());
|
||||
return new RefreshFolderOperation(folder.getFile(), System.currentTimeMillis(), false,
|
||||
false, true, folder.getStorageManager(), folder.getAccount(),
|
||||
MainApp.getAppContext())
|
||||
.execute(folder.getClient());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onPostExecute(RemoteOperationResult result) {
|
||||
if (callback != null) {
|
||||
callback.onTaskFinished(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Document {
|
||||
private final FileDataStorageManager storageManager;
|
||||
private final long fileId;
|
||||
|
||||
Document(FileDataStorageManager storageManager, long fileId) {
|
||||
this.storageManager = storageManager;
|
||||
this.fileId = fileId;
|
||||
}
|
||||
|
||||
Document(FileDataStorageManager storageManager, OCFile file) {
|
||||
this.storageManager = storageManager;
|
||||
this.fileId = file.getFileId();
|
||||
}
|
||||
|
||||
Document(FileDataStorageManager storageManager, String filePath) {
|
||||
this.storageManager = storageManager;
|
||||
this.fileId = storageManager.getFileByPath(filePath).getFileId();
|
||||
}
|
||||
|
||||
public String getDocumentId() {
|
||||
for(int i = 0; i < rootIdToStorageManager.size(); i++) {
|
||||
if (Objects.equals(storageManager, rootIdToStorageManager.valueAt(i))) {
|
||||
return rootIdToStorageManager.keyAt(i) + DOCUMENTID_SEPARATOR + fileId;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
FileDataStorageManager getStorageManager() {
|
||||
return storageManager;
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return getStorageManager().getAccount();
|
||||
}
|
||||
|
||||
public OCFile getFile() {
|
||||
return getStorageManager().getFileById(fileId);
|
||||
}
|
||||
|
||||
public String getRemotePath() {
|
||||
return getFile().getRemotePath();
|
||||
}
|
||||
|
||||
OwnCloudClient getClient() {
|
||||
try {
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(getAccount(), MainApp.getAppContext());
|
||||
return OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, getContext());
|
||||
} catch (OperationCanceledException | IOException | AuthenticatorException |
|
||||
com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
|
||||
Log_OC.e(TAG, "Failed to set client", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean isExpired() {
|
||||
return getFile().getLastSyncDateForData() + CACHE_EXPIRATION < System.currentTimeMillis();
|
||||
}
|
||||
|
||||
Document getParent() {
|
||||
long parentId = getFile().getParentId();
|
||||
if (parentId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Document(getStorageManager(), parentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,9 +42,11 @@ import android.net.Uri;
|
||||
import android.os.Binder;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.SyncedFolder;
|
||||
import com.owncloud.android.db.ProviderMeta;
|
||||
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
@@ -58,7 +60,10 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import dagger.android.AndroidInjection;
|
||||
|
||||
/**
|
||||
* The ContentProvider for the ownCloud App.
|
||||
@@ -91,6 +96,7 @@ public class FileContentProvider extends ContentProvider {
|
||||
public static final int ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION = 20;
|
||||
public static final int MINIMUM_PATH_SEGMENTS_SIZE = 1;
|
||||
|
||||
@Inject protected Clock clock;
|
||||
private DataBaseHelper mDbHelper;
|
||||
private Context mContext;
|
||||
private UriMatcher mUriMatcher;
|
||||
@@ -414,6 +420,7 @@ public class FileContentProvider extends ContentProvider {
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
AndroidInjection.inject(this);
|
||||
mDbHelper = new DataBaseHelper(getContext());
|
||||
mContext = getContext();
|
||||
|
||||
@@ -822,10 +829,12 @@ public class FileContentProvider extends ContentProvider {
|
||||
+ ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY + " INTEGER, " // wifi_only
|
||||
+ ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY + " INTEGER, " // charging only
|
||||
+ ProviderTableMeta.SYNCED_FOLDER_ENABLED + " INTEGER, " // enabled
|
||||
+ ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER, " // enable date
|
||||
+ ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE + " INTEGER, " // subfolder by date
|
||||
+ ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " TEXT, " // account
|
||||
+ ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION + " INTEGER, " // upload action
|
||||
+ ProviderTableMeta.SYNCED_FOLDER_TYPE + " INTEGER );" // type
|
||||
+ ProviderTableMeta.SYNCED_FOLDER_TYPE + " INTEGER, " // type
|
||||
+ ProviderTableMeta.SYNCED_FOLDER_HIDDEN + " INTEGER );" // hidden
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2013,6 +2022,48 @@ public class FileContentProvider extends ContentProvider {
|
||||
if (!upgraded) {
|
||||
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
|
||||
}
|
||||
|
||||
if (oldVersion < 50 && newVersion >= 50) {
|
||||
Log_OC.i(SQL, "Entering in the #50 add persistent enable date to synced_folders table");
|
||||
db.beginTransaction();
|
||||
try {
|
||||
db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
|
||||
ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER ");
|
||||
|
||||
db.execSQL("UPDATE " + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + " SET " +
|
||||
ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " = CASE " +
|
||||
" WHEN enabled = 0 THEN " + SyncedFolder.EMPTY_ENABLED_TIMESTAMP_MS + " " +
|
||||
" ELSE " + clock.getCurrentTime() +
|
||||
" END ");
|
||||
|
||||
upgraded = true;
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
if (!upgraded) {
|
||||
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
|
||||
}
|
||||
|
||||
if (oldVersion < 51 && newVersion >= 51) {
|
||||
Log_OC.i(SQL, "Entering in the #51 add show/hide to folderSync table");
|
||||
db.beginTransaction();
|
||||
try {
|
||||
db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
|
||||
ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_HIDDEN + " INTEGER ");
|
||||
|
||||
upgraded = true;
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
if (!upgraded) {
|
||||
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.os.Looper;
|
||||
import android.provider.BaseColumns;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
@@ -180,18 +181,14 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
||||
|
||||
// need to trust on the AccountUtils to get the current account since the query in the client side is not
|
||||
// directly started by our code, but from SearchView implementation
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
|
||||
if (account == null) {
|
||||
throw new IllegalArgumentException("Account may not be null!");
|
||||
}
|
||||
User user = accountManager.getUser();
|
||||
|
||||
String userQuery = lastPathSegment.toLowerCase(Locale.ROOT);
|
||||
|
||||
// request to the OC server about users and groups matching userQuery
|
||||
GetShareesRemoteOperation searchRequest = new GetShareesRemoteOperation(userQuery, REQUESTED_PAGE,
|
||||
RESULTS_PER_PAGE);
|
||||
RemoteOperationResult result = searchRequest.execute(account, getContext());
|
||||
RemoteOperationResult result = searchRequest.execute(user.toPlatformAccount(), getContext());
|
||||
List<JSONObject> names = new ArrayList<>();
|
||||
|
||||
if (result.isSuccess()) {
|
||||
@@ -217,8 +214,10 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
||||
Uri remoteBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_REMOTE).build();
|
||||
Uri emailBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_EMAIL).build();
|
||||
|
||||
FileDataStorageManager manager = new FileDataStorageManager(account, getContext().getContentResolver());
|
||||
boolean federatedShareAllowed = manager.getCapability(account.name).getFilesSharingFederationOutgoing()
|
||||
FileDataStorageManager manager = new FileDataStorageManager(user.toPlatformAccount(),
|
||||
getContext().getContentResolver());
|
||||
boolean federatedShareAllowed = manager.getCapability(user.getAccountName())
|
||||
.getFilesSharingFederationOutgoing()
|
||||
.isTrue();
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/**
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* Copyright (C) 2015 ownCloud Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.view.View;
|
||||
|
||||
import com.owncloud.android.R;
|
||||
|
||||
public class RadioButtonPreference extends CheckBoxPreference implements View.OnLongClickListener {
|
||||
|
||||
public RadioButtonPreference(Context context) {
|
||||
super(context, null, android.R.attr.checkBoxPreferenceStyle);
|
||||
setWidgetLayoutResource(R.layout.preference_widget_radiobutton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Switch;
|
||||
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.utils.ThemeUtils;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
@@ -76,12 +77,14 @@ public class ThemeableSwitchPreference extends SwitchPreference {
|
||||
if(thumbColorStateList == null && trackColorStateList == null) {
|
||||
int color = ThemeUtils.primaryAccentColor(getContext());
|
||||
int trackColor = Color.argb(77, Color.red(color), Color.green(color), Color.blue(color));
|
||||
int trackColorUnchecked = getContext().getResources().getColor(R.color.switch_track_color_unchecked);
|
||||
thumbColorStateList = new ColorStateList(
|
||||
new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
|
||||
new int[]{color, Color.WHITE});
|
||||
trackColorStateList = new ColorStateList(
|
||||
new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
|
||||
new int[]{trackColor, Color.parseColor("#4D000000")});
|
||||
new int[][]{new int[]{android.R.attr.state_checked},
|
||||
new int[]{}},
|
||||
new int[]{trackColor, trackColorUnchecked});
|
||||
}
|
||||
|
||||
// setting the thumb color
|
||||
|
||||
@@ -169,7 +169,8 @@ public class ActivitiesActivity extends FileActivity implements ActivityListInte
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(getAccount(), getContentResolver());
|
||||
adapter = new ActivityListAdapter(this, getUserAccountManager(), this, storageManager, getCapabilities(), false);
|
||||
adapter = new ActivityListAdapter(this, getUserAccountManager(), this, storageManager,
|
||||
getCapabilities(), false);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
|
||||
@@ -99,7 +99,6 @@ public class StickyHeaderItemDecoration extends RecyclerView.ItemDecoration {
|
||||
int headerPosition = adapter.getHeaderPositionForItem(itemPosition);
|
||||
int layoutId = adapter.getHeaderLayout(itemPosition);
|
||||
View header = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
|
||||
header.setBackgroundColor(Color.WHITE);
|
||||
adapter.bindHeaderData(header, headerPosition);
|
||||
return header;
|
||||
}
|
||||
|
||||
+6
-2
@@ -28,6 +28,7 @@ import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
@@ -58,8 +59,11 @@ public class ActivitiesServiceApiImpl implements ActivitiesServiceApi {
|
||||
|
||||
@Override
|
||||
public void getAllActivities(int lastGiven, ActivitiesServiceCallback<List<Object>> callback) {
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
GetActivityListTask getActivityListTask = new GetActivityListTask(account, accountManager, lastGiven, callback);
|
||||
User user = accountManager.getUser();
|
||||
GetActivityListTask getActivityListTask = new GetActivityListTask(user.toPlatformAccount(),
|
||||
accountManager,
|
||||
lastGiven,
|
||||
callback);
|
||||
getActivityListTask.execute();
|
||||
}
|
||||
|
||||
|
||||
+20
-32
@@ -22,19 +22,16 @@
|
||||
*/
|
||||
package com.owncloud.android.ui.activities.data.files;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
@@ -44,8 +41,6 @@ import com.owncloud.android.operations.RefreshFolderOperation;
|
||||
import com.owncloud.android.ui.activity.BaseActivity;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Implementation of the Files service API that communicates with the NextCloud remote server.
|
||||
*/
|
||||
@@ -54,15 +49,18 @@ public class FilesServiceApiImpl implements FilesServiceApi {
|
||||
private static final String TAG = FilesServiceApiImpl.class.getSimpleName();
|
||||
|
||||
private UserAccountManager accountManager;
|
||||
private ClientFactory clientFactory;
|
||||
|
||||
public FilesServiceApiImpl(UserAccountManager accountManager) {
|
||||
public FilesServiceApiImpl(UserAccountManager accountManager, ClientFactory clientFactory) {
|
||||
this.accountManager = accountManager;
|
||||
this.clientFactory = clientFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readRemoteFile(String fileUrl, BaseActivity activity, FilesServiceCallback<OCFile> callback) {
|
||||
ReadRemoteFileTask readRemoteFileTask = new ReadRemoteFileTask(
|
||||
accountManager,
|
||||
clientFactory,
|
||||
fileUrl,
|
||||
activity,
|
||||
callback
|
||||
@@ -77,30 +75,29 @@ public class FilesServiceApiImpl implements FilesServiceApi {
|
||||
// TODO: Figure out a better way to do this than passing a BaseActivity reference.
|
||||
private final BaseActivity baseActivity;
|
||||
private final String fileUrl;
|
||||
private final Account account;
|
||||
private final User user;
|
||||
private final UserAccountManager accountManager;
|
||||
private final ClientFactory clientFactory;
|
||||
|
||||
private ReadRemoteFileTask(UserAccountManager accountManager,
|
||||
ClientFactory clientFactory,
|
||||
String fileUrl,
|
||||
BaseActivity baseActivity,
|
||||
FilesServiceCallback<OCFile> callback) {
|
||||
this.callback = callback;
|
||||
this.baseActivity = baseActivity;
|
||||
this.fileUrl = fileUrl;
|
||||
this.account = accountManager.getCurrentAccount();
|
||||
this.user = accountManager.getUser();
|
||||
this.accountManager = accountManager;
|
||||
this.clientFactory = clientFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
final Context context = MainApp.getAppContext();
|
||||
OwnCloudAccount ocAccount;
|
||||
OwnCloudClient ownCloudClient;
|
||||
try {
|
||||
ocAccount = new OwnCloudAccount(account, context);
|
||||
ownCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
getClientFor(ocAccount, MainApp.getAppContext());
|
||||
ownCloudClient.setOwnCloudVersion(accountManager.getServerVersion(account));
|
||||
OwnCloudClient ownCloudClient = clientFactory.create(user);
|
||||
ownCloudClient.setOwnCloudVersion(user.getServer().getVersion());
|
||||
// always update file as it could be an old state saved in database
|
||||
RemoteOperationResult resultRemoteFileOp = new ReadFileRemoteOperation(fileUrl).execute(ownCloudClient);
|
||||
|
||||
@@ -111,28 +108,19 @@ public class FilesServiceApiImpl implements FilesServiceApi {
|
||||
if (remoteOcFile.isFolder()) {
|
||||
// perform folder synchronization
|
||||
RemoteOperation synchFolderOp = new RefreshFolderOperation(remoteOcFile,
|
||||
System.currentTimeMillis(),
|
||||
false,
|
||||
true,
|
||||
baseActivity.getStorageManager(),
|
||||
baseActivity.getAccount(),
|
||||
context);
|
||||
System.currentTimeMillis(),
|
||||
false,
|
||||
true,
|
||||
baseActivity.getStorageManager(),
|
||||
baseActivity.getAccount(),
|
||||
context);
|
||||
synchFolderOp.execute(ownCloudClient);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
Log_OC.e(TAG, "Account not found", e);
|
||||
errorMessage = baseActivity.getString(R.string.account_not_found);
|
||||
} catch (IOException e) {
|
||||
Log_OC.e(TAG, "IO error", e);
|
||||
errorMessage = baseActivity.getString(R.string.io_error);
|
||||
} catch (OperationCanceledException e) {
|
||||
Log_OC.e(TAG, "Operation has been canceled", e);
|
||||
errorMessage = baseActivity.getString(R.string.operation_canceled);
|
||||
} catch (AuthenticatorException e) {
|
||||
Log_OC.e(TAG, "Authentication Exception", e);
|
||||
errorMessage = baseActivity.getString(R.string.authentication_exception);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -8,9 +8,13 @@ import android.accounts.OperationCanceledException;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.PersistableBundle;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
@@ -19,43 +23,93 @@ import com.owncloud.android.lib.resources.status.OCCapability;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
/**
|
||||
* Base activity with common behaviour for activities dealing with ownCloud {@link Account}s .
|
||||
*/
|
||||
public abstract class BaseActivity extends AppCompatActivity implements Injectable {
|
||||
|
||||
private static final String TAG = BaseActivity.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* ownCloud {@link Account} where the main {@link OCFile} handled by the activity is located.
|
||||
*/
|
||||
private Account mCurrentAccount;
|
||||
private Account currentAccount;
|
||||
|
||||
/**
|
||||
* Capabilities of the server where {@link #mCurrentAccount} lives.
|
||||
* Capabilities of the server where {@link #currentAccount} lives.
|
||||
*/
|
||||
private OCCapability mCapabilities;
|
||||
private OCCapability capabilities;
|
||||
|
||||
/**
|
||||
* Access point to the cached database for the current ownCloud {@link Account}.
|
||||
*/
|
||||
private FileDataStorageManager mStorageManager;
|
||||
private FileDataStorageManager storageManager;
|
||||
|
||||
/**
|
||||
* Tracks whether the activity should be recreate()'d after a theme change
|
||||
*/
|
||||
private boolean themeChangePending;
|
||||
private boolean paused;
|
||||
|
||||
@Inject UserAccountManager accountManager;
|
||||
@Inject AppPreferences preferences;
|
||||
|
||||
private AppPreferences.Listener onPreferencesChanged = new AppPreferences.Listener() {
|
||||
@Override
|
||||
public void onDarkThemeEnabledChanged(boolean enabled) {
|
||||
BaseActivity.this.onThemeSettingsChanged();
|
||||
}
|
||||
};
|
||||
|
||||
public UserAccountManager getUserAccountManager() {
|
||||
return accountManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
preferences.addListener(onPreferencesChanged);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
preferences.removeListener(onPreferencesChanged);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
paused = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
paused = false;
|
||||
|
||||
if(themeChangePending) {
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
|
||||
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
|
||||
super.onCreate(savedInstanceState, persistentState);
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
setAccount(account, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
|
||||
Log_OC.v(TAG, "onNewIntent() start");
|
||||
Account current = accountManager.getCurrentAccount();
|
||||
if (current != null && mCurrentAccount != null && !mCurrentAccount.name.equals(current.name)) {
|
||||
mCurrentAccount = current;
|
||||
if (current != null && currentAccount != null && !currentAccount.name.equals(current.name)) {
|
||||
currentAccount = current;
|
||||
}
|
||||
Log_OC.v(TAG, "onNewIntent() stop");
|
||||
}
|
||||
@@ -68,13 +122,21 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
||||
protected void onRestart() {
|
||||
Log_OC.v(TAG, "onRestart() start");
|
||||
super.onRestart();
|
||||
boolean validAccount = mCurrentAccount != null && accountManager.exists(mCurrentAccount);
|
||||
boolean validAccount = currentAccount != null && accountManager.exists(currentAccount);
|
||||
if (!validAccount) {
|
||||
swapToDefaultAccount();
|
||||
}
|
||||
Log_OC.v(TAG, "onRestart() end");
|
||||
}
|
||||
|
||||
private void onThemeSettingsChanged() {
|
||||
if(paused) {
|
||||
themeChangePending = true;
|
||||
} else {
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets and validates the ownCloud {@link Account} associated to the Activity.
|
||||
*
|
||||
@@ -87,10 +149,19 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
||||
protected void setAccount(Account account, boolean savedAccount) {
|
||||
boolean validAccount = account != null && accountManager.setCurrentOwnCloudAccount(account.name);
|
||||
if (validAccount) {
|
||||
mCurrentAccount = account;
|
||||
currentAccount = account;
|
||||
} else {
|
||||
swapToDefaultAccount();
|
||||
}
|
||||
|
||||
if(currentAccount != null) {
|
||||
storageManager = new FileDataStorageManager(currentAccount, getContentResolver());
|
||||
capabilities = storageManager.getCapability(currentAccount.name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setUser(User user) {
|
||||
setAccount(user.toPlatformAccount(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +177,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
||||
/// no account available: force account creation
|
||||
createAccount(true);
|
||||
} else {
|
||||
mCurrentAccount = newAccount;
|
||||
currentAccount = newAccount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,26 +198,6 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
||||
new Handler());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the ownCloud {@link Account} associated to the Activity was just updated.
|
||||
*
|
||||
* Child classes must grant that state depending on the {@link Account} is updated.
|
||||
*/
|
||||
@Deprecated
|
||||
protected void onAccountSet() {
|
||||
if (getAccount() != null) {
|
||||
mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
|
||||
mCapabilities = mStorageManager.getCapability(mCurrentAccount.name);
|
||||
} else {
|
||||
Log_OC.e(TAG, "onAccountChanged was called with NULL account associated!");
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void setAccount(Account account) {
|
||||
mCurrentAccount = account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the capabilities of the server where the current OC account lives.
|
||||
*
|
||||
@@ -154,7 +205,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
||||
* set yet.
|
||||
*/
|
||||
public OCCapability getCapabilities() {
|
||||
return mCapabilities;
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,20 +216,19 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
||||
* is located.
|
||||
*/
|
||||
public Account getAccount() {
|
||||
return mCurrentAccount;
|
||||
return currentAccount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
if(mCurrentAccount != null) {
|
||||
onAccountSet();
|
||||
public Optional<User> getUser() {
|
||||
if (currentAccount != null) {
|
||||
return accountManager.getUser(currentAccount.name);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public FileDataStorageManager getStorageManager() {
|
||||
return mStorageManager;
|
||||
return storageManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
@@ -93,7 +92,7 @@ public class CommunityActivity extends FileActivity {
|
||||
getString(R.string.contributing_link)))));
|
||||
|
||||
MaterialButton reportButton = findViewById(R.id.community_testing_report);
|
||||
reportButton.getBackground().setColorFilter(ThemeUtils.primaryColor(this, true), PorterDuff.Mode.SRC_ATOP);
|
||||
reportButton.setBackgroundColor(ThemeUtils.primaryColor(this,true));
|
||||
reportButton.setOnClickListener(v -> DisplayUtils.startLinkIntent(this, R.string.report_issue_link));
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,10 @@ import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.nextcloud.client.onboarding.FirstRunActivity;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.MainApp;
|
||||
@@ -109,7 +111,9 @@ import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.appcompat.graphics.drawable.DrawerArrowDrawable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
|
||||
@@ -215,6 +219,9 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
@Inject
|
||||
AppPreferences preferences;
|
||||
|
||||
@Inject
|
||||
ClientFactory clientFactory;
|
||||
|
||||
/**
|
||||
* Initializes the drawer, its content and highlights the menu item with the given id.
|
||||
* This method needs to be called after the content view has been set.
|
||||
@@ -355,21 +362,19 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
navigationView.getMenu().setGroupVisible(R.id.drawer_menu_accounts, false);
|
||||
}
|
||||
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
User account = accountManager.getUser();
|
||||
filterDrawerMenu(navigationView.getMenu(), account);
|
||||
}
|
||||
|
||||
private void filterDrawerMenu(Menu menu, Account account) {
|
||||
OCCapability capability = null;
|
||||
if (account != null) {
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver());
|
||||
capability = storageManager.getCapability(account.name);
|
||||
}
|
||||
private void filterDrawerMenu(final Menu menu, @NonNull final User user) {
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(user.toPlatformAccount(),
|
||||
getContentResolver());
|
||||
OCCapability capability = storageManager.getCapability(user.getAccountName());
|
||||
|
||||
boolean hasSearchSupport = accountManager.getServerVersion(account).isSearchSupported();
|
||||
boolean hasSearchSupport = user.getServer().getVersion().isSearchSupported();
|
||||
|
||||
DrawerMenuUtil.filterSearchMenuItems(menu, account, getResources(), hasSearchSupport);
|
||||
DrawerMenuUtil.filterTrashbinMenuItem(menu, account, capability, accountManager);
|
||||
DrawerMenuUtil.filterSearchMenuItems(menu, user.toPlatformAccount(), getResources(), hasSearchSupport);
|
||||
DrawerMenuUtil.filterTrashbinMenuItem(menu, user.toPlatformAccount(), capability, accountManager);
|
||||
DrawerMenuUtil.filterActivityMenuItem(menu, capability);
|
||||
|
||||
DrawerMenuUtil.setupHomeMenuItem(menu, getResources());
|
||||
@@ -683,7 +688,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
if (mNavigationView != null && mDrawerLayout != null) {
|
||||
if (persistingAccounts.size() > 0) {
|
||||
repopulateAccountList(persistingAccounts);
|
||||
setAccountInDrawer(accountManager.getCurrentAccount());
|
||||
setAccountInDrawer(accountManager.getUser());
|
||||
populateDrawerOwnCloudAccounts();
|
||||
|
||||
// activate second/end account avatar
|
||||
@@ -789,30 +794,25 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
* sets the given account name in the drawer in case the drawer is available. The account name is shortened
|
||||
* beginning from the @-sign in the username.
|
||||
*
|
||||
* @param account the account to be set in the drawer
|
||||
* @param user the account to be set in the drawer
|
||||
*/
|
||||
protected void setAccountInDrawer(Account account) {
|
||||
if (mDrawerLayout != null && account != null) {
|
||||
protected void setAccountInDrawer(User user) {
|
||||
if (mDrawerLayout != null && user != null) {
|
||||
TextView username = (TextView) findNavigationViewChildById(R.id.drawer_username);
|
||||
TextView usernameFull = (TextView) findNavigationViewChildById(R.id.drawer_username_full);
|
||||
|
||||
usernameFull.setText(DisplayUtils.convertIdn(account.name.substring(account.name.lastIndexOf('@') + 1),
|
||||
String name = user.getAccountName();
|
||||
usernameFull.setText(DisplayUtils.convertIdn(name.substring(name.lastIndexOf('@') + 1),
|
||||
false));
|
||||
usernameFull.setTextColor(ThemeUtils.fontColor(this));
|
||||
|
||||
try {
|
||||
OwnCloudAccount oca = new OwnCloudAccount(account, this);
|
||||
username.setText(oca.getDisplayName());
|
||||
username.setTextColor(ThemeUtils.fontColor(this));
|
||||
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
|
||||
Log_OC.w(TAG, "Couldn't read display name of account fallback to account name");
|
||||
username.setText(UserAccountManager.getUsername(account));
|
||||
}
|
||||
username.setText(user.toOwnCloudAccount().getDisplayName());
|
||||
username.setTextColor(ThemeUtils.fontColor(this));
|
||||
|
||||
View currentAccountView = findNavigationViewChildById(R.id.drawer_current_account);
|
||||
currentAccountView.setTag(account.name);
|
||||
currentAccountView.setTag(name);
|
||||
|
||||
DisplayUtils.setAvatar(account, this, mCurrentAccountAvatarRadiusDimension, getResources(),
|
||||
DisplayUtils.setAvatar(user.toPlatformAccount(), this, mCurrentAccountAvatarRadiusDimension, getResources(),
|
||||
currentAccountView, this);
|
||||
|
||||
// check and show quota info if available
|
||||
@@ -956,6 +956,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
};
|
||||
|
||||
DisplayUtils.downloadIcon(getUserAccountManager(),
|
||||
clientFactory,
|
||||
this,
|
||||
firstQuota.iconUrl,
|
||||
target,
|
||||
@@ -989,7 +990,17 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
MenuItem menuItem = mNavigationView.getMenu().getItem(i);
|
||||
if (menuItem.getIcon() != null) {
|
||||
menuItem.getIcon().clearColorFilter();
|
||||
menuItem.setTitle(Html.fromHtml("<font color='#000000'>" + menuItem.getTitle() + "</font>"));
|
||||
if (menuItem.getGroupId() != R.id.drawer_menu_accounts
|
||||
|| menuItem.getItemId() == R.id.drawer_menu_account_add
|
||||
|| menuItem.getItemId() == R.id.drawer_menu_account_manage) {
|
||||
ThemeUtils.tintDrawable(
|
||||
menuItem.getIcon(), ContextCompat.getColor(this, R.color.drawer_menu_icon));
|
||||
}
|
||||
menuItem.setTitle(Html.fromHtml(
|
||||
"<font color='"
|
||||
+ ThemeUtils.colorToHexString(ContextCompat.getColor(this, R.color.text_color))
|
||||
+ "'>" + menuItem.getTitle()
|
||||
+ "</font>"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1012,14 +1023,14 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
// set user space information
|
||||
Thread t = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
final Account currentAccount = accountManager.getCurrentAccount();
|
||||
final User user = accountManager.getUser();
|
||||
|
||||
if (currentAccount == null) {
|
||||
if (user.isAnonymous()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Context context = MainApp.getAppContext();
|
||||
RemoteOperationResult result = new GetUserInfoRemoteOperation().execute(currentAccount, context);
|
||||
RemoteOperationResult result = new GetUserInfoRemoteOperation().execute(user.toPlatformAccount(), context);
|
||||
|
||||
if (result.isSuccess() && result.getData() != null) {
|
||||
final UserInfo userInfo = (UserInfo) result.getData().get(0);
|
||||
@@ -1068,7 +1079,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
|
||||
float density = getResources().getDisplayMetrics().density;
|
||||
final int size = Math.round(24 * density);
|
||||
int greyColor = getResources().getColor(R.color.standard_grey);
|
||||
int greyColor = ContextCompat.getColor(this, R.color.drawer_menu_icon);
|
||||
|
||||
for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.LINK)) {
|
||||
int id = mNavigationView.getMenu().add(R.id.drawer_menu_external_links,
|
||||
@@ -1089,6 +1100,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
};
|
||||
|
||||
DisplayUtils.downloadIcon(getUserAccountManager(),
|
||||
clientFactory,
|
||||
this,
|
||||
link.iconUrl,
|
||||
target,
|
||||
@@ -1263,6 +1275,9 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
getDelegate().setLocalNightMode(preferences.isDarkThemeEnabled() ?
|
||||
AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
|
||||
getDelegate().applyDayNight();
|
||||
setDrawerMenuItemChecked(mCheckedMenuItem);
|
||||
}
|
||||
|
||||
@@ -1278,7 +1293,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
|
||||
// current account has changed
|
||||
if (data.getBooleanExtra(ManageAccountsActivity.KEY_CURRENT_ACCOUNT_CHANGED, false)) {
|
||||
setAccount(accountManager.getCurrentAccount());
|
||||
setAccount(accountManager.getCurrentAccount(), false);
|
||||
updateAccountList();
|
||||
restart();
|
||||
} else {
|
||||
@@ -1360,12 +1375,11 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
}
|
||||
}
|
||||
|
||||
Account currentAccount = accountManager.getCurrentAccount();
|
||||
|
||||
mAvatars[0] = currentAccount;
|
||||
User user = accountManager.getUser();
|
||||
mAvatars[0] = user.toPlatformAccount();
|
||||
int j = 0;
|
||||
for (int i = 1; i <= 2 && i < persistingAccounts.size() && j < persistingAccounts.size(); j++) {
|
||||
if (!currentAccount.equals(persistingAccounts.get(j))) {
|
||||
if (!user.equals(persistingAccounts.get(j))) {
|
||||
mAvatars[i] = persistingAccounts.get(j);
|
||||
i++;
|
||||
}
|
||||
@@ -1447,11 +1461,10 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
getCapabilities.execute(getStorageManager(), getBaseContext());
|
||||
}
|
||||
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
|
||||
if (account != null && getStorageManager() != null &&
|
||||
getStorageManager().getCapability(account.name) != null &&
|
||||
getStorageManager().getCapability(account.name).getExternalLinks().isTrue()) {
|
||||
User user = accountManager.getUser();
|
||||
String name = user.getAccountName();
|
||||
if (getStorageManager() != null && getStorageManager().getCapability(name) != null &&
|
||||
getStorageManager().getCapability(name).getExternalLinks().isTrue()) {
|
||||
|
||||
int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL,
|
||||
FileActivity.APP_OPENED_COUNT);
|
||||
@@ -1466,7 +1479,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
||||
|
||||
Log_OC.d("ExternalLinks", "update via api");
|
||||
RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
|
||||
RemoteOperationResult result = getExternalLinksOperation.execute(account, this);
|
||||
RemoteOperationResult result = getExternalLinksOperation.execute(user.toPlatformAccount(), this);
|
||||
|
||||
if (result.isSuccess() && result.getData() != null) {
|
||||
externalLinksProvider.deleteAllExternalLinks();
|
||||
|
||||
@@ -65,7 +65,6 @@ public class ExternalSiteWebView extends FileActivity {
|
||||
private boolean showSidebar;
|
||||
String url;
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Log_OC.v(TAG, "onCreate() start");
|
||||
@@ -93,7 +92,6 @@ public class ExternalSiteWebView extends FileActivity {
|
||||
webview.setFocusableInTouchMode(true);
|
||||
webview.setClickable(true);
|
||||
|
||||
|
||||
// allow debugging (when building the debug version); see details in
|
||||
// https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
|
||||
@@ -114,39 +112,8 @@ public class ExternalSiteWebView extends FileActivity {
|
||||
setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
|
||||
}
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
ThemeUtils.setColoredTitle(actionBar, title, this);
|
||||
|
||||
if (showSidebar) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
} else {
|
||||
setDrawerIndicatorEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
// enable zoom
|
||||
webSettings.setSupportZoom(true);
|
||||
webSettings.setBuiltInZoomControls(true);
|
||||
webSettings.setDisplayZoomControls(false);
|
||||
|
||||
// Non-responsive webs are zoomed out when loaded
|
||||
webSettings.setUseWideViewPort(true);
|
||||
webSettings.setLoadWithOverviewMode(true);
|
||||
|
||||
// user agent
|
||||
webSettings.setUserAgentString(MainApp.getUserAgent());
|
||||
|
||||
// no private data storing
|
||||
webSettings.setSavePassword(false);
|
||||
webSettings.setSaveFormData(false);
|
||||
|
||||
// disable local file access
|
||||
webSettings.setAllowFileAccess(false);
|
||||
|
||||
// enable javascript
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
webSettings.setDomStorageEnabled(true);
|
||||
setupActionBar(title);
|
||||
setupWebSettings(webSettings);
|
||||
|
||||
final ProgressBar progressBar = findViewById(R.id.progressBar);
|
||||
|
||||
@@ -172,6 +139,45 @@ public class ExternalSiteWebView extends FileActivity {
|
||||
webview.loadUrl(url);
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
private void setupWebSettings(WebSettings webSettings) {
|
||||
// enable zoom
|
||||
webSettings.setSupportZoom(true);
|
||||
webSettings.setBuiltInZoomControls(true);
|
||||
webSettings.setDisplayZoomControls(false);
|
||||
|
||||
// Non-responsive webs are zoomed out when loaded
|
||||
webSettings.setUseWideViewPort(true);
|
||||
webSettings.setLoadWithOverviewMode(true);
|
||||
|
||||
// user agent
|
||||
webSettings.setUserAgentString(MainApp.getUserAgent());
|
||||
|
||||
// no private data storing
|
||||
webSettings.setSavePassword(false);
|
||||
webSettings.setSaveFormData(false);
|
||||
|
||||
// disable local file access
|
||||
webSettings.setAllowFileAccess(false);
|
||||
|
||||
// enable javascript
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
webSettings.setDomStorageEnabled(true);
|
||||
}
|
||||
|
||||
private void setupActionBar(String title) {
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
ThemeUtils.setColoredTitle(actionBar, title, this);
|
||||
|
||||
if (showSidebar) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
} else {
|
||||
setDrawerIndicatorEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
boolean retval;
|
||||
|
||||
@@ -54,11 +54,13 @@ import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.appinfo.AppInfo;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.media.PlayerServiceConnection;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
@@ -765,7 +767,7 @@ public class FileDisplayActivity extends FileActivity
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.main_menu, menu);
|
||||
inflater.inflate(R.menu.activity_file_display, menu);
|
||||
menu.findItem(R.id.action_create_dir).setVisible(false);
|
||||
|
||||
menu.findItem(R.id.action_select_all).setVisible(false);
|
||||
@@ -2545,8 +2547,8 @@ public class FileDisplayActivity extends FileActivity
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
final Account account = getAccount();
|
||||
if (account != null) {
|
||||
Optional<User> optionalUser = getUser();
|
||||
if (optionalUser.isPresent()) {
|
||||
/// Check whether the 'main' OCFile handled by the Activity is contained in the
|
||||
// current Account
|
||||
OCFile file = getFile();
|
||||
@@ -2572,10 +2574,12 @@ public class FileDisplayActivity extends FileActivity
|
||||
}
|
||||
setFile(file);
|
||||
|
||||
setAccountInDrawer(account);
|
||||
User user = optionalUser.get();
|
||||
setAccountInDrawer(user);
|
||||
setupDrawer();
|
||||
|
||||
final boolean accountChanged = !account.equals(mLastDisplayedAccount);
|
||||
final String lastDisplayedAccountName = mLastDisplayedAccount != null ? mLastDisplayedAccount.name : null;
|
||||
final boolean accountChanged = !user.getAccountName().equals(lastDisplayedAccountName);
|
||||
if (accountChanged) {
|
||||
Log_OC.d(TAG, "Initializing Fragments in onAccountChanged..");
|
||||
initFragmentsWithFile();
|
||||
@@ -2587,7 +2591,11 @@ public class FileDisplayActivity extends FileActivity
|
||||
updateActionBarTitleAndHomeButton(file.isFolder() ? null : file);
|
||||
}
|
||||
}
|
||||
mLastDisplayedAccount = account;
|
||||
if (optionalUser.isPresent()) {
|
||||
mLastDisplayedAccount = optionalUser.get().toPlatformAccount();
|
||||
} else {
|
||||
mLastDisplayedAccount = null;
|
||||
}
|
||||
|
||||
EventBus.getDefault().post(new TokenPushEvent());
|
||||
checkForNewDevVersionNecessary(findViewById(R.id.root_layout), getApplicationContext());
|
||||
@@ -2621,7 +2629,8 @@ public class FileDisplayActivity extends FileActivity
|
||||
return;
|
||||
}
|
||||
|
||||
setAccount(newAccount);
|
||||
setAccount(newAccount, false);
|
||||
updateAccountList();
|
||||
}
|
||||
|
||||
String fileId = String.valueOf(intent.getStringExtra(KEY_FILE_ID));
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
|
||||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources.NotFoundException;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -38,10 +38,10 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
@@ -91,8 +91,8 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
|
||||
private boolean mSearchOnlyFolders;
|
||||
private boolean mDoNotEnterEncryptedFolder;
|
||||
|
||||
protected Button mCancelBtn;
|
||||
protected Button mChooseBtn;
|
||||
protected MaterialButton mCancelBtn;
|
||||
protected MaterialButton mChooseBtn;
|
||||
private String caption;
|
||||
@Inject AppPreferences preferences;
|
||||
|
||||
@@ -293,11 +293,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.main_menu, menu);
|
||||
menu.findItem(R.id.action_switch_view).setVisible(false);
|
||||
menu.findItem(R.id.action_sync_account).setVisible(false);
|
||||
menu.findItem(R.id.action_select_all).setVisible(false);
|
||||
// menu.findItem(R.id.action_sort).setVisible(false);
|
||||
inflater.inflate(R.menu.activity_folder_picker, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -406,7 +402,8 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
|
||||
mChooseBtn = findViewById(R.id.folder_picker_btn_choose);
|
||||
|
||||
if (mChooseBtn != null) {
|
||||
mChooseBtn.getBackground().setColorFilter(ThemeUtils.primaryColor(this, true), PorterDuff.Mode.SRC_ATOP);
|
||||
mChooseBtn.setBackgroundTintMode(PorterDuff.Mode.SRC_ATOP);
|
||||
mChooseBtn.setBackgroundTintList(ColorStateList.valueOf(ThemeUtils.primaryColor(this, true)));
|
||||
mChooseBtn.setOnClickListener(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import android.view.MenuItem;
|
||||
|
||||
import com.evernote.android.job.JobRequest;
|
||||
import com.evernote.android.job.util.support.PersistableBundleCompat;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.onboarding.FirstRunActivity;
|
||||
import com.owncloud.android.MainApp;
|
||||
@@ -126,15 +127,12 @@ public class ManageAccountsActivity extends FileActivity implements AccountListA
|
||||
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
|
||||
originalAccounts = DisplayUtils.toAccountNameSet(Arrays.asList(accountList));
|
||||
|
||||
Account currentAccount = getUserAccountManager().getCurrentAccount();
|
||||
Account currentAccount = getAccount();
|
||||
|
||||
if (currentAccount != null) {
|
||||
originalCurrentAccount = currentAccount.name;
|
||||
}
|
||||
|
||||
setAccount(currentAccount);
|
||||
onAccountSet();
|
||||
|
||||
arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
||||
|
||||
multipleAccountsSupported = getResources().getBoolean(R.bool.multiaccount_support);
|
||||
@@ -201,11 +199,11 @@ public class ManageAccountsActivity extends FileActivity implements AccountListA
|
||||
* @return true if account list has changed, false if not
|
||||
*/
|
||||
private boolean hasCurrentAccountChanged() {
|
||||
Account account = getUserAccountManager().getCurrentAccount();
|
||||
if (account == null) {
|
||||
User account = getUserAccountManager().getUser();
|
||||
if (account.isAnonymous()) {
|
||||
return true;
|
||||
} else {
|
||||
return !account.name.equals(originalCurrentAccount);
|
||||
return !account.getAccountName().equals(originalCurrentAccount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +321,8 @@ public class ManageAccountsActivity extends FileActivity implements AccountListA
|
||||
}
|
||||
}
|
||||
|
||||
if (getUserAccountManager().getCurrentAccount() == null) {
|
||||
User user = getUserAccountManager().getUser();
|
||||
if (user.isAnonymous()) {
|
||||
String accountName = "";
|
||||
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
|
||||
if (accounts.length != 0) {
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
|
||||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.Bundle;
|
||||
@@ -39,13 +36,14 @@ import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.jobs.NotificationJob;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
@@ -58,9 +56,10 @@ import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.PushUtils;
|
||||
import com.owncloud.android.utils.ThemeUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
@@ -109,7 +108,9 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
||||
private NotificationListAdapter adapter;
|
||||
private Snackbar snackbar;
|
||||
private OwnCloudClient client;
|
||||
private Account currentAccount;
|
||||
private Optional<User> optionalUser;
|
||||
|
||||
@Inject ClientFactory clientFactory;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -119,16 +120,18 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
||||
setContentView(R.layout.notifications_layout);
|
||||
unbinder = ButterKnife.bind(this);
|
||||
|
||||
currentAccount = getAccount();
|
||||
optionalUser = getUser();
|
||||
|
||||
// use account from intent (opened via android notification can have a different account than current one)
|
||||
if (getIntent() != null && getIntent().getExtras() != null) {
|
||||
String account = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT);
|
||||
|
||||
if (account != null && (currentAccount == null || !account.equalsIgnoreCase(currentAccount.name))) {
|
||||
accountManager.setCurrentOwnCloudAccount(account);
|
||||
setAccount(getUserAccountManager().getCurrentAccount());
|
||||
currentAccount = getAccount();
|
||||
String accountName = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT);
|
||||
if(accountName != null && optionalUser.isPresent()) {
|
||||
User user = optionalUser.get();
|
||||
if (user.getAccountName().equalsIgnoreCase(accountName)) {
|
||||
accountManager.setCurrentOwnCloudAccount(accountName);
|
||||
setUser(getUserAccountManager().getUser());
|
||||
optionalUser = getUser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +145,7 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
||||
setupDrawer(R.id.nav_notifications);
|
||||
ThemeUtils.setColoredTitle(getSupportActionBar(), getString(R.string.drawer_item_notifications), this);
|
||||
|
||||
if (currentAccount == null) {
|
||||
if (!optionalUser.isPresent()) {
|
||||
// show error
|
||||
runOnUiThread(() -> setEmptyContent(noResultsHeadline, getString(R.string.account_not_found)));
|
||||
return;
|
||||
@@ -156,7 +159,6 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
||||
swipeEmptyListRefreshLayout.setOnRefreshListener(() -> {
|
||||
setLoadingMessage();
|
||||
fetchAndSetData();
|
||||
|
||||
});
|
||||
|
||||
setupPushWarning();
|
||||
@@ -175,16 +177,16 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
||||
snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_not_implemented,
|
||||
Snackbar.LENGTH_INDEFINITE);
|
||||
} else {
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
||||
|
||||
boolean usesOldLogin = arbitraryDataProvider.getBooleanValue(currentAccount.name,
|
||||
final ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
||||
final String accountName = optionalUser.isPresent() ? optionalUser.get().getAccountName() : "";
|
||||
final boolean usesOldLogin = arbitraryDataProvider.getBooleanValue(accountName,
|
||||
UserAccountManager.ACCOUNT_USES_STANDARD_PASSWORD);
|
||||
|
||||
if (usesOldLogin) {
|
||||
snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_old_login,
|
||||
Snackbar.LENGTH_INDEFINITE);
|
||||
} else {
|
||||
String pushValue = arbitraryDataProvider.getValue(currentAccount.name, PushUtils.KEY_PUSH);
|
||||
String pushValue = arbitraryDataProvider.getValue(accountName, PushUtils.KEY_PUSH);
|
||||
|
||||
if (pushValue == null || pushValue.isEmpty()) {
|
||||
snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_temp_error,
|
||||
@@ -250,13 +252,12 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
||||
|
||||
private void fetchAndSetData() {
|
||||
Thread t = new Thread(() -> {
|
||||
if (client == null) {
|
||||
if (client == null && optionalUser.isPresent()) {
|
||||
try {
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(currentAccount, this);
|
||||
client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, this);
|
||||
client.setOwnCloudVersion(accountManager.getServerVersion(currentAccount));
|
||||
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException |
|
||||
IOException | OperationCanceledException | AuthenticatorException e) {
|
||||
User user = optionalUser.get();
|
||||
client = clientFactory.create(user);
|
||||
client.setOwnCloudVersion(user.getServer().getVersion());
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
Log_OC.e(TAG, "Error initializing client", e);
|
||||
}
|
||||
}
|
||||
@@ -303,7 +304,7 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
||||
}
|
||||
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.notifications_actions_menu, menu);
|
||||
getMenuInflater().inflate(R.menu.activity_notifications, menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -392,11 +393,13 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionCallback(boolean isSuccess, NotificationListAdapter.NotificationViewHolder holder) {
|
||||
public void onActionCallback(boolean isSuccess,
|
||||
Notification notification,
|
||||
NotificationListAdapter.NotificationViewHolder holder) {
|
||||
if (isSuccess) {
|
||||
adapter.removeNotification(holder);
|
||||
} else {
|
||||
adapter.setButtonEnabled(holder, true);
|
||||
adapter.setButtons(holder, notification);
|
||||
DisplayUtils.showSnackMessage(this, getString(R.string.notification_action_failed));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
@@ -97,7 +96,7 @@ public class PassCodeActivity extends AppCompatActivity implements Injectable {
|
||||
int elementColor = ThemeUtils.elementColor(this);
|
||||
|
||||
mBCancel = findViewById(R.id.cancel);
|
||||
mBCancel.getBackground().setColorFilter(elementColor, PorterDuff.Mode.SRC_ATOP);
|
||||
mBCancel.setBackgroundColor(ThemeUtils.primaryColor(this));
|
||||
|
||||
mPassCodeHdr = findViewById(R.id.header);
|
||||
mPassCodeHdrExplanation = findViewById(R.id.explanation);
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources.NotFoundException;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
@@ -63,6 +64,7 @@ import android.widget.ProgressBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.MainApp;
|
||||
@@ -206,8 +208,6 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
Log_OC.i(TAG, "No ownCloud account is available");
|
||||
DialogNoAccount dialog = new DialogNoAccount();
|
||||
dialog.show(getSupportFragmentManager(), null);
|
||||
} else if (!savedAccount) {
|
||||
setAccount(accounts[0]);
|
||||
}
|
||||
|
||||
if (!somethingToUpload()) {
|
||||
@@ -400,6 +400,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
|
||||
final EditText userInput = view.findViewById(R.id.user_input);
|
||||
setFilename(userInput, selectPos);
|
||||
userInput.setHighlightColor(ThemeUtils.primaryColor(getContext()));
|
||||
userInput.requestFocus();
|
||||
|
||||
final Spinner spinner = view.findViewById(R.id.file_type);
|
||||
@@ -677,7 +678,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
// there is no need for checking for is there more then one
|
||||
// account at this point
|
||||
// since account setup can set only one account at time
|
||||
setAccount(accounts[0]);
|
||||
setAccount(accounts[0], false);
|
||||
populateDirectoryList();
|
||||
}
|
||||
}
|
||||
@@ -748,10 +749,10 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
|
||||
mListView.setAdapter(sa);
|
||||
}
|
||||
Button btnChooseFolder = findViewById(R.id.uploader_choose_folder);
|
||||
btnChooseFolder.setOnClickListener(this);
|
||||
btnChooseFolder.getBackground().setColorFilter(ThemeUtils.primaryColor(getAccount(), true, this),
|
||||
PorterDuff.Mode.SRC_ATOP);
|
||||
MaterialButton btnChooseFolder = findViewById(R.id.uploader_choose_folder);
|
||||
btnChooseFolder.setBackgroundTintMode(PorterDuff.Mode.SRC_ATOP);
|
||||
btnChooseFolder.setBackgroundTintList(ColorStateList.valueOf(ThemeUtils.primaryColor(this, true)));
|
||||
btnChooseFolder.setOnClickListener(this);
|
||||
btnChooseFolder.setTextColor(ThemeUtils.fontColor(this));
|
||||
|
||||
if (mFile.canWrite()) {
|
||||
@@ -1015,7 +1016,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.receive_file_menu, menu);
|
||||
inflater.inflate(R.menu.activity_receive_external_files, menu);
|
||||
|
||||
if (!isHaveMultipleAccount()) {
|
||||
MenuItem switchAccountMenu = menu.findItem(R.id.action_switch_account);
|
||||
|
||||
@@ -49,6 +49,7 @@ import android.widget.Toast;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
@@ -155,7 +156,8 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
||||
break;
|
||||
}
|
||||
|
||||
Glide.with(this).using(new CustomGlideStreamLoader(currentAccountProvider)).load(template.getThumbnailLink())
|
||||
Glide.with(this).using(new CustomGlideStreamLoader(currentAccountProvider, clientFactory))
|
||||
.load(template.getThumbnailLink())
|
||||
.placeholder(placeholder)
|
||||
.error(placeholder)
|
||||
.into(thumbnail);
|
||||
@@ -250,7 +252,7 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
||||
}
|
||||
|
||||
if ("image/png".equalsIgnoreCase(file.getMimeType())) {
|
||||
thumbnailView.setBackgroundColor(getResources().getColor(R.color.background_color));
|
||||
thumbnailView.setBackgroundColor(getResources().getColor(R.color.bg_default));
|
||||
}
|
||||
} else {
|
||||
thumbnailView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(), file.getFileName(),
|
||||
@@ -314,9 +316,9 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
||||
OCFile file = data.getParcelableExtra(FolderPickerActivity.EXTRA_FILES);
|
||||
|
||||
new Thread(() -> {
|
||||
Account account = currentAccountProvider.getCurrentAccount();
|
||||
User user = currentAccountProvider.getUser();
|
||||
RichDocumentsCreateAssetOperation operation = new RichDocumentsCreateAssetOperation(file.getRemotePath());
|
||||
RemoteOperationResult result = operation.execute(account, this);
|
||||
RemoteOperationResult result = operation.execute(user.toPlatformAccount(), this);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
String asset = (String) result.getSingleData();
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -39,7 +38,6 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.preference.PreferenceScreen;
|
||||
@@ -53,15 +51,18 @@ import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.webkit.URLUtil;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.etm.EtmActivity;
|
||||
import com.nextcloud.client.logger.ui.LogsActivity;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.client.preferences.AppPreferencesImpl;
|
||||
import com.owncloud.android.BuildConfig;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity;
|
||||
import com.owncloud.android.authentication.PassCodeManager;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.datamodel.ExternalLinksProvider;
|
||||
@@ -69,8 +70,6 @@ import com.owncloud.android.datastorage.DataStorageProvider;
|
||||
import com.owncloud.android.datastorage.StoragePoint;
|
||||
import com.owncloud.android.lib.common.ExternalLink;
|
||||
import com.owncloud.android.lib.common.ExternalLinkType;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.asynctasks.LoadingVersionNumberTask;
|
||||
import com.owncloud.android.utils.DeviceCredentialUtils;
|
||||
@@ -95,7 +94,7 @@ import androidx.core.content.res.ResourcesCompat;
|
||||
*
|
||||
* It proxies the necessary calls via {@link androidx.appcompat.app.AppCompatDelegate} to be used with AppCompat.
|
||||
*/
|
||||
public class SettingsActivity extends PreferenceActivity
|
||||
public class SettingsActivity extends ThemedPreferenceActivity
|
||||
implements StorageMigration.StorageMigrationProgressListener, LoadingVersionNumberTask.VersionDevInterface,
|
||||
Injectable {
|
||||
|
||||
@@ -114,6 +113,7 @@ public class SettingsActivity extends PreferenceActivity
|
||||
private static final int ACTION_CONFIRM_PASSCODE = 6;
|
||||
private static final int ACTION_CONFIRM_DEVICE_CREDENTIALS = 7;
|
||||
private static final int ACTION_REQUEST_CODE_DAVDROID_SETUP = 10;
|
||||
private static final int TRUE_VALUE = 1;
|
||||
|
||||
private static final String DAV_PATH = "/remote.php/dav";
|
||||
|
||||
@@ -129,10 +129,11 @@ public class SettingsActivity extends PreferenceActivity
|
||||
private String storagePath;
|
||||
private String pendingLock;
|
||||
|
||||
private Account account;
|
||||
private User user;
|
||||
@Inject ArbitraryDataProvider arbitraryDataProvider;
|
||||
@Inject AppPreferences preferences;
|
||||
@Inject UserAccountManager accountManager;
|
||||
@Inject ClientFactory clientFactory;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@@ -155,7 +156,7 @@ public class SettingsActivity extends PreferenceActivity
|
||||
String appVersion = getAppVersion();
|
||||
PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference("preference_screen");
|
||||
|
||||
account = accountManager.getCurrentAccount();
|
||||
user = accountManager.getUser();
|
||||
|
||||
// retrieve user's base uri
|
||||
setupBaseUri();
|
||||
@@ -407,7 +408,7 @@ public class SettingsActivity extends PreferenceActivity
|
||||
}
|
||||
|
||||
private void setupE2EMnemonicPreference(PreferenceCategory preferenceCategoryMore) {
|
||||
String mnemonic = arbitraryDataProvider.getValue(account.name, EncryptionUtils.MNEMONIC);
|
||||
String mnemonic = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.MNEMONIC);
|
||||
|
||||
Preference pMnemonic = findPreference("mnemonic");
|
||||
if (pMnemonic != null) {
|
||||
@@ -602,11 +603,11 @@ public class SettingsActivity extends PreferenceActivity
|
||||
|
||||
final SwitchPreference pUploadOnWifiCheckbox = (SwitchPreference) findPreference("synced_folder_on_wifi");
|
||||
pUploadOnWifiCheckbox.setChecked(
|
||||
arbitraryDataProvider.getBooleanValue(account, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI));
|
||||
arbitraryDataProvider.getBooleanValue(user.toPlatformAccount(), SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI));
|
||||
|
||||
pUploadOnWifiCheckbox.setOnPreferenceClickListener(preference -> {
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(account.name, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI,
|
||||
String.valueOf(pUploadOnWifiCheckbox.isChecked()));
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI,
|
||||
String.valueOf(pUploadOnWifiCheckbox.isChecked()));
|
||||
|
||||
return true;
|
||||
});
|
||||
@@ -690,6 +691,16 @@ public class SettingsActivity extends PreferenceActivity
|
||||
}
|
||||
|
||||
loadStoragePath();
|
||||
|
||||
SwitchPreference themePref = (SwitchPreference) findPreference("dark_theme_enabled");
|
||||
boolean darkThemeEnabled = preferences.isDarkThemeEnabled();
|
||||
int summaryResId = darkThemeEnabled ? R.string.prefs_value_theme_dark : R.string.prefs_value_theme_light;
|
||||
themePref.setSummary(summaryResId);
|
||||
themePref.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean)newValue;
|
||||
MainApp.setAppTheme(enabled);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private String getAppVersion() {
|
||||
@@ -725,7 +736,7 @@ public class SettingsActivity extends PreferenceActivity
|
||||
Window window = getWindow();
|
||||
if (window != null) {
|
||||
window.getDecorView().setBackgroundDrawable(new ColorDrawable(ResourcesCompat
|
||||
.getColor(getResources(), R.color.background_color, null)));
|
||||
.getColor(getResources(), R.color.bg_default, null)));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
window.setStatusBarColor(ThemeUtils.primaryColor(this));
|
||||
@@ -748,8 +759,13 @@ public class SettingsActivity extends PreferenceActivity
|
||||
// arguments
|
||||
if (serverBaseUri != null) {
|
||||
davDroidLoginIntent.putExtra("url", serverBaseUri.toString() + DAV_PATH);
|
||||
|
||||
davDroidLoginIntent.putExtra("loginFlow", TRUE_VALUE);
|
||||
davDroidLoginIntent.setData(Uri.parse(serverBaseUri.toString() + AuthenticatorActivity.WEB_LOGIN));
|
||||
davDroidLoginIntent.putExtra("davPath", DAV_PATH);
|
||||
}
|
||||
davDroidLoginIntent.putExtra("username", UserAccountManager.getUsername(account));
|
||||
davDroidLoginIntent.putExtra("username", UserAccountManager.getUsername(user.toPlatformAccount()));
|
||||
|
||||
startActivityForResult(davDroidLoginIntent, ACTION_REQUEST_CODE_DAVDROID_SETUP);
|
||||
} else {
|
||||
// DAVdroid not installed
|
||||
@@ -773,9 +789,7 @@ public class SettingsActivity extends PreferenceActivity
|
||||
// retrieve and set user's base URI
|
||||
Thread t = new Thread(() -> {
|
||||
try {
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(account, MainApp.getAppContext());
|
||||
serverBaseUri = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount,
|
||||
getApplicationContext()).getBaseUri();
|
||||
serverBaseUri = clientFactory.create(user).getBaseUri();
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, "Error retrieving user's base URI", e);
|
||||
}
|
||||
@@ -841,7 +855,7 @@ public class SettingsActivity extends PreferenceActivity
|
||||
RequestCredentialsActivity.KEY_CHECK_RESULT_TRUE) {
|
||||
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
||||
String mnemonic = arbitraryDataProvider.getValue(account.name, EncryptionUtils.MNEMONIC);
|
||||
String mnemonic = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.MNEMONIC);
|
||||
|
||||
int accentColor = ThemeUtils.primaryAccentColor(this);
|
||||
|
||||
@@ -1001,5 +1015,4 @@ public class SettingsActivity extends PreferenceActivity
|
||||
public void returnVersion(Integer latestVersion) {
|
||||
FileActivity.showDevSnackbar(this, latestVersion, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,7 +30,6 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
@@ -144,7 +143,8 @@ public class SsoGrantPermissionActivity extends BaseActivity {
|
||||
int start = text.indexOf(textBlock);
|
||||
int end = start + textBlock.length();
|
||||
ssb.setSpan(new StyleSpan(Typeface.BOLD), start, end, 0);
|
||||
ssb.setSpan(new ForegroundColorSpan(Color.BLACK), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
ssb.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.text_color)), start, end,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
return ssb;
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.NotificationManager;
|
||||
@@ -38,12 +37,18 @@ import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.nextcloud.client.device.PowerManagementService;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.BuildConfig;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
@@ -86,6 +91,9 @@ import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS;
|
||||
import static com.owncloud.android.datamodel.SyncedFolderDisplayItem.UNPERSISTED_ID;
|
||||
@@ -101,18 +109,37 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
private static final String SYNCED_FOLDER_PREFERENCES_DIALOG_TAG = "SYNCED_FOLDER_PREFERENCES_DIALOG";
|
||||
private static final String TAG = SyncedFoldersActivity.class.getSimpleName();
|
||||
|
||||
private RecyclerView mRecyclerView;
|
||||
private SyncedFolderAdapter mAdapter;
|
||||
private LinearLayout mProgress;
|
||||
private TextView mEmpty;
|
||||
private SyncedFolderProvider mSyncedFolderProvider;
|
||||
private SyncedFolderPreferencesDialogFragment mSyncedFolderPreferencesDialogFragment;
|
||||
@BindView(R.id.empty_list_view)
|
||||
public LinearLayout emptyContentContainer;
|
||||
|
||||
@BindView(R.id.empty_list_icon)
|
||||
public ImageView emptyContentIcon;
|
||||
|
||||
@BindView(R.id.empty_list_progress)
|
||||
public ProgressBar emptyContentProgressBar;
|
||||
|
||||
@BindView(R.id.empty_list_view_headline)
|
||||
public TextView emptyContentHeadline;
|
||||
|
||||
@BindView(R.id.empty_list_view_text)
|
||||
public TextView emptyContentMessage;
|
||||
|
||||
@BindView(R.id.empty_list_view_action)
|
||||
public MaterialButton emptyContentActionButton;
|
||||
|
||||
@BindView(android.R.id.list)
|
||||
public RecyclerView mRecyclerView;
|
||||
|
||||
private SyncedFolderAdapter adapter;
|
||||
private SyncedFolderProvider syncedFolderProvider;
|
||||
private SyncedFolderPreferencesDialogFragment syncedFolderPreferencesDialogFragment;
|
||||
private boolean showSidebar = true;
|
||||
|
||||
private String path;
|
||||
private int type;
|
||||
@Inject AppPreferences preferences;
|
||||
@Inject PowerManagementService powerManagementService;
|
||||
@Inject Clock clock;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -123,16 +150,17 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
}
|
||||
|
||||
setContentView(R.layout.synced_folders_layout);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
String account;
|
||||
Account currentAccount;
|
||||
if (getIntent() != null && getIntent().getExtras() != null) {
|
||||
account = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT);
|
||||
currentAccount = getAccount();
|
||||
|
||||
if (account != null && currentAccount != null && !account.equalsIgnoreCase(currentAccount.name)) {
|
||||
accountManager.setCurrentOwnCloudAccount(account);
|
||||
setAccount(getUserAccountManager().getCurrentAccount());
|
||||
final String accountName = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT);
|
||||
Optional<User> optionalUser = getUser();
|
||||
if (optionalUser.isPresent() && accountName != null) {
|
||||
User user = optionalUser.get();
|
||||
if (!accountName.equalsIgnoreCase(user.getAccountName())) {
|
||||
accountManager.setCurrentOwnCloudAccount(accountName);
|
||||
setUser(getUserAccountManager().getUser());
|
||||
}
|
||||
}
|
||||
|
||||
path = getIntent().getStringExtra(MediaFoldersDetectionJob.KEY_MEDIA_FOLDER_PATH);
|
||||
@@ -175,7 +203,7 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.synced_folders_menu, menu);
|
||||
inflater.inflate(R.menu.activity_synced_folders, menu);
|
||||
|
||||
if (powerManagementService.isPowerSavingExclusionAvailable()) {
|
||||
MenuItem item = menu.findItem(R.id.action_disable_power_save_check);
|
||||
@@ -216,50 +244,56 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
* sets up the UI elements and loads all media/synced folders.
|
||||
*/
|
||||
private void setupContent() {
|
||||
mRecyclerView = findViewById(android.R.id.list);
|
||||
|
||||
mProgress = findViewById(android.R.id.progress);
|
||||
mEmpty = findViewById(android.R.id.empty);
|
||||
|
||||
final int gridWidth = getResources().getInteger(R.integer.media_grid_width);
|
||||
boolean lightVersion = getResources().getBoolean(R.bool.syncedFolder_light);
|
||||
mAdapter = new SyncedFolderAdapter(this, gridWidth, this, lightVersion);
|
||||
mSyncedFolderProvider = new SyncedFolderProvider(getContentResolver(), preferences);
|
||||
adapter = new SyncedFolderAdapter(this, clock, gridWidth, this, lightVersion);
|
||||
syncedFolderProvider = new SyncedFolderProvider(getContentResolver(), preferences, clock);
|
||||
emptyContentIcon.setImageResource(R.drawable.nav_synced_folders);
|
||||
emptyContentActionButton.setBackgroundColor(ThemeUtils.primaryColor(this));
|
||||
emptyContentActionButton.setTextColor(ThemeUtils.fontColor(this));
|
||||
|
||||
final GridLayoutManager lm = new GridLayoutManager(this, gridWidth);
|
||||
mAdapter.setLayoutManager(lm);
|
||||
adapter.setLayoutManager(lm);
|
||||
int spacing = getResources().getDimensionPixelSize(R.dimen.media_grid_spacing);
|
||||
mRecyclerView.addItemDecoration(new MediaGridItemDecoration(spacing));
|
||||
mRecyclerView.setLayoutManager(lm);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
|
||||
load(gridWidth * 2, false);
|
||||
}
|
||||
|
||||
@OnClick(R.id.empty_list_view_action)
|
||||
public void showHiddenItems() {
|
||||
if (adapter.getSectionCount() == 0 && adapter.getUnfilteredSectionCount() > adapter.getSectionCount()) {
|
||||
adapter.toggleHiddenItemsVisibility();
|
||||
emptyContentContainer.setVisibility(View.GONE);
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* loads all media/synced folders, adds them to the recycler view adapter and shows the list.
|
||||
*
|
||||
* @param perFolderMediaItemLimit the amount of media items to be loaded/shown per media folder
|
||||
*/
|
||||
private void load(final int perFolderMediaItemLimit, boolean force) {
|
||||
if (mAdapter.getItemCount() > 0 && !force) {
|
||||
if (adapter.getItemCount() > 0 && !force) {
|
||||
return;
|
||||
}
|
||||
setListShown(false);
|
||||
showLoadingContent();
|
||||
final List<MediaFolder> mediaFolders = MediaProvider.getImageFolders(getContentResolver(),
|
||||
perFolderMediaItemLimit, this, false);
|
||||
mediaFolders.addAll(MediaProvider.getVideoFolders(getContentResolver(), perFolderMediaItemLimit,
|
||||
this, false));
|
||||
|
||||
List<SyncedFolder> syncedFolderArrayList = mSyncedFolderProvider.getSyncedFolders();
|
||||
List<SyncedFolder> syncedFolderArrayList = syncedFolderProvider.getSyncedFolders();
|
||||
List<SyncedFolder> currentAccountSyncedFoldersList = new ArrayList<>();
|
||||
Account currentAccount = getUserAccountManager().getCurrentAccount();
|
||||
User user = getUserAccountManager().getUser();
|
||||
for (SyncedFolder syncedFolder : syncedFolderArrayList) {
|
||||
if (currentAccount != null && syncedFolder.getAccount().equals(currentAccount.name)) {
|
||||
|
||||
if (syncedFolder.getAccount().equals(user.getAccountName())) {
|
||||
// delete non-existing & disabled synced folders
|
||||
if (!new File(syncedFolder.getLocalPath()).exists() && !syncedFolder.isEnabled()) {
|
||||
mSyncedFolderProvider.deleteSyncedFolder(syncedFolder.getId());
|
||||
syncedFolderProvider.deleteSyncedFolder(syncedFolder.getId());
|
||||
} else {
|
||||
currentAccountSyncedFoldersList.add(syncedFolder);
|
||||
}
|
||||
@@ -269,14 +303,14 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
List<SyncedFolderDisplayItem> syncFolderItems = sortSyncedFolderItems(
|
||||
mergeFolderData(currentAccountSyncedFoldersList, mediaFolders));
|
||||
|
||||
mAdapter.setSyncFolderItems(syncFolderItems);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
setListShown(true);
|
||||
adapter.setSyncFolderItems(syncFolderItems);
|
||||
adapter.notifyDataSetChanged();
|
||||
showList();
|
||||
|
||||
if (!TextUtils.isEmpty(path)) {
|
||||
int section = mAdapter.getSectionByLocalPathAndType(path, type);
|
||||
int section = adapter.getSectionByLocalPathAndType(path, type);
|
||||
if (section >= 0) {
|
||||
onSyncFolderSettingsClick(section, mAdapter.get(section));
|
||||
onSyncFolderSettingsClick(section, adapter.get(section));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,16 +414,18 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
syncedFolder.getId(),
|
||||
syncedFolder.getLocalPath(),
|
||||
syncedFolder.getRemotePath(),
|
||||
syncedFolder.getWifiOnly(),
|
||||
syncedFolder.getChargingOnly(),
|
||||
syncedFolder.getSubfolderByDate(),
|
||||
syncedFolder.isWifiOnly(),
|
||||
syncedFolder.isChargingOnly(),
|
||||
syncedFolder.isSubfolderByDate(),
|
||||
syncedFolder.getAccount(),
|
||||
syncedFolder.getUploadAction(),
|
||||
syncedFolder.isEnabled(),
|
||||
clock.getCurrentTime(),
|
||||
filePaths,
|
||||
localFolder.getName(),
|
||||
files.length,
|
||||
syncedFolder.getType());
|
||||
syncedFolder.getType(),
|
||||
syncedFolder.isHidden());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -405,16 +441,18 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
syncedFolder.getId(),
|
||||
syncedFolder.getLocalPath(),
|
||||
syncedFolder.getRemotePath(),
|
||||
syncedFolder.getWifiOnly(),
|
||||
syncedFolder.getChargingOnly(),
|
||||
syncedFolder.getSubfolderByDate(),
|
||||
syncedFolder.isWifiOnly(),
|
||||
syncedFolder.isChargingOnly(),
|
||||
syncedFolder.isSubfolderByDate(),
|
||||
syncedFolder.getAccount(),
|
||||
syncedFolder.getUploadAction(),
|
||||
syncedFolder.isEnabled(),
|
||||
clock.getCurrentTime(),
|
||||
mediaFolder.filePaths,
|
||||
mediaFolder.folderName,
|
||||
mediaFolder.numberOfFiles,
|
||||
mediaFolder.type);
|
||||
mediaFolder.type,
|
||||
syncedFolder.isHidden());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -432,13 +470,15 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
getAccount().name,
|
||||
getAccount().name,
|
||||
FileUploader.LOCAL_BEHAVIOUR_FORGET,
|
||||
false,
|
||||
clock.getCurrentTime(),
|
||||
mediaFolder.filePaths,
|
||||
mediaFolder.folderName,
|
||||
mediaFolder.numberOfFiles,
|
||||
mediaFolder.type);
|
||||
mediaFolder.type,
|
||||
false);
|
||||
}
|
||||
|
||||
private File[] getFileList(File localFolder) {
|
||||
@@ -484,15 +524,35 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
}
|
||||
|
||||
/**
|
||||
* show/hide recycler view list or the empty message / progress info.
|
||||
*
|
||||
* @param shown flag if list should be shown
|
||||
* show recycler view list or the empty message info (in case list is empty).
|
||||
*/
|
||||
private void setListShown(boolean shown) {
|
||||
private void showList() {
|
||||
if (mRecyclerView != null) {
|
||||
mRecyclerView.setVisibility(shown ? View.VISIBLE : View.GONE);
|
||||
mProgress.setVisibility(shown ? View.GONE : View.VISIBLE);
|
||||
mEmpty.setVisibility(shown && mAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
emptyContentProgressBar.setVisibility(View.GONE);
|
||||
|
||||
checkAndShowEmptyListContent();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAndShowEmptyListContent() {
|
||||
if (adapter.getSectionCount() == 0 && adapter.getUnfilteredSectionCount() > adapter.getSectionCount()) {
|
||||
emptyContentContainer.setVisibility(View.VISIBLE);
|
||||
int hiddenFoldersCount = adapter.getHiddenFolderCount();
|
||||
|
||||
showEmptyContent(getString(R.string.drawer_synced_folders),
|
||||
getResources().getQuantityString(R.plurals.synced_folders_show_hidden_folders,
|
||||
hiddenFoldersCount,
|
||||
hiddenFoldersCount),
|
||||
getResources().getQuantityString(R.plurals.synced_folders_show_hidden_folders,
|
||||
hiddenFoldersCount,
|
||||
hiddenFoldersCount));
|
||||
} else if (adapter.getSectionCount() == 0 && adapter.getUnfilteredSectionCount() == 0) {
|
||||
emptyContentContainer.setVisibility(View.VISIBLE);
|
||||
showEmptyContent(getString(R.string.drawer_synced_folders),
|
||||
getString(R.string.synced_folders_no_results));
|
||||
} else {
|
||||
emptyContentContainer.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -518,8 +578,8 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
Log.d(TAG, "Show custom folder dialog");
|
||||
SyncedFolderDisplayItem emptyCustomFolder = new SyncedFolderDisplayItem(
|
||||
SyncedFolder.UNPERSISTED_ID, null, null, true, false,
|
||||
false, getAccount().name,
|
||||
FileUploader.LOCAL_BEHAVIOUR_FORGET, false, null, MediaFolderType.CUSTOM);
|
||||
false, getAccount().name, FileUploader.LOCAL_BEHAVIOUR_FORGET, false,
|
||||
clock.getCurrentTime(), null, MediaFolderType.CUSTOM, false);
|
||||
onSyncFolderSettingsClick(0, emptyCustomFolder);
|
||||
}
|
||||
|
||||
@@ -548,14 +608,11 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
|
||||
@Override
|
||||
public void onSyncStatusToggleClick(int section, SyncedFolderDisplayItem syncedFolderDisplayItem) {
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().
|
||||
getContentResolver());
|
||||
|
||||
if (syncedFolderDisplayItem.getId() > UNPERSISTED_ID) {
|
||||
mSyncedFolderProvider.updateSyncedFolderEnabled(syncedFolderDisplayItem.getId(),
|
||||
syncedFolderDisplayItem.isEnabled());
|
||||
syncedFolderProvider.updateSyncedFolderEnabled(syncedFolderDisplayItem.getId(),
|
||||
syncedFolderDisplayItem.isEnabled());
|
||||
} else {
|
||||
long storedId = mSyncedFolderProvider.storeSyncedFolder(syncedFolderDisplayItem);
|
||||
long storedId = syncedFolderProvider.storeSyncedFolder(syncedFolderDisplayItem);
|
||||
if (storedId != -1) {
|
||||
syncedFolderDisplayItem.setId(storedId);
|
||||
}
|
||||
@@ -565,9 +622,6 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolderDisplayItem);
|
||||
|
||||
showBatteryOptimizationInfo();
|
||||
} else {
|
||||
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + syncedFolderDisplayItem.getId();
|
||||
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -577,22 +631,72 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
FragmentTransaction ft = fm.beginTransaction();
|
||||
ft.addToBackStack(null);
|
||||
|
||||
mSyncedFolderPreferencesDialogFragment = SyncedFolderPreferencesDialogFragment.newInstance(
|
||||
syncedFolderPreferencesDialogFragment = SyncedFolderPreferencesDialogFragment.newInstance(
|
||||
syncedFolderDisplayItem, section);
|
||||
mSyncedFolderPreferencesDialogFragment.show(ft, SYNCED_FOLDER_PREFERENCES_DIALOG_TAG);
|
||||
syncedFolderPreferencesDialogFragment.show(ft, SYNCED_FOLDER_PREFERENCES_DIALOG_TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVisibilityToggleClick(int section, SyncedFolderDisplayItem syncedFolder) {
|
||||
syncedFolder.setHidden(!syncedFolder.isHidden());
|
||||
|
||||
saveOrUpdateSyncedFolder(syncedFolder);
|
||||
adapter.setSyncFolderItem(section, syncedFolder);
|
||||
|
||||
checkAndShowEmptyListContent();
|
||||
}
|
||||
|
||||
private void showEmptyContent(String headline, String message) {
|
||||
showEmptyContent(headline, message, false);
|
||||
emptyContentActionButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void showEmptyContent(String headline, String message, String action) {
|
||||
showEmptyContent(headline, message, false);
|
||||
emptyContentActionButton.setText(action);
|
||||
emptyContentActionButton.setVisibility(View.VISIBLE);
|
||||
emptyContentMessage.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void showLoadingContent() {
|
||||
showEmptyContent(
|
||||
getString(R.string.drawer_synced_folders),
|
||||
getString(R.string.synced_folders_loading_folders),
|
||||
true
|
||||
);
|
||||
emptyContentActionButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void showEmptyContent(String headline, String message, boolean loading) {
|
||||
if (emptyContentContainer != null) {
|
||||
emptyContentContainer.setVisibility(View.VISIBLE);
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
|
||||
emptyContentHeadline.setText(headline);
|
||||
emptyContentMessage.setText(message);
|
||||
emptyContentMessage.setVisibility(View.VISIBLE);
|
||||
|
||||
if (loading) {
|
||||
emptyContentProgressBar.setVisibility(View.VISIBLE);
|
||||
emptyContentIcon.setVisibility(View.GONE);
|
||||
} else {
|
||||
emptyContentProgressBar.setVisibility(View.GONE);
|
||||
emptyContentIcon.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_REMOTE_FOLDER
|
||||
&& resultCode == RESULT_OK && mSyncedFolderPreferencesDialogFragment != null) {
|
||||
&& resultCode == RESULT_OK && syncedFolderPreferencesDialogFragment != null) {
|
||||
OCFile chosenFolder = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
|
||||
mSyncedFolderPreferencesDialogFragment.setRemoteFolderSummary(chosenFolder.getRemotePath());
|
||||
syncedFolderPreferencesDialogFragment.setRemoteFolderSummary(chosenFolder.getRemotePath());
|
||||
}
|
||||
if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_LOCAL_FOLDER
|
||||
&& resultCode == RESULT_OK && mSyncedFolderPreferencesDialogFragment != null) {
|
||||
&& resultCode == RESULT_OK && syncedFolderPreferencesDialogFragment != null) {
|
||||
String localPath = data.getStringExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);
|
||||
mSyncedFolderPreferencesDialogFragment.setLocalFolderSummary(localPath);
|
||||
syncedFolderPreferencesDialogFragment.setLocalFolderSummary(localPath);
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
@@ -600,76 +704,80 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
|
||||
@Override
|
||||
public void onSaveSyncedFolderPreference(SyncedFolderParcelable syncedFolder) {
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().
|
||||
getContentResolver());
|
||||
|
||||
// custom folders newly created aren't in the list already,
|
||||
// so triggering a refresh
|
||||
if (MediaFolderType.CUSTOM == syncedFolder.getType() && syncedFolder.getId() == UNPERSISTED_ID) {
|
||||
SyncedFolderDisplayItem newCustomFolder = new SyncedFolderDisplayItem(
|
||||
SyncedFolder.UNPERSISTED_ID, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(),
|
||||
syncedFolder.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(),
|
||||
syncedFolder.getAccount(), syncedFolder.getUploadAction(), syncedFolder.getEnabled(),
|
||||
new File(syncedFolder.getLocalPath()).getName(), syncedFolder.getType());
|
||||
long storedId = mSyncedFolderProvider.storeSyncedFolder(newCustomFolder);
|
||||
if (storedId != -1) {
|
||||
newCustomFolder.setId(storedId);
|
||||
if (newCustomFolder.isEnabled()) {
|
||||
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(newCustomFolder);
|
||||
} else {
|
||||
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + newCustomFolder.getId();
|
||||
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
|
||||
}
|
||||
}
|
||||
mAdapter.addSyncFolderItem(newCustomFolder);
|
||||
syncedFolder.isWifiOnly(), syncedFolder.isChargingOnly(), syncedFolder.isSubfolderByDate(),
|
||||
syncedFolder.getAccount(), syncedFolder.getUploadAction(), syncedFolder.isEnabled(),
|
||||
clock.getCurrentTime(), new File(syncedFolder.getLocalPath()).getName(), syncedFolder.getType(), syncedFolder.isHidden());
|
||||
|
||||
saveOrUpdateSyncedFolder(newCustomFolder);
|
||||
adapter.addSyncFolderItem(newCustomFolder);
|
||||
} else {
|
||||
SyncedFolderDisplayItem item = mAdapter.get(syncedFolder.getSection());
|
||||
item = updateSyncedFolderItem(item, syncedFolder.getLocalPath(), syncedFolder.getRemotePath(), syncedFolder
|
||||
.getWifiOnly(), syncedFolder.getChargingOnly(), syncedFolder.getSubfolderByDate(), syncedFolder
|
||||
.getUploadAction(), syncedFolder.getEnabled());
|
||||
SyncedFolderDisplayItem item = adapter.get(syncedFolder.getSection());
|
||||
updateSyncedFolderItem(item, syncedFolder.getId(), syncedFolder.getLocalPath(),
|
||||
syncedFolder.getRemotePath(), syncedFolder
|
||||
.isWifiOnly(), syncedFolder.isChargingOnly(), syncedFolder.isSubfolderByDate(), syncedFolder
|
||||
.getUploadAction(), syncedFolder.isEnabled());
|
||||
|
||||
if (syncedFolder.getId() == UNPERSISTED_ID) {
|
||||
// newly set up folder sync config
|
||||
long storedId = mSyncedFolderProvider.storeSyncedFolder(item);
|
||||
if (storedId != -1) {
|
||||
item.setId(storedId);
|
||||
if (item.isEnabled()) {
|
||||
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
|
||||
} else {
|
||||
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId();
|
||||
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// existing synced folder setup to be updated
|
||||
mSyncedFolderProvider.updateSyncFolder(item);
|
||||
if (item.isEnabled()) {
|
||||
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
|
||||
} else {
|
||||
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId();
|
||||
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
|
||||
}
|
||||
}
|
||||
saveOrUpdateSyncedFolder(item);
|
||||
|
||||
mAdapter.setSyncFolderItem(syncedFolder.getSection(), item);
|
||||
// TODO test if notifiyItemChanged is suffiecient (should improve performance)
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
mSyncedFolderPreferencesDialogFragment = null;
|
||||
syncedFolderPreferencesDialogFragment = null;
|
||||
|
||||
if (syncedFolder.getEnabled()) {
|
||||
if (syncedFolder.isEnabled()) {
|
||||
showBatteryOptimizationInfo();
|
||||
}
|
||||
}
|
||||
|
||||
private void saveOrUpdateSyncedFolder(SyncedFolderDisplayItem item) {
|
||||
if (item.getId() == UNPERSISTED_ID) {
|
||||
// newly set up folder sync config
|
||||
storeSyncedFolder(item);
|
||||
} else {
|
||||
// existing synced folder setup to be updated
|
||||
syncedFolderProvider.updateSyncFolder(item);
|
||||
if (item.isEnabled()) {
|
||||
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
|
||||
} else {
|
||||
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId();
|
||||
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().
|
||||
getContentResolver());
|
||||
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void storeSyncedFolder(SyncedFolderDisplayItem item) {
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().
|
||||
getContentResolver());
|
||||
long storedId = syncedFolderProvider.storeSyncedFolder(item);
|
||||
if (storedId != -1) {
|
||||
item.setId(storedId);
|
||||
if (item.isEnabled()) {
|
||||
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(item);
|
||||
} else {
|
||||
String syncedFolderInitiatedKey = "syncedFolderIntitiated_" + item.getId();
|
||||
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelSyncedFolderPreference() {
|
||||
mSyncedFolderPreferencesDialogFragment = null;
|
||||
syncedFolderPreferencesDialogFragment = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteSyncedFolderPreference(SyncedFolderParcelable syncedFolder) {
|
||||
mSyncedFolderProvider.deleteSyncedFolder(syncedFolder.getId());
|
||||
mAdapter.removeItem(syncedFolder.getSection());
|
||||
syncedFolderProvider.deleteSyncedFolder(syncedFolder.getId());
|
||||
adapter.removeItem(syncedFolder.getSection());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -683,24 +791,24 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
* @param subfolderByDate created sub folders
|
||||
* @param uploadAction upload action
|
||||
* @param enabled is sync enabled
|
||||
* @return the updated item
|
||||
*/
|
||||
private SyncedFolderDisplayItem updateSyncedFolderItem(SyncedFolderDisplayItem item,
|
||||
private void updateSyncedFolderItem(SyncedFolderDisplayItem item,
|
||||
long id,
|
||||
String localPath,
|
||||
String remotePath,
|
||||
Boolean wifiOnly,
|
||||
Boolean chargingOnly,
|
||||
Boolean subfolderByDate,
|
||||
boolean wifiOnly,
|
||||
boolean chargingOnly,
|
||||
boolean subfolderByDate,
|
||||
Integer uploadAction,
|
||||
Boolean enabled) {
|
||||
boolean enabled) {
|
||||
item.setId(id);
|
||||
item.setLocalPath(localPath);
|
||||
item.setRemotePath(remotePath);
|
||||
item.setWifiOnly(wifiOnly);
|
||||
item.setChargingOnly(chargingOnly);
|
||||
item.setSubfolderByDate(subfolderByDate);
|
||||
item.setUploadAction(uploadAction);
|
||||
item.setEnabled(enabled);
|
||||
return item;
|
||||
item.setEnabled(enabled, clock.getCurrentTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -727,7 +835,6 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
setDrawerMenuItemChecked(R.id.nav_synced_folders);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Daniel Bailey
|
||||
* Copyright (C) 2019 Daniel Bailey
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or 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.owncloud.android.ui.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class ThemedPreferenceActivity extends PreferenceActivity {
|
||||
|
||||
/**
|
||||
* Tracks whether the activity should be recreate()'d after a theme change
|
||||
*/
|
||||
private boolean themeChangePending;
|
||||
private boolean paused;
|
||||
|
||||
@Inject AppPreferences preferences;
|
||||
|
||||
private AppPreferences.Listener onThemeChangedListener = new AppPreferences.Listener() {
|
||||
@Override
|
||||
public void onDarkThemeEnabledChanged(boolean enabled) {
|
||||
if(paused) {
|
||||
themeChangePending = true;
|
||||
return;
|
||||
}
|
||||
recreate();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
preferences.addListener(onThemeChangedListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
preferences.removeListener(onThemeChangedListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
paused = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
paused = false;
|
||||
|
||||
if(themeChangePending) {
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,6 @@ import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
@@ -92,7 +91,7 @@ public class UploadFilesActivity extends FileActivity implements
|
||||
private boolean mSelectAll;
|
||||
private boolean mLocalFolderPickerMode;
|
||||
private LocalFileListFragment mFileListFragment;
|
||||
protected Button mUploadBtn;
|
||||
protected MaterialButton mUploadBtn;
|
||||
private Spinner mBehaviourSpinner;
|
||||
private Account mAccountOnCreation;
|
||||
private DialogFragment mCurrentDialog;
|
||||
@@ -178,7 +177,8 @@ public class UploadFilesActivity extends FileActivity implements
|
||||
mCancelButton.setOnClickListener(this);
|
||||
|
||||
mUploadBtn = findViewById(R.id.upload_files_btn_upload);
|
||||
mUploadBtn.getBackground().setColorFilter(ThemeUtils.primaryColor(this, true), PorterDuff.Mode.SRC_ATOP);
|
||||
mUploadBtn.setBackgroundTintMode(PorterDuff.Mode.SRC_ATOP);
|
||||
mUploadBtn.setBackgroundTintList(ColorStateList.valueOf(ThemeUtils.primaryColor(this, true)));
|
||||
mUploadBtn.setOnClickListener(this);
|
||||
|
||||
int localBehaviour = preferences.getUploaderBehaviour();
|
||||
@@ -254,7 +254,7 @@ public class UploadFilesActivity extends FileActivity implements
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
mOptionsMenu = menu;
|
||||
getMenuInflater().inflate(R.menu.upload_files_picker, menu);
|
||||
getMenuInflater().inflate(R.menu.activity_upload_files, menu);
|
||||
|
||||
if(!mLocalFolderPickerMode) {
|
||||
MenuItem selectAll = menu.findItem(R.id.action_select_all);
|
||||
|
||||
@@ -43,9 +43,11 @@ import com.evernote.android.job.Job;
|
||||
import com.evernote.android.job.JobManager;
|
||||
import com.evernote.android.job.JobRequest;
|
||||
import com.evernote.android.job.util.support.PersistableBundleCompat;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.device.PowerManagementService;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.UploadsStorageManager;
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
@@ -230,9 +232,9 @@ public class UploadListActivity extends FileActivity {
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
ThemeUtils.setColoredTitle(getSupportActionBar(), R.string.uploads_view_title, this);
|
||||
final Account account = getAccount();
|
||||
if (account != null) {
|
||||
setAccountInDrawer(account);
|
||||
final Optional<User> optionalUser = getUser();
|
||||
if (optionalUser.isPresent()) {
|
||||
setAccountInDrawer(optionalUser.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +271,7 @@ public class UploadListActivity extends FileActivity {
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.upload_list_menu, menu);
|
||||
inflater.inflate(R.menu.activity_upload_list, menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.app.AlertDialog;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
@@ -135,9 +135,6 @@ public class UserInfoActivity extends FileActivity implements Injectable {
|
||||
setContentView(R.layout.user_info_layout);
|
||||
unbinder = ButterKnife.bind(this);
|
||||
|
||||
setAccount(getUserAccountManager().getCurrentAccount());
|
||||
onAccountSet();
|
||||
|
||||
boolean useBackgroundImage = URLUtil.isValidUrl(
|
||||
getStorageManager().getCapability(account.name).getServerBackground());
|
||||
|
||||
@@ -159,7 +156,7 @@ public class UserInfoActivity extends FileActivity implements Injectable {
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.user_info_menu, menu);
|
||||
inflater.inflate(R.menu.activity_user_info, menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ package com.owncloud.android.ui.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.PictureDrawable;
|
||||
import android.net.Uri;
|
||||
import android.text.Spannable;
|
||||
@@ -52,6 +51,7 @@ import com.bumptech.glide.load.model.StreamEncoder;
|
||||
import com.bumptech.glide.load.resource.file.FileToStreamDecoder;
|
||||
import com.caverock.androidsvg.SVG;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
@@ -95,6 +95,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
|
||||
protected Context context;
|
||||
private CurrentAccountProvider currentAccountProvider;
|
||||
private ClientFactory clientFactory;
|
||||
private FileDataStorageManager storageManager;
|
||||
private OCCapability capability;
|
||||
protected List<Object> values;
|
||||
@@ -247,8 +248,11 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
|
||||
if (MimeTypeUtil.isImageOrVideo(previewObject.getMimeType())) {
|
||||
int placeholder = R.drawable.file;
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider)).load(previewObject.getSource()).
|
||||
placeholder(placeholder).error(placeholder).into(imageView);
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider, clientFactory))
|
||||
.load(previewObject.getSource())
|
||||
.placeholder(placeholder)
|
||||
.error(placeholder)
|
||||
.into(imageView);
|
||||
} else {
|
||||
if (MimeTypeUtil.isFolder(previewObject.getMimeType())) {
|
||||
imageView.setImageDrawable(
|
||||
@@ -298,8 +302,10 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
String uri = client.getBaseUri() + "/index.php/apps/files/api/v1/thumbnail/" + px + "/" + px +
|
||||
Uri.encode(file.getRemotePath(), "/");
|
||||
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider)).load(uri).placeholder(placeholder)
|
||||
.error(placeholder).into(fileIcon); // using custom fetcher
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider, clientFactory))
|
||||
.load(uri).placeholder(placeholder)
|
||||
.error(placeholder)
|
||||
.into(fileIcon); // using custom fetcher
|
||||
|
||||
} else {
|
||||
if (isDetailView) {
|
||||
@@ -369,7 +375,12 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
}
|
||||
}, idx1, idx2, 0);
|
||||
ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), idx1, idx2, 0);
|
||||
ssb.setSpan(new ForegroundColorSpan(Color.BLACK), idx1, idx2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
ssb.setSpan(
|
||||
new ForegroundColorSpan(context.getResources().getColor(R.color.text_color)),
|
||||
idx1,
|
||||
idx2,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
);
|
||||
}
|
||||
idx1 = text.indexOf('{', idx2);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ package com.owncloud.android.ui.adapter;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -156,7 +155,7 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
||||
gridViewHolder.checkbox.setImageDrawable(ThemeUtils.tintDrawable(R.drawable.ic_checkbox_marked,
|
||||
ThemeUtils.primaryColor(mContext)));
|
||||
} else {
|
||||
gridViewHolder.itemLayout.setBackgroundColor(Color.WHITE);
|
||||
gridViewHolder.itemLayout.setBackgroundColor(mContext.getResources().getColor(R.color.bg_default));
|
||||
gridViewHolder.checkbox.setImageResource(R.drawable.ic_checkbox_blank_outline);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,6 @@ package com.owncloud.android.ui.adapter;
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
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;
|
||||
@@ -77,7 +75,7 @@ import butterknife.ButterKnife;
|
||||
public class NotificationListAdapter extends RecyclerView.Adapter<NotificationListAdapter.NotificationViewHolder> {
|
||||
private static final String FILE = "file";
|
||||
private StyleSpan styleSpanBold = new StyleSpan(Typeface.BOLD);
|
||||
private ForegroundColorSpan foregroundColorSpanBlack = new ForegroundColorSpan(Color.BLACK);
|
||||
private ForegroundColorSpan foregroundColorSpanBlack;
|
||||
|
||||
private List<Notification> notificationsList;
|
||||
private OwnCloudClient client;
|
||||
@@ -87,6 +85,8 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
||||
this.notificationsList = new ArrayList<>();
|
||||
this.client = client;
|
||||
this.notificationsActivity = notificationsActivity;
|
||||
foregroundColorSpanBlack = new ForegroundColorSpan(
|
||||
notificationsActivity.getResources().getColor(R.color.text_color));
|
||||
}
|
||||
|
||||
public void setNotificationItems(List<Notification> notificationItems) {
|
||||
@@ -140,14 +140,24 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
||||
downloadIcon(notification.getIcon(), holder.icon);
|
||||
}
|
||||
|
||||
setButtons(holder, notification);
|
||||
|
||||
holder.dismiss.setOnClickListener(v -> new DeleteNotificationTask(client, notification, holder,
|
||||
notificationsActivity).execute());
|
||||
}
|
||||
|
||||
public void setButtons(NotificationViewHolder holder, Notification notification) {
|
||||
// add action buttons
|
||||
holder.buttons.removeAllViews();
|
||||
MaterialButton button;
|
||||
|
||||
Resources resources = notificationsActivity.getResources();
|
||||
NotificationExecuteActionTask task = new NotificationExecuteActionTask(client, holder, notificationsActivity);
|
||||
NotificationExecuteActionTask task = new NotificationExecuteActionTask(client,
|
||||
holder,
|
||||
notification,
|
||||
notificationsActivity);
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
params.setMargins(20, 0, 20, 0);
|
||||
|
||||
for (Action action : notification.getActions()) {
|
||||
@@ -156,15 +166,14 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
||||
int primaryColor = ThemeUtils.primaryColor(notificationsActivity);
|
||||
|
||||
if (action.primary) {
|
||||
button.getBackground().setColorFilter(primaryColor, PorterDuff.Mode.SRC_ATOP);
|
||||
button.setBackgroundColor(primaryColor);
|
||||
button.setTextColor(ThemeUtils.fontColor(notificationsActivity));
|
||||
button.setTypeface(button.getTypeface(), Typeface.BOLD);
|
||||
} else {
|
||||
button.setStrokeColor(ColorStateList.valueOf(resources.getColor(R.color.grey_200)));
|
||||
button.setStrokeWidth(3);
|
||||
|
||||
button.getBackground().setColorFilter(resources.getColor(R.color.transparent),
|
||||
PorterDuff.Mode.SRC_ATOP);
|
||||
button.setBackgroundColor(resources.getColor(R.color.transparent));
|
||||
button.setTextColor(primaryColor);
|
||||
button.setTypeface(button.getTypeface(), Typeface.BOLD);
|
||||
}
|
||||
@@ -184,9 +193,6 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
||||
|
||||
holder.buttons.addView(button);
|
||||
}
|
||||
|
||||
holder.dismiss.setOnClickListener(v -> new DeleteNotificationTask(client, notification, holder,
|
||||
notificationsActivity).execute());
|
||||
}
|
||||
|
||||
private SpannableStringBuilder makeSpecialPartsBold(Notification notification) {
|
||||
|
||||
@@ -30,7 +30,6 @@ import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
@@ -48,6 +47,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.target.BitmapImageViewTarget;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.R;
|
||||
@@ -118,7 +118,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
private Set<OCFile> checkedFiles;
|
||||
|
||||
private FileDataStorageManager mStorageManager;
|
||||
private Account account;
|
||||
private User user;
|
||||
private OCFileListFragmentInterface ocFileListFragmentInterface;
|
||||
|
||||
private FilesFilter mFilesFilter;
|
||||
@@ -136,7 +136,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
|
||||
public OCFileListAdapter(
|
||||
Context context,
|
||||
Account account,
|
||||
User user,
|
||||
AppPreferences preferences,
|
||||
UserAccountManager accountManager,
|
||||
ComponentsGetter transferServiceGetter,
|
||||
@@ -148,16 +148,16 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
mContext = context;
|
||||
this.preferences = preferences;
|
||||
this.accountManager = accountManager;
|
||||
this.account = account;
|
||||
this.user = user;
|
||||
mHideItemOptions = argHideItemOptions;
|
||||
this.gridView = gridView;
|
||||
checkedFiles = new HashSet<>();
|
||||
|
||||
this.transferServiceGetter = transferServiceGetter;
|
||||
|
||||
if (account != null) {
|
||||
if (this.user != null) {
|
||||
AccountManager platformAccountManager = AccountManager.get(mContext);
|
||||
userId = platformAccountManager.getUserData(account,
|
||||
userId = platformAccountManager.getUserData(this.user.toPlatformAccount(),
|
||||
com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);
|
||||
} else {
|
||||
userId = "";
|
||||
@@ -330,7 +330,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
gridViewHolder.checkbox.setImageDrawable(ThemeUtils.tintDrawable(R.drawable.ic_checkbox_marked,
|
||||
ThemeUtils.primaryColor(mContext)));
|
||||
} else {
|
||||
gridViewHolder.itemLayout.setBackgroundColor(Color.WHITE);
|
||||
gridViewHolder.itemLayout.setBackgroundColor(mContext.getResources().getColor(R.color.bg_default));
|
||||
gridViewHolder.checkbox.setImageResource(R.drawable.ic_checkbox_blank_outline);
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
showFederatedShareAvatar(sharee.getUserId(), avatarRadius, resources, avatar);
|
||||
} else {
|
||||
avatar.setTag(sharee);
|
||||
DisplayUtils.setAvatar(account,
|
||||
DisplayUtils.setAvatar(user.toPlatformAccount(),
|
||||
sharee.getUserId(),
|
||||
sharee.getDisplayName(),
|
||||
this,
|
||||
@@ -461,17 +461,17 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
OperationsService.OperationsServiceBinder operationsServiceBinder = transferServiceGetter.getOperationsServiceBinder();
|
||||
FileDownloader.FileDownloaderBinder fileDownloaderBinder = transferServiceGetter.getFileDownloaderBinder();
|
||||
FileUploader.FileUploaderBinder fileUploaderBinder = transferServiceGetter.getFileUploaderBinder();
|
||||
if (operationsServiceBinder != null && operationsServiceBinder.isSynchronizing(account, file)) {
|
||||
if (operationsServiceBinder != null && operationsServiceBinder.isSynchronizing(user.toPlatformAccount(), file)) {
|
||||
//synchronizing
|
||||
gridViewHolder.localFileIndicator.setImageResource(R.drawable.ic_synchronizing);
|
||||
gridViewHolder.localFileIndicator.setVisibility(View.VISIBLE);
|
||||
|
||||
} else if (fileDownloaderBinder != null && fileDownloaderBinder.isDownloading(account, file)) {
|
||||
} else if (fileDownloaderBinder != null && fileDownloaderBinder.isDownloading(user.toPlatformAccount(), file)) {
|
||||
// downloading
|
||||
gridViewHolder.localFileIndicator.setImageResource(R.drawable.ic_synchronizing);
|
||||
gridViewHolder.localFileIndicator.setVisibility(View.VISIBLE);
|
||||
|
||||
} else if (fileUploaderBinder != null && fileUploaderBinder.isUploading(account, file)) {
|
||||
} else if (fileUploaderBinder != null && fileUploaderBinder.isUploading(user.toPlatformAccount(), file)) {
|
||||
//uploading
|
||||
gridViewHolder.localFileIndicator.setImageResource(R.drawable.ic_synchronizing);
|
||||
gridViewHolder.localFileIndicator.setVisibility(View.VISIBLE);
|
||||
@@ -576,13 +576,17 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
if (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, thumbnailView)) {
|
||||
try {
|
||||
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
||||
new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView, mStorageManager,
|
||||
account, asyncTasks);
|
||||
new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView,
|
||||
mStorageManager,
|
||||
user.toPlatformAccount(),
|
||||
asyncTasks);
|
||||
|
||||
if (thumbnail == null) {
|
||||
thumbnail = BitmapUtils.drawableToBitmap(
|
||||
MimeTypeUtil.getFileTypeIcon(file.getMimeType(), file.getFileName(),
|
||||
account, mContext));
|
||||
MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
|
||||
file.getFileName(),
|
||||
user.toPlatformAccount(),
|
||||
mContext));
|
||||
}
|
||||
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
|
||||
new ThumbnailsCacheManager.AsyncThumbnailDrawable(mContext.getResources(),
|
||||
@@ -598,12 +602,12 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
}
|
||||
|
||||
if ("image/png".equalsIgnoreCase(file.getMimeType())) {
|
||||
thumbnailView.setBackgroundColor(mContext.getResources().getColor(R.color.background_color));
|
||||
thumbnailView.setBackgroundColor(mContext.getResources().getColor(R.color.bg_default));
|
||||
}
|
||||
} else {
|
||||
thumbnailView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
|
||||
file.getFileName(),
|
||||
account,
|
||||
user.toPlatformAccount(),
|
||||
mContext));
|
||||
}
|
||||
}
|
||||
@@ -686,7 +690,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
sharedIconView.setImageResource(R.drawable.ic_unshared);
|
||||
sharedIconView.setContentDescription(mContext.getString(R.string.shared_icon_share));
|
||||
}
|
||||
if (accountManager.accountOwnsFile(file, account)) {
|
||||
if (accountManager.accountOwnsFile(file, user.toPlatformAccount())) {
|
||||
sharedIconView.setOnClickListener(view -> ocFileListFragmentInterface.onShareIconClick(file));
|
||||
} else {
|
||||
sharedIconView.setOnClickListener(view -> ocFileListFragmentInterface.showShareDetailView(file));
|
||||
@@ -704,7 +708,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
* @param limitToMimeType show only files of this mimeType
|
||||
*/
|
||||
public void swapDirectory(
|
||||
Account account,
|
||||
User account,
|
||||
OCFile directory,
|
||||
FileDataStorageManager updatedStorageManager,
|
||||
boolean onlyOnDevice, String limitToMimeType
|
||||
@@ -713,8 +717,8 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
|
||||
if (updatedStorageManager != null && !updatedStorageManager.equals(mStorageManager)) {
|
||||
mStorageManager = updatedStorageManager;
|
||||
showShareAvatar = mStorageManager.getCapability(account.name).getVersion().isShareesOnDavSupported();
|
||||
this.account = account;
|
||||
showShareAvatar = mStorageManager.getCapability(account.getAccountName()).getVersion().isShareesOnDavSupported();
|
||||
this.user = account;
|
||||
}
|
||||
if (mStorageManager != null) {
|
||||
mFiles = mStorageManager.getFolderContent(directory, onlyOnDevice);
|
||||
@@ -745,11 +749,11 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
FileDataStorageManager storageManager, OCFile folder, boolean clear) {
|
||||
if (storageManager != null && mStorageManager == null) {
|
||||
mStorageManager = storageManager;
|
||||
showShareAvatar = mStorageManager.getCapability(account.name).getVersion().isShareesOnDavSupported();
|
||||
showShareAvatar = mStorageManager.getCapability(user.getAccountName()).getVersion().isShareesOnDavSupported();
|
||||
}
|
||||
|
||||
if (mStorageManager == null) {
|
||||
mStorageManager = new FileDataStorageManager(account, mContext.getContentResolver());
|
||||
mStorageManager = new FileDataStorageManager(user.toPlatformAccount(), mContext.getContentResolver());
|
||||
}
|
||||
|
||||
if (clear) {
|
||||
@@ -809,12 +813,12 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
shares.add(ocShare);
|
||||
|
||||
// get ocFile from Server to have an up-to-date copy
|
||||
RemoteOperationResult result = new ReadFileRemoteOperation(ocShare.getPath()).execute(account,
|
||||
RemoteOperationResult result = new ReadFileRemoteOperation(ocShare.getPath()).execute(user.toPlatformAccount(),
|
||||
mContext);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
OCFile file = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
|
||||
FileStorageUtils.searchForLocalFileInDefaultPath(file, account);
|
||||
FileStorageUtils.searchForLocalFileInDefaultPath(file, user.toPlatformAccount());
|
||||
file = mStorageManager.saveFileWithParent(file, mContext);
|
||||
|
||||
ShareType newShareType = ocShare.getShareType();
|
||||
@@ -869,7 +873,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
|
||||
for (Object remoteFile : objects) {
|
||||
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) remoteFile);
|
||||
FileStorageUtils.searchForLocalFileInDefaultPath(ocFile, account);
|
||||
FileStorageUtils.searchForLocalFileInDefaultPath(ocFile, user.toPlatformAccount());
|
||||
|
||||
try {
|
||||
if (ExtendedListFragment.SearchType.PHOTO_SEARCH == searchType) {
|
||||
@@ -886,9 +890,9 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
true,
|
||||
false,
|
||||
mStorageManager,
|
||||
account,
|
||||
user.toPlatformAccount(),
|
||||
mContext);
|
||||
refreshFolderOperation.execute(account, mContext);
|
||||
refreshFolderOperation.execute(user.toPlatformAccount(), mContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,16 +23,20 @@ package com.owncloud.android.ui.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.afollestad.sectionedrecyclerview.SectionedRecyclerViewAdapter;
|
||||
import com.afollestad.sectionedrecyclerview.SectionedViewHolder;
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.MediaFolderType;
|
||||
import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
|
||||
@@ -53,62 +57,174 @@ import butterknife.ButterKnife;
|
||||
*/
|
||||
public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter<SectionedViewHolder> {
|
||||
|
||||
private final Context mContext;
|
||||
private final int mGridWidth;
|
||||
private final int mGridTotal;
|
||||
private final ClickListener mListener;
|
||||
private final List<SyncedFolderDisplayItem> mSyncFolderItems;
|
||||
private final boolean mLight;
|
||||
private final Context context;
|
||||
private final Clock clock;
|
||||
private final int gridWidth;
|
||||
private final int gridTotal;
|
||||
private final ClickListener clickListener;
|
||||
private final List<SyncedFolderDisplayItem> syncFolderItems;
|
||||
private final List<SyncedFolderDisplayItem> filteredSyncFolderItems;
|
||||
private final boolean light;
|
||||
private final int VIEW_TYPE_EMPTY = Integer.MAX_VALUE;
|
||||
private boolean hideItems;
|
||||
|
||||
public SyncedFolderAdapter(Context context, int gridWidth, ClickListener listener, boolean light) {
|
||||
mContext = context;
|
||||
mGridWidth = gridWidth;
|
||||
mGridTotal = gridWidth * 2;
|
||||
mListener = listener;
|
||||
mSyncFolderItems = new ArrayList<>();
|
||||
mLight = light;
|
||||
public SyncedFolderAdapter(Context context, Clock clock, int gridWidth, ClickListener listener, boolean light) {
|
||||
this.context = context;
|
||||
this.clock = clock;
|
||||
this.gridWidth = gridWidth;
|
||||
gridTotal = gridWidth * 2;
|
||||
clickListener = listener;
|
||||
syncFolderItems = new ArrayList<>();
|
||||
filteredSyncFolderItems = new ArrayList<>();
|
||||
this.light = light;
|
||||
this.hideItems = true;
|
||||
|
||||
shouldShowHeadersForEmptySections(true);
|
||||
shouldShowFooters(true);
|
||||
}
|
||||
|
||||
public void toggleHiddenItemsVisibility() {
|
||||
hideItems = !hideItems;
|
||||
filteredSyncFolderItems.clear();
|
||||
filteredSyncFolderItems.addAll(filterHiddenItems(syncFolderItems, hideItems));
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setSyncFolderItems(List<SyncedFolderDisplayItem> syncFolderItems) {
|
||||
mSyncFolderItems.clear();
|
||||
mSyncFolderItems.addAll(syncFolderItems);
|
||||
this.syncFolderItems.clear();
|
||||
this.syncFolderItems.addAll(syncFolderItems);
|
||||
|
||||
this.filteredSyncFolderItems.clear();
|
||||
this.filteredSyncFolderItems.addAll(filterHiddenItems(this.syncFolderItems, hideItems));
|
||||
}
|
||||
|
||||
public void setSyncFolderItem(int location, SyncedFolderDisplayItem syncFolderItem) {
|
||||
mSyncFolderItems.set(location, syncFolderItem);
|
||||
if (hideItems && syncFolderItem.isHidden() && filteredSyncFolderItems.contains(syncFolderItem)) {
|
||||
filteredSyncFolderItems.remove(location);
|
||||
} else {
|
||||
if (filteredSyncFolderItems.contains(syncFolderItem)) {
|
||||
filteredSyncFolderItems.set(filteredSyncFolderItems.indexOf(syncFolderItem), syncFolderItem);
|
||||
} else {
|
||||
filteredSyncFolderItems.add(syncFolderItem);
|
||||
}
|
||||
}
|
||||
|
||||
if (syncFolderItems.contains(syncFolderItem)) {
|
||||
syncFolderItems.set(syncFolderItems.indexOf(syncFolderItem), syncFolderItem);
|
||||
} else {
|
||||
syncFolderItems.add(syncFolderItem);
|
||||
}
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void addSyncFolderItem(SyncedFolderDisplayItem syncFolderItem) {
|
||||
mSyncFolderItems.add(syncFolderItem);
|
||||
notifyDataSetChanged();
|
||||
syncFolderItems.add(syncFolderItem);
|
||||
|
||||
// add item for display when either all items should be shown (!hideItems)
|
||||
// or if item should be shown (!.isHidden())
|
||||
if (!hideItems || !syncFolderItem.isHidden()) {
|
||||
filteredSyncFolderItems.add(syncFolderItem);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeItem(int section) {
|
||||
mSyncFolderItems.remove(section);
|
||||
notifyDataSetChanged();
|
||||
if (filteredSyncFolderItems.contains(syncFolderItems.get(section))) {
|
||||
filteredSyncFolderItems.remove(syncFolderItems.get(section));
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
syncFolderItems.remove(section);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter for hidden items
|
||||
*
|
||||
* @param items Collection of items to filter
|
||||
* @return Non-hidden items
|
||||
*/
|
||||
private List<SyncedFolderDisplayItem> filterHiddenItems(List<SyncedFolderDisplayItem> items, boolean hide) {
|
||||
if (!hide) {
|
||||
return items;
|
||||
} else {
|
||||
List<SyncedFolderDisplayItem> result = new ArrayList<>();
|
||||
|
||||
for (SyncedFolderDisplayItem item : items) {
|
||||
if (!item.isHidden() && !result.contains(item)) {
|
||||
result.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSectionCount() {
|
||||
return mSyncFolderItems.size();
|
||||
if (filteredSyncFolderItems.size() > 0) {
|
||||
return filteredSyncFolderItems.size() + 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int getUnfilteredSectionCount() {
|
||||
if (syncFolderItems.size() > 0) {
|
||||
return syncFolderItems.size() + 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount(int section) {
|
||||
List<String> filePaths = mSyncFolderItems.get(section).getFilePaths();
|
||||
if (section < filteredSyncFolderItems.size()) {
|
||||
List<String> filePaths = filteredSyncFolderItems.get(section).getFilePaths();
|
||||
|
||||
if (filePaths != null) {
|
||||
return mSyncFolderItems.get(section).getFilePaths().size();
|
||||
if (filePaths != null) {
|
||||
return filteredSyncFolderItems.get(section).getFilePaths().size();
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public SyncedFolderDisplayItem get(int section) {
|
||||
return mSyncFolderItems.get(section);
|
||||
return filteredSyncFolderItems.get(section);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int section, int relativePosition, int absolutePosition) {
|
||||
if (isLastSection(section)) {
|
||||
return VIEW_TYPE_EMPTY;
|
||||
} else {
|
||||
return VIEW_TYPE_ITEM;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeaderViewType(int section) {
|
||||
if (isLastSection(section)) {
|
||||
return VIEW_TYPE_EMPTY;
|
||||
} else {
|
||||
return VIEW_TYPE_HEADER;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFooterViewType(int section) {
|
||||
if (isLastSection(section) && showFooter()) {
|
||||
return VIEW_TYPE_FOOTER;
|
||||
} else {
|
||||
// only show footer after last item and only if folders have been hidden
|
||||
return VIEW_TYPE_EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean showFooter() {
|
||||
return syncFolderItems.size() > filteredSyncFolderItems.size();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,9 +235,9 @@ public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter<SectionedV
|
||||
* @return the section index of the looked up synced folder, <code>-1</code> if not present
|
||||
*/
|
||||
public int getSectionByLocalPathAndType(String localPath, int type) {
|
||||
for (int i = 0; i < mSyncFolderItems.size(); i++) {
|
||||
if (mSyncFolderItems.get(i).getLocalPath().equalsIgnoreCase(localPath) &&
|
||||
mSyncFolderItems.get(i).getType().getId().equals(type)) {
|
||||
for (int i = 0; i < filteredSyncFolderItems.size(); i++) {
|
||||
if (filteredSyncFolderItems.get(i).getLocalPath().equalsIgnoreCase(localPath) &&
|
||||
filteredSyncFolderItems.get(i).getType().getId().equals(type)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -131,70 +247,96 @@ public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter<SectionedV
|
||||
|
||||
@Override
|
||||
public void onBindHeaderViewHolder(SectionedViewHolder commonHolder, final int section, boolean expanded) {
|
||||
HeaderViewHolder holder = (HeaderViewHolder) commonHolder;
|
||||
if (section < filteredSyncFolderItems.size()) {
|
||||
HeaderViewHolder holder = (HeaderViewHolder) commonHolder;
|
||||
holder.mainHeaderContainer.setVisibility(View.VISIBLE);
|
||||
|
||||
holder.mainHeaderContainer.setVisibility(View.VISIBLE);
|
||||
holder.title.setText(filteredSyncFolderItems.get(section).getFolderName());
|
||||
|
||||
holder.title.setText(mSyncFolderItems.get(section).getFolderName());
|
||||
if (MediaFolderType.VIDEO == filteredSyncFolderItems.get(section).getType()) {
|
||||
holder.type.setImageResource(R.drawable.video_32dp);
|
||||
} else if (MediaFolderType.IMAGE == filteredSyncFolderItems.get(section).getType()) {
|
||||
holder.type.setImageResource(R.drawable.image_32dp);
|
||||
} else {
|
||||
holder.type.setImageResource(R.drawable.folder_star_32dp);
|
||||
}
|
||||
|
||||
if (MediaFolderType.VIDEO == mSyncFolderItems.get(section).getType()) {
|
||||
holder.type.setImageResource(R.drawable.video_32dp);
|
||||
} else if (MediaFolderType.IMAGE == mSyncFolderItems.get(section).getType()) {
|
||||
holder.type.setImageResource(R.drawable.image_32dp);
|
||||
} else {
|
||||
holder.type.setImageResource(R.drawable.folder_star_32dp);
|
||||
holder.syncStatusButton.setVisibility(View.VISIBLE);
|
||||
holder.syncStatusButton.setTag(section);
|
||||
holder.syncStatusButton.setOnClickListener(v -> {
|
||||
filteredSyncFolderItems.get(section).setEnabled(
|
||||
!filteredSyncFolderItems.get(section).isEnabled(),
|
||||
clock.getCurrentTime()
|
||||
);
|
||||
setSyncButtonActiveIcon(holder.syncStatusButton, filteredSyncFolderItems.get(section).isEnabled());
|
||||
clickListener.onSyncStatusToggleClick(section, filteredSyncFolderItems.get(section));
|
||||
});
|
||||
setSyncButtonActiveIcon(holder.syncStatusButton, filteredSyncFolderItems.get(section).isEnabled());
|
||||
|
||||
if (light) {
|
||||
holder.menuButton.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.menuButton.setVisibility(View.VISIBLE);
|
||||
holder.menuButton.setTag(section);
|
||||
holder.menuButton.setOnClickListener(v -> onOverflowIconClicked(section,
|
||||
filteredSyncFolderItems.get(section),
|
||||
v));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
holder.syncStatusButton.setVisibility(View.VISIBLE);
|
||||
holder.syncStatusButton.setTag(section);
|
||||
holder.syncStatusButton.setOnClickListener(v -> {
|
||||
mSyncFolderItems.get(section).setEnabled(!mSyncFolderItems.get(section).isEnabled());
|
||||
setSyncButtonActiveIcon(holder.syncStatusButton, mSyncFolderItems.get(section).isEnabled());
|
||||
mListener.onSyncStatusToggleClick(section, mSyncFolderItems.get(section));
|
||||
});
|
||||
setSyncButtonActiveIcon(holder.syncStatusButton, mSyncFolderItems.get(section).isEnabled());
|
||||
private void onOverflowIconClicked(int section, SyncedFolderDisplayItem item, View view) {
|
||||
PopupMenu popup = new PopupMenu(context, view);
|
||||
popup.inflate(R.menu.synced_folders_adapter);
|
||||
popup.setOnMenuItemClickListener(i -> optionsItemSelected(i, section, item));
|
||||
popup.getMenu()
|
||||
.findItem(R.id.action_auto_upload_folder_toggle_visibility)
|
||||
.setChecked(item.isHidden());
|
||||
|
||||
holder.syncStatusButton.setVisibility(View.VISIBLE);
|
||||
holder.syncStatusButton.setTag(section);
|
||||
holder.syncStatusButton.setOnClickListener(v -> {
|
||||
mSyncFolderItems.get(section).setEnabled(!mSyncFolderItems.get(section).isEnabled());
|
||||
setSyncButtonActiveIcon(holder.syncStatusButton, mSyncFolderItems.get(section).isEnabled());
|
||||
mListener.onSyncStatusToggleClick(section, mSyncFolderItems.get(section));
|
||||
});
|
||||
setSyncButtonActiveIcon(holder.syncStatusButton, mSyncFolderItems.get(section).isEnabled());
|
||||
popup.show();
|
||||
}
|
||||
|
||||
if (mLight) {
|
||||
holder.menuButton.setVisibility(View.GONE);
|
||||
private boolean optionsItemSelected(MenuItem menuItem, int section, SyncedFolderDisplayItem item) {
|
||||
if (menuItem.getItemId() == R.id.action_auto_upload_folder_toggle_visibility) {
|
||||
clickListener.onVisibilityToggleClick(section, item);
|
||||
} else {
|
||||
holder.menuButton.setVisibility(View.VISIBLE);
|
||||
holder.menuButton.setTag(section);
|
||||
holder.menuButton.setOnClickListener(v -> mListener.onSyncFolderSettingsClick(section,
|
||||
mSyncFolderItems.get(section)));
|
||||
// default: R.id.action_create_custom_folder
|
||||
clickListener.onSyncFolderSettingsClick(section, item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindFooterViewHolder(SectionedViewHolder holder, int section) {
|
||||
// not needed
|
||||
if (isLastSection(section) && showFooter()) {
|
||||
FooterViewHolder footerHolder = (FooterViewHolder) holder;
|
||||
footerHolder.title.setOnClickListener(v -> toggleHiddenItemsVisibility());
|
||||
footerHolder.title.setText(
|
||||
context.getResources().getQuantityString(
|
||||
R.plurals.synced_folders_show_hidden_folders,
|
||||
getHiddenFolderCount(),
|
||||
getHiddenFolderCount()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(SectionedViewHolder commonHolder, int section, int relativePosition,
|
||||
int absolutePosition) {
|
||||
if (mSyncFolderItems.get(section).getFilePaths() != null) {
|
||||
if (section < filteredSyncFolderItems.size() && filteredSyncFolderItems.get(section).getFilePaths() != null) {
|
||||
MainViewHolder holder = (MainViewHolder) commonHolder;
|
||||
|
||||
File file = new File(mSyncFolderItems.get(section).getFilePaths().get(relativePosition));
|
||||
File file = new File(filteredSyncFolderItems.get(section).getFilePaths().get(relativePosition));
|
||||
|
||||
ThumbnailsCacheManager.MediaThumbnailGenerationTask task =
|
||||
new ThumbnailsCacheManager.MediaThumbnailGenerationTask(holder.image, mContext);
|
||||
new ThumbnailsCacheManager.MediaThumbnailGenerationTask(holder.image, context);
|
||||
|
||||
ThumbnailsCacheManager.AsyncMediaThumbnailDrawable asyncDrawable =
|
||||
new ThumbnailsCacheManager.AsyncMediaThumbnailDrawable(
|
||||
mContext.getResources(),
|
||||
ThumbnailsCacheManager.mDefaultImg,
|
||||
task
|
||||
context.getResources(),
|
||||
ThumbnailsCacheManager.mDefaultImg,
|
||||
task
|
||||
);
|
||||
holder.image.setImageDrawable(asyncDrawable);
|
||||
|
||||
@@ -203,11 +345,11 @@ public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter<SectionedV
|
||||
// set proper tag
|
||||
holder.image.setTag(file.hashCode());
|
||||
|
||||
holder.itemView.setTag(relativePosition % mGridWidth);
|
||||
holder.itemView.setTag(relativePosition % gridWidth);
|
||||
|
||||
if (mSyncFolderItems.get(section).getNumberOfFiles() > mGridTotal && relativePosition >= mGridTotal - 1) {
|
||||
if (filteredSyncFolderItems.get(section).getNumberOfFiles() > gridTotal && relativePosition >= gridTotal - 1) {
|
||||
holder.counterValue.setText(String.format(Locale.US, "%d",
|
||||
mSyncFolderItems.get(section).getNumberOfFiles() - mGridTotal));
|
||||
filteredSyncFolderItems.get(section).getNumberOfFiles() - gridTotal));
|
||||
holder.counterBar.setVisibility(View.VISIBLE);
|
||||
holder.thumbnailDarkener.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
@@ -223,15 +365,34 @@ public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter<SectionedV
|
||||
if (viewType == VIEW_TYPE_HEADER) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.synced_folders_item_header, parent, false);
|
||||
return new HeaderViewHolder(v);
|
||||
} else if (viewType == VIEW_TYPE_FOOTER) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.synced_folders_footer, parent, false);
|
||||
return new FooterViewHolder(v);
|
||||
} else if (viewType == VIEW_TYPE_EMPTY) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.synced_folders_empty, parent, false);
|
||||
return new EmptyViewHolder(v);
|
||||
} else {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_sync_item, parent, false);
|
||||
return new MainViewHolder(v);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLastSection(int section) {
|
||||
return section >= getSectionCount() - 1;
|
||||
}
|
||||
|
||||
public int getHiddenFolderCount() {
|
||||
if (syncFolderItems != null && filteredSyncFolderItems != null) {
|
||||
return syncFolderItems.size() - filteredSyncFolderItems.size();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public interface ClickListener {
|
||||
void onSyncStatusToggleClick(int section, SyncedFolderDisplayItem syncedFolderDisplayItem);
|
||||
void onSyncFolderSettingsClick(int section, SyncedFolderDisplayItem syncedFolderDisplayItem);
|
||||
void onVisibilityToggleClick(int section, SyncedFolderDisplayItem item);
|
||||
}
|
||||
|
||||
static class HeaderViewHolder extends SectionedViewHolder {
|
||||
@@ -256,7 +417,29 @@ public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter<SectionedV
|
||||
}
|
||||
}
|
||||
|
||||
static class FooterViewHolder extends SectionedViewHolder {
|
||||
@BindView(R.id.footer_container)
|
||||
public LinearLayout mainFooterContainer;
|
||||
|
||||
@BindView(R.id.footer_text)
|
||||
public TextView title;
|
||||
|
||||
private FooterViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
}
|
||||
|
||||
static class EmptyViewHolder extends SectionedViewHolder {
|
||||
private EmptyViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
|
||||
static class MainViewHolder extends SectionedViewHolder {
|
||||
@BindView(R.id.grid_item_container)
|
||||
public FrameLayout item_container;
|
||||
|
||||
@BindView(R.id.thumbnail)
|
||||
public ImageView image;
|
||||
|
||||
@@ -278,7 +461,7 @@ public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter<SectionedV
|
||||
private void setSyncButtonActiveIcon(ImageButton syncStatusButton, boolean enabled) {
|
||||
if (enabled) {
|
||||
syncStatusButton.setImageDrawable(ThemeUtils.tintDrawable(R.drawable.ic_cloud_sync_on,
|
||||
ThemeUtils.primaryColor(mContext)));
|
||||
ThemeUtils.primaryColor(context)));
|
||||
} else {
|
||||
syncStatusButton.setImageResource(R.drawable.ic_cloud_sync_off);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.Template;
|
||||
import com.owncloud.android.ui.dialog.ChooseTemplateDialogFragment;
|
||||
@@ -56,17 +57,20 @@ public class TemplateAdapter extends RecyclerView.Adapter<TemplateAdapter.ViewHo
|
||||
private Context context;
|
||||
private ChooseTemplateDialogFragment.Type type;
|
||||
private CurrentAccountProvider currentAccountProvider;
|
||||
private ClientFactory clientFactory;
|
||||
|
||||
public TemplateAdapter(
|
||||
ChooseTemplateDialogFragment.Type type,
|
||||
ClickListener clickListener,
|
||||
Context context,
|
||||
CurrentAccountProvider currentAccountProvider
|
||||
CurrentAccountProvider currentAccountProvider,
|
||||
ClientFactory clientFactory
|
||||
) {
|
||||
this.clickListener = clickListener;
|
||||
this.type = type;
|
||||
this.context = context;
|
||||
this.currentAccountProvider = currentAccountProvider;
|
||||
this.clientFactory = clientFactory;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -135,7 +139,8 @@ public class TemplateAdapter extends RecyclerView.Adapter<TemplateAdapter.ViewHo
|
||||
break;
|
||||
}
|
||||
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider)).load(template.getThumbnailLink())
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider, clientFactory))
|
||||
.load(template.getThumbnailLink())
|
||||
.placeholder(placeholder)
|
||||
.error(placeholder)
|
||||
.into(thumbnail);
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
@@ -31,6 +30,7 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
@@ -65,7 +65,7 @@ public class TrashbinListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
private final TrashbinActivityInterface trashbinActivityInterface;
|
||||
private List<TrashbinFile> files;
|
||||
private final Context context;
|
||||
private final Account account;
|
||||
private final User user;
|
||||
private final FileDataStorageManager storageManager;
|
||||
private final AppPreferences preferences;
|
||||
|
||||
@@ -76,11 +76,11 @@ public class TrashbinListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
FileDataStorageManager storageManager,
|
||||
AppPreferences preferences,
|
||||
Context context,
|
||||
Account account
|
||||
User user
|
||||
) {
|
||||
this.files = new ArrayList<>();
|
||||
this.trashbinActivityInterface = trashbinActivityInterface;
|
||||
this.account = account;
|
||||
this.user = user;
|
||||
this.storageManager = storageManager;
|
||||
this.preferences = preferences;
|
||||
this.context = context;
|
||||
@@ -237,7 +237,7 @@ public class TrashbinListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
try {
|
||||
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
||||
new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView, storageManager,
|
||||
account, asyncTasks);
|
||||
user.toPlatformAccount(), asyncTasks);
|
||||
|
||||
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
|
||||
new ThumbnailsCacheManager.AsyncThumbnailDrawable(context.getResources(),
|
||||
@@ -253,11 +253,11 @@ public class TrashbinListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
}
|
||||
|
||||
if ("image/png".equalsIgnoreCase(file.getMimeType())) {
|
||||
thumbnailView.setBackgroundColor(context.getResources().getColor(R.color.background_color));
|
||||
thumbnailView.setBackgroundColor(context.getResources().getColor(R.color.bg_default));
|
||||
}
|
||||
} else {
|
||||
thumbnailView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(), file.getFileName(),
|
||||
account, context));
|
||||
user.toPlatformAccount(), context));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,7 +416,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
||||
|
||||
if ("image/png".equals(item.getMimeType())) {
|
||||
itemViewHolder.thumbnail.setBackgroundColor(parentActivity.getResources()
|
||||
.getColor(R.color.background_color));
|
||||
.getColor(R.color.bg_default));
|
||||
}
|
||||
|
||||
|
||||
@@ -451,7 +451,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
|
||||
|
||||
if ("image/png".equalsIgnoreCase(item.getMimeType())) {
|
||||
itemViewHolder.thumbnail.setBackgroundColor(parentActivity.getResources()
|
||||
.getColor(R.color.background_color));
|
||||
.getColor(R.color.bg_default));
|
||||
}
|
||||
} else {
|
||||
itemViewHolder.thumbnail.setImageDrawable(MimeTypeUtil.getFileTypeIcon(item.getMimeType(), fileName,
|
||||
|
||||
@@ -183,7 +183,7 @@ public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.UserVi
|
||||
context.getTheme().applyStyle(R.style.FallbackThemingTheme, true);
|
||||
}
|
||||
PopupMenu popup = new PopupMenu(context, view);
|
||||
popup.inflate(R.menu.file_detail_sharing_menu);
|
||||
popup.inflate(R.menu.item_user_sharing_settings);
|
||||
|
||||
prepareOptionsMenu(popup.getMenu(), share);
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.operations.RichDocumentsUrlOperation;
|
||||
import com.owncloud.android.ui.activity.RichDocumentsWebView;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.ThemeUtils;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
@@ -80,9 +81,9 @@ public class LoadUrlTask extends AsyncTask<String, Void, String> {
|
||||
if (richDocumentsWebView.getWebview().getVisibility() != View.VISIBLE) {
|
||||
Snackbar snackbar = DisplayUtils.createSnackbar(richDocumentsWebView.findViewById(android.R.id.content),
|
||||
R.string.timeout_richDocuments, Snackbar.LENGTH_INDEFINITE)
|
||||
.setActionTextColor(richDocumentsWebView.getResources().getColor(R.color.white))
|
||||
.setAction(R.string.fallback_weblogin_back, v -> richDocumentsWebView.closeView());
|
||||
|
||||
ThemeUtils.colorSnackbar(richDocumentsWebView.getApplicationContext(),snackbar);
|
||||
richDocumentsWebView.setLoadingSnackbar(snackbar);
|
||||
snackbar.show();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.notifications.models.Action;
|
||||
import com.owncloud.android.lib.resources.notifications.models.Notification;
|
||||
import com.owncloud.android.ui.activity.NotificationsActivity;
|
||||
import com.owncloud.android.ui.adapter.NotificationListAdapter;
|
||||
|
||||
@@ -22,12 +23,16 @@ public class NotificationExecuteActionTask extends AsyncTask<Action, Void, Boole
|
||||
|
||||
private NotificationListAdapter.NotificationViewHolder holder;
|
||||
private OwnCloudClient client;
|
||||
private Notification notification;
|
||||
private NotificationsActivity notificationsActivity;
|
||||
|
||||
public NotificationExecuteActionTask(OwnCloudClient client, NotificationListAdapter.NotificationViewHolder holder,
|
||||
public NotificationExecuteActionTask(OwnCloudClient client,
|
||||
NotificationListAdapter.NotificationViewHolder holder,
|
||||
Notification notification,
|
||||
NotificationsActivity notificationsActivity) {
|
||||
this.client = client;
|
||||
this.holder = holder;
|
||||
this.notification = notification;
|
||||
this.notificationsActivity = notificationsActivity;
|
||||
}
|
||||
|
||||
@@ -73,6 +78,6 @@ public class NotificationExecuteActionTask extends AsyncTask<Action, Void, Boole
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean isSuccess) {
|
||||
notificationsActivity.onActionCallback(isSuccess, holder);
|
||||
notificationsActivity.onActionCallback(isSuccess, notification, holder);
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,9 @@
|
||||
|
||||
package com.owncloud.android.ui.asynctasks;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
@@ -38,18 +38,18 @@ import java.lang.ref.WeakReference;
|
||||
public class PhotoSearchTask extends AsyncTask<Void, Void, RemoteOperationResult> {
|
||||
|
||||
private int columnCount;
|
||||
private Account account;
|
||||
private User user;
|
||||
private WeakReference<PhotoFragment> photoFragmentWeakReference;
|
||||
private SearchRemoteOperation searchRemoteOperation;
|
||||
private FileDataStorageManager storageManager;
|
||||
|
||||
public PhotoSearchTask(int columnsCount,
|
||||
PhotoFragment photoFragment,
|
||||
Account account,
|
||||
User user,
|
||||
SearchRemoteOperation searchRemoteOperation,
|
||||
FileDataStorageManager storageManager) {
|
||||
this.columnCount = columnsCount;
|
||||
this.account = account;
|
||||
this.user = user;
|
||||
this.photoFragmentWeakReference = new WeakReference<>(photoFragment);
|
||||
this.searchRemoteOperation = searchRemoteOperation;
|
||||
this.storageManager = storageManager;
|
||||
@@ -88,7 +88,7 @@ public class PhotoSearchTask extends AsyncTask<Void, Void, RemoteOperationResult
|
||||
searchRemoteOperation.setTimestamp(timestamp);
|
||||
|
||||
if (photoFragment.getContext() != null) {
|
||||
return searchRemoteOperation.execute(account, photoFragment.getContext());
|
||||
return searchRemoteOperation.execute(user.toPlatformAccount(), photoFragment.getContext());
|
||||
} else {
|
||||
return new RemoteOperationResult(new IllegalStateException("No context available"));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
package com.owncloud.android.ui.dialog;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
@@ -40,16 +39,16 @@ import android.view.WindowManager.LayoutParams;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.Template;
|
||||
import com.owncloud.android.files.CreateFileFromTemplateOperation;
|
||||
import com.owncloud.android.files.FetchTemplateOperation;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.activity.ExternalSiteWebView;
|
||||
@@ -88,7 +87,8 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements Dial
|
||||
private TemplateAdapter adapter;
|
||||
private OCFile parentFolder;
|
||||
private OwnCloudClient client;
|
||||
@Inject CurrentAccountProvider currentAccount;
|
||||
@Inject CurrentAccountProvider currentUser;
|
||||
@Inject ClientFactory clientFactory;
|
||||
|
||||
public enum Type {
|
||||
DOCUMENT,
|
||||
@@ -151,9 +151,8 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements Dial
|
||||
fileName.getBackground().setColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
|
||||
|
||||
try {
|
||||
Account account = currentAccount.getCurrentAccount();
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(account, activity);
|
||||
client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, getContext());
|
||||
User user = currentUser.getUser();
|
||||
client = clientFactory.create(user);
|
||||
|
||||
new FetchTemplateTask(this, client).execute(type);
|
||||
} catch (Exception e) {
|
||||
@@ -162,7 +161,7 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements Dial
|
||||
|
||||
listView.setHasFixedSize(true);
|
||||
listView.setLayoutManager(new GridLayoutManager(activity, 2));
|
||||
adapter = new TemplateAdapter(type, this, getContext(), currentAccount);
|
||||
adapter = new TemplateAdapter(type, this, getContext(), currentUser, clientFactory);
|
||||
listView.setAdapter(adapter);
|
||||
|
||||
// Build the dialog
|
||||
|
||||
@@ -99,6 +99,7 @@ public class CreateFolderDialogFragment
|
||||
inputText.setText("");
|
||||
inputText.requestFocus();
|
||||
inputText.getBackground().setColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
|
||||
inputText.setHighlightColor(ThemeUtils.primaryColor(getActivity()));
|
||||
|
||||
// Build the dialog
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.resources.shares.OCShare;
|
||||
import com.owncloud.android.ui.activity.FileActivity;
|
||||
import com.owncloud.android.utils.ThemeUtils;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
@@ -140,6 +141,11 @@ public class ExpirationDatePickerDialogFragment
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
dialog.getButton(DatePickerDialog.BUTTON_NEUTRAL).setTextColor(ThemeUtils.primaryColor(getContext(), true));
|
||||
dialog.getButton(DatePickerDialog.BUTTON_NEGATIVE).setTextColor(ThemeUtils.primaryColor(getContext(), true));
|
||||
dialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setTextColor(ThemeUtils.primaryColor(getContext(), true));
|
||||
|
||||
// Prevent days in the past may be chosen
|
||||
DatePicker picker = dialog.getDatePicker();
|
||||
picker.setMinDate(tomorrowInMillis - 1000);
|
||||
|
||||
@@ -109,6 +109,7 @@ public class NoteDialogFragment extends DialogFragment implements DialogInterfac
|
||||
|
||||
// Setup layout
|
||||
noteEditText.setText(share.getNote());
|
||||
noteEditText.setHighlightColor(ThemeUtils.primaryColor(getActivity()));
|
||||
noteEditText.requestFocus();
|
||||
ThemeUtils.colorTextInputLayout(noteEditTextInputLayout, accentColor);
|
||||
|
||||
@@ -136,8 +137,13 @@ public class NoteDialogFragment extends DialogFragment implements DialogInterfac
|
||||
ComponentsGetter componentsGetter = (ComponentsGetter) getActivity();
|
||||
|
||||
if (componentsGetter != null) {
|
||||
componentsGetter.getFileOperationsHelper().updateNoteToShare(share,
|
||||
noteEditText.getText().toString().trim());
|
||||
String note = "";
|
||||
|
||||
if (noteEditText.getText() != null) {
|
||||
note = noteEditText.getText().toString().trim();
|
||||
}
|
||||
|
||||
componentsGetter.getFileOperationsHelper().updateNoteToShare(share, note);
|
||||
} else {
|
||||
DisplayUtils.showSnackMessage(requireActivity(), R.string.note_could_not_sent);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ public class RenameFileDialogFragment
|
||||
// Setup layout
|
||||
String currentName = mTargetFile.getFileName();
|
||||
EditText inputText = v.findViewById(R.id.user_input);
|
||||
inputText.setHighlightColor(ThemeUtils.primaryColor(getActivity()));
|
||||
inputText.setText(currentName);
|
||||
ThemeUtils.themeEditText(getContext(), inputText, false);
|
||||
int selectionStart = 0;
|
||||
|
||||
@@ -144,6 +144,7 @@ public class SharePasswordDialogFragment extends DialogFragment implements Dialo
|
||||
// Build the dialog
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),
|
||||
R.style.Theme_ownCloud_Dialog_NoButtonBarStyle);
|
||||
|
||||
builder.setView(v)
|
||||
.setPositiveButton(R.string.common_ok, this)
|
||||
.setNegativeButton(R.string.common_cancel, this)
|
||||
|
||||
+8
-8
@@ -202,7 +202,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
|
||||
ThemeUtils.themeDialogActionButton(mSave);
|
||||
|
||||
// Set values
|
||||
setEnabled(mSyncedFolder.getEnabled());
|
||||
setEnabled(mSyncedFolder.isEnabled());
|
||||
|
||||
if (!TextUtils.isEmpty(mSyncedFolder.getLocalPath())) {
|
||||
mLocalFolderPath.setText(
|
||||
@@ -223,11 +223,11 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
|
||||
mRemoteFolderSummary.setText(R.string.choose_remote_folder);
|
||||
}
|
||||
|
||||
mUploadOnWifiCheckbox.setChecked(mSyncedFolder.getWifiOnly());
|
||||
mUploadOnWifiCheckbox.setChecked(mSyncedFolder.isWifiOnly());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
mUploadOnChargingCheckbox.setChecked(mSyncedFolder.getChargingOnly());
|
||||
mUploadOnChargingCheckbox.setChecked(mSyncedFolder.isChargingOnly());
|
||||
}
|
||||
mUploadUseSubfoldersCheckbox.setChecked(mSyncedFolder.getSubfolderByDate());
|
||||
mUploadUseSubfoldersCheckbox.setChecked(mSyncedFolder.isSubfolderByDate());
|
||||
|
||||
mUploadBehaviorSummary.setText(mUploadBehaviorItemStrings[mSyncedFolder.getUploadActionInteger()]);
|
||||
}
|
||||
@@ -344,7 +344,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mSyncedFolder.setWifiOnly(!mSyncedFolder.getWifiOnly());
|
||||
mSyncedFolder.setWifiOnly(!mSyncedFolder.isWifiOnly());
|
||||
mUploadOnWifiCheckbox.toggle();
|
||||
}
|
||||
});
|
||||
@@ -355,7 +355,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mSyncedFolder.setChargingOnly(!mSyncedFolder.getChargingOnly());
|
||||
mSyncedFolder.setChargingOnly(!mSyncedFolder.isChargingOnly());
|
||||
mUploadOnChargingCheckbox.toggle();
|
||||
}
|
||||
});
|
||||
@@ -365,7 +365,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
|
||||
new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mSyncedFolder.setSubfolderByDate(!mSyncedFolder.getSubfolderByDate());
|
||||
mSyncedFolder.setSubfolderByDate(!mSyncedFolder.isSubfolderByDate());
|
||||
mUploadUseSubfoldersCheckbox.toggle();
|
||||
}
|
||||
});
|
||||
@@ -401,7 +401,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
|
||||
view.findViewById(R.id.sync_enabled).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setEnabled(!mSyncedFolder.getEnabled());
|
||||
setEnabled(!mSyncedFolder.isEnabled());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -27,70 +27,76 @@ import com.owncloud.android.datamodel.MediaFolderType;
|
||||
import com.owncloud.android.datamodel.SyncedFolderDisplayItem;
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Parcelable for {@link SyncedFolderDisplayItem} objects to transport them from/to dialog fragments.
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class SyncedFolderParcelable implements Parcelable {
|
||||
private String mFolderName;
|
||||
private String mLocalPath;
|
||||
private String mRemotePath;
|
||||
private Boolean mWifiOnly = false;
|
||||
private Boolean mChargingOnly = false;
|
||||
private Boolean mEnabled = false;
|
||||
private Boolean mSubfolderByDate = false;
|
||||
private Integer mUploadAction;
|
||||
private MediaFolderType mType;
|
||||
private long mId;
|
||||
private String mAccount;
|
||||
private int mSection;
|
||||
@Getter @Setter private String folderName;
|
||||
@Getter @Setter private String localPath;
|
||||
@Getter @Setter private String remotePath;
|
||||
@Getter @Setter private boolean wifiOnly = false;
|
||||
@Getter @Setter private boolean chargingOnly = false;
|
||||
@Getter @Setter private boolean enabled = false;
|
||||
@Getter @Setter private boolean subfolderByDate = false;
|
||||
@Getter private Integer uploadAction;
|
||||
@Getter @Setter private MediaFolderType type;
|
||||
@Getter @Setter private boolean hidden = false;
|
||||
@Getter @Setter private long id;
|
||||
@Getter @Setter private String account;
|
||||
@Getter @Setter private int section;
|
||||
|
||||
public SyncedFolderParcelable(SyncedFolderDisplayItem syncedFolderDisplayItem, int section) {
|
||||
mId = syncedFolderDisplayItem.getId();
|
||||
mFolderName = syncedFolderDisplayItem.getFolderName();
|
||||
mLocalPath = syncedFolderDisplayItem.getLocalPath();
|
||||
mRemotePath = syncedFolderDisplayItem.getRemotePath();
|
||||
mWifiOnly = syncedFolderDisplayItem.getWifiOnly();
|
||||
mChargingOnly = syncedFolderDisplayItem.getChargingOnly();
|
||||
mEnabled = syncedFolderDisplayItem.isEnabled();
|
||||
mSubfolderByDate = syncedFolderDisplayItem.getSubfolderByDate();
|
||||
mType = syncedFolderDisplayItem.getType();
|
||||
mAccount = syncedFolderDisplayItem.getAccount();
|
||||
mUploadAction = syncedFolderDisplayItem.getUploadAction();
|
||||
mSection = section;
|
||||
id = syncedFolderDisplayItem.getId();
|
||||
folderName = syncedFolderDisplayItem.getFolderName();
|
||||
localPath = syncedFolderDisplayItem.getLocalPath();
|
||||
remotePath = syncedFolderDisplayItem.getRemotePath();
|
||||
wifiOnly = syncedFolderDisplayItem.isWifiOnly();
|
||||
chargingOnly = syncedFolderDisplayItem.isChargingOnly();
|
||||
enabled = syncedFolderDisplayItem.isEnabled();
|
||||
subfolderByDate = syncedFolderDisplayItem.isSubfolderByDate();
|
||||
type = syncedFolderDisplayItem.getType();
|
||||
account = syncedFolderDisplayItem.getAccount();
|
||||
uploadAction = syncedFolderDisplayItem.getUploadAction();
|
||||
this.section = section;
|
||||
hidden = syncedFolderDisplayItem.isHidden();
|
||||
}
|
||||
|
||||
private SyncedFolderParcelable(Parcel read) {
|
||||
mId = read.readLong();
|
||||
mFolderName = read.readString();
|
||||
mLocalPath = read.readString();
|
||||
mRemotePath = read.readString();
|
||||
mWifiOnly = read.readInt()!= 0;
|
||||
mChargingOnly = read.readInt() != 0;
|
||||
mEnabled = read.readInt() != 0;
|
||||
mSubfolderByDate = read.readInt() != 0;
|
||||
mType = MediaFolderType.getById(read.readInt());
|
||||
mAccount = read.readString();
|
||||
mUploadAction = read.readInt();
|
||||
mSection = read.readInt();
|
||||
id = read.readLong();
|
||||
folderName = read.readString();
|
||||
localPath = read.readString();
|
||||
remotePath = read.readString();
|
||||
wifiOnly = read.readInt()!= 0;
|
||||
chargingOnly = read.readInt() != 0;
|
||||
enabled = read.readInt() != 0;
|
||||
subfolderByDate = read.readInt() != 0;
|
||||
type = MediaFolderType.getById(read.readInt());
|
||||
account = read.readString();
|
||||
uploadAction = read.readInt();
|
||||
section = read.readInt();
|
||||
hidden = read.readInt() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeLong(mId);
|
||||
dest.writeString(mFolderName);
|
||||
dest.writeString(mLocalPath);
|
||||
dest.writeString(mRemotePath);
|
||||
dest.writeInt(mWifiOnly ? 1 : 0);
|
||||
dest.writeInt(mChargingOnly ? 1 : 0);
|
||||
dest.writeInt(mEnabled ? 1 : 0);
|
||||
dest.writeInt(mSubfolderByDate ? 1 : 0);
|
||||
dest.writeInt(mType.getId());
|
||||
dest.writeString(mAccount);
|
||||
dest.writeInt(mUploadAction);
|
||||
dest.writeInt(mSection);
|
||||
dest.writeLong(id);
|
||||
dest.writeString(folderName);
|
||||
dest.writeString(localPath);
|
||||
dest.writeString(remotePath);
|
||||
dest.writeInt(wifiOnly ? 1 : 0);
|
||||
dest.writeInt(chargingOnly ? 1 : 0);
|
||||
dest.writeInt(enabled ? 1 : 0);
|
||||
dest.writeInt(subfolderByDate ? 1 : 0);
|
||||
dest.writeInt(type.getId());
|
||||
dest.writeString(account);
|
||||
dest.writeInt(uploadAction);
|
||||
dest.writeInt(section);
|
||||
dest.writeInt(hidden ? 1 : 0);
|
||||
}
|
||||
|
||||
public static final Creator<SyncedFolderParcelable> CREATOR =
|
||||
@@ -112,76 +118,8 @@ public class SyncedFolderParcelable implements Parcelable {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getFolderName() {
|
||||
return mFolderName;
|
||||
}
|
||||
|
||||
public void setFolderName(String mFolderName) {
|
||||
this.mFolderName = mFolderName;
|
||||
}
|
||||
|
||||
public String getLocalPath() {
|
||||
return mLocalPath;
|
||||
}
|
||||
|
||||
public void setLocalPath(String mLocalPath) {
|
||||
this.mLocalPath = mLocalPath;
|
||||
}
|
||||
|
||||
public String getRemotePath() {
|
||||
return mRemotePath;
|
||||
}
|
||||
|
||||
public void setRemotePath(String mRemotePath) {
|
||||
this.mRemotePath = mRemotePath;
|
||||
}
|
||||
|
||||
public Boolean getWifiOnly() {
|
||||
return mWifiOnly;
|
||||
}
|
||||
|
||||
public void setWifiOnly(Boolean mWifiOnly) {
|
||||
this.mWifiOnly = mWifiOnly;
|
||||
}
|
||||
|
||||
public Boolean getChargingOnly() {
|
||||
return mChargingOnly;
|
||||
}
|
||||
|
||||
public void setChargingOnly(Boolean mChargingOnly) {
|
||||
this.mChargingOnly = mChargingOnly;
|
||||
}
|
||||
|
||||
public Boolean getEnabled() {
|
||||
return mEnabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean mEnabled) {
|
||||
this.mEnabled = mEnabled;
|
||||
}
|
||||
|
||||
public Boolean getSubfolderByDate() {
|
||||
return mSubfolderByDate;
|
||||
}
|
||||
|
||||
public void setSubfolderByDate(Boolean mSubfolderByDate) {
|
||||
this.mSubfolderByDate = mSubfolderByDate;
|
||||
}
|
||||
|
||||
public MediaFolderType getType() {
|
||||
return mType;
|
||||
}
|
||||
|
||||
public void setType(MediaFolderType mType) {
|
||||
this.mType = mType;
|
||||
}
|
||||
|
||||
public Integer getUploadAction() {
|
||||
return mUploadAction;
|
||||
}
|
||||
|
||||
public Integer getUploadActionInteger() {
|
||||
switch (mUploadAction) {
|
||||
switch (uploadAction) {
|
||||
case FileUploader.LOCAL_BEHAVIOUR_FORGET:
|
||||
return 0;
|
||||
case FileUploader.LOCAL_BEHAVIOUR_MOVE:
|
||||
@@ -192,41 +130,17 @@ public class SyncedFolderParcelable implements Parcelable {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setUploadAction(String mUploadAction) {
|
||||
switch (mUploadAction) {
|
||||
public void setUploadAction(String uploadAction) {
|
||||
switch (uploadAction) {
|
||||
case "LOCAL_BEHAVIOUR_FORGET":
|
||||
this.mUploadAction = FileUploader.LOCAL_BEHAVIOUR_FORGET;
|
||||
this.uploadAction = FileUploader.LOCAL_BEHAVIOUR_FORGET;
|
||||
break;
|
||||
case "LOCAL_BEHAVIOUR_MOVE":
|
||||
this.mUploadAction = FileUploader.LOCAL_BEHAVIOUR_MOVE;
|
||||
this.uploadAction = FileUploader.LOCAL_BEHAVIOUR_MOVE;
|
||||
break;
|
||||
case "LOCAL_BEHAVIOUR_DELETE":
|
||||
this.mUploadAction = FileUploader.LOCAL_BEHAVIOUR_DELETE;
|
||||
this.uploadAction = FileUploader.LOCAL_BEHAVIOUR_DELETE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
public void setId(long mId) {
|
||||
this.mId = mId;
|
||||
}
|
||||
|
||||
public String getAccount() {
|
||||
return mAccount;
|
||||
}
|
||||
|
||||
public void setAccount(String mAccount) {
|
||||
this.mAccount = mAccount;
|
||||
}
|
||||
|
||||
public int getSection() {
|
||||
return mSection;
|
||||
}
|
||||
|
||||
public void setSection(int mSection) {
|
||||
this.mSection = mSection;
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,7 @@ import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
@@ -194,6 +195,9 @@ public class ExtendedListFragment extends Fragment implements
|
||||
searchView.setOnCloseListener(this);
|
||||
ThemeUtils.themeSearchView(searchView, true, requireContext());
|
||||
|
||||
SearchView.SearchAutoComplete theTextArea = searchView.findViewById(R.id.search_src_text);
|
||||
theTextArea.setHighlightColor(ThemeUtils.primaryAccentColor(getContext()));
|
||||
|
||||
final Handler handler = new Handler();
|
||||
|
||||
DisplayMetrics displaymetrics = new DisplayMetrics();
|
||||
@@ -301,7 +305,8 @@ public class ExtendedListFragment extends Fragment implements
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (accountManager.isSearchSupported(accountManager.getCurrentAccount())) {
|
||||
User user = accountManager.getUser();
|
||||
if (user.getServer().getVersion().isSearchSupported()) {
|
||||
EventBus.getDefault().post(new SearchEvent(query,
|
||||
SearchRemoteOperation.SearchType.FILE_SEARCH, SearchEvent.UnsetType.NO_UNSET));
|
||||
} else {
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
package com.owncloud.android.ui.fragment;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@@ -41,15 +38,14 @@ import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.owncloud.android.MainApp;
|
||||
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.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.activities.GetActivitiesRemoteOperation;
|
||||
@@ -72,7 +68,6 @@ import com.owncloud.android.utils.ThemeUtils;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -149,6 +144,7 @@ public class FileDetailActivitiesFragment extends Fragment implements
|
||||
private VersionListInterface.CommentCallback callback;
|
||||
|
||||
@Inject UserAccountManager accountManager;
|
||||
@Inject ClientFactory clientFactory;
|
||||
|
||||
public static FileDetailActivitiesFragment newInstance(OCFile file, Account account) {
|
||||
FileDetailActivitiesFragment fragment = new FileDetailActivitiesFragment();
|
||||
@@ -258,7 +254,9 @@ public class FileDetailActivitiesFragment extends Fragment implements
|
||||
PorterDuff.Mode.SRC_IN);
|
||||
emptyContentIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_activity_light_grey));
|
||||
|
||||
adapter = new ActivityAndVersionListAdapter(getContext(), accountManager, this, this, storageManager, capability);
|
||||
adapter = new ActivityAndVersionListAdapter(getContext(), accountManager, this, this,
|
||||
storageManager,
|
||||
capability);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
|
||||
@@ -301,9 +299,9 @@ public class FileDetailActivitiesFragment extends Fragment implements
|
||||
|
||||
final SwipeRefreshLayout empty = swipeEmptyListRefreshLayout;
|
||||
final SwipeRefreshLayout list = swipeListRefreshLayout;
|
||||
final Account currentAccount = accountManager.getCurrentAccount();
|
||||
final User user = accountManager.getUser();
|
||||
|
||||
if (currentAccount == null) {
|
||||
if (user.isAnonymous()) {
|
||||
activity.runOnUiThread(() -> {
|
||||
setEmptyContent(getString(R.string.common_error), getString(R.string.file_detail_activity_error));
|
||||
list.setVisibility(View.GONE);
|
||||
@@ -312,15 +310,10 @@ public class FileDetailActivitiesFragment extends Fragment implements
|
||||
return;
|
||||
}
|
||||
|
||||
final Context context = MainApp.getAppContext();
|
||||
|
||||
Thread t = new Thread(() -> {
|
||||
OwnCloudAccount ocAccount;
|
||||
try {
|
||||
ocAccount = new OwnCloudAccount(currentAccount, context);
|
||||
ownCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
getClientFor(ocAccount, MainApp.getAppContext());
|
||||
ownCloudClient.setOwnCloudVersion(accountManager.getServerVersion(currentAccount));
|
||||
ownCloudClient = clientFactory.create(user);
|
||||
ownCloudClient.setOwnCloudVersion(user.getServer().getVersion());
|
||||
isLoadingActivities = true;
|
||||
|
||||
GetActivitiesRemoteOperation getRemoteNotificationOperation;
|
||||
@@ -385,8 +378,7 @@ public class FileDetailActivitiesFragment extends Fragment implements
|
||||
}
|
||||
|
||||
hideRefreshLayoutLoader(activity);
|
||||
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException | IOException |
|
||||
OperationCanceledException | AuthenticatorException | NullPointerException e) {
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
Log_OC.e(TAG, "Error fetching file details activities", e);
|
||||
}
|
||||
});
|
||||
|
||||
Loaded 100 of 320 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user