Merge pull request #349 from Bnyro/library

Create Playlist Btn Rework
This commit is contained in:
Bnyro 2022-06-02 18:15:48 +02:00 committed by GitHub
commit 3d404b2dbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 18 deletions

View File

@ -80,7 +80,8 @@ class PlaylistFragment : Fragment() {
response.relatedStreams!!.toMutableList(),
playlist_id!!,
isOwner,
requireActivity()
requireActivity(),
childFragmentManager
)
view.findViewById<RecyclerView>(R.id.playlist_recView).adapter = playlistAdapter
val scrollView = view.findViewById<ScrollView>(R.id.playlist_scrollview)

View File

@ -172,7 +172,7 @@ class SettingsActivity :
val login = findPreference<Preference>("login_register")
login?.setOnPreferenceClickListener {
requireMainActivityRestart = true
val newFragment = LoginDialog()
newFragment.show(childFragmentManager, "Login")
true

View File

@ -7,7 +7,6 @@ import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.fragment.app.DialogFragment
import androidx.preference.PreferenceManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
/**
@ -51,9 +50,11 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog
}
// Add Video to Playlist Dialog
1 -> {
val sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(requireContext())
val token = sharedPreferences.getString("token", "")
val sharedPref = context?.getSharedPreferences(
"token",
Context.MODE_PRIVATE
)
val token = sharedPref?.getString("token", "")
if (token != "") {
val newFragment = AddtoPlaylistDialog()
val bundle = Bundle()

View File

@ -11,10 +11,12 @@ import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.PlayerFragment
import com.github.libretube.R
import com.github.libretube.RetrofitInstance
import com.github.libretube.VideoOptionsDialog
import com.github.libretube.obj.PlaylistId
import com.github.libretube.obj.StreamItem
import com.squareup.picasso.Picasso
@ -27,7 +29,8 @@ class PlaylistAdapter(
private val videoFeed: MutableList<StreamItem>,
private val playlistId: String,
private val isOwner: Boolean,
private val activity: Activity
private val activity: Activity,
private val childFragmentManager: FragmentManager
) : RecyclerView.Adapter<PlaylistViewHolder>() {
private val TAG = "PlaylistAdapter"
override fun getItemCount(): Int {
@ -66,6 +69,13 @@ class PlaylistAdapter(
.replace(R.id.container, frag)
.commitNow()
}
holder.v.setOnLongClickListener {
val videoId = streamItem.url!!.replace("/watch?v=", "")
VideoOptionsDialog(videoId, holder.v.context)
.show(childFragmentManager, VideoOptionsDialog.TAG)
true
}
if (isOwner) {
val delete = holder.v.findViewById<ImageView>(R.id.delete_playlist)
delete.visibility = View.VISIBLE

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -49,15 +48,6 @@
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/create_playlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/createPlaylist"
android:layout_gravity="center"
android:layout_margin="8dp"
android:textColor="?attr/colorSurface"
android:drawableLeft="@drawable/ic_add" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -73,4 +63,28 @@
</LinearLayout>
</ScrollView>
</com.github.libretube.CustomSwipeToRefresh>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<com.google.android.material.button.MaterialButton
android:layout_gravity="right"
android:id="@+id/create_playlist"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:insetLeft="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
android:insetBottom="0dp"
app:cornerRadius="16dp"
app:icon="@drawable/ic_add"
android:backgroundTint="?attr/colorSecondary"
app:iconGravity="textStart"
app:iconPadding="0dp" />
</FrameLayout>
</FrameLayout>