mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
subscribed button
This commit is contained in:
parent
94818c663c
commit
0073c865b3
@ -27,6 +27,7 @@
|
||||
android:exported="true"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:hardwareAccelerated="true"
|
||||
android:screenOrientation="portrait"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.github.libretube
|
||||
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.fragment.app.Fragment
|
||||
@ -14,6 +16,8 @@ import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.adapters.ChannelAdapter
|
||||
import com.github.libretube.obj.Subscribe
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.squareup.picasso.Picasso
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
@ -26,6 +30,7 @@ class ChannelFragment : Fragment() {
|
||||
var nextPage: String? =null
|
||||
var channelAdapter: ChannelAdapter? = null
|
||||
var isLoading = true
|
||||
var isSubscribed: Boolean =false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -51,8 +56,9 @@ class ChannelFragment : Fragment() {
|
||||
view.findViewById<TextView>(R.id.channel_name).text=channel_id
|
||||
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 scrollView = view.findViewById<ScrollView>(R.id.channel_scrollView)
|
||||
scrollView.viewTreeObserver
|
||||
.addOnScrollChangedListener {
|
||||
@ -67,6 +73,85 @@ class ChannelFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun isSubscribed(button: MaterialButton){
|
||||
@SuppressLint("ResourceAsColor")
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
RetrofitInstance.api.isSubscribed(channel_id!!,sharedPref?.getString("token","")!!)
|
||||
}catch(e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG, "HttpException, unexpected response")
|
||||
return@launchWhenCreated
|
||||
}
|
||||
runOnUiThread {
|
||||
if (response.subscribed==true){
|
||||
isSubscribed=true
|
||||
button.text=getString(R.string.unsubscribe)
|
||||
button.setTextColor(R.attr.colorPrimaryDark)
|
||||
}
|
||||
button.setOnClickListener {
|
||||
if(isSubscribed){
|
||||
unsubscribe()
|
||||
button.text=getString(R.string.subscribe)
|
||||
button.setTextColor(resources.getColor(R.color.md_theme_light_primary))
|
||||
|
||||
}else{
|
||||
subscribe()
|
||||
button.text=getString(R.string.unsubscribe)
|
||||
button.setTextColor(R.attr.colorPrimaryDark)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun subscribe(){
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
RetrofitInstance.api.subscribe(sharedPref?.getString("token","")!!, Subscribe(channel_id))
|
||||
}catch(e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG, "HttpException, unexpected response$e")
|
||||
return@launchWhenCreated
|
||||
}
|
||||
isSubscribed=true
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
private fun unsubscribe(){
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
RetrofitInstance.api.unsubscribe(sharedPref?.getString("token","")!!, Subscribe(channel_id))
|
||||
}catch(e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG, "HttpException, unexpected response")
|
||||
return@launchWhenCreated
|
||||
}
|
||||
isSubscribed=false
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun fetchChannel(view: View){
|
||||
|
@ -129,10 +129,10 @@ class MainActivity : AppCompatActivity() {
|
||||
val orientation = newConfig.orientation
|
||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
println("Portrait")
|
||||
//unsetFullscreen()
|
||||
unsetFullscreen()
|
||||
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
println("Landscape")
|
||||
//setFullscreen()
|
||||
setFullscreen()
|
||||
}
|
||||
}
|
||||
private fun setFullscreen() {
|
||||
|
@ -47,10 +47,10 @@ interface PipedApi {
|
||||
suspend fun subscriptions(@Header("Authorization") token: String): List<Subscription>
|
||||
|
||||
@POST("subscribe")
|
||||
suspend fun subscribe(@Header("Authorization") token: String, @Body subscribe: Subscribe): String
|
||||
suspend fun subscribe(@Header("Authorization") token: String, @Body subscribe: Subscribe): Message
|
||||
|
||||
@POST("unsubscribe")
|
||||
suspend fun unsubscribe(@Header("Authorization") token: String, @Body subscribe: Subscribe): String
|
||||
suspend fun unsubscribe(@Header("Authorization") token: String, @Body subscribe: Subscribe): Message
|
||||
|
||||
//only for fetching servers list
|
||||
@GET("Instances.md")
|
||||
|
@ -27,6 +27,8 @@ class SubscriptionAdapter(private val videoFeed: List<StreamItem>): RecyclerView
|
||||
fun updateItems(){
|
||||
//limitedVideoFeed.add("")
|
||||
i += 10
|
||||
if(i>videoFeed.size)
|
||||
i=videoFeed.size
|
||||
//println("suck another dick: "+newItems[0].title)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
5
app/src/main/java/com/github/libretube/obj/Message.kt
Normal file
5
app/src/main/java/com/github/libretube/obj/Message.kt
Normal file
@ -0,0 +1,5 @@
|
||||
package com.github.libretube.obj
|
||||
|
||||
data class Message(
|
||||
var message: String? = null
|
||||
)
|
@ -151,7 +151,9 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp">
|
||||
android:paddingRight="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:background="?android:attr/selectableItemBackground">
|
||||
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/player_channelImage"
|
||||
|
@ -5,6 +5,7 @@
|
||||
<string name="choose_quality_dialog">Choose Quality:</string>
|
||||
<string name="search_hint">Search</string>
|
||||
<string name="subscribe">SUBSCRIBE</string>
|
||||
<string name="unsubscribe">UNSUBSCRIBE</string>
|
||||
<string name="share">Share</string>
|
||||
<string name="download">Download</string>
|
||||
<string name="save">Save</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user