Updated some dialogs to md3

This commit is contained in:
archroid 2022-05-20 14:50:36 +04:30
parent 0dc3f87db3
commit 536098bf0b
No known key found for this signature in database
GPG Key ID: D8EE5C11EDF911B1
10 changed files with 103 additions and 34 deletions

View File

@ -4,14 +4,17 @@ import android.app.Dialog
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.util.TypedValue
import android.view.View import android.view.View
import android.widget.* import android.widget.*
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.text.HtmlCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.github.libretube.adapters.PlaylistsAdapter import com.github.libretube.adapters.PlaylistsAdapter
import com.github.libretube.obj.PlaylistId import com.github.libretube.obj.PlaylistId
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import retrofit2.HttpException import retrofit2.HttpException
import java.io.IOException import java.io.IOException
@ -24,7 +27,7 @@ class AddtoPlaylistDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity?.let { return activity?.let {
videoId = arguments?.getString("videoId")!! videoId = arguments?.getString("videoId")!!
val builder = AlertDialog.Builder(it) val builder = MaterialAlertDialogBuilder(it)
// Get the layout inflater // Get the layout inflater
val inflater = requireActivity().layoutInflater; val inflater = requireActivity().layoutInflater;
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
@ -35,6 +38,15 @@ class AddtoPlaylistDialog : DialogFragment() {
if(token!=""){ if(token!=""){
fetchPlaylists() fetchPlaylists()
} }
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
builder.setView(view) builder.setView(view)
builder.create() builder.create()
} ?: throw IllegalStateException("Activity cannot be null") } ?: throw IllegalStateException("Activity cannot be null")

View File

@ -1,12 +1,15 @@
package com.github.libretube package com.github.libretube
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button import android.widget.Button
import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.setFragmentResult import androidx.fragment.app.setFragmentResult
@ -18,6 +21,15 @@ class CreatePlaylistDialog : DialogFragment() {
): View? { ): View? {
var rootView: View = inflater.inflate(R.layout.dialog_create_playlist, container, false) var rootView: View = inflater.inflate(R.layout.dialog_create_playlist, container, false)
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 cancelBtn = rootView.findViewById<Button>(R.id.cancel_button) val cancelBtn = rootView.findViewById<Button>(R.id.cancel_button)
cancelBtn.setOnClickListener { cancelBtn.setOnClickListener {
dismiss() dismiss()

View File

@ -4,10 +4,13 @@ import android.app.Dialog
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.util.TypedValue
import android.view.View import android.view.View
import android.widget.* import android.widget.*
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.text.HtmlCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
class DownloadDialog : DialogFragment() { class DownloadDialog : DialogFragment() {
@ -29,7 +32,7 @@ class DownloadDialog : DialogFragment() {
audioUrl = arguments?.getStringArrayList("audioUrl") as ArrayList<String> audioUrl = arguments?.getStringArrayList("audioUrl") as ArrayList<String>
duration = arguments?.getInt("duration")!! duration = arguments?.getInt("duration")!!
videoId = arguments?.getString("videoId")!! videoId = arguments?.getString("videoId")!!
val builder = AlertDialog.Builder(it) val builder = MaterialAlertDialogBuilder(it)
// Get the layout inflater // Get the layout inflater
val inflater = requireActivity().layoutInflater val inflater = requireActivity().layoutInflater
var view: View = inflater.inflate(R.layout.dialog_download, null) var view: View = inflater.inflate(R.layout.dialog_download, null)
@ -82,6 +85,16 @@ class DownloadDialog : DialogFragment() {
context?.startService(intent) context?.startService(intent)
dismiss() dismiss()
} }
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
builder.setView(view) builder.setView(view)
builder.create() builder.create()
} ?: throw IllegalStateException("Activity cannot be null") } ?: throw IllegalStateException("Activity cannot be null")

View File

@ -5,17 +5,20 @@ import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.util.TypedValue
import android.view.View import android.view.View
import android.widget.Button import android.widget.Button
import android.widget.EditText import android.widget.EditText
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.text.HtmlCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.github.libretube.adapters.TrendingAdapter import com.github.libretube.adapters.TrendingAdapter
import com.github.libretube.obj.Login import com.github.libretube.obj.Login
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.w3c.dom.Text import org.w3c.dom.Text
import retrofit2.HttpException import retrofit2.HttpException
import java.io.IOException import java.io.IOException
@ -28,7 +31,7 @@ class LoginDialog : DialogFragment() {
lateinit var password: EditText lateinit var password: EditText
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity?.let { return activity?.let {
val builder = AlertDialog.Builder(it) val builder = MaterialAlertDialogBuilder(it)
// Get the layout inflater // Get the layout inflater
val inflater = requireActivity().layoutInflater; val inflater = requireActivity().layoutInflater;
val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE)
@ -70,6 +73,17 @@ class LoginDialog : DialogFragment() {
} }
} }
} }
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
builder.setView(view) builder.setView(view)
builder.create() builder.create()
} ?: throw IllegalStateException("Activity cannot be null") } ?: throw IllegalStateException("Activity cannot be null")

View File

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

View File

@ -7,13 +7,17 @@
> >
<ImageView
android:src="@drawable/ic_libretube_foreground" <TextView
android:id="@+id/title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="64dp" android:layout_height="wrap_content"
android:scaleType="center" android:text="@string/app_name"
android:background="#CD5757" android:gravity="center"
android:contentDescription="@string/app_name" /> android:layout_margin="10dp"
android:textSize="20sp"
/>
<Spinner <Spinner
android:id="@+id/playlists_spinner" android:id="@+id/playlists_spinner"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -7,13 +7,16 @@
> >
<ImageView
android:layout_width="300dp" <TextView
android:layout_height="64dp" android:id="@+id/title"
android:background="#CD5757" android:layout_width="match_parent"
android:contentDescription="@string/app_name" android:layout_height="wrap_content"
android:scaleType="center" android:text="@string/app_name"
android:src="@drawable/ic_libretube_foreground" /> android:gravity="center"
android:layout_margin="10dp"
android:textSize="20sp"
/>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"

View File

@ -6,13 +6,15 @@
> >
<ImageView <TextView
android:src="@drawable/ic_libretube_foreground" android:id="@+id/title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="64dp" android:layout_height="wrap_content"
android:scaleType="center" android:text="@string/app_name"
android:background="#CD5757" android:gravity="center"
android:contentDescription="@string/app_name" /> android:layout_margin="10dp"
android:textSize="20sp"
/>
<Spinner <Spinner
android:id="@+id/video_spinner" android:id="@+id/video_spinner"

View File

@ -7,13 +7,17 @@
> >
<ImageView
android:src="@drawable/ic_libretube_foreground"
<TextView
android:id="@+id/title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="64dp" android:layout_height="wrap_content"
android:scaleType="center" android:text="@string/app_name"
android:background="#CD5757" android:gravity="center"
android:contentDescription="@string/app_name" /> android:layout_margin="10dp"
android:textSize="20sp"
/>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"

View File

@ -3,13 +3,16 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<ImageView
android:src="@drawable/ic_libretube_foreground" <TextView
android:id="@+id/title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="64dp" android:layout_height="wrap_content"
android:scaleType="center" android:text="@string/app_name"
android:background="#CD5757" android:gravity="center"
android:contentDescription="@string/app_name" /> android:layout_margin="10dp"
android:textSize="20sp"
/>
<TextView <TextView
android:id="@+id/user" android:id="@+id/user"