Create Playlist Rework

This commit is contained in:
Bnyro 2022-05-04 11:28:00 +02:00
parent e077e1ea9f
commit cc7dd8426c
5 changed files with 114 additions and 37 deletions

View File

@ -0,0 +1,41 @@
package com.github.libretube
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.Toast
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.setFragmentResult
class CreatePlaylistDialog : DialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
var rootView: View = inflater.inflate(R.layout.dialog_create_playlist, container, false)
val cancelBtn = rootView.findViewById<Button>(R.id.cancel_button)
cancelBtn.setOnClickListener {
dismiss()
}
val playlistName = rootView.findViewById<com.google.android.material.textfield.TextInputEditText>(R.id.playlist_name)
val createPlaylistBtn = rootView.findViewById<Button>(R.id.create_new_playlist)
createPlaylistBtn.setOnClickListener {
var listName = playlistName.text.toString()
if(listName != "") {
setFragmentResult("key_parent", bundleOf("playlistName" to "$listName"))
dismiss()
}
else {
Toast.makeText(context, R.string.emptyPlaylistName, Toast.LENGTH_LONG).show()
}
}
return rootView
}
}

View File

@ -3,21 +3,20 @@ package com.github.libretube
import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
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.ChannelAdapter
import com.github.libretube.adapters.PlaylistsAdapter
import com.github.libretube.adapters.SubscriptionAdapter
import com.github.libretube.obj.Playlists
import com.squareup.picasso.Picasso
import retrofit2.HttpException
import java.io.IOException
@ -59,10 +58,13 @@ class Library : Fragment() {
Log.d(TAG,"hmm")
fetchPlaylists(view)
}
val playlistName = view.findViewById<EditText>(R.id.playlists_name)
view.findViewById<Button>(R.id.create_playlist).setOnClickListener {
if(playlistName.text.toString()!="") createPlaylist(playlistName.text.toString(),view)
hideKeyboard()
val newFragment = CreatePlaylistDialog()
newFragment.show(childFragmentManager, "Create Playlist")
}
childFragmentManager.setFragmentResultListener("key_parent", this) { _, result->
val playlistName = result.getString("playlistName")
createPlaylist("$playlistName", view);
}
} else{
with(view.findViewById<ImageView>(R.id.boogh2)){

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="300dp"
android:layout_height="64dp"
android:background="#CD5757"
android:contentDescription="@string/app_name"
android:scaleType="center"
android:src="@drawable/ic_libretube_foreground" />
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
android:layout_marginTop="16dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginBottom="4dp"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/playlist_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/playlistName"
android:inputType="text"
android:padding="12dp" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel"
android:padding="8dp"
android:layout_margin="8dp"/>
<Button
android:id="@+id/create_new_playlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/createPlaylist"
android:padding="8dp"
android:layout_margin="8dp"/>
</LinearLayout>
</LinearLayout>

View File

@ -48,34 +48,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/outlinedTextField"
style="@style/Widget.Material3.CardView.Filled"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_margin="5dp"
>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:background="@android:color/transparent">
<EditText
android:id="@+id/playlists_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:layout_margin="8dp"
android:background="@android:color/transparent"
android:hint="@string/playlistName"/>
</com.google.android.material.textfield.TextInputLayout>
</com.google.android.material.card.MaterialCardView>
<Button
android:id="@+id/create_playlist"

View File

@ -46,6 +46,7 @@
<string name="createPlaylist">Create Playlist</string>
<string name="playlistCreated">Playlist created!</string>
<string name="playlistName">Playlist Name</string>
<string name="emptyPlaylistName">The playlist name can\'t be empty</string>
<string name="addToPlaylist">Add to Playlist</string>
<string name="success">Success!</string>
<string name="fail">Failed :(</string>