Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f053ef4a35 |
No files matched your search
@@ -16,9 +16,6 @@ comment:
|
||||
layout: "header, diff, changes, uncovered, tree"
|
||||
behavior: default
|
||||
|
||||
github_checks:
|
||||
annotations: false
|
||||
|
||||
ignore:
|
||||
- "app/src/main/res/values*/*"
|
||||
- "src/main/res/values*/*"
|
||||
|
||||
@@ -19,21 +19,49 @@ steps:
|
||||
commands:
|
||||
- scripts/checkIfRunDrone.sh $GIT_USERNAME $GIT_TOKEN $DRONE_PULL_REQUEST || exit 0
|
||||
- emulator -avd android -no-snapshot -gpu swiftshader_indirect -no-window -no-audio -skin 500x833 &
|
||||
- sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g app/src/main/res/values/setup.xml
|
||||
- ./gradlew assembleGplayDebugAndroidTest
|
||||
- sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g src/main/res/values/setup.xml
|
||||
- sed -i s"#server#server#" gradle.properties
|
||||
- sed -i s"#1#5#" ./src/androidTest/java/com/nextcloud/client/RetryTestRule.kt
|
||||
- ./gradlew assembleGplay
|
||||
- ./gradlew assembleGplayDebug
|
||||
- scripts/wait_for_emulator.sh
|
||||
- scripts/deleteOldComments.sh "stable" "Unit" $DRONE_PULL_REQUEST $GIT_TOKEN
|
||||
- ./gradlew jacocoTestGplayDebugUnitTestReport || scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "stable" "Unit" $DRONE_PULL_REQUEST $GIT_TOKEN
|
||||
- ./gradlew installGplayDebugAndroidTest
|
||||
- scripts/wait_for_server.sh "server"
|
||||
- scripts/deleteOldComments.sh "stable" "IT" $DRONE_PULL_REQUEST $GIT_TOKEN
|
||||
- ./gradlew createGplayDebugCoverageReport -Pcoverage -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.owncloud.android.utils.ScreenshotTest || scripts/uploadReport.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER "stable" "IT" $DRONE_PULL_REQUEST $GIT_TOKEN
|
||||
- ./gradlew combinedTestReport
|
||||
- name: notify
|
||||
image: drillster/drone-email
|
||||
settings:
|
||||
port: 587
|
||||
from: [email protected]
|
||||
recipients_only: true
|
||||
username:
|
||||
from_secret: EMAIL_USERNAME
|
||||
password:
|
||||
from_secret: EMAIL_PASSWORD
|
||||
recipients:
|
||||
from_secret: EMAIL_RECIPIENTS
|
||||
host:
|
||||
from_secret: EMAIL_HOST
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
status:
|
||||
- failure
|
||||
branch:
|
||||
- master
|
||||
- stable-*
|
||||
|
||||
services:
|
||||
- name: server
|
||||
image: ghcr.io/nextcloud/continuous-integration-server:latest # also change in updateScreenshots.sh
|
||||
image: nextcloudci/server:server-17 # also change in updateScreenshots.sh
|
||||
environment:
|
||||
EVAL: true
|
||||
commands:
|
||||
- BRANCH='stable23' /usr/local/bin/initnc.sh
|
||||
- BRANCH='stable22' /usr/local/bin/initnc.sh
|
||||
- echo 127.0.0.1 server >> /etc/hosts
|
||||
- su www-data -c "OC_PASS=user1 php /var/www/html/occ user:add --password-from-env --display-name='User One' user1"
|
||||
- su www-data -c "OC_PASS=user2 php /var/www/html/occ user:add --password-from-env --display-name='User Two' user2"
|
||||
@@ -42,11 +70,11 @@ services:
|
||||
- su www-data -c "php /var/www/html/occ group:add users"
|
||||
- su www-data -c "php /var/www/html/occ group:adduser users user1"
|
||||
- su www-data -c "php /var/www/html/occ group:adduser users user2"
|
||||
- su www-data -c "git clone -b stable23 https://github.com/nextcloud/activity.git /var/www/html/apps/activity/"
|
||||
- su www-data -c "git clone -b stable22 https://github.com/nextcloud/activity.git /var/www/html/apps/activity/"
|
||||
- su www-data -c "php /var/www/html/occ app:enable activity"
|
||||
- su www-data -c "git clone -b stable23 https://github.com/nextcloud/text.git /var/www/html/apps/text/"
|
||||
- su www-data -c "git clone -b stable22 https://github.com/nextcloud/text.git /var/www/html/apps/text/"
|
||||
- su www-data -c "php /var/www/html/occ app:enable text"
|
||||
- su www-data -c "git clone -b stable23 https://github.com/nextcloud/end_to_end_encryption.git /var/www/html/apps/end_to_end_encryption/"
|
||||
- su www-data -c "git clone -b stable22 https://github.com/nextcloud/end_to_end_encryption.git /var/www/html/apps/end_to_end_encryption/"
|
||||
- su www-data -c "php /var/www/html/occ app:enable end_to_end_encryption"
|
||||
- /usr/local/bin/run.sh
|
||||
|
||||
@@ -78,12 +106,36 @@ steps:
|
||||
commands:
|
||||
- scripts/checkIfRunDrone.sh $GIT_USERNAME $GIT_TOKEN $DRONE_PULL_REQUEST || exit 0
|
||||
- emulator -avd android -no-snapshot -gpu swiftshader_indirect -no-window -no-audio -skin 500x833 &
|
||||
- sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g app/src/main/res/values/setup.xml
|
||||
- sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g src/main/res/values/setup.xml
|
||||
- sed -i s"#1#5#" ./src/androidTest/java/com/nextcloud/client/RetryTestRule.kt
|
||||
- scripts/runCombinedTest.sh $GIT_USERNAME $GIT_TOKEN $DRONE_PULL_REQUEST $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER
|
||||
|
||||
- name: notify
|
||||
image: drillster/drone-email
|
||||
settings:
|
||||
port: 587
|
||||
from: [email protected]
|
||||
recipients_only: true
|
||||
username:
|
||||
from_secret: EMAIL_USERNAME
|
||||
password:
|
||||
from_secret: EMAIL_PASSWORD
|
||||
recipients:
|
||||
from_secret: EMAIL_RECIPIENTS
|
||||
host:
|
||||
from_secret: EMAIL_HOST
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
status:
|
||||
- failure
|
||||
branch:
|
||||
- master
|
||||
- stable-*
|
||||
|
||||
services:
|
||||
- name: server
|
||||
image: ghcr.io/nextcloud/continuous-integration-server:latest # also change in updateScreenshots.sh
|
||||
image: nextcloudci/server:server-17 # also change in updateScreenshots.sh
|
||||
environment:
|
||||
EVAL: true
|
||||
commands:
|
||||
@@ -132,7 +184,7 @@ steps:
|
||||
from_secret: LOG_PASSWORD
|
||||
commands:
|
||||
- emulator -avd android -no-snapshot -gpu swiftshader_indirect -no-window -no-audio -skin 500x833 &
|
||||
- sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g app/src/main/res/values/setup.xml
|
||||
- sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g src/main/res/values/setup.xml
|
||||
- sed -i s'#showOnlyFailingTestsInReports = ciBuild#showOnlyFailingTestsInReports = false#' build.gradle
|
||||
- scripts/wait_for_emulator.sh
|
||||
- scripts/runAllScreenshotCombinations noCI false
|
||||
|
||||
@@ -3,21 +3,19 @@ name: "Analysis"
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ master, stable-* ]
|
||||
push:
|
||||
branches: [ master, stable-* ]
|
||||
|
||||
jobs:
|
||||
analysis:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: "temurin"
|
||||
distribution: "adopt"
|
||||
java-version: 11
|
||||
- name: Run analysis wrapper
|
||||
run: |
|
||||
mkdir -p $HOME/.gradle
|
||||
echo "org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > $HOME/.gradle/gradle.properties
|
||||
scripts/analysis/analysis-wrapper.sh ${{ secrets.GIT_USERNAME }} ${{ secrets.GIT_TOKEN }} ${{ steps.get-vars.outputs.branch }} ${{ secrets.LOG_USERNAME }} ${{ secrets.LOG_PASSWORD }} $GITHUB_RUN_NUMBER ${{ steps.get-vars.outputs.pr }}
|
||||
scripts/analysis/analysis-wrapper.sh ${{ secrets.GIT_USERNAME }} ${{ secrets.GIT_TOKEN }} $GITHUB_REF ${{ secrets.LOG_USERNAME }} ${{ secrets.LOG_PASSWORD }} $GITHUB_RUN_NUMBER ${{ github.event.pull_request.number }}
|
||||
@@ -12,11 +12,11 @@ jobs:
|
||||
matrix:
|
||||
flavor: [ Generic, Gplay, Huawei ]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v2
|
||||
- name: set up JDK 11
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: "temurin"
|
||||
distribution: "adopt"
|
||||
java-version: 11
|
||||
- name: Build ${{ matrix.flavor }}
|
||||
run: |
|
||||
|
||||
@@ -10,13 +10,13 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
task: [ detekt, ktlintCheck ]
|
||||
task: [ detekt, ktlint ]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: "temurin"
|
||||
distribution: "adopt"
|
||||
java-version: 11
|
||||
- name: Check ${{ matrix.task }}
|
||||
run: ./gradlew ${{ matrix.task }}
|
||||
@@ -6,41 +6,41 @@
|
||||
name: Rebase command
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: created
|
||||
issue_comment:
|
||||
types: created
|
||||
|
||||
jobs:
|
||||
rebase:
|
||||
runs-on: ubuntu-latest
|
||||
rebase:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
# On pull requests and if the comment starts with `/rebase`
|
||||
if: github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/rebase')
|
||||
# On pull requests and if the comment starts with `/rebase`
|
||||
if: github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/rebase')
|
||||
|
||||
steps:
|
||||
- name: Add reaction on start
|
||||
uses: peter-evans/create-or-update-comment@v1
|
||||
with:
|
||||
token: ${{ secrets.COMMAND_BOT_PAT }}
|
||||
repository: ${{ github.event.repository.full_name }}
|
||||
comment-id: ${{ github.event.comment.id }}
|
||||
reaction-type: "+1"
|
||||
steps:
|
||||
- name: Add reaction on start
|
||||
uses: peter-evans/create-or-update-comment@v1
|
||||
with:
|
||||
token: ${{ secrets.COMMAND_BOT_PAT }}
|
||||
repository: ${{ github.event.repository.full_name }}
|
||||
comment-id: ${{ github.event.comment.id }}
|
||||
reaction-type: "+1"
|
||||
|
||||
- name: Checkout the latest code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.COMMAND_BOT_PAT }}
|
||||
- name: Checkout the latest code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.COMMAND_BOT_PAT }}
|
||||
|
||||
- name: Automatic Rebase
|
||||
uses: cirrus-actions/[email protected]
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.COMMAND_BOT_PAT }}
|
||||
- name: Automatic Rebase
|
||||
uses: cirrus-actions/[email protected]
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.COMMAND_BOT_PAT }}
|
||||
|
||||
- name: Add reaction on failure
|
||||
uses: peter-evans/create-or-update-comment@v1
|
||||
if: failure()
|
||||
with:
|
||||
token: ${{ secrets.COMMAND_BOT_PAT }}
|
||||
repository: ${{ github.event.repository.full_name }}
|
||||
comment-id: ${{ github.event.comment.id }}
|
||||
reaction-type: "-1"
|
||||
- name: Add reaction on failure
|
||||
uses: peter-evans/create-or-update-comment@v1
|
||||
if: failure()
|
||||
with:
|
||||
token: ${{ secrets.COMMAND_BOT_PAT }}
|
||||
repository: ${{ github.event.repository.full_name }}
|
||||
comment-id: ${{ github.event.comment.id }}
|
||||
reaction-type: "-1"
|
||||
@@ -9,6 +9,6 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v2
|
||||
- name: Detect SNAPSHOT
|
||||
run: scripts/analysis/detectSNAPSHOT.sh
|
||||
@@ -9,5 +9,5 @@ jobs:
|
||||
name: "Validation"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v2
|
||||
- uses: gradle/wrapper-validation-action@v1
|
||||
@@ -11,19 +11,14 @@ jobs:
|
||||
- name: Check if secrets are available
|
||||
run: echo "::set-output name=ok::${{ secrets.KS_PASS != '' }}"
|
||||
id: check-secrets
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v2
|
||||
if: ${{ steps.check-secrets.outputs.ok == 'true' }}
|
||||
- name: set up JDK 11
|
||||
uses: actions/setup-java@v3
|
||||
if: ${{ steps.check-secrets.outputs.ok == 'true' }}
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: "temurin"
|
||||
distribution: "adopt"
|
||||
java-version: 11
|
||||
- name: Install NDK and cmake
|
||||
if: ${{ steps.check-secrets.outputs.ok == 'true' }}
|
||||
run: |
|
||||
source ndk.env
|
||||
/usr/local/lib/android/sdk/tools/bin/sdkmanager "ndk;${NDK_VERSION}" "cmake;${CMAKE_VERSION}"
|
||||
- name: Build QA
|
||||
if: ${{ steps.check-secrets.outputs.ok == 'true' }}
|
||||
env:
|
||||
@@ -34,8 +29,8 @@ jobs:
|
||||
run: |
|
||||
mkdir -p $HOME/.gradle
|
||||
echo "org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > $HOME/.gradle/gradle.properties
|
||||
sed -i "/qa/,/\}/ s/versionCode .*/versionCode ${{github.event.number}} /" app/build.gradle
|
||||
sed -i "/qa/,/\}/ s/versionName .*/versionName \"${{github.event.number}}\"/" app/build.gradle
|
||||
sed -i "/qa/,/\}/ s/versionCode .*/versionCode ${{github.event.number}} /" build.gradle
|
||||
sed -i "/qa/,/\}/ s/versionName .*/versionName \"${{github.event.number}}\"/" build.gradle
|
||||
./gradlew assembleQaDebug
|
||||
$(find /usr/local/lib/android/sdk/build-tools/*/apksigner | sort | tail -n1) sign --ks-pass pass:$KS_PASS --key-pass pass:$KEY_PASS --ks-key-alias key0 --ks scripts/QA_keystore.jks app/build/outputs/apk/qa/debug/qa-debug-*.apk
|
||||
$(find /usr/local/lib/android/sdk/build-tools/*/apksigner | sort | tail -n1) sign --ks-pass pass:$KS_PASS --key-pass pass:$KEY_PASS --ks-key-alias key0 --ks scripts/QA_keystore.jks build/outputs/apk/qa/debug/qa-debug-*.apk
|
||||
sudo scripts/uploadArtifact.sh $LOG_USERNAME $LOG_PASSWORD ${{github.event.number}} ${{github.event.number}} ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -1,55 +0,0 @@
|
||||
name: Scorecards supply-chain security
|
||||
on:
|
||||
# Only the default branch is supported.
|
||||
branch_protection_rule:
|
||||
schedule:
|
||||
- cron: '33 1 * * 5'
|
||||
push:
|
||||
branches: [ master ]
|
||||
|
||||
# Declare default permissions as read only.
|
||||
permissions: read-all
|
||||
|
||||
jobs:
|
||||
analysis:
|
||||
name: Scorecards analysis
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
# Needed to upload the results to code-scanning dashboard.
|
||||
security-events: write
|
||||
actions: read
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: "Checkout code"
|
||||
uses: actions/checkout@v3 # v2.4.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: "Run analysis"
|
||||
uses: ossf/scorecard-action@e3e75cf2ffbf9364bbff86cdbdf52b23176fe492 # v1.0.1
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
# Read-only PAT token. To create it,
|
||||
# follow the steps in https://github.com/ossf/scorecard-action#pat-token-creation.
|
||||
repo_token: ${{ secrets.SCORECARD_READ_TOKEN }}
|
||||
# Publish the results to enable scorecard badges. For more details, see
|
||||
# https://github.com/ossf/scorecard-action#publishing-results.
|
||||
# For private repositories, `publish_results` will automatically be set to `false`,
|
||||
# regardless of the value entered here.
|
||||
publish_results: false
|
||||
|
||||
# Upload the results as artifacts (optional).
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # v2.3.1
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
retention-days: 5
|
||||
|
||||
# Upload the results to GitHub's code scanning dashboard.
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@5f532563584d71fdef14ee64d17bafb34f751ce5 # v1.0.26
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
@@ -14,17 +14,17 @@ jobs:
|
||||
color: [ blue ]
|
||||
api-level: [ 27 ]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Gradle cache
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
~/.gradle/caches
|
||||
~/.gradle/wrapper
|
||||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
|
||||
- name: AVD cache
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v2
|
||||
id: avd-cache
|
||||
with:
|
||||
path: |
|
||||
@@ -34,7 +34,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: "temurin"
|
||||
distribution: "adopt"
|
||||
java-version: 11
|
||||
|
||||
- name: create AVD and generate snapshot for caching
|
||||
@@ -71,15 +71,15 @@ jobs:
|
||||
sdcard-path-or-size: 100M
|
||||
target: google_apis
|
||||
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -skin 500x833
|
||||
script: ./gradlew uninstallAll gplayDebugExecuteScreenshotTests -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest -Pandroid.testInstrumentationRunnerArguments.COLOR=${{ matrix.color }} -Pandroid.testInstrumentationRunnerArguments.DARKMODE=${{ matrix.scheme }}
|
||||
script: ./gradlew gplayDebugExecuteScreenshotTests -Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest -Pandroid.testInstrumentationRunnerArguments.COLOR=${{ matrix.color }} -Pandroid.testInstrumentationRunnerArguments.DARKMODE=${{ matrix.scheme }}
|
||||
- name: upload failing results
|
||||
if: ${{ failure() }}
|
||||
run:
|
||||
scripts/uploadReport.sh "${{ secrets.LOG_USERNAME }}" "${{ secrets.LOG_PASSWORD }}" ${{github.event.number}} "${{ matrix.color }}-${{ matrix.scheme }}" "Screenshot" ${{github.event.number}} ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Archive Espresso results
|
||||
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
|
||||
uses: actions/upload-artifact@v2
|
||||
if: ${{ always() }}
|
||||
with:
|
||||
name: Report-${{ matrix.color }}-${{ matrix.scheme }}
|
||||
path: app/build/reports
|
||||
path: build/reports
|
||||
retention-days: 4
|
||||
@@ -7,7 +7,7 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v5
|
||||
- uses: actions/stale@v4.1.0
|
||||
with:
|
||||
days-before-stale: 28
|
||||
days-before-close: 14
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
name: Unit tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ master, stable-* ]
|
||||
push:
|
||||
branches: [ master, stable-* ]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: "temurin"
|
||||
java-version: 11
|
||||
- name: Delete old comments
|
||||
if: ${{ always() }}
|
||||
run: scripts/deleteOldComments.sh "test" "Unit" ${{github.event.number}} ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Run unit tests with coverage
|
||||
uses: gradle/gradle-build-action@v2
|
||||
with:
|
||||
arguments: jacocoTestGplayDebugUnitTest
|
||||
- name: Upload failing results
|
||||
if: ${{ failure() }}
|
||||
run:
|
||||
scripts/uploadReport.sh "${{ secrets.LOG_USERNAME }}" "${{ secrets.LOG_PASSWORD }}" ${{github.event.number}} "test" "Unit" ${{github.event.number}} ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Upload coverage to codecov
|
||||
uses: codecov/codecov-action@v2
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
flags: unit
|
||||
fail_ci_if_error: true
|
||||
- name: Upload jacoco artifacts
|
||||
if: ${{ failure() }}
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: test-results
|
||||
path: app/build/reports/tests/testGplayDebugUnitTest/
|
||||
@@ -1,7 +1,6 @@
|
||||
# built application files
|
||||
*.apk
|
||||
*.ap_
|
||||
*.aab
|
||||
|
||||
# files for the dex VM
|
||||
*.dex
|
||||
|
||||
@@ -65,6 +65,9 @@
|
||||
<MarkdownNavigatorCodeStyleSettings>
|
||||
<option name="RIGHT_MARGIN" value="120" />
|
||||
</MarkdownNavigatorCodeStyleSettings>
|
||||
<XML>
|
||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||
</XML>
|
||||
<codeStyleSettings language="JAVA">
|
||||
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
|
||||
<option name="ALIGN_MULTILINE_METHOD_BRACKETS" value="true" />
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
host = https://www.transifex.com
|
||||
|
||||
[nextcloud.android]
|
||||
file_filter = app/src/main/res/values-<lang>/strings.xml
|
||||
source_file = app/src/main/res/values/strings.xml
|
||||
file_filter = src/main/res/values-<lang>/strings.xml
|
||||
source_file = src/main/res/values/strings.xml
|
||||
type = ANDROID
|
||||
source_lang = en
|
||||
lang_map = af_ZA: af-rZA, am_ET: am-rET, ar_AE: ar-rAE, ar_BH: ar-rBH, ar_DZ: ar-rDZ, ar_EG: ar-rEG, ar_IQ: ar-rIQ, ar_JO: ar-rJO, ar_KW: ar-rKW, ar_LB: ar-rLB, ar_LY: ar-rLY, ar_MA: ar-rMA, ar_OM: ar-rOM, ar_QA: ar-rQA, ar_SA: ar-rSA, ar_SY: ar-rSY, ar_TN: ar-rTN, ar_YE: ar-rYE, arn_CL: arn-rCL, as_IN: as-rIN, az_AZ: az-rAZ, ba_RU: ba-rRU, be_BY: be-rBY, bg_BG: bg-rBG, bn_BD: bn-rBD, bn_IN: bn-rIN, bo_CN: bo-rCN, br_FR: br-rFR, bs_BA: bs-rBA, ca_ES: ca-rES, co_FR: co-rFR, cs_CZ: cs-rCZ, cy_GB: cy-rGB, da_DK: da-rDK, de_AT: de-rAT, de_CH: de-rCH, de_DE: de-rDE, de_LI: de-rLI, de_LU: de-rLU, dsb_DE: dsb-rDE, dv_MV: dv-rMV, el_GR: el-rGR, en_AU: en-rAU, en_BZ: en-rBZ, en_CA: en-rCA, en_GB: b+en+001, en_IE: en-rIE, en_IN: en-rIN, en_JM: en-rJM, en_MY: en-rMY, en_NZ: en-rNZ, en_PH: en-rPH, en_SG: en-rSG, en_TT: en-rTT, en_US: en-rUS, en_ZA: en-rZA, en_ZW: en-rZW, en@pirate: en-rpirate, es_AR: es-rAR, es_BO: es-rBO, es_CL: es-rCL, es_CO: es-rCO, es_CR: es-rCR, es_DO: es-rDO, es_EC: es-rEC, es_ES: es-rES, es_GT: es-rGT, es_HN: es-rHN, es_MX: es-rMX, es_NI: es-rNI, es_PA: es-rPA, es_PE: es-rPE, es_PR: es-rPR, es_PY: es-rPY, es_SV: es-rSV, es_419: b+es+419, es_UY: es-rUY, es_VE: es-rVE, et_EE: et-rEE, eu_ES: eu-rES, fa_IR: fa-rIR, fi_FI: fi-rFI, fil_PH: fil-rPH, fo_FO: fo-rFO, fr_BE: fr-rBE, fr_CA: fr-rCA, fr_CH: fr-rCH, fr_FR: fr-rFR, fr_LU: fr-rLU, fr_MC: fr-rMC, fy_NL: fy-rNL, ga_IE: ga-rIE, gd_GB: gd-rGB, gl_ES: gl-rES, gsw_FR: gsw-rFR, gu_IN: gu-rIN, ha_NG: ha-rNG, he: iw, he_IL: he-rIL, hi_IN: hi-rIN, hr_BA: hr-rBA, hr_HR: hr-rHR, hsb_DE: hsb-rDE, hu_HU: hu-rHU, hy_AM: hy-rAM, id: in, id_ID: id-rID, ig_NG: ig-rNG, ii_CN: ii-rCN, is_IS: is-rIS, it_CH: it-rCH, it_IT: it-rIT, iu_CA: iu-rCA, ja_JP: ja-rJP, ka_GE: ka-rGE, kk_KZ: kk-rKZ, kl_GL: kl-rGL, km_KH: km-rKH, kn_IN: kn-rIN, ko_KR: ko-rKR, kok_IN: kok-rIN, ku_IQ: ku-rIQ, ky_KG: ky-rKG, lb_LU: lb-rLU, lo_LA: lo-rLA, lt_LT: lt-rLT, lv_LV: lv-rLV, mi_NZ: mi-rNZ, mk_MK: mk-rMK, ml_IN: ml-rIN, mn_CN: mn-rCN, mn_MN: mn-rMN, moh_CA: moh-rCA, mr_IN: mr-rIN, ms_BN: ms-rBN, ms_MY: ms-rMY, my_MM: my, mt_MT: mt-rMT, nb_NO: nb-rNO, ne_NP: ne-rNP, nl_BE: nl-rBE, nl_NL: nl-rNL, nn_NO: nn-rNO, nso_ZA: nso-rZA, oc_FR: oc-rFR, or_IN: or-rIN, pa_IN: pa-rIN, pl_PL: pl-rPL, prs_AF: prs-rAF, ps_AF: ps-rAF, pt_BR: pt-rBR, pt_PT: pt-rPT, qut_GT: qut-rGT, quz_BO: quz-rBO, quz_EC: quz-rEC, quz_PE: quz-rPE, rm_CH: rm-rCH, ro_RO: ro-rRO, ru_RU: ru-rRU, rw_RW: rw-rRW, sa_IN: sa-rIN, sah_RU: sah-rRU, se_FI: se-rFI, se_NO: se-rNO, se_SE: se-rSE, si_LK: si-rLK, sk_SK: sk-rSK, sl_SI: sl-rSI, sma_NO: sma-rNO, sma_SE: sma-rSE, smj_NO: smj-rNO, smj_SE: smj-rSE, smn_FI: smn-rFI, sms_FI: sms-rFI, sq_AL: sq-rAL, sr_BA: sr-rBA, sr_CS: sr-rCS, sr_ME: sr-rME, sr_RS: sr-rRS, sr@latin: sr-rSP, sv_FI: sv-rFI, sv_SE: sv-rSE, sw_KE: sw-rKE, syr_SY: syr-rSY, ta_IN: ta-rIN, ta_LK: ta-rLK, te_IN: te-rIN, tg_TJ: tg-rTJ, th_TH: th-rTH, tk_TM: tk-rTM, tn_ZA: tn-rZA, tr_TR: tr-rTR, tt_RU: tt-rRU, tzm_DZ: tzm-rDZ, ug_CN: ug-rCN, uk_UA: uk-rUA, ur_PK: ur-rPK, uz_UZ: uz-rUZ, vi_VN: vi-rVN, wo_SN: wo-rSN, xh_ZA: xh-rZA, yo_NG: yo-rNG, zh_CN: zh-rCN, zh_CN.GB2312:zh-rBG, zh_HK: zh-rHK, zh_MO: zh-rMO, zh_SG: zh-rSG, zh_TW: zh-rTW, zu_ZA: zu-rZA
|
||||
@@ -1,39 +1,3 @@
|
||||
## 3.20.0 RC2 (April 7, 2022)
|
||||
|
||||
- Built-in PDF viewer
|
||||
- Built-in document scanner
|
||||
- Better choices for storage permissions
|
||||
- Many bugfixes and improvements
|
||||
|
||||
Minimum: NC 16 Server, Android 6.0 Marshmallow
|
||||
|
||||
For a full list, please see https://github.com/nextcloud/android/milestone/64
|
||||
## 3.20.0 RC1 (March 28, 2022)
|
||||
|
||||
- Built-in PDF viewer
|
||||
- Built-in document scanner
|
||||
- Better choices for storage permissions
|
||||
- Many bugfixes and improvements
|
||||
|
||||
Minimum: NC 16 Server, Android 6.0 Marshmallow
|
||||
|
||||
For a full list, please see https://github.com/nextcloud/android/milestone/64
|
||||
## 3.19.1 (March 10, 2022)
|
||||
|
||||
- Minor fixes and improvements
|
||||
|
||||
Minimum: NC 16 Server, Android 6.0 Marshmallow
|
||||
|
||||
For a full list, please see https://github.com/nextcloud/android/milestone/65
|
||||
## 3.19.0 (February 3, 2022)
|
||||
|
||||
- Support external storage in Media page
|
||||
- Connection fallback to IPv4 when IPv6 fails
|
||||
- Many other fixes and improvements
|
||||
|
||||
Minimum: NC 16 Server, Android 6.0 Marshmallow
|
||||
|
||||
For a full list, please see https://github.com/nextcloud/android/milestone/62
|
||||
## 3.18.1 (December 22, 2021)
|
||||
|
||||
- Fix connection bug for usernames with spaces
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# [Nextcloud](https://nextcloud.com) Android app
|
||||
|
||||
[](https://webchat.freenode.net/?channels=nextcloud)
|
||||
[](https://webchat.freenode.net/?channels=nextcloud-mobile)
|
||||
|
||||
|
||||
# Index
|
||||
1. [Guidelines](#guidelines)
|
||||
1. [Issue reporting](#issue-reporting)
|
||||
|
||||
@@ -8,23 +8,23 @@ GEM
|
||||
artifactory (3.0.15)
|
||||
atomos (0.1.3)
|
||||
aws-eventstream (1.2.0)
|
||||
aws-partitions (1.568.0)
|
||||
aws-sdk-core (3.130.0)
|
||||
aws-partitions (1.541.0)
|
||||
aws-sdk-core (3.124.0)
|
||||
aws-eventstream (~> 1, >= 1.0.2)
|
||||
aws-partitions (~> 1, >= 1.525.0)
|
||||
aws-sigv4 (~> 1.1)
|
||||
jmespath (~> 1.0)
|
||||
aws-sdk-kms (1.55.0)
|
||||
aws-sdk-core (~> 3, >= 3.127.0)
|
||||
aws-sdk-kms (1.52.0)
|
||||
aws-sdk-core (~> 3, >= 3.122.0)
|
||||
aws-sigv4 (~> 1.1)
|
||||
aws-sdk-s3 (1.113.0)
|
||||
aws-sdk-core (~> 3, >= 3.127.0)
|
||||
aws-sdk-s3 (1.109.0)
|
||||
aws-sdk-core (~> 3, >= 3.122.0)
|
||||
aws-sdk-kms (~> 1)
|
||||
aws-sigv4 (~> 1.4)
|
||||
aws-sigv4 (1.4.0)
|
||||
aws-eventstream (~> 1, >= 1.0.2)
|
||||
babosa (1.0.4)
|
||||
claide (1.1.0)
|
||||
claide (1.0.3)
|
||||
colored (1.2)
|
||||
colored2 (3.1.2)
|
||||
commander (4.6.0)
|
||||
@@ -36,18 +36,17 @@ GEM
|
||||
unf (>= 0.0.5, < 1.0.0)
|
||||
dotenv (2.7.6)
|
||||
emoji_regex (3.2.3)
|
||||
excon (0.92.1)
|
||||
faraday (1.10.0)
|
||||
excon (0.89.0)
|
||||
faraday (1.8.0)
|
||||
faraday-em_http (~> 1.0)
|
||||
faraday-em_synchrony (~> 1.0)
|
||||
faraday-excon (~> 1.1)
|
||||
faraday-httpclient (~> 1.0)
|
||||
faraday-multipart (~> 1.0)
|
||||
faraday-httpclient (~> 1.0.1)
|
||||
faraday-net_http (~> 1.0)
|
||||
faraday-net_http_persistent (~> 1.0)
|
||||
faraday-net_http_persistent (~> 1.1)
|
||||
faraday-patron (~> 1.0)
|
||||
faraday-rack (~> 1.0)
|
||||
faraday-retry (~> 1.0)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
ruby2_keywords (>= 0.0.4)
|
||||
faraday-cookie_jar (0.0.7)
|
||||
faraday (>= 0.8.0)
|
||||
@@ -56,17 +55,14 @@ GEM
|
||||
faraday-em_synchrony (1.0.0)
|
||||
faraday-excon (1.1.0)
|
||||
faraday-httpclient (1.0.1)
|
||||
faraday-multipart (1.0.3)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
faraday-net_http (1.0.1)
|
||||
faraday-net_http_persistent (1.2.0)
|
||||
faraday-patron (1.0.0)
|
||||
faraday-rack (1.0.0)
|
||||
faraday-retry (1.0.3)
|
||||
faraday_middleware (1.2.0)
|
||||
faraday (~> 1.0)
|
||||
fastimage (2.2.6)
|
||||
fastlane (2.205.0)
|
||||
fastimage (2.2.5)
|
||||
fastlane (2.199.0)
|
||||
CFPropertyList (>= 2.3, < 4.0.0)
|
||||
addressable (>= 2.8, < 3.0.0)
|
||||
artifactory (~> 3.0)
|
||||
@@ -105,11 +101,11 @@ GEM
|
||||
xcodeproj (>= 1.13.0, < 2.0.0)
|
||||
xcpretty (~> 0.3.0)
|
||||
xcpretty-travis-formatter (>= 0.0.3)
|
||||
fastlane-plugin-huawei_appgallery_connect (1.0.18)
|
||||
fastlane-plugin-huawei_appgallery_connect (1.0.17)
|
||||
gh_inspector (1.1.3)
|
||||
google-apis-androidpublisher_v3 (0.16.0)
|
||||
google-apis-androidpublisher_v3 (0.14.0)
|
||||
google-apis-core (>= 0.4, < 2.a)
|
||||
google-apis-core (0.4.2)
|
||||
google-apis-core (0.4.1)
|
||||
addressable (~> 2.5, >= 2.5.1)
|
||||
googleauth (>= 0.16.2, < 2.a)
|
||||
httpclient (>= 2.8.1, < 3.a)
|
||||
@@ -118,11 +114,11 @@ GEM
|
||||
retriable (>= 2.0, < 4.a)
|
||||
rexml
|
||||
webrick
|
||||
google-apis-iamcredentials_v1 (0.10.0)
|
||||
google-apis-iamcredentials_v1 (0.9.0)
|
||||
google-apis-core (>= 0.4, < 2.a)
|
||||
google-apis-playcustomapp_v1 (0.7.0)
|
||||
google-apis-playcustomapp_v1 (0.6.0)
|
||||
google-apis-core (>= 0.4, < 2.a)
|
||||
google-apis-storage_v1 (0.11.0)
|
||||
google-apis-storage_v1 (0.10.0)
|
||||
google-apis-core (>= 0.4, < 2.a)
|
||||
google-cloud-core (1.6.0)
|
||||
google-cloud-env (~> 1.0)
|
||||
@@ -130,7 +126,7 @@ GEM
|
||||
google-cloud-env (1.5.0)
|
||||
faraday (>= 0.17.3, < 2.0)
|
||||
google-cloud-errors (1.2.0)
|
||||
google-cloud-storage (1.36.1)
|
||||
google-cloud-storage (1.35.0)
|
||||
addressable (~> 2.8)
|
||||
digest-crc (~> 0.4)
|
||||
google-apis-iamcredentials_v1 (~> 0.1)
|
||||
@@ -138,8 +134,8 @@ GEM
|
||||
google-cloud-core (~> 1.6)
|
||||
googleauth (>= 0.16.2, < 2.a)
|
||||
mini_mime (~> 1.0)
|
||||
googleauth (1.1.2)
|
||||
faraday (>= 0.17.3, < 3.a)
|
||||
googleauth (1.1.0)
|
||||
faraday (>= 0.17.3, < 2.0)
|
||||
jwt (>= 1.4, < 3.0)
|
||||
memoist (~> 0.16)
|
||||
multi_json (~> 1.11)
|
||||
@@ -149,7 +145,7 @@ GEM
|
||||
http-cookie (1.0.4)
|
||||
domain_name (~> 0.5)
|
||||
httpclient (2.8.3)
|
||||
jmespath (1.6.1)
|
||||
jmespath (1.4.0)
|
||||
json (2.6.1)
|
||||
jwt (2.3.0)
|
||||
memoist (0.16.2)
|
||||
@@ -174,9 +170,9 @@ GEM
|
||||
ruby2_keywords (0.0.5)
|
||||
rubyzip (2.3.2)
|
||||
security (0.1.3)
|
||||
signet (0.16.1)
|
||||
signet (0.16.0)
|
||||
addressable (~> 2.8)
|
||||
faraday (>= 0.17.5, < 3.0)
|
||||
faraday (>= 0.17.3, < 2.0)
|
||||
jwt (>= 1.5, < 3.0)
|
||||
multi_json (~> 1.10)
|
||||
simctl (1.6.8)
|
||||
@@ -193,7 +189,7 @@ GEM
|
||||
uber (0.1.0)
|
||||
unf (0.1.4)
|
||||
unf_ext
|
||||
unf_ext (0.0.8.1)
|
||||
unf_ext (0.0.8)
|
||||
unicode-display_width (1.8.0)
|
||||
webrick (1.7.0)
|
||||
word_wrap (1.0.0)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# [Nextcloud](https://nextcloud.com) Android app :iphone:
|
||||
|
||||
[](https://drone.nextcloud.com/nextcloud/android) [](https://www.codacy.com/app/Nextcloud/android?utm_source=github.com&utm_medium=referral&utm_content=nextcloud/android&utm_campaign=Badge_Grade) [](https://github.com/nextcloud/android/releases/latest)
|
||||
[](https://drone.nextcloud.com/nextcloud/android) [](https://www.codacy.com/app/Nextcloud/android?utm_source=github.com&utm_medium=referral&utm_content=nextcloud/android&utm_campaign=Badge_Grade) [](https://github.com/nextcloud/android/releases/latest) [](https://webchat.freenode.net/?channels=nextcloud-mobile)
|
||||
|
||||
[<img src="https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png"
|
||||
alt="Download from Google Play"
|
||||
@@ -16,6 +16,7 @@
|
||||
## How to contribute :rocket:
|
||||
If you want to [contribute](https://nextcloud.com/contribute/) to Nextcloud, you are very welcome:
|
||||
|
||||
- on our IRC channels [](https://webchat.freenode.net/?channels=nextcloud) and [](https://webchat.freenode.net/?channels=nextcloud-mobile) on freenode
|
||||
- our forum at https://help.nextcloud.com
|
||||
- for translations of the app on [Transifex](https://www.transifex.com/nextcloud/nextcloud/android/)
|
||||
- opening issues and PRs (including a corresponding issue)
|
||||
@@ -74,7 +75,7 @@ or
|
||||
|
||||
## Support :rescue_worker_helmet:
|
||||
|
||||
If you need assistance or want to ask a question about the Android app, you are welcome to [ask for support](https://help.nextcloud.com/c/clients/android) in our Forums. If you have found a bug, feel free to [open a new Issue on GitHub](https://github.com/nextcloud/android/issues). Keep in mind, that this repository only manages the Android app. If you find bugs or have problems with the server/backend, you should ask the [Nextcloud server team](https://github.com/nextcloud/server) for help!
|
||||
If you need assistance or want to ask a question about the Android app, you are welcome to [ask for support](https://help.nextcloud.com/c/clients/android) in our Forums or the [IRC-Channel](https://webchat.freenode.net/?channels=nextcloud-mobile). If you have found a bug, feel free to [open a new Issue on GitHub](https://github.com/nextcloud/android/issues). Keep in mind, that this repository only manages the Android app. If you find bugs or have problems with the server/backend, you should ask the [Nextcloud server team](https://github.com/nextcloud/server) for help!
|
||||
|
||||
## Remarks :scroll:
|
||||
|
||||
|
||||
@@ -89,16 +89,20 @@ The app is currently equipped to be built with three flavours:
|
||||
#### 1. Direct usage of library project
|
||||
|
||||
This is handy if one wants to make changes both to files app and library:
|
||||
|
||||
- Add the following to `settings.gradle`:
|
||||
```groovy
|
||||
includeBuild('[path to library clone]') {
|
||||
dependencySubstitution {
|
||||
substitute module('com.github.nextcloud:android-library') using project(':library')
|
||||
- in files app root: ln -s $pathToLibraryProject nextcloud-android-library
|
||||
- uncomment in build.gradle:
|
||||
- `// implementation project('nextcloud-android-library')`
|
||||
- comment in build.gradle:
|
||||
```
|
||||
implementation ("com.github.nextcloud:android-library:$androidLibraryVersion") {
|
||||
exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version
|
||||
}
|
||||
}
|
||||
```
|
||||
- Sync project with gradle files
|
||||
```
|
||||
- comment in settings.gradle:
|
||||
- `include ':'`
|
||||
- add in settings.gradle:
|
||||
- `include 'nextcloud-android-library'`
|
||||
- sync project with gradle files
|
||||
|
||||
Now every change in library can be directly used in files app.
|
||||
|
||||
|
||||
@@ -43,6 +43,18 @@ The third party software included and used by this project is:
|
||||
The library is included in the Nextcloud client APK.
|
||||
See http://jackrabbit.apache.org/
|
||||
|
||||
* TouchImageView, 1.2.0. commit 6dbeac4f11936185ba374c73144ac431c23c9aab
|
||||
Copyright (c) 2014 Michael Ortiz
|
||||
Licensed under MIT License
|
||||
This library is in the source code.
|
||||
See https://github.com/MikeOrtiz/TouchImageView
|
||||
|
||||
* floatingactionbutton 1.10.21.
|
||||
Copyright (c) 2014 Jerzy Chalupski
|
||||
Licensed under Apache License, Version 2.0.
|
||||
The library is included in the Nextcloud client APK.
|
||||
See https://github.com/futuresimple/android-floating-action-button
|
||||
|
||||
* AndroidSVG 1.2.1.
|
||||
Copyright (c) 2014 Paul LeBeau
|
||||
Licensed under Apache License, Version 2.0.
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
/build
|
||||
@@ -1,431 +0,0 @@
|
||||
import com.github.spotbugs.snom.SpotBugsTask
|
||||
import org.gradle.internal.jvm.Jvm
|
||||
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.1.2'
|
||||
classpath 'com.hiya:jacoco-android:0.2'
|
||||
classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.6'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.19.0"
|
||||
classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
|
||||
classpath 'com.karumi:shot:5.13.0'
|
||||
classpath "org.jacoco:org.jacoco.core:$jacoco_version"
|
||||
classpath "org.jacoco:org.jacoco.report:$jacoco_version"
|
||||
classpath "org.jacoco:org.jacoco.agent:$jacoco_version"
|
||||
classpath "org.jlleitschuh.gradle:ktlint-gradle:10.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
apply plugin: 'kotlin-parcelize'
|
||||
apply plugin: 'checkstyle'
|
||||
apply plugin: 'pmd'
|
||||
apply plugin: 'com.hiya.jacoco-android'
|
||||
apply plugin: 'com.github.spotbugs'
|
||||
apply plugin: 'io.gitlab.arturbosch.detekt'
|
||||
apply plugin: 'shot'
|
||||
apply plugin: "org.jlleitschuh.gradle.ktlint"
|
||||
|
||||
println "Gradle uses Java ${Jvm.current()}"
|
||||
|
||||
configurations {
|
||||
all {
|
||||
exclude group: 'org.jetbrains', module: 'annotations-java5' // via prism4j, already using annotations explicitly
|
||||
|
||||
// check for updates every build
|
||||
resolutionStrategy {
|
||||
cacheChangingModulesFor 0, 'seconds'
|
||||
exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
configurations.configureEach {
|
||||
resolutionStrategy.eachDependency {
|
||||
if (requested.group == "org.checkerframework" && requested.name != "checker-compat-qual") {
|
||||
useVersion(checkerVersion)
|
||||
because("https://github.com/google/ExoPlayer/issues/10007")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// semantic versioning for version code
|
||||
def versionMajor = 3
|
||||
def versionMinor = 20
|
||||
def versionPatch = 2
|
||||
def versionBuild = 90 // 0-50=Alpha / 51-98=RC / 90-99=stable
|
||||
|
||||
|
||||
def ndkEnv = new HashMap<String, String>()
|
||||
file("$project.rootDir/ndk.env").readLines().each() {
|
||||
def (key, value) = it.tokenize('=')
|
||||
ndkEnv.put(key, value)
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
compileSdkVersion 31
|
||||
// install this NDK version and Cmake to produce smaller APKs. Build will still work if not installed
|
||||
ndkVersion "${ndkEnv.get("NDK_VERSION")}"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 30
|
||||
|
||||
buildConfigField 'boolean', 'CI', ciBuild.toString()
|
||||
|
||||
// arguments to be passed to functional tests
|
||||
testInstrumentationRunner "com.nextcloud.client.ScreenshotTestRunner"
|
||||
testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
|
||||
testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
|
||||
testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
|
||||
testInstrumentationRunnerArguments disableAnalytics: 'true'
|
||||
|
||||
multiDexEnabled true
|
||||
|
||||
versionCode versionMajor * 10000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
|
||||
|
||||
if (versionBuild > 89) {
|
||||
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
|
||||
} else if (versionBuild > 50) {
|
||||
versionName "${versionMajor}.${versionMinor}.${versionPatch} RC" + (versionBuild - 50)
|
||||
} else {
|
||||
versionName "${versionMajor}.${versionMinor}.${versionPatch} Alpha" + (versionBuild + 1)
|
||||
}
|
||||
|
||||
// adapt structure from Eclipse to Gradle/Android Studio expectations;
|
||||
// see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
|
||||
|
||||
flavorDimensions "default"
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
testCoverageEnabled (project.hasProperty('coverage'))
|
||||
}
|
||||
}
|
||||
|
||||
productFlavors {
|
||||
// used for f-droid
|
||||
generic {
|
||||
applicationId 'com.nextcloud.client'
|
||||
dimension "default"
|
||||
}
|
||||
|
||||
gplay {
|
||||
applicationId 'com.nextcloud.client'
|
||||
dimension "default"
|
||||
}
|
||||
|
||||
huawei {
|
||||
applicationId 'com.nextcloud.client'
|
||||
dimension "default"
|
||||
}
|
||||
|
||||
versionDev {
|
||||
applicationId "com.nextcloud.android.beta"
|
||||
dimension "default"
|
||||
versionCode 20220322
|
||||
versionName "20220322"
|
||||
}
|
||||
|
||||
qa {
|
||||
applicationId "com.nextcloud.android.qa"
|
||||
dimension "default"
|
||||
versionCode 1
|
||||
versionName "1"
|
||||
}
|
||||
}
|
||||
|
||||
testOptions {
|
||||
unitTests.returnDefaultValues = true
|
||||
animationsDisabled true
|
||||
}
|
||||
}
|
||||
|
||||
// adapt structure from Eclipse to Gradle/Android Studio expectations;
|
||||
// see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
|
||||
packagingOptions {
|
||||
resources {
|
||||
excludes += ['META-INF/LICENSE.txt', 'META-INF/LICENSE']
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("checkstyle", Checkstyle) {
|
||||
configFile = file("${rootProject.projectDir}/checkstyle.xml")
|
||||
configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
|
||||
source 'src'
|
||||
include '**/*.java'
|
||||
exclude '**/gen/**'
|
||||
classpath = files()
|
||||
}
|
||||
|
||||
tasks.register("pmd", Pmd) {
|
||||
ruleSetFiles = files("${project.rootDir}/ruleset.xml")
|
||||
ignoreFailures = true // should continue checking
|
||||
ruleSets = []
|
||||
|
||||
source 'src'
|
||||
include '**/*.java'
|
||||
exclude '**/gen/**'
|
||||
|
||||
reports {
|
||||
xml.enabled = false
|
||||
html.enabled = true
|
||||
xml {
|
||||
destination = file("$project.buildDir/reports/pmd/pmd.xml")
|
||||
}
|
||||
html {
|
||||
destination = file("$project.buildDir/reports/pmd/pmd.html")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
check.dependsOn 'checkstyle', 'spotbugsGplayDebug', 'pmd', 'lint', 'ktlintCheck', 'detekt'
|
||||
|
||||
buildFeatures {
|
||||
dataBinding true
|
||||
viewBinding true
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
lint {
|
||||
abortOnError false
|
||||
checkGeneratedSources true
|
||||
disable 'MissingTranslation', 'GradleDependency', 'VectorPath', 'IconMissingDensityFolder', 'IconDensities', 'GoogleAppIndexingWarning', 'MissingDefaultResource', 'InvalidPeriodicWorkRequestInterval', 'StringFormatInvalid', 'MissingQuantity'
|
||||
htmlOutput file("$project.buildDir/reports/lint/lint.html")
|
||||
htmlReport true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// dependencies for app building
|
||||
implementation 'androidx.multidex:multidex:2.0.1'
|
||||
// implementation project('nextcloud-android-library')
|
||||
implementation ("com.github.nextcloud:android-library:$androidLibraryVersion") {
|
||||
exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version
|
||||
}
|
||||
|
||||
compileOnly 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' // remove after entire switch to lib v2
|
||||
implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
|
||||
implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.5' // remove after entire switch to lib v2
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
implementation 'com.jakewharton:disklrucache:2.0.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||
implementation 'androidx.webkit:webkit:1.4.0'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
implementation 'androidx.exifinterface:exifinterface:1.3.3'
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
|
||||
implementation "androidx.work:work-runtime:$workRuntime"
|
||||
implementation "androidx.work:work-runtime-ktx:$workRuntime"
|
||||
implementation "androidx.fragment:fragment-ktx:1.4.1"
|
||||
implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
|
||||
compileOnly 'com.google.code.findbugs:annotations:3.0.1u2'
|
||||
implementation 'commons-io:commons-io:2.11.0'
|
||||
implementation 'org.greenrobot:eventbus:3.3.1'
|
||||
implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
|
||||
implementation 'org.lukhnos:nnio:0.2'
|
||||
implementation 'org.bouncycastle:bcpkix-jdk15to18:1.70'
|
||||
implementation 'com.google.code.gson:gson:2.9.0'
|
||||
implementation 'com.afollestad:sectioned-recyclerview:0.5.0'
|
||||
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
|
||||
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24'
|
||||
implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.4' // 'com.github.blikoon:QRCodeScanner:0.1.2'
|
||||
implementation 'com.google.android.flexbox:flexbox:3.0.0'
|
||||
implementation('com.github.bumptech.glide:glide:3.8.0') {
|
||||
exclude group: "com.android.support"
|
||||
}
|
||||
implementation 'com.caverock:androidsvg:1.4'
|
||||
implementation 'androidx.annotation:annotation:1.3.0'
|
||||
implementation 'com.vanniktech:emoji-google:0.8.0'
|
||||
|
||||
implementation "com.github.cotechde.hwsecurity:hwsecurity-fido:$fidoVersion"
|
||||
implementation "com.github.cotechde.hwsecurity:hwsecurity-fido2:$fidoVersion"
|
||||
|
||||
// document scanner not available on FDroid (generic) due to OpenCV binaries
|
||||
gplayImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
|
||||
huaweiImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
|
||||
qaImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
|
||||
versionDevImplementation "com.github.zynkware:Document-Scanning-Android-SDK:$documentScannerVersion"
|
||||
|
||||
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.11.0'
|
||||
spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
|
||||
|
||||
implementation "com.google.dagger:dagger:$daggerVersion"
|
||||
implementation "com.google.dagger:dagger-android:$daggerVersion"
|
||||
implementation "com.google.dagger:dagger-android-support:$daggerVersion"
|
||||
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
|
||||
kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
|
||||
|
||||
implementation 'org.conscrypt:conscrypt-android:2.5.2'
|
||||
|
||||
implementation "com.google.android.exoplayer:exoplayer:$exoplayerVersion"
|
||||
implementation "com.google.android.exoplayer:extension-okhttp:$exoplayerVersion"
|
||||
|
||||
implementation 'me.zhanghai.android.fastscroll:library:1.1.8'
|
||||
|
||||
// Shimmer animation
|
||||
implementation 'io.github.elye:loaderviewlibrary:3.0.0'
|
||||
|
||||
// dependencies for markdown rendering
|
||||
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"
|
||||
|
||||
implementation ('org.mnode.ical4j:ical4j:1.0.8') {
|
||||
['org.apache.commons','commons-logging'].each {
|
||||
exclude group: "$it"
|
||||
}
|
||||
}
|
||||
|
||||
if (project.hasProperty("leakCanary")) {
|
||||
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
|
||||
}
|
||||
|
||||
// dependencies for local unit tests
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
testImplementation "org.mockito:mockito-core:$mockitoVersion"
|
||||
testImplementation "androidx.test:core:$androidxTestVersion"
|
||||
testImplementation "org.powermock:powermock-core:$powermockVersion"
|
||||
testImplementation "org.powermock:powermock-module-junit4:$powermockVersion"
|
||||
testImplementation "org.powermock:powermock-api-mockito2:$powermockVersion"
|
||||
testImplementation 'org.json:json:20220320'
|
||||
testImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion"
|
||||
testImplementation 'androidx.arch.core:core-testing:2.1.0'
|
||||
testImplementation "io.mockk:mockk:$mockkVersion"
|
||||
testImplementation "io.mockk:mockk-android:$mockkVersion"
|
||||
|
||||
// dependencies for instrumented tests
|
||||
// JUnit4 Rules
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation "androidx.test:rules:$androidxTestVersion"
|
||||
// Android JUnit Runner
|
||||
androidTestImplementation "androidx.test:runner:$androidxTestVersion"
|
||||
androidTestUtil "androidx.test:orchestrator:$androidxTestVersion"
|
||||
androidTestImplementation "androidx.test:core-ktx:$androidxTestVersion"
|
||||
|
||||
// Espresso
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
|
||||
|
||||
// Mocking support
|
||||
androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
|
||||
androidTestImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion"
|
||||
androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
|
||||
androidTestImplementation("org.mockito:mockito-android:$mockitoVersion") {
|
||||
exclude group: "net.bytebuddy", module: "byte-buddy-android"
|
||||
}
|
||||
androidTestImplementation "net.bytebuddy:byte-buddy:$byteBuddyVersion"
|
||||
androidTestImplementation "net.bytebuddy:byte-buddy-android:$byteBuddyVersion"
|
||||
androidTestImplementation "io.mockk:mockk-android:$mockkVersion"
|
||||
androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'
|
||||
androidTestImplementation "com.facebook.testing.screenshot:core:0.15.0"
|
||||
|
||||
// UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
|
||||
// androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
|
||||
// fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
|
||||
//androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
|
||||
androidTestImplementation 'tools.fastlane:screengrab:2.1.1'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
implementation "com.github.stateless4j:stateless4j:2.6.0"
|
||||
|
||||
// upon each update first test: new registration, receive push
|
||||
gplayImplementation "com.google.firebase:firebase-messaging:23.0.2"
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
resolutionStrategy{
|
||||
cacheChangingModulesFor 0, 'seconds'
|
||||
force 'org.objenesis:objenesis:2.6'
|
||||
eachDependency { details ->
|
||||
if ('org.jacoco' == details.requested.group) {
|
||||
details.useVersion "$jacoco_version"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
tasks.withType(Test) {
|
||||
// increased logging for tests
|
||||
testLogging {
|
||||
events "passed", "skipped", "failed"
|
||||
}
|
||||
}
|
||||
|
||||
android.applicationVariants.all { variant ->
|
||||
variant.outputs.all { output ->
|
||||
outputFileName = "${output.baseName}-${variant.versionCode}.apk"
|
||||
}
|
||||
}
|
||||
|
||||
task installGitHooks(type: Copy, group: "development") {
|
||||
description = "Install git hooks"
|
||||
from("${project.rootDir}/scripts/hooks") {
|
||||
include '*'
|
||||
}
|
||||
into "${project.rootDir}/.git/hooks"
|
||||
}
|
||||
|
||||
detekt {
|
||||
reports {
|
||||
xml {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
config = files("detekt.yml")
|
||||
}
|
||||
|
||||
shot {
|
||||
showOnlyFailingTestsInReports = ciBuild
|
||||
// CI environment renders some shadows slightly different from local VMs
|
||||
// Add a 0.5% tolerance to account for that
|
||||
tolerance = ciBuild ? 0.5: 0
|
||||
}
|
||||
|
||||
jacoco {
|
||||
toolVersion = "$jacoco_version"
|
||||
}
|
||||
|
||||
spotbugs {
|
||||
ignoreFailures = true // should continue checking
|
||||
effort = "max"
|
||||
reportLevel = "medium"
|
||||
}
|
||||
|
||||
tasks.withType(SpotBugsTask){task ->
|
||||
String variantNameCap = task.name.replace("spotbugs", "")
|
||||
String variantName = variantNameCap.substring(0, 1).toLowerCase() + variantNameCap.substring(1)
|
||||
|
||||
dependsOn "compile${variantNameCap}Sources"
|
||||
|
||||
excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
|
||||
classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
|
||||
reports {
|
||||
xml.enabled = false
|
||||
html {
|
||||
enabled = true
|
||||
destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 26 KiB |
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.datamodel
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class FileDataStorageManagerContentResolverIT : FileDataStorageManagerIT() {
|
||||
companion object {
|
||||
private const val MANY_FILES_AMOUNT = 5000
|
||||
}
|
||||
|
||||
override fun before() {
|
||||
sut = FileDataStorageManager(user, targetContext.contentResolver)
|
||||
super.before()
|
||||
}
|
||||
|
||||
/**
|
||||
* only on FileDataStorageManager
|
||||
*/
|
||||
@Test
|
||||
fun testFolderWithManyFiles() {
|
||||
// create folder
|
||||
val folderA = OCFile("/folderA/")
|
||||
folderA.setFolder().parentId = sut.getFileByDecryptedRemotePath("/")!!.fileId
|
||||
sut.saveFile(folderA)
|
||||
Assert.assertTrue(sut.fileExists("/folderA/"))
|
||||
Assert.assertEquals(0, sut.getFolderContent(folderA, false).size)
|
||||
val folderAId = sut.getFileByDecryptedRemotePath("/folderA/")!!.fileId
|
||||
|
||||
// create files
|
||||
val newFiles = (1..MANY_FILES_AMOUNT).map {
|
||||
val file = OCFile("/folderA/file$it")
|
||||
file.parentId = folderAId
|
||||
sut.saveFile(file)
|
||||
|
||||
val storedFile = sut.getFileByDecryptedRemotePath("/folderA/file$it")
|
||||
Assert.assertNotNull(storedFile)
|
||||
storedFile
|
||||
}
|
||||
|
||||
// save files in folder
|
||||
sut.saveFolder(
|
||||
folderA,
|
||||
newFiles,
|
||||
ArrayList()
|
||||
)
|
||||
// check file count is correct
|
||||
Assert.assertEquals(MANY_FILES_AMOUNT, sut.getFolderContent(folderA, false).size)
|
||||
}
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.files
|
||||
|
||||
import android.view.Menu
|
||||
import androidx.appcompat.view.menu.MenuBuilder
|
||||
import androidx.test.core.app.launchActivity
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.nextcloud.client.TestActivity
|
||||
import com.nextcloud.client.account.User
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.files.services.FileDownloader
|
||||
import com.owncloud.android.files.services.FileUploader
|
||||
import com.owncloud.android.lib.resources.files.model.FileLockType
|
||||
import com.owncloud.android.lib.resources.status.CapabilityBooleanType
|
||||
import com.owncloud.android.lib.resources.status.OCCapability
|
||||
import com.owncloud.android.services.OperationsService
|
||||
import com.owncloud.android.ui.activity.ComponentsGetter
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class FileMenuFilterIT : AbstractIT() {
|
||||
|
||||
@MockK
|
||||
private lateinit var mockComponentsGetter: ComponentsGetter
|
||||
|
||||
@MockK
|
||||
private lateinit var mockStorageManager: FileDataStorageManager
|
||||
|
||||
@MockK
|
||||
private lateinit var mockFileUploaderBinder: FileUploader.FileUploaderBinder
|
||||
|
||||
@MockK
|
||||
private lateinit var mockFileDownloaderBinder: FileDownloader.FileDownloaderBinder
|
||||
|
||||
@MockK
|
||||
private lateinit var mockOperationsServiceBinder: OperationsService.OperationsServiceBinder
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockKAnnotations.init(this)
|
||||
every { mockFileUploaderBinder.isUploading(any(), any()) } returns false
|
||||
every { mockComponentsGetter.fileUploaderBinder } returns mockFileUploaderBinder
|
||||
every { mockFileDownloaderBinder.isDownloading(any(), any()) } returns false
|
||||
every { mockComponentsGetter.fileDownloaderBinder } returns mockFileDownloaderBinder
|
||||
every { mockOperationsServiceBinder.isSynchronizing(any(), any()) } returns false
|
||||
every { mockComponentsGetter.operationsServiceBinder } returns mockOperationsServiceBinder
|
||||
}
|
||||
|
||||
@Test
|
||||
fun filter_noLockingCapability_lockItemsInvisible() {
|
||||
val capability = OCCapability().apply {
|
||||
endToEndEncryption = CapabilityBooleanType.UNKNOWN
|
||||
}
|
||||
|
||||
val file = OCFile("/foo.md")
|
||||
|
||||
testLockingVisibilities(
|
||||
capability,
|
||||
file,
|
||||
ExpectedLockVisibilities(lockFile = false, unlockFile = false, lockedBy = false, lockedUntil = false)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun filter_lockingCapability_fileUnlocked_lockVisible() {
|
||||
val capability = OCCapability().apply {
|
||||
endToEndEncryption = CapabilityBooleanType.UNKNOWN
|
||||
filesLockingVersion = "1.0"
|
||||
}
|
||||
|
||||
val file = OCFile("/foo.md")
|
||||
|
||||
testLockingVisibilities(
|
||||
capability,
|
||||
file,
|
||||
ExpectedLockVisibilities(lockFile = true, unlockFile = false, lockedBy = false, lockedUntil = false)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun filter_lockingCapability_fileLocked_lockedByAndProps() {
|
||||
val capability = OCCapability().apply {
|
||||
endToEndEncryption = CapabilityBooleanType.UNKNOWN
|
||||
filesLockingVersion = "1.0"
|
||||
}
|
||||
|
||||
val file = OCFile("/foo.md").apply {
|
||||
isLocked = true
|
||||
lockType = FileLockType.MANUAL
|
||||
lockOwnerId = user.accountName.split("@")[0]
|
||||
lockOwnerDisplayName = "TEST"
|
||||
lockTimestamp = 1000 // irrelevant
|
||||
lockTimeout = 1000 // irrelevant
|
||||
}
|
||||
|
||||
testLockingVisibilities(
|
||||
capability,
|
||||
file,
|
||||
ExpectedLockVisibilities(lockFile = false, unlockFile = true, lockedBy = true, lockedUntil = true)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun filter_lockingCapability_fileLockedByOthers_lockedByAndProps() {
|
||||
val capability = OCCapability().apply {
|
||||
endToEndEncryption = CapabilityBooleanType.UNKNOWN
|
||||
filesLockingVersion = "1.0"
|
||||
}
|
||||
|
||||
val file = OCFile("/foo.md").apply {
|
||||
isLocked = true
|
||||
lockType = FileLockType.MANUAL
|
||||
lockOwnerId = "A_DIFFERENT_USER"
|
||||
lockOwnerDisplayName = "A_DIFFERENT_USER"
|
||||
lockTimestamp = 1000 // irrelevant
|
||||
lockTimeout = 1000 // irrelevant
|
||||
}
|
||||
testLockingVisibilities(
|
||||
capability,
|
||||
file,
|
||||
ExpectedLockVisibilities(lockFile = false, unlockFile = false, lockedBy = true, lockedUntil = true)
|
||||
)
|
||||
}
|
||||
|
||||
private data class ExpectedLockVisibilities(
|
||||
val lockFile: Boolean,
|
||||
val unlockFile: Boolean,
|
||||
val lockedBy: Boolean,
|
||||
val lockedUntil: Boolean
|
||||
)
|
||||
|
||||
private fun configureCapability(capability: OCCapability) {
|
||||
every { mockStorageManager.getCapability(any<User>()) } returns capability
|
||||
every { mockStorageManager.getCapability(any<String>()) } returns capability
|
||||
every { mockComponentsGetter.storageManager } returns mockStorageManager
|
||||
}
|
||||
|
||||
private fun getMenu(activity: TestActivity): Menu {
|
||||
val inflater = activity.menuInflater
|
||||
val menu = MenuBuilder(activity)
|
||||
inflater.inflate(R.menu.item_file, menu)
|
||||
return menu
|
||||
}
|
||||
|
||||
private fun testLockingVisibilities(
|
||||
capability: OCCapability,
|
||||
file: OCFile,
|
||||
expectedLockVisibilities: ExpectedLockVisibilities
|
||||
) {
|
||||
configureCapability(capability)
|
||||
|
||||
launchActivity<TestActivity>().use {
|
||||
it.onActivity { activity ->
|
||||
val menu = getMenu(activity)
|
||||
|
||||
val sut = FileMenuFilter(file, mockComponentsGetter, activity, true, user)
|
||||
|
||||
sut.filter(menu, false)
|
||||
|
||||
Assert.assertEquals(
|
||||
expectedLockVisibilities.lockFile,
|
||||
menu.findItem(R.id.action_lock_file).isVisible
|
||||
)
|
||||
Assert.assertEquals(
|
||||
expectedLockVisibilities.unlockFile,
|
||||
menu.findItem(R.id.action_unlock_file).isVisible
|
||||
)
|
||||
Assert.assertEquals(
|
||||
expectedLockVisibilities.lockedBy,
|
||||
menu.findItem(R.id.action_locked_by).isVisible
|
||||
)
|
||||
Assert.assertEquals(
|
||||
expectedLockVisibilities.lockedUntil,
|
||||
menu.findItem(R.id.action_locked_until).isVisible
|
||||
)
|
||||
|
||||
// locked by and until should always be disabled, they're not real actions
|
||||
Assert.assertFalse(menu.findItem(R.id.action_locked_by).isEnabled)
|
||||
Assert.assertFalse(menu.findItem(R.id.action_locked_until).isEnabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui
|
||||
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.espresso.Espresso
|
||||
import androidx.test.espresso.action.ViewActions
|
||||
import androidx.test.espresso.matcher.ViewMatchers
|
||||
import androidx.test.espresso.web.sugar.Web
|
||||
import androidx.test.espresso.web.webdriver.DriverAtoms
|
||||
import androidx.test.espresso.web.webdriver.Locator
|
||||
import androidx.test.filters.LargeTest
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.nextcloud.client.GrantStoragePermissionRule
|
||||
import com.nextcloud.client.RetryTestRule
|
||||
import com.nextcloud.client.account.UserAccountManager
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity
|
||||
import org.junit.AfterClass
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@LargeTest
|
||||
class LoginIT : AbstractIT() {
|
||||
@get:Rule
|
||||
val permissionRule = GrantStoragePermissionRule.grant()
|
||||
|
||||
@get:Rule
|
||||
var retryTestRule = RetryTestRule()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
tearDown()
|
||||
ActivityScenario.launch(AuthenticatorActivity::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(InterruptedException::class)
|
||||
@Suppress("MagicNumber")
|
||||
fun login() {
|
||||
val arguments = InstrumentationRegistry.getArguments()
|
||||
val baseUrl = arguments.getString("TEST_SERVER_URL")!!
|
||||
val loginName = arguments.getString("TEST_SERVER_USERNAME")!!
|
||||
val password = arguments.getString("TEST_SERVER_PASSWORD")!!
|
||||
Espresso.onView(ViewMatchers.withId(R.id.login)).perform(ViewActions.click())
|
||||
Espresso.onView(ViewMatchers.withId(R.id.host_url_input)).perform(ViewActions.typeText(baseUrl))
|
||||
Espresso.onView(ViewMatchers.withId(R.id.host_url_input)).perform(ViewActions.typeTextIntoFocusedView("\n"))
|
||||
Thread.sleep(3000)
|
||||
Web.onWebView().forceJavascriptEnabled()
|
||||
|
||||
// click on login
|
||||
Web.onWebView()
|
||||
.withElement(DriverAtoms.findElement(Locator.XPATH, "//p[@id='redirect-link']/a"))
|
||||
.perform(DriverAtoms.webClick())
|
||||
|
||||
// username
|
||||
Web.onWebView()
|
||||
.withElement(DriverAtoms.findElement(Locator.XPATH, "//input[@id='user']"))
|
||||
.perform(DriverAtoms.webKeys(loginName))
|
||||
|
||||
// password
|
||||
Web.onWebView()
|
||||
.withElement(DriverAtoms.findElement(Locator.XPATH, "//input[@id='password']"))
|
||||
.perform(DriverAtoms.webKeys(password))
|
||||
|
||||
// click login
|
||||
Web.onWebView()
|
||||
.withElement(DriverAtoms.findElement(Locator.XPATH, "//input[@type='submit']"))
|
||||
.perform(DriverAtoms.webClick())
|
||||
Thread.sleep(2000)
|
||||
|
||||
// grant access
|
||||
Web.onWebView()
|
||||
.withElement(DriverAtoms.findElement(Locator.XPATH, "//input[@type='submit']"))
|
||||
.perform(DriverAtoms.webClick())
|
||||
Thread.sleep((5 * 1000).toLong())
|
||||
|
||||
// check for account
|
||||
val targetContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val accountManager: UserAccountManager = UserAccountManagerImpl.fromContext(targetContext)
|
||||
Assert.assertEquals(1, accountManager.accounts.size.toLong())
|
||||
val account = accountManager.accounts[0]
|
||||
|
||||
// account.name is loginName@baseUrl (without protocol)
|
||||
Assert.assertEquals(loginName, account.name.split("@".toRegex()).toTypedArray()[0])
|
||||
Assert.assertEquals(
|
||||
baseUrl.split("//".toRegex()).toTypedArray()[1],
|
||||
account.name.split("@".toRegex()).toTypedArray()[1]
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@AfterClass
|
||||
fun tearDown() {
|
||||
val targetContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
val accountManager: UserAccountManager = UserAccountManagerImpl.fromContext(targetContext)
|
||||
if (accountManager.accounts.isNotEmpty()) {
|
||||
accountManager.removeAllAccounts()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.activity
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import com.nextcloud.client.GrantStoragePermissionRule
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.utils.FileStorageUtils
|
||||
import com.owncloud.android.utils.ScreenshotTest
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
class UploadFilesActivityIT : AbstractIT() {
|
||||
@get:Rule
|
||||
var activityRule = IntentsTestRule(UploadFilesActivity::class.java, true, false)
|
||||
|
||||
@get:Rule
|
||||
var permissionRule = GrantStoragePermissionRule.grant()
|
||||
|
||||
private val directories = listOf("A", "B", "C", "D")
|
||||
.map { File("${FileStorageUtils.getTemporalPath(account.name)}${File.separator}$it") }
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
directories.forEach { it.mkdirs() }
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
directories.forEach { it.deleteRecursively() }
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun noneSelected() {
|
||||
val sut: UploadFilesActivity = activityRule.launchActivity(null)
|
||||
|
||||
sut.runOnUiThread {
|
||||
sut.fileListFragment.setFiles(
|
||||
directories +
|
||||
listOf(
|
||||
File("1.txt"),
|
||||
File("2.pdf"),
|
||||
File("3.mp3")
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
waitForIdleSync()
|
||||
shortSleep()
|
||||
|
||||
screenshot(sut)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun localFolderPickerMode() {
|
||||
val sut: UploadFilesActivity = activityRule.launchActivity(
|
||||
Intent().apply {
|
||||
putExtra(
|
||||
UploadFilesActivity.KEY_LOCAL_FOLDER_PICKER_MODE,
|
||||
true
|
||||
)
|
||||
putExtra(
|
||||
UploadFilesActivity.REQUEST_CODE_KEY,
|
||||
FileDisplayActivity.REQUEST_CODE__SELECT_FILES_FROM_FILE_SYSTEM
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
sut.runOnUiThread {
|
||||
sut.fileListFragment.setFiles(
|
||||
directories
|
||||
)
|
||||
}
|
||||
|
||||
waitForIdleSync()
|
||||
|
||||
screenshot(sut)
|
||||
}
|
||||
|
||||
fun fileSelected() {
|
||||
val sut: UploadFilesActivity = activityRule.launchActivity(null)
|
||||
|
||||
// TODO select one
|
||||
|
||||
screenshot(sut)
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
class OCFileListAdapterIT : AbstractIT() {
|
||||
@Test
|
||||
fun testParseMedia() {
|
||||
// empty start
|
||||
storageManager.deleteAllFiles()
|
||||
|
||||
val startDate: Long = 0
|
||||
val endDate: Long = 3642752043
|
||||
assertEquals(0, storageManager.getGalleryItems(startDate, endDate).size)
|
||||
|
||||
// create dummy files
|
||||
OCFile("/test.txt").apply {
|
||||
mimeType = "text/plain"
|
||||
}.let {
|
||||
storageManager.saveFile(it)
|
||||
}
|
||||
|
||||
OCFile("/image.png").apply {
|
||||
mimeType = "image/png"
|
||||
modificationTimestamp = 1000000
|
||||
}.let {
|
||||
storageManager.saveFile(it)
|
||||
}
|
||||
|
||||
OCFile("/image2.png").apply {
|
||||
mimeType = "image/png"
|
||||
modificationTimestamp = 1000050
|
||||
}.let {
|
||||
storageManager.saveFile(it)
|
||||
}
|
||||
|
||||
OCFile("/video.mpg").apply {
|
||||
mimeType = "video/mpg"
|
||||
modificationTimestamp = 1000045
|
||||
}.let {
|
||||
storageManager.saveFile(it)
|
||||
}
|
||||
|
||||
OCFile("/video2.avi").apply {
|
||||
mimeType = "video/avi"
|
||||
modificationTimestamp = endDate + 10
|
||||
}.let {
|
||||
storageManager.saveFile(it)
|
||||
}
|
||||
|
||||
// list of remoteFiles
|
||||
assertEquals(5, storageManager.allFiles.size)
|
||||
assertEquals(3, storageManager.getGalleryItems(startDate, endDate).size)
|
||||
assertEquals(4, storageManager.allGalleryItems.size)
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.preview
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.utils.ScreenshotTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
class PreviewBitmapScreenshotIT : AbstractIT() {
|
||||
|
||||
companion object {
|
||||
private const val PNG_FILE_ASSET = "imageFile.png"
|
||||
}
|
||||
|
||||
@get:Rule
|
||||
val testActivityRule = IntentsTestRule(PreviewBitmapActivity::class.java, true, false)
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showBitmap() {
|
||||
|
||||
val pngFile = getFile(PNG_FILE_ASSET)
|
||||
|
||||
val activity = testActivityRule.launchActivity(
|
||||
Intent().putExtra(
|
||||
PreviewBitmapActivity.EXTRA_BITMAP_PATH,
|
||||
pngFile.absolutePath
|
||||
)
|
||||
)
|
||||
|
||||
shortSleep()
|
||||
waitForIdleSync()
|
||||
|
||||
screenshot(activity)
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.preview.pdf
|
||||
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import com.nextcloud.client.TestActivity
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.utils.ScreenshotTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
class PreviewPdfFragmentScreenshotIT : AbstractIT() {
|
||||
|
||||
companion object {
|
||||
private const val PDF_FILE_ASSET = "test.pdf"
|
||||
}
|
||||
|
||||
@get:Rule
|
||||
val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
|
||||
|
||||
@Test
|
||||
@ScreenshotTest
|
||||
fun showPdf() {
|
||||
val activity = testActivityRule.launchActivity(null)
|
||||
|
||||
val pdfFile = getFile(PDF_FILE_ASSET)
|
||||
val ocFile = OCFile("/test.pdf").apply {
|
||||
storagePath = pdfFile.absolutePath
|
||||
}
|
||||
|
||||
val sut = PreviewPdfFragment.newInstance(ocFile)
|
||||
activity.addFragment(sut)
|
||||
|
||||
while (!sut.lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
shortSleep()
|
||||
}
|
||||
|
||||
activity.runOnUiThread {
|
||||
sut.dismissSnack()
|
||||
}
|
||||
|
||||
shortSleep()
|
||||
waitForIdleSync()
|
||||
|
||||
screenshot(activity)
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<!--
|
||||
~ Nextcloud Android client application
|
||||
~
|
||||
~ @author Álvaro Brey Vilas
|
||||
~ Copyright (C) 2022 Álvaro Brey Vilas
|
||||
~ Copyright (C) 2022 Nextcloud GmbH
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<application>
|
||||
<activity
|
||||
android:name=".ui.activity.AppScanActivity"
|
||||
tools:node="remove" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.activity
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Bundle
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import com.owncloud.android.utils.PermissionUtil
|
||||
import com.zynksoftware.documentscanner.ScanActivity
|
||||
import com.zynksoftware.documentscanner.model.DocumentScannerErrorModel
|
||||
import com.zynksoftware.documentscanner.model.ScannerResults
|
||||
import com.zynksoftware.documentscanner.ui.DocumentScanner
|
||||
|
||||
@Suppress("unused")
|
||||
class AppScanActivity : ScanActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
addFragmentContentLayout()
|
||||
}
|
||||
|
||||
override fun onError(error: DocumentScannerErrorModel) {
|
||||
DisplayUtils.showSnackMessage(this, R.string.error_starting_scan_doc)
|
||||
}
|
||||
|
||||
override fun onSuccess(scannerResults: ScannerResults) {
|
||||
val intent = Intent()
|
||||
|
||||
intent.putExtra(
|
||||
"file",
|
||||
scannerResults.transformedImageFile?.absolutePath ?: scannerResults.croppedImageFile?.absolutePath
|
||||
)
|
||||
|
||||
setResult(Activity.RESULT_OK, intent)
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onClose() {
|
||||
finish()
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val enabled: Boolean = true
|
||||
|
||||
@JvmStatic
|
||||
fun scanFromCamera(activity: Activity, requestCode: Int) {
|
||||
val configuration = DocumentScanner.Configuration()
|
||||
configuration.imageType = Bitmap.CompressFormat.PNG
|
||||
DocumentScanner.init(activity, configuration)
|
||||
val scanIntent = Intent(activity, AppScanActivity::class.java)
|
||||
if (PermissionUtil.checkSelfPermission(activity, Manifest.permission.CAMERA)) {
|
||||
activity.startActivityForResult(scanIntent, requestCode)
|
||||
} else {
|
||||
PermissionUtil.requestCameraPermission(activity, PermissionUtil.PERMISSIONS_SCAN_DOCUMENT)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.activity
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Bundle
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import com.owncloud.android.utils.PermissionUtil
|
||||
import com.zynksoftware.documentscanner.ScanActivity
|
||||
import com.zynksoftware.documentscanner.model.DocumentScannerErrorModel
|
||||
import com.zynksoftware.documentscanner.model.ScannerResults
|
||||
import com.zynksoftware.documentscanner.ui.DocumentScanner
|
||||
|
||||
class AppScanActivity : ScanActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
addFragmentContentLayout()
|
||||
}
|
||||
|
||||
override fun onError(error: DocumentScannerErrorModel) {
|
||||
DisplayUtils.showSnackMessage(this, R.string.error_starting_scan_doc)
|
||||
}
|
||||
|
||||
override fun onSuccess(scannerResults: ScannerResults) {
|
||||
val intent = Intent()
|
||||
|
||||
intent.putExtra(
|
||||
"file",
|
||||
scannerResults.transformedImageFile?.absolutePath ?: scannerResults.croppedImageFile?.absolutePath
|
||||
)
|
||||
|
||||
setResult(Activity.RESULT_OK, intent)
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onClose() {
|
||||
finish()
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val enabled: Boolean = true
|
||||
|
||||
@JvmStatic
|
||||
fun scanFromCamera(activity: Activity, requestCode: Int) {
|
||||
val configuration = DocumentScanner.Configuration()
|
||||
configuration.imageType = Bitmap.CompressFormat.PNG
|
||||
DocumentScanner.init(activity, configuration)
|
||||
val scanIntent = Intent(activity, AppScanActivity::class.java)
|
||||
if (PermissionUtil.checkSelfPermission(activity, Manifest.permission.CAMERA)) {
|
||||
activity.startActivityForResult(scanIntent, requestCode)
|
||||
} else {
|
||||
PermissionUtil.requestCameraPermission(activity, PermissionUtil.PERMISSIONS_SCAN_DOCUMENT)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.activity
|
||||
|
||||
import android.view.View
|
||||
|
||||
/**
|
||||
* Activity providing information about ways to participate in the app's development.
|
||||
*/
|
||||
class HuaweiCommunityActivity : CommunityActivity() {
|
||||
override fun setupContent() {
|
||||
super.setupContent()
|
||||
binding.communityReleaseCandidatePlaystore.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.android.files
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.resources.files.model.FileLockType
|
||||
|
||||
object FileLockingHelper {
|
||||
/**
|
||||
* Checks whether the given `userId` can unlock the [OCFile].
|
||||
*/
|
||||
@JvmStatic
|
||||
fun canUserUnlockFile(userId: String, file: OCFile): Boolean {
|
||||
if (!file.isLocked || file.lockOwnerId == null || file.lockType != FileLockType.MANUAL) {
|
||||
return false
|
||||
}
|
||||
return file.lockOwnerId == userId
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.android.files
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.os.Build
|
||||
import android.text.style.StyleSpan
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.nextcloud.utils.TimeConstants
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.resources.files.model.FileLockType
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
|
||||
/**
|
||||
* Customizes a Menu to show locking information
|
||||
*/
|
||||
class FileLockingMenuCustomization(val context: Context) {
|
||||
fun customizeMenu(menu: Menu, file: OCFile) {
|
||||
if (file.isLocked) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
menu.setGroupDividerEnabled(true)
|
||||
}
|
||||
menu.findItem(R.id.action_locked_by).title = getLockedByText(file)
|
||||
showLockedUntil(menu, file)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getLockedByText(file: OCFile): CharSequence {
|
||||
val username = file.lockOwnerDisplayName ?: file.lockOwnerId
|
||||
val resource = when (file.lockType) {
|
||||
FileLockType.COLLABORATIVE -> R.string.locked_by_app
|
||||
else -> R.string.locked_by
|
||||
}
|
||||
return DisplayUtils.createTextWithSpan(
|
||||
context.getString(resource, username),
|
||||
username,
|
||||
StyleSpan(Typeface.BOLD)
|
||||
)
|
||||
}
|
||||
|
||||
private fun showLockedUntil(menu: Menu, file: OCFile) {
|
||||
val lockedUntil: MenuItem = menu.findItem(R.id.action_locked_until)
|
||||
if (file.lockTimestamp == 0L || file.lockTimeout == 0L) {
|
||||
lockedUntil.isVisible = false
|
||||
} else {
|
||||
lockedUntil.title =
|
||||
context.getString(R.string.lock_expiration_info, getExpirationRelativeText(file))
|
||||
lockedUntil.isVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun getExpirationRelativeText(file: OCFile): CharSequence? {
|
||||
val expirationTimestamp = (file.lockTimestamp + file.lockTimeout) * TimeConstants.MILLIS_PER_SECOND
|
||||
return DisplayUtils.getRelativeTimestamp(context, expirationTimestamp, true)
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.android.files
|
||||
|
||||
import android.content.Context
|
||||
import android.view.ContextThemeWrapper
|
||||
import android.view.View
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import com.owncloud.android.R
|
||||
|
||||
/**
|
||||
* This is a [PopupMenu] with grayed out disabled elements
|
||||
*/
|
||||
class ThemedPopupMenu(
|
||||
context: Context,
|
||||
anchor: View
|
||||
) : PopupMenu(wrapContext(context), anchor) {
|
||||
|
||||
companion object {
|
||||
private fun wrapContext(context: Context): Context =
|
||||
ContextThemeWrapper(context, R.style.Nextcloud_Widget_PopupMenu)
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.client.media
|
||||
|
||||
import android.content.Context
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource
|
||||
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory
|
||||
import com.google.android.exoplayer2.upstream.DefaultDataSource
|
||||
import com.nextcloud.common.NextcloudClient
|
||||
|
||||
object NextcloudExoPlayer {
|
||||
|
||||
/**
|
||||
* Creates an [ExoPlayer] that uses [NextcloudClient] for HTTP connections, thus respecting redirections,
|
||||
* IP versions and certificates.
|
||||
*
|
||||
*/
|
||||
@JvmStatic
|
||||
fun createNextcloudExoplayer(context: Context, nextcloudClient: NextcloudClient): ExoPlayer {
|
||||
val okHttpDataSourceFactory = OkHttpDataSource.Factory(nextcloudClient.client)
|
||||
val mediaSourceFactory = DefaultMediaSourceFactory(
|
||||
DefaultDataSource.Factory(
|
||||
context,
|
||||
okHttpDataSourceFactory
|
||||
)
|
||||
)
|
||||
return ExoPlayer.Builder(context).setMediaSourceFactory(mediaSourceFactory).build()
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android Library is available under MIT license
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.nextcloud.client.utils
|
||||
|
||||
import org.apache.commons.codec.binary.Hex
|
||||
import java.security.MessageDigest
|
||||
|
||||
object HashUtil {
|
||||
private const val ALGORITHM_MD5 = "MD5"
|
||||
|
||||
@JvmStatic
|
||||
fun md5Hash(input: String): String {
|
||||
val digest = MessageDigest.getInstance(ALGORITHM_MD5)
|
||||
.digest(input.toByteArray())
|
||||
return String(Hex.encodeHex(digest))
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.utils
|
||||
|
||||
object TimeConstants {
|
||||
const val MILLIS_PER_SECOND = 1000
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android Library is available under MIT license
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.nextcloud.utils.view
|
||||
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import me.zhanghai.android.fastscroll.FastScroller
|
||||
import me.zhanghai.android.fastscroll.FastScrollerBuilder
|
||||
|
||||
object FastScroll {
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun applyFastScroll(recyclerView: RecyclerView, viewHelper: FastScroller.ViewHelper? = null) {
|
||||
val builder = FastScrollerBuilder(recyclerView).useMd2Style()
|
||||
if (viewHelper != null) {
|
||||
builder.setViewHelper(viewHelper)
|
||||
}
|
||||
builder.build()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun fixAppBarForFastScroll(appBarLayout: AppBarLayout, content: ViewGroup) {
|
||||
val contentLayoutInitialPaddingBottom = content.paddingBottom
|
||||
appBarLayout.addOnOffsetChangedListener(
|
||||
AppBarLayout.OnOffsetChangedListener { _, offset ->
|
||||
content.setPadding(
|
||||
content.paddingLeft,
|
||||
content.paddingTop,
|
||||
content.paddingRight,
|
||||
contentLayoutInitialPaddingBottom + appBarLayout.totalScrollRange + offset
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* @author David A. Velasco
|
||||
* 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.authentication
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.PowerManager
|
||||
import android.view.WindowManager
|
||||
import com.nextcloud.client.core.Clock
|
||||
import com.nextcloud.client.preferences.AppPreferences
|
||||
import com.owncloud.android.MainApp
|
||||
import com.owncloud.android.ui.activity.PassCodeActivity
|
||||
import com.owncloud.android.ui.activity.RequestCredentialsActivity
|
||||
import com.owncloud.android.ui.activity.SettingsActivity
|
||||
import com.owncloud.android.utils.DeviceCredentialUtils
|
||||
import kotlin.math.abs
|
||||
|
||||
@Suppress("TooManyFunctions")
|
||||
class PassCodeManager(private val preferences: AppPreferences, private val clock: Clock) {
|
||||
companion object {
|
||||
private val exemptOfPasscodeActivities = setOf(
|
||||
PassCodeActivity::class.java,
|
||||
RequestCredentialsActivity::class.java
|
||||
)
|
||||
const val PASSCODE_ACTIVITY = 9999
|
||||
|
||||
/**
|
||||
* Keeping a "low" positive value is the easiest way to prevent
|
||||
* the pass code being requested on screen rotations.
|
||||
*/
|
||||
private const val PASS_CODE_TIMEOUT = 5000
|
||||
}
|
||||
|
||||
private var visibleActivitiesCounter = 0
|
||||
|
||||
private fun isExemptActivity(activity: Activity): Boolean {
|
||||
return exemptOfPasscodeActivities.contains(activity.javaClass)
|
||||
}
|
||||
|
||||
fun onActivityStarted(activity: Activity): Boolean {
|
||||
var askedForPin = false
|
||||
val timestamp = preferences.lockTimestamp
|
||||
setSecureFlag(activity)
|
||||
|
||||
if (!isExemptActivity(activity)) {
|
||||
if (passCodeShouldBeRequested(timestamp)) {
|
||||
askedForPin = true
|
||||
preferences.lockTimestamp = 0
|
||||
requestPasscode(activity)
|
||||
}
|
||||
if (deviceCredentialsShouldBeRequested(timestamp, activity)) {
|
||||
askedForPin = true
|
||||
preferences.lockTimestamp = 0
|
||||
requestCredentials(activity)
|
||||
}
|
||||
}
|
||||
|
||||
if (!askedForPin && preferences.lockTimestamp != 0L) {
|
||||
updateLockTimestamp()
|
||||
}
|
||||
|
||||
if (!isExemptActivity(activity)) {
|
||||
visibleActivitiesCounter++ // keep it AFTER passCodeShouldBeRequested was checked
|
||||
}
|
||||
return askedForPin
|
||||
}
|
||||
|
||||
private fun setSecureFlag(activity: Activity) {
|
||||
val window = activity.window
|
||||
if (window != null) {
|
||||
if (isPassCodeEnabled() || deviceCredentialsAreEnabled(activity)) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
|
||||
} else {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestPasscode(activity: Activity) {
|
||||
val i = Intent(MainApp.getAppContext(), PassCodeActivity::class.java)
|
||||
i.action = PassCodeActivity.ACTION_CHECK
|
||||
i.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
activity.startActivityForResult(i, PASSCODE_ACTIVITY)
|
||||
}
|
||||
|
||||
private fun requestCredentials(activity: Activity) {
|
||||
val i = Intent(MainApp.getAppContext(), RequestCredentialsActivity::class.java)
|
||||
i.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
activity.startActivityForResult(i, PASSCODE_ACTIVITY)
|
||||
}
|
||||
|
||||
fun onActivityStopped(activity: Activity) {
|
||||
if (visibleActivitiesCounter > 0 && !isExemptActivity(activity)) {
|
||||
visibleActivitiesCounter--
|
||||
}
|
||||
val powerMgr = activity.getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||
if ((isPassCodeEnabled() || deviceCredentialsAreEnabled(activity)) && !powerMgr?.isScreenOn) {
|
||||
activity.moveTaskToBack(true)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateLockTimestamp() {
|
||||
preferences.lockTimestamp = clock.millisSinceBoot
|
||||
}
|
||||
|
||||
/**
|
||||
* `true` if the time elapsed since last unlock is longer than [PASS_CODE_TIMEOUT] and no activities are visible
|
||||
*/
|
||||
private fun shouldBeLocked(timestamp: Long) =
|
||||
abs(clock.millisSinceBoot - timestamp) > PASS_CODE_TIMEOUT &&
|
||||
visibleActivitiesCounter <= 0
|
||||
|
||||
private fun passCodeShouldBeRequested(timestamp: Long): Boolean {
|
||||
return shouldBeLocked(timestamp) && isPassCodeEnabled()
|
||||
}
|
||||
|
||||
private fun isPassCodeEnabled(): Boolean = SettingsActivity.LOCK_PASSCODE == preferences.lockPreference
|
||||
|
||||
private fun deviceCredentialsShouldBeRequested(timestamp: Long, activity: Activity): Boolean {
|
||||
return shouldBeLocked(timestamp) && deviceCredentialsAreEnabled(activity)
|
||||
}
|
||||
|
||||
private fun deviceCredentialsAreEnabled(activity: Activity): Boolean {
|
||||
return SettingsActivity.LOCK_DEVICE_CREDENTIALS == preferences.lockPreference ||
|
||||
(preferences.isFingerprintUnlockEnabled && DeviceCredentialUtils.areCredentialsAvailable(activity))
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Nextcloud application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017-2018 Mario Danic <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.datamodel
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
/*
|
||||
* Push data from server, https://github.com/nextcloud/notifications/blob/master/docs/push-v2.md#encrypted-subject-data
|
||||
*/
|
||||
@Parcelize
|
||||
data class DecryptedPushMessage(
|
||||
val app: String,
|
||||
val type: String,
|
||||
val subject: String,
|
||||
val id: String,
|
||||
val nid: Int,
|
||||
val delete: Boolean,
|
||||
@SerializedName("delete-all")
|
||||
val deleteAll: Boolean
|
||||
) : Parcelable
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.datamodel
|
||||
|
||||
data class GalleryItems(val date: Long, val files: List<OCFile>)
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Nextcloud application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017-2018 Mario Danic <[email protected]>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.datamodel
|
||||
|
||||
import android.accounts.Account
|
||||
import android.os.Parcelable
|
||||
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class SignatureVerification(val signatureValid: Boolean, val account: Account?) : Parcelable
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2018 Tobias Kaminsky
|
||||
* Copyright (C) 2018 Nextcloud GmbH.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.datamodel
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
/**
|
||||
* Template for creating a file from it via RichDocuments app
|
||||
*/
|
||||
@Parcelize
|
||||
data class Template(
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val thumbnailLink: String,
|
||||
val type: Type,
|
||||
val extension: String
|
||||
) : Parcelable {
|
||||
enum class Type {
|
||||
DOCUMENT, SPREADSHEET, PRESENTATION, UNKNOWN;
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun parse(name: String) = try {
|
||||
valueOf(name.uppercase())
|
||||
} catch (_: IllegalArgumentException) {
|
||||
UNKNOWN
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.owncloud.android.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.net.http.SslCertificate
|
||||
import android.net.http.SslError
|
||||
import android.webkit.SslErrorHandler
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity
|
||||
import com.owncloud.android.lib.common.network.NetworkUtils
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.security.cert.CertificateException
|
||||
import java.security.cert.CertificateFactory
|
||||
import java.security.cert.X509Certificate
|
||||
|
||||
open class NextcloudWebViewClient(val supportFragmentManager: FragmentManager) : WebViewClient() {
|
||||
|
||||
private val tag: String? = NextcloudWebViewClient::class.simpleName
|
||||
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
@SuppressLint("WebViewClientOnReceivedSslError")
|
||||
override fun onReceivedSslError(view: WebView?, handler: SslErrorHandler, error: SslError?) {
|
||||
val cert = error?.let { getX509CertificateFromError(it) }
|
||||
try {
|
||||
if (NetworkUtils.isCertInKnownServersStore(cert, view?.context?.applicationContext)) {
|
||||
handler.proceed()
|
||||
} else {
|
||||
showUntrustedCertDialog(cert, error, handler)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log_OC.e(tag, "Cert could not be verified")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the X509Certificate from SslError
|
||||
*
|
||||
* @param error SslError
|
||||
* @return X509Certificate from error
|
||||
*/
|
||||
open fun getX509CertificateFromError(error: SslError): X509Certificate? {
|
||||
val bundle = SslCertificate.saveState(error.certificate)
|
||||
val x509Certificate: X509Certificate?
|
||||
val bytes = bundle.getByteArray("x509-certificate")
|
||||
x509Certificate = if (bytes == null) {
|
||||
null
|
||||
} else {
|
||||
try {
|
||||
val certFactory = CertificateFactory.getInstance("X.509")
|
||||
val cert = certFactory.generateCertificate(ByteArrayInputStream(bytes))
|
||||
cert as X509Certificate
|
||||
} catch (e: CertificateException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
return x509Certificate
|
||||
}
|
||||
/**
|
||||
* Show untrusted cert dialog
|
||||
*/
|
||||
private fun showUntrustedCertDialog(
|
||||
x509Certificate: X509Certificate?,
|
||||
error: SslError?,
|
||||
handler: SslErrorHandler?
|
||||
) {
|
||||
// Show a dialog with the certificate info
|
||||
val dialog: SslUntrustedCertDialog = if (x509Certificate == null) {
|
||||
SslUntrustedCertDialog.newInstanceForEmptySslError(error, handler)
|
||||
} else {
|
||||
SslUntrustedCertDialog.newInstanceForFullSslError(x509Certificate, error, handler)
|
||||
}
|
||||
val fm: FragmentManager = supportFragmentManager
|
||||
val ft = fm.beginTransaction()
|
||||
ft.addToBackStack(null)
|
||||
dialog.show(ft, AuthenticatorActivity.UNTRUSTED_CERT_DIALOG_TAG)
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* @author masensio
|
||||
* Copyright (C) 2016 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.activity
|
||||
|
||||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.nextcloud.client.account.UserAccountManager
|
||||
import com.nextcloud.client.di.Injectable
|
||||
import com.nextcloud.client.preferences.AppPreferences
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class ManageSpaceActivity : AppCompatActivity(), Injectable {
|
||||
|
||||
@Inject
|
||||
lateinit var preferences: AppPreferences
|
||||
|
||||
@Inject
|
||||
lateinit var userAccountManager: UserAccountManager
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_manage_space)
|
||||
val actionBar = supportActionBar
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true)
|
||||
actionBar.setTitle(R.string.manage_space_title)
|
||||
}
|
||||
val descriptionTextView = findViewById<TextView>(R.id.general_description)
|
||||
descriptionTextView.text = getString(R.string.manage_space_description, getString(R.string.app_name))
|
||||
val clearDataButton = findViewById<Button>(R.id.clearDataButton)
|
||||
clearDataButton.setOnClickListener {
|
||||
val clearDataTask = ClearDataAsyncTask()
|
||||
clearDataTask.execute()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
var retval = true
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> finish()
|
||||
else -> {
|
||||
Log_OC.w(TAG, "Unknown menu item triggered")
|
||||
retval = super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
return retval
|
||||
}
|
||||
|
||||
/**
|
||||
* AsyncTask for Clear Data, saving the passcode
|
||||
*/
|
||||
private inner class ClearDataAsyncTask : AsyncTask<Void, Void, Boolean>() {
|
||||
private val preferences = this@ManageSpaceActivity.preferences
|
||||
private val userAccountManager = this@ManageSpaceActivity.userAccountManager
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
override fun doInBackground(vararg params: Void): Boolean {
|
||||
val lockPref = preferences.lockPreference
|
||||
val passCodeEnable = SettingsActivity.LOCK_PASSCODE == lockPref
|
||||
var passCodeDigits = arrayOfNulls<String>(4)
|
||||
if (passCodeEnable) {
|
||||
passCodeDigits = preferences.passCode
|
||||
}
|
||||
|
||||
// Clear data
|
||||
preferences.clear()
|
||||
val result = clearApplicationData()
|
||||
|
||||
// Recover passcode
|
||||
if (passCodeEnable) {
|
||||
preferences.setPassCode(
|
||||
passCodeDigits[0],
|
||||
passCodeDigits[1],
|
||||
passCodeDigits[2],
|
||||
passCodeDigits[3]
|
||||
)
|
||||
}
|
||||
preferences.lockPreference = lockPref
|
||||
userAccountManager.removeAllAccounts()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun onPostExecute(result: Boolean) {
|
||||
super.onPostExecute(result)
|
||||
if (!result) {
|
||||
Snackbar.make(
|
||||
findViewById(android.R.id.content),
|
||||
R.string.manage_space_clear_data,
|
||||
Snackbar.LENGTH_LONG
|
||||
).show()
|
||||
} else {
|
||||
finishAndRemoveTask()
|
||||
exitProcess(0)
|
||||
}
|
||||
}
|
||||
|
||||
fun clearApplicationData(): Boolean {
|
||||
var clearResult = true
|
||||
val appDir = File(cacheDir.parent!!)
|
||||
if (appDir.exists()) {
|
||||
val children = appDir.list()
|
||||
if (children != null) {
|
||||
children.filter { it != LIB_FOLDER }.forEach { s ->
|
||||
val fileToDelete = File(appDir, s)
|
||||
clearResult = clearResult && deleteDir(fileToDelete)
|
||||
Log_OC.d(TAG, "Clear Application Data, File: " + fileToDelete.name + " DELETED *****")
|
||||
}
|
||||
} else {
|
||||
clearResult = false
|
||||
}
|
||||
}
|
||||
return clearResult
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
fun deleteDir(dir: File?): Boolean {
|
||||
if (dir != null && dir.isDirectory) {
|
||||
dir.list()?.forEach { child ->
|
||||
val success = deleteDir(File(dir, child))
|
||||
if (!success) {
|
||||
Log_OC.w(TAG, "File NOT deleted $child")
|
||||
return false
|
||||
} else {
|
||||
Log_OC.d(TAG, "File deleted $child")
|
||||
}
|
||||
} ?: return false
|
||||
}
|
||||
return dir?.delete() ?: false
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = ManageSpaceActivity::class.java.simpleName
|
||||
private const val LIB_FOLDER = "lib"
|
||||
}
|
||||
}
|
||||
@@ -1,809 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Andy Scherzinger
|
||||
* Copyright (C) 2016 Andy Scherzinger
|
||||
* Copyright (C) 2016 Nextcloud
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* 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.annotation.SuppressLint
|
||||
import android.app.NotificationManager
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.PowerManager
|
||||
import android.provider.Settings
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.nextcloud.client.core.Clock
|
||||
import com.nextcloud.client.device.PowerManagementService
|
||||
import com.nextcloud.client.di.Injectable
|
||||
import com.nextcloud.client.jobs.BackgroundJobManager
|
||||
import com.nextcloud.client.jobs.MediaFoldersDetectionWork
|
||||
import com.nextcloud.client.jobs.NotificationWork
|
||||
import com.nextcloud.client.preferences.AppPreferences
|
||||
import com.owncloud.android.BuildConfig
|
||||
import com.owncloud.android.MainApp
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.databinding.SyncedFoldersLayoutBinding
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider
|
||||
import com.owncloud.android.datamodel.MediaFolder
|
||||
import com.owncloud.android.datamodel.MediaFolderType
|
||||
import com.owncloud.android.datamodel.MediaProvider
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.datamodel.SyncedFolder
|
||||
import com.owncloud.android.datamodel.SyncedFolderDisplayItem
|
||||
import com.owncloud.android.datamodel.SyncedFolderProvider
|
||||
import com.owncloud.android.files.services.FileUploader
|
||||
import com.owncloud.android.files.services.NameCollisionPolicy
|
||||
import com.owncloud.android.ui.adapter.SyncedFolderAdapter
|
||||
import com.owncloud.android.ui.decoration.MediaGridItemDecoration
|
||||
import com.owncloud.android.ui.dialog.SyncedFolderPreferencesDialogFragment
|
||||
import com.owncloud.android.ui.dialog.SyncedFolderPreferencesDialogFragment.OnSyncedFolderPreferenceListener
|
||||
import com.owncloud.android.ui.dialog.parcel.SyncedFolderParcelable
|
||||
import com.owncloud.android.utils.PermissionUtil
|
||||
import com.owncloud.android.utils.SyncedFolderUtils
|
||||
import com.owncloud.android.utils.theme.ThemeButtonUtils
|
||||
import com.owncloud.android.utils.theme.ThemeUtils
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Activity displaying all auto-synced folders and/or instant upload media folders.
|
||||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
class SyncedFoldersActivity :
|
||||
FileActivity(),
|
||||
SyncedFolderAdapter.ClickListener,
|
||||
OnSyncedFolderPreferenceListener,
|
||||
Injectable {
|
||||
|
||||
companion object {
|
||||
private const val SYNCED_FOLDER_PREFERENCES_DIALOG_TAG = "SYNCED_FOLDER_PREFERENCES_DIALOG"
|
||||
// yes, there is a typo in this value
|
||||
private const val KEY_SYNCED_FOLDER_INITIATED_PREFIX = "syncedFolderIntitiated_"
|
||||
private val PRIORITIZED_FOLDERS = arrayOf("Camera", "Screenshots")
|
||||
private val TAG = SyncedFoldersActivity::class.java.simpleName
|
||||
|
||||
/**
|
||||
* Sorts list of [SyncedFolderDisplayItem]s.
|
||||
*
|
||||
* @param syncFolderItemList list of items to be sorted
|
||||
* @return sorted list of items
|
||||
*/
|
||||
@JvmStatic
|
||||
@Suppress("ComplexMethod")
|
||||
fun sortSyncedFolderItems(syncFolderItemList: List<SyncedFolderDisplayItem?>): List<SyncedFolderDisplayItem?> {
|
||||
return syncFolderItemList.sortedWith { f1, f2 ->
|
||||
if (f1 == null && f2 == null) {
|
||||
0
|
||||
} else if (f1 == null) {
|
||||
-1
|
||||
} else if (f2 == null) {
|
||||
1
|
||||
} else if (f1.isEnabled && f2.isEnabled) {
|
||||
when {
|
||||
f1.folderName == null -> -1
|
||||
f2.folderName == null -> 1
|
||||
else -> f1.folderName.lowercase(Locale.getDefault()).compareTo(
|
||||
f2.folderName.lowercase(Locale.getDefault())
|
||||
)
|
||||
}
|
||||
} else if (f1.folderName == null && f2.folderName == null) {
|
||||
0
|
||||
} else if (f1.isEnabled) {
|
||||
-1
|
||||
} else if (f2.isEnabled) {
|
||||
1
|
||||
} else if (f1.folderName == null) {
|
||||
-1
|
||||
} else if (f2.folderName == null) {
|
||||
1
|
||||
} else {
|
||||
for (folder in PRIORITIZED_FOLDERS) {
|
||||
if (folder == f1.folderName && folder == f2.folderName) {
|
||||
return@sortedWith 0
|
||||
} else if (folder == f1.folderName) {
|
||||
return@sortedWith -1
|
||||
} else if (folder == f2.folderName) {
|
||||
return@sortedWith 1
|
||||
}
|
||||
}
|
||||
f1.folderName.lowercase(Locale.getDefault()).compareTo(
|
||||
f2.folderName.lowercase(Locale.getDefault())
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
lateinit var preferences: AppPreferences
|
||||
|
||||
@Inject
|
||||
lateinit var powerManagementService: PowerManagementService
|
||||
|
||||
@Inject
|
||||
lateinit var clock: Clock
|
||||
|
||||
@Inject
|
||||
lateinit var backgroundJobManager: BackgroundJobManager
|
||||
|
||||
private lateinit var binding: SyncedFoldersLayoutBinding
|
||||
private lateinit var adapter: SyncedFolderAdapter
|
||||
private lateinit var syncedFolderProvider: SyncedFolderProvider
|
||||
|
||||
private var syncedFolderPreferencesDialogFragment: SyncedFolderPreferencesDialogFragment? = null
|
||||
private var path: String? = null
|
||||
private var type = 0
|
||||
private var loadJob: Job? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = SyncedFoldersLayoutBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
if (intent != null && intent.extras != null) {
|
||||
val accountName = intent.extras!!.getString(NotificationWork.KEY_NOTIFICATION_ACCOUNT)
|
||||
val optionalUser = user
|
||||
if (optionalUser.isPresent && accountName != null) {
|
||||
val user = optionalUser.get()
|
||||
if (!accountName.equals(user.accountName, ignoreCase = true)) {
|
||||
accountManager.setCurrentOwnCloudAccount(accountName)
|
||||
setUser(userAccountManager.user)
|
||||
}
|
||||
}
|
||||
path = intent.getStringExtra(MediaFoldersDetectionWork.KEY_MEDIA_FOLDER_PATH)
|
||||
type = intent.getIntExtra(MediaFoldersDetectionWork.KEY_MEDIA_FOLDER_TYPE, -1)
|
||||
|
||||
// Cancel notification
|
||||
val notificationId = intent.getIntExtra(MediaFoldersDetectionWork.NOTIFICATION_ID, 0)
|
||||
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.cancel(notificationId)
|
||||
}
|
||||
|
||||
// setup toolbar
|
||||
setupToolbar()
|
||||
updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_synced_folders))
|
||||
setupDrawer()
|
||||
setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
|
||||
if (supportActionBar != null) {
|
||||
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
||||
}
|
||||
if (mDrawerToggle != null) {
|
||||
mDrawerToggle.isDrawerIndicatorEnabled = false
|
||||
}
|
||||
|
||||
setupContent()
|
||||
if (ThemeUtils.themingEnabled(this)) {
|
||||
setTheme(R.style.FallbackThemingTheme)
|
||||
}
|
||||
binding.emptyList.emptyListViewAction.setOnClickListener { showHiddenItems() }
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
val inflater = menuInflater
|
||||
inflater.inflate(R.menu.activity_synced_folders, menu)
|
||||
if (powerManagementService.isPowerSavingExclusionAvailable) {
|
||||
val item = menu.findItem(R.id.action_disable_power_save_check)
|
||||
item.isVisible = true
|
||||
item.isChecked = preferences.isPowerCheckDisabled
|
||||
item.setOnMenuItemClickListener { powerCheck -> onDisablePowerSaveCheckClicked(powerCheck) }
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun onDisablePowerSaveCheckClicked(powerCheck: MenuItem): Boolean {
|
||||
if (!powerCheck.isChecked) {
|
||||
showPowerCheckDialog()
|
||||
}
|
||||
preferences.isPowerCheckDisabled = !powerCheck.isChecked
|
||||
powerCheck.isChecked = !powerCheck.isChecked
|
||||
return true
|
||||
}
|
||||
|
||||
private fun showPowerCheckDialog() {
|
||||
val alertDialog = AlertDialog.Builder(this)
|
||||
.setView(findViewById(R.id.root_layout))
|
||||
.setPositiveButton(R.string.common_ok) { dialog, _ -> dialog.dismiss() }
|
||||
.setTitle(R.string.autoupload_disable_power_save_check)
|
||||
.setMessage(getString(R.string.power_save_check_dialog_message))
|
||||
.show()
|
||||
ThemeButtonUtils.themeBorderlessButton(alertDialog.getButton(AlertDialog.BUTTON_POSITIVE))
|
||||
}
|
||||
|
||||
/**
|
||||
* sets up the UI elements and loads all media/synced folders.
|
||||
*/
|
||||
private fun setupContent() {
|
||||
val gridWidth = resources.getInteger(R.integer.media_grid_width)
|
||||
val lightVersion = resources.getBoolean(R.bool.syncedFolder_light)
|
||||
adapter = SyncedFolderAdapter(this, clock, gridWidth, this, lightVersion)
|
||||
syncedFolderProvider = SyncedFolderProvider(contentResolver, preferences, clock)
|
||||
binding.emptyList.emptyListIcon.setImageResource(R.drawable.nav_synced_folders)
|
||||
ThemeButtonUtils.colorPrimaryButton(binding.emptyList.emptyListViewAction, this)
|
||||
val lm = GridLayoutManager(this, gridWidth)
|
||||
adapter.setLayoutManager(lm)
|
||||
val spacing = resources.getDimensionPixelSize(R.dimen.media_grid_spacing)
|
||||
binding.list.addItemDecoration(MediaGridItemDecoration(spacing))
|
||||
binding.list.layoutManager = lm
|
||||
binding.list.adapter = adapter
|
||||
load(getItemsDisplayedPerFolder(), false)
|
||||
}
|
||||
|
||||
private fun showHiddenItems() {
|
||||
if (adapter.sectionCount == 0 && adapter.unfilteredSectionCount > adapter.sectionCount) {
|
||||
adapter.toggleHiddenItemsVisibility()
|
||||
binding.emptyList.emptyListView.visibility = View.GONE
|
||||
binding.list.visibility = 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
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun load(perFolderMediaItemLimit: Int, force: Boolean) {
|
||||
if (adapter.itemCount > 0 && !force) {
|
||||
return
|
||||
}
|
||||
showLoadingContent()
|
||||
loadJob = CoroutineScope(Dispatchers.IO).launch {
|
||||
loadJob?.cancel()
|
||||
val mediaFolders = MediaProvider.getImageFolders(
|
||||
contentResolver,
|
||||
perFolderMediaItemLimit, this@SyncedFoldersActivity, false
|
||||
)
|
||||
mediaFolders.addAll(
|
||||
MediaProvider.getVideoFolders(
|
||||
contentResolver, perFolderMediaItemLimit,
|
||||
this@SyncedFoldersActivity, false
|
||||
)
|
||||
)
|
||||
val syncedFolderArrayList = syncedFolderProvider.syncedFolders
|
||||
val currentAccountSyncedFoldersList: MutableList<SyncedFolder> = ArrayList()
|
||||
val user = userAccountManager.user
|
||||
for (syncedFolder in syncedFolderArrayList) {
|
||||
if (syncedFolder.account == user.accountName) {
|
||||
// delete non-existing & disabled synced folders
|
||||
if (!File(syncedFolder.localPath).exists() && !syncedFolder.isEnabled) {
|
||||
syncedFolderProvider.deleteSyncedFolder(syncedFolder.id)
|
||||
} else {
|
||||
currentAccountSyncedFoldersList.add(syncedFolder)
|
||||
}
|
||||
}
|
||||
}
|
||||
val syncFolderItems = sortSyncedFolderItems(
|
||||
mergeFolderData(currentAccountSyncedFoldersList, mediaFolders)
|
||||
)
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
adapter.setSyncFolderItems(syncFolderItems)
|
||||
adapter.notifyDataSetChanged()
|
||||
showList()
|
||||
if (!TextUtils.isEmpty(path)) {
|
||||
val section = adapter.getSectionByLocalPathAndType(path, type)
|
||||
if (section >= 0) {
|
||||
onSyncFolderSettingsClick(section, adapter[section])
|
||||
}
|
||||
}
|
||||
loadJob = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
loadJob?.cancel()
|
||||
}
|
||||
|
||||
/**
|
||||
* merges two lists of [SyncedFolder] and [MediaFolder] items into one of SyncedFolderItems.
|
||||
*
|
||||
* @param syncedFolders the synced folders
|
||||
* @param mediaFolders the media folders
|
||||
* @return the merged list of SyncedFolderItems
|
||||
*/
|
||||
private fun mergeFolderData(
|
||||
syncedFolders: List<SyncedFolder>,
|
||||
mediaFolders: List<MediaFolder>
|
||||
): List<SyncedFolderDisplayItem?> {
|
||||
val syncedFoldersMap = createSyncedFoldersMap(syncedFolders)
|
||||
val result: MutableList<SyncedFolderDisplayItem?> = ArrayList()
|
||||
for (mediaFolder in mediaFolders) {
|
||||
if (syncedFoldersMap.containsKey(mediaFolder.absolutePath + "-" + mediaFolder.type)) {
|
||||
val syncedFolder = syncedFoldersMap[mediaFolder.absolutePath + "-" + mediaFolder.type]
|
||||
syncedFoldersMap.remove(mediaFolder.absolutePath + "-" + mediaFolder.type)
|
||||
if (syncedFolder != null && SyncedFolderUtils.isQualifyingMediaFolder(syncedFolder)) {
|
||||
if (MediaFolderType.CUSTOM == syncedFolder.type) {
|
||||
result.add(createSyncedFolderWithoutMediaFolder(syncedFolder))
|
||||
} else {
|
||||
result.add(createSyncedFolder(syncedFolder, mediaFolder))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (SyncedFolderUtils.isQualifyingMediaFolder(mediaFolder)) {
|
||||
result.add(createSyncedFolderFromMediaFolder(mediaFolder))
|
||||
}
|
||||
}
|
||||
}
|
||||
for (syncedFolder in syncedFoldersMap.values) {
|
||||
result.add(createSyncedFolderWithoutMediaFolder(syncedFolder))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun createSyncedFolderWithoutMediaFolder(syncedFolder: SyncedFolder): SyncedFolderDisplayItem {
|
||||
val localFolder = File(syncedFolder.localPath)
|
||||
val files = SyncedFolderUtils.getFileList(localFolder)
|
||||
val filePaths = getDisplayFilePathList(files.toList())
|
||||
return SyncedFolderDisplayItem(
|
||||
syncedFolder.id,
|
||||
syncedFolder.localPath,
|
||||
syncedFolder.remotePath,
|
||||
syncedFolder.isWifiOnly,
|
||||
syncedFolder.isChargingOnly,
|
||||
syncedFolder.isExisting,
|
||||
syncedFolder.isSubfolderByDate,
|
||||
syncedFolder.account,
|
||||
syncedFolder.uploadAction,
|
||||
syncedFolder.nameCollisionPolicyInt,
|
||||
syncedFolder.isEnabled,
|
||||
clock.currentTime,
|
||||
filePaths,
|
||||
localFolder.name,
|
||||
files.size.toLong(),
|
||||
syncedFolder.type,
|
||||
syncedFolder.isHidden
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a SyncedFolderDisplayItem merging a [SyncedFolder] and a [MediaFolder] object instance.
|
||||
*
|
||||
* @param syncedFolder the synced folder object
|
||||
* @param mediaFolder the media folder object
|
||||
* @return the created SyncedFolderDisplayItem
|
||||
*/
|
||||
private fun createSyncedFolder(syncedFolder: SyncedFolder, mediaFolder: MediaFolder): SyncedFolderDisplayItem {
|
||||
return SyncedFolderDisplayItem(
|
||||
syncedFolder.id,
|
||||
syncedFolder.localPath,
|
||||
syncedFolder.remotePath,
|
||||
syncedFolder.isWifiOnly,
|
||||
syncedFolder.isChargingOnly,
|
||||
syncedFolder.isExisting,
|
||||
syncedFolder.isSubfolderByDate,
|
||||
syncedFolder.account,
|
||||
syncedFolder.uploadAction,
|
||||
syncedFolder.nameCollisionPolicyInt,
|
||||
syncedFolder.isEnabled,
|
||||
clock.currentTime,
|
||||
mediaFolder.filePaths,
|
||||
mediaFolder.folderName,
|
||||
mediaFolder.numberOfFiles,
|
||||
mediaFolder.type,
|
||||
syncedFolder.isHidden
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a [SyncedFolderDisplayItem] based on a [MediaFolder] object instance.
|
||||
*
|
||||
* @param mediaFolder the media folder object
|
||||
* @return the created SyncedFolderDisplayItem
|
||||
*/
|
||||
private fun createSyncedFolderFromMediaFolder(mediaFolder: MediaFolder): SyncedFolderDisplayItem {
|
||||
return SyncedFolderDisplayItem(
|
||||
SyncedFolder.UNPERSISTED_ID,
|
||||
mediaFolder.absolutePath,
|
||||
getString(R.string.instant_upload_path) + "/" + mediaFolder.folderName,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
account.name,
|
||||
FileUploader.LOCAL_BEHAVIOUR_FORGET,
|
||||
NameCollisionPolicy.ASK_USER.serialize(),
|
||||
false,
|
||||
clock.currentTime,
|
||||
mediaFolder.filePaths,
|
||||
mediaFolder.folderName,
|
||||
mediaFolder.numberOfFiles,
|
||||
mediaFolder.type,
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
private fun getItemsDisplayedPerFolder(): Int {
|
||||
return resources.getInteger(R.integer.media_grid_width) * 2
|
||||
}
|
||||
|
||||
private fun getDisplayFilePathList(files: List<File>?): List<String>? {
|
||||
if (!files.isNullOrEmpty()) {
|
||||
return files.take(getItemsDisplayedPerFolder())
|
||||
.map { it.absolutePath }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a lookup map for a list of given [SyncedFolder]s with their local path as the key.
|
||||
*
|
||||
* @param syncFolders list of [SyncedFolder]s
|
||||
* @return the lookup map for [SyncedFolder]s
|
||||
*/
|
||||
private fun createSyncedFoldersMap(syncFolders: List<SyncedFolder>?): MutableMap<String, SyncedFolder> {
|
||||
val result: MutableMap<String, SyncedFolder> = HashMap()
|
||||
if (syncFolders != null) {
|
||||
for (syncFolder in syncFolders) {
|
||||
result[syncFolder.localPath + "-" + syncFolder.type] = syncFolder
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* show recycler view list or the empty message info (in case list is empty).
|
||||
*/
|
||||
private fun showList() {
|
||||
binding.list.visibility = View.VISIBLE
|
||||
binding.loadingContent.visibility = View.GONE
|
||||
checkAndShowEmptyListContent()
|
||||
}
|
||||
|
||||
private fun checkAndShowEmptyListContent() {
|
||||
if (adapter.sectionCount == 0 && adapter.unfilteredSectionCount > adapter.sectionCount) {
|
||||
binding.emptyList.emptyListView.visibility = View.VISIBLE
|
||||
val hiddenFoldersCount = adapter.hiddenFolderCount
|
||||
showEmptyContent(
|
||||
getString(R.string.drawer_synced_folders),
|
||||
resources.getQuantityString(
|
||||
R.plurals.synced_folders_show_hidden_folders,
|
||||
hiddenFoldersCount,
|
||||
hiddenFoldersCount
|
||||
),
|
||||
resources.getQuantityString(
|
||||
R.plurals.synced_folders_show_hidden_folders,
|
||||
hiddenFoldersCount,
|
||||
hiddenFoldersCount
|
||||
)
|
||||
)
|
||||
} else if (adapter.sectionCount == 0 && adapter.unfilteredSectionCount == 0) {
|
||||
binding.emptyList.emptyListView.visibility = View.VISIBLE
|
||||
showEmptyContent(
|
||||
getString(R.string.drawer_synced_folders),
|
||||
getString(R.string.synced_folders_no_results)
|
||||
)
|
||||
} else {
|
||||
binding.emptyList.emptyListView.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
var result = true
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> finish()
|
||||
R.id.action_create_custom_folder -> {
|
||||
Log.d(TAG, "Show custom folder dialog")
|
||||
if (PermissionUtil.checkExternalStoragePermission(this)) {
|
||||
val emptyCustomFolder = SyncedFolderDisplayItem(
|
||||
SyncedFolder.UNPERSISTED_ID,
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
account.name,
|
||||
FileUploader.LOCAL_BEHAVIOUR_FORGET,
|
||||
NameCollisionPolicy.ASK_USER.serialize(),
|
||||
false,
|
||||
clock.currentTime,
|
||||
null,
|
||||
MediaFolderType.CUSTOM,
|
||||
false
|
||||
)
|
||||
onSyncFolderSettingsClick(0, emptyCustomFolder)
|
||||
} else {
|
||||
PermissionUtil.requestExternalStoragePermission(this, true)
|
||||
}
|
||||
result = super.onOptionsItemSelected(item)
|
||||
}
|
||||
else -> result = super.onOptionsItemSelected(item)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
override fun onSyncStatusToggleClick(section: Int, syncedFolderDisplayItem: SyncedFolderDisplayItem) {
|
||||
if (syncedFolderDisplayItem.id > SyncedFolder.UNPERSISTED_ID) {
|
||||
syncedFolderProvider.updateSyncedFolderEnabled(
|
||||
syncedFolderDisplayItem.id,
|
||||
syncedFolderDisplayItem.isEnabled
|
||||
)
|
||||
} else {
|
||||
val storedId = syncedFolderProvider.storeSyncedFolder(syncedFolderDisplayItem)
|
||||
if (storedId != -1L) {
|
||||
syncedFolderDisplayItem.id = storedId
|
||||
}
|
||||
}
|
||||
if (syncedFolderDisplayItem.isEnabled) {
|
||||
backgroundJobManager.startImmediateFilesSyncJob(skipCustomFolders = false, overridePowerSaving = false)
|
||||
showBatteryOptimizationInfo()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSyncFolderSettingsClick(section: Int, syncedFolderDisplayItem: SyncedFolderDisplayItem) {
|
||||
val fm = supportFragmentManager
|
||||
val ft = fm.beginTransaction()
|
||||
ft.addToBackStack(null)
|
||||
syncedFolderPreferencesDialogFragment = SyncedFolderPreferencesDialogFragment.newInstance(
|
||||
syncedFolderDisplayItem, section
|
||||
).also {
|
||||
it.show(ft, SYNCED_FOLDER_PREFERENCES_DIALOG_TAG)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onVisibilityToggleClick(section: Int, syncedFolder: SyncedFolderDisplayItem) {
|
||||
syncedFolder.isHidden = !syncedFolder.isHidden
|
||||
saveOrUpdateSyncedFolder(syncedFolder)
|
||||
adapter.setSyncFolderItem(section, syncedFolder)
|
||||
checkAndShowEmptyListContent()
|
||||
}
|
||||
|
||||
private fun showEmptyContent(headline: String, message: String, action: String) {
|
||||
showEmptyContent(headline, message)
|
||||
binding.emptyList.emptyListViewAction.text = action
|
||||
binding.emptyList.emptyListViewAction.visibility = View.VISIBLE
|
||||
binding.emptyList.emptyListViewText.visibility = View.GONE
|
||||
}
|
||||
|
||||
private fun showLoadingContent() {
|
||||
binding.loadingContent.visibility = View.VISIBLE
|
||||
binding.emptyList.emptyListViewAction.visibility = View.GONE
|
||||
}
|
||||
|
||||
private fun showEmptyContent(headline: String, message: String) {
|
||||
binding.emptyList.emptyListViewAction.visibility = View.GONE
|
||||
binding.emptyList.emptyListView.visibility = View.VISIBLE
|
||||
binding.list.visibility = View.GONE
|
||||
binding.loadingContent.visibility = View.GONE
|
||||
binding.emptyList.emptyListViewHeadline.text = headline
|
||||
binding.emptyList.emptyListViewText.text = message
|
||||
binding.emptyList.emptyListViewText.visibility = View.VISIBLE
|
||||
binding.emptyList.emptyListIcon.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_REMOTE_FOLDER &&
|
||||
resultCode == RESULT_OK && syncedFolderPreferencesDialogFragment != null
|
||||
) {
|
||||
val chosenFolder: OCFile = data!!.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER)!!
|
||||
syncedFolderPreferencesDialogFragment!!.setRemoteFolderSummary(chosenFolder.remotePath)
|
||||
} else if (
|
||||
requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_LOCAL_FOLDER &&
|
||||
resultCode == RESULT_OK && syncedFolderPreferencesDialogFragment != null
|
||||
) {
|
||||
val localPath = data!!.getStringExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES)
|
||||
syncedFolderPreferencesDialogFragment!!.setLocalFolderSummary(localPath)
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSaveSyncedFolderPreference(syncedFolder: SyncedFolderParcelable) {
|
||||
// custom folders newly created aren't in the list already,
|
||||
// so triggering a refresh
|
||||
if (MediaFolderType.CUSTOM == syncedFolder.type && syncedFolder.id == SyncedFolder.UNPERSISTED_ID) {
|
||||
val newCustomFolder = SyncedFolderDisplayItem(
|
||||
SyncedFolder.UNPERSISTED_ID,
|
||||
syncedFolder.localPath,
|
||||
syncedFolder.remotePath,
|
||||
syncedFolder.isWifiOnly,
|
||||
syncedFolder.isChargingOnly,
|
||||
syncedFolder.isExisting,
|
||||
syncedFolder.isSubfolderByDate,
|
||||
syncedFolder.account,
|
||||
syncedFolder.uploadAction,
|
||||
syncedFolder.nameCollisionPolicy.serialize(),
|
||||
syncedFolder.isEnabled,
|
||||
clock.currentTime,
|
||||
File(syncedFolder.localPath).name,
|
||||
syncedFolder.type,
|
||||
syncedFolder.isHidden
|
||||
)
|
||||
saveOrUpdateSyncedFolder(newCustomFolder)
|
||||
adapter.addSyncFolderItem(newCustomFolder)
|
||||
} else {
|
||||
val item = adapter[syncedFolder.section]
|
||||
updateSyncedFolderItem(
|
||||
item,
|
||||
syncedFolder.id,
|
||||
syncedFolder.localPath,
|
||||
syncedFolder.remotePath,
|
||||
syncedFolder.isWifiOnly,
|
||||
syncedFolder.isChargingOnly,
|
||||
syncedFolder.isExisting,
|
||||
syncedFolder.isSubfolderByDate,
|
||||
syncedFolder.uploadAction,
|
||||
syncedFolder.nameCollisionPolicy.serialize(),
|
||||
syncedFolder.isEnabled
|
||||
)
|
||||
saveOrUpdateSyncedFolder(item)
|
||||
|
||||
adapter.notifyItemChanged(adapter.getSectionHeaderIndex(syncedFolder.section))
|
||||
}
|
||||
syncedFolderPreferencesDialogFragment = null
|
||||
if (syncedFolder.isEnabled) {
|
||||
showBatteryOptimizationInfo()
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveOrUpdateSyncedFolder(item: SyncedFolderDisplayItem) {
|
||||
if (item.id == SyncedFolder.UNPERSISTED_ID) {
|
||||
// newly set up folder sync config
|
||||
storeSyncedFolder(item)
|
||||
} else {
|
||||
// existing synced folder setup to be updated
|
||||
syncedFolderProvider.updateSyncFolder(item)
|
||||
if (item.isEnabled) {
|
||||
backgroundJobManager.startImmediateFilesSyncJob(skipCustomFolders = false, overridePowerSaving = false)
|
||||
} else {
|
||||
val syncedFolderInitiatedKey = KEY_SYNCED_FOLDER_INITIATED_PREFIX + item.id
|
||||
val arbitraryDataProvider = ArbitraryDataProvider(MainApp.getAppContext().contentResolver)
|
||||
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun storeSyncedFolder(item: SyncedFolderDisplayItem) {
|
||||
val arbitraryDataProvider = ArbitraryDataProvider(MainApp.getAppContext().contentResolver)
|
||||
val storedId = syncedFolderProvider.storeSyncedFolder(item)
|
||||
if (storedId != -1L) {
|
||||
item.id = storedId
|
||||
if (item.isEnabled) {
|
||||
backgroundJobManager.startImmediateFilesSyncJob(skipCustomFolders = false, overridePowerSaving = false)
|
||||
} else {
|
||||
val syncedFolderInitiatedKey = KEY_SYNCED_FOLDER_INITIATED_PREFIX + item.id
|
||||
arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCancelSyncedFolderPreference() {
|
||||
syncedFolderPreferencesDialogFragment = null
|
||||
}
|
||||
|
||||
override fun onDeleteSyncedFolderPreference(syncedFolder: SyncedFolderParcelable) {
|
||||
syncedFolderProvider.deleteSyncedFolder(syncedFolder.id)
|
||||
adapter.removeItem(syncedFolder.section)
|
||||
}
|
||||
|
||||
/**
|
||||
* update given synced folder with the given values.
|
||||
*
|
||||
* @param item the synced folder to be updated
|
||||
* @param localPath the local path
|
||||
* @param remotePath the remote path
|
||||
* @param wifiOnly upload on wifi only
|
||||
* @param chargingOnly upload on charging only
|
||||
* @param existing also upload existing
|
||||
* @param subfolderByDate created sub folders
|
||||
* @param uploadAction upload action
|
||||
* @param nameCollisionPolicy what to do on name collision
|
||||
* @param enabled is sync enabled
|
||||
*/
|
||||
@Suppress("LongParameterList")
|
||||
private fun updateSyncedFolderItem(
|
||||
item: SyncedFolderDisplayItem,
|
||||
id: Long,
|
||||
localPath: String,
|
||||
remotePath: String,
|
||||
wifiOnly: Boolean,
|
||||
chargingOnly: Boolean,
|
||||
existing: Boolean,
|
||||
subfolderByDate: Boolean,
|
||||
uploadAction: Int,
|
||||
nameCollisionPolicy: Int,
|
||||
enabled: Boolean
|
||||
) {
|
||||
item.id = id
|
||||
item.localPath = localPath
|
||||
item.remotePath = remotePath
|
||||
item.isWifiOnly = wifiOnly
|
||||
item.isChargingOnly = chargingOnly
|
||||
item.isExisting = existing
|
||||
item.isSubfolderByDate = subfolderByDate
|
||||
item.uploadAction = uploadAction
|
||||
item.setNameCollisionPolicy(nameCollisionPolicy)
|
||||
item.setEnabled(enabled, clock.currentTime)
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
permissions: Array<String>,
|
||||
grantResults: IntArray
|
||||
) {
|
||||
when (requestCode) {
|
||||
PermissionUtil.PERMISSIONS_EXTERNAL_STORAGE -> {
|
||||
// If request is cancelled, result arrays are empty.
|
||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
// permission was granted
|
||||
load(getItemsDisplayedPerFolder(), true)
|
||||
} else {
|
||||
// permission denied --> request again
|
||||
PermissionUtil.requestExternalStoragePermission(this, true)
|
||||
}
|
||||
}
|
||||
else -> super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showBatteryOptimizationInfo() {
|
||||
if (powerManagementService.isPowerSavingExclusionAvailable || checkIfBatteryOptimizationEnabled()) {
|
||||
val alertDialogBuilder = AlertDialog.Builder(this, R.style.Theme_ownCloud_Dialog)
|
||||
.setTitle(getString(R.string.battery_optimization_title))
|
||||
.setMessage(getString(R.string.battery_optimization_message))
|
||||
.setPositiveButton(getString(R.string.battery_optimization_disable)) { _, _ ->
|
||||
// show instant upload
|
||||
@SuppressLint("BatteryLife") val intent = Intent(
|
||||
Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
|
||||
Uri.parse("package:" + BuildConfig.APPLICATION_ID)
|
||||
)
|
||||
if (intent.resolveActivity(packageManager) != null) {
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
.setNeutralButton(getString(R.string.battery_optimization_close)) { dialog, _ -> dialog.dismiss() }
|
||||
.setIcon(R.drawable.ic_battery_alert)
|
||||
if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
val alertDialog = alertDialogBuilder.show()
|
||||
ThemeButtonUtils.themeBorderlessButton(
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE),
|
||||
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if battery optimization is enabled. If unknown, fallback to true.
|
||||
*
|
||||
* @return true if battery optimization is enabled
|
||||
*/
|
||||
private fun checkIfBatteryOptimizationEnabled(): Boolean {
|
||||
val powerManager = getSystemService(POWER_SERVICE) as PowerManager?
|
||||
return when {
|
||||
powerManager != null -> !powerManager.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID)
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import com.nextcloud.client.account.User
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.utils.FileSortOrder
|
||||
|
||||
interface CommonOCFileListAdapterInterface {
|
||||
fun isMultiSelect(): Boolean
|
||||
fun cancelAllPendingTasks()
|
||||
fun getItemPosition(file: OCFile): Int
|
||||
fun swapDirectory(
|
||||
user: User,
|
||||
directory: OCFile,
|
||||
storageManager: FileDataStorageManager,
|
||||
onlyOnDevice: Boolean,
|
||||
mLimitToMimeType: String
|
||||
)
|
||||
|
||||
fun setHighlightedItem(file: OCFile)
|
||||
fun setSortOrder(mFile: OCFile, sortOrder: FileSortOrder)
|
||||
fun addCheckedFile(file: OCFile)
|
||||
fun isCheckedFile(file: OCFile): Boolean
|
||||
fun getCheckedItems(): Set<OCFile>
|
||||
fun removeCheckedFile(file: OCFile)
|
||||
fun notifyItemChanged(file: OCFile)
|
||||
fun getFilesCount(): Int
|
||||
fun setMultiSelect(boolean: Boolean)
|
||||
fun clearCheckedItems()
|
||||
}
|
||||
@@ -1,250 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import com.afollestad.sectionedrecyclerview.SectionedRecyclerViewAdapter
|
||||
import com.afollestad.sectionedrecyclerview.SectionedViewHolder
|
||||
import com.nextcloud.client.account.User
|
||||
import com.nextcloud.client.preferences.AppPreferences
|
||||
import com.owncloud.android.databinding.GalleryHeaderBinding
|
||||
import com.owncloud.android.databinding.GridImageBinding
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.datamodel.GalleryItems
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.ui.activity.ComponentsGetter
|
||||
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import com.owncloud.android.utils.FileSortOrder
|
||||
import com.owncloud.android.utils.FileStorageUtils
|
||||
import me.zhanghai.android.fastscroll.PopupTextProvider
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
|
||||
class GalleryAdapter(
|
||||
val context: Context,
|
||||
user: User,
|
||||
ocFileListFragmentInterface: OCFileListFragmentInterface,
|
||||
preferences: AppPreferences,
|
||||
transferServiceGetter: ComponentsGetter
|
||||
) : SectionedRecyclerViewAdapter<SectionedViewHolder>(), CommonOCFileListAdapterInterface, PopupTextProvider {
|
||||
var files: List<GalleryItems> = mutableListOf()
|
||||
private var ocFileListDelegate: OCFileListDelegate
|
||||
private var storageManager: FileDataStorageManager
|
||||
|
||||
init {
|
||||
storageManager = transferServiceGetter.storageManager
|
||||
|
||||
ocFileListDelegate = OCFileListDelegate(
|
||||
context,
|
||||
ocFileListFragmentInterface,
|
||||
user,
|
||||
storageManager,
|
||||
false,
|
||||
preferences,
|
||||
true,
|
||||
transferServiceGetter,
|
||||
showMetadata = false,
|
||||
showShareAvatar = false
|
||||
)
|
||||
}
|
||||
|
||||
override fun showFooters(): Boolean = false
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SectionedViewHolder {
|
||||
return if (viewType == VIEW_TYPE_HEADER) {
|
||||
GalleryHeaderViewHolder(
|
||||
GalleryHeaderBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
} else {
|
||||
GalleryItemViewHolder(
|
||||
GridImageBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(
|
||||
holder: SectionedViewHolder?,
|
||||
section: Int,
|
||||
relativePosition: Int,
|
||||
absolutePosition: Int
|
||||
) {
|
||||
if (holder != null) {
|
||||
val itemViewHolder = holder as GalleryItemViewHolder
|
||||
val ocFile = files[section].files[relativePosition]
|
||||
|
||||
ocFileListDelegate.bindGridViewHolder(itemViewHolder, ocFile)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(section: Int): Int {
|
||||
return files[section].files.size
|
||||
}
|
||||
|
||||
override fun getSectionCount(): Int {
|
||||
return files.size
|
||||
}
|
||||
|
||||
override fun getPopupText(position: Int): String {
|
||||
return DisplayUtils.getDateByPattern(
|
||||
files[getRelativePosition(position).section()].date,
|
||||
context,
|
||||
DisplayUtils.MONTH_YEAR_PATTERN
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindHeaderViewHolder(holder: SectionedViewHolder?, section: Int, expanded: Boolean) {
|
||||
if (holder != null) {
|
||||
val headerViewHolder = holder as GalleryHeaderViewHolder
|
||||
val galleryItem = files[section]
|
||||
|
||||
headerViewHolder.binding.month.text = DisplayUtils.getDateByPattern(
|
||||
galleryItem.date,
|
||||
context,
|
||||
DisplayUtils.MONTH_PATTERN
|
||||
)
|
||||
headerViewHolder.binding.year.text = DisplayUtils.getDateByPattern(
|
||||
galleryItem.date,
|
||||
context, DisplayUtils.YEAR_PATTERN
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindFooterViewHolder(holder: SectionedViewHolder?, section: Int) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun showAllGalleryItems() {
|
||||
val items = storageManager.allGalleryItems
|
||||
|
||||
files = items
|
||||
.groupBy { firstOfMonth(it.modificationTimestamp) }
|
||||
.map { GalleryItems(it.key, FileStorageUtils.sortOcFolderDescDateModifiedWithoutFavoritesFirst(it.value)) }
|
||||
.sortedBy { it.date }.reversed()
|
||||
|
||||
Handler(Looper.getMainLooper()).post { notifyDataSetChanged() }
|
||||
}
|
||||
|
||||
private fun firstOfMonth(timestamp: Long): Long {
|
||||
val cal = Calendar.getInstance()
|
||||
cal.time = Date(timestamp)
|
||||
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH))
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0)
|
||||
cal.set(Calendar.MINUTE, 0)
|
||||
cal.set(Calendar.SECOND, 0)
|
||||
|
||||
return cal.timeInMillis
|
||||
}
|
||||
|
||||
fun isEmpty(): Boolean {
|
||||
return files.isEmpty()
|
||||
}
|
||||
|
||||
fun getItem(position: Int): OCFile? {
|
||||
val itemCoord = getRelativePosition(position)
|
||||
return files
|
||||
.getOrNull(itemCoord.section())?.files
|
||||
?.getOrNull(itemCoord.relativePos())
|
||||
}
|
||||
|
||||
override fun isMultiSelect(): Boolean {
|
||||
return ocFileListDelegate.isMultiSelect
|
||||
}
|
||||
|
||||
override fun cancelAllPendingTasks() {
|
||||
ocFileListDelegate.cancelAllPendingTasks()
|
||||
}
|
||||
|
||||
override fun getItemPosition(file: OCFile): Int {
|
||||
val item = files.find { it.files.contains(file) }
|
||||
return getAbsolutePosition(files.indexOf(item), item?.files?.indexOf(file) ?: 0)
|
||||
}
|
||||
|
||||
override fun swapDirectory(
|
||||
user: User,
|
||||
directory: OCFile,
|
||||
storageManager: FileDataStorageManager,
|
||||
onlyOnDevice: Boolean,
|
||||
mLimitToMimeType: String
|
||||
) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun setHighlightedItem(file: OCFile) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun setSortOrder(mFile: OCFile, sortOrder: FileSortOrder) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun addCheckedFile(file: OCFile) {
|
||||
ocFileListDelegate.addCheckedFile(file)
|
||||
}
|
||||
|
||||
override fun isCheckedFile(file: OCFile): Boolean {
|
||||
return ocFileListDelegate.isCheckedFile(file)
|
||||
}
|
||||
|
||||
override fun getCheckedItems(): Set<OCFile> {
|
||||
return ocFileListDelegate.checkedItems
|
||||
}
|
||||
|
||||
override fun removeCheckedFile(file: OCFile) {
|
||||
ocFileListDelegate.removeCheckedFile(file)
|
||||
}
|
||||
|
||||
override fun notifyItemChanged(file: OCFile) {
|
||||
notifyItemChanged(getItemPosition(file))
|
||||
}
|
||||
|
||||
override fun getFilesCount(): Int {
|
||||
return files.fold(0) { acc, item -> acc + item.files.size }
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun setMultiSelect(boolean: Boolean) {
|
||||
ocFileListDelegate.isMultiSelect = boolean
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun clearCheckedItems() {
|
||||
ocFileListDelegate.clearCheckedItems()
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
fun addFiles(items: List<GalleryItems>) {
|
||||
files = items
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import com.afollestad.sectionedrecyclerview.SectionedViewHolder
|
||||
import com.owncloud.android.databinding.GalleryHeaderBinding
|
||||
|
||||
class GalleryHeaderViewHolder(val binding: GalleryHeaderBinding) : SectionedViewHolder(binding.root)
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import com.afollestad.sectionedrecyclerview.SectionedViewHolder
|
||||
import com.elyeproj.loaderviewlibrary.LoaderImageView
|
||||
import com.owncloud.android.databinding.GridImageBinding
|
||||
|
||||
class GalleryItemViewHolder(val binding: GridImageBinding) :
|
||||
SectionedViewHolder(binding.root), ListGridImageViewHolder {
|
||||
override val thumbnail: ImageView
|
||||
get() = binding.thumbnail
|
||||
|
||||
override val shimmerThumbnail: LoaderImageView
|
||||
get() = binding.thumbnailShimmer
|
||||
|
||||
override val favorite: ImageView
|
||||
get() = binding.favoriteAction
|
||||
|
||||
override val localFileIndicator: ImageView
|
||||
get() = binding.localFileIndicator
|
||||
|
||||
override val shared: ImageView
|
||||
get() = binding.sharedIcon
|
||||
|
||||
override val checkbox: ImageView
|
||||
get() = binding.customCheckbox
|
||||
|
||||
override val itemLayout: View
|
||||
get() = binding.ListItemLayout
|
||||
|
||||
override val unreadComments: ImageView
|
||||
get() = binding.unreadComments
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import com.elyeproj.loaderviewlibrary.LoaderImageView
|
||||
|
||||
interface ListGridImageViewHolder {
|
||||
val thumbnail: ImageView
|
||||
val shimmerThumbnail: LoaderImageView
|
||||
val favorite: ImageView
|
||||
val localFileIndicator: ImageView
|
||||
val shared: ImageView
|
||||
val checkbox: ImageView
|
||||
val itemLayout: View
|
||||
val unreadComments: ImageView
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import android.widget.TextView
|
||||
|
||||
internal interface ListGridItemViewHolder : ListGridImageViewHolder {
|
||||
val fileName: TextView
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.owncloud.android.ui.AvatarGroupLayout
|
||||
|
||||
internal interface ListItemViewHolder : ListGridItemViewHolder {
|
||||
val fileSize: TextView
|
||||
val fileSizeSeparator: View
|
||||
val lastModification: TextView
|
||||
val overflowMenu: ImageView
|
||||
val sharedAvatars: AvatarGroupLayout
|
||||
}
|
||||
@@ -1,948 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* @author Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* Copyright (C) 2018 Tobias Kaminsky
|
||||
* Copyright (C) 2018 Nextcloud
|
||||
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* 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.adapter;
|
||||
|
||||
import android.accounts.AccountManager;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ContentValues;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.elyeproj.loaderviewlibrary.LoaderImageView;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.databinding.GridImageBinding;
|
||||
import com.owncloud.android.databinding.GridItemBinding;
|
||||
import com.owncloud.android.databinding.ListFooterBinding;
|
||||
import com.owncloud.android.databinding.ListHeaderBinding;
|
||||
import com.owncloud.android.databinding.ListItemBinding;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||
import com.owncloud.android.datamodel.VirtualFolderType;
|
||||
import com.owncloud.android.db.ProviderMeta;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.files.model.RemoteFile;
|
||||
import com.owncloud.android.lib.resources.shares.OCShare;
|
||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||
import com.owncloud.android.lib.resources.shares.ShareeUser;
|
||||
import com.owncloud.android.operations.RefreshFolderOperation;
|
||||
import com.owncloud.android.operations.RemoteOperationFailedException;
|
||||
import com.owncloud.android.ui.activity.ComponentsGetter;
|
||||
import com.owncloud.android.ui.fragment.SearchType;
|
||||
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface;
|
||||
import com.owncloud.android.ui.preview.PreviewTextFragment;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.FileSortOrder;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
import com.owncloud.android.utils.MimeTypeUtil;
|
||||
import com.owncloud.android.utils.theme.CapabilityUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeDrawableUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import me.zhanghai.android.fastscroll.PopupTextProvider;
|
||||
|
||||
/**
|
||||
* This Adapter populates a RecyclerView with all files and folders in a Nextcloud instance.
|
||||
*/
|
||||
public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
implements DisplayUtils.AvatarGenerationListener,
|
||||
CommonOCFileListAdapterInterface, PopupTextProvider {
|
||||
|
||||
private static final int showFilenameColumnThreshold = 4;
|
||||
private final String userId;
|
||||
private Activity activity;
|
||||
private AppPreferences preferences;
|
||||
private List<OCFile> mFiles = new ArrayList<>();
|
||||
private List<OCFile> mFilesAll = new ArrayList<>();
|
||||
private boolean hideItemOptions;
|
||||
private long lastTimestamp;
|
||||
private boolean gridView;
|
||||
|
||||
private FileDataStorageManager mStorageManager;
|
||||
private User user;
|
||||
private OCFileListFragmentInterface ocFileListFragmentInterface;
|
||||
|
||||
private OCFile currentDirectory;
|
||||
private static final String TAG = OCFileListAdapter.class.getSimpleName();
|
||||
|
||||
private static final int VIEWTYPE_FOOTER = 0;
|
||||
private static final int VIEWTYPE_ITEM = 1;
|
||||
private static final int VIEWTYPE_IMAGE = 2;
|
||||
private static final int VIEWTYPE_HEADER = 3;
|
||||
|
||||
private boolean onlyOnDevice;
|
||||
private final OCFileListDelegate ocFileListDelegate;
|
||||
private FileSortOrder sortOrder;
|
||||
|
||||
private final SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM yyyy", Locale.getDefault());
|
||||
|
||||
public OCFileListAdapter(
|
||||
Activity activity,
|
||||
@NonNull User user,
|
||||
AppPreferences preferences,
|
||||
ComponentsGetter transferServiceGetter,
|
||||
OCFileListFragmentInterface ocFileListFragmentInterface,
|
||||
boolean argHideItemOptions,
|
||||
boolean gridView
|
||||
) {
|
||||
this.ocFileListFragmentInterface = ocFileListFragmentInterface;
|
||||
this.activity = activity;
|
||||
this.preferences = preferences;
|
||||
this.user = user;
|
||||
hideItemOptions = argHideItemOptions;
|
||||
this.gridView = gridView;
|
||||
mStorageManager = transferServiceGetter.getStorageManager();
|
||||
|
||||
if (mStorageManager == null) {
|
||||
mStorageManager = new FileDataStorageManager(user, activity.getContentResolver());
|
||||
}
|
||||
|
||||
userId = AccountManager
|
||||
.get(activity)
|
||||
.getUserData(this.user.toPlatformAccount(),
|
||||
com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);
|
||||
|
||||
ocFileListDelegate = new OCFileListDelegate(activity,
|
||||
ocFileListFragmentInterface,
|
||||
user,
|
||||
mStorageManager,
|
||||
hideItemOptions,
|
||||
preferences,
|
||||
gridView,
|
||||
transferServiceGetter,
|
||||
true,
|
||||
CapabilityUtils
|
||||
.getCapability(activity)
|
||||
.getVersion()
|
||||
.isShareesOnDavSupported());
|
||||
|
||||
// initialise thumbnails cache on background thread
|
||||
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
|
||||
}
|
||||
|
||||
public boolean isMultiSelect() {
|
||||
return ocFileListDelegate.isMultiSelect();
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
public void setMultiSelect(boolean bool) {
|
||||
ocFileListDelegate.setMultiSelect(bool);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void removeCheckedFile(@NonNull OCFile file) {
|
||||
ocFileListDelegate.removeCheckedFile(file);
|
||||
}
|
||||
|
||||
public void addAllFilesToCheckedFiles() {
|
||||
ocFileListDelegate.addToCheckedFiles(mFiles);
|
||||
}
|
||||
|
||||
public int getItemPosition(@NonNull OCFile file) {
|
||||
int position = mFiles.indexOf(file);
|
||||
|
||||
if (shouldShowHeader()) {
|
||||
position = position + 1;
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setFavoriteAttributeForItemID(String fileId, boolean favorite, boolean removeFromList) {
|
||||
for (OCFile file : mFiles) {
|
||||
if (file.getRemoteId().equals(fileId)) {
|
||||
file.setFavorite(favorite);
|
||||
|
||||
if (removeFromList) {
|
||||
mFiles.remove(file);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (OCFile file : mFilesAll) {
|
||||
if (file.getRemoteId().equals(fileId)) {
|
||||
file.setFavorite(favorite);
|
||||
|
||||
mStorageManager.saveFile(file);
|
||||
|
||||
if (removeFromList) {
|
||||
mFiles.remove(file);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FileSortOrder sortOrder = preferences.getSortOrderByFolder(currentDirectory);
|
||||
mFiles = sortOrder.sortCloudFiles(mFiles);
|
||||
|
||||
new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
|
||||
}
|
||||
|
||||
public void refreshCommentsCount(String fileId) {
|
||||
for (OCFile file : mFiles) {
|
||||
if (file.getRemoteId().equals(fileId)) {
|
||||
file.setUnreadCommentsCount(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (OCFile file : mFilesAll) {
|
||||
if (file.getRemoteId().equals(fileId)) {
|
||||
file.setUnreadCommentsCount(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
|
||||
}
|
||||
|
||||
public void setEncryptionAttributeForItemID(String fileId, boolean encrypted) {
|
||||
int filesSize = mFiles.size();
|
||||
for (int i = 0; i < filesSize; i++) {
|
||||
if (mFiles.get(i).getRemoteId().equals(fileId)) {
|
||||
OCFile file = mFiles.get(i);
|
||||
file.setEncrypted(encrypted);
|
||||
mStorageManager.saveFile(file);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
filesSize = mFilesAll.size();
|
||||
for (int i = 0; i < filesSize; i++) {
|
||||
if (mFilesAll.get(i).getRemoteId().equals(fileId)) {
|
||||
mFilesAll.get(i).setEncrypted(encrypted);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
if (mFiles == null || mFiles.size() <= position) {
|
||||
return 0;
|
||||
}
|
||||
return mFiles.get(position).getFileId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (shouldShowHeader()) {
|
||||
return mFiles.size() + 2; // for header and footer
|
||||
} else {
|
||||
return mFiles.size() + 1; // for footer
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return mFiles.size() == 0;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
switch (viewType) {
|
||||
default:
|
||||
case VIEWTYPE_ITEM:
|
||||
if (gridView) {
|
||||
return new OCFileListGridItemViewHolder(
|
||||
GridItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)
|
||||
);
|
||||
} else {
|
||||
return new OCFileListItemViewHolder(
|
||||
ListItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)
|
||||
);
|
||||
}
|
||||
|
||||
case VIEWTYPE_IMAGE:
|
||||
if (gridView) {
|
||||
return new OCFileListGridImageViewHolder(
|
||||
GridImageBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)
|
||||
);
|
||||
} else {
|
||||
return new OCFileListItemViewHolder(
|
||||
ListItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)
|
||||
);
|
||||
}
|
||||
|
||||
case VIEWTYPE_FOOTER:
|
||||
return new OCFileListFooterViewHolder(
|
||||
ListFooterBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)
|
||||
);
|
||||
|
||||
case VIEWTYPE_HEADER:
|
||||
ListHeaderBinding binding = ListHeaderBinding.inflate(
|
||||
LayoutInflater.from(parent.getContext()),
|
||||
parent,
|
||||
false);
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = binding.headerView.getLayoutParams();
|
||||
layoutParams.height = (int) (parent.getHeight() * 0.3);
|
||||
binding.headerView.setLayoutParams(layoutParams);
|
||||
|
||||
return new OCFileListHeaderViewHolder(binding);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressFBWarnings("ITC_INHERITANCE_TYPE_CHECKING")
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
if (holder instanceof OCFileListFooterViewHolder) {
|
||||
OCFileListFooterViewHolder footerViewHolder = (OCFileListFooterViewHolder) holder;
|
||||
footerViewHolder.getFooterText().setText(getFooterText());
|
||||
footerViewHolder.getLoadingProgressBar().getIndeterminateDrawable()
|
||||
.setColorFilter(ThemeColorUtils.primaryColor(activity), PorterDuff.Mode.SRC_IN);
|
||||
footerViewHolder.getLoadingProgressBar().setVisibility(
|
||||
ocFileListFragmentInterface.isLoading() ? View.VISIBLE : View.GONE);
|
||||
} else if (holder instanceof OCFileListHeaderViewHolder) {
|
||||
OCFileListHeaderViewHolder headerViewHolder = (OCFileListHeaderViewHolder) holder;
|
||||
String text = currentDirectory.getRichWorkspace();
|
||||
|
||||
PreviewTextFragment.setText(headerViewHolder.getHeaderText(), text, null, activity, true, true);
|
||||
headerViewHolder.getHeaderView().setOnClickListener(v -> ocFileListFragmentInterface.onHeaderClicked());
|
||||
} else {
|
||||
ListGridImageViewHolder gridViewHolder = (ListGridImageViewHolder) holder;
|
||||
OCFile file = getItem(position);
|
||||
|
||||
if (file == null) {
|
||||
Log_OC.e(this, "Cannot bind on view holder on a null file");
|
||||
return;
|
||||
}
|
||||
|
||||
ocFileListDelegate.bindGridViewHolder(gridViewHolder, file);
|
||||
|
||||
if (holder instanceof ListItemViewHolder) {
|
||||
bindListItemViewHolder((ListItemViewHolder) gridViewHolder, file);
|
||||
}
|
||||
|
||||
if (holder instanceof ListGridItemViewHolder) {
|
||||
bindListGridItemViewHolder((ListGridItemViewHolder) holder, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void bindListItemViewHolder(ListItemViewHolder holder, OCFile file) {
|
||||
if ((file.isSharedWithMe() || file.isSharedWithSharee()) && !isMultiSelect() && !gridView &&
|
||||
!hideItemOptions) {
|
||||
holder.getSharedAvatars().setVisibility(View.VISIBLE);
|
||||
holder.getSharedAvatars().removeAllViews();
|
||||
|
||||
String fileOwner = file.getOwnerId();
|
||||
List<ShareeUser> sharees = file.getSharees();
|
||||
|
||||
// use fileOwner if not oneself, then add at first
|
||||
ShareeUser fileOwnerSharee = new ShareeUser(fileOwner, file.getOwnerDisplayName(), ShareType.USER);
|
||||
if (!TextUtils.isEmpty(fileOwner) &&
|
||||
!fileOwner.equals(userId) &&
|
||||
!sharees.contains(fileOwnerSharee)) {
|
||||
sharees.add(fileOwnerSharee);
|
||||
}
|
||||
|
||||
Collections.reverse(sharees);
|
||||
|
||||
Log_OC.d(this, "sharees of " + file.getFileName() + ": " + sharees);
|
||||
|
||||
holder.getSharedAvatars().setAvatars(user, sharees);
|
||||
holder.getSharedAvatars().setOnClickListener(
|
||||
view -> ocFileListFragmentInterface.onShareIconClick(file));
|
||||
} else {
|
||||
holder.getSharedAvatars().setVisibility(View.GONE);
|
||||
holder.getSharedAvatars().removeAllViews();
|
||||
}
|
||||
|
||||
// npe fix: looks like file without local storage path somehow get here
|
||||
final String storagePath = file.getStoragePath();
|
||||
if (onlyOnDevice && storagePath != null) {
|
||||
File localFile = new File(storagePath);
|
||||
long localSize;
|
||||
if (localFile.isDirectory()) {
|
||||
localSize = FileStorageUtils.getFolderSize(localFile);
|
||||
} else {
|
||||
localSize = localFile.length();
|
||||
}
|
||||
|
||||
holder.getFileSize().setText(DisplayUtils.bytesToHumanReadable(localSize));
|
||||
holder.getFileSize().setVisibility(View.VISIBLE);
|
||||
holder.getFileSizeSeparator().setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
final long fileLength = file.getFileLength();
|
||||
if (fileLength >= 0) {
|
||||
holder.getFileSize().setText(DisplayUtils.bytesToHumanReadable(fileLength));
|
||||
holder.getFileSize().setVisibility(View.VISIBLE);
|
||||
holder.getFileSizeSeparator().setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.getFileSize().setVisibility(View.GONE);
|
||||
holder.getFileSizeSeparator().setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
final long modificationTimestamp = file.getModificationTimestamp();
|
||||
if (modificationTimestamp > 0) {
|
||||
holder.getLastModification().setText(DisplayUtils.getRelativeTimestamp(activity,
|
||||
modificationTimestamp));
|
||||
holder.getLastModification().setVisibility(View.VISIBLE);
|
||||
} else if (file.getFirstShareTimestamp() > 0) {
|
||||
holder.getLastModification().setText(
|
||||
DisplayUtils.getRelativeTimestamp(activity, file.getFirstShareTimestamp())
|
||||
);
|
||||
holder.getLastModification().setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.getLastModification().setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
if (isMultiSelect() || gridView || hideItemOptions) {
|
||||
holder.getOverflowMenu().setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.getOverflowMenu().setVisibility(View.VISIBLE);
|
||||
holder.getOverflowMenu().setOnClickListener(view -> ocFileListFragmentInterface
|
||||
.onOverflowIconClicked(file, view));
|
||||
}
|
||||
|
||||
if (file.isLocked()) {
|
||||
holder.getOverflowMenu().setImageResource(R.drawable.ic_locked_dots_small);
|
||||
} else {
|
||||
holder.getOverflowMenu().setImageResource(R.drawable.ic_dots_vertical);
|
||||
}
|
||||
}
|
||||
|
||||
private void bindListGridItemViewHolder(ListGridItemViewHolder holder, OCFile file) {
|
||||
holder.getFileName().setText(file.getDecryptedFileName());
|
||||
|
||||
boolean gridImage = MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file);
|
||||
if (gridView && gridImage) {
|
||||
holder.getFileName().setVisibility(View.GONE);
|
||||
} else {
|
||||
if (gridView && ocFileListFragmentInterface.getColumnsCount() > showFilenameColumnThreshold) {
|
||||
holder.getFileName().setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.getFileName().setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) {
|
||||
if (holder instanceof ListGridImageViewHolder) {
|
||||
LoaderImageView thumbnailShimmer = ((ListGridImageViewHolder) holder).getShimmerThumbnail();
|
||||
if (thumbnailShimmer.getVisibility() == View.VISIBLE) {
|
||||
thumbnailShimmer.setImageResource(R.drawable.background);
|
||||
thumbnailShimmer.resetLoader();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getFooterText() {
|
||||
int filesCount = 0;
|
||||
int foldersCount = 0;
|
||||
int count = mFiles.size();
|
||||
OCFile file;
|
||||
final boolean showHiddenFiles = preferences.isShowHiddenFilesEnabled();
|
||||
for (int i = 0; i < count; i++) {
|
||||
file = mFiles.get(i);
|
||||
if (file.isFolder()) {
|
||||
foldersCount++;
|
||||
} else {
|
||||
if (!file.isHidden() || showHiddenFiles) {
|
||||
filesCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return generateFooterText(filesCount, foldersCount);
|
||||
}
|
||||
|
||||
private String generateFooterText(int filesCount, int foldersCount) {
|
||||
String output;
|
||||
Resources resources = activity.getResources();
|
||||
|
||||
if (filesCount + foldersCount <= 0) {
|
||||
output = "";
|
||||
} else if (foldersCount <= 0) {
|
||||
output = resources.getQuantityString(R.plurals.file_list__footer__file, filesCount, filesCount);
|
||||
} else if (filesCount <= 0) {
|
||||
output = resources.getQuantityString(R.plurals.file_list__footer__folder, foldersCount, foldersCount);
|
||||
} else {
|
||||
output = resources.getQuantityString(R.plurals.file_list__footer__file, filesCount, filesCount) + ", " +
|
||||
resources.getQuantityString(R.plurals.file_list__footer__folder, foldersCount, foldersCount);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public @Nullable
|
||||
OCFile getItem(int position) {
|
||||
int newPosition = position;
|
||||
|
||||
if (shouldShowHeader() && position > 0) {
|
||||
newPosition = position - 1;
|
||||
}
|
||||
|
||||
if (newPosition >= mFiles.size()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return mFiles.get(newPosition);
|
||||
}
|
||||
|
||||
public boolean shouldShowHeader() {
|
||||
if (currentDirectory == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (MainApp.isOnlyOnDevice()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentDirectory.getRichWorkspace() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !TextUtils.isEmpty(currentDirectory.getRichWorkspace().trim());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (shouldShowHeader()) {
|
||||
if (position == 0) {
|
||||
return VIEWTYPE_HEADER;
|
||||
} else {
|
||||
if (position == mFiles.size() + 1) {
|
||||
return VIEWTYPE_FOOTER;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (position == mFiles.size()) {
|
||||
return VIEWTYPE_FOOTER;
|
||||
}
|
||||
}
|
||||
|
||||
OCFile item = getItem(position);
|
||||
if (item == null) {
|
||||
return VIEWTYPE_ITEM;
|
||||
}
|
||||
|
||||
if (MimeTypeUtil.isImageOrVideo(item)) {
|
||||
return VIEWTYPE_IMAGE;
|
||||
} else {
|
||||
return VIEWTYPE_ITEM;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the adapted directory for a new one
|
||||
*
|
||||
* @param directory New folder to adapt. Can be NULL, meaning "no content to adapt".
|
||||
* @param updatedStorageManager Optional updated storage manager; used to replace
|
||||
* @param limitToMimeType show only files of this mimeType
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
public void swapDirectory(
|
||||
@NonNull User account,
|
||||
@NonNull OCFile directory,
|
||||
@NonNull FileDataStorageManager updatedStorageManager,
|
||||
boolean onlyOnDevice, @NonNull String limitToMimeType
|
||||
) {
|
||||
this.onlyOnDevice = onlyOnDevice;
|
||||
|
||||
if (!updatedStorageManager.equals(mStorageManager)) {
|
||||
mStorageManager = updatedStorageManager;
|
||||
ocFileListDelegate.setShowShareAvatar(CapabilityUtils.getCapability(account, activity).getVersion().isShareesOnDavSupported());
|
||||
this.user = account;
|
||||
}
|
||||
if (mStorageManager != null) {
|
||||
mFiles = mStorageManager.getFolderContent(directory, onlyOnDevice);
|
||||
|
||||
if (!preferences.isShowHiddenFilesEnabled()) {
|
||||
mFiles = filterHiddenFiles(mFiles);
|
||||
}
|
||||
if (!limitToMimeType.isEmpty()) {
|
||||
mFiles = filterByMimeType(mFiles, limitToMimeType);
|
||||
}
|
||||
sortOrder = preferences.getSortOrderByFolder(directory);
|
||||
mFiles = sortOrder.sortCloudFiles(mFiles);
|
||||
mFilesAll.clear();
|
||||
mFilesAll.addAll(mFiles);
|
||||
|
||||
currentDirectory = directory;
|
||||
} else {
|
||||
mFiles.clear();
|
||||
mFilesAll.clear();
|
||||
}
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setData(List<Object> objects,
|
||||
SearchType searchType,
|
||||
FileDataStorageManager storageManager,
|
||||
@Nullable OCFile folder,
|
||||
boolean clear) {
|
||||
if (storageManager != null && mStorageManager == null) {
|
||||
mStorageManager = storageManager;
|
||||
ocFileListDelegate.setShowShareAvatar(mStorageManager
|
||||
.getCapability(user.getAccountName())
|
||||
.getVersion()
|
||||
.isShareesOnDavSupported());
|
||||
}
|
||||
|
||||
if (mStorageManager == null) {
|
||||
mStorageManager = new FileDataStorageManager(user, activity.getContentResolver());
|
||||
}
|
||||
|
||||
if (clear) {
|
||||
mFiles.clear();
|
||||
resetLastTimestamp();
|
||||
preferences.setPhotoSearchTimestamp(0);
|
||||
|
||||
VirtualFolderType type;
|
||||
switch (searchType) {
|
||||
case FAVORITE_SEARCH:
|
||||
type = VirtualFolderType.FAVORITE;
|
||||
break;
|
||||
case GALLERY_SEARCH:
|
||||
type = VirtualFolderType.GALLERY;
|
||||
break;
|
||||
default:
|
||||
type = VirtualFolderType.NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (type != VirtualFolderType.GALLERY) {
|
||||
mStorageManager.deleteVirtuals(type);
|
||||
}
|
||||
}
|
||||
|
||||
// early exit
|
||||
if (objects.size() > 0 && mStorageManager != null) {
|
||||
if (searchType == SearchType.SHARED_FILTER) {
|
||||
parseShares(objects);
|
||||
} else {
|
||||
if (searchType != SearchType.GALLERY_SEARCH) {
|
||||
parseVirtuals(objects, searchType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (searchType == SearchType.GALLERY_SEARCH ||
|
||||
searchType == SearchType.RECENTLY_MODIFIED_SEARCH) {
|
||||
mFiles = FileStorageUtils.sortOcFolderDescDateModifiedWithoutFavoritesFirst(mFiles);
|
||||
} else if (searchType != SearchType.SHARED_FILTER) {
|
||||
FileSortOrder sortOrder = preferences.getSortOrderByFolder(folder);
|
||||
mFiles = sortOrder.sortCloudFiles(mFiles);
|
||||
}
|
||||
|
||||
mFilesAll.clear();
|
||||
mFilesAll.addAll(mFiles);
|
||||
|
||||
new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
|
||||
}
|
||||
|
||||
private void parseShares(List<Object> objects) {
|
||||
List<OCShare> shares = new ArrayList<>();
|
||||
|
||||
for (Object shareObject : objects) {
|
||||
// check type before cast as of long running data fetch it is possible that old result is filled
|
||||
if (shareObject instanceof OCShare) {
|
||||
OCShare ocShare = (OCShare) shareObject;
|
||||
shares.add(ocShare);
|
||||
}
|
||||
}
|
||||
|
||||
List<OCFile> files = OCShareToOCFileConverter.buildOCFilesFromShares(shares);
|
||||
mFiles.addAll(files);
|
||||
mStorageManager.saveShares(shares);
|
||||
}
|
||||
|
||||
private void parseVirtuals(List<Object> objects, SearchType searchType) {
|
||||
VirtualFolderType type;
|
||||
boolean onlyMedia = false;
|
||||
|
||||
switch (searchType) {
|
||||
case FAVORITE_SEARCH:
|
||||
type = VirtualFolderType.FAVORITE;
|
||||
break;
|
||||
case GALLERY_SEARCH:
|
||||
type = VirtualFolderType.GALLERY;
|
||||
onlyMedia = true;
|
||||
|
||||
int lastPosition = objects.size() - 1;
|
||||
|
||||
if (lastPosition < 0) {
|
||||
lastTimestamp = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
RemoteFile lastFile = (RemoteFile) objects.get(lastPosition);
|
||||
lastTimestamp = lastFile.getModifiedTimestamp() / 1000;
|
||||
break;
|
||||
default:
|
||||
type = VirtualFolderType.NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
List<ContentValues> contentValues = new ArrayList<>();
|
||||
|
||||
for (Object remoteFile : objects) {
|
||||
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) remoteFile);
|
||||
FileStorageUtils.searchForLocalFileInDefaultPath(ocFile, user.getAccountName());
|
||||
|
||||
try {
|
||||
ocFile = mStorageManager.saveFileWithParent(ocFile, activity);
|
||||
|
||||
if (SearchType.GALLERY_SEARCH != searchType) {
|
||||
// also sync folder content
|
||||
if (ocFile.isFolder()) {
|
||||
long currentSyncTime = System.currentTimeMillis();
|
||||
RemoteOperation refreshFolderOperation = new RefreshFolderOperation(ocFile,
|
||||
currentSyncTime,
|
||||
true,
|
||||
false,
|
||||
mStorageManager,
|
||||
user,
|
||||
activity);
|
||||
refreshFolderOperation.execute(user.toPlatformAccount(), activity);
|
||||
}
|
||||
}
|
||||
|
||||
if (!onlyMedia || MimeTypeUtil.isImage(ocFile) || MimeTypeUtil.isVideo(ocFile)) {
|
||||
mFiles.add(ocFile);
|
||||
}
|
||||
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE, type.toString());
|
||||
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile.getFileId());
|
||||
|
||||
contentValues.add(cv);
|
||||
} catch (RemoteOperationFailedException e) {
|
||||
Log_OC.e(TAG, "Error saving file with parent" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
preferences.setPhotoSearchTimestamp(System.currentTimeMillis());
|
||||
mStorageManager.saveVirtuals(contentValues);
|
||||
}
|
||||
|
||||
public void showVirtuals(VirtualFolderType type, boolean onlyImages, FileDataStorageManager storageManager) {
|
||||
mFiles = storageManager.getVirtualFolderContent(type, onlyImages);
|
||||
|
||||
if (VirtualFolderType.GALLERY == type) {
|
||||
mFiles = FileStorageUtils.sortOcFolderDescDateModifiedWithoutFavoritesFirst(mFiles);
|
||||
}
|
||||
|
||||
mFilesAll.clear();
|
||||
mFilesAll.addAll(mFiles);
|
||||
|
||||
new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
|
||||
}
|
||||
|
||||
|
||||
public void setSortOrder(@Nullable OCFile folder, FileSortOrder sortOrder) {
|
||||
preferences.setSortOrder(folder, sortOrder);
|
||||
mFiles = sortOrder.sortCloudFiles(mFiles);
|
||||
notifyDataSetChanged();
|
||||
|
||||
this.sortOrder = sortOrder;
|
||||
}
|
||||
|
||||
public Set<OCFile> getCheckedItems() {
|
||||
return ocFileListDelegate.getCheckedItems();
|
||||
}
|
||||
|
||||
public void setCheckedItem(Set<OCFile> files) {
|
||||
ocFileListDelegate.setCheckedItem(files);
|
||||
}
|
||||
|
||||
public void clearCheckedItems() {
|
||||
ocFileListDelegate.clearCheckedItems();
|
||||
}
|
||||
|
||||
public void setFiles(List<OCFile> files) {
|
||||
mFiles = files;
|
||||
}
|
||||
|
||||
public List<OCFile> getFiles() {
|
||||
return mFiles;
|
||||
}
|
||||
|
||||
public void resetLastTimestamp() {
|
||||
lastTimestamp = -1;
|
||||
}
|
||||
|
||||
public long getLastTimestamp() {
|
||||
return lastTimestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void avatarGenerated(Drawable avatarDrawable, Object callContext) {
|
||||
((ImageView) callContext).setImageDrawable(avatarDrawable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCallGeneratedCallback(String tag, Object callContext) {
|
||||
return ((ImageView) callContext).getTag().equals(tag);
|
||||
}
|
||||
|
||||
public boolean isCheckedFile(OCFile file) {
|
||||
return ocFileListDelegate.isCheckedFile(file);
|
||||
}
|
||||
|
||||
public void addCheckedFile(OCFile file) {
|
||||
ocFileListDelegate.addCheckedFile(file);
|
||||
}
|
||||
|
||||
public void setHighlightedItem(OCFile file) {
|
||||
ocFileListDelegate.setHighlightedItem(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter for hidden files
|
||||
*
|
||||
* @param files Collection of files to filter
|
||||
* @return Non-hidden files
|
||||
*/
|
||||
private List<OCFile> filterHiddenFiles(List<OCFile> files) {
|
||||
List<OCFile> ret = new ArrayList<>();
|
||||
|
||||
for (OCFile file : files) {
|
||||
if (!file.isHidden() && !ret.contains(file)) {
|
||||
ret.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private List<OCFile> filterByMimeType(List<OCFile> files, String mimeType) {
|
||||
List<OCFile> ret = new ArrayList<>();
|
||||
|
||||
for (OCFile file : files) {
|
||||
if (file.isFolder() || file.getMimeType().startsWith(mimeType)) {
|
||||
ret.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void cancelAllPendingTasks() {
|
||||
ocFileListDelegate.cancelAllPendingTasks();
|
||||
}
|
||||
|
||||
public void setGridView(boolean bool) {
|
||||
gridView = bool;
|
||||
}
|
||||
|
||||
public void setShowMetadata(boolean bool) {
|
||||
ocFileListDelegate.setMultiSelect(bool);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getPopupText(int position) {
|
||||
OCFile file = getItem(position);
|
||||
|
||||
if (file == null || sortOrder == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
switch (sortOrder.getType()) {
|
||||
case ALPHABET:
|
||||
return String.valueOf(file.getFileName().charAt(0)).toUpperCase(Locale.getDefault());
|
||||
case DATE:
|
||||
long milliseconds = file.getModificationTimestamp();
|
||||
Date date = new Date(milliseconds);
|
||||
return dateFormat.format(date);
|
||||
case SIZE:
|
||||
return DisplayUtils.bytesToHumanReadable(file.getFileLength());
|
||||
default:
|
||||
Log_OC.d(TAG, "getPopupText: Unsupported sort order: " + sortOrder.getType());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void setShowShareAvatar(boolean bool) {
|
||||
ocFileListDelegate.setShowShareAvatar(bool);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void setCurrentDirectory(OCFile folder) {
|
||||
currentDirectory = folder;
|
||||
}
|
||||
|
||||
@SuppressFBWarnings("EI_EXPOSE_REP")
|
||||
public List<OCFile> getAllFiles() {
|
||||
return mFilesAll;
|
||||
}
|
||||
|
||||
public OCFile getCurrentDirectory() {
|
||||
return currentDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFilesCount() {
|
||||
return mFiles.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyItemChanged(@NonNull OCFile file) {
|
||||
notifyItemChanged(getItemPosition(file));
|
||||
}
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import com.nextcloud.client.account.User
|
||||
import com.nextcloud.client.preferences.AppPreferences
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager.ThumbnailGenerationTask
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.ui.activity.ComponentsGetter
|
||||
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils
|
||||
import com.owncloud.android.utils.theme.ThemeDrawableUtils
|
||||
|
||||
@Suppress("LongParameterList", "TooManyFunctions")
|
||||
class OCFileListDelegate(
|
||||
private val context: Context,
|
||||
private val ocFileListFragmentInterface: OCFileListFragmentInterface,
|
||||
private val user: User,
|
||||
private val storageManager: FileDataStorageManager,
|
||||
private val hideItemOptions: Boolean,
|
||||
private val preferences: AppPreferences,
|
||||
private val gridView: Boolean,
|
||||
private val transferServiceGetter: ComponentsGetter,
|
||||
private val showMetadata: Boolean,
|
||||
private var showShareAvatar: Boolean
|
||||
) {
|
||||
private val checkedFiles: MutableSet<OCFile> = HashSet()
|
||||
private var highlightedItem: OCFile? = null
|
||||
var isMultiSelect = false
|
||||
private val asyncTasks: MutableList<ThumbnailGenerationTask> = ArrayList()
|
||||
fun setHighlightedItem(highlightedItem: OCFile?) {
|
||||
this.highlightedItem = highlightedItem
|
||||
}
|
||||
|
||||
fun isCheckedFile(file: OCFile): Boolean {
|
||||
return checkedFiles.contains(file)
|
||||
}
|
||||
|
||||
fun addCheckedFile(file: OCFile) {
|
||||
checkedFiles.add(file)
|
||||
highlightedItem = null
|
||||
}
|
||||
|
||||
fun removeCheckedFile(file: OCFile) {
|
||||
checkedFiles.remove(file)
|
||||
}
|
||||
|
||||
fun addToCheckedFiles(files: List<OCFile>?) {
|
||||
checkedFiles.addAll(files!!)
|
||||
}
|
||||
|
||||
val checkedItems: Set<OCFile>
|
||||
get() = checkedFiles
|
||||
|
||||
fun setCheckedItem(files: Set<OCFile>?) {
|
||||
checkedFiles.clear()
|
||||
checkedFiles.addAll(files!!)
|
||||
}
|
||||
|
||||
fun clearCheckedItems() {
|
||||
checkedFiles.clear()
|
||||
}
|
||||
|
||||
fun bindGridViewHolder(gridViewHolder: ListGridImageViewHolder, file: OCFile) {
|
||||
// thumbnail
|
||||
gridViewHolder.thumbnail.tag = file.fileId
|
||||
DisplayUtils.setThumbnail(
|
||||
file,
|
||||
gridViewHolder.thumbnail,
|
||||
user,
|
||||
storageManager,
|
||||
asyncTasks,
|
||||
gridView,
|
||||
context,
|
||||
gridViewHolder.shimmerThumbnail,
|
||||
preferences
|
||||
)
|
||||
// item layout + click listeners
|
||||
bindGridItemLayout(file, gridViewHolder)
|
||||
|
||||
// unread comments
|
||||
bindUnreadComments(file, gridViewHolder)
|
||||
|
||||
// multiSelect (Checkbox)
|
||||
if (isMultiSelect) {
|
||||
gridViewHolder.checkbox.visibility = View.VISIBLE
|
||||
} else {
|
||||
gridViewHolder.checkbox.visibility = View.GONE
|
||||
}
|
||||
|
||||
// download state
|
||||
gridViewHolder.localFileIndicator.visibility = View.INVISIBLE // default first
|
||||
|
||||
// metadata (downloaded, favorite)
|
||||
bindGridMetadataViews(file, gridViewHolder)
|
||||
|
||||
// shares
|
||||
val shouldHideShare = gridView || hideItemOptions || file.isFolder && !file.canReshare()
|
||||
if (shouldHideShare) {
|
||||
gridViewHolder.shared.visibility = View.GONE
|
||||
} else {
|
||||
showShareIcon(gridViewHolder, file)
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindUnreadComments(file: OCFile, gridViewHolder: ListGridImageViewHolder) {
|
||||
if (file.unreadCommentsCount > 0) {
|
||||
gridViewHolder.unreadComments.visibility = View.VISIBLE
|
||||
gridViewHolder.unreadComments.setOnClickListener {
|
||||
ocFileListFragmentInterface
|
||||
.showActivityDetailView(file)
|
||||
}
|
||||
} else {
|
||||
gridViewHolder.unreadComments.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindGridItemLayout(file: OCFile, gridViewHolder: ListGridImageViewHolder) {
|
||||
if (highlightedItem != null && file.fileId == highlightedItem!!.fileId) {
|
||||
gridViewHolder.itemLayout.setBackgroundColor(
|
||||
context.resources
|
||||
.getColor(R.color.selected_item_background)
|
||||
)
|
||||
} else if (isCheckedFile(file)) {
|
||||
gridViewHolder.itemLayout.setBackgroundColor(
|
||||
context.resources
|
||||
.getColor(R.color.selected_item_background)
|
||||
)
|
||||
gridViewHolder.checkbox.setImageDrawable(
|
||||
ThemeDrawableUtils.tintDrawable(
|
||||
R.drawable.ic_checkbox_marked,
|
||||
ThemeColorUtils.primaryColor(context)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
gridViewHolder.itemLayout.setBackgroundColor(context.resources.getColor(R.color.bg_default))
|
||||
gridViewHolder.checkbox.setImageResource(R.drawable.ic_checkbox_blank_outline)
|
||||
}
|
||||
gridViewHolder.itemLayout.setOnClickListener { ocFileListFragmentInterface.onItemClicked(file) }
|
||||
if (!hideItemOptions) {
|
||||
gridViewHolder.itemLayout.isLongClickable = true
|
||||
gridViewHolder.itemLayout.setOnLongClickListener {
|
||||
ocFileListFragmentInterface.onLongItemClicked(
|
||||
file
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindGridMetadataViews(file: OCFile, gridViewHolder: ListGridImageViewHolder) {
|
||||
if (showMetadata) {
|
||||
showLocalFileIndicator(file, gridViewHolder)
|
||||
gridViewHolder.favorite.visibility = if (file.isFavorite) View.VISIBLE else View.GONE
|
||||
} else {
|
||||
gridViewHolder.localFileIndicator.visibility = View.GONE
|
||||
gridViewHolder.favorite.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun showLocalFileIndicator(file: OCFile, gridViewHolder: ListGridImageViewHolder) {
|
||||
val operationsServiceBinder = transferServiceGetter.operationsServiceBinder
|
||||
val fileDownloaderBinder = transferServiceGetter.fileDownloaderBinder
|
||||
val fileUploaderBinder = transferServiceGetter.fileUploaderBinder
|
||||
when {
|
||||
operationsServiceBinder?.isSynchronizing(user, file) == true ||
|
||||
fileDownloaderBinder?.isDownloading(user, file) == true ||
|
||||
fileUploaderBinder?.isUploading(user, file) == true -> {
|
||||
// synchronizing, downloading or uploading
|
||||
gridViewHolder.localFileIndicator.setImageResource(R.drawable.ic_synchronizing)
|
||||
gridViewHolder.localFileIndicator.visibility = View.VISIBLE
|
||||
}
|
||||
file.etagInConflict != null -> {
|
||||
// conflict
|
||||
gridViewHolder.localFileIndicator.setImageResource(R.drawable.ic_synchronizing_error)
|
||||
gridViewHolder.localFileIndicator.visibility = View.VISIBLE
|
||||
}
|
||||
file.isDown -> {
|
||||
// downloaded
|
||||
gridViewHolder.localFileIndicator.setImageResource(R.drawable.ic_synced)
|
||||
gridViewHolder.localFileIndicator.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showShareIcon(gridViewHolder: ListGridImageViewHolder, file: OCFile) {
|
||||
val sharedIconView = gridViewHolder.shared
|
||||
if (gridViewHolder is OCFileListItemViewHolder || file.unreadCommentsCount == 0) {
|
||||
sharedIconView.visibility = View.VISIBLE
|
||||
if (file.isSharedWithSharee || file.isSharedWithMe) {
|
||||
if (showShareAvatar) {
|
||||
sharedIconView.visibility = View.GONE
|
||||
} else {
|
||||
sharedIconView.visibility = View.VISIBLE
|
||||
sharedIconView.setImageResource(R.drawable.shared_via_users)
|
||||
sharedIconView.contentDescription = context.getString(R.string.shared_icon_shared)
|
||||
}
|
||||
} else if (file.isSharedViaLink) {
|
||||
sharedIconView.setImageResource(R.drawable.shared_via_link)
|
||||
sharedIconView.contentDescription = context.getString(R.string.shared_icon_shared_via_link)
|
||||
} else {
|
||||
sharedIconView.setImageResource(R.drawable.ic_unshared)
|
||||
sharedIconView.contentDescription = context.getString(R.string.shared_icon_share)
|
||||
}
|
||||
sharedIconView.setOnClickListener { ocFileListFragmentInterface.onShareIconClick(file) }
|
||||
} else {
|
||||
sharedIconView.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
fun cancelAllPendingTasks() {
|
||||
for (task in asyncTasks) {
|
||||
task.cancel(true)
|
||||
if (task.getMethod != null) {
|
||||
Log_OC.d(TAG, "cancel: abort get method directly")
|
||||
task.getMethod.abort()
|
||||
}
|
||||
}
|
||||
asyncTasks.clear()
|
||||
}
|
||||
|
||||
fun setShowShareAvatar(bool: Boolean) {
|
||||
showShareAvatar = bool
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = OCFileListDelegate::class.java.simpleName
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.owncloud.android.databinding.ListFooterBinding
|
||||
|
||||
internal class OCFileListFooterViewHolder(var binding: ListFooterBinding) : RecyclerView.ViewHolder(
|
||||
binding.root
|
||||
) {
|
||||
val footerText
|
||||
get() = binding.footerText
|
||||
|
||||
val loadingProgressBar
|
||||
get() = binding.loadingProgressBar
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.elyeproj.loaderviewlibrary.LoaderImageView
|
||||
import com.owncloud.android.databinding.GridImageBinding
|
||||
|
||||
internal class OCFileListGridImageViewHolder(var binding: GridImageBinding) :
|
||||
RecyclerView.ViewHolder(
|
||||
binding.root
|
||||
),
|
||||
ListGridImageViewHolder {
|
||||
override val thumbnail: ImageView
|
||||
get() = binding.thumbnail
|
||||
override val shimmerThumbnail: LoaderImageView
|
||||
get() = binding.thumbnailShimmer
|
||||
override val favorite: ImageView
|
||||
get() = binding.favoriteAction
|
||||
override val localFileIndicator: ImageView
|
||||
get() = binding.localFileIndicator
|
||||
override val shared: ImageView
|
||||
get() = binding.sharedIcon
|
||||
override val checkbox: ImageView
|
||||
get() = binding.customCheckbox
|
||||
override val itemLayout: View
|
||||
get() = binding.ListItemLayout
|
||||
override val unreadComments: ImageView
|
||||
get() = binding.unreadComments
|
||||
|
||||
init {
|
||||
binding.favoriteAction.drawable.mutate()
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.elyeproj.loaderviewlibrary.LoaderImageView
|
||||
import com.owncloud.android.databinding.GridItemBinding
|
||||
|
||||
internal class OCFileListGridItemViewHolder(var binding: GridItemBinding) :
|
||||
RecyclerView.ViewHolder(
|
||||
binding.root
|
||||
),
|
||||
ListGridItemViewHolder {
|
||||
override val fileName: TextView
|
||||
get() = binding.Filename
|
||||
override val thumbnail: ImageView
|
||||
get() = binding.thumbnail
|
||||
override val shimmerThumbnail: LoaderImageView
|
||||
get() = binding.thumbnailShimmer
|
||||
override val favorite: ImageView
|
||||
get() = binding.favoriteAction
|
||||
override val localFileIndicator: ImageView
|
||||
get() = binding.localFileIndicator
|
||||
override val shared: ImageView
|
||||
get() = binding.sharedIcon
|
||||
override val checkbox: ImageView
|
||||
get() = binding.customCheckbox
|
||||
override val itemLayout: View
|
||||
get() = binding.ListItemLayout
|
||||
override val unreadComments: ImageView
|
||||
get() = binding.unreadComments
|
||||
|
||||
init {
|
||||
binding.favoriteAction.drawable.mutate()
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.owncloud.android.databinding.ListHeaderBinding
|
||||
|
||||
internal class OCFileListHeaderViewHolder(var binding: ListHeaderBinding) : RecyclerView.ViewHolder(
|
||||
binding.root
|
||||
) {
|
||||
val headerText
|
||||
get() = binding.headerText
|
||||
|
||||
val headerView
|
||||
get() = binding.headerView
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2022 Tobias Kaminsky
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.elyeproj.loaderviewlibrary.LoaderImageView
|
||||
import com.owncloud.android.databinding.ListItemBinding
|
||||
import com.owncloud.android.ui.AvatarGroupLayout
|
||||
|
||||
internal class OCFileListItemViewHolder(private var binding: ListItemBinding) :
|
||||
RecyclerView.ViewHolder(
|
||||
binding.root
|
||||
),
|
||||
ListItemViewHolder {
|
||||
override val fileSize: TextView
|
||||
get() = binding.fileSize
|
||||
override val fileSizeSeparator: View
|
||||
get() = binding.fileSeparator
|
||||
override val lastModification: TextView
|
||||
get() = binding.lastMod
|
||||
override val overflowMenu: ImageView
|
||||
get() = binding.overflowMenu
|
||||
override val sharedAvatars: AvatarGroupLayout
|
||||
get() = binding.sharedAvatars
|
||||
override val fileName: TextView
|
||||
get() = binding.Filename
|
||||
override val thumbnail: ImageView
|
||||
get() = binding.thumbnail
|
||||
override val shimmerThumbnail: LoaderImageView
|
||||
get() = binding.thumbnailShimmer
|
||||
override val favorite: ImageView
|
||||
get() = binding.favoriteAction
|
||||
override val localFileIndicator: ImageView
|
||||
get() = binding.localFileIndicator
|
||||
override val shared: ImageView
|
||||
get() = binding.sharedIcon
|
||||
override val checkbox: ImageView
|
||||
get() = binding.customCheckbox
|
||||
override val itemLayout: View
|
||||
get() = binding.ListItemLayout
|
||||
override val unreadComments: ImageView
|
||||
get() = binding.unreadComments
|
||||
|
||||
init {
|
||||
binding.favoriteAction.drawable.mutate()
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.resources.shares.OCShare
|
||||
import com.owncloud.android.lib.resources.shares.ShareType
|
||||
import com.owncloud.android.lib.resources.shares.ShareeUser
|
||||
|
||||
object OCShareToOCFileConverter {
|
||||
private const val MILLIS_PER_SECOND = 1000
|
||||
|
||||
/**
|
||||
* Generates a list of incomplete [OCFile] from a list of [OCShare]
|
||||
*
|
||||
* This is actually pretty complex as we get one [OCShare] item for each shared instance for the same folder
|
||||
*
|
||||
* **THIS ONLY WORKS WITH FILES SHARED *BY* THE USER, NOT FOR SHARES *WITH* THE USER**
|
||||
*/
|
||||
@JvmStatic
|
||||
fun buildOCFilesFromShares(shares: List<OCShare>): List<OCFile> {
|
||||
val groupedByPath: Map<String, List<OCShare>> = shares.groupBy { it.path }
|
||||
return groupedByPath
|
||||
.map { (path: String, shares: List<OCShare>) -> buildOcFile(path, shares) }
|
||||
.sortedByDescending { it.firstShareTimestamp }
|
||||
}
|
||||
|
||||
private fun buildOcFile(path: String, shares: List<OCShare>): OCFile {
|
||||
require(shares.all { it.path == path })
|
||||
// common attributes
|
||||
val firstShare = shares.first()
|
||||
val file = OCFile(path).apply {
|
||||
decryptedRemotePath = path
|
||||
ownerId = firstShare.userId
|
||||
ownerDisplayName = firstShare.ownerDisplayName
|
||||
isPreviewAvailable = firstShare.isHasPreview
|
||||
mimeType = firstShare.mimetype
|
||||
note = firstShare.note
|
||||
fileId = firstShare.fileSource
|
||||
remoteId = firstShare.remoteId.toString()
|
||||
// use first share timestamp as timestamp
|
||||
firstShareTimestamp = shares.minOf { it.sharedDate * MILLIS_PER_SECOND }
|
||||
// don't have file length or mod timestamp
|
||||
fileLength = -1
|
||||
modificationTimestamp = -1
|
||||
}
|
||||
if (shares.any { it.shareType in listOf(ShareType.PUBLIC_LINK, ShareType.EMAIL) }) {
|
||||
file.isSharedViaLink = true
|
||||
}
|
||||
if (shares.any { it.shareType !in listOf(ShareType.PUBLIC_LINK, ShareType.EMAIL) }) {
|
||||
file.isSharedWithSharee = true
|
||||
file.sharees = shares
|
||||
.filter { it.shareType != ShareType.PUBLIC_LINK && it.shareType != ShareType.EMAIL }
|
||||
.map { ShareeUser(it.shareWith, it.sharedWithDisplayName, it.shareType) }
|
||||
}
|
||||
return file
|
||||
}
|
||||
}
|
||||
@@ -1,202 +0,0 @@
|
||||
/*
|
||||
* 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 General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.asynctasks;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
|
||||
import com.owncloud.android.lib.resources.files.model.RemoteFile;
|
||||
import com.owncloud.android.lib.resources.status.OCCapability;
|
||||
import com.owncloud.android.operations.RefreshFolderOperation;
|
||||
import com.owncloud.android.ui.fragment.GalleryFragment;
|
||||
import com.owncloud.android.ui.fragment.SearchType;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
|
||||
public class GallerySearchTask extends AsyncTask<Void, Void, GallerySearchTask.Result> {
|
||||
|
||||
private final User user;
|
||||
private final WeakReference<GalleryFragment> photoFragmentWeakReference;
|
||||
private final FileDataStorageManager storageManager;
|
||||
private final int limit;
|
||||
private final long startDate;
|
||||
private final long endDate;
|
||||
|
||||
public GallerySearchTask(GalleryFragment photoFragment,
|
||||
User user,
|
||||
FileDataStorageManager storageManager,
|
||||
long startDate,
|
||||
long endDate,
|
||||
int limit) {
|
||||
this.user = user;
|
||||
this.photoFragmentWeakReference = new WeakReference<>(photoFragment);
|
||||
this.storageManager = storageManager;
|
||||
this.startDate = startDate;
|
||||
this.endDate = endDate;
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GallerySearchTask.Result doInBackground(Void... voids) {
|
||||
if (photoFragmentWeakReference.get() == null) {
|
||||
return new Result(false, false, -1);
|
||||
}
|
||||
GalleryFragment photoFragment = photoFragmentWeakReference.get();
|
||||
|
||||
if (isCancelled()) {
|
||||
return new Result(false, false, -1);
|
||||
} else {
|
||||
OCCapability ocCapability = storageManager.getCapability(user.getAccountName());
|
||||
|
||||
SearchRemoteOperation searchRemoteOperation = new SearchRemoteOperation("",
|
||||
SearchRemoteOperation.SearchType.GALLERY_SEARCH,
|
||||
false,
|
||||
ocCapability);
|
||||
|
||||
|
||||
searchRemoteOperation.setLimit(limit);
|
||||
searchRemoteOperation.setStartDate(startDate);
|
||||
searchRemoteOperation.setEndDate(endDate);
|
||||
|
||||
if (photoFragment.getContext() != null) {
|
||||
Log_OC.d(this,
|
||||
"Start gallery search with " + new Date(startDate * 1000L) +
|
||||
" - " + new Date(endDate * 1000L) +
|
||||
" with limit: " + limit);
|
||||
|
||||
RemoteOperationResult result = searchRemoteOperation.execute(user.toPlatformAccount(),
|
||||
photoFragment.getContext());
|
||||
|
||||
boolean emptySearch = parseMedia(startDate, endDate, result.getData());
|
||||
long lastTimeStamp = findLastTimestamp(result.getData());
|
||||
return new Result(result.isSuccess(), emptySearch, lastTimeStamp);
|
||||
} else {
|
||||
return new Result(false, false, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(GallerySearchTask.Result result) {
|
||||
if (photoFragmentWeakReference.get() != null) {
|
||||
GalleryFragment photoFragment = photoFragmentWeakReference.get();
|
||||
|
||||
photoFragment.setLoading(false);
|
||||
photoFragment.searchCompleted(result.emptySearch, result.lastTimestamp);
|
||||
|
||||
if (result.success && photoFragment.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
photoFragment.showAllGalleryItems();
|
||||
} else {
|
||||
photoFragment.setEmptyListMessage(SearchType.GALLERY_SEARCH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long findLastTimestamp(ArrayList<RemoteFile> remoteFiles) {
|
||||
int lastPosition = remoteFiles.size() - 1;
|
||||
|
||||
if (lastPosition < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
RemoteFile lastFile = remoteFiles.get(lastPosition);
|
||||
return lastFile.getModifiedTimestamp() / 1000;
|
||||
}
|
||||
|
||||
private boolean parseMedia(long startDate, long endDate, List<Object> remoteFiles) {
|
||||
// retrieve all between startDate and endDate
|
||||
Map<String, OCFile> localFilesMap = RefreshFolderOperation.prefillLocalFilesMap(null,
|
||||
storageManager.getGalleryItems(startDate * 1000L,
|
||||
endDate * 1000L));
|
||||
List<OCFile> filesToAdd = new ArrayList<>();
|
||||
List<OCFile> filesToUpdate = new ArrayList<>();
|
||||
|
||||
OCFile localFile;
|
||||
for (Object file : remoteFiles) {
|
||||
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) file);
|
||||
|
||||
localFile = localFilesMap.remove(ocFile.getRemotePath());
|
||||
|
||||
if (localFile == null) {
|
||||
// add new file
|
||||
filesToAdd.add(ocFile);
|
||||
} else if (!localFile.getEtag().equals(ocFile.getEtag())) {
|
||||
// update file
|
||||
ocFile.setLastSyncDateForData(System.currentTimeMillis());
|
||||
filesToUpdate.add(ocFile);
|
||||
}
|
||||
}
|
||||
|
||||
// add new files
|
||||
for (OCFile file : filesToAdd) {
|
||||
storageManager.saveFile(file);
|
||||
}
|
||||
|
||||
// update existing files
|
||||
for (OCFile file : filesToUpdate) {
|
||||
storageManager.saveFile(file);
|
||||
}
|
||||
|
||||
// existing files to remove
|
||||
for (OCFile file : localFilesMap.values()) {
|
||||
storageManager.removeFile(file, true, true);
|
||||
}
|
||||
|
||||
Log_OC.d(this, "Gallery search result:" +
|
||||
" new: " + filesToAdd.size() +
|
||||
" updated: " + filesToUpdate.size() +
|
||||
" deleted: " + localFilesMap.size());
|
||||
|
||||
return didNotFindNewResults(filesToAdd, filesToUpdate, localFilesMap.values());
|
||||
}
|
||||
|
||||
private boolean didNotFindNewResults(List<OCFile> filesToAdd,
|
||||
List<OCFile> filesToUpdate,
|
||||
Collection<OCFile> filesToRemove) {
|
||||
return filesToAdd.isEmpty() && filesToUpdate.isEmpty() && filesToRemove.isEmpty();
|
||||
}
|
||||
|
||||
public static class Result {
|
||||
public boolean success;
|
||||
public boolean emptySearch;
|
||||
public long lastTimestamp;
|
||||
|
||||
public Result(boolean success, boolean emptySearch, long lastTimestamp) {
|
||||
this.success = success;
|
||||
this.emptySearch = emptySearch;
|
||||
this.lastTimestamp = lastTimestamp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.dialog
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.databinding.StoragePermissionDialogBinding
|
||||
import com.owncloud.android.ui.dialog.StoragePermissionDialogFragment.Listener
|
||||
import com.owncloud.android.utils.theme.ThemeButtonUtils
|
||||
|
||||
/**
|
||||
* Dialog that shows permission options in SDK >= 30
|
||||
*
|
||||
* Allows choosing "full access" (MANAGE_ALL_FILES) or "read-only media" (READ_EXTERNAL_STORAGE)
|
||||
*
|
||||
* @param listener a [Listener] for button clicks. The dialog will auto-dismiss after the callback is called.
|
||||
* @param permissionRequired Whether the permission is absolutely required by the calling component.
|
||||
* This changes the texts to a more strict version.
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
class StoragePermissionDialogFragment(val listener: Listener, val permissionRequired: Boolean = false) :
|
||||
DialogFragment() {
|
||||
private lateinit var binding: StoragePermissionDialogBinding
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
dialog?.let {
|
||||
val alertDialog = it as AlertDialog
|
||||
ThemeButtonUtils.themeBorderlessButton(alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
// Inflate the layout for the dialog
|
||||
val inflater = requireActivity().layoutInflater
|
||||
binding = StoragePermissionDialogBinding.inflate(inflater, null, false)
|
||||
|
||||
val view: View = binding.root
|
||||
val explanationResource = when {
|
||||
permissionRequired -> R.string.file_management_permission_text
|
||||
else -> R.string.file_management_permission_optional_text
|
||||
}
|
||||
binding.storagePermissionExplanation.text = getString(explanationResource, getString(R.string.app_name))
|
||||
|
||||
// Setup layout
|
||||
ThemeButtonUtils.colorPrimaryButton(binding.btnFullAccess, context)
|
||||
binding.btnFullAccess.setOnClickListener {
|
||||
listener.onClickFullAccess()
|
||||
dismiss()
|
||||
}
|
||||
ThemeButtonUtils.themeBorderlessButton(binding.btnReadOnly)
|
||||
binding.btnReadOnly.setOnClickListener {
|
||||
listener.onClickMediaReadOnly()
|
||||
dismiss()
|
||||
}
|
||||
|
||||
// Build the dialog
|
||||
val titleResource = when {
|
||||
permissionRequired -> R.string.file_management_permission
|
||||
else -> R.string.file_management_permission_optional
|
||||
}
|
||||
val dialog = MaterialAlertDialogBuilder(requireActivity(), R.style.Theme_ownCloud_Dialog)
|
||||
.setTitle(titleResource)
|
||||
.setView(view)
|
||||
.setNegativeButton(R.string.common_cancel) { _, _ ->
|
||||
listener.onCancel()
|
||||
dismiss()
|
||||
}
|
||||
.create()
|
||||
|
||||
return dialog
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
fun onCancel()
|
||||
fun onClickFullAccess()
|
||||
fun onClickMediaReadOnly()
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.events
|
||||
|
||||
data class FileLockEvent(val filePath: String, val shouldLock: Boolean)
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Mario Danic
|
||||
* Copyright (C) 2017 Mario Danic
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.events
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class SyncEventFinished(val intent: Intent) : Parcelable
|
||||
@@ -1,264 +0,0 @@
|
||||
/*
|
||||
* 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 General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.fragment;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.nextcloud.utils.view.FastScroll;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
import com.owncloud.android.ui.adapter.CommonOCFileListAdapterInterface;
|
||||
import com.owncloud.android.ui.adapter.GalleryAdapter;
|
||||
import com.owncloud.android.ui.asynctasks.GallerySearchTask;
|
||||
import com.owncloud.android.ui.events.ChangeMenuEvent;
|
||||
import com.owncloud.android.ui.fragment.util.GalleryFastScrollViewHelper;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* A Fragment that lists all files and folders in a given path
|
||||
*/
|
||||
public class GalleryFragment extends OCFileListFragment {
|
||||
private static final int MAX_ITEMS_PER_ROW = 10;
|
||||
private boolean photoSearchQueryRunning = false;
|
||||
private AsyncTask<Void, Void, GallerySearchTask.Result> photoSearchTask;
|
||||
private long startDate;
|
||||
private long endDate;
|
||||
private long daySpan = 30;
|
||||
private int limit = 300;
|
||||
private GalleryAdapter mAdapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
searchFragment = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (photoSearchTask != null) {
|
||||
photoSearchTask.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
getRecyclerView().addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
loadMoreWhenEndReached(recyclerView, dy);
|
||||
}
|
||||
});
|
||||
|
||||
Log_OC.i(this, "onCreateView() in GalleryFragment end");
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
currentSearchType = SearchType.GALLERY_SEARCH;
|
||||
|
||||
menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_GRID_AND_SORT;
|
||||
requireActivity().invalidateOptionsMenu();
|
||||
|
||||
handleSearchEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAdapter(Bundle args) {
|
||||
mAdapter = new GalleryAdapter(requireContext(),
|
||||
accountManager.getUser(),
|
||||
this,
|
||||
preferences,
|
||||
mContainerActivity);
|
||||
|
||||
setRecyclerViewAdapter(mAdapter);
|
||||
|
||||
|
||||
GridLayoutManager layoutManager = new GridLayoutManager(getContext(), getColumnsCount());
|
||||
mAdapter.setLayoutManager(layoutManager);
|
||||
getRecyclerView().setLayoutManager(layoutManager);
|
||||
|
||||
FastScroll.applyFastScroll(getRecyclerView(), new GalleryFastScrollViewHelper(getRecyclerView(), mAdapter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
super.onRefresh();
|
||||
|
||||
handleSearchEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonOCFileListAdapterInterface getCommonAdapter() {
|
||||
return mAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
setLoading(photoSearchQueryRunning);
|
||||
final FragmentActivity activity = getActivity();
|
||||
if (activity instanceof FileDisplayActivity) {
|
||||
FileDisplayActivity fileDisplayActivity = ((FileDisplayActivity) activity);
|
||||
fileDisplayActivity.updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_item_gallery));
|
||||
fileDisplayActivity.setMainFabVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageEvent(ChangeMenuEvent changeMenuEvent) {
|
||||
super.onMessageEvent(changeMenuEvent);
|
||||
}
|
||||
|
||||
private void handleSearchEvent() {
|
||||
prepareCurrentSearch(searchEvent);
|
||||
setEmptyListLoadingMessage();
|
||||
|
||||
// always show first stored items
|
||||
mAdapter.showAllGalleryItems();
|
||||
|
||||
setFabVisible(false);
|
||||
|
||||
searchAndDisplay();
|
||||
}
|
||||
|
||||
private void searchAndDisplay() {
|
||||
// first: always search from now to -30 days
|
||||
if (!photoSearchQueryRunning) {
|
||||
photoSearchQueryRunning = true;
|
||||
|
||||
startDate = (System.currentTimeMillis() / 1000) - 30 * 24 * 60 * 60;
|
||||
endDate = System.currentTimeMillis() / 1000;
|
||||
|
||||
photoSearchTask = new GallerySearchTask(this,
|
||||
accountManager.getUser(),
|
||||
mContainerActivity.getStorageManager(),
|
||||
startDate,
|
||||
endDate,
|
||||
limit)
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
public void searchCompleted(boolean emptySearch, long lastTimeStamp) {
|
||||
photoSearchQueryRunning = false;
|
||||
|
||||
if (mAdapter.isEmpty()) {
|
||||
setEmptyListMessage(SearchType.GALLERY_SEARCH);
|
||||
}
|
||||
|
||||
if (emptySearch && mAdapter.getItemCount() > 0) {
|
||||
Log_OC.d(this, "End gallery search");
|
||||
return;
|
||||
}
|
||||
if (daySpan == 30) {
|
||||
daySpan = 90;
|
||||
} else if (daySpan == 90) {
|
||||
daySpan = 180;
|
||||
} else if (daySpan == 180) {
|
||||
daySpan = 999;
|
||||
} else if (daySpan == 999 && limit > 0) {
|
||||
limit = -1; // no limit
|
||||
} else {
|
||||
Log_OC.d(this, "End gallery search");
|
||||
return;
|
||||
}
|
||||
|
||||
if (lastTimeStamp > -1) {
|
||||
endDate = lastTimeStamp;
|
||||
}
|
||||
|
||||
startDate = endDate - (daySpan * 24 * 60 * 60);
|
||||
|
||||
photoSearchTask = new GallerySearchTask(this,
|
||||
accountManager.getUser(),
|
||||
mContainerActivity.getStorageManager(),
|
||||
startDate,
|
||||
endDate,
|
||||
limit)
|
||||
.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoading() {
|
||||
return photoSearchQueryRunning;
|
||||
}
|
||||
|
||||
private void loadMoreWhenEndReached(@NonNull RecyclerView recyclerView, int dy) {
|
||||
if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
|
||||
GridLayoutManager gridLayoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
|
||||
|
||||
// scroll down
|
||||
if (dy > 0 && !photoSearchQueryRunning) {
|
||||
int visibleItemCount = gridLayoutManager.getChildCount();
|
||||
int totalItemCount = gridLayoutManager.getItemCount();
|
||||
int lastVisibleItem = gridLayoutManager.findLastCompletelyVisibleItemPosition();
|
||||
|
||||
if ((totalItemCount - visibleItemCount) <= (lastVisibleItem + MAX_ITEMS_PER_ROW)
|
||||
&& (totalItemCount - visibleItemCount) > 0) {
|
||||
// Almost reached the end, continue to load new photos
|
||||
OCFile lastFile = mAdapter.getItem(lastVisibleItem - 1);
|
||||
|
||||
if (lastFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
daySpan = 30;
|
||||
endDate = lastFile.getModificationTimestamp() / 1000;
|
||||
startDate = endDate - (daySpan * 24 * 60 * 60);
|
||||
|
||||
photoSearchQueryRunning = true;
|
||||
photoSearchTask = new GallerySearchTask(this,
|
||||
accountManager.getUser(),
|
||||
mContainerActivity.getStorageManager(),
|
||||
startDate,
|
||||
endDate,
|
||||
limit)
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void showAllGalleryItems() {
|
||||
mAdapter.showAllGalleryItems();
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.fragment
|
||||
|
||||
import android.os.AsyncTask
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import com.nextcloud.client.account.User
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
import com.owncloud.android.ui.events.SearchEvent
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
class OCFileListSearchAsyncTask(
|
||||
containerActivity: FileFragment.ContainerActivity,
|
||||
fragment: OCFileListFragment,
|
||||
private val remoteOperation: RemoteOperation<List<Any>>,
|
||||
private val currentUser: User,
|
||||
private val event: SearchEvent
|
||||
) : AsyncTask<Void, Void, Boolean>() {
|
||||
private val activityReference: WeakReference<FileFragment.ContainerActivity> = WeakReference(containerActivity)
|
||||
private val fragmentReference: WeakReference<OCFileListFragment> = WeakReference(fragment)
|
||||
|
||||
private val fileDataStorageManager: FileDataStorageManager?
|
||||
get() = activityReference.get()?.storageManager
|
||||
|
||||
private fun RemoteOperationResult<out Any>.hasSuccessfulResult() = this.isSuccess && this.resultData != null
|
||||
|
||||
override fun onPreExecute() {
|
||||
fragmentReference.get()?.let { fragment ->
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
fragment.isLoading = true
|
||||
fragment.setEmptyListLoadingMessage()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun doInBackground(vararg voids: Void): Boolean {
|
||||
val fragment = fragmentReference.get()
|
||||
if (fragment?.context == null || isCancelled) {
|
||||
return java.lang.Boolean.FALSE
|
||||
}
|
||||
|
||||
fragment.setTitle()
|
||||
val remoteOperationResult = remoteOperation.execute(
|
||||
currentUser.toPlatformAccount(), fragment.context
|
||||
)
|
||||
if (remoteOperationResult.hasSuccessfulResult() && !isCancelled && fragment.searchFragment) {
|
||||
fragment.searchEvent = event
|
||||
if (remoteOperationResult.resultData.isNullOrEmpty()) {
|
||||
fragment.setEmptyView(event)
|
||||
} else {
|
||||
fragment.adapter.setData(
|
||||
remoteOperationResult.resultData,
|
||||
fragment.currentSearchType,
|
||||
fileDataStorageManager,
|
||||
fragment.mFile,
|
||||
true
|
||||
)
|
||||
}
|
||||
}
|
||||
return remoteOperationResult.isSuccess
|
||||
}
|
||||
|
||||
override fun onPostExecute(bool: Boolean) {
|
||||
fragmentReference.get()?.let { fragment ->
|
||||
fragment.isLoading = false
|
||||
if (!isCancelled) {
|
||||
fragment.adapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.owncloud.android.ui.fragment
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
enum class SearchType : Parcelable {
|
||||
NO_SEARCH,
|
||||
REGULAR_FILTER,
|
||||
FILE_SEARCH,
|
||||
FAVORITE_SEARCH,
|
||||
GALLERY_SEARCH,
|
||||
RECENTLY_MODIFIED_SEARCH,
|
||||
|
||||
// not a real filter, but nevertheless
|
||||
SHARED_FILTER
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* 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 General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.view.View
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.nextcloud.client.account.User
|
||||
import com.nextcloud.client.di.Injectable
|
||||
import com.nextcloud.client.logger.Logger
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation
|
||||
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
|
||||
import com.owncloud.android.lib.resources.files.SearchRemoteOperation
|
||||
import com.owncloud.android.lib.resources.files.model.RemoteFile
|
||||
import com.owncloud.android.lib.resources.shares.GetSharesRemoteOperation
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity
|
||||
import com.owncloud.android.ui.events.SearchEvent
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import com.owncloud.android.utils.FileStorageUtils
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* A Fragment that lists folders shared by the user
|
||||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
class SharedListFragment : OCFileListFragment(), Injectable {
|
||||
|
||||
@Inject
|
||||
lateinit var logger: Logger
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
searchFragment = true
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
adapter.setShowMetadata(false)
|
||||
currentSearchType = SearchType.SHARED_FILTER
|
||||
searchEvent = SearchEvent("", SearchRemoteOperation.SearchType.SHARED_FILTER)
|
||||
menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_GRID_AND_SORT
|
||||
requireActivity().invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
Handler().post {
|
||||
if (activity is FileDisplayActivity) {
|
||||
val fileDisplayActivity = activity as FileDisplayActivity
|
||||
fileDisplayActivity.updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_item_shared))
|
||||
fileDisplayActivity.setMainFabVisible(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSearchRemoteOperation(currentUser: User?, event: SearchEvent?): RemoteOperation<*> {
|
||||
return GetSharesRemoteOperation()
|
||||
}
|
||||
|
||||
private suspend fun fetchFileData(partialFile: OCFile): OCFile? {
|
||||
return withContext(Dispatchers.IO) {
|
||||
val user = accountManager.user
|
||||
val fetchResult = ReadFileRemoteOperation(partialFile.remotePath)
|
||||
.execute(user.toPlatformAccount(), context)
|
||||
if (!fetchResult.isSuccess) {
|
||||
logger.e(SHARED_TAG, "Error fetching file")
|
||||
if (fetchResult.isException) {
|
||||
logger.e(SHARED_TAG, "exception: ", fetchResult.exception)
|
||||
}
|
||||
null
|
||||
} else {
|
||||
val remoteFile = fetchResult.data[0] as RemoteFile
|
||||
val file = FileStorageUtils.fillOCFile(remoteFile)
|
||||
FileStorageUtils.searchForLocalFileInDefaultPath(file, user.accountName)
|
||||
val savedFile = mContainerActivity.storageManager.saveFileWithParent(file, context)
|
||||
savedFile.apply {
|
||||
isSharedViaLink = partialFile.isSharedViaLink
|
||||
isSharedWithSharee = partialFile.isSharedWithSharee
|
||||
sharees = partialFile.sharees
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetchFileAndRun(partialFile: OCFile, block: (file: OCFile) -> Unit) {
|
||||
lifecycleScope.launch {
|
||||
isLoading = true
|
||||
val file = fetchFileData(partialFile)
|
||||
isLoading = false
|
||||
if (file != null) {
|
||||
block(file)
|
||||
} else {
|
||||
DisplayUtils.showSnackMessage(requireActivity(), R.string.error_retrieving_file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onShareIconClick(file: OCFile) {
|
||||
fetchFileAndRun(file) { fetched ->
|
||||
super.onShareIconClick(fetched)
|
||||
}
|
||||
}
|
||||
|
||||
override fun showShareDetailView(file: OCFile) {
|
||||
fetchFileAndRun(file) { fetched ->
|
||||
super.showShareDetailView(fetched)
|
||||
}
|
||||
}
|
||||
|
||||
override fun showActivityDetailView(file: OCFile) {
|
||||
fetchFileAndRun(file) { fetched ->
|
||||
super.showActivityDetailView(fetched)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onOverflowIconClicked(file: OCFile, view: View?) {
|
||||
fetchFileAndRun(file) { fetched ->
|
||||
super.onOverflowIconClicked(fetched, view)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onItemClicked(file: OCFile) {
|
||||
fetchFileAndRun(file) { fetched ->
|
||||
super.onItemClicked(fetched)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLongItemClicked(file: OCFile): Boolean {
|
||||
fetchFileAndRun(file) { fetched ->
|
||||
super.onLongItemClicked(fetched)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val SHARED_TAG = SharedListFragment::class.java.simpleName
|
||||
}
|
||||
}
|
||||
@@ -1,264 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android Library is available under MIT license
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.fragment.util
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Rect
|
||||
import android.view.MotionEvent
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
|
||||
import androidx.recyclerview.widget.RecyclerView.SimpleOnItemTouchListener
|
||||
import com.afollestad.sectionedrecyclerview.ItemCoord
|
||||
import com.owncloud.android.datamodel.GalleryItems
|
||||
import com.owncloud.android.ui.adapter.GalleryAdapter
|
||||
import me.zhanghai.android.fastscroll.FastScroller
|
||||
import me.zhanghai.android.fastscroll.PopupTextProvider
|
||||
import me.zhanghai.android.fastscroll.Predicate
|
||||
import kotlin.math.ceil
|
||||
|
||||
/**
|
||||
* Custom ViewHelper to get fast scroll working on gallery, which has a gridview and variable height (due to headers)
|
||||
*
|
||||
* Copied from me.zhanghai.android.fastscroll.RecyclerViewHelper and heavily modified for gallery structure
|
||||
*/
|
||||
class GalleryFastScrollViewHelper(
|
||||
private val mView: RecyclerView,
|
||||
private val mPopupTextProvider: PopupTextProvider?
|
||||
) : FastScroller.ViewHelper {
|
||||
// used to calculate paddings
|
||||
private val mTempRect = Rect()
|
||||
|
||||
private val layoutManager by lazy { mView.layoutManager as GridLayoutManager }
|
||||
|
||||
// header is always 1st in the adapter
|
||||
private val headerHeight by lazy { getItemHeight(0) }
|
||||
// the 2nd element is always an item
|
||||
private val rowHeight by lazy { getItemHeight(1) }
|
||||
|
||||
private val columnCount by lazy { layoutManager.spanCount }
|
||||
|
||||
private fun getItemHeight(position: Int): Int {
|
||||
if (mView.childCount <= position) {
|
||||
return 0
|
||||
}
|
||||
val itemView = mView.getChildAt(position)
|
||||
mView.getDecoratedBoundsWithMargins(itemView, mTempRect)
|
||||
return mTempRect.height()
|
||||
}
|
||||
|
||||
override fun addOnPreDrawListener(onPreDraw: Runnable) {
|
||||
mView.addItemDecoration(object : ItemDecoration() {
|
||||
override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {
|
||||
onPreDraw.run()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun addOnScrollChangedListener(onScrollChanged: Runnable) {
|
||||
mView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
onScrollChanged.run()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun addOnTouchEventListener(onTouchEvent: Predicate<MotionEvent?>) {
|
||||
mView.addOnItemTouchListener(object : SimpleOnItemTouchListener() {
|
||||
override fun onInterceptTouchEvent(recyclerView: RecyclerView, event: MotionEvent): Boolean {
|
||||
return onTouchEvent.test(event)
|
||||
}
|
||||
|
||||
override fun onTouchEvent(recyclerView: RecyclerView, event: MotionEvent) {
|
||||
onTouchEvent.test(event)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun getScrollRange(): Int {
|
||||
val headerCount = getHeaderCount()
|
||||
val rowCount = getRowCount()
|
||||
|
||||
if (headerCount == 0 || rowCount == 0) {
|
||||
return 0
|
||||
}
|
||||
val totalHeaderHeight = headerCount * headerHeight
|
||||
val totalRowHeight = rowCount * rowHeight
|
||||
return mView.paddingTop + totalHeaderHeight + totalRowHeight + mView.paddingBottom
|
||||
}
|
||||
|
||||
private fun getHeaderCount(): Int {
|
||||
val adapter = mView.adapter as GalleryAdapter
|
||||
return adapter.sectionCount
|
||||
}
|
||||
|
||||
private fun getRowCount(): Int {
|
||||
val adapter = mView.adapter as GalleryAdapter
|
||||
if (adapter.sectionCount == 0) return 0
|
||||
// in each section, the final row may contain less than the max of items
|
||||
return adapter.files.sumOf { itemCountToRowCount(it.files.size) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates current absolute offset depending on view state (first visible element)
|
||||
*/
|
||||
override fun getScrollOffset(): Int {
|
||||
val firstItemPosition = getFirstItemAdapterPosition()
|
||||
if (firstItemPosition == RecyclerView.NO_POSITION) {
|
||||
return 0
|
||||
}
|
||||
|
||||
val adapter = mView.adapter as GalleryAdapter
|
||||
val itemCoord: ItemCoord = adapter.getRelativePosition(firstItemPosition)
|
||||
val isHeader = itemCoord.relativePos() == -1
|
||||
|
||||
val seenRowsInPreviousSections = adapter.files
|
||||
.subList(0, itemCoord.section())
|
||||
.sumOf { itemCountToRowCount(it.files.size) }
|
||||
val seenRowsInThisSection = if (isHeader) 0 else itemCountToRowCount(itemCoord.relativePos())
|
||||
val totalSeenRows = seenRowsInPreviousSections + seenRowsInThisSection
|
||||
|
||||
val seenHeaders = when {
|
||||
isHeader -> itemCoord.section() // don't count the current section header
|
||||
else -> itemCoord.section() + 1
|
||||
}
|
||||
|
||||
val firstItemTop = getFirstItemOffset()
|
||||
|
||||
val totalRowOffset = totalSeenRows * rowHeight
|
||||
val totalHeaderOffset = seenHeaders * headerHeight
|
||||
return mView.paddingTop + totalHeaderOffset + totalRowOffset - firstItemTop
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls to an absolute offset
|
||||
*/
|
||||
override fun scrollTo(offset: Int) {
|
||||
mView.stopScroll()
|
||||
val offsetTmp = offset - mView.paddingTop
|
||||
val (position, remainingOffset) = findPositionForOffset(offsetTmp)
|
||||
scrollToPositionWithOffset(position, -remainingOffset)
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an absolute offset, returns the closest position to that offset (without going over it),
|
||||
* and the remaining offset
|
||||
*/
|
||||
private fun findPositionForOffset(offset: Int): Pair<Int, Int> {
|
||||
val adapter = mView.adapter as GalleryAdapter
|
||||
|
||||
// find section
|
||||
val sectionStartOffsets = getSectionStartOffsets(adapter.files)
|
||||
val previousSections = sectionStartOffsets.filter { it <= offset }
|
||||
|
||||
val section = previousSections.size - 1
|
||||
val sectionStartOffset = previousSections.last()
|
||||
|
||||
// now calculate where to scroll within the section
|
||||
var remainingOffset = offset - sectionStartOffset
|
||||
val positionWithinSection: Int
|
||||
if (remainingOffset <= headerHeight) {
|
||||
// header position
|
||||
positionWithinSection = -1
|
||||
} else {
|
||||
// row position
|
||||
remainingOffset -= headerHeight
|
||||
val rowCount = remainingOffset / rowHeight
|
||||
if (rowCount > 0) {
|
||||
val rowStartIndex = rowCount * columnCount
|
||||
positionWithinSection = rowStartIndex
|
||||
|
||||
remainingOffset -= rowCount * rowHeight
|
||||
} else {
|
||||
positionWithinSection = 0 // first item
|
||||
}
|
||||
}
|
||||
val absolutePosition = adapter.getAbsolutePosition(section, positionWithinSection)
|
||||
return Pair(absolutePosition, remainingOffset)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the offset heights at which the section corresponding to that index starts
|
||||
*/
|
||||
private fun getSectionStartOffsets(files: List<GalleryItems>): List<Int> {
|
||||
val sectionHeights =
|
||||
files.map { headerHeight + itemCountToRowCount(it.files.size) * rowHeight }
|
||||
val sectionStartOffsets = sectionHeights.indices.map { i ->
|
||||
when (i) {
|
||||
0 -> 0
|
||||
else -> sectionHeights.subList(0, i).sum()
|
||||
}
|
||||
}
|
||||
return sectionStartOffsets
|
||||
}
|
||||
|
||||
private fun itemCountToRowCount(itemsCount: Int): Int {
|
||||
return ceil(itemsCount.toDouble() / columnCount).toInt()
|
||||
}
|
||||
|
||||
override fun getPopupText(): String? {
|
||||
var popupTextProvider: PopupTextProvider? = mPopupTextProvider
|
||||
if (popupTextProvider == null) {
|
||||
val adapter = mView.adapter
|
||||
if (adapter is PopupTextProvider) {
|
||||
popupTextProvider = adapter
|
||||
}
|
||||
}
|
||||
if (popupTextProvider == null) {
|
||||
return null
|
||||
}
|
||||
val position = getFirstItemAdapterPosition()
|
||||
return if (position == RecyclerView.NO_POSITION) {
|
||||
null
|
||||
} else popupTextProvider.getPopupText(position)
|
||||
}
|
||||
|
||||
private fun getFirstItemAdapterPosition(): Int {
|
||||
if (mView.childCount == 0) {
|
||||
return RecyclerView.NO_POSITION
|
||||
}
|
||||
val itemView = mView.getChildAt(0)
|
||||
return layoutManager.getPosition(itemView)
|
||||
}
|
||||
|
||||
private fun getFirstItemOffset(): Int {
|
||||
if (mView.childCount == 0) {
|
||||
return RecyclerView.NO_POSITION
|
||||
}
|
||||
val itemView = mView.getChildAt(0)
|
||||
mView.getDecoratedBoundsWithMargins(itemView, mTempRect)
|
||||
return mTempRect.top
|
||||
}
|
||||
|
||||
private fun scrollToPositionWithOffset(position: Int, offset: Int) {
|
||||
var offsetTmp = offset
|
||||
// LinearLayoutManager actually takes offset from paddingTop instead of top of RecyclerView.
|
||||
offsetTmp -= mView.paddingTop
|
||||
layoutManager.scrollToPositionWithOffset(position, offsetTmp)
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.preview
|
||||
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.owncloud.android.databinding.ActivityPreviewBitmapBinding
|
||||
|
||||
/**
|
||||
* Zoomable preview of a single bitmap
|
||||
*/
|
||||
class PreviewBitmapActivity : AppCompatActivity() {
|
||||
|
||||
companion object {
|
||||
const val EXTRA_BITMAP_PATH = "EXTRA_BITMAP_PATH"
|
||||
}
|
||||
|
||||
private lateinit var binding: ActivityPreviewBitmapBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityPreviewBitmapBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setupImage()
|
||||
|
||||
supportActionBar?.let {
|
||||
it.setDisplayHomeAsUpEnabled(true)
|
||||
it.setDisplayShowHomeEnabled(true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupImage() {
|
||||
val path = intent.getStringExtra(EXTRA_BITMAP_PATH)
|
||||
require(path != null)
|
||||
|
||||
val bitmap = BitmapFactory.decodeFile(path)
|
||||
binding.image.setImageBitmap(bitmap)
|
||||
}
|
||||
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
onBackPressed()
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -1,265 +0,0 @@
|
||||
/*
|
||||
* ownCloud Android client application
|
||||
*
|
||||
* @author David A. Velasco
|
||||
* 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.preview
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.media.MediaPlayer
|
||||
import android.media.MediaPlayer.OnCompletionListener
|
||||
import android.media.MediaPlayer.OnPreparedListener
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
import com.google.android.exoplayer2.MediaItem
|
||||
import com.google.android.exoplayer2.Player
|
||||
import com.nextcloud.client.account.UserAccountManager
|
||||
import com.nextcloud.client.di.Injectable
|
||||
import com.nextcloud.client.media.ErrorFormat.toString
|
||||
import com.nextcloud.client.media.NextcloudExoPlayer.createNextcloudExoplayer
|
||||
import com.nextcloud.client.network.ClientFactory
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.databinding.ActivityPreviewVideoBinding
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.ui.activity.FileActivity
|
||||
import com.owncloud.android.utils.MimeTypeUtil
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Activity implementing a basic video player.
|
||||
*
|
||||
* THIS CLASS NEEDS WORK; the old listeners (OnCompletion, OnPrepared; OnError) don't work with ExoPlayer
|
||||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
class PreviewVideoActivity :
|
||||
FileActivity(),
|
||||
OnCompletionListener,
|
||||
OnPreparedListener,
|
||||
MediaPlayer.OnErrorListener,
|
||||
Player.Listener,
|
||||
Injectable {
|
||||
|
||||
@Inject
|
||||
lateinit var clientFactory: ClientFactory
|
||||
|
||||
@Inject
|
||||
lateinit var accountManager: UserAccountManager
|
||||
|
||||
private var mSavedPlaybackPosition: Long = -1 // in the unit time handled by MediaPlayer.getCurrentPosition()
|
||||
private var mAutoplay = false // when 'true', the playback starts immediately with the activity
|
||||
private var exoPlayer: ExoPlayer? = null // view to play the file; both performs and show the playback
|
||||
private var mStreamUri: Uri? = null
|
||||
private lateinit var binding: ActivityPreviewVideoBinding
|
||||
|
||||
private lateinit var pauseButton: View
|
||||
|
||||
private lateinit var playButton: View
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
Log_OC.v(TAG, "onCreate")
|
||||
|
||||
binding = ActivityPreviewVideoBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val extras = intent.extras
|
||||
|
||||
if (savedInstanceState == null && extras != null) {
|
||||
mSavedPlaybackPosition = extras.getLong(EXTRA_START_POSITION)
|
||||
mAutoplay = extras.getBoolean(EXTRA_AUTOPLAY)
|
||||
mStreamUri = extras[EXTRA_STREAM_URL] as Uri?
|
||||
} else if (savedInstanceState != null) {
|
||||
mSavedPlaybackPosition = savedInstanceState.getLong(EXTRA_START_POSITION)
|
||||
mAutoplay = savedInstanceState.getBoolean(EXTRA_AUTOPLAY)
|
||||
mStreamUri = savedInstanceState[EXTRA_STREAM_URL] as Uri?
|
||||
}
|
||||
|
||||
supportActionBar?.hide()
|
||||
}
|
||||
|
||||
private fun setupPlayerView() {
|
||||
binding.videoPlayer.player = exoPlayer
|
||||
exoPlayer!!.addListener(this)
|
||||
|
||||
binding.root.findViewById<View>(R.id.exo_exit_fs).setOnClickListener { onBackPressed() }
|
||||
|
||||
pauseButton = binding.root.findViewById(R.id.exo_pause)
|
||||
pauseButton.setOnClickListener { exoPlayer!!.pause() }
|
||||
|
||||
playButton = binding.root.findViewById(R.id.exo_play)
|
||||
playButton.setOnClickListener { exoPlayer!!.play() }
|
||||
|
||||
if (mSavedPlaybackPosition >= 0) {
|
||||
exoPlayer?.seekTo(mSavedPlaybackPosition)
|
||||
}
|
||||
|
||||
onIsPlayingChanged(exoPlayer!!.isPlaying)
|
||||
}
|
||||
|
||||
override fun onIsPlayingChanged(isPlaying: Boolean) {
|
||||
super.onIsPlayingChanged(isPlaying)
|
||||
if (isPlaying) {
|
||||
playButton.visibility = View.GONE
|
||||
pauseButton.visibility = View.VISIBLE
|
||||
} else {
|
||||
playButton.visibility = View.VISIBLE
|
||||
pauseButton.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putLong(EXTRA_START_POSITION, currentPosition())
|
||||
outState.putBoolean(EXTRA_AUTOPLAY, isPlaying())
|
||||
outState.putParcelable(EXTRA_STREAM_URL, mStreamUri)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
Log_OC.v(TAG, "onBackPressed")
|
||||
val i = Intent()
|
||||
i.putExtra(EXTRA_AUTOPLAY, isPlaying())
|
||||
i.putExtra(EXTRA_START_POSITION, currentPosition())
|
||||
setResult(RESULT_OK, i)
|
||||
exoPlayer?.stop()
|
||||
exoPlayer?.release()
|
||||
super.onBackPressed()
|
||||
}
|
||||
|
||||
private fun isPlaying() = exoPlayer?.isPlaying ?: false
|
||||
private fun currentPosition() = exoPlayer?.currentPosition ?: 0
|
||||
|
||||
/**
|
||||
* Called when the file is ready to be played.
|
||||
*
|
||||
* Just starts the playback.
|
||||
*
|
||||
* @param mp [MediaPlayer] instance performing the playback.
|
||||
*/
|
||||
override fun onPrepared(mp: MediaPlayer) {
|
||||
Log_OC.v(TAG, "onPrepare")
|
||||
exoPlayer?.seekTo(mSavedPlaybackPosition)
|
||||
if (mAutoplay) {
|
||||
exoPlayer?.play()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the file is finished playing.
|
||||
*
|
||||
* Rewinds the video
|
||||
*
|
||||
* @param mp [MediaPlayer] instance performing the playback.
|
||||
*/
|
||||
override fun onCompletion(mp: MediaPlayer?) {
|
||||
exoPlayer?.seekTo(0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an error in playback occurs.
|
||||
*
|
||||
* @param mp [MediaPlayer] instance performing the playback.
|
||||
* @param what Type of error
|
||||
* @param extra Extra code specific to the error
|
||||
*/
|
||||
override fun onError(mp: MediaPlayer, what: Int, extra: Int): Boolean {
|
||||
Log_OC.e(TAG, "Error in video playback, what = $what, extra = $extra")
|
||||
val message = toString(this, what, extra)
|
||||
AlertDialog.Builder(this)
|
||||
.setMessage(message)
|
||||
.setPositiveButton(android.R.string.VideoView_error_button) { _: DialogInterface?, _: Int ->
|
||||
onCompletion(null)
|
||||
}
|
||||
.setCancelable(false)
|
||||
.show()
|
||||
return true
|
||||
}
|
||||
|
||||
private fun play(item: MediaItem) {
|
||||
exoPlayer?.addMediaItem(item)
|
||||
exoPlayer?.prepare()
|
||||
|
||||
if (mAutoplay) {
|
||||
exoPlayer?.play()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
if (account != null) {
|
||||
|
||||
require(file != null) { throw IllegalStateException("Instanced with a NULL OCFile") }
|
||||
var fileToPlay: OCFile? = file
|
||||
|
||||
// Validate handled file (first image to preview)
|
||||
require(MimeTypeUtil.isVideo(fileToPlay)) { "Non-video file passed as argument" }
|
||||
|
||||
fileToPlay = storageManager.getFileById(fileToPlay!!.fileId)
|
||||
if (fileToPlay != null) {
|
||||
val mediaItem = when {
|
||||
fileToPlay.isDown -> MediaItem.fromUri(fileToPlay.storageUri)
|
||||
else -> MediaItem.fromUri(mStreamUri!!)
|
||||
}
|
||||
if (exoPlayer != null) {
|
||||
setupPlayerView()
|
||||
play(mediaItem)
|
||||
} else {
|
||||
val context = this
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val client = clientFactory.createNextcloudClient(accountManager.user)
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
exoPlayer = createNextcloudExoplayer(context, client)
|
||||
setupPlayerView()
|
||||
play(mediaItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
if (exoPlayer?.isPlaying == true) {
|
||||
exoPlayer?.pause()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** Key to receive a flag signaling if the video should be started immediately */
|
||||
const val EXTRA_AUTOPLAY = "AUTOPLAY"
|
||||
|
||||
/** Key to receive the position of the playback where the video should be put at start */
|
||||
const val EXTRA_START_POSITION = "START_POSITION"
|
||||
const val EXTRA_STREAM_URL = "STREAM_URL"
|
||||
private val TAG = PreviewVideoActivity::class.java.simpleName
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.preview.pdf
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.pdf.PdfRenderer
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.owncloud.android.databinding.PreviewPdfPageItemBinding
|
||||
|
||||
/**
|
||||
* @param renderer an **open** [PdfRenderer]
|
||||
*/
|
||||
class PreviewPdfAdapter(
|
||||
private val renderer: PdfRenderer,
|
||||
private val screenWidth: Int,
|
||||
private val onClickListener: (Bitmap) -> Unit
|
||||
) :
|
||||
RecyclerView.Adapter<PreviewPdfAdapter.ViewHolder>() {
|
||||
|
||||
class ViewHolder(val binding: PreviewPdfPageItemBinding, val onClickListener: (Bitmap) -> Unit) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(bitmap: Bitmap) {
|
||||
binding.page.setImageBitmap(bitmap)
|
||||
binding.root.setOnClickListener {
|
||||
onClickListener(bitmap)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val binding = PreviewPdfPageItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return ViewHolder(binding, onClickListener)
|
||||
}
|
||||
|
||||
override fun getItemCount() = renderer.pageCount
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val page = renderer.openPage(position)
|
||||
val bitmap = renderPage(page)
|
||||
holder.bind(bitmap)
|
||||
}
|
||||
|
||||
private fun renderPage(page: PdfRenderer.Page) = page.use {
|
||||
val bitmap = createBitmapForPage(it)
|
||||
page.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY)
|
||||
bitmap
|
||||
}
|
||||
|
||||
private fun createBitmapForPage(page: PdfRenderer.Page): Bitmap {
|
||||
val bitmap = Bitmap.createBitmap(
|
||||
screenWidth, (screenWidth.toFloat() / page.width * page.height).toInt(), Bitmap.Config.ARGB_8888
|
||||
)
|
||||
|
||||
val canvas = Canvas(bitmap)
|
||||
canvas.drawColor(Color.WHITE)
|
||||
canvas.drawBitmap(bitmap, 0f, 0f, null)
|
||||
|
||||
return bitmap
|
||||
}
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.preview.pdf
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.nextcloud.client.di.Injectable
|
||||
import com.nextcloud.client.di.ViewModelFactory
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.databinding.PreviewPdfFragmentBinding
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.files.FileMenuFilter
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity
|
||||
import com.owncloud.android.ui.preview.PreviewBitmapActivity
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
class PreviewPdfFragment : Fragment(), Injectable {
|
||||
|
||||
@Inject
|
||||
lateinit var vmFactory: ViewModelFactory
|
||||
|
||||
private lateinit var binding: PreviewPdfFragmentBinding
|
||||
private lateinit var viewModel: PreviewPdfViewModel
|
||||
private lateinit var file: OCFile
|
||||
|
||||
private var snack: Snackbar? = null
|
||||
|
||||
companion object {
|
||||
private const val ARG_FILE = "FILE"
|
||||
|
||||
@JvmStatic
|
||||
fun newInstance(file: OCFile): PreviewPdfFragment = PreviewPdfFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putParcelable(ARG_FILE, file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
binding = PreviewPdfFragmentBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
setupObservers()
|
||||
|
||||
file = requireArguments().getParcelable(ARG_FILE)!!
|
||||
viewModel.process(file)
|
||||
}
|
||||
|
||||
private fun setupObservers() {
|
||||
viewModel.pdfRenderer.observe(viewLifecycleOwner) { renderer ->
|
||||
binding.pdfRecycler.adapter = PreviewPdfAdapter(renderer, getScreenWidth()) { page ->
|
||||
viewModel.onClickPage(page)
|
||||
}
|
||||
}
|
||||
viewModel.previewImagePath.observe(viewLifecycleOwner) {
|
||||
it?.let { path ->
|
||||
val intent = Intent(context, PreviewBitmapActivity::class.java).apply {
|
||||
putExtra(PreviewBitmapActivity.EXTRA_BITMAP_PATH, path)
|
||||
}
|
||||
requireContext().startActivity(intent)
|
||||
}
|
||||
}
|
||||
viewModel.shouldShowZoomTip.observe(viewLifecycleOwner) { shouldShow ->
|
||||
if (shouldShow) {
|
||||
snack = DisplayUtils.showSnackMessage(binding.root, R.string.pdf_zoom_tip)
|
||||
viewModel.onZoomTipShown()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
viewModel = ViewModelProvider(this, vmFactory)[PreviewPdfViewModel::class.java]
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
private fun getScreenWidth(): Int =
|
||||
requireContext().resources.displayMetrics.widthPixels
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu) {
|
||||
super.onPrepareOptionsMenu(menu)
|
||||
FileMenuFilter.hideAll(menu)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val parent = activity
|
||||
if (parent is FileDisplayActivity) {
|
||||
parent.showSortListGroup(false)
|
||||
parent.updateActionBarTitleAndHomeButton(file)
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
fun dismissSnack() {
|
||||
snack?.dismiss()
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.preview.pdf
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.pdf.PdfRenderer
|
||||
import android.os.ParcelFileDescriptor
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.nextcloud.client.preferences.AppPreferences
|
||||
import com.owncloud.android.MainApp
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import javax.inject.Inject
|
||||
|
||||
class PreviewPdfViewModel @Inject constructor(val appPreferences: AppPreferences) : ViewModel() {
|
||||
|
||||
companion object {
|
||||
private const val SHOW_ZOOM_TIP_TIMES = 3
|
||||
}
|
||||
|
||||
private var _pdfRenderer = MutableLiveData<PdfRenderer>()
|
||||
val pdfRenderer: LiveData<PdfRenderer>
|
||||
get() = _pdfRenderer
|
||||
|
||||
private var _previewImagePath = MutableLiveData<String>()
|
||||
val previewImagePath: LiveData<String>
|
||||
get() = _previewImagePath
|
||||
|
||||
private var _showZoomTip = MutableLiveData<Boolean>()
|
||||
val shouldShowZoomTip: LiveData<Boolean>
|
||||
get() = _showZoomTip
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
closeRenderer()
|
||||
}
|
||||
|
||||
private fun closeRenderer() {
|
||||
try {
|
||||
_pdfRenderer.value?.close()
|
||||
} catch (e: IllegalStateException) {
|
||||
Log_OC.e(this, "closeRenderer: trying to close already closed renderer", e)
|
||||
}
|
||||
}
|
||||
|
||||
fun process(file: OCFile) {
|
||||
closeRenderer()
|
||||
_pdfRenderer.value =
|
||||
PdfRenderer(ParcelFileDescriptor.open(File(file.storagePath), ParcelFileDescriptor.MODE_READ_ONLY))
|
||||
if (appPreferences.pdfZoomTipShownCount < SHOW_ZOOM_TIP_TIMES) {
|
||||
_showZoomTip.value = true
|
||||
}
|
||||
}
|
||||
|
||||
fun onClickPage(page: Bitmap) {
|
||||
val file = File.createTempFile("pdf_page", ".bmp", MainApp.getAppContext().cacheDir)
|
||||
val outStream = FileOutputStream(file)
|
||||
page.compress(Bitmap.CompressFormat.PNG, 0, outStream)
|
||||
outStream.close()
|
||||
|
||||
_previewImagePath.value = file.path
|
||||
}
|
||||
|
||||
fun onZoomTipShown() {
|
||||
appPreferences.pdfZoomTipShownCount++
|
||||
_showZoomTip.value = false
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Sven R. Kunze
|
||||
* Copyright (C) 2017 Sven R. Kunze
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
*
|
||||
* 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.utils
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile
|
||||
import java.io.File
|
||||
import java.util.Collections
|
||||
|
||||
/**
|
||||
* Sort order
|
||||
*/
|
||||
open class FileSortOrder(@JvmField var name: String, var isAscending: Boolean) {
|
||||
|
||||
val sortMultiplier: Int
|
||||
get() = if (isAscending) 1 else -1
|
||||
|
||||
@Suppress("EnumNaming") // already saved in user preferences -.-'
|
||||
enum class Type {
|
||||
trashBinView, localFileListView
|
||||
}
|
||||
|
||||
enum class SortType {
|
||||
SIZE, ALPHABET, DATE
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val sort_a_to_z_id = "sort_a_to_z"
|
||||
const val sort_z_to_a_id = "sort_z_to_a"
|
||||
const val sort_old_to_new_id = "sort_old_to_new"
|
||||
const val sort_new_to_old_id = "sort_new_to_old"
|
||||
const val sort_small_to_big_id = "sort_small_to_big"
|
||||
const val sort_big_to_small_id = "sort_big_to_small"
|
||||
|
||||
@JvmField
|
||||
val sort_a_to_z: FileSortOrder = FileSortOrderByName(sort_a_to_z_id, true)
|
||||
|
||||
@JvmField
|
||||
val sort_z_to_a: FileSortOrder = FileSortOrderByName(sort_z_to_a_id, false)
|
||||
|
||||
@JvmField
|
||||
val sort_old_to_new: FileSortOrder = FileSortOrderByDate(sort_old_to_new_id, true)
|
||||
|
||||
@JvmField
|
||||
val sort_new_to_old: FileSortOrder = FileSortOrderByDate(sort_new_to_old_id, false)
|
||||
|
||||
@JvmField
|
||||
val sort_small_to_big: FileSortOrder = FileSortOrderBySize(sort_small_to_big_id, true)
|
||||
|
||||
@JvmField
|
||||
val sort_big_to_small: FileSortOrder = FileSortOrderBySize(sort_big_to_small_id, false)
|
||||
|
||||
@JvmField
|
||||
val sortOrders: Map<String, FileSortOrder> = Collections.unmodifiableMap(
|
||||
mapOf(
|
||||
sort_a_to_z.name to sort_a_to_z,
|
||||
sort_z_to_a.name to sort_z_to_a,
|
||||
sort_old_to_new.name to sort_old_to_new,
|
||||
sort_new_to_old.name to sort_new_to_old,
|
||||
sort_small_to_big.name to sort_small_to_big,
|
||||
sort_big_to_small.name to sort_big_to_small
|
||||
)
|
||||
)
|
||||
|
||||
/**
|
||||
* Sorts list by Favourites.
|
||||
*
|
||||
* @param files files to sort
|
||||
*/
|
||||
@JvmStatic
|
||||
fun sortCloudFilesByFavourite(files: MutableList<OCFile>): List<OCFile> {
|
||||
files.sortWith { o1: OCFile, o2: OCFile ->
|
||||
when {
|
||||
o1.isFavorite && o2.isFavorite -> 0
|
||||
o1.isFavorite -> -1
|
||||
o2.isFavorite -> 1
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
}
|
||||
|
||||
open fun sortCloudFiles(files: MutableList<OCFile>): List<OCFile> {
|
||||
return sortCloudFilesByFavourite(files)
|
||||
}
|
||||
|
||||
open fun sortLocalFiles(files: MutableList<File>): List<File> {
|
||||
return files
|
||||
}
|
||||
|
||||
open fun sortTrashbinFiles(files: MutableList<TrashbinFile>): List<TrashbinFile> {
|
||||
return files
|
||||
}
|
||||
|
||||
open fun getType(): SortType {
|
||||
return when (name) {
|
||||
sort_z_to_a_id,
|
||||
sort_a_to_z_id -> SortType.ALPHABET
|
||||
|
||||
sort_small_to_big_id,
|
||||
sort_big_to_small_id -> SortType.SIZE
|
||||
|
||||
sort_new_to_old_id,
|
||||
sort_old_to_new_id -> SortType.DATE
|
||||
|
||||
else -> SortType.ALPHABET
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Sven R. Kunze
|
||||
* Copyright (C) 2017 Sven R. Kunze
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
*
|
||||
* 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.utils
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Created by srkunze on 28.08.17.
|
||||
*/
|
||||
class FileSortOrderByDate(name: String, ascending: Boolean) : FileSortOrder(name, ascending) {
|
||||
/**
|
||||
* Sorts list by Date.
|
||||
*
|
||||
* @param files list of files to sort
|
||||
*/
|
||||
override fun sortCloudFiles(files: MutableList<OCFile>): List<OCFile> {
|
||||
val multiplier = if (isAscending) 1 else -1
|
||||
files.sortWith { o1: OCFile, o2: OCFile ->
|
||||
multiplier * o1.modificationTimestamp.compareTo(o2.modificationTimestamp)
|
||||
}
|
||||
return super.sortCloudFiles(files)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts list by Date.
|
||||
*
|
||||
* @param files list of files to sort
|
||||
*/
|
||||
override fun sortTrashbinFiles(files: MutableList<TrashbinFile>): List<TrashbinFile> {
|
||||
val multiplier = if (isAscending) 1 else -1
|
||||
files.sortWith { o1: TrashbinFile, o2: TrashbinFile ->
|
||||
multiplier * o1.deletionTimestamp.compareTo(o2.deletionTimestamp)
|
||||
}
|
||||
return super.sortTrashbinFiles(files)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts list by Date.
|
||||
*
|
||||
* @param files list of files to sort
|
||||
*/
|
||||
override fun sortLocalFiles(files: MutableList<File>): List<File> {
|
||||
val multiplier = if (isAscending) 1 else -1
|
||||
files.sortWith { o1: File, o2: File ->
|
||||
multiplier * o1.lastModified().compareTo(o2.lastModified())
|
||||
}
|
||||
return files
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Sven R. Kunze
|
||||
* Copyright (C) 2017 Sven R. Kunze
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
*
|
||||
* 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.utils
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.resources.files.model.ServerFileInterface
|
||||
import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
|
||||
import third_parties.daveKoeller.AlphanumComparator
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* Sorts list by Name.
|
||||
*
|
||||
* Created by srkunze on 28.08.17.
|
||||
*/
|
||||
class FileSortOrderByName internal constructor(name: String?, ascending: Boolean) : FileSortOrder(name!!, ascending) {
|
||||
/**
|
||||
*
|
||||
* @param files files to sort
|
||||
*/
|
||||
@SuppressFBWarnings("Bx")
|
||||
override fun sortCloudFiles(files: MutableList<OCFile>): List<OCFile> {
|
||||
val sortedByName = sortServerFiles(files)
|
||||
return super.sortCloudFiles(sortedByName)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts list by Name.
|
||||
*
|
||||
* @param files files to sort
|
||||
*/
|
||||
override fun sortTrashbinFiles(files: MutableList<TrashbinFile>): List<TrashbinFile> {
|
||||
val sortedByName = sortServerFiles(files)
|
||||
return super.sortTrashbinFiles(sortedByName)
|
||||
}
|
||||
|
||||
private fun <T : ServerFileInterface> sortServerFiles(files: MutableList<T>): MutableList<T> {
|
||||
files.sortWith { o1: ServerFileInterface, o2: ServerFileInterface ->
|
||||
when {
|
||||
o1.isFolder && o2.isFolder -> sortMultiplier * AlphanumComparator.compare(o1, o2)
|
||||
o1.isFolder -> -1
|
||||
o2.isFolder -> 1
|
||||
else -> sortMultiplier * AlphanumComparator.compare(o1, o2)
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts list by Name.
|
||||
*
|
||||
* @param files files to sort
|
||||
*/
|
||||
override fun sortLocalFiles(files: MutableList<File>): List<File> {
|
||||
files.sortWith { o1: File, o2: File ->
|
||||
when {
|
||||
o1.isDirectory && o2.isDirectory -> sortMultiplier * o1.path.lowercase(Locale.getDefault())
|
||||
.compareTo(o2.path.lowercase(Locale.getDefault()))
|
||||
o1.isDirectory -> -1
|
||||
o2.isDirectory -> 1
|
||||
else -> sortMultiplier * AlphanumComparator.compare(
|
||||
o1.path.lowercase(Locale.getDefault()),
|
||||
o2.path.lowercase(Locale.getDefault())
|
||||
)
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Sven R. Kunze
|
||||
* Copyright (C) 2017 Sven R. Kunze
|
||||
* Copyright (C) 2022 Álvaro Brey Vilas
|
||||
*
|
||||
* 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.utils
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.resources.files.model.ServerFileInterface
|
||||
import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Sorts files by sizes
|
||||
*/
|
||||
class FileSortOrderBySize internal constructor(name: String?, ascending: Boolean) : FileSortOrder(name!!, ascending) {
|
||||
|
||||
override fun sortCloudFiles(files: MutableList<OCFile>): List<OCFile> {
|
||||
val sortedBySize = sortServerFiles(files)
|
||||
return super.sortCloudFiles(sortedBySize)
|
||||
}
|
||||
|
||||
override fun sortTrashbinFiles(files: MutableList<TrashbinFile>): List<TrashbinFile> {
|
||||
val sortedBySize = sortServerFiles(files)
|
||||
return super.sortTrashbinFiles(sortedBySize)
|
||||
}
|
||||
|
||||
private fun <T : ServerFileInterface> sortServerFiles(files: MutableList<T>): MutableList<T> {
|
||||
files.sortWith { o1: ServerFileInterface, o2: ServerFileInterface ->
|
||||
when {
|
||||
o1.isFolder && o2.isFolder -> sortMultiplier * o1.fileLength.compareTo(o2.fileLength)
|
||||
o1.isFolder -> -1
|
||||
o2.isFolder -> 1
|
||||
else -> sortMultiplier * o1.fileLength.compareTo(o2.fileLength)
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
override fun sortLocalFiles(files: MutableList<File>): List<File> {
|
||||
|
||||
files.sortWith { o1: File, o2: File ->
|
||||
when {
|
||||
o1.isDirectory && o2.isDirectory -> sortMultiplier * FileStorageUtils.getFolderSize(o1)
|
||||
.compareTo(FileStorageUtils.getFolderSize(o2))
|
||||
o1.isDirectory -> -1
|
||||
o2.isDirectory -> 1
|
||||
else -> sortMultiplier * o1.length().compareTo(o2.length())
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Álvaro Brey Vilas
|
||||
* @author Andy Scherzinger
|
||||
* Copyright (C) 2021 Álvaro Brey Vilas
|
||||
* Copyright (C) 2021 Nextcloud GmbH
|
||||
* Copyright (C) 2015 Andy Scherzinger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.utils
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.ResolveInfo
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.provider.Settings
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.nextcloud.client.preferences.AppPreferences
|
||||
import com.nextcloud.client.preferences.AppPreferencesImpl
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.ui.dialog.StoragePermissionDialogFragment
|
||||
import com.owncloud.android.utils.theme.ThemeSnackbarUtils
|
||||
|
||||
object PermissionUtil {
|
||||
const val PERMISSIONS_EXTERNAL_STORAGE = 1
|
||||
const val PERMISSIONS_READ_CONTACTS_AUTOMATIC = 2
|
||||
const val PERMISSIONS_WRITE_CONTACTS = 4
|
||||
const val PERMISSIONS_CAMERA = 5
|
||||
const val PERMISSIONS_READ_CALENDAR_AUTOMATIC = 6
|
||||
const val PERMISSIONS_WRITE_CALENDAR = 7
|
||||
const val PERMISSIONS_SCAN_DOCUMENT = 6
|
||||
|
||||
const val REQUEST_CODE_MANAGE_ALL_FILES = 19203
|
||||
|
||||
const val PERMISSION_CHOICE_DIALOG_TAG = "PERMISSION_CHOICE_DIALOG"
|
||||
|
||||
/**
|
||||
* Wrapper method for ContextCompat.checkSelfPermission().
|
||||
* Determine whether *the app* has been granted a particular permission.
|
||||
*
|
||||
* @param permission The name of the permission being checked.
|
||||
* @return `true` if app has the permission, or `false` if not.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun checkSelfPermission(context: Context, permission: String): Boolean =
|
||||
ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED
|
||||
|
||||
/**
|
||||
* Wrapper method for ActivityCompat.shouldShowRequestPermissionRationale().
|
||||
* Gets whether you should show UI with rationale for requesting a permission.
|
||||
* You should do this only if you do not have the permission and the context in
|
||||
* which the permission is requested does not clearly communicate to the user
|
||||
* what would be the benefit from granting this permission.
|
||||
*
|
||||
* @param activity The target activity.
|
||||
* @param permission A permission to be requested.
|
||||
* @return Whether to show permission rationale UI.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun shouldShowRequestPermissionRationale(activity: Activity, permission: String): Boolean =
|
||||
ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)
|
||||
|
||||
/**
|
||||
* Determine whether the app has been granted external storage permissions depending on SDK.
|
||||
*
|
||||
* For sdk >= 30 we use the storage manager special permission for full access, or READ_EXTERNAL_STORAGE
|
||||
* for limited access
|
||||
*
|
||||
* Under sdk 30 we use WRITE_EXTERNAL_STORAGE
|
||||
*
|
||||
* @return `true` if app has the permission, or `false` if not.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun checkExternalStoragePermission(context: Context): Boolean = when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> Environment.isExternalStorageManager() || checkSelfPermission(
|
||||
context,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
)
|
||||
else -> checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
}
|
||||
|
||||
/**
|
||||
* Request relevant external storage permission depending on SDK, if needed.
|
||||
*
|
||||
* Activities should implement [Activity.onRequestPermissionsResult]
|
||||
* and handle the [PERMISSIONS_EXTERNAL_STORAGE] code, as well as [Activity.onActivityResult]
|
||||
* with `requestCode=`[REQUEST_CODE_MANAGE_ALL_FILES]
|
||||
*
|
||||
* @param activity The target activity.
|
||||
* @param permissionRequired for SDK >=30 specifically, show again even if already denied in the past
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun requestExternalStoragePermission(activity: AppCompatActivity, permissionRequired: Boolean = false) {
|
||||
if (!checkExternalStoragePermission(activity)) {
|
||||
when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
|
||||
if (canRequestAllFilesPermission(activity)) {
|
||||
// can request All Files, show choice
|
||||
showPermissionChoiceDialog(activity, permissionRequired)
|
||||
} else {
|
||||
// can not request all files, request READ_EXTERNAL_STORAGE
|
||||
requestStoragePermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
}
|
||||
}
|
||||
else -> requestStoragePermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Request a storage permission
|
||||
*/
|
||||
private fun requestStoragePermission(activity: Activity, permission: String) {
|
||||
fun doRequest() {
|
||||
ActivityCompat.requestPermissions(
|
||||
activity, arrayOf(permission),
|
||||
PERMISSIONS_EXTERNAL_STORAGE
|
||||
)
|
||||
}
|
||||
|
||||
// Check if we should show an explanation
|
||||
if (shouldShowRequestPermissionRationale(activity, permission)) {
|
||||
// Show explanation to the user and then request permission
|
||||
Snackbar
|
||||
.make(
|
||||
activity.findViewById(android.R.id.content),
|
||||
R.string.permission_storage_access,
|
||||
Snackbar.LENGTH_INDEFINITE
|
||||
)
|
||||
.setAction(R.string.common_ok) {
|
||||
doRequest()
|
||||
}
|
||||
.also {
|
||||
ThemeSnackbarUtils.colorSnackbar(activity, it)
|
||||
}
|
||||
.show()
|
||||
} else {
|
||||
// No explanation needed, request the permission.
|
||||
doRequest()
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private fun canRequestAllFilesPermission(context: Context) =
|
||||
manifestHasAllFilesPermission(context) && hasManageAllFilesActivity(context)
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private fun hasManageAllFilesActivity(context: Context): Boolean {
|
||||
val intent = getManageAllFilesIntent(context)
|
||||
|
||||
val launchables: List<ResolveInfo> = context.packageManager
|
||||
.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER)
|
||||
return launchables.isNotEmpty()
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private fun manifestHasAllFilesPermission(context: Context): Boolean {
|
||||
val packageInfo = context.packageManager.getPackageInfo(context.packageName, PackageManager.GET_PERMISSIONS)
|
||||
return packageInfo?.requestedPermissions?.contains(Manifest.permission.MANAGE_EXTERNAL_STORAGE) ?: false
|
||||
}
|
||||
|
||||
/**
|
||||
* sdk >= 30: Choice between All Files access or read_external_storage
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private fun showPermissionChoiceDialog(activity: AppCompatActivity, permissionRequired: Boolean) {
|
||||
val preferences: AppPreferences = AppPreferencesImpl.fromContext(activity)
|
||||
|
||||
if (!preferences.isStoragePermissionRequested || permissionRequired) {
|
||||
if (activity.supportFragmentManager.findFragmentByTag(PERMISSION_CHOICE_DIALOG_TAG) == null) {
|
||||
val listener = object : StoragePermissionDialogFragment.Listener {
|
||||
override fun onCancel() {
|
||||
preferences.isStoragePermissionRequested = true
|
||||
}
|
||||
|
||||
override fun onClickFullAccess() {
|
||||
preferences.isStoragePermissionRequested = true
|
||||
val intent = getManageAllFilesIntent(activity)
|
||||
activity.startActivityForResult(intent, REQUEST_CODE_MANAGE_ALL_FILES)
|
||||
preferences.isStoragePermissionRequested = true
|
||||
}
|
||||
|
||||
override fun onClickMediaReadOnly() {
|
||||
preferences.isStoragePermissionRequested = true
|
||||
requestStoragePermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
}
|
||||
}
|
||||
val dialogFragment = StoragePermissionDialogFragment(listener, permissionRequired)
|
||||
dialogFragment.show(activity.supportFragmentManager, PERMISSION_CHOICE_DIALOG_TAG)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private fun getManageAllFilesIntent(context: Context) =
|
||||
Intent().apply {
|
||||
action = Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
|
||||
data = Uri.parse("package:${context.applicationContext.packageName}")
|
||||
}
|
||||
|
||||
/**
|
||||
* request camera permission.
|
||||
*
|
||||
* @param activity The target activity.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun requestCameraPermission(activity: Activity, requestCode: Int) {
|
||||
ActivityCompat.requestPermissions(
|
||||
activity, arrayOf(Manifest.permission.CAMERA),
|
||||
requestCode
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<!--
|
||||
~ Nextcloud Android client application
|
||||
~
|
||||
~ @author Álvaro Brey Vilas
|
||||
~ Copyright (C) 2022 Álvaro Brey Vilas
|
||||
~ Copyright (C) 2022 Nextcloud GmbH
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="m7.9482,15.6104c0.3479,0 0.682,-0.1385 0.9282,-0.3847 0.2462,-0.2462 0.3847,-0.5803 0.3847,-0.9282 0,-0.7286 -0.5908,-1.3129 -1.3129,-1.3129 -0.3479,0 -0.682,0.1385 -0.9282,0.3847 -0.2462,0.2462 -0.3847,0.5803 -0.3847,0.9282 0,0.3479 0.1385,0.682 0.3847,0.9282 0.2462,0.2462 0.5803,0.3847 0.9282,0.3847M11.8868,9.7025c0.3479,0 0.682,0.1385 0.9282,0.3847 0.2462,0.2462 0.3847,0.5803 0.3847,0.9282v6.5644c0,0.3479 -0.1385,0.682 -0.3847,0.9282 -0.2462,0.2462 -0.5803,0.3847 -0.9282,0.3847H4.0095c-0.3479,0 -0.682,-0.1385 -0.9282,-0.3847 -0.2462,-0.2462 -0.3847,-0.5803 -0.3847,-0.9282v-6.5644c0,-0.7286 0.5908,-1.3129 1.3129,-1.3129H4.666V8.3896c0,-0.8704 0.3459,-1.7054 0.961,-2.3212 0.6157,-0.6151 1.4507,-0.961 2.3212,-0.961 0.8704,0 1.7054,0.3459 2.3212,0.961 0.6151,0.6157 0.961,1.4507 0.961,2.3212v1.3129h0.6564M7.9482,6.4203c-0.5219,0 -1.0234,0.2074 -1.3923,0.577C6.1863,7.3662 5.9789,7.8677 5.9789,8.3896V9.7025H9.9175V8.3896c0,-0.5219 -0.2074,-1.0234 -0.577,-1.3923C8.9716,6.6277 8.47,6.4203 7.9482,6.4203Z"
|
||||
android:strokeWidth="0.656438"
|
||||
android:fillColor="#666666"/>
|
||||
<path
|
||||
android:pathData="m19.3033,8c1.1,0 2,-0.9 2,-2 0,-1.1 -0.9,-2 -2,-2 -1.1,0 -2,0.9 -2,2 0,1.1 0.9,2 2,2zM19.3033,10c-1.1,0 -2,0.9 -2,2 0,1.1 0.9,2 2,2 1.1,0 2,-0.9 2,-2 0,-1.1 -0.9,-2 -2,-2zM19.3033,16c-1.1,0 -2,0.9 -2,2 0,1.1 0.9,2 2,2 1.1,0 2,-0.9 2,-2 0,-1.1 -0.9,-2 -2,-2z"
|
||||
android:fillColor="#666666"/>
|
||||
</vector>
|
||||
@@ -1,13 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:autoMirrored="true"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
tools:ignore="VectorRaster">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M23,21.1663C23,22.1728 22.1728,23 21.1663,23L17.5,23L17.5,21.1663L21.1663,21.1663L21.1663,17.5L23,17.5L23,21.1663ZM2.8337,23C1.8272,23 1,22.1728 1,21.1663L1,17.5L2.8337,17.5L2.8337,21.1663L6.5,21.1663L6.5,23L2.8337,23ZM6.4483,4.85C6.1645,4.85 5.9423,5.0744 5.9423,5.3604L5.9423,18.6396C5.9423,18.9256 6.1645,19.15 6.4483,19.15L17.5616,19.15C17.8443,19.15 18.0665,18.9256 18.0665,18.6396L18.0665,7.9146L15.036,4.85L6.4483,4.85ZM7.963,16.0854L12.0044,16.0854L12.0044,17.1073L7.963,17.1073L7.963,16.0854ZM7.963,13.0219L16.0458,13.0219L16.0458,14.0427L7.963,14.0427L7.963,13.0219ZM7.963,9.9573L13.0153,9.9573L13.0153,10.9781L7.963,10.9781L7.963,9.9573ZM7.963,6.8927L14.0251,6.8927L14.0251,7.9146L7.963,7.9146L7.963,6.8927ZM1,2.8337C1,1.8272 1.8272,1 2.8337,1L6.5,1L6.5,2.8337L2.8337,2.8337L2.8337,6.5L1,6.5L1,2.8337ZM21.1663,1C22.1728,1 23,1.8272 23,2.8337L23,6.5L21.1663,6.5L21.1663,2.8337L17.5,2.8337L17.5,1L21.1663,1Z" />
|
||||
</vector>
|
||||
@@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Nextcloud Android client application
|
||||
~
|
||||
~ @author Álvaro Brey Vilas
|
||||
~ Copyright (C) 2022 Álvaro Brey Vilas
|
||||
~ Copyright (C) 2022 Nextcloud GmbH
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="@color/grey_200">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="?android:colorPrimary" />
|
||||
</shape>
|
||||
<color android:color="@color/white" />
|
||||
</item>
|
||||
</ripple>
|
||||