mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
subscribed button
This commit is contained in:
parent
94818c663c
commit
0073c865b3
@ -27,6 +27,7 @@
|
|||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:configChanges="orientation|screenSize"
|
android:configChanges="orientation|screenSize"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
>
|
>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.github.libretube
|
package com.github.libretube
|
||||||
|
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
@ -14,6 +16,8 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.github.libretube.adapters.ChannelAdapter
|
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 com.squareup.picasso.Picasso
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -26,6 +30,7 @@ class ChannelFragment : Fragment() {
|
|||||||
var nextPage: String? =null
|
var nextPage: String? =null
|
||||||
var channelAdapter: ChannelAdapter? = null
|
var channelAdapter: ChannelAdapter? = null
|
||||||
var isLoading = true
|
var isLoading = true
|
||||||
|
var isSubscribed: Boolean =false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -51,8 +56,9 @@ class ChannelFragment : Fragment() {
|
|||||||
view.findViewById<TextView>(R.id.channel_name).text=channel_id
|
view.findViewById<TextView>(R.id.channel_name).text=channel_id
|
||||||
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)
|
||||||
|
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 {
|
||||||
@ -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){
|
private fun fetchChannel(view: View){
|
||||||
|
@ -129,10 +129,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val orientation = newConfig.orientation
|
val orientation = newConfig.orientation
|
||||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
println("Portrait")
|
println("Portrait")
|
||||||
//unsetFullscreen()
|
unsetFullscreen()
|
||||||
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
println("Landscape")
|
println("Landscape")
|
||||||
//setFullscreen()
|
setFullscreen()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private fun setFullscreen() {
|
private fun setFullscreen() {
|
||||||
|
@ -47,10 +47,10 @@ interface PipedApi {
|
|||||||
suspend fun subscriptions(@Header("Authorization") token: String): List<Subscription>
|
suspend fun subscriptions(@Header("Authorization") token: String): List<Subscription>
|
||||||
|
|
||||||
@POST("subscribe")
|
@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")
|
@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
|
//only for fetching servers list
|
||||||
@GET("Instances.md")
|
@GET("Instances.md")
|
||||||
|
@ -27,6 +27,8 @@ class SubscriptionAdapter(private val videoFeed: List<StreamItem>): RecyclerView
|
|||||||
fun updateItems(){
|
fun updateItems(){
|
||||||
//limitedVideoFeed.add("")
|
//limitedVideoFeed.add("")
|
||||||
i += 10
|
i += 10
|
||||||
|
if(i>videoFeed.size)
|
||||||
|
i=videoFeed.size
|
||||||
//println("suck another dick: "+newItems[0].title)
|
//println("suck another dick: "+newItems[0].title)
|
||||||
notifyDataSetChanged()
|
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_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:paddingLeft="8dp"
|
android:paddingLeft="8dp"
|
||||||
android:paddingRight="8dp">
|
android:paddingRight="8dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:background="?android:attr/selectableItemBackground">
|
||||||
|
|
||||||
<de.hdodenhof.circleimageview.CircleImageView
|
<de.hdodenhof.circleimageview.CircleImageView
|
||||||
android:id="@+id/player_channelImage"
|
android:id="@+id/player_channelImage"
|
||||||
@ -178,7 +180,7 @@
|
|||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:background="@android:color/transparent"
|
android:background="@android:color/transparent"
|
||||||
android:text="@string/subscribe"
|
android:text="@string/subscribe"
|
||||||
android:textColor="@color/colorPrimary" />
|
android:textColor="@color/colorPrimary"/>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<string name="choose_quality_dialog">Choose Quality:</string>
|
<string name="choose_quality_dialog">Choose Quality:</string>
|
||||||
<string name="search_hint">Search</string>
|
<string name="search_hint">Search</string>
|
||||||
<string name="subscribe">SUBSCRIBE</string>
|
<string name="subscribe">SUBSCRIBE</string>
|
||||||
|
<string name="unsubscribe">UNSUBSCRIBE</string>
|
||||||
<string name="share">Share</string>
|
<string name="share">Share</string>
|
||||||
<string name="download">Download</string>
|
<string name="download">Download</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user