Skip to content

Commit

Permalink
Merge pull request #1993 from Hafizzle/Fiz/initial-class-selection-co…
Browse files Browse the repository at this point in the history
…st-gem-fix

Initial Class Selection sometimes costing gems fix
  • Loading branch information
phillipthelen committed Jun 23, 2023
2 parents 06cadb2 + 3970c0f commit 540c918
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ class FullProfileActivity : BaseActivity() {

binding.avatarWithBars.setContent {
HabiticaTheme {
AppHeaderView(member.value, isMyProfile = isMyProfile()) {
}
AppHeaderView(member.value, isMyProfile = isMyProfile(), onMemberRowClicked = {}, onClassSelectionClicked = {})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
}
}

private val classSelectionResult =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
lifecycleScope.launch(ExceptionHandler.coroutine()) {
userRepository.retrieveUser(true, true)
}
}

val isAppBarExpanded: Boolean
get() = binding.content.appbar.height - binding.content.appbar.bottom == 0

Expand Down Expand Up @@ -265,19 +272,38 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
binding.content.headerView.setContent {
HabiticaTheme {
val user by viewModel.user.observeAsState(null)
val teamPlan by viewModel.userViewModel.currentTeamPlan.collectAsStateLifecycleAware(null)
val teamPlan by viewModel.userViewModel.currentTeamPlan.collectAsStateLifecycleAware(
null
)
val teamPlanMembers by viewModel.userViewModel.currentTeamPlanMembers.observeAsState()
val canShowTeamHeader: Boolean by viewModel.canShowTeamPlanHeader
AppHeaderView(user, teamPlan = if (canShowTeamHeader) teamPlan else null, teamPlanMembers = teamPlanMembers) {
showAsBottomSheet { onClose ->
val group by viewModel.userViewModel.currentTeamPlanGroup.collectAsState(null)
val members by viewModel.userViewModel.currentTeamPlanMembers.observeAsState()
GroupPlanMemberList(members, group) {
onClose()
FullProfileActivity.open(it)
AppHeaderView(
user,
teamPlan = if (canShowTeamHeader) teamPlan else null,
teamPlanMembers = teamPlanMembers,
onMemberRowClicked = {
showAsBottomSheet { onClose ->
val group by viewModel.userViewModel.currentTeamPlanGroup.collectAsState(
null
)
val members by viewModel.userViewModel.currentTeamPlanMembers.observeAsState()
GroupPlanMemberList(members, group) {
onClose()
FullProfileActivity.open(it)
}

}
},
onClassSelectionClicked = {
val bundle = Bundle()
bundle.putBoolean("isInitialSelection", user?.flags?.classSelected == false)
val intent = Intent(this@MainActivity, ClassSelectionActivity::class.java)
intent.putExtras(bundle)
classSelectionResult.launch(
intent
)
}
}
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ fun AppHeaderView(
teamPlan : TeamPlan? = null,
teamPlanMembers : List<Member>? = null,
onMemberRowClicked : () -> Unit,
onClassSelectionClicked: () -> Unit
) {
Column(modifier) {
Row {
Expand Down Expand Up @@ -181,7 +182,7 @@ fun AppHeaderView(
background = HabiticaTheme.colors.basicButtonColor(),
color = MaterialTheme.colors.onPrimary,
onClick = {
MainNavigationController.navigate(R.id.classSelectionActivity)
onClassSelectionClicked()
},
contentPadding = PaddingValues(0.dp),
fontSize = 14.sp,
Expand Down Expand Up @@ -397,8 +398,9 @@ private fun Preview(@PreviewParameter(UserProvider::class) data: Pair<User, Team
teamPlan = data.second,
modifier = Modifier
.background(HabiticaTheme.colors.contentBackground)
.padding(8.dp)
) {
}
.padding(8.dp),
onMemberRowClicked = { },
onClassSelectionClicked = { }
)
}
}

0 comments on commit 540c918

Please sign in to comment.