mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
Switch to Material Dialog
This commit is contained in:
parent
4947c97d70
commit
e5105f2f73
@ -1,12 +1,11 @@
|
||||
package com.github.libretube
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
@ -16,50 +15,52 @@ import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.setFragmentResult
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.github.libretube.obj.Playlists
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import retrofit2.HttpException
|
||||
|
||||
class CreatePlaylistDialog : DialogFragment() {
|
||||
val TAG = "CreatePlaylistDialog"
|
||||
private var token: String = ""
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
var rootView: View = inflater.inflate(R.layout.dialog_create_playlist, container, false)
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return activity?.let {
|
||||
val builder = MaterialAlertDialogBuilder(it)
|
||||
val inflater = requireActivity().layoutInflater
|
||||
val view: View = inflater.inflate(R.layout.dialog_create_playlist, null)
|
||||
|
||||
val typedValue = TypedValue()
|
||||
this.requireActivity().theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true)
|
||||
val hexColor = String.format("#%06X", (0xFFFFFF and typedValue.data))
|
||||
val appName = HtmlCompat.fromHtml(
|
||||
"Libre<span style='color:$hexColor';>Tube</span>",
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT
|
||||
)
|
||||
rootView.findViewById<TextView>(R.id.title).text = appName
|
||||
val typedValue = TypedValue()
|
||||
this.requireActivity().theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true)
|
||||
val hexColor = String.format("#%06X", (0xFFFFFF and typedValue.data))
|
||||
val appName = HtmlCompat.fromHtml(
|
||||
"Libre<span style='color:$hexColor';>Tube</span>",
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT
|
||||
)
|
||||
view.findViewById<TextView>(R.id.title).text = appName
|
||||
|
||||
val cancelBtn = rootView.findViewById<Button>(R.id.cancel_button)
|
||||
cancelBtn.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
token = sharedPref?.getString("token", "")!!
|
||||
|
||||
val playlistName = rootView.findViewById<TextInputEditText>(R.id.playlist_name)
|
||||
val createPlaylistBtn = rootView.findViewById<Button>(R.id.create_new_playlist)
|
||||
createPlaylistBtn.setOnClickListener {
|
||||
var listName = playlistName.text.toString()
|
||||
if (listName != "") {
|
||||
createPlaylist("$listName")
|
||||
} else {
|
||||
Toast.makeText(context, R.string.emptyPlaylistName, Toast.LENGTH_LONG).show()
|
||||
val cancelBtn = view.findViewById<Button>(R.id.cancel_button)
|
||||
cancelBtn.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
return rootView
|
||||
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
|
||||
token = sharedPref?.getString("token", "")!!
|
||||
|
||||
val playlistName = view.findViewById<TextInputEditText>(R.id.playlist_name)
|
||||
val createPlaylistBtn = view.findViewById<Button>(R.id.create_new_playlist)
|
||||
createPlaylistBtn.setOnClickListener {
|
||||
var listName = playlistName.text.toString()
|
||||
if (listName != "") {
|
||||
createPlaylist("$listName")
|
||||
} else {
|
||||
Toast.makeText(context, R.string.emptyPlaylistName, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
builder.setView(view)
|
||||
builder.create()
|
||||
} ?: throw IllegalStateException("Activity cannot be null")
|
||||
}
|
||||
private fun createPlaylist(name: String) {
|
||||
fun run() {
|
||||
@ -79,13 +80,14 @@ class CreatePlaylistDialog : DialogFragment() {
|
||||
if (response != null) {
|
||||
Toast.makeText(context, R.string.playlistCreated, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
Toast.makeText(context, getString(R.string.unknown_error), Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(context, getString(R.string.unknown_error), Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
}.invokeOnCompletion {
|
||||
setFragmentResult("fetchPlaylists", bundleOf("" to ""))
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.github.libretube.adapters.PlaylistsAdapter
|
||||
import com.github.libretube.obj.Playlists
|
||||
import java.io.IOException
|
||||
import retrofit2.HttpException
|
||||
|
||||
|
@ -2,15 +2,10 @@ package com.github.libretube
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import java.net.URLEncoder
|
||||
|
||||
/**
|
||||
* Dialog with different options for a selected video.
|
||||
|
@ -23,10 +23,16 @@
|
||||
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"
|
||||
|
||||
app:boxCornerRadiusBottomStart="15dp"
|
||||
app:boxCornerRadiusBottomEnd="15dp"
|
||||
app:boxCornerRadiusTopEnd="15dp"
|
||||
app:boxCornerRadiusTopStart="15dp"
|
||||
>
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
|
Loading…
Reference in New Issue
Block a user