Skip to content

Commit

Permalink
Configured retry button in FilesFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
itszechs committed Jun 21, 2022
1 parent 65fad07 commit 950422c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/src/main/java/zechs/drive/stream/ui/files/FilesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,14 @@ class FilesFragment : BaseFragment() {
}
is Resource.Loading -> {
isLoading = true
if (!viewModel.hasLoaded) {
if (!viewModel.hasLoaded || viewModel.hasFailed) {
isLoading(true)
}
binding.error.root.apply {
if (isVisible) {
isGone = true
}
}
}
}
}
Expand Down Expand Up @@ -186,6 +191,12 @@ class FilesFragment : BaseFragment() {
error.apply {
root.isVisible = true
errorTxt.text = msg ?: getString(R.string.something_went_wrong)
btnRetry.apply {
isVisible = true
setOnClickListener {
viewModel.queryFiles(args.query)
}
}
}
}
isLoading = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class FilesViewModel @Inject constructor(

var hasLoaded = false

var hasFailed = false
private set

var isLastPage = nextPageToken == null
private set

Expand All @@ -57,6 +60,7 @@ class FilesViewModel @Inject constructor(
} else {
getTeamDrives(drive)
}
hasFailed = false
} else {
_filesList.postValue(Resource.Error("Unable to build Drive Service"))
Log.d(TAG, "Unable to build Drive Service")
Expand All @@ -78,6 +82,7 @@ class FilesViewModel @Inject constructor(
_filesList.postValue(Resource.Error(e.message ?: "Something went wrong"))
Log.e(TAG, "Something went wrong", e)
}
hasFailed = true
}

private suspend fun getQuery(drive: Drive, query: String) {
Expand Down

0 comments on commit 950422c

Please sign in to comment.