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

View File

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

View File

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