fix crash when opening /user/ link

This commit is contained in:
Bnyro 2022-09-08 20:28:01 +02:00
parent f8dabbda4e
commit 32b5ae7094
2 changed files with 28 additions and 27 deletions

View File

@ -325,7 +325,7 @@ class MainActivity : BaseActivity() {
intent?.getStringExtra(IntentData.channelName) != null -> navController.navigate(
R.id.channelFragment,
bundleOf(
IntentData.channelId to intent?.getStringExtra(IntentData.channelName)
IntentData.channelName to intent?.getStringExtra(IntentData.channelName)
)
)
intent?.getStringExtra(IntentData.playlistId) != null -> navController.navigate(

View File

@ -39,6 +39,7 @@ class ChannelFragment : BaseFragment() {
channelName = it.getString(IntentData.channelName)
?.replace("/c/", "")
?.replace("/user/", "")
Log.e(TAG(), channelName.toString())
}
}
@ -60,7 +61,6 @@ class ChannelFragment : BaseFragment() {
val refreshChannel = {
binding.channelRefresh.isRefreshing = true
fetchChannel()
isSubscribed()
}
refreshChannel()
binding.channelRefresh.setOnRefreshListener {
@ -82,31 +82,6 @@ class ChannelFragment : BaseFragment() {
}
}
private fun isSubscribed() {
lifecycleScope.launchWhenCreated {
isSubscribed = SubscriptionHelper.isSubscribed(channelId!!)
if (isSubscribed == null) return@launchWhenCreated
runOnUiThread {
if (isSubscribed == true) {
binding.channelSubscribe.text = getString(R.string.unsubscribe)
}
binding.channelSubscribe.setOnClickListener {
binding.channelSubscribe.text = if (isSubscribed == true) {
SubscriptionHelper.unsubscribe(channelId!!)
isSubscribed = false
getString(R.string.subscribe)
} else {
SubscriptionHelper.subscribe(channelId!!)
isSubscribed = true
getString(R.string.unsubscribe)
}
}
}
}
}
private fun fetchChannel() {
fun run() {
lifecycleScope.launchWhenCreated {
@ -126,9 +101,35 @@ class ChannelFragment : BaseFragment() {
Log.e(TAG(), "HttpException, unexpected response")
return@launchWhenCreated
}
// needed if the channel gets loaded by the ID
channelId = response.id
// fetch and update the subscription status
isSubscribed = SubscriptionHelper.isSubscribed(channelId!!)
if (isSubscribed == null) return@launchWhenCreated
runOnUiThread {
if (isSubscribed == true) {
binding.channelSubscribe.text = getString(R.string.unsubscribe)
}
binding.channelSubscribe.setOnClickListener {
binding.channelSubscribe.text = if (isSubscribed == true) {
SubscriptionHelper.unsubscribe(channelId!!)
isSubscribed = false
getString(R.string.subscribe)
} else {
SubscriptionHelper.subscribe(channelId!!)
isSubscribed = true
getString(R.string.unsubscribe)
}
}
}
nextPage = response.nextpage
isLoading = false
binding.channelRefresh.isRefreshing = false
runOnUiThread {
binding.channelScrollView.visibility = View.VISIBLE
binding.channelName.text = response.name