1
0
Fork 0

For #5047 - Wires up dialog to webAppUseCases

master
Jeff Boek 2019-09-11 13:02:20 -07:00
parent faff73b9b3
commit d18ec49704
3 changed files with 17 additions and 8 deletions

View File

@ -10,8 +10,9 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
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 org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.increaseTapArea
import org.mozilla.fenix.ext.loadIntoView import org.mozilla.fenix.ext.loadIntoView
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.requireComponents
@ -25,10 +26,7 @@ class CreateShortcutFragment : DialogFragment() {
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? = inflater.inflate(R.layout.fragment_create_shortcut, container, false)
val view = inflater.inflate(R.layout.fragment_create_shortcut, container, false)
return view
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
@ -36,7 +34,12 @@ class CreateShortcutFragment : DialogFragment() {
requireComponents.core.icons.loadIntoView(favicon_image, session.url) requireComponents.core.icons.loadIntoView(favicon_image, session.url)
shortcut_text.setText(session.title) shortcut_text.setText(session.title)
add_button.increaseTapArea(32) cancel_button.setOnClickListener { dismiss() }
cancel_button.increaseTapArea(32) add_button.setOnClickListener {
val text = shortcut_text.text.toString()
MainScope().launch {
requireComponents.useCases.webAppUseCases.addToHomescreen(text)
}.invokeOnCompletion { dismiss() }
}
} }
} }

View File

@ -35,6 +35,7 @@
android:text="@string/add_to_homescreen_title"/> android:text="@string/add_to_homescreen_title"/>
<ImageView <ImageView
android:id="@+id/favicon_image" android:id="@+id/favicon_image"
android:importantForAccessibility="no"
android:layout_width="32dp" android:layout_width="32dp"
android:layout_height="32dp" android:layout_height="32dp"
android:layout_marginTop="32dp" android:layout_marginTop="32dp"
@ -42,6 +43,9 @@
app:layout_constraintStart_toStartOf="parent"/> app:layout_constraintStart_toStartOf="parent"/>
<EditText <EditText
android:id="@+id/shortcut_text" android:id="@+id/shortcut_text"
android:inputType="text"
android:importantForAutofill="no"
android:hint="@string/add_to_homescreen_text_description"
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"

View File

@ -871,4 +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-->
<string name="add_to_homescreen_text_description">Shortcut name</string>
</resources> </resources>