Skip to content

Commit

Permalink
Merge branch 'main' into fix-off-center-identity-name
Browse files Browse the repository at this point in the history
  • Loading branch information
orhoj authored Mar 5, 2024
2 parents e55a54c + afc3354 commit 027b765
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Incorrect environment name in a private key export file for Mainnet
- Improper handling of rejected identity verification when setting up a new wallet
- An issue where the identity name was off-center when the edit name icon was visible
- An issue where exporting transaction logs for an account without any transactions would be stuck at 0%

### Changed
- Suggest running a recovery when facing account or identity creation errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class ExportTransactionLogActivity : BaseActivity(
viewModel.onIdleRequested()

hideActionBarBack(isVisible = true) {
viewModel.onIdleRequested()
finish()
}
}
Expand Down Expand Up @@ -86,6 +85,7 @@ class ExportTransactionLogActivity : BaseActivity(

binding.successLayout.isVisible = downloadState is FileDownloadScreenState.Downloaded
binding.failedLayout.isVisible = downloadState is FileDownloadScreenState.Failed
binding.noContentLayout.isVisible = downloadState is FileDownloadScreenState.NoContent

binding.generate.isVisible = downloadState is FileDownloadScreenState.Idle
binding.cancel.isVisible = downloadState is FileDownloadScreenState.Downloading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.ResponseBody
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.http.GET
import retrofit2.http.Streaming
Expand All @@ -31,20 +32,24 @@ import java.util.concurrent.TimeUnit
interface FileDownloadApi {
@Streaming
@GET
suspend fun downloadFile(@Url url: String?): ResponseBody
suspend fun downloadFile(@Url url: String?): Response<ResponseBody>
}

sealed class FileDownloadScreenState {
object Idle : FileDownloadScreenState()
data class Downloading(val progress: Int) : FileDownloadScreenState()
object Failed : FileDownloadScreenState()
object Downloaded : FileDownloadScreenState()
object NoContent : FileDownloadScreenState()
}

class ExportTransactionLogViewModel(application: Application) : AndroidViewModel(application) {
lateinit var account: Account
private lateinit var api: FileDownloadApi

val HTTP_OK = 200
val HTTP_NO_CONTENT = 204

val textResourceInt: MutableLiveData<Int> by lazy { MutableLiveData<Int>() }

private sealed class DownloadState {
Expand Down Expand Up @@ -78,8 +83,17 @@ class ExportTransactionLogViewModel(application: Application) : AndroidViewModel
)
)

api.downloadFile(downloadFile)
.saveFile(destinationFolder)
val response = api.downloadFile(downloadFile)
val statusCode = response.code()
if (statusCode == HTTP_NO_CONTENT) {
this@ExportTransactionLogViewModel.downloadState.postValue(FileDownloadScreenState.NoContent)
return@launch
} else if (statusCode != HTTP_OK || response.body() == null) {
this@ExportTransactionLogViewModel.downloadState.postValue(FileDownloadScreenState.Failed)
return@launch
}

response.body()!!.saveFile(destinationFolder)
.collect { downloadState ->
// Add visual delay and ensure the coroutine is active.
delay(300)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/activity_export_transaction_log.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
style="@style/CryptoX_Container_Error.TextView"
android:text="@string/export_transaction_log_failed" />

<TextView
android:id="@+id/no_content_layout"
style="@style/CryptoX_Container_Information.TextView"
android:text="@string/export_transaction_log_no_content" />

<Space
android:layout_width="0dp"
android:layout_height="20dp" />
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@
<string name="export_transaction_log_cancel">Cancel</string>
<string name="export_transaction_log_saved">The transaction logs have been saved</string>
<string name="export_transaction_log_failed">Failed to download transaction logs</string>
<string name="export_transaction_log_no_content">There are no transaction logs available for this account</string>
<string name="export_transaction_log_progress">%1$d%%</string> <!-- 45% -->
<string name="export_transaction_log_downloading">Downloading transaction logs…</string>

Expand Down

0 comments on commit 027b765

Please sign in to comment.