[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 {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
return 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>) {
|
suspend fun restoreBackup(activity: Activity, inputStream: InputStream?, contents: List<BackupContent>) {
|
||||||
BackupHelper.restoreBackup(activity, inputStream, contents)
|
BackupHelper.restoreBackup(activity, inputStream, contents)
|
||||||
|
if (contents.contains(BackupContent.SETTINGS)) {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
val intent = Intent(
|
val intent = Intent(
|
||||||
activity,
|
activity,
|
||||||
|
@ -38,4 +39,5 @@ class BackupViewModel : ViewModel() {
|
||||||
exitProcess(0)
|
exitProcess(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -144,7 +144,6 @@ object BackupHelper {
|
||||||
restorePreferences(context, it, entry)
|
restorePreferences(context, it, entry)
|
||||||
} else if (entry.isImageEntry() && contents.contains(USER_IMAGES)) {
|
} else if (entry.isImageEntry() && contents.contains(USER_IMAGES)) {
|
||||||
restoreImages(context, it, entry)
|
restoreImages(context, it, entry)
|
||||||
|
|
||||||
} else if (entry.isCustomArtistImageEntry() && contents.contains(
|
} else if (entry.isCustomArtistImageEntry() && contents.contains(
|
||||||
CUSTOM_ARTIST_IMAGES
|
CUSTOM_ARTIST_IMAGES
|
||||||
)
|
)
|
||||||
|
@ -168,11 +167,7 @@ object BackupHelper {
|
||||||
val filePath =
|
val filePath =
|
||||||
context.filesDir.path + File.separator + zipEntry.getFileName()
|
context.filesDir.path + File.separator + zipEntry.getFileName()
|
||||||
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
||||||
val bytesIn = ByteArray(DEFAULT_BUFFER_SIZE)
|
zipIn.copyTo(bos)
|
||||||
var read: Int
|
|
||||||
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
|
||||||
bos.write(bytesIn, 0, read)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,11 +179,7 @@ object BackupHelper {
|
||||||
file.delete()
|
file.delete()
|
||||||
}
|
}
|
||||||
BufferedOutputStream(FileOutputStream(file)).use { bos ->
|
BufferedOutputStream(FileOutputStream(file)).use { bos ->
|
||||||
val bytesIn = ByteArray(DEFAULT_BUFFER_SIZE)
|
zipIn.copyTo(bos)
|
||||||
var read: Int
|
|
||||||
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
|
||||||
bos.write(bytesIn, 0, read)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,11 +187,7 @@ object BackupHelper {
|
||||||
val filePath =
|
val filePath =
|
||||||
context.filesDir.parent!! + File.separator + DATABASES_PATH + File.separator + zipEntry.getFileName()
|
context.filesDir.parent!! + File.separator + DATABASES_PATH + File.separator + zipEntry.getFileName()
|
||||||
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
||||||
val bytesIn = ByteArray(DEFAULT_BUFFER_SIZE)
|
zipIn.copyTo(bos)
|
||||||
var read: Int
|
|
||||||
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
|
||||||
bos.write(bytesIn, 0, read)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,11 +198,7 @@ object BackupHelper {
|
||||||
val filePath =
|
val filePath =
|
||||||
context.filesDir.parent!! + File.separator + DATABASES_PATH + File.separator + zipEntry.getFileName()
|
context.filesDir.parent!! + File.separator + DATABASES_PATH + File.separator + zipEntry.getFileName()
|
||||||
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
||||||
val bytesIn = ByteArray(DEFAULT_BUFFER_SIZE)
|
zipIn.copyTo(bos)
|
||||||
var read: Int
|
|
||||||
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
|
||||||
bos.write(bytesIn, 0, read)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,11 +220,7 @@ object BackupHelper {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
).use { bos ->
|
).use { bos ->
|
||||||
val bytesIn = ByteArray(DEFAULT_BUFFER_SIZE)
|
zipIn.copyTo(bos)
|
||||||
var read: Int
|
|
||||||
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
|
||||||
bos.write(bytesIn, 0, read)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,11 +232,7 @@ object BackupHelper {
|
||||||
val filePath =
|
val filePath =
|
||||||
context.filesDir.parentFile?.absolutePath + "/shared_prefs/" + zipEntry.getFileName()
|
context.filesDir.parentFile?.absolutePath + "/shared_prefs/" + zipEntry.getFileName()
|
||||||
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
BufferedOutputStream(FileOutputStream(filePath)).use { bos ->
|
||||||
val bytesIn = ByteArray(DEFAULT_BUFFER_SIZE)
|
zipIn.copyTo(bos)
|
||||||
var read: Int
|
|
||||||
while (zipIn.read(bytesIn).also { read = it } != -1) {
|
|
||||||
bos.write(bytesIn, 0, read)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,9 @@
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@id/title"
|
app:layout_constraintEnd_toStartOf="@id/title"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
android:src="@drawable/ic_restore"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
Loading…
Add table
Add a link
Reference in a new issue