Skip to content

Commit 21cafbf

Browse files
committed
Some logic of initializing the view
1 parent ba393e8 commit 21cafbf

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

app/src/main/java/org/wikipedia/donate/DonorHistoryActivity.kt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,56 @@ package org.wikipedia.donate
33
import android.content.Context
44
import android.content.Intent
55
import android.os.Bundle
6+
import androidx.activity.viewModels
7+
import androidx.core.view.isVisible
68
import org.wikipedia.Constants
9+
import org.wikipedia.R
710
import org.wikipedia.activity.BaseActivity
811
import org.wikipedia.databinding.ActivityDonorHistoryBinding
12+
import org.wikipedia.settings.Prefs
13+
import org.wikipedia.util.ResourceUtil
14+
import kotlin.getValue
915

1016
class DonorHistoryActivity : BaseActivity() {
1117

1218
private lateinit var binding: ActivityDonorHistoryBinding
19+
private val viewModel: DonorHistoryViewModel by viewModels { DonorHistoryViewModel.Factory(intent.extras!!) }
20+
1321

1422
override fun onCreate(savedInstanceState: Bundle?) {
1523
super.onCreate(savedInstanceState)
1624
binding = ActivityDonorHistoryBinding.inflate(layoutInflater)
1725
}
1826

27+
private fun init() {
28+
29+
binding.donationInfoContainer.isVisible = viewModel.isDonor
30+
31+
var donorStatusTextColor = R.attr.primary_color
32+
val donorStatusText = if (!Prefs.hasDonorHistorySaved) {
33+
donorStatusTextColor = R.attr.placeholder_color
34+
R.string.donor_history_update_donor_status_default
35+
} else if (viewModel.isDonor) {
36+
R.string.donor_history_update_donor_status_donor
37+
} else {
38+
R.string.donor_history_update_donor_status_not_a_donor
39+
}
40+
binding.donorStatus.text = getString(donorStatusText)
41+
binding.donorStatus.setTextColor(ResourceUtil.getThemedColorStateList(this, donorStatusTextColor))
42+
43+
var lastDonatedTextColor = R.attr.primary_color
44+
val lastDonatedText = if (viewModel.lastDonated == null) {
45+
lastDonatedTextColor = R.attr.placeholder_color
46+
R.string.donor_history_last_donated_hint
47+
} else {
48+
R.string.donor_history_last_donated
49+
}
50+
binding.lastDonationLabel.text = getString(lastDonatedText)
51+
binding.donorStatus.setTextColor(ResourceUtil.getThemedColorStateList(this, lastDonatedTextColor))
52+
53+
binding.recurringDonorCheckbox.isChecked = viewModel.isRecurringDonor
54+
}
55+
1956
companion object {
2057
fun newIntent(context: Context, completedDonation: Boolean = false): Intent {
2158
return Intent(context, DonorHistoryActivity::class.java)

app/src/main/java/org/wikipedia/donate/DonorHistoryViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class DonorHistoryViewModel(bundle: Bundle) : ViewModel() {
1818
}
1919

2020
var completedDonation = bundle.getBoolean(Constants.ARG_BOOLEAN)
21-
var isDonor = Prefs.hasDonorHistorySaved && Prefs.donationResults.isNotEmpty()
22-
var lastDonated = Prefs.donationResults.last().dateTime
21+
var isDonor = completedDonation || (Prefs.hasDonorHistorySaved && Prefs.donationResults.isNotEmpty())
22+
var lastDonated = Prefs.donationResults.lastOrNull()?.dateTime
2323
var isRecurringDonor = Prefs.isRecurringDonor
2424

2525
private val _uiState = MutableStateFlow(Resource<List<RbDefinition.Usage>>())

app/src/main/res/layout/activity_donor_history.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
android:layout_marginStart="16dp">
8585

8686
<TextView
87-
android:id="@+id/recurringLabel"
87+
android:id="@+id/recurringDonorLabel"
8888
style="@style/P"
8989
android:layout_width="0dp"
9090
android:layout_height="wrap_content"
@@ -97,7 +97,7 @@
9797
app:drawableTint="?attr/primary_color"/>
9898

9999
<com.google.android.material.checkbox.MaterialCheckBox
100-
android:id="@+id/recurringCheckbox"
100+
android:id="@+id/recurringDonorCheckbox"
101101
android:layout_width="wrap_content"
102102
android:layout_height="wrap_content"/>
103103

0 commit comments

Comments
 (0)