From d2f79f902f1dd98696691abeba4a0914bd6c190e Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Thu, 17 Sep 2020 13:26:03 +1000 Subject: [PATCH] Move files & strings --- res/values/strings.xml | 3 ++- .../thoughtcrime/securesms/backup/BackupDialog.java | 3 +-- .../securesms/backup/FullBackupExporter.java | 7 +++---- .../securesms/database/DatabaseFactory.java | 1 + .../database/helpers/SQLCipherOpenHelper.java | 4 ++-- .../thoughtcrime/securesms/jobs/LocalBackupJob.java | 2 +- .../model => loki/database}/BackupFileRecord.kt | 4 ++-- .../{ => loki}/database/LokiBackupFilesDatabase.kt | 7 +++---- .../preferences/ChatsPreferenceFragment.java | 9 +++------ src/org/thoughtcrime/securesms/util/BackupUtil.kt | 3 +-- .../thoughtcrime/securesms/util/BackupUtilOld.java | 11 ++--------- .../thoughtcrime/securesms/util/ContextProvider.kt | 2 ++ 12 files changed, 23 insertions(+), 33 deletions(-) rename src/org/thoughtcrime/securesms/{database/model => loki/database}/BackupFileRecord.kt (64%) rename src/org/thoughtcrime/securesms/{ => loki}/database/LokiBackupFilesDatabase.kt (94%) diff --git a/res/values/strings.xml b/res/values/strings.xml index d801f1dfa7..98298e8f98 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1499,7 +1499,6 @@ Disable and delete all local backups? Delete backups Copied to clipboard - Failed to activate backups. Please try again or contact support. Session requires external storage permission in order to create backups, but it has been permanently denied. Please continue to app settings, select \"Permissions\" and enable \"Storage\". Last backup: %s In progress @@ -1867,4 +1866,6 @@ Voice Message Details + Failed to activate backups. Please try again or contact support. + diff --git a/src/org/thoughtcrime/securesms/backup/BackupDialog.java b/src/org/thoughtcrime/securesms/backup/BackupDialog.java index c7ca55ad35..177e75e1dd 100644 --- a/src/org/thoughtcrime/securesms/backup/BackupDialog.java +++ b/src/org/thoughtcrime/securesms/backup/BackupDialog.java @@ -1,6 +1,5 @@ package org.thoughtcrime.securesms.backup; - import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -51,7 +50,7 @@ public class BackupDialog { } catch (IOException e) { Log.e(TAG, "Failed to activate backups.", e); Toast.makeText(context, - context.getString(R.string.BackupDialog_activation_error), + context.getString(R.string.dialog_backup_activation_failed), Toast.LENGTH_LONG) .show(); return; diff --git a/src/org/thoughtcrime/securesms/backup/FullBackupExporter.java b/src/org/thoughtcrime/securesms/backup/FullBackupExporter.java index 8d361b89c9..a7f1fb1582 100644 --- a/src/org/thoughtcrime/securesms/backup/FullBackupExporter.java +++ b/src/org/thoughtcrime/securesms/backup/FullBackupExporter.java @@ -1,14 +1,13 @@ package org.thoughtcrime.securesms.backup; - import android.content.Context; import android.database.Cursor; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - import android.net.Uri; import android.text.TextUtils; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.annimon.stream.function.Consumer; import com.annimon.stream.function.Predicate; import com.google.protobuf.ByteString; diff --git a/src/org/thoughtcrime/securesms/database/DatabaseFactory.java b/src/org/thoughtcrime/securesms/database/DatabaseFactory.java index de065a819b..3df26109b8 100644 --- a/src/org/thoughtcrime/securesms/database/DatabaseFactory.java +++ b/src/org/thoughtcrime/securesms/database/DatabaseFactory.java @@ -32,6 +32,7 @@ import org.thoughtcrime.securesms.database.helpers.ClassicOpenHelper; import org.thoughtcrime.securesms.database.helpers.SQLCipherMigrationHelper; import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper; import org.thoughtcrime.securesms.loki.database.LokiAPIDatabase; +import org.thoughtcrime.securesms.loki.database.LokiBackupFilesDatabase; import org.thoughtcrime.securesms.loki.database.LokiMessageDatabase; import org.thoughtcrime.securesms.loki.database.LokiPreKeyBundleDatabase; import org.thoughtcrime.securesms.loki.database.LokiPreKeyRecordDatabase; diff --git a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java index 9e105f45a3..21ddb9f1a0 100644 --- a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java +++ b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java @@ -24,7 +24,7 @@ import org.thoughtcrime.securesms.database.GroupDatabase; import org.thoughtcrime.securesms.database.GroupReceiptDatabase; import org.thoughtcrime.securesms.database.IdentityDatabase; import org.thoughtcrime.securesms.database.JobDatabase; -import org.thoughtcrime.securesms.database.LokiBackupFilesDatabase; +import org.thoughtcrime.securesms.loki.database.LokiBackupFilesDatabase; import org.thoughtcrime.securesms.database.MmsDatabase; import org.thoughtcrime.securesms.database.OneTimePreKeyDatabase; import org.thoughtcrime.securesms.database.PushDatabase; @@ -92,7 +92,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper { private static final int lokiV13 = 34; private static final int lokiV14_BACKUP_FILES = 35; - private static final int DATABASE_VERSION = lokiV14_BACKUP_FILES; // Loki - onUpgrade(...) must be updated to use Loki version numbers if Session makes any database changes + private static final int DATABASE_VERSION = lokiV14_BACKUP_FILES; // Loki - onUpgrade(...) must be updated to use Loki version numbers if Signal makes any database changes private static final String DATABASE_NAME = "signal.db"; private final Context context; diff --git a/src/org/thoughtcrime/securesms/jobs/LocalBackupJob.java b/src/org/thoughtcrime/securesms/jobs/LocalBackupJob.java index 938a7ebffd..3e378a1fb5 100644 --- a/src/org/thoughtcrime/securesms/jobs/LocalBackupJob.java +++ b/src/org/thoughtcrime/securesms/jobs/LocalBackupJob.java @@ -4,7 +4,7 @@ package org.thoughtcrime.securesms.jobs; import androidx.annotation.NonNull; import org.thoughtcrime.securesms.database.NoExternalStorageException; -import org.thoughtcrime.securesms.database.model.BackupFileRecord; +import org.thoughtcrime.securesms.loki.database.BackupFileRecord; import org.thoughtcrime.securesms.jobmanager.Data; import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.logging.Log; diff --git a/src/org/thoughtcrime/securesms/database/model/BackupFileRecord.kt b/src/org/thoughtcrime/securesms/loki/database/BackupFileRecord.kt similarity index 64% rename from src/org/thoughtcrime/securesms/database/model/BackupFileRecord.kt rename to src/org/thoughtcrime/securesms/loki/database/BackupFileRecord.kt index 83948d3530..0d3fc63bcf 100644 --- a/src/org/thoughtcrime/securesms/database/model/BackupFileRecord.kt +++ b/src/org/thoughtcrime/securesms/loki/database/BackupFileRecord.kt @@ -1,4 +1,4 @@ -package org.thoughtcrime.securesms.database.model +package org.thoughtcrime.securesms.loki.database import android.net.Uri import java.util.* @@ -8,5 +8,5 @@ import java.util.* */ data class BackupFileRecord(val id: Long, val uri: Uri, val fileSize: Long, val timestamp: Date) { - constructor(uri: Uri, fileSize: Long, timestamp: Date): this(-1, uri, fileSize, timestamp) + constructor(uri: Uri, fileSize: Long, timestamp: Date) : this(-1, uri, fileSize, timestamp) } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/database/LokiBackupFilesDatabase.kt b/src/org/thoughtcrime/securesms/loki/database/LokiBackupFilesDatabase.kt similarity index 94% rename from src/org/thoughtcrime/securesms/database/LokiBackupFilesDatabase.kt rename to src/org/thoughtcrime/securesms/loki/database/LokiBackupFilesDatabase.kt index d68b61a6f1..65ed0cc8bd 100644 --- a/src/org/thoughtcrime/securesms/database/LokiBackupFilesDatabase.kt +++ b/src/org/thoughtcrime/securesms/loki/database/LokiBackupFilesDatabase.kt @@ -1,12 +1,11 @@ -package org.thoughtcrime.securesms.database +package org.thoughtcrime.securesms.loki.database import android.content.ContentValues import android.content.Context import android.database.Cursor import android.net.Uri -import androidx.annotation.NonNull +import org.thoughtcrime.securesms.database.Database import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper -import org.thoughtcrime.securesms.database.model.BackupFileRecord import java.lang.IllegalArgumentException import java.util.* import kotlin.collections.ArrayList @@ -15,7 +14,7 @@ import kotlin.collections.ArrayList * Keeps track of the backup files saved by the app. * Uses [BackupFileRecord] as an entry data projection. */ -class LokiBackupFilesDatabase(context: Context?, databaseHelper: SQLCipherOpenHelper?) +class LokiBackupFilesDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Database(context, databaseHelper) { companion object { diff --git a/src/org/thoughtcrime/securesms/preferences/ChatsPreferenceFragment.java b/src/org/thoughtcrime/securesms/preferences/ChatsPreferenceFragment.java index 5d12ab3eb9..53e9b5078e 100644 --- a/src/org/thoughtcrime/securesms/preferences/ChatsPreferenceFragment.java +++ b/src/org/thoughtcrime/securesms/preferences/ChatsPreferenceFragment.java @@ -1,6 +1,5 @@ package org.thoughtcrime.securesms.preferences; -import android.Manifest; import android.annotation.SuppressLint; import android.content.Context; import android.content.DialogInterface; @@ -27,7 +26,6 @@ import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.preferences.widgets.ProgressPreference; import org.thoughtcrime.securesms.util.BackupDirSelector; import org.thoughtcrime.securesms.util.BackupUtil; -import org.thoughtcrime.securesms.util.FragmentContextProvider; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.Trimmer; @@ -120,9 +118,8 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment { } private void setBackupSummary() { - findPreference(TextSecurePreferences.BACKUP_NOW).setSummary( - String.format(getString(R.string.ChatsPreferenceFragment_last_backup_s), - BackupUtil.getLastBackupTimeString(getContext(), Locale.getDefault()))); + findPreference(TextSecurePreferences.BACKUP_NOW) + .setSummary(String.format(getString(R.string.ChatsPreferenceFragment_last_backup_s), BackupUtil.getLastBackupTimeString(getContext(), Locale.getDefault()))); } private void setMediaDownloadSummaries() { @@ -152,7 +149,7 @@ public class ChatsPreferenceFragment extends ListSummaryPreferenceFragment { private class BackupClickListener implements Preference.OnPreferenceClickListener { @Override public boolean onPreferenceClick(Preference preference) { - if (!((SwitchPreferenceCompat)preference).isChecked()) { + if (!((SwitchPreferenceCompat) preference).isChecked()) { BackupDialog.showEnableBackupDialog(getActivity(), (SwitchPreferenceCompat)preference, backupDirSelector); } else { BackupDialog.showDisableBackupDialog(getActivity(), (SwitchPreferenceCompat)preference); diff --git a/src/org/thoughtcrime/securesms/util/BackupUtil.kt b/src/org/thoughtcrime/securesms/util/BackupUtil.kt index 894a70087d..0454bab3f6 100644 --- a/src/org/thoughtcrime/securesms/util/BackupUtil.kt +++ b/src/org/thoughtcrime/securesms/util/BackupUtil.kt @@ -17,11 +17,10 @@ import org.thoughtcrime.securesms.backup.BackupPassphrase import org.thoughtcrime.securesms.backup.FullBackupExporter import org.thoughtcrime.securesms.crypto.AttachmentSecretProvider import org.thoughtcrime.securesms.database.DatabaseFactory -import org.thoughtcrime.securesms.database.model.BackupFileRecord +import org.thoughtcrime.securesms.loki.database.BackupFileRecord import org.thoughtcrime.securesms.service.LocalBackupListener import org.whispersystems.libsignal.util.ByteUtil import java.io.IOException -import java.lang.IllegalStateException import java.security.SecureRandom import java.text.SimpleDateFormat import java.util.* diff --git a/src/org/thoughtcrime/securesms/util/BackupUtilOld.java b/src/org/thoughtcrime/securesms/util/BackupUtilOld.java index 31aad6b8bd..4f4cb92374 100644 --- a/src/org/thoughtcrime/securesms/util/BackupUtilOld.java +++ b/src/org/thoughtcrime/securesms/util/BackupUtilOld.java @@ -2,21 +2,14 @@ package org.thoughtcrime.securesms.util; import android.content.Context; -import androidx.annotation.NonNull; + import androidx.annotation.Nullable; -import org.thoughtcrime.securesms.database.model.BackupFileRecord; -import org.thoughtcrime.securesms.logging.Log; +import org.thoughtcrime.securesms.loki.database.BackupFileRecord; -import network.loki.messenger.R; import org.thoughtcrime.securesms.database.NoExternalStorageException; -import org.whispersystems.libsignal.util.ByteUtil; import java.io.File; -import java.security.SecureRandom; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Locale; //TODO AC: Delete this class when its functionality is // fully replaced by the BackupUtil.kt and related classes. diff --git a/src/org/thoughtcrime/securesms/util/ContextProvider.kt b/src/org/thoughtcrime/securesms/util/ContextProvider.kt index 60b02e9a95..4bc8e104dd 100644 --- a/src/org/thoughtcrime/securesms/util/ContextProvider.kt +++ b/src/org/thoughtcrime/securesms/util/ContextProvider.kt @@ -15,6 +15,7 @@ interface ContextProvider { } class ActivityContextProvider(private val activity: Activity): ContextProvider { + override fun getContext(): Context { return activity } @@ -25,6 +26,7 @@ class ActivityContextProvider(private val activity: Activity): ContextProvider { } class FragmentContextProvider(private val fragment: Fragment): ContextProvider { + override fun getContext(): Context { return fragment.requireContext() }