Loading data/src/main/java/com/moez/QKSMS/repository/BackupRepositoryImpl.kt +7 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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" } Loading Loading @@ -151,7 +153,10 @@ class BackupRepositoryImpl @Inject constructor( override fun getBackupProgress(): Observable<BackupRepository.Progress> = backupProgress override fun getBackups(): Observable<List<BackupFile>> = QkFileObserver(BACKUP_DIRECTORY).observable override fun getBackups(): Observable<List<BackupFile>> { 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()) Loading @@ -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 Loading data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt +10 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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<Message> { FileUtils.moveDir(File(OLD_MEDIA_DIRECTORY), File(MEDIA_DIRECTORY)) return Realm.getDefaultInstance() .where(Message::class.java) .equalTo("threadId", threadId) Loading Loading @@ -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 Loading data/src/main/java/com/moez/QKSMS/util/FileUtils.kt 0 → 100644 +30 −0 Original line number Diff line number Diff line /* * 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 <https://www.gnu.org/licenses/>. */ 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() } } } presentation/src/main/java/com/moez/QKSMS/common/util/FileLoggingTree.kt +3 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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") Loading Loading
data/src/main/java/com/moez/QKSMS/repository/BackupRepositoryImpl.kt +7 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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" } Loading Loading @@ -151,7 +153,10 @@ class BackupRepositoryImpl @Inject constructor( override fun getBackupProgress(): Observable<BackupRepository.Progress> = backupProgress override fun getBackups(): Observable<List<BackupFile>> = QkFileObserver(BACKUP_DIRECTORY).observable override fun getBackups(): Observable<List<BackupFile>> { 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()) Loading @@ -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 Loading
data/src/main/java/com/moez/QKSMS/repository/MessageRepositoryImpl.kt +10 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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<Message> { FileUtils.moveDir(File(OLD_MEDIA_DIRECTORY), File(MEDIA_DIRECTORY)) return Realm.getDefaultInstance() .where(Message::class.java) .equalTo("threadId", threadId) Loading Loading @@ -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 Loading
data/src/main/java/com/moez/QKSMS/util/FileUtils.kt 0 → 100644 +30 −0 Original line number Diff line number Diff line /* * 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 <https://www.gnu.org/licenses/>. */ 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() } } }
presentation/src/main/java/com/moez/QKSMS/common/util/FileLoggingTree.kt +3 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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") Loading