Fixed backups not visible

This commit is contained in:
Prathamesh More 2021-10-11 11:47:12 +05:30
parent c5c4144973
commit 6ff3eb2e2a
4 changed files with 14 additions and 20 deletions

View file

@ -58,11 +58,10 @@ class BackupFragment : Fragment(R.layout.fragment_backup), BackupAdapter.BackupC
}
private fun checkIsEmpty() {
binding.emptyText.setText(R.string.no_backups_found)
(backupAdapter!!.itemCount == 0).run {
binding.empty.isVisible = this
binding.backupTitle.isVisible = this
}
val isEmpty = backupAdapter!!.itemCount == 0
binding.empty.isVisible = isEmpty
binding.backupTitle.isVisible = !isEmpty
binding.backupRecyclerview.isVisible = !isEmpty
}
fun setupRecyclerview() {

View file

@ -2,12 +2,11 @@ package code.name.monkey.retromusic.fragments.backup
import android.app.Activity
import android.content.Intent
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import code.name.monkey.retromusic.helper.BackupHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import kotlin.system.exitProcess
@ -15,17 +14,15 @@ import kotlin.system.exitProcess
class BackupViewModel : ViewModel() {
private val backupsMutableLiveData = MutableLiveData<List<File>>()
val backupsLiveData = backupsMutableLiveData
val backupsLiveData: LiveData<List<File>> = backupsMutableLiveData
fun loadBackups() {
viewModelScope.launch {
File(BackupHelper.backupRootPath).listFiles { file, _ ->
return@listFiles file.extension == BackupHelper.BACKUP_EXTENSION
File(BackupHelper.backupRootPath).listFiles { _, name ->
return@listFiles name.endsWith(BackupHelper.BACKUP_EXTENSION)
}?.toList()?.let {
backupsMutableLiveData.value = it
}
}
}
suspend fun restoreBackup(activity: Activity, file: File) {
BackupHelper.restoreBackup(activity, file)

View file

@ -123,7 +123,7 @@ object BackupHelper {
val backupRootPath =
Environment.getExternalStorageDirectory().toString() + "/RetroMusic/Backups/"
const val BACKUP_EXTENSION = "zip"
const val BACKUP_EXTENSION = "rmbak"
private const val APPEND_EXTENSION = ".$BACKUP_EXTENSION"
private const val DATABASES_PATH = "databases"
private const val SETTINGS_PATH = "prefs"

View file

@ -55,9 +55,8 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/backup_recyclerview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/backup_title" />
@ -66,14 +65,13 @@
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@+id/create_backup"
tools:visibility="visible">
<com.google.android.material.textview.MaterialTextView
@ -89,7 +87,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/empty"
android:text="@string/no_backups_found"
android:textAppearance="@style/TextViewHeadline5"
android:textColor="?android:attr/textColorSecondary"
tools:visibility="visible" />