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 val tokenRefreshContext = newSingleThreadContext("TokenRefreshContext")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private var accountID = ""
 | 
					    private var accountID = ""
 | 
				
			||||||
 | 
					    private var externalID = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private var policy = ""
 | 
					    private var policy = ""
 | 
				
			||||||
    private var signature = ""
 | 
					    private var signature = ""
 | 
				
			||||||
@ -245,6 +246,7 @@ object Crunchyroll {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        accountID = account.accountId
 | 
					        accountID = account.accountId
 | 
				
			||||||
 | 
					        externalID = account.externalId
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -704,4 +706,20 @@ object Crunchyroll {
 | 
				
			|||||||
        requestPatch(profileEndpoint, bodyObject = json)
 | 
					        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 Watchlist = Collection<Item>
 | 
				
			||||||
typealias ContinueWatchingList = Collection<ContinueWatchingItem>
 | 
					typealias ContinueWatchingList = Collection<ContinueWatchingItem>
 | 
				
			||||||
typealias RecommendationsList = Collection<Item>
 | 
					typealias RecommendationsList = Collection<Item>
 | 
				
			||||||
 | 
					typealias Benefits = Collection<Benefit>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Serializable
 | 
					@Serializable
 | 
				
			||||||
data class UpNextSeriesItem(
 | 
					data class UpNextSeriesItem(
 | 
				
			||||||
@ -226,6 +227,7 @@ val NoneSimilarToResult = SimilarToResult(0, emptyList())
 | 
				
			|||||||
val NoneDiscSeasonList = DiscSeasonList(0, emptyList())
 | 
					val NoneDiscSeasonList = DiscSeasonList(0, emptyList())
 | 
				
			||||||
val NoneContinueWatchingList = ContinueWatchingList(0, emptyList())
 | 
					val NoneContinueWatchingList = ContinueWatchingList(0, emptyList())
 | 
				
			||||||
val NoneRecommendationsList = RecommendationsList(0, emptyList())
 | 
					val NoneRecommendationsList = RecommendationsList(0, emptyList())
 | 
				
			||||||
 | 
					val NoneBenefits = Benefits(0, emptyList())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
val NoneUpNextSeriesItem = UpNextSeriesItem(
 | 
					val NoneUpNextSeriesItem = UpNextSeriesItem(
 | 
				
			||||||
    playhead = 0,
 | 
					    playhead = 0,
 | 
				
			||||||
@ -412,3 +414,16 @@ val NoneProfile = Profile(
 | 
				
			|||||||
    preferredContentSubtitleLanguage = "",
 | 
					    preferredContentSubtitleLanguage = "",
 | 
				
			||||||
    username = ""
 | 
					    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.BuildConfig
 | 
				
			||||||
import org.mosad.teapod.R
 | 
					import org.mosad.teapod.R
 | 
				
			||||||
import org.mosad.teapod.databinding.FragmentAccountBinding
 | 
					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.Crunchyroll
 | 
				
			||||||
import org.mosad.teapod.parser.crunchyroll.Profile
 | 
					import org.mosad.teapod.parser.crunchyroll.Profile
 | 
				
			||||||
import org.mosad.teapod.parser.crunchyroll.supportedLocals
 | 
					import org.mosad.teapod.parser.crunchyroll.supportedLocals
 | 
				
			||||||
@ -33,6 +34,9 @@ class AccountFragment : Fragment() {
 | 
				
			|||||||
    private var profile: Deferred<Profile> = lifecycleScope.async {
 | 
					    private var profile: Deferred<Profile> = lifecycleScope.async {
 | 
				
			||||||
        Crunchyroll.profile()
 | 
					        Crunchyroll.profile()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    private var benefits: Deferred<Benefits> = lifecycleScope.async {
 | 
				
			||||||
 | 
					        Crunchyroll.benefits()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
 | 
					    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
 | 
				
			||||||
        binding = FragmentAccountBinding.inflate(inflater, container, false)
 | 
					        binding = FragmentAccountBinding.inflate(inflater, container, false)
 | 
				
			||||||
@ -44,14 +48,18 @@ class AccountFragment : Fragment() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        binding.textAccountLogin.text = EncryptedPreferences.login
 | 
					        binding.textAccountLogin.text = EncryptedPreferences.login
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // TODO reimplement for cr, if possible (maybe account status would be better? (premium))
 | 
					        // load account status and tier (async) info before anything else
 | 
				
			||||||
        // load subscription (async) info before anything else
 | 
					 | 
				
			||||||
        binding.textAccountSubscription.text = getString(R.string.account_subscription, getString(R.string.loading))
 | 
					 | 
				
			||||||
        lifecycleScope.launch {
 | 
					        lifecycleScope.launch {
 | 
				
			||||||
            binding.textAccountSubscription.text = getString(
 | 
					            benefits.await().apply {
 | 
				
			||||||
                R.string.account_subscription,
 | 
					                this.items.firstOrNull { it.benefit == "cr_premium" }?.let {
 | 
				
			||||||
                "TODO"
 | 
					                    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
 | 
					        // add preferred subtitles
 | 
				
			||||||
@ -80,12 +88,6 @@ class AccountFragment : Fragment() {
 | 
				
			|||||||
            showLoginDialog()
 | 
					            showLoginDialog()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        binding.linearAccountSubscription.setOnClickListener {
 | 
					 | 
				
			||||||
            // TODO
 | 
					 | 
				
			||||||
            //startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(AoDParser.getSubscriptionUrl())))
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        binding.linearSettingsContentLanguage.setOnClickListener {
 | 
					        binding.linearSettingsContentLanguage.setOnClickListener {
 | 
				
			||||||
            showContentLanguageSelection()
 | 
					            showContentLanguageSelection()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -112,7 +112,7 @@
 | 
				
			|||||||
                            android:layout_width="match_parent"
 | 
					                            android:layout_width="match_parent"
 | 
				
			||||||
                            android:layout_height="wrap_content"
 | 
					                            android:layout_height="wrap_content"
 | 
				
			||||||
                            android:layout_weight="1"
 | 
					                            android:layout_weight="1"
 | 
				
			||||||
                            android:text="@string/account_subscription"
 | 
					                            android:text="@string/loading"
 | 
				
			||||||
                            android:textSize="16sp" />
 | 
					                            android:textSize="16sp" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <TextView
 | 
					                        <TextView
 | 
				
			||||||
@ -120,7 +120,7 @@
 | 
				
			|||||||
                            android:layout_width="match_parent"
 | 
					                            android:layout_width="match_parent"
 | 
				
			||||||
                            android:layout_height="wrap_content"
 | 
					                            android:layout_height="wrap_content"
 | 
				
			||||||
                            android:layout_weight="1"
 | 
					                            android:layout_weight="1"
 | 
				
			||||||
                            android:text="@string/account_subscription_desc"
 | 
					                            android:text="@string/account_tier"
 | 
				
			||||||
                            android:textColor="?textSecondary" />
 | 
					                            android:textColor="?textSecondary" />
 | 
				
			||||||
                    </LinearLayout>
 | 
					                    </LinearLayout>
 | 
				
			||||||
                </LinearLayout>
 | 
					                </LinearLayout>
 | 
				
			||||||
 | 
				
			|||||||
@ -37,6 +37,8 @@
 | 
				
			|||||||
    <string name="account_login_desc">Zum bearbeiten tippen</string>
 | 
					    <string name="account_login_desc">Zum bearbeiten tippen</string>
 | 
				
			||||||
    <string name="account_subscription">Abo %1$s</string>
 | 
					    <string name="account_subscription">Abo %1$s</string>
 | 
				
			||||||
    <string name="account_subscription_desc">Zum verlängern tippen</string>
 | 
					    <string name="account_subscription_desc">Zum verlängern tippen</string>
 | 
				
			||||||
 | 
					    <string name="account_premium">Premium Mitglied</string>
 | 
				
			||||||
 | 
					    <string name="account_tier">Typ: %1$s</string>
 | 
				
			||||||
    <string name="info">Info</string>
 | 
					    <string name="info">Info</string>
 | 
				
			||||||
    <string name="info_about_desc">Version %1$s (%2$s)</string>
 | 
					    <string name="info_about_desc">Version %1$s (%2$s)</string>
 | 
				
			||||||
    <string name="settings">Einstellungen</string>
 | 
					    <string name="settings">Einstellungen</string>
 | 
				
			||||||
 | 
				
			|||||||
@ -49,6 +49,11 @@
 | 
				
			|||||||
    <string name="account_login_desc">Tap to edit</string>
 | 
					    <string name="account_login_desc">Tap to edit</string>
 | 
				
			||||||
    <string name="account_subscription">Subscription %1$s</string>
 | 
					    <string name="account_subscription">Subscription %1$s</string>
 | 
				
			||||||
    <string name="account_subscription_desc">Tap to extend</string>
 | 
					    <string name="account_subscription_desc">Tap to extend</string>
 | 
				
			||||||
 | 
					    <string name="account_premium">Premium member</string>
 | 
				
			||||||
 | 
					    <string name="account_tier">Tier: %1$s</string>
 | 
				
			||||||
 | 
					    <string name="account_tier_fan" translatable="false">Fan</string>
 | 
				
			||||||
 | 
					    <string name="account_tier_mega_fan" translatable="false">Mega Fan</string>
 | 
				
			||||||
 | 
					    <string name="account_tier_ultimate_fan" translatable="false">Ultimate Fan</string>
 | 
				
			||||||
    <string name="settings">Settings</string>
 | 
					    <string name="settings">Settings</string>
 | 
				
			||||||
    <string name="settings_content_language">Preferred content language</string>
 | 
					    <string name="settings_content_language">Preferred content language</string>
 | 
				
			||||||
    <string name="settings_content_language_desc">English</string>
 | 
					    <string name="settings_content_language_desc">English</string>
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user