subscribe button

This commit is contained in:
rimthekid 2022-02-13 21:35:51 +04:00
parent 3cd3d90062
commit 922853d2b6
3 changed files with 17 additions and 8 deletions

View File

@ -12,6 +12,7 @@ import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import android.widget.ScrollView import android.widget.ScrollView
import android.widget.TextView import android.widget.TextView
import android.widget.Toast
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -57,8 +58,11 @@ class ChannelFragment : Fragment() {
val recyclerView = view.findViewById<RecyclerView>(R.id.channel_recView) val recyclerView = view.findViewById<RecyclerView>(R.id.channel_recView)
recyclerView.layoutManager = LinearLayoutManager(context) recyclerView.layoutManager = LinearLayoutManager(context)
fetchChannel(view) fetchChannel(view)
val subButton = view.findViewById<MaterialButton>(R.id.channel_subscribe) val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
isSubscribed(subButton) if(sharedPref?.getString("token","")!=""){
val subButton = view.findViewById<MaterialButton>(R.id.channel_subscribe)
isSubscribed(subButton)
}
val scrollView = view.findViewById<ScrollView>(R.id.channel_scrollView) val scrollView = view.findViewById<ScrollView>(R.id.channel_scrollView)
scrollView.viewTreeObserver scrollView.viewTreeObserver
.addOnScrollChangedListener { .addOnScrollChangedListener {
@ -97,6 +101,7 @@ class ChannelFragment : Fragment() {
button.text=getString(R.string.unsubscribe) button.text=getString(R.string.unsubscribe)
button.setTextColor(R.attr.colorPrimaryDark) button.setTextColor(R.attr.colorPrimaryDark)
} }
if(response.subscribed!=null){
button.setOnClickListener { button.setOnClickListener {
if(isSubscribed){ if(isSubscribed){
unsubscribe() unsubscribe()
@ -108,7 +113,7 @@ class ChannelFragment : Fragment() {
button.text=getString(R.string.unsubscribe) button.text=getString(R.string.unsubscribe)
button.setTextColor(R.attr.colorPrimaryDark) button.setTextColor(R.attr.colorPrimaryDark)
} }
} }}
} }
} }
} }

View File

@ -381,9 +381,12 @@ class PlayerFragment : Fragment() {
activity.findViewById<MotionLayout>(R.id.mainMotionLayout).transitionToEnd() activity.findViewById<MotionLayout>(R.id.mainMotionLayout).transitionToEnd()
view.findViewById<MotionLayout>(R.id.playerMotionLayout).transitionToEnd() view.findViewById<MotionLayout>(R.id.playerMotionLayout).transitionToEnd()
} }
val channelId = response.uploaderUrl?.replace("/channel/","") val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
val subButton = view.findViewById<MaterialButton>(R.id.player_subscribe) if(sharedPref?.getString("token","")!=""){
isSubscribed(subButton, channelId!!) val channelId = response.uploaderUrl?.replace("/channel/","")
val subButton = view.findViewById<MaterialButton>(R.id.player_subscribe)
isSubscribed(subButton, channelId!!)
}
} }
} }
@ -413,6 +416,7 @@ class PlayerFragment : Fragment() {
button.text=getString(R.string.unsubscribe) button.text=getString(R.string.unsubscribe)
button.setTextColor(R.attr.colorPrimaryDark) button.setTextColor(R.attr.colorPrimaryDark)
} }
if(response.subscribed!=null){
button.setOnClickListener { button.setOnClickListener {
if(isSubscribed){ if(isSubscribed){
unsubscribe(channel_id) unsubscribe(channel_id)
@ -424,7 +428,7 @@ class PlayerFragment : Fragment() {
button.text=getString(R.string.unsubscribe) button.text=getString(R.string.unsubscribe)
button.setTextColor(R.attr.colorPrimaryDark) button.setTextColor(R.attr.colorPrimaryDark)
} }
} }}
} }
} }
} }

View File

@ -178,7 +178,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:background="@android:color/transparent" android:background="?android:attr/selectableItemBackground"
android:text="@string/subscribe" android:text="@string/subscribe"
android:textColor="@color/colorPrimary" /> android:textColor="@color/colorPrimary" />
</RelativeLayout> </RelativeLayout>