Skip to content

Commit 8b207b5

Browse files
committed
Style PWA in recent screen
1 parent 4939d9d commit 8b207b5

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

components/feature/pwa/src/main/java/mozilla/components/feature/pwa/AbstractWebAppShellActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import mozilla.components.concept.engine.Engine
1313
import mozilla.components.concept.engine.EngineView
1414
import mozilla.components.concept.engine.manifest.WebAppManifest
1515
import mozilla.components.feature.pwa.ext.applyOrientation
16+
import mozilla.components.feature.pwa.ext.asTaskDescription
1617
import mozilla.components.support.ktx.android.view.enterToImmersiveMode
1718

1819
/**
@@ -51,6 +52,8 @@ abstract class AbstractWebAppShellActivity : AppCompatActivity() {
5152
}
5253

5354
applyOrientation(manifest)
55+
56+
setTaskDescription(manifest.asTaskDescription())
5457
}
5558

5659
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)

components/feature/pwa/src/main/java/mozilla/components/feature/pwa/WebAppLauncherActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class WebAppLauncherActivity : AppCompatActivity() {
6262
internal fun launchWebAppShell() {
6363
val intent = Intent()
6464
intent.action = AbstractWebAppShellActivity.INTENT_ACTION
65-
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
65+
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
6666
intent.`package` = packageName
6767

6868
try {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package mozilla.components.feature.pwa.ext
6+
7+
import android.app.ActivityManager.TaskDescription
8+
import mozilla.components.concept.engine.manifest.WebAppManifest
9+
10+
/**
11+
* Create a [TaskDescription] for the activity manager based on the manifest.
12+
*
13+
* Since the web app icon is provided dynamically by the web site, we can't provide a resource ID.
14+
* Instead we use the deprecated constructor.
15+
*/
16+
@Suppress("Deprecation")
17+
fun WebAppManifest.asTaskDescription() =
18+
TaskDescription(name, null, themeColor ?: 0)

components/feature/pwa/src/test/java/mozilla/components/feature/pwa/WebAppLauncherActivityTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class WebAppLauncherActivityTest {
118118
verify(activity).startActivity(captor.capture())
119119

120120
assertEquals(AbstractWebAppShellActivity.INTENT_ACTION, captor.value.action)
121-
assertEquals(Intent.FLAG_ACTIVITY_NEW_TASK, captor.value.flags)
121+
assertEquals(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK, captor.value.flags)
122122
assertEquals("test", captor.value.`package`)
123123
}
124124
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package mozilla.components.feature.pwa.ext
6+
7+
import android.graphics.Color.rgb
8+
import androidx.test.ext.junit.runners.AndroidJUnit4
9+
import mozilla.components.concept.engine.manifest.WebAppManifest
10+
import org.junit.Assert.assertEquals
11+
import org.junit.Assert.assertNull
12+
import org.junit.Test
13+
import org.junit.runner.RunWith
14+
15+
@RunWith(AndroidJUnit4::class)
16+
class WebAppManifestKtTest {
17+
18+
@Test
19+
fun `should use name as label`() {
20+
val taskDescription = WebAppManifest(
21+
name = "Demo",
22+
startUrl = "https://example.com"
23+
).asTaskDescription()
24+
assertEquals("Demo", taskDescription.label)
25+
assertNull(taskDescription.icon)
26+
assertEquals(0, taskDescription.primaryColor)
27+
}
28+
29+
@Test
30+
fun `should use themeColor as primaryColor`() {
31+
val taskDescription = WebAppManifest(
32+
name = "My App",
33+
startUrl = "https://example.com",
34+
themeColor = rgb(255, 0, 255)
35+
).asTaskDescription()
36+
assertEquals("My App", taskDescription.label)
37+
assertNull(taskDescription.icon)
38+
assertEquals(rgb(255, 0, 255), taskDescription.primaryColor)
39+
}
40+
}

0 commit comments

Comments
 (0)