Skip to content

Commit

Permalink
Merge pull request #12 from TinasheMzondiwa/develop
Browse files Browse the repository at this point in the history
3.0.1 Update
  • Loading branch information
TinasheMzondiwa authored Jul 5, 2020
2 parents 8e8a4a9 + 1f281c7 commit 56d7038
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/semver.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
major=3
minor=0
patch=0
build=5
patch=1
build=0
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RemoteHymnsRepository(
Resource.success(data)
} catch (ex: Exception) {
Timber.e(ex)
Resource.error(ex)
Resource.success(listOf(defaultHymnal))
}
}

Expand Down Expand Up @@ -102,13 +102,19 @@ class RemoteHymnsRepository(
private fun createFile(code: String): File = File.createTempFile(code, FILE_SUFFIX)

private fun parseJson(jsonString: String): List<RemoteHymn>? {
val listDataType: Type = Types.newParameterizedType(List::class.java, RemoteHymn::class.java)
val listDataType: Type =
Types.newParameterizedType(List::class.java, RemoteHymn::class.java)
val adapter: JsonAdapter<List<RemoteHymn>> = moshi.adapter(listDataType)
return adapter.fromJson(jsonString)
}

companion object {
private const val FOLDER = "cis"
private const val FILE_SUFFIX = "json"
private val defaultHymnal = RemoteHymnal(
"english",
"Christ In Song",
"English"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class SupportFragment : Fragment() {
setHasOptionsMenu(true)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return FragmentSupportBinding.inflate(inflater, container, false).also {
binding = it
binding?.apply {
Expand Down Expand Up @@ -72,6 +76,12 @@ class SupportFragment : Fragment() {
launchWebUrl(it)
}
viewModel.inAppProductsLiveData.observeNonNull(viewLifecycleOwner) { products ->
if (products.isEmpty()) {
binding?.tvOneTimeDonation?.setText(R.string.error_un_available)
return@observeNonNull
} else {
binding?.tvOneTimeDonation?.setText(R.string.one_tine_donation)
}
binding?.chipGroupInApp?.apply {
removeAllViews()
products.forEach { product ->
Expand All @@ -97,6 +107,12 @@ class SupportFragment : Fragment() {
}
}
viewModel.subscriptionsLiveData.observeNonNull(viewLifecycleOwner) { subs ->
if (subs.isEmpty()) {
binding?.tvMonthlyDonation?.setText(R.string.blank)
return@observeNonNull
} else {
binding?.tvOneTimeDonation?.setText(R.string.monthly_donations)
}
binding?.chipGroupSubs?.apply {
removeAllViews()
subs.forEach { product ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ class SupportViewModel @ViewModelInject constructor() :

viewModelScope.launch(Dispatchers.IO) {
val result = billingClient?.querySkuDetails(params)
if (result?.billingResult?.responseCode == BillingClient.BillingResponseCode.OK) {
mutableInAppProducts.postValue(result.skuDetailsList?.sortedBy { it.priceAmountMicros })
val products = if (result?.billingResult?.responseCode == BillingClient.BillingResponseCode.OK) {
result.skuDetailsList?.sortedBy { it.priceAmountMicros }
} else {
Timber.e(result?.billingResult?.debugMessage)
emptyList()
}
mutableInAppProducts.postValue(products)
}
}

Expand All @@ -133,11 +135,13 @@ class SupportViewModel @ViewModelInject constructor() :

viewModelScope.launch(Dispatchers.IO) {
val result = billingClient?.querySkuDetails(params)
if (result?.billingResult?.responseCode == BillingClient.BillingResponseCode.OK) {
mutableSubscriptions.postValue(result.skuDetailsList)
val subs = if (result?.billingResult?.responseCode == BillingClient.BillingResponseCode.OK) {
result.skuDetailsList
} else {
Timber.e(result?.billingResult?.debugMessage)
emptyList()
}
mutableSubscriptions.postValue(subs)
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/fragment_support.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
android:paddingVertical="@dimen/spacing_medium">

<TextView
android:id="@+id/tvOneTimeDonation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/spacing_medium"
Expand Down Expand Up @@ -90,6 +91,7 @@
android:paddingVertical="@dimen/spacing_medium">

<TextView
android:id="@+id/tvMonthlyDonation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/spacing_medium"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="error_invalid_content">Invalid content</string>
<string name="error_invalid_number">Hymn %1$d is unavailable</string>
<string name="error_item_already_owned">You have already purchased this item.\nPlease select a different amount.</string>
<string name="error_un_available">Unavailable</string>
<string name="full_screen">Fullscreen</string>
<string name="hint_description">Description (Optional)</string>
<string name="hint_title">Title</string>
Expand Down

0 comments on commit 56d7038

Please sign in to comment.