mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
create playlist
This commit is contained in:
parent
0c76b99fe2
commit
bf8e029cad
@ -20,12 +20,11 @@ class CreatePlaylistDialog: DialogFragment() {
|
||||
val inflater = requireActivity().layoutInflater;
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
val token = sharedPref?.getString("token","")
|
||||
var view: View
|
||||
var view: View = inflater.inflate(R.layout.dialog_createplaylist, null)
|
||||
Log.e("dafaq",token!!)
|
||||
if(token!=""){
|
||||
val sharedPref2 = context?.getSharedPreferences("username", Context.MODE_PRIVATE)
|
||||
val user = sharedPref2?.getString("username","")
|
||||
view = inflater.inflate(R.layout.dialog_logout, null)
|
||||
view.findViewById<TextView>(R.id.user).text = view.findViewById<TextView>(R.id.user).text.toString()+" ("+user+")"
|
||||
view.findViewById<Button>(R.id.logout).setOnClickListener {
|
||||
Toast.makeText(context,R.string.loggedout, Toast.LENGTH_SHORT).show()
|
||||
|
@ -7,10 +7,7 @@ import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.ScrollView
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import android.widget.*
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
@ -19,6 +16,7 @@ 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
|
||||
@ -61,6 +59,19 @@ 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)
|
||||
}
|
||||
} else{
|
||||
with(view.findViewById<ImageView>(R.id.boogh2)){
|
||||
visibility=View.VISIBLE
|
||||
setImageResource(R.drawable.ic_login)
|
||||
}
|
||||
with(view.findViewById<TextView>(R.id.textLike2)){
|
||||
visibility=View.VISIBLE
|
||||
text = getString(R.string.please_login)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,14 +125,14 @@ class Library : Fragment() {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.api.createPlaylist(token, name)
|
||||
RetrofitInstance.api.createPlaylist(token, Playlists(name = name))
|
||||
}catch(e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
Toast.makeText(context,R.string.unknown_error, Toast.LENGTH_SHORT).show()
|
||||
return@launchWhenCreated
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG, "HttpException, unexpected response")
|
||||
Log.e(TAG, "HttpException, unexpected response $e")
|
||||
Toast.makeText(context,R.string.server_error, Toast.LENGTH_SHORT).show()
|
||||
return@launchWhenCreated
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ interface PipedApi {
|
||||
suspend fun deletePlaylist(@Header("Authorization") token: String, @Body playlistId: PlaylistId): Message
|
||||
|
||||
@POST("user/playlists/create")
|
||||
suspend fun createPlaylist(@Header("Authorization") token: String, @Body name: String): PlaylistId
|
||||
suspend fun createPlaylist(@Header("Authorization") token: String, @Body name: Playlists): PlaylistId
|
||||
|
||||
//only for fetching servers list
|
||||
@GET
|
||||
|
52
app/src/main/res/layout/dialog_createplaylist.xml
Normal file
52
app/src/main/res/layout/dialog_createplaylist.xml
Normal file
@ -0,0 +1,52 @@
|
||||
<?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:src="@drawable/ic_libretube_foreground"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:scaleType="center"
|
||||
android:background="#CD5757"
|
||||
android:contentDescription="@string/app_name" />
|
||||
|
||||
<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/username"
|
||||
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/create_playlist_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/createPlaylist"
|
||||
android:padding="8dp"
|
||||
android:layout_margin="8dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -1,5 +1,7 @@
|
||||
<?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"
|
||||
android:layout_height="match_parent"
|
||||
@ -46,6 +48,34 @@
|
||||
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"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -45,4 +45,5 @@
|
||||
<string name="areYouSure">Are you sure you want to delete this playlist?</string>
|
||||
<string name="createPlaylist">Create Playlist</string>
|
||||
<string name="playlistCreated">Playlist created!</string>
|
||||
<string name="playlistName">Playlist Name</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user