From 4ff79e6cc109ed21be0114b38db511b359c05ae3 Mon Sep 17 00:00:00 2001 From: althafvly Date: Thu, 17 Nov 2022 12:37:49 +0530 Subject: [PATCH 1/3] Message: Rename main directory to 'Message' --- .../main/java/com/moez/QKSMS/repository/BackupRepositoryImpl.kt | 2 +- .../java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt | 2 +- .../src/main/java/com/moez/QKSMS/common/util/FileLoggingTree.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/src/main/java/com/moez/QKSMS/repository/BackupRepositoryImpl.kt b/data/src/main/java/com/moez/QKSMS/repository/BackupRepositoryImpl.kt index 9fff3db35..bb510044b 100644 --- a/data/src/main/java/com/moez/QKSMS/repository/BackupRepositoryImpl.kt +++ b/data/src/main/java/com/moez/QKSMS/repository/BackupRepositoryImpl.kt @@ -53,7 +53,7 @@ class BackupRepositoryImpl @Inject constructor( ) : BackupRepository { companion object { - private val BACKUP_DIRECTORY = Environment.getExternalStorageDirectory().toString() + "/QKSMS/Backups" + private val BACKUP_DIRECTORY = Environment.getExternalStorageDirectory().toString() + "/Message/Backups" } data class Backup( diff --git a/data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt b/data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt index 7cdddf1d2..ba8d21c32 100644 --- a/data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt +++ b/data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt @@ -172,7 +172,7 @@ class MessageRepositoryImpl @Inject constructor( val extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(part.type) ?: return null val date = part.messages?.first()?.date - val dir = File(Environment.getExternalStorageDirectory(), "QKSMS/Media").apply { mkdirs() } + val dir = File(Environment.getExternalStorageDirectory(), "Message/Media").apply { mkdirs() } val fileName = part.name?.takeIf { name -> name.endsWith(extension) } ?: "${part.type.split("/").last()}_$date.$extension" var file: File diff --git a/presentation/src/main/java/com/moez/QKSMS/common/util/FileLoggingTree.kt b/presentation/src/main/java/com/moez/QKSMS/common/util/FileLoggingTree.kt index aa1dd6322..56358dd1d 100644 --- a/presentation/src/main/java/com/moez/QKSMS/common/util/FileLoggingTree.kt +++ b/presentation/src/main/java/com/moez/QKSMS/common/util/FileLoggingTree.kt @@ -59,7 +59,7 @@ class FileLoggingTree @Inject constructor(private val prefs: Preferences) : Timb synchronized(fileLock) { try { // Create the directory - val dir = File(Environment.getExternalStorageDirectory(), "QKSMS/Logs").apply { mkdirs() } + val dir = File(Environment.getExternalStorageDirectory(), "Message/Logs").apply { mkdirs() } // Create the file val file = File(dir, "${SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(System.currentTimeMillis())}.log") -- GitLab From e12c7c22fb5af4f06ea133f68acd86b397a6912e Mon Sep 17 00:00:00 2001 From: althafvly Date: Thu, 17 Nov 2022 13:00:43 +0530 Subject: [PATCH 2/3] Message: Move previous data to new dir --- .../QKSMS/repository/BackupRepositoryImpl.kt | 8 ++++- .../QKSMS/repository/MessageRepositoryImpl.kt | 11 ++++++- .../java/com/moez/QKSMS/util/FileUtils.kt | 30 +++++++++++++++++++ .../moez/QKSMS/common/util/FileLoggingTree.kt | 3 ++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 data/src/main/java/com/moez/QKSMS/util/FileUtils.kt diff --git a/data/src/main/java/com/moez/QKSMS/repository/BackupRepositoryImpl.kt b/data/src/main/java/com/moez/QKSMS/repository/BackupRepositoryImpl.kt index bb510044b..efa51ad65 100644 --- a/data/src/main/java/com/moez/QKSMS/repository/BackupRepositoryImpl.kt +++ b/data/src/main/java/com/moez/QKSMS/repository/BackupRepositoryImpl.kt @@ -22,6 +22,7 @@ import android.content.Context import android.os.Environment import android.provider.Telephony import androidx.core.content.contentValuesOf +import com.moez.QKSMS.util.FileUtils import com.moez.QKSMS.model.BackupFile import com.moez.QKSMS.model.Message import com.moez.QKSMS.util.Preferences @@ -53,6 +54,7 @@ class BackupRepositoryImpl @Inject constructor( ) : BackupRepository { companion object { + private val OLD_BACKUP_DIRECTORY = Environment.getExternalStorageDirectory().toString() + "/QKSMS/Backups" private val BACKUP_DIRECTORY = Environment.getExternalStorageDirectory().toString() + "/Message/Backups" } @@ -151,7 +153,10 @@ class BackupRepositoryImpl @Inject constructor( override fun getBackupProgress(): Observable = backupProgress - override fun getBackups(): Observable> = QkFileObserver(BACKUP_DIRECTORY).observable + override fun getBackups(): Observable> { + FileUtils.moveDir(File(OLD_BACKUP_DIRECTORY), File(BACKUP_DIRECTORY)) + + return QkFileObserver(BACKUP_DIRECTORY).observable .map { File(BACKUP_DIRECTORY).listFiles() ?: arrayOf() } .subscribeOn(Schedulers.io()) .observeOn(Schedulers.computation()) @@ -170,6 +175,7 @@ class BackupRepositoryImpl @Inject constructor( } } .map { files -> files.sortedByDescending { file -> file.date } } + } override fun performRestore(filePath: String) { // If a backupFile or restore is already running, don't do anything diff --git a/data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt b/data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt index ba8d21c32..7fbd3d536 100644 --- a/data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt +++ b/data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt @@ -46,6 +46,7 @@ import com.moez.QKSMS.compat.TelephonyCompat import com.moez.QKSMS.extensions.anyOf import com.moez.QKSMS.manager.ActiveConversationManager import com.moez.QKSMS.manager.KeyManager +import com.moez.QKSMS.util.FileUtils import com.moez.QKSMS.model.Attachment import com.moez.QKSMS.model.Conversation import com.moez.QKSMS.model.Message @@ -83,7 +84,14 @@ class MessageRepositoryImpl @Inject constructor( private val syncRepository: SyncRepository ) : MessageRepository { + companion object { + private val OLD_MEDIA_DIRECTORY = Environment.getExternalStorageDirectory().toString() + "/QKSMS/Media" + private val MEDIA_DIRECTORY = Environment.getExternalStorageDirectory().toString() + "/Message/Media" + } + override fun getMessages(threadId: Long, query: String): RealmResults { + FileUtils.moveDir(File(OLD_MEDIA_DIRECTORY), File(MEDIA_DIRECTORY)) + return Realm.getDefaultInstance() .where(Message::class.java) .equalTo("threadId", threadId) @@ -172,7 +180,8 @@ class MessageRepositoryImpl @Inject constructor( val extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(part.type) ?: return null val date = part.messages?.first()?.date - val dir = File(Environment.getExternalStorageDirectory(), "Message/Media").apply { mkdirs() } + val dir = File(MEDIA_DIRECTORY).apply { mkdirs() } + val fileName = part.name?.takeIf { name -> name.endsWith(extension) } ?: "${part.type.split("/").last()}_$date.$extension" var file: File diff --git a/data/src/main/java/com/moez/QKSMS/util/FileUtils.kt b/data/src/main/java/com/moez/QKSMS/util/FileUtils.kt new file mode 100644 index 000000000..2ac317f3d --- /dev/null +++ b/data/src/main/java/com/moez/QKSMS/util/FileUtils.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2022 MURENA SAS + * 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 . + */ +package com.moez.QKSMS.util + +import java.io.File + +object FileUtils { + + fun moveDir(oldDir: File, newDir: File) { + if (oldDir.exists() && oldDir.isDirectory) { + newDir.apply { mkdirs() } + oldDir.copyRecursively(newDir) + oldDir.deleteRecursively() + } + } + +} diff --git a/presentation/src/main/java/com/moez/QKSMS/common/util/FileLoggingTree.kt b/presentation/src/main/java/com/moez/QKSMS/common/util/FileLoggingTree.kt index 56358dd1d..8dbdcc2da 100644 --- a/presentation/src/main/java/com/moez/QKSMS/common/util/FileLoggingTree.kt +++ b/presentation/src/main/java/com/moez/QKSMS/common/util/FileLoggingTree.kt @@ -20,6 +20,7 @@ package com.moez.QKSMS.common.util import android.os.Environment import android.util.Log +import com.moez.QKSMS.util.FileUtils import com.moez.QKSMS.util.Preferences import io.reactivex.schedulers.Schedulers import timber.log.Timber @@ -60,6 +61,8 @@ class FileLoggingTree @Inject constructor(private val prefs: Preferences) : Timb try { // Create the directory val dir = File(Environment.getExternalStorageDirectory(), "Message/Logs").apply { mkdirs() } + val oldDir = File(Environment.getExternalStorageDirectory(), "QKSMS/Logs") + FileUtils.moveDir(oldDir, dir) // Create the file val file = File(dir, "${SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(System.currentTimeMillis())}.log") -- GitLab From 01ce3e6aef577bc32139c6827d03e03c55286d8e Mon Sep 17 00:00:00 2001 From: althafvly Date: Thu, 17 Nov 2022 14:21:04 +0530 Subject: [PATCH 3/3] Message: Change 'MESSAGE' strings to 'Message' --- presentation/src/main/res/values/strings.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index abd36c213..7464dd0d5 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -168,7 +168,7 @@ Stop restore Messages that have already been restored will remain on your device Backups - /MESSAGE/Backups + /Message/Backups No backups found No messages @@ -279,8 +279,8 @@ Blocked conversations Blocking Manager - MESSAGE - Built-in blocking functionality in MESSAGE + Message + Built-in blocking functionality in Message Call Blocker - Incoming/Outgoing Block spam messages, numbers & unknown calls with blacklist & Schedule Call Control -- GitLab