1
0
Fork 0

For #5047 - Creates dialog ui for naming a shortcut

master
Jeff Boek 2019-09-10 15:15:46 -07:00
parent e3209dcc84
commit faff73b9b3
6 changed files with 155 additions and 1 deletions

View File

@ -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 -> {

View File

@ -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)
}
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="8dp"/>
<solid android:color="?above" />
</shape>

View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/createShortcutWrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/scrim_background"
android:fitsSystemWindows="true"
tools:context="org.mozilla.fenix.shortcut.CreateShortcutFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:background="@drawable/dialog_background">
<TextView
android:id="@+id/dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/HeaderTextStyle"
android:textSize="20sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="@string/add_to_homescreen_title"/>
<ImageView
android:id="@+id/favicon_image"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginTop="32dp"
app:layout_constraintTop_toBottomOf="@id/dialog_title"
app:layout_constraintStart_toStartOf="parent"/>
<EditText
android:id="@+id/shortcut_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="32dp"
android:backgroundTint="?neutral"
app:layout_constraintStart_toEndOf="@id/favicon_image"
app:layout_constraintTop_toTopOf="@id/favicon_image"
app:layout_constraintBottom_toBottomOf="@id/favicon_image"
app:layout_constraintEnd_toEndOf="parent"/>
<Button
android:id="@+id/add_button"
style="@style/CreateShortcutDialogButton"
android:background="?selectableItemBackground"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
app:layout_constraintTop_toBottomOf="@id/shortcut_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="@string/add_to_homescreen_add"/>
<Button
android:id="@+id/cancel_button"
style="@style/CreateShortcutDialogButton"
android:background="?selectableItemBackground"
android:text="@string/add_to_homescreen_cancel"
app:layout_constraintBottom_toBottomOf="@id/add_button"
app:layout_constraintEnd_toStartOf="@id/add_button" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>

View File

@ -184,6 +184,9 @@
<action
android:id="@+id/action_browserFragment_to_createCollectionFragment"
app:destination="@id/createCollectionFragment" />
<action
android:id="@+id/action_browserFragment_to_createShortcutFragment"
app:destination="@id/createShortcutFragment" />
<action
android:id="@+id/action_browserFragment_to_shareFragment"
app:destination="@id/shareFragment" />
@ -469,6 +472,11 @@
android:name="org.mozilla.fenix.collections.CreateCollectionFragment"
android:label="fragment_create_collection"
tools:layout="@layout/fragment_create_collection" />
<dialog
android:id="@+id/createShortcutFragment"
android:name="org.mozilla.fenix.shortcut.CreateShortcutFragment"
android:label="fragment_create_shortcut"
tools:layout="@layout/fragment_create_shortcut" />
<dialog
android:id="@+id/shareFragment"
android:name="org.mozilla.fenix.share.ShareFragment"

View File

@ -302,6 +302,21 @@
</style>
<style name="CreateCollectionDialogStyle" parent="DialogStyleBase"/>
<style name="CreateShortcutDialogStyle" parent="DialogStyleBase"/>
<style name="CreateShortcutDialogButton" parent="Widget.AppCompat.Button.Borderless">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textSize">12sp</item>
<item name="android:minHeight">40dp</item>
<item name="android:minWidth">40dp</item>
<item name="android:paddingStart">16dp</item>
<item name="android:paddingEnd">16dp</item>
<item name="android:layout_marginTop">32dp</item>
<item name="android:textColor">?accent</item>
</style>
<style name="FirefoxAccountsDialogStyle" parent="DialogStyleBase">
<item name="android:windowBackground">@drawable/scrim_background</item>
<item name="android:colorControlHighlight">@android:color/transparent</item>