diff --git a/.github/workflows/assembleFlavors.yml b/.github/workflows/assembleFlavors.yml index 165c7f720a6f..a334359beae6 100644 --- a/.github/workflows/assembleFlavors.yml +++ b/.github/workflows/assembleFlavors.yml @@ -19,7 +19,7 @@ jobs: matrix: flavor: [ Generic, Gplay, Huawei ] steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v3 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3 - name: set up JDK 17 uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3 with: diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 3151bfac84d8..ddb198952505 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -19,7 +19,7 @@ jobs: matrix: task: [ detekt, spotlessKotlinCheck ] steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v3 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3 - name: Set up JDK 17 uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3 with: diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index d0ef92034436..369b7acfc146 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -12,6 +12,10 @@ on: permissions: contents: read +concurrency: + group: code-ql-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + jobs: analyze: name: Analyze @@ -32,7 +36,7 @@ jobs: with: swap-size-gb: 10 - name: Initialize CodeQL - uses: github/codeql-action/init@0116bc2df50751f9724a2e35ef1f24d22f90e4e1 # v2.22.3 + uses: github/codeql-action/init@49abf0ba24d0b7953cb586944e918a0b92074c80 # v2.22.4 with: languages: ${{ matrix.language }} - name: Set up JDK 17 @@ -46,4 +50,4 @@ jobs: echo "org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > "$HOME/.gradle/gradle.properties" ./gradlew assembleDebug - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@0116bc2df50751f9724a2e35ef1f24d22f90e4e1 # v2.22.3 + uses: github/codeql-action/analyze@49abf0ba24d0b7953cb586944e918a0b92074c80 # v2.22.4 diff --git a/.github/workflows/command-rebase.yml b/.github/workflows/command-rebase.yml index 8c215c1c4ca6..60876df35457 100644 --- a/.github/workflows/command-rebase.yml +++ b/.github/workflows/command-rebase.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Add reaction on start - uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2 + uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3.1.0 with: token: ${{ secrets.COMMAND_BOT_PAT }} repository: ${{ github.event.repository.full_name }} @@ -31,7 +31,7 @@ jobs: reaction-type: "+1" - name: Checkout the latest code - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: fetch-depth: 0 token: ${{ secrets.COMMAND_BOT_PAT }} @@ -42,7 +42,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.COMMAND_BOT_PAT }} - name: Add reaction on failure - uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2 + uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3.1.0 if: failure() with: token: ${{ secrets.COMMAND_BOT_PAT }} diff --git a/.github/workflows/detectWrongSettings.yml b/.github/workflows/detectWrongSettings.yml index 599e7d06b4c5..9d6dce59a20c 100644 --- a/.github/workflows/detectWrongSettings.yml +++ b/.github/workflows/detectWrongSettings.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v3 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3 - name: Set up JDK 17 uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3 with: diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index 8f9090e6cf50..8a6f9e6cd7ad 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -19,7 +19,7 @@ jobs: - name: Check if secrets are available run: echo "::set-output name=ok::${{ secrets.KS_PASS != '' }}" id: check-secrets - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v3 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3 if: ${{ steps.check-secrets.outputs.ok == 'true' }} - name: set up JDK 17 uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3 diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 04e89bad60bb..bd873fbb8143 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -29,7 +29,7 @@ jobs: persist-credentials: false - name: "Run analysis" - uses: ossf/scorecard-action@483ef80eb98fb506c348f7d62e28055e49fe2398 # v2.3.0 + uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1 with: results_file: results.sarif results_format: sarif @@ -37,6 +37,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@0116bc2df50751f9724a2e35ef1f24d22f90e4e1 # v2.22.3 + uses: github/codeql-action/upload-sarif@49abf0ba24d0b7953cb586944e918a0b92074c80 # v2.22.4 with: sarif_file: results.sarif diff --git a/.github/workflows/screenShotTest.yml b/.github/workflows/screenShotTest.yml index 9b768312963c..e036d66e6ec5 100644 --- a/.github/workflows/screenShotTest.yml +++ b/.github/workflows/screenShotTest.yml @@ -22,7 +22,7 @@ jobs: color: [ blue ] api-level: [ 27 ] steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v3 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v3 - name: Gradle cache uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3 diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index f7b750515f89..12a5a6da2b64 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -18,7 +18,7 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up JDK 17 uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index ebc537ffa5c9..5d6df215c09e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,30 @@ -## 3.24.1 (February 21, 2022) +## 3.26.0 (September 16, 2023) + +- image editing +- image details, with map +- show other Nextcloud apps + +Minimum: NC 16 Server, Android 6.0 Marshmallow + +For a full list, please see https://github.com/nextcloud/android/milestone/84 + +## 3.25.0 (June 13, 2023) + +- show Groupfolder +- Tag in file listing + +Minimum: NC 16 Server, Android 6.0 Marshmallow + +For a full list, please see https://github.com/nextcloud/android/milestone/81 + +## 3.24.1 (February 21, 2023) - Fix crash in previous version when connecting to old server versions Minimum: NC 16 Server, Android 6.0 Marshmallow +For a full list, please see https://github.com/nextcloud/android/milestone/80 + ## 3.24.0 (February 13, 2023) - Several performance optimizations by @starypatyk diff --git a/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_keepBoth.png b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_keepBoth.png index 47172a3da27b..97e0219c3302 100644 Binary files a/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_keepBoth.png and b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_keepBoth.png differ diff --git a/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_keepExisting.png b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_keepExisting.png index 8ad1818f865e..57b78febd9c2 100644 Binary files a/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_keepExisting.png and b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_keepExisting.png differ diff --git a/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_keepNew.png b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_keepNew.png index e51fdd8144d0..bf4f56484ee1 100644 Binary files a/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_keepNew.png and b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_keepNew.png differ diff --git a/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_screenshotTextFiles.png b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_screenshotTextFiles.png index 336694046bc1..df72127e511a 100644 Binary files a/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_screenshotTextFiles.png and b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ConflictsResolveActivityIT_screenshotTextFiles.png differ diff --git a/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ContactsPreferenceActivityIT_openContactsPreference.png b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ContactsPreferenceActivityIT_openContactsPreference.png index 26c12663b702..f450422215b5 100644 Binary files a/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ContactsPreferenceActivityIT_openContactsPreference.png and b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.ContactsPreferenceActivityIT_openContactsPreference.png differ diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt index 427b9f605d7b..d8a417513be0 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt @@ -29,7 +29,6 @@ import android.content.ContentResolver import android.content.Context import android.content.Intent import android.content.Intent.FLAG_ACTIVITY_NEW_TASK -import android.graphics.BitmapFactory import androidx.core.app.NotificationCompat import androidx.work.Worker import androidx.work.WorkerParameters @@ -69,9 +68,7 @@ class FilesExportWork( val successfulExports = exportFiles(fileIDs) - // show notification showSuccessNotification(successfulExports) - return Result.success() } @@ -105,7 +102,13 @@ class FilesExportWork( @Throws(IllegalStateException::class) private fun exportFile(ocFile: OCFile) { - FileExportUtils().exportFile(ocFile.fileName, ocFile.mimeType, contentResolver, ocFile, null) + FileExportUtils().exportFile( + ocFile.fileName, + ocFile.mimeType, + contentResolver, + ocFile, + null + ) } private fun downloadFile(ocFile: OCFile) { @@ -119,19 +122,16 @@ class FilesExportWork( } private fun showErrorNotification(successfulExports: Int) { - if (successfulExports == 0) { - showNotification( - appContext.resources.getQuantityString(R.plurals.export_failed, successfulExports, successfulExports) - ) + val message = if (successfulExports == 0) { + appContext.resources.getQuantityString(R.plurals.export_failed, successfulExports, successfulExports) } else { - showNotification( - appContext.resources.getQuantityString( - R.plurals.export_partially_failed, - successfulExports, - successfulExports - ) + appContext.resources.getQuantityString( + R.plurals.export_partially_failed, + successfulExports, + successfulExports ) } + showNotification(message) } private fun showSuccessNotification(successfulExports: Int) { @@ -152,9 +152,7 @@ class FilesExportWork( NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD ) .setSmallIcon(R.drawable.notification_icon) - .setLargeIcon(BitmapFactory.decodeResource(appContext.resources, R.drawable.notification_icon)) - .setSubText(user.accountName) - .setContentText(message) + .setContentTitle(message) .setAutoCancel(true) viewThemeUtils.androidx.themeNotificationCompatBuilder(appContext, notificationBuilder) @@ -166,7 +164,8 @@ class FilesExportWork( appContext, notificationId, actionIntent, - PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE + PendingIntent.FLAG_CANCEL_CURRENT or + PendingIntent.FLAG_IMMUTABLE ) notificationBuilder.addAction( NotificationCompat.Action( @@ -176,7 +175,8 @@ class FilesExportWork( ) ) - val notificationManager = appContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val notificationManager = appContext + .getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager notificationManager.notify(notificationId, notificationBuilder.build()) } diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/ChooseTemplateDialogFragment.kt b/app/src/main/java/com/owncloud/android/ui/dialog/ChooseTemplateDialogFragment.kt index a0e9aa514f28..b56513207ae2 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/ChooseTemplateDialogFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/ChooseTemplateDialogFragment.kt @@ -32,10 +32,10 @@ import android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.view.View -import android.widget.Button import androidx.appcompat.app.AlertDialog import androidx.fragment.app.DialogFragment import androidx.recyclerview.widget.GridLayoutManager +import com.google.android.material.button.MaterialButton import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.nextcloud.android.lib.resources.directediting.DirectEditingCreateFileRemoteOperation import com.nextcloud.android.lib.resources.directediting.DirectEditingObtainListOfTemplatesRemoteOperation @@ -90,7 +90,7 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem private var adapter: TemplateAdapter? = null private var parentFolder: OCFile? = null private var title: String? = null - private var positiveButton: Button? = null + private var positiveButton: MaterialButton? = null private var creator: Creator? = null enum class Type { @@ -103,17 +103,18 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem override fun onStart() { super.onStart() val alertDialog = dialog as AlertDialog - val button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) - viewThemeUtils.platform.colorTextButtons( - button, - alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL) - ) - button.setOnClickListener(this) - button.isEnabled = false - button.isClickable = false + val positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) as MaterialButton + viewThemeUtils.material.colorMaterialButtonPrimaryTonal(positiveButton) + + val negativeButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE) as MaterialButton + viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton) - positiveButton = button + positiveButton.setOnClickListener(this) + positiveButton.isEnabled = false + positiveButton.isClickable = false + + this.positiveButton = positiveButton checkEnablingCreateButton() } @@ -128,6 +129,7 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem parentFolder = arguments.getParcelable(ARG_PARENT_FOLDER) creator = arguments.getParcelable(ARG_CREATOR) + title = arguments.getString(ARG_HEADLINE, getString(R.string.select_template)) title = when (savedInstanceState) { null -> arguments.getString(ARG_HEADLINE) @@ -175,7 +177,7 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem val builder = MaterialAlertDialogBuilder(activity) builder.setView(view) .setPositiveButton(R.string.create, null) - .setNeutralButton(R.string.common_cancel, null) + .setNegativeButton(R.string.common_cancel, null) .setTitle(title) viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.list.context, builder) @@ -208,8 +210,8 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem } fun setTemplateList(templateList: TemplateList?) { - adapter!!.setTemplateList(templateList) - adapter!!.notifyDataSetChanged() + adapter?.setTemplateList(templateList) + adapter?.notifyDataSetChanged() } override fun onClick(template: Template) { diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/ConflictsResolveDialog.java b/app/src/main/java/com/owncloud/android/ui/dialog/ConflictsResolveDialog.java index a7333ffcab73..088e6f1aa127 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/ConflictsResolveDialog.java +++ b/app/src/main/java/com/owncloud/android/ui/dialog/ConflictsResolveDialog.java @@ -29,6 +29,7 @@ import android.widget.Button; import android.widget.Toast; +import com.google.android.material.button.MaterialButton; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.nextcloud.client.account.User; import com.nextcloud.client.di.Injectable; @@ -70,7 +71,7 @@ public class ConflictsResolveDialog extends DialogFragment implements Injectable public OnConflictDecisionMadeListener listener; private User user; private final List asyncTasks = new ArrayList<>(); - private Button positiveButton; + private MaterialButton positiveButton; @Inject ViewThemeUtils viewThemeUtils; @Inject SyncedFolderProvider syncedFolderProvider; @@ -119,9 +120,11 @@ public void onStart() { return; } - positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); - viewThemeUtils.platform.colorTextButtons(positiveButton, - alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL)); + positiveButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); + MaterialButton negativeButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE); + + viewThemeUtils.material.colorMaterialButtonPrimaryTonal(positiveButton); + viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton); positiveButton.setEnabled(false); } @@ -175,7 +178,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { } }) - .setNeutralButton(R.string.common_cancel, (dialog, which) -> { + .setNegativeButton(R.string.common_cancel, (dialog, which) -> { if (listener != null) { listener.conflictDecisionMade(Decision.CANCEL); } @@ -275,4 +278,5 @@ public void onStop() { asyncTasks.clear(); } + } diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/BackupFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/BackupFragment.java deleted file mode 100644 index aad71fe6246f..000000000000 --- a/app/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/BackupFragment.java +++ /dev/null @@ -1,691 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Mario Danic - * @author TSI-mc - * Copyright (C) 2017 Mario Danic - * Copyright (C) 2017 Nextcloud GmbH. - * Copyright (C) 2023 TSI-mc - * - * 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 . - */ -package com.owncloud.android.ui.fragment.contactsbackup; - -import android.Manifest; -import android.app.DatePickerDialog; -import android.content.Context; -import android.content.Intent; -import android.os.AsyncTask; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CompoundButton; -import android.widget.DatePicker; -import android.widget.Toast; - -import com.nextcloud.client.account.User; -import com.nextcloud.client.di.Injectable; -import com.nextcloud.client.jobs.BackgroundJobManager; -import com.nextcloud.java.util.Optional; -import com.owncloud.android.R; -import com.owncloud.android.databinding.BackupFragmentBinding; -import com.owncloud.android.datamodel.ArbitraryDataProvider; -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.operations.RefreshFolderOperation; -import com.owncloud.android.ui.activity.ContactsPreferenceActivity; -import com.owncloud.android.ui.activity.SettingsActivity; -import com.owncloud.android.ui.fragment.FileFragment; -import com.owncloud.android.utils.DisplayUtils; -import com.owncloud.android.utils.MimeTypeUtil; -import com.owncloud.android.utils.PermissionUtil; -import com.owncloud.android.utils.theme.ThemeUtils; -import com.owncloud.android.utils.theme.ViewThemeUtils; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import javax.inject.Inject; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.ActionBar; -import androidx.fragment.app.Fragment; -import third_parties.daveKoeller.AlphanumComparator; - -import static com.owncloud.android.ui.activity.ContactsPreferenceActivity.PREFERENCE_CONTACTS_AUTOMATIC_BACKUP; -import static com.owncloud.android.ui.activity.ContactsPreferenceActivity.PREFERENCE_CONTACTS_LAST_BACKUP; - -public class BackupFragment extends FileFragment implements DatePickerDialog.OnDateSetListener, Injectable { - public static final String TAG = BackupFragment.class.getSimpleName(); - private static final String ARG_SHOW_SIDEBAR = "SHOW_SIDEBAR"; - private static final String KEY_CALENDAR_PICKER_OPEN = "IS_CALENDAR_PICKER_OPEN"; - private static final String KEY_CALENDAR_DAY = "CALENDAR_DAY"; - private static final String KEY_CALENDAR_MONTH = "CALENDAR_MONTH"; - private static final String KEY_CALENDAR_YEAR = "CALENDAR_YEAR"; - - public static final String PREFERENCE_CONTACTS_BACKUP_ENABLED = "PREFERENCE_CONTACTS_BACKUP_ENABLED"; - public static final String PREFERENCE_CALENDAR_BACKUP_ENABLED = "PREFERENCE_CALENDAR_BACKUP_ENABLED"; - - - private BackupFragmentBinding binding; - - @Inject BackgroundJobManager backgroundJobManager; - @Inject ThemeUtils themeUtils; - - @Inject ArbitraryDataProvider arbitraryDataProvider; - @Inject ViewThemeUtils viewThemeUtils; - - private Date selectedDate; - private boolean calendarPickerOpen; - - private DatePickerDialog datePickerDialog; - - private CompoundButton.OnCheckedChangeListener dailyBackupCheckedChangeListener; - private CompoundButton.OnCheckedChangeListener contactsCheckedListener; - private CompoundButton.OnCheckedChangeListener calendarCheckedListener; - private User user; - private boolean showSidebar = true; - //flag to check if calendar backup should be shown and backup should be done or not - private boolean showCalendarBackup = true; - public static BackupFragment create(boolean showSidebar) { - BackupFragment fragment = new BackupFragment(); - Bundle bundle = new Bundle(); - bundle.putBoolean(ARG_SHOW_SIDEBAR, showSidebar); - fragment.setArguments(bundle); - return fragment; - } - - private boolean isCalendarBackupEnabled() { - return arbitraryDataProvider.getBooleanValue(user, PREFERENCE_CALENDAR_BACKUP_ENABLED); - } - - private void setCalendarBackupEnabled(final boolean enabled) { - arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), PREFERENCE_CALENDAR_BACKUP_ENABLED, enabled); - } - - private boolean isContactsBackupEnabled() { - return arbitraryDataProvider.getBooleanValue(user, PREFERENCE_CONTACTS_BACKUP_ENABLED); - } - - private void setContactsBackupEnabled(final boolean enabled) { - arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), PREFERENCE_CONTACTS_BACKUP_ENABLED, enabled); - } - - @Override - public View onCreateView(@NonNull final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - - // use grey as fallback for elements where custom theming is not available - if (themeUtils.themingEnabled(getContext())) { - getContext().getTheme().applyStyle(R.style.FallbackThemingTheme, true); - } - - binding = BackupFragmentBinding.inflate(inflater, container, false); - View view = binding.getRoot(); - - setHasOptionsMenu(true); - - if (getArguments() != null) { - showSidebar = getArguments().getBoolean(ARG_SHOW_SIDEBAR); - } - - showCalendarBackup = requireContext().getResources().getBoolean(R.bool.show_calendar_backup); - - final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity(); - user = contactsPreferenceActivity.getUser().orElseThrow(RuntimeException::new); - - ActionBar actionBar = contactsPreferenceActivity != null ? contactsPreferenceActivity.getSupportActionBar() : null; - - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - viewThemeUtils.files.themeActionBar(requireContext(), actionBar, - showCalendarBackup ? R.string.backup_title : R.string.contact_backup_title); - } - - - viewThemeUtils.androidx.colorSwitchCompat(binding.contacts); - viewThemeUtils.androidx.colorSwitchCompat(binding.calendar); - viewThemeUtils.androidx.colorSwitchCompat(binding.dailyBackup); - binding.dailyBackup.setChecked(arbitraryDataProvider.getBooleanValue(user, - PREFERENCE_CONTACTS_AUTOMATIC_BACKUP)); - - binding.contacts.setChecked(isContactsBackupEnabled() && checkContactBackupPermission()); - binding.calendar.setChecked(isCalendarBackupEnabled() && checkCalendarBackupPermission(getContext())); - - binding.calendar.setVisibility(showCalendarBackup ? View.VISIBLE : View.GONE); - - setupCheckListeners(); - - setBackupNowButtonVisibility(); - - binding.backupNow.setOnClickListener(v -> backupNow()); - - binding.contactsDatepicker.setOnClickListener(v -> openCleanDate()); - - // display last backup - Long lastBackupTimestamp = arbitraryDataProvider.getLongValue(user, PREFERENCE_CONTACTS_LAST_BACKUP); - - if (lastBackupTimestamp == -1) { - binding.lastBackupWithDate.setVisibility(View.GONE); - } else { - binding.lastBackupWithDate.setText( - String.format(getString(R.string.last_backup), - DisplayUtils.getRelativeTimestamp(contactsPreferenceActivity, lastBackupTimestamp))); - } - - if (savedInstanceState != null && savedInstanceState.getBoolean(KEY_CALENDAR_PICKER_OPEN, false)) { - if (savedInstanceState.getInt(KEY_CALENDAR_YEAR, -1) != -1 && - savedInstanceState.getInt(KEY_CALENDAR_MONTH, -1) != -1 && - savedInstanceState.getInt(KEY_CALENDAR_DAY, -1) != -1) { - selectedDate = new Date(savedInstanceState.getInt(KEY_CALENDAR_YEAR), - savedInstanceState.getInt(KEY_CALENDAR_MONTH), savedInstanceState.getInt(KEY_CALENDAR_DAY)); - } - calendarPickerOpen = true; - } - - viewThemeUtils.material.colorMaterialButtonPrimaryFilled(binding.backupNow); - viewThemeUtils.material.colorMaterialButtonPrimaryOutlined(binding.contactsDatepicker); - - viewThemeUtils.platform.colorTextView(binding.dataToBackUpTitle); - viewThemeUtils.platform.colorTextView(binding.backupSettingsTitle); - - return view; - } - - private void setupCheckListeners() { - dailyBackupCheckedChangeListener = (buttonView, isChecked) -> { - if (checkAndAskForContactsReadPermission()) { - setAutomaticBackup(isChecked); - } - }; - binding.dailyBackup.setOnCheckedChangeListener(dailyBackupCheckedChangeListener); - - - contactsCheckedListener = (buttonView, isChecked) -> { - if (isChecked) { - if (checkAndAskForContactsReadPermission()) { - setContactsBackupEnabled(true); - } - } else { - setContactsBackupEnabled(false); - } - setBackupNowButtonVisibility(); - setAutomaticBackup(binding.dailyBackup.isChecked()); - }; - binding.contacts.setOnCheckedChangeListener(contactsCheckedListener); - - calendarCheckedListener = (buttonView, isChecked) -> { - if (isChecked) { - if (checkAndAskForCalendarReadPermission()) { - setCalendarBackupEnabled(true); - } - } else { - setCalendarBackupEnabled(false); - } - setBackupNowButtonVisibility(); - setAutomaticBackup(binding.dailyBackup.isChecked()); - }; - binding.calendar.setOnCheckedChangeListener(calendarCheckedListener); - } - - private void setBackupNowButtonVisibility() { - if (binding.contacts.isChecked() || binding.calendar.isChecked()) { - binding.backupNow.setVisibility(View.VISIBLE); - } else { - binding.backupNow.setVisibility(View.INVISIBLE); - } - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - } - - @Override - public void onResume() { - super.onResume(); - - if (calendarPickerOpen) { - if (selectedDate != null) { - openDate(selectedDate); - } else { - openDate(null); - } - } - - final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity(); - if (contactsPreferenceActivity != null) { - String backupFolderPath = getResources().getString(R.string.contacts_backup_folder) + OCFile.PATH_SEPARATOR; - refreshBackupFolder(backupFolderPath, - contactsPreferenceActivity.getApplicationContext(), - contactsPreferenceActivity.getStorageManager()); - } - } - - private void refreshBackupFolder(final String backupFolderPath, - final Context context, - final FileDataStorageManager storageManager) { - AsyncTask task = new AsyncTask() { - @Override - protected Boolean doInBackground(String... path) { - OCFile folder = storageManager.getFileByPath(path[0]); - - if (folder != null) { - RefreshFolderOperation operation = new RefreshFolderOperation(folder, System.currentTimeMillis(), - false, false, storageManager, user, context); - - RemoteOperationResult result = operation.execute(user, context); - return result.isSuccess(); - } else { - return Boolean.FALSE; - } - } - - @Override - protected void onPostExecute(Boolean result) { - if (result && binding != null) { - OCFile backupFolder = storageManager.getFileByPath(backupFolderPath); - - List backupFiles = storageManager - .getFolderContent(backupFolder, false); - - Collections.sort(backupFiles, new AlphanumComparator<>()); - - if (backupFiles == null || backupFiles.isEmpty()) { - binding.contactsDatepicker.setVisibility(View.INVISIBLE); - } else { - binding.contactsDatepicker.setVisibility(View.VISIBLE); - } - } - } - }; - - task.execute(backupFolderPath); - } - - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity(); - - boolean retval; - switch (item.getItemId()) { - case android.R.id.home: - if (showSidebar) { - if (contactsPreferenceActivity.isDrawerOpen()) { - contactsPreferenceActivity.closeDrawer(); - } else { - contactsPreferenceActivity.openDrawer(); - } - } else if (getActivity() != null) { - getActivity().finish(); - } else { - Intent settingsIntent = new Intent(getContext(), SettingsActivity.class); - settingsIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(settingsIntent); - } - retval = true; - break; - - default: - retval = super.onOptionsItemSelected(item); - break; - } - return retval; - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - super.onRequestPermissionsResult(requestCode, permissions, grantResults); - - if (requestCode == PermissionUtil.PERMISSIONS_READ_CONTACTS_AUTOMATIC) { - for (int index = 0; index < permissions.length; index++) { - if (Manifest.permission.READ_CONTACTS.equalsIgnoreCase(permissions[index])) { - if (grantResults[index] >= 0) { - // if approved, exit for loop - setContactsBackupEnabled(true); - break; - } - - // if not accepted, disable again - binding.contacts.setOnCheckedChangeListener(null); - binding.contacts.setChecked(false); - binding.contacts.setOnCheckedChangeListener(contactsCheckedListener); - } - } - } - - if (requestCode == PermissionUtil.PERMISSIONS_READ_CALENDAR_AUTOMATIC) { - boolean readGranted = false; - boolean writeGranted = false; - for (int index = 0; index < permissions.length; index++) { - if (Manifest.permission.WRITE_CALENDAR.equalsIgnoreCase(permissions[index]) && grantResults[index] >= 0) { - writeGranted = true; - } else if (Manifest.permission.READ_CALENDAR.equalsIgnoreCase(permissions[index]) && grantResults[index] >= 0) { - readGranted = true; - } - } - if (!readGranted || !writeGranted) { - // if not accepted, disable again - binding.calendar.setOnCheckedChangeListener(null); - binding.calendar.setChecked(false); - binding.calendar.setOnCheckedChangeListener(calendarCheckedListener); - } else { - setCalendarBackupEnabled(true); - } - } - - setBackupNowButtonVisibility(); - setAutomaticBackup(binding.dailyBackup.isChecked()); - } - - public void backupNow() { - if (isContactsBackupEnabled() && checkContactBackupPermission()) { - startContactsBackupJob(); - } - - if (showCalendarBackup && isCalendarBackupEnabled() && checkCalendarBackupPermission(requireContext())) { - startCalendarBackupJob(); - } - - DisplayUtils.showSnackMessage(requireView().findViewById(R.id.contacts_linear_layout), - R.string.contacts_preferences_backup_scheduled); - } - - private void startContactsBackupJob() { - ContactsPreferenceActivity activity = (ContactsPreferenceActivity) getActivity(); - if (activity != null) { - Optional optionalUser = activity.getUser(); - if (optionalUser.isPresent()) { - backgroundJobManager.startImmediateContactsBackup(optionalUser.get()); - } - } - } - - private void startCalendarBackupJob() { - ContactsPreferenceActivity activity = (ContactsPreferenceActivity) getActivity(); - if (activity != null) { - Optional optionalUser = activity.getUser(); - if (optionalUser.isPresent()) { - backgroundJobManager.startImmediateCalendarBackup(optionalUser.get()); - } - } - } - - private void setAutomaticBackup(final boolean enabled) { - - final ContactsPreferenceActivity activity = (ContactsPreferenceActivity) getActivity(); - if (activity == null) { - return; - } - Optional optionalUser = activity.getUser(); - if (!optionalUser.isPresent()) { - return; - } - User user = optionalUser.get(); - if (enabled) { - if (isContactsBackupEnabled()) { - Log_OC.d(TAG, "Scheduling contacts backup job"); - backgroundJobManager.schedulePeriodicContactsBackup(user); - } else { - Log_OC.d(TAG, "Cancelling contacts backup job"); - backgroundJobManager.cancelPeriodicContactsBackup(user); - } - if (isCalendarBackupEnabled()) { - Log_OC.d(TAG, "Scheduling calendar backup job"); - backgroundJobManager.schedulePeriodicCalendarBackup(user); - } else { - Log_OC.d(TAG, "Cancelling calendar backup job"); - backgroundJobManager.cancelPeriodicCalendarBackup(user); - } - } else { - Log_OC.d(TAG, "Cancelling all backup jobs"); - backgroundJobManager.cancelPeriodicContactsBackup(user); - backgroundJobManager.cancelPeriodicCalendarBackup(user); - } - - arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), - PREFERENCE_CONTACTS_AUTOMATIC_BACKUP, - String.valueOf(enabled)); - } - - private boolean checkAndAskForContactsReadPermission() { - final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity(); - - // check permissions - if (PermissionUtil.checkSelfPermission(contactsPreferenceActivity, Manifest.permission.READ_CONTACTS)) { - return true; - } else { - // No explanation needed, request the permission. - requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, - PermissionUtil.PERMISSIONS_READ_CONTACTS_AUTOMATIC); - return false; - } - } - - private boolean checkAndAskForCalendarReadPermission() { - final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity(); - - // check permissions - if (checkCalendarBackupPermission(contactsPreferenceActivity)) { - return true; - } else { - // No explanation needed, request the permission. - requestPermissions(new String[]{Manifest.permission.READ_CALENDAR, Manifest.permission.WRITE_CALENDAR}, - PermissionUtil.PERMISSIONS_READ_CALENDAR_AUTOMATIC); - return false; - } - } - - private boolean checkCalendarBackupPermission(final Context context) { - return PermissionUtil.checkSelfPermission(context, Manifest.permission.READ_CALENDAR) && PermissionUtil.checkSelfPermission(context, Manifest.permission.WRITE_CALENDAR); - } - - private boolean checkContactBackupPermission() { - return PermissionUtil.checkSelfPermission(getContext(), Manifest.permission.READ_CONTACTS); - } - - public void openCleanDate() { - if (checkAndAskForCalendarReadPermission() && checkAndAskForContactsReadPermission()) { - openDate(null); - } - } - - public void openDate(@Nullable Date savedDate) { - final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity(); - - if (contactsPreferenceActivity == null) { - Toast.makeText(getContext(), getString(R.string.error_choosing_date), Toast.LENGTH_LONG).show(); - return; - } - - String contactsBackupFolderString = - getResources().getString(R.string.contacts_backup_folder) + OCFile.PATH_SEPARATOR; - String calendarBackupFolderString = - getResources().getString(R.string.calendar_backup_folder) + OCFile.PATH_SEPARATOR; - - FileDataStorageManager storageManager = contactsPreferenceActivity.getStorageManager(); - - OCFile contactsBackupFolder = storageManager.getFileByDecryptedRemotePath(contactsBackupFolderString); - OCFile calendarBackupFolder = storageManager.getFileByDecryptedRemotePath(calendarBackupFolderString); - - List backupFiles = storageManager.getFolderContent(contactsBackupFolder, false); - backupFiles.addAll(storageManager.getFolderContent(calendarBackupFolder, false)); - - Collections.sort(backupFiles, (o1, o2) -> { - return Long.compare(o1.getModificationTimestamp(), o2.getModificationTimestamp()); - }); - - Calendar cal = Calendar.getInstance(); - int year; - int month; - int day; - - if (savedDate == null) { - year = cal.get(Calendar.YEAR); - month = cal.get(Calendar.MONTH) + 1; - day = cal.get(Calendar.DAY_OF_MONTH); - } else { - year = savedDate.getYear(); - month = savedDate.getMonth(); - day = savedDate.getDay(); - } - - if (backupFiles.size() > 0 && backupFiles.get(backupFiles.size() - 1) != null) { - datePickerDialog = new DatePickerDialog(contactsPreferenceActivity, this, year, month, day); - datePickerDialog.getDatePicker().setMaxDate(backupFiles.get(backupFiles.size() - 1) - .getModificationTimestamp()); - datePickerDialog.getDatePicker().setMinDate(backupFiles.get(0).getModificationTimestamp()); - - datePickerDialog.setOnDismissListener(dialog -> selectedDate = null); - - datePickerDialog.setTitle(""); - datePickerDialog.show(); - - viewThemeUtils.platform.colorTextButtons(datePickerDialog.getButton(DatePickerDialog.BUTTON_NEGATIVE), - datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE)); - - // set background to transparent - datePickerDialog.getButton(DatePickerDialog.BUTTON_NEGATIVE).setBackgroundColor(0x00000000); - datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setBackgroundColor(0x00000000); - } else { - DisplayUtils.showSnackMessage(getView().findViewById(R.id.contacts_linear_layout), - R.string.contacts_preferences_something_strange_happened); - } - } - - @Override - public void onDestroyView() { - binding = null; - super.onDestroyView(); - } - - @Override - public void onStop() { - super.onStop(); - if (datePickerDialog != null) { - datePickerDialog.dismiss(); - } - } - - @Override - public void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - if (datePickerDialog != null) { - outState.putBoolean(KEY_CALENDAR_PICKER_OPEN, datePickerDialog.isShowing()); - - if (datePickerDialog.isShowing()) { - outState.putInt(KEY_CALENDAR_DAY, datePickerDialog.getDatePicker().getDayOfMonth()); - outState.putInt(KEY_CALENDAR_MONTH, datePickerDialog.getDatePicker().getMonth()); - outState.putInt(KEY_CALENDAR_YEAR, datePickerDialog.getDatePicker().getYear()); - } - } - } - - @Override - public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { - final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity(); - - if (contactsPreferenceActivity == null) { - Toast.makeText(getContext(), getString(R.string.error_choosing_date), Toast.LENGTH_LONG).show(); - return; - } - - selectedDate = new Date(year, month, dayOfMonth); - - String contactsBackupFolderString = - getResources().getString(R.string.contacts_backup_folder) + OCFile.PATH_SEPARATOR; - String calendarBackupFolderString = - getResources().getString(R.string.calendar_backup_folder) + OCFile.PATH_SEPARATOR; - - FileDataStorageManager storageManager = contactsPreferenceActivity.getStorageManager(); - - OCFile contactsBackupFolder = storageManager.getFileByDecryptedRemotePath(contactsBackupFolderString); - OCFile calendarBackupFolder = storageManager.getFileByDecryptedRemotePath(calendarBackupFolderString); - - List backupFiles = storageManager.getFolderContent(contactsBackupFolder, false); - backupFiles.addAll(storageManager.getFolderContent(calendarBackupFolder, false)); - - // find file with modification with date and time between 00:00 and 23:59 - // if more than one file exists, take oldest - Calendar date = Calendar.getInstance(); - date.set(year, month, dayOfMonth); - - // start - date.set(Calendar.HOUR, 0); - date.set(Calendar.MINUTE, 0); - date.set(Calendar.SECOND, 1); - date.set(Calendar.MILLISECOND, 0); - date.set(Calendar.AM_PM, Calendar.AM); - long start = date.getTimeInMillis(); - - // end - date.set(Calendar.HOUR, 23); - date.set(Calendar.MINUTE, 59); - date.set(Calendar.SECOND, 59); - long end = date.getTimeInMillis(); - - OCFile contactsBackupToRestore = null; - List calendarBackupsToRestore = new ArrayList<>(); - - for (OCFile file : backupFiles) { - if (start < file.getModificationTimestamp() && end > file.getModificationTimestamp()) { - // contact - if (MimeTypeUtil.isVCard(file)) { - if (contactsBackupToRestore == null) { - contactsBackupToRestore = file; - } else if (contactsBackupToRestore.getModificationTimestamp() < file.getModificationTimestamp()) { - contactsBackupToRestore = file; - } - } - - // calendars - if (showCalendarBackup && MimeTypeUtil.isCalendar(file)) { - calendarBackupsToRestore.add(file); - } - } - } - - List backupToRestore = new ArrayList<>(); - - if (contactsBackupToRestore != null) { - backupToRestore.add(contactsBackupToRestore); - } - - backupToRestore.addAll(calendarBackupsToRestore); - - - if (backupToRestore.isEmpty()) { - DisplayUtils.showSnackMessage(getView().findViewById(R.id.contacts_linear_layout), - R.string.contacts_preferences_no_file_found); - } else { - final User user = contactsPreferenceActivity.getUser().orElseThrow(RuntimeException::new); - OCFile[] files = new OCFile[backupToRestore.size()]; - Fragment contactListFragment = BackupListFragment.newInstance(backupToRestore.toArray(files), user); - - contactsPreferenceActivity.getSupportFragmentManager(). - beginTransaction() - .replace(R.id.frame_container, contactListFragment, BackupListFragment.TAG) - .addToBackStack(ContactsPreferenceActivity.BACKUP_TO_LIST) - .commit(); - } - } -} diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/BackupFragment.kt b/app/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/BackupFragment.kt new file mode 100644 index 000000000000..e216bacaed7d --- /dev/null +++ b/app/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/BackupFragment.kt @@ -0,0 +1,726 @@ +/* + * Nextcloud Android client application + * + * @author Mario Danic + * @author TSI-mc + * Copyright (C) 2017 Mario Danic + * Copyright (C) 2017 Nextcloud GmbH. + * Copyright (C) 2023 TSI-mc + * + * 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 . + */ +package com.owncloud.android.ui.fragment.contactsbackup + +import android.Manifest +import android.annotation.SuppressLint +import android.app.DatePickerDialog +import android.app.DatePickerDialog.OnDateSetListener +import android.content.Context +import android.content.Intent +import android.os.AsyncTask +import android.os.Bundle +import android.view.LayoutInflater +import android.view.MenuItem +import android.view.View +import android.view.ViewGroup +import android.widget.CompoundButton +import android.widget.DatePicker +import android.widget.Toast +import com.nextcloud.client.account.User +import com.nextcloud.client.di.Injectable +import com.nextcloud.client.jobs.BackgroundJobManager +import com.owncloud.android.R +import com.owncloud.android.databinding.BackupFragmentBinding +import com.owncloud.android.datamodel.ArbitraryDataProvider +import com.owncloud.android.datamodel.FileDataStorageManager +import com.owncloud.android.datamodel.OCFile +import com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.operations.RefreshFolderOperation +import com.owncloud.android.ui.activity.ContactsPreferenceActivity +import com.owncloud.android.ui.activity.SettingsActivity +import com.owncloud.android.ui.fragment.FileFragment +import com.owncloud.android.utils.DisplayUtils +import com.owncloud.android.utils.MimeTypeUtil +import com.owncloud.android.utils.PermissionUtil +import com.owncloud.android.utils.PermissionUtil.checkSelfPermission +import com.owncloud.android.utils.theme.ThemeUtils +import com.owncloud.android.utils.theme.ViewThemeUtils +import third_parties.daveKoeller.AlphanumComparator +import java.util.Calendar +import java.util.Collections +import java.util.Date +import javax.inject.Inject + +@Suppress("TooManyFunctions") +class BackupFragment : FileFragment(), OnDateSetListener, Injectable { + private lateinit var binding: BackupFragmentBinding + + @JvmField + @Inject + var backgroundJobManager: BackgroundJobManager? = null + + @JvmField + @Inject + var themeUtils: ThemeUtils? = null + + @JvmField + @Inject + var arbitraryDataProvider: ArbitraryDataProvider? = null + + @JvmField + @Inject + var viewThemeUtils: ViewThemeUtils? = null + + private var selectedDate: Date? = null + private var calendarPickerOpen = false + private var datePickerDialog: DatePickerDialog? = null + private var contactsCheckedListener: CompoundButton.OnCheckedChangeListener? = null + private var calendarCheckedListener: CompoundButton.OnCheckedChangeListener? = null + private var user: User? = null + private var showSidebar = true + + // flag to check if calendar backup should be shown and backup should be done or not + private var showCalendarBackup = true + private var isCalendarBackupEnabled: Boolean + get() = user?.let { arbitraryDataProvider?.getBooleanValue(it, PREFERENCE_CALENDAR_BACKUP_ENABLED) } ?: false + private set(enabled) { + arbitraryDataProvider!!.storeOrUpdateKeyValue( + user!!.accountName, + PREFERENCE_CALENDAR_BACKUP_ENABLED, + enabled + ) + } + + private var isContactsBackupEnabled: Boolean + get() = user?.let { arbitraryDataProvider?.getBooleanValue(it, PREFERENCE_CONTACTS_BACKUP_ENABLED) } ?: false + private set(enabled) { + arbitraryDataProvider!!.storeOrUpdateKeyValue( + user!!.accountName, + PREFERENCE_CONTACTS_BACKUP_ENABLED, + enabled + ) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + // use grey as fallback for elements where custom theming is not available + if (themeUtils?.themingEnabled(context) == true) { + requireContext().theme.applyStyle(R.style.FallbackThemingTheme, true) + } + + binding = BackupFragmentBinding.inflate(inflater, container, false) + val view: View = binding.root + + setHasOptionsMenu(true) + + if (arguments != null) { + showSidebar = requireArguments().getBoolean(ARG_SHOW_SIDEBAR) + } + + showCalendarBackup = requireContext().resources.getBoolean(R.bool.show_calendar_backup) + + val contactsPreferenceActivity = activity as ContactsPreferenceActivity? + user = contactsPreferenceActivity?.user?.orElseThrow { RuntimeException() } + + setupSwitches(user) + + setupCheckListeners() + setBackupNowButtonVisibility() + + setOnClickListeners() + + contactsPreferenceActivity?.let { + displayLastBackup(it) + applyUserColorToActionBar(it) + } + + setupDates(savedInstanceState) + applyUserColor() + + return view + } + + private fun setupSwitches(user: User?) { + user?.let { + binding.dailyBackup.isChecked = arbitraryDataProvider?.getBooleanValue( + it, + ContactsPreferenceActivity.PREFERENCE_CONTACTS_AUTOMATIC_BACKUP + ) ?: false + } + + binding.contacts.isChecked = isContactsBackupEnabled && checkContactBackupPermission() + binding.calendar.isChecked = isCalendarBackupEnabled && checkCalendarBackupPermission(requireContext()) + binding.calendar.visibility = if (showCalendarBackup) View.VISIBLE else View.GONE + } + + private fun setupCheckListeners() { + binding.dailyBackup.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean -> + if (checkAndAskForContactsReadPermission()) { + setAutomaticBackup(isChecked) + } + } + + initContactsCheckedListener() + binding.contacts.setOnCheckedChangeListener(contactsCheckedListener) + + initCalendarCheckedListener() + binding.calendar.setOnCheckedChangeListener(calendarCheckedListener) + } + + private fun initContactsCheckedListener() { + contactsCheckedListener = + CompoundButton.OnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean -> + if (isChecked) { + if (checkAndAskForContactsReadPermission()) { + isContactsBackupEnabled = true + } + } else { + isContactsBackupEnabled = false + } + setBackupNowButtonVisibility() + setAutomaticBackup(binding.dailyBackup.isChecked) + } + } + + private fun initCalendarCheckedListener() { + calendarCheckedListener = + CompoundButton.OnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean -> + if (isChecked) { + if (checkAndAskForCalendarReadPermission()) { + isCalendarBackupEnabled = true + } + } else { + isCalendarBackupEnabled = false + } + setBackupNowButtonVisibility() + setAutomaticBackup(binding.dailyBackup.isChecked) + } + } + + private fun setBackupNowButtonVisibility() { + binding.backupNow.visibility = + if (binding.contacts.isChecked || binding.calendar.isChecked) View.VISIBLE else View.INVISIBLE + } + + private fun setOnClickListeners() { + binding.backupNow.setOnClickListener { backupNow() } + binding.contactsDatepicker.setOnClickListener { openCleanDate() } + } + + private fun displayLastBackup(contactsPreferenceActivity: ContactsPreferenceActivity) { + val lastBackupTimestamp = user?.let { + arbitraryDataProvider?.getLongValue( + it, + ContactsPreferenceActivity.PREFERENCE_CONTACTS_LAST_BACKUP + ) + } ?: -1L + + if (lastBackupTimestamp == -1L) { + binding.lastBackupWithDate.visibility = View.GONE + } else { + binding.lastBackupWithDate.text = String.format( + getString(R.string.last_backup), + DisplayUtils.getRelativeTimestamp(contactsPreferenceActivity, lastBackupTimestamp) + ) + } + } + + private fun applyUserColorToActionBar(contactsPreferenceActivity: ContactsPreferenceActivity) { + val actionBar = contactsPreferenceActivity.supportActionBar + + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true) + viewThemeUtils?.files?.themeActionBar( + requireContext(), + actionBar, + if (showCalendarBackup) R.string.backup_title else R.string.contact_backup_title + ) + } + } + + private fun setupDates(savedInstanceState: Bundle?) { + if (savedInstanceState != null && savedInstanceState.getBoolean(KEY_CALENDAR_PICKER_OPEN, false)) { + if (savedInstanceState.getInt(KEY_CALENDAR_YEAR, -1) != -1 && savedInstanceState.getInt( + KEY_CALENDAR_MONTH, + -1 + ) != -1 && savedInstanceState.getInt( + KEY_CALENDAR_DAY, -1 + ) != -1 + ) { + val cal = Calendar.getInstance() + cal[Calendar.YEAR] = savedInstanceState.getInt(KEY_CALENDAR_YEAR) + cal[Calendar.MONTH] = savedInstanceState.getInt(KEY_CALENDAR_MONTH) + cal[Calendar.DAY_OF_MONTH] = savedInstanceState.getInt(KEY_CALENDAR_DAY) + selectedDate = cal.time + } + calendarPickerOpen = true + } + } + + private fun applyUserColor() { + viewThemeUtils?.androidx?.colorSwitchCompat(binding.contacts) + viewThemeUtils?.androidx?.colorSwitchCompat(binding.calendar) + viewThemeUtils?.androidx?.colorSwitchCompat(binding.dailyBackup) + + viewThemeUtils?.material?.colorMaterialButtonPrimaryFilled(binding.backupNow) + viewThemeUtils?.material?.colorMaterialButtonPrimaryOutlined(binding.contactsDatepicker) + + viewThemeUtils?.platform?.colorTextView(binding.dataToBackUpTitle) + viewThemeUtils?.platform?.colorTextView(binding.backupSettingsTitle) + } + + override fun onResume() { + super.onResume() + + if (calendarPickerOpen) { + if (selectedDate != null) { + openDate(selectedDate) + } else { + openDate(null) + } + } + + val contactsPreferenceActivity = activity as ContactsPreferenceActivity? + if (contactsPreferenceActivity != null) { + val backupFolderPath = resources.getString(R.string.contacts_backup_folder) + OCFile.PATH_SEPARATOR + refreshBackupFolder( + backupFolderPath, + contactsPreferenceActivity.applicationContext, + contactsPreferenceActivity.storageManager + ) + } + } + + private fun refreshBackupFolder( + backupFolderPath: String, + context: Context, + storageManager: FileDataStorageManager + ) { + val task: AsyncTask = + @SuppressLint("StaticFieldLeak") + object : AsyncTask() { + @Deprecated("Deprecated in Java") + override fun doInBackground(vararg path: String): Boolean { + val folder = storageManager.getFileByPath(path[0]) + return if (folder != null) { + val operation = RefreshFolderOperation( + folder, + System.currentTimeMillis(), + false, + false, + storageManager, + user, + context + ) + val result = operation.execute(user, context) + result.isSuccess + } else { + java.lang.Boolean.FALSE + } + } + + @Deprecated("Deprecated in Java") + override fun onPostExecute(result: Boolean) { + if (result) { + val backupFolder = storageManager.getFileByPath(backupFolderPath) + val backupFiles = storageManager + .getFolderContent(backupFolder, false) + Collections.sort(backupFiles, AlphanumComparator()) + if (backupFiles == null || backupFiles.isEmpty()) { + binding.contactsDatepicker.visibility = View.INVISIBLE + } else { + binding.contactsDatepicker.visibility = View.VISIBLE + } + } + } + } + + task.execute(backupFolderPath) + } + + @Deprecated("Deprecated in Java") + override fun onOptionsItemSelected(item: MenuItem): Boolean { + val contactsPreferenceActivity = activity as ContactsPreferenceActivity? + + val retval: Boolean + when (item.itemId) { + android.R.id.home -> { + if (showSidebar) { + if (contactsPreferenceActivity!!.isDrawerOpen) { + contactsPreferenceActivity.closeDrawer() + } else { + contactsPreferenceActivity.openDrawer() + } + } else if (activity != null) { + requireActivity().finish() + } else { + val settingsIntent = Intent(context, SettingsActivity::class.java) + settingsIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP + startActivity(settingsIntent) + } + retval = true + } + + else -> retval = super.onOptionsItemSelected(item) + } + return retval + } + + @Deprecated("Deprecated in Java") + @Suppress("NestedBlockDepth") + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + + if (requestCode == PermissionUtil.PERMISSIONS_READ_CONTACTS_AUTOMATIC) { + for (index in permissions.indices) { + if (Manifest.permission.READ_CONTACTS.equals(permissions[index], ignoreCase = true)) { + if (grantResults[index] >= 0) { + // if approved, exit for loop + isContactsBackupEnabled = true + break + } + + // if not accepted, disable again + binding.contacts.setOnCheckedChangeListener(null) + binding.contacts.isChecked = false + binding.contacts.setOnCheckedChangeListener(contactsCheckedListener) + } + } + } + if (requestCode == PermissionUtil.PERMISSIONS_READ_CALENDAR_AUTOMATIC) { + var readGranted = false + var writeGranted = false + for (index in permissions.indices) { + if (Manifest.permission.WRITE_CALENDAR.equals( + permissions[index], + ignoreCase = true + ) && grantResults[index] >= 0 + ) { + writeGranted = true + } else if (Manifest.permission.READ_CALENDAR.equals( + permissions[index], + ignoreCase = true + ) && grantResults[index] >= 0 + ) { + readGranted = true + } + } + if (!readGranted || !writeGranted) { + // if not accepted, disable again + binding.calendar.setOnCheckedChangeListener(null) + binding.calendar.isChecked = false + binding.calendar.setOnCheckedChangeListener(calendarCheckedListener) + } else { + isCalendarBackupEnabled = true + } + } + setBackupNowButtonVisibility() + setAutomaticBackup(binding.dailyBackup.isChecked) + } + + private fun backupNow() { + if (isContactsBackupEnabled && checkContactBackupPermission()) { + startContactsBackupJob() + } + if (showCalendarBackup && isCalendarBackupEnabled && checkCalendarBackupPermission(requireContext())) { + startCalendarBackupJob() + } + DisplayUtils.showSnackMessage( + requireView().findViewById(R.id.contacts_linear_layout), + R.string.contacts_preferences_backup_scheduled + ) + } + + private fun startContactsBackupJob() { + val activity = activity as ContactsPreferenceActivity? + if (activity != null) { + val optionalUser = activity.user + if (optionalUser.isPresent) { + backgroundJobManager!!.startImmediateContactsBackup(optionalUser.get()) + } + } + } + + private fun startCalendarBackupJob() { + val activity = activity as ContactsPreferenceActivity? + if (activity != null) { + val optionalUser = activity.user + if (optionalUser.isPresent) { + backgroundJobManager!!.startImmediateCalendarBackup(optionalUser.get()) + } + } + } + + private fun setAutomaticBackup(enabled: Boolean) { + val activity = activity as ContactsPreferenceActivity? ?: return + val optionalUser = activity.user + if (!optionalUser.isPresent) { + return + } + val user = optionalUser.get() + if (enabled) { + if (isContactsBackupEnabled) { + Log_OC.d(TAG, "Scheduling contacts backup job") + backgroundJobManager?.schedulePeriodicContactsBackup(user) + } else { + Log_OC.d(TAG, "Cancelling contacts backup job") + backgroundJobManager?.cancelPeriodicContactsBackup(user) + } + if (isCalendarBackupEnabled) { + Log_OC.d(TAG, "Scheduling calendar backup job") + backgroundJobManager?.schedulePeriodicCalendarBackup(user) + } else { + Log_OC.d(TAG, "Cancelling calendar backup job") + backgroundJobManager?.cancelPeriodicCalendarBackup(user) + } + } else { + Log_OC.d(TAG, "Cancelling all backup jobs") + backgroundJobManager?.cancelPeriodicContactsBackup(user) + backgroundJobManager?.cancelPeriodicCalendarBackup(user) + } + arbitraryDataProvider?.storeOrUpdateKeyValue( + user.accountName, + ContactsPreferenceActivity.PREFERENCE_CONTACTS_AUTOMATIC_BACKUP, + enabled.toString() + ) + } + + private fun checkAndAskForContactsReadPermission(): Boolean { + val contactsPreferenceActivity = activity as ContactsPreferenceActivity? + + // check permissions + return if (checkSelfPermission(contactsPreferenceActivity!!, Manifest.permission.READ_CONTACTS)) { + true + } else { + // No explanation needed, request the permission. + requestPermissions( + arrayOf(Manifest.permission.READ_CONTACTS), + PermissionUtil.PERMISSIONS_READ_CONTACTS_AUTOMATIC + ) + false + } + } + + private fun checkAndAskForCalendarReadPermission(): Boolean { + val contactsPreferenceActivity = activity as ContactsPreferenceActivity? + + // check permissions + return if (contactsPreferenceActivity?.let { checkCalendarBackupPermission(it) } == true) { + true + } else { + // No explanation needed, request the permission. + requestPermissions( + arrayOf( + Manifest.permission.READ_CALENDAR, + Manifest.permission.WRITE_CALENDAR + ), + PermissionUtil.PERMISSIONS_READ_CALENDAR_AUTOMATIC + ) + false + } + } + + private fun checkCalendarBackupPermission(context: Context): Boolean { + return checkSelfPermission(requireContext(), Manifest.permission.READ_CALENDAR) && checkSelfPermission( + context, Manifest.permission.WRITE_CALENDAR + ) + } + + private fun checkContactBackupPermission(): Boolean { + return checkSelfPermission(requireContext(), Manifest.permission.READ_CONTACTS) + } + + private fun openCleanDate() { + if (checkAndAskForCalendarReadPermission() && checkAndAskForContactsReadPermission()) { + openDate(null) + } + } + + private fun openDate(savedDate: Date?) { + val contactsPreferenceActivity = activity as ContactsPreferenceActivity? + if (contactsPreferenceActivity == null) { + Toast.makeText(context, getString(R.string.error_choosing_date), Toast.LENGTH_LONG).show() + return + } + + val contactsBackupFolderString = resources.getString(R.string.contacts_backup_folder) + OCFile.PATH_SEPARATOR + val calendarBackupFolderString = resources.getString(R.string.calendar_backup_folder) + OCFile.PATH_SEPARATOR + val storageManager = contactsPreferenceActivity.storageManager + val contactsBackupFolder = storageManager.getFileByDecryptedRemotePath(contactsBackupFolderString) + val calendarBackupFolder = storageManager.getFileByDecryptedRemotePath(calendarBackupFolderString) + + val backupFiles = storageManager.getFolderContent(contactsBackupFolder, false) + backupFiles.addAll(storageManager.getFolderContent(calendarBackupFolder, false)) + backupFiles.sortWith { o1: OCFile?, o2: OCFile? -> + if (o1 != null && o2 != null) { + o1.modificationTimestamp.compareTo(o2.modificationTimestamp) + } else { + -1 + } + } + + val cal = Calendar.getInstance() + val year: Int + val month: Int + val day: Int + if (savedDate == null) { + year = cal[Calendar.YEAR] + month = cal[Calendar.MONTH] + 1 + day = cal[Calendar.DAY_OF_MONTH] + } else { + year = savedDate.year + month = savedDate.month + day = savedDate.day + } + if (backupFiles.size > 0 && backupFiles[backupFiles.size - 1] != null) { + datePickerDialog = DatePickerDialog(contactsPreferenceActivity, this, year, month, day) + datePickerDialog?.datePicker?.maxDate = backupFiles[backupFiles.size - 1]!! + .modificationTimestamp + datePickerDialog?.datePicker?.minDate = backupFiles[0]!!.modificationTimestamp + datePickerDialog?.setOnDismissListener { selectedDate = null } + datePickerDialog?.setTitle("") + datePickerDialog?.show() + + viewThemeUtils?.platform?.colorTextButtons( + datePickerDialog!!.getButton(DatePickerDialog.BUTTON_NEGATIVE), + datePickerDialog!!.getButton(DatePickerDialog.BUTTON_POSITIVE) + ) + + // set background to transparent + datePickerDialog?.getButton(DatePickerDialog.BUTTON_NEGATIVE)?.setBackgroundColor(0x00000000) + datePickerDialog?.getButton(DatePickerDialog.BUTTON_POSITIVE)?.setBackgroundColor(0x00000000) + } else { + DisplayUtils.showSnackMessage( + requireView().findViewById(R.id.contacts_linear_layout), + R.string.contacts_preferences_something_strange_happened + ) + } + } + + override fun onStop() { + super.onStop() + + datePickerDialog?.dismiss() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + + datePickerDialog?.let { + outState.putBoolean(KEY_CALENDAR_PICKER_OPEN, it.isShowing) + + if (it.isShowing) { + outState.putInt(KEY_CALENDAR_DAY, it.datePicker.dayOfMonth) + outState.putInt(KEY_CALENDAR_MONTH, it.datePicker.month) + outState.putInt(KEY_CALENDAR_YEAR, it.datePicker.year) + } + } + } + + @Suppress("TooGenericExceptionCaught", "NestedBlockDepth", "ComplexMethod", "LongMethod", "MagicNumber") + override fun onDateSet(view: DatePicker, year: Int, month: Int, dayOfMonth: Int) { + val contactsPreferenceActivity = activity as ContactsPreferenceActivity? + if (contactsPreferenceActivity == null) { + Toast.makeText(context, getString(R.string.error_choosing_date), Toast.LENGTH_LONG).show() + return + } + + selectedDate = Date(year, month, dayOfMonth) + val contactsBackupFolderString = resources.getString(R.string.contacts_backup_folder) + OCFile.PATH_SEPARATOR + val calendarBackupFolderString = resources.getString(R.string.calendar_backup_folder) + OCFile.PATH_SEPARATOR + val storageManager = contactsPreferenceActivity.storageManager + val contactsBackupFolder = storageManager.getFileByDecryptedRemotePath(contactsBackupFolderString) + val calendarBackupFolder = storageManager.getFileByDecryptedRemotePath(calendarBackupFolderString) + val backupFiles = storageManager.getFolderContent(contactsBackupFolder, false) + backupFiles.addAll(storageManager.getFolderContent(calendarBackupFolder, false)) + + // find file with modification with date and time between 00:00 and 23:59 + // if more than one file exists, take oldest + val date = Calendar.getInstance() + date[year, month] = dayOfMonth + + // start + date[Calendar.HOUR] = 0 + date[Calendar.MINUTE] = 0 + date[Calendar.SECOND] = 1 + date[Calendar.MILLISECOND] = 0 + date[Calendar.AM_PM] = Calendar.AM + val start = date.timeInMillis + + // end + date[Calendar.HOUR] = 23 + date[Calendar.MINUTE] = 59 + date[Calendar.SECOND] = 59 + val end = date.timeInMillis + var contactsBackupToRestore: OCFile? = null + val calendarBackupsToRestore: MutableList = ArrayList() + for (file in backupFiles) { + if (start < file.modificationTimestamp && end > file.modificationTimestamp) { + // contact + if (MimeTypeUtil.isVCard(file)) { + if (contactsBackupToRestore == null) { + contactsBackupToRestore = file + } else if (contactsBackupToRestore.modificationTimestamp < file.modificationTimestamp) { + contactsBackupToRestore = file + } + } + + // calendars + if (showCalendarBackup && MimeTypeUtil.isCalendar(file)) { + calendarBackupsToRestore.add(file) + } + } + } + val backupToRestore: MutableList = ArrayList() + if (contactsBackupToRestore != null) { + backupToRestore.add(contactsBackupToRestore) + } + backupToRestore.addAll(calendarBackupsToRestore) + if (backupToRestore.isEmpty()) { + DisplayUtils.showSnackMessage( + requireView().findViewById(R.id.contacts_linear_layout), + R.string.contacts_preferences_no_file_found + ) + } else { + val user = contactsPreferenceActivity.user.orElseThrow { RuntimeException() } + val files: Array = arrayOfNulls(backupToRestore.size) + + val contactListFragment = BackupListFragment.newInstance(files, user) + + contactsPreferenceActivity.supportFragmentManager.beginTransaction() + .replace(R.id.frame_container, contactListFragment, BackupListFragment.TAG) + .addToBackStack(ContactsPreferenceActivity.BACKUP_TO_LIST) + .commit() + } + } + + companion object { + val TAG = BackupFragment::class.java.simpleName + private const val ARG_SHOW_SIDEBAR = "SHOW_SIDEBAR" + private const val KEY_CALENDAR_PICKER_OPEN = "IS_CALENDAR_PICKER_OPEN" + private const val KEY_CALENDAR_DAY = "CALENDAR_DAY" + private const val KEY_CALENDAR_MONTH = "CALENDAR_MONTH" + private const val KEY_CALENDAR_YEAR = "CALENDAR_YEAR" + const val PREFERENCE_CONTACTS_BACKUP_ENABLED = "PREFERENCE_CONTACTS_BACKUP_ENABLED" + const val PREFERENCE_CALENDAR_BACKUP_ENABLED = "PREFERENCE_CALENDAR_BACKUP_ENABLED" + + @JvmStatic + fun create(showSidebar: Boolean): BackupFragment { + val fragment = BackupFragment() + val bundle = Bundle() + bundle.putBoolean(ARG_SHOW_SIDEBAR, showSidebar) + fragment.arguments = bundle + return fragment + } + } +} diff --git a/app/src/main/res/layout/backup_fragment.xml b/app/src/main/res/layout/backup_fragment.xml index d5b873b8878f..a8467ef4c1d5 100644 --- a/app/src/main/res/layout/backup_fragment.xml +++ b/app/src/main/res/layout/backup_fragment.xml @@ -17,8 +17,8 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . --> - - - - + android:textSize="@dimen/two_line_primary_text_size" /> - - - - + android:gravity="end" + android:orientation="horizontal"> + android:theme="@style/Widget.Material3.Button.IconButton.Filled" /> diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 9cba7d9ff1af..b78e6fd7ba7f 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -660,6 +660,7 @@ Đặt mật khẩu Mật khẩu được bảo vệ Có thể chỉnh sửa + Thả file Chỉ xem Quyền kho %1$s (từ xa) diff --git a/app/src/main/res/values/dims.xml b/app/src/main/res/values/dims.xml index 1cccbde91496..2b389cefa22c 100644 --- a/app/src/main/res/values/dims.xml +++ b/app/src/main/res/values/dims.xml @@ -132,6 +132,8 @@ 16sp 18sp 24dp + 160dp + 4 12dp 50dp diff --git a/scripts/analysis/lint-results.txt b/scripts/analysis/lint-results.txt index 31824795b1a7..2c0dfa2b0d8a 100644 --- a/scripts/analysis/lint-results.txt +++ b/scripts/analysis/lint-results.txt @@ -1,2 +1,2 @@ DO NOT TOUCH; GENERATED BY DRONE - Lint Report: 80 warnings + Lint Report: 79 warnings