-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from anilibria/feature/GHP-41537911-history-e…
…xport [GHP-41537911] feat: add support opening history file
- Loading branch information
Showing
28 changed files
with
392 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...mobile/src/main/java/ru/radiationx/anilibria/ui/fragments/history/HistoryFileViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ru.radiationx.anilibria.ui.fragments.history | ||
|
||
import android.net.Uri | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.launch | ||
import ru.radiationx.anilibria.ui.common.ErrorHandler | ||
import ru.radiationx.anilibria.utils.messages.SystemMessenger | ||
import ru.radiationx.data.historyfile.HistoryFileRepository | ||
import ru.radiationx.shared.ktx.coRunCatching | ||
import ru.radiationx.shared_app.common.SystemUtils | ||
import toothpick.InjectConstructor | ||
|
||
@InjectConstructor | ||
class HistoryFileViewModel( | ||
private val historyFileRepository: HistoryFileRepository, | ||
private val systemUtils: SystemUtils, | ||
private val errorHandler: ErrorHandler, | ||
private val systemMessenger: SystemMessenger, | ||
) : ViewModel() { | ||
|
||
fun onExportClick() { | ||
viewModelScope.launch { | ||
coRunCatching { | ||
historyFileRepository.exportFile() | ||
}.onSuccess { | ||
systemUtils.shareLocalFile(it) | ||
}.onFailure { | ||
errorHandler.handle(it) | ||
} | ||
} | ||
} | ||
|
||
fun onImportFileSelected(uri: Uri) { | ||
viewModelScope.launch { | ||
coRunCatching { | ||
historyFileRepository.importFile(uri) | ||
}.onSuccess { | ||
systemMessenger.showMessage("История успешно импортирована") | ||
}.onFailure { | ||
errorHandler.handle(it) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.