diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt index 704faa147..5a5521a92 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt @@ -110,7 +110,14 @@ class DefaultBrowserToolbarController( ) ToolbarMenu.Item.AddToHomeScreen -> { MainScope().launch { - context.components.useCases.webAppUseCases.addToHomescreen() + with(context.components.useCases.webAppUseCases) { + if (isPWA()) { + addToHomescreen() + } else { + val directions = BrowserFragmentDirections.actionBrowserFragmentToCreateShortcutFragment() + navController.navigate(directions) + } + } } } ToolbarMenu.Item.Share -> { diff --git a/app/src/main/java/org/mozilla/fenix/shortcut/CreateShortcutFragment.kt b/app/src/main/java/org/mozilla/fenix/shortcut/CreateShortcutFragment.kt new file mode 100644 index 000000000..c852b2910 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/shortcut/CreateShortcutFragment.kt @@ -0,0 +1,42 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.shortcut + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.DialogFragment +import kotlinx.android.synthetic.main.fragment_create_shortcut.* +import org.mozilla.fenix.R +import org.mozilla.fenix.ext.increaseTapArea +import org.mozilla.fenix.ext.loadIntoView +import org.mozilla.fenix.ext.requireComponents + +class CreateShortcutFragment : DialogFragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setStyle(STYLE_NO_TITLE, R.style.CreateShortcutDialogStyle) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val view = inflater.inflate(R.layout.fragment_create_shortcut, container, false) + return view + } + + 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) + + add_button.increaseTapArea(32) + cancel_button.increaseTapArea(32) + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/dialog_background.xml b/app/src/main/res/drawable/dialog_background.xml new file mode 100644 index 000000000..aa3fcf5c6 --- /dev/null +++ b/app/src/main/res/drawable/dialog_background.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_create_shortcut.xml b/app/src/main/res/layout/fragment_create_shortcut.xml new file mode 100644 index 000000000..6dacb01ce --- /dev/null +++ b/app/src/main/res/layout/fragment_create_shortcut.xml @@ -0,0 +1,73 @@ + + + + + + + + +