add subscription status and tier to the AccountFragment
This commit is contained in:
@ -61,6 +61,7 @@ object Crunchyroll {
|
||||
private val tokenRefreshContext = newSingleThreadContext("TokenRefreshContext")
|
||||
|
||||
private var accountID = ""
|
||||
private var externalID = ""
|
||||
|
||||
private var policy = ""
|
||||
private var signature = ""
|
||||
@ -245,6 +246,7 @@ object Crunchyroll {
|
||||
}
|
||||
|
||||
accountID = account.accountId
|
||||
externalID = account.externalId
|
||||
}
|
||||
|
||||
/**
|
||||
@ -704,4 +706,20 @@ object Crunchyroll {
|
||||
requestPatch(profileEndpoint, bodyObject = json)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional profile (benefits) information for the currently logged in account.
|
||||
*
|
||||
* * @return A **[Profile]** object
|
||||
*/
|
||||
suspend fun benefits(): Benefits {
|
||||
val profileEndpoint = "/subs/v1/subscriptions/$externalID/benefits"
|
||||
|
||||
return try {
|
||||
requestGet(profileEndpoint)
|
||||
} catch (ex: SerializationException) {
|
||||
Log.e(TAG, "SerializationException in benefits().", ex)
|
||||
NoneBenefits
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -125,6 +125,7 @@ typealias DiscSeasonList = Collection<SeasonListItem>
|
||||
typealias Watchlist = Collection<Item>
|
||||
typealias ContinueWatchingList = Collection<ContinueWatchingItem>
|
||||
typealias RecommendationsList = Collection<Item>
|
||||
typealias Benefits = Collection<Benefit>
|
||||
|
||||
@Serializable
|
||||
data class UpNextSeriesItem(
|
||||
@ -226,6 +227,7 @@ val NoneSimilarToResult = SimilarToResult(0, emptyList())
|
||||
val NoneDiscSeasonList = DiscSeasonList(0, emptyList())
|
||||
val NoneContinueWatchingList = ContinueWatchingList(0, emptyList())
|
||||
val NoneRecommendationsList = RecommendationsList(0, emptyList())
|
||||
val NoneBenefits = Benefits(0, emptyList())
|
||||
|
||||
val NoneUpNextSeriesItem = UpNextSeriesItem(
|
||||
playhead = 0,
|
||||
@ -412,3 +414,16 @@ val NoneProfile = Profile(
|
||||
preferredContentSubtitleLanguage = "",
|
||||
username = ""
|
||||
)
|
||||
|
||||
/**
|
||||
* benefit data class
|
||||
*/
|
||||
@Serializable
|
||||
data class Benefit(
|
||||
@SerialName("benefit") val benefit: String,
|
||||
@SerialName("source") val source: String,
|
||||
)
|
||||
val NoneBenefit = Benefit(
|
||||
benefit = "",
|
||||
source = ""
|
||||
)
|
||||
|
@ -15,6 +15,7 @@ import kotlinx.coroutines.runBlocking
|
||||
import org.mosad.teapod.BuildConfig
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.databinding.FragmentAccountBinding
|
||||
import org.mosad.teapod.parser.crunchyroll.Benefits
|
||||
import org.mosad.teapod.parser.crunchyroll.Crunchyroll
|
||||
import org.mosad.teapod.parser.crunchyroll.Profile
|
||||
import org.mosad.teapod.parser.crunchyroll.supportedLocals
|
||||
@ -33,6 +34,9 @@ class AccountFragment : Fragment() {
|
||||
private var profile: Deferred<Profile> = lifecycleScope.async {
|
||||
Crunchyroll.profile()
|
||||
}
|
||||
private var benefits: Deferred<Benefits> = lifecycleScope.async {
|
||||
Crunchyroll.benefits()
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
binding = FragmentAccountBinding.inflate(inflater, container, false)
|
||||
@ -44,14 +48,18 @@ class AccountFragment : Fragment() {
|
||||
|
||||
binding.textAccountLogin.text = EncryptedPreferences.login
|
||||
|
||||
// TODO reimplement for cr, if possible (maybe account status would be better? (premium))
|
||||
// load subscription (async) info before anything else
|
||||
binding.textAccountSubscription.text = getString(R.string.account_subscription, getString(R.string.loading))
|
||||
// load account status and tier (async) info before anything else
|
||||
lifecycleScope.launch {
|
||||
binding.textAccountSubscription.text = getString(
|
||||
R.string.account_subscription,
|
||||
"TODO"
|
||||
)
|
||||
benefits.await().apply {
|
||||
this.items.firstOrNull { it.benefit == "cr_premium" }?.let {
|
||||
binding.textAccountSubscription.text = getString(R.string.account_premium)
|
||||
}
|
||||
|
||||
this.items.firstOrNull { it.benefit == "cr_fan_pack" }?.let {
|
||||
binding.textAccountSubscriptionDesc.text =
|
||||
getString(R.string.account_tier, getString(R.string.account_tier_mega_fan))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add preferred subtitles
|
||||
@ -80,12 +88,6 @@ class AccountFragment : Fragment() {
|
||||
showLoginDialog()
|
||||
}
|
||||
|
||||
binding.linearAccountSubscription.setOnClickListener {
|
||||
// TODO
|
||||
//startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(AoDParser.getSubscriptionUrl())))
|
||||
}
|
||||
|
||||
|
||||
binding.linearSettingsContentLanguage.setOnClickListener {
|
||||
showContentLanguageSelection()
|
||||
}
|
||||
|
Reference in New Issue
Block a user