For #5047 - Addresses nits
- Changes MainScope to viewLifecycleScope - Fixes string name/comment to better describe what it is - Adds disabled state to the add buttonmaster
parent
d18ec49704
commit
e092dfd684
|
@ -8,9 +8,10 @@ import android.os.Bundle
|
||||||
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 androidx.core.widget.addTextChangedListener
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import kotlinx.android.synthetic.main.fragment_create_shortcut.*
|
import kotlinx.android.synthetic.main.fragment_create_shortcut.*
|
||||||
import kotlinx.coroutines.MainScope
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.ext.loadIntoView
|
import org.mozilla.fenix.ext.loadIntoView
|
||||||
|
@ -30,16 +31,37 @@ class CreateShortcutFragment : DialogFragment() {
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
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() }
|
val session = requireComponents.core.sessionManager.selectedSession
|
||||||
add_button.setOnClickListener {
|
|
||||||
val text = shortcut_text.text.toString()
|
if (session == null) {
|
||||||
MainScope().launch {
|
dismiss()
|
||||||
requireComponents.useCases.webAppUseCases.addToHomescreen(text)
|
} else {
|
||||||
}.invokeOnCompletion { dismiss() }
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
android:id="@+id/shortcut_text"
|
android:id="@+id/shortcut_text"
|
||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
android:importantForAutofill="no"
|
android:importantForAutofill="no"
|
||||||
android:hint="@string/add_to_homescreen_text_description"
|
android:hint="@string/add_to_homescreen_text_placeholder"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
|
|
|
@ -871,6 +871,6 @@
|
||||||
<string name="add_to_homescreen_cancel">Cancel</string>
|
<string name="add_to_homescreen_cancel">Cancel</string>
|
||||||
<!-- Add button text for the Add to Homescreen dialog -->
|
<!-- Add button text for the Add to Homescreen dialog -->
|
||||||
<string name="add_to_homescreen_add">Add</string>
|
<string name="add_to_homescreen_add">Add</string>
|
||||||
<!-- Content description (not visible, for screen readers etc.): Text field for shortcut name-->
|
<!-- Placeholder text for the TextView in the Add to Homescreen dialog -->
|
||||||
<string name="add_to_homescreen_text_description">Shortcut name</string>
|
<string name="add_to_homescreen_text_placeholder">Shortcut name</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue