mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
sub channels rewrite
This commit is contained in:
parent
d2c4b41618
commit
83d634bc95
@ -20,6 +20,7 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.github.libretube.adapters.SubscriptionAdapter
|
||||
@ -82,7 +83,7 @@ class Subscriptions : Fragment() {
|
||||
toggleSubs.setOnClickListener {
|
||||
if (!channelRecView.isVisible) {
|
||||
if (!loadedSubbedChannels) {
|
||||
channelRecView?.layoutManager = GridLayoutManager(context, 4)
|
||||
channelRecView?.layoutManager = LinearLayoutManager(context)
|
||||
fetchChannels(channelRecView)
|
||||
loadedSubbedChannels = true
|
||||
}
|
||||
|
@ -1,19 +1,30 @@
|
||||
package com.github.libretube.adapters
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.MainActivity
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.obj.Subscribe
|
||||
import com.github.libretube.obj.Subscription
|
||||
import com.github.libretube.util.RetrofitInstance
|
||||
import com.squareup.picasso.Picasso
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscription>) :
|
||||
RecyclerView.Adapter<SubscriptionChannelViewHolder>() {
|
||||
val TAG = "SubChannelAdapter"
|
||||
override fun getItemCount(): Int {
|
||||
return subscriptions.size
|
||||
}
|
||||
@ -35,6 +46,31 @@ class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscrip
|
||||
val bundle = bundleOf("channel_id" to subscription.url)
|
||||
activity.navController.navigate(R.id.channel, bundle)
|
||||
}
|
||||
val unsubscribeBtn = holder.v.findViewById<com.google.android.material.button.MaterialButton>(R.id.subs_subscribe)
|
||||
unsubscribeBtn.setOnClickListener {
|
||||
val channel_id = subscription.url?.replace("/channel/", "")!!
|
||||
unsubscribe(holder.v.context, channel_id)
|
||||
}
|
||||
}
|
||||
|
||||
private fun unsubscribe(context: Context, channel_id: String) {
|
||||
fun run() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
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")
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG, "HttpException, unexpected response")
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,25 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_margin="8dp"
|
||||
android:padding="8dp"
|
||||
android:background="?android:attr/selectableItemBackground">
|
||||
|
||||
<de.hdodenhof.circleimageview.CircleImageView
|
||||
android:id="@+id/subscription_channel_image"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginBottom="4dp" />
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp" />
|
||||
|
||||
<TextView
|
||||
android:text="kirrrrrrrrrrrrrrrrrrrrrrrrrrfgdfg"
|
||||
android:id="@+id/subscription_channel_name"
|
||||
android:layout_width="60dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_toEndOf="@id/subscription_channel_image"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1" />
|
||||
</LinearLayout>
|
||||
android:maxLines="1"
|
||||
android:text="Channel Name"
|
||||
android:textSize="16dp" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/subs_subscribe"
|
||||
style="@style/Widget.Material3.Button.ElevatedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="?attr/colorOnPrimary"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:drawableLeft="@drawable/ic_bell"
|
||||
android:drawableTint="@color/white"
|
||||
android:textColor="@color/white"
|
||||
android:text="@string/unsubscribe"
|
||||
app:cornerRadius="11dp" />
|
||||
</RelativeLayout>
|
Loading…
x
Reference in New Issue
Block a user