|
|
|
@ -8,9 +8,10 @@ import android.os.Bundle
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.view.ViewGroup
|
|
|
|
|
import androidx.core.widget.addTextChangedListener
|
|
|
|
|
import androidx.fragment.app.DialogFragment
|
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
|
import kotlinx.android.synthetic.main.fragment_create_shortcut.*
|
|
|
|
|
import kotlinx.coroutines.MainScope
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
|
import org.mozilla.fenix.ext.loadIntoView
|
|
|
|
@ -30,16 +31,37 @@ class CreateShortcutFragment : DialogFragment() {
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
val session = requireComponents.core.sessionManager.selectedSession!!
|
|
|
|
|
requireComponents.core.icons.loadIntoView(favicon_image, session.url)
|
|
|
|
|
shortcut_text.setText(session.title)
|
|
|
|
|
|
|
|
|
|
cancel_button.setOnClickListener { dismiss() }
|
|
|
|
|
add_button.setOnClickListener {
|
|
|
|
|
val text = shortcut_text.text.toString()
|
|
|
|
|
MainScope().launch {
|
|
|
|
|
requireComponents.useCases.webAppUseCases.addToHomescreen(text)
|
|
|
|
|
}.invokeOnCompletion { dismiss() }
|
|
|
|
|
|
|
|
|
|
val session = requireComponents.core.sessionManager.selectedSession
|
|
|
|
|
|
|
|
|
|
if (session == null) {
|
|
|
|
|
dismiss()
|
|
|
|
|
} else {
|
|
|
|
|
requireComponents.core.icons.loadIntoView(favicon_image, session.url)
|
|
|
|
|
|
|
|
|
|
cancel_button.setOnClickListener { dismiss() }
|
|
|
|
|
add_button.setOnClickListener {
|
|
|
|
|
val text = shortcut_text.text.toString()
|
|
|
|
|
viewLifecycleOwner.lifecycleScope.launch {
|
|
|
|
|
requireComponents.useCases.webAppUseCases.addToHomescreen(text)
|
|
|
|
|
}.invokeOnCompletion { dismiss() }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shortcut_text.addTextChangedListener {
|
|
|
|
|
updateAddButtonEnabledState()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shortcut_text.setText(session.title)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun updateAddButtonEnabledState() {
|
|
|
|
|
add_button.isEnabled = shortcut_text.text.isNotEmpty()
|
|
|
|
|
add_button.alpha = if (shortcut_text.text.isNotEmpty()) ENABLED_ALPHA else DISABLED_ALPHA
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
private const val ENABLED_ALPHA = 1.0f
|
|
|
|
|
private const val DISABLED_ALPHA = 0.4f
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|