Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Compose RepoDetailActivity #57

Merged
merged 26 commits into from
Mar 17, 2022
Merged

Compose RepoDetailActivity #57

merged 26 commits into from
Mar 17, 2022

Conversation

Goooler
Copy link
Owner

@Goooler Goooler commented Mar 16, 2022

Comment on lines 8 to 9
@GET("https://api.github.com/repos/{owner}/{repo}")
suspend fun getRepoDetail(@Path("owner") owner: String, @Path("repo") repo: String)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Goooler Goooler added this to the 1.6.0 milestone Mar 16, 2022
Comment on lines 80 to 90
Button(onClick = {
"All ${model.starsCount} stars".showToast()
}) {
Icon(
Icons.Filled.Star,
contentDescription = "Star",
modifier = Modifier.size(ButtonDefaults.IconSize)
)
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
Text(model.starsCount.toString())
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +43 to +45
SwipeRefresh(state = rememberSwipeRefreshState(isRefreshing), onRefresh = onRefresh) {
DetailPage(model, onForkClick)
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +18 to +21
intent.getStringExtra(FULL_NAME)?.let {
vm.fullName = it
vm.refresh()
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must refresh manually for the first time.

@Goooler Goooler merged commit 2e08d99 into trunk Mar 17, 2022
@Goooler Goooler deleted the repo_detail branch March 17, 2022 07:21
Comment on lines +13 to +46
class DetailViewModel : BaseViewModel() {

private val repository = DetailRepository(RetrofitHelper.create())
private var repoDetail = RepoDetailModel()
private val _repoDetailModel = MutableLiveData(repoDetail)

lateinit var fullName: String
val repoDetailModel: LiveData<RepoDetailModel> = _repoDetailModel
val isRefreshing: MutableBooleanLiveData = MutableBooleanLiveData()

fun refresh() {
isRefreshing.value = true
viewModelScope.launch {
repository.getRepoDetail(fullName).let {
repoDetail = RepoDetailModel(
it.fullName,
it.description.orEmpty(),
it.license?.name.orEmpty(),
it.starsCount,
it.forksCount,
it.openIssuesCount
)
}
_repoDetailModel.value = repoDetail
isRefreshing.value = false
}
}

fun fork() {
repoDetail = repoDetail.copy()
repoDetail.forksCount++
_repoDetailModel.value = repoDetail
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Goooler Goooler mentioned this pull request Mar 23, 2022
Goooler added a commit that referenced this pull request Apr 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant