[Backup] Code Cleanup
This commit is contained in:
parent
4af4771cfe
commit
48da7dced3
4 changed files with 17 additions and 40 deletions
|
@ -21,7 +21,7 @@ class BackupAdapter(
|
|||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
LayoutInflater.from(activity).inflate(R.layout.item_list_card, parent, false)
|
||||
LayoutInflater.from(activity).inflate(R.layout.item_list_backup, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ class BackupViewModel : ViewModel() {
|
|||
|
||||
suspend fun restoreBackup(activity: Activity, inputStream: InputStream?, contents: List<BackupContent>) {
|
||||
BackupHelper.restoreBackup(activity, inputStream, contents)
|
||||
if (contents.contains(BackupContent.SETTINGS)) {
|
||||
withContext(Dispatchers.Main) {
|
||||
val intent = Intent(
|
||||
activity,
|
||||
|
@ -39,3 +40,4 @@ class BackupViewModel : ViewModel() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -144,7 +144,6 @@ object BackupHelper {
|
|||
restorePreferences(context, it, entry)
|
||||
} else if (entry.isImageEntry() && contents.contains(USER_IMAGES)) {
|
||||
restoreImages(context, it, entry)
|
||||
|
||||
} else if (entry.isCustomArtistImageEntry() && contents.contains(
|
||||
CUSTOM_ARTIST_IMAGES
|
||||
)
|
||||
|
@ -168,11 +167,7 @@ object BackupHelper {
|
|||
val filePath =
|
||||
context.filesDir.path + File.separator + zipEntry.getFileName()
|
||||
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
||||
val bytesIn = ByteArray(DEFAULT_BUFFER_SIZE)
|
||||
var read: Int
|
||||
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
||||
bos.write(bytesIn, 0, read)
|
||||
}
|
||||
zipIn.copyTo(bos)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,11 +179,7 @@ object BackupHelper {
|
|||
file.delete()
|
||||
}
|
||||
BufferedOutputStream(FileOutputStream(file)).use { bos ->
|
||||
val bytesIn = ByteArray(DEFAULT_BUFFER_SIZE)
|
||||
var read: Int
|
||||
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
||||
bos.write(bytesIn, 0, read)
|
||||
}
|
||||
zipIn.copyTo(bos)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,11 +187,7 @@ object BackupHelper {
|
|||
val filePath =
|
||||
context.filesDir.parent!! + File.separator + DATABASES_PATH + File.separator + zipEntry.getFileName()
|
||||
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
||||
val bytesIn = ByteArray(DEFAULT_BUFFER_SIZE)
|
||||
var read: Int
|
||||
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
||||
bos.write(bytesIn, 0, read)
|
||||
}
|
||||
zipIn.copyTo(bos)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,11 +198,7 @@ object BackupHelper {
|
|||
val filePath =
|
||||
context.filesDir.parent!! + File.separator + DATABASES_PATH + File.separator + zipEntry.getFileName()
|
||||
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
||||
val bytesIn = ByteArray(DEFAULT_BUFFER_SIZE)
|
||||
var read: Int
|
||||
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
||||
bos.write(bytesIn, 0, read)
|
||||
}
|
||||
zipIn.copyTo(bos)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,11 +220,7 @@ object BackupHelper {
|
|||
)
|
||||
)
|
||||
).use { bos ->
|
||||
val bytesIn = ByteArray(DEFAULT_BUFFER_SIZE)
|
||||
var read: Int
|
||||
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
||||
bos.write(bytesIn, 0, read)
|
||||
}
|
||||
zipIn.copyTo(bos)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,11 +232,7 @@ object BackupHelper {
|
|||
val filePath =
|
||||
context.filesDir.parentFile?.absolutePath + "/shared_prefs/" + zipEntry.getFileName()
|
||||
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
||||
val bytesIn = ByteArray(DEFAULT_BUFFER_SIZE)
|
||||
var read: Int
|
||||
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
||||
bos.write(bytesIn, 0, read)
|
||||
}
|
||||
zipIn.copyTo(bos)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@
|
|||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/title"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:src="@drawable/ic_restore"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
Loading…
Add table
Add a link
Reference in a new issue