Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e12c7c22 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Message: Move previous data to new dir

parent 4ff79e6c
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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<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())
@@ -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
+10 −1
Original line number Diff line number Diff line
@@ -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<Message> {
        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
+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()
        }
    }

}
+3 −0
Original line number Diff line number Diff line
@@ -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")