Skip to content

Commit

Permalink
Update bounty code so that it doesn't reference money or track wether…
Browse files Browse the repository at this point in the history
… the bounty has been 'fulfilled'.
  • Loading branch information
davkutalek committed Jan 1, 2024
1 parent 41cf2cf commit 44a3b5c
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ class BountyRepositoryImpl(
private fun generateChannelBounties(channels: List<Channel>, bounties: List<Bounty>): List<ChannelBounties> {
if (channels.isEmpty() || bounties.isEmpty()) return emptyList()

val openBounties = bounties.filter { it.action.bounty_is_open || it.transactionCount != 0 }
// val openBounties = bounties.filter { it.action.bounty_is_open || it.transactionCount != 0 }

val channelBounties = channels.filter { c ->
openBounties.any { it.action.channel_id == c.id }
bounties.any { it.action.channel_id == c.id }
}.map { channel ->
ChannelBounties(channel, openBounties.filter { it.action.channel_id == channel.id })
ChannelBounties(channel, bounties.filter { it.action.channel_id == channel.id })
}

return channelBounties
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/hover/stax/home/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class MainActivity : AbstractGoogleAuthActivity(), BiometricChecker.AuthListener
checkForRequest(intent)
checkForFragmentDirection(intent)
observeForAppReview()
setGoogleLoginInterface(this)
}

override fun onNewIntent(intent: Intent?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright 2022 Stax
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ import timber.log.Timber

const val FORCED_VERSION = "force_update_app_version"

abstract class AbstractGoogleAuthActivity :
AppCompatActivity(),
StaxGoogleLoginInterface {
abstract class AbstractGoogleAuthActivity : AppCompatActivity() {

private val loginViewModel: LoginViewModel by viewModel()
private lateinit var staxGoogleLoginInterface: StaxGoogleLoginInterface

private lateinit var updateManager: AppUpdateManager
private var installListener: InstallStateUpdatedListener? = null
Expand Down Expand Up @@ -78,10 +75,6 @@ abstract class AbstractGoogleAuthActivity :
}
}

fun setGoogleLoginInterface(staxGoogleLoginInterface: StaxGoogleLoginInterface) {
this.staxGoogleLoginInterface = staxGoogleLoginInterface
}

private fun initGoogleAuth() {
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.google_server_client_id)).requestEmail().build()
Expand All @@ -90,11 +83,11 @@ abstract class AbstractGoogleAuthActivity :

private fun setLoginObserver() = with(loginViewModel) {
error.observe(this@AbstractGoogleAuthActivity) {
it?.let { staxGoogleLoginInterface.googleLoginFailed() }
it?.let { googleLoginFailed() }
}

googleUser.observe(this@AbstractGoogleAuthActivity) {
it?.let { staxGoogleLoginInterface.googleLoginSuccessful() }
it?.let { googleLoginSuccessful() }
}
}

Expand All @@ -106,7 +99,7 @@ abstract class AbstractGoogleAuthActivity :
loginViewModel.signIntoGoogle(result.data)
} else {
Timber.e("Google sign in failed")
staxGoogleLoginInterface.googleLoginFailed()
googleLoginFailed()
}
}

Expand Down Expand Up @@ -185,11 +178,11 @@ abstract class AbstractGoogleAuthActivity :
}
}

override fun googleLoginSuccessful() {
private fun googleLoginSuccessful() {
if (loginViewModel.staxUser.value?.isMapper == true) BountyApplicationFragmentDirections.actionBountyApplicationFragmentToBountyListFragment()
}

override fun googleLoginFailed() {
private fun googleLoginFailed() {
UIHelper.flashAndReportMessage(this, R.string.login_google_err)
}

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/hover/stax/login/LoginViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ class LoginViewModel(
val account = task.getResult(ApiException::class.java)!!
setUser(account, account.idToken!!)
} catch (e: ApiException) {
Timber.e(e, "Google sign in failed")
Timber.e(e, e.message)
onError((getApplication() as Context).getString(R.string.login_google_err))
}
}

private fun loginUser(token: String, signInAccount: GoogleSignInAccount) =
viewModelScope.launch {
Timber.e("logging in...")
try {
val authorization = authRepository.authorizeClient(token)
val response = authRepository.fetchTokenInfo(authorization.redirectUri.code)
Expand Down Expand Up @@ -110,7 +111,7 @@ class LoginViewModel(
_loginState.value = LoginScreenUiState(LoginUiState.Success)
}
} catch (e: Exception) {
Timber.e("Login failed $e")
Timber.e(e, "Login failed ${e.message}")
_loginState.value = LoginScreenUiState(LoginUiState.Error)
}
}
Expand Down
21 changes: 0 additions & 21 deletions app/src/main/java/com/hover/stax/login/StaxGoogleLoginInterface.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class OnBoardingActivity : AbstractGoogleAuthActivity() {

setupNavigation()
navigateNextScreen()
setGoogleLoginInterface(this)
}

private fun setupNavigation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class BountyApplicationFragment : Fragment(), View.OnClickListener {
super.onViewCreated(view, savedInstanceState)

binding.progressIndicator.setVisibilityAfterHide(View.GONE)
binding.instructions.apply {
text = HtmlCompat.fromHtml(getString(R.string.bounty_email_stage_desc2), HtmlCompat.FROM_HTML_MODE_LEGACY)
movementMethod = LinkMovementMethod.getInstance()
}
// binding.instructions.apply {
// text = HtmlCompat.fromHtml(getString(R.string.bounty_email_stage_desc2), HtmlCompat.FROM_HTML_MODE_LEGACY)
// movementMethod = LinkMovementMethod.getInstance()
// }

startObservers()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ class BountyListFragment : Fragment() {
.setDialogTitle(
getString(
R.string.bounty_claim_title, b.action.root_code,
HoverAction.getHumanFriendlyType(requireContext(), b.action.transaction_type), b.action.bounty_amount
HoverAction.getHumanFriendlyType(requireContext(), b.action.transaction_type)
)
)
.setDialogMessage(getString(R.string.bounty_claim_explained, b.action.bounty_amount, b.getInstructions(requireActivity())))
.setDialogMessage(getString(R.string.bounty_claim_explained, b.getInstructions(requireActivity())))
.setPosButton(R.string.start_USSD_Flow) { startBounty(b) }
dialog!!.showIt()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ fun BountyLi(bounty: Bounty, bountyViewModel: BountyViewModel) {
style = if (isOpen(bounty)) MaterialTheme.typography.body1 else strikeThrough
)

Text(
text = stringResource(R.string.bounty_amount_with_currency, bounty.action.bounty_amount),
modifier = Modifier
.padding(top = margin8, bottom = margin8),
style = if (isOpen(bounty)) MaterialTheme.typography.body1 else strikeThrough,
fontWeight = FontWeight.Medium
)
// Text(
// text = stringResource(R.string.bounty_amount_with_currency, bounty.action.bounty_amount),
// modifier = Modifier
// .padding(top = margin8, bottom = margin8),
// style = if (isOpen(bounty)) MaterialTheme.typography.body1 else strikeThrough,
// fontWeight = FontWeight.Medium
// )
}

if (getMsg(bounty) != 0)
Expand All @@ -97,55 +97,58 @@ fun BountyLi(bounty: Bounty, bountyViewModel: BountyViewModel) {

private fun getColor(bounty: Bounty): Int {
return when {
bounty.hasSuccessfulTransactions() -> R.color.muted_green
bounty.isLastTransactionFailed() -> R.color.stax_bounty_red_bg
!bounty.action.bounty_is_open -> R.color.lighter_grey
bounty.transactionCount > 0 -> R.color.pending_brown
// bounty.hasSuccessfulTransactions() -> R.color.muted_green
// bounty.isLastTransactionFailed() -> R.color.stax_bounty_red_bg
// !bounty.action.bounty_is_open -> R.color.lighter_grey
// bounty.transactionCount > 0 -> R.color.pending_brown
else -> R.color.colorSurface
}
}

private fun getMsg(bounty: Bounty): Int {
return when {
bounty.hasSuccessfulTransactions() -> R.string.done
bounty.isLastTransactionFailed() && !bounty.action.bounty_is_open -> R.string.bounty_transaction_failed
bounty.isLastTransactionFailed() && bounty.action.bounty_is_open -> R.string.bounty_transaction_failed_try_again
bounty.transactionCount > 0 -> R.string.bounty_pending_short_desc
else -> 0
}
return 0
// return when {
// bounty.hasSuccessfulTransactions() -> R.string.done
// bounty.isLastTransactionFailed() && !bounty.action.bounty_is_open -> R.string.bounty_transaction_failed
// bounty.isLastTransactionFailed() && bounty.action.bounty_is_open -> R.string.bounty_transaction_failed_try_again
// bounty.transactionCount > 0 -> R.string.bounty_pending_short_desc
// else -> 0
// }
}

private fun getIcon(bounty: Bounty): Int {
return when {
bounty.hasSuccessfulTransactions() -> R.drawable.ic_check
bounty.isLastTransactionFailed() -> R.drawable.ic_error
bounty.transactionCount > 0 -> R.drawable.ic_warning
else -> 0
}
return 0
// return when {
// bounty.hasSuccessfulTransactions() -> R.drawable.ic_check
// bounty.isLastTransactionFailed() -> R.drawable.ic_error
// bounty.transactionCount > 0 -> R.drawable.ic_warning
// else -> 0
// }
}

private fun isOpen(bounty: Bounty): Boolean {
return when {
bounty.hasSuccessfulTransactions() -> false
bounty.isLastTransactionFailed() && !bounty.action.bounty_is_open -> false
bounty.isLastTransactionFailed() && bounty.action.bounty_is_open -> true
!bounty.action.bounty_is_open -> false
bounty.transactionCount > 0 -> true
else -> true
}
return true
// return when {
// bounty.hasSuccessfulTransactions() -> false
// bounty.isLastTransactionFailed() && !bounty.action.bounty_is_open -> false
// bounty.isLastTransactionFailed() && bounty.action.bounty_is_open -> true
// !bounty.action.bounty_is_open -> false
// bounty.transactionCount > 0 -> true
// else -> true
// }
}

private fun getTapAction(bounty: Bounty): BountySelectEvent? {
return when {
bounty.hasSuccessfulTransactions() ->
BountySelectEvent.ViewTransactionDetail(bounty.transactions.last().uuid)
bounty.isLastTransactionFailed() && !bounty.action.bounty_is_open ->
BountySelectEvent.ViewTransactionDetail(bounty.transactions.last().uuid)
bounty.isLastTransactionFailed() && bounty.action.bounty_is_open ->
BountySelectEvent.ViewBountyDetail(bounty)
!bounty.action.bounty_is_open -> null
bounty.transactionCount > 0 ->
BountySelectEvent.ViewTransactionDetail(bounty.transactions.last().uuid)
// bounty.hasSuccessfulTransactions() ->
// BountySelectEvent.ViewTransactionDetail(bounty.transactions.last().uuid)
// bounty.isLastTransactionFailed() && !bounty.action.bounty_is_open ->
// BountySelectEvent.ViewTransactionDetail(bounty.transactions.last().uuid)
// bounty.isLastTransactionFailed() && bounty.action.bounty_is_open ->
// BountySelectEvent.ViewBountyDetail(bounty)
// !bounty.action.bounty_is_open -> null
// bounty.transactionCount > 0 ->
// BountySelectEvent.ViewTransactionDetail(bounty.transactions.last().uuid)
else -> BountySelectEvent.ViewBountyDetail(bounty)
}
}
Expand Down Expand Up @@ -174,13 +177,13 @@ fun BountyCardPreview() {
style = MaterialTheme.typography.body1
)

Text(
text = "USD $1",
modifier = Modifier
.padding(top = margin8, bottom = margin8),
style = MaterialTheme.typography.body1,
fontWeight = FontWeight.Medium
)
// Text(
// text = "USD $1",
// modifier = Modifier
// .padding(top = margin8, bottom = margin8),
// style = MaterialTheme.typography.body1,
// fontWeight = FontWeight.Medium
// )
}

SpannableImageTextView(
Expand Down
26 changes: 13 additions & 13 deletions app/src/main/res/layout/fragment_bounty_application.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/instructions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_16"
android:lineSpacingExtra="1.5dp"
android:layout_marginHorizontal="@dimen/margin_16"
android:text="@string/bounty_email_stage_desc2"
android:textSize="@dimen/text_16"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/intro" />
<!-- <TextView-->
<!-- android:id="@+id/instructions"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginTop="@dimen/margin_16"-->
<!-- android:lineSpacingExtra="1.5dp"-->
<!-- android:layout_marginHorizontal="@dimen/margin_16"-->
<!-- android:text="@string/bounty_email_stage_desc2"-->
<!-- android:textSize="@dimen/text_16"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toBottomOf="@id/intro" />-->

<TextView
android:id="@+id/signedInDetails"
Expand All @@ -66,7 +66,7 @@
android:textAllCaps="false"
app:layout_constraintBottom_toTopOf="@id/progressIndicator"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/instructions" />
app:layout_constraintTop_toBottomOf="@id/intro" />

<LinearLayout
android:id="@+id/btnSignIn"
Expand All @@ -80,7 +80,7 @@
android:padding="@dimen/margin_13"
app:layout_constraintBottom_toTopOf="@id/progressIndicator"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/instructions">
app:layout_constraintTop_toBottomOf="@id/intro">

<ImageView
android:layout_width="@dimen/margin_24"
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/values-am/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,7 @@

<string name="available_flows">ሊገኙ የሚችሉ ፍሰቶች</string>

<string name="bounty_claim_title">%1$s - %2$s - $%3$d</string>

<string name="bounty_claim_explained">$ %1$d ዶላር ለመጠየቅ ፣ %2$s።\n\nልክ እንደጨረሱ ለክፍያ መረጃ ለመሰብሰብ ኢሜይል እንልክልዎታለን። በ1-5 የሥራ ቀናት ውስጥ ይከፈልዎታል </string>
<string name="bounty_claim_title">%1$s - %2$s</string>

<string name="bounty_error_none">ምንም ጉርሻዎች የሉም። እባክዎ ቆይተው እንደገና ያረጋግጡ።</string>

Expand Down
Loading

0 comments on commit 44a3b5c

Please sign in to comment.