Skip to content

Commit

Permalink
Update notification per latest UI, fix #281
Browse files Browse the repository at this point in the history
  • Loading branch information
JunDai authored and JUN DAI committed Mar 20, 2020
1 parent cd4d864 commit 3104a01
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ internal class MapboxNavigationNotification : NavigationNotification {
}
collapsedNotificationRemoteViews?.setTextViewText(
R.id.notificationDistanceText,
currentDistanceText
currentDistanceText.toString()
)
expandedNotificationRemoteViews?.setTextViewText(
R.id.notificationDistanceText,
currentDistanceText
currentDistanceText.toString()
)
}
}
Expand Down
12 changes: 6 additions & 6 deletions libandroid-navigation/src/main/res/drawable/ic_close.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
android:width="14dp"
android:height="14dp"
android:viewportWidth="14"
android:viewportHeight="14">
<path
android:fillColor="#FF000000"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
android:fillColor="#FFFFFF"
android:pathData="M14,1.4l-1.4,-1.4l-5.6,5.6l-5.6,-5.6l-1.4,1.4l5.6,5.6l-5.6,5.6l1.4,1.4l5.6,-5.6l5.6,5.6l1.4,-1.4l-5.6,-5.6z" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigationCollapsedNotificationLayout"
style="@android:style/TextAppearance.StatusBar.EventContent"
android:layout_width="match_parent"
android:layout_height="64dp">
android:layout_height="64dp"
tools:background="@color/mapboxNotificationBlue">

<ImageView
android:id="@+id/maneuverImage"
Expand All @@ -14,6 +14,7 @@
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:cropToPadding="true"
Expand All @@ -22,6 +23,7 @@

<TextView
android:id="@+id/notificationDistanceText"
style="@style/NotificationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/maneuverImage"
Expand All @@ -47,6 +49,7 @@

<TextView
android:id="@+id/notificationArrivalText"
style="@style/NotificationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/notificationDistanceText"
Expand All @@ -61,6 +64,7 @@

<TextView
android:id="@+id/notificationInstructionText"
style="@style/NotificationText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/maneuverImage"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigationExpandedNotificationLayout"
style="@android:style/TextAppearance.StatusBar.EventContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="8dp"
android:paddingBottom="8dp">
android:paddingBottom="8dp"
tools:background="@color/mapboxNotificationBlue">

<include layout="@layout/collapsed_navigation_notification_layout" />

Expand All @@ -26,8 +28,7 @@
android:layout_gravity="center"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:src="@drawable/ic_close"
android:tint="@android:color/white" />
android:src="@drawable/ic_close" />

<TextView
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="NotificationText" parent="android:TextAppearance.Material.Notification" />
<style name="NotificationTitle" parent="android:TextAppearance.Material.Notification.Title" />
<style name="NotificationTime" parent="android:TextAppearance.Material.Notification.Time" />

<style name="NotificationTitle" parent="android:TextAppearance.StatusBar.EventContent">
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
</style>

<style name="NotificationText" parent="android:TextAppearance.StatusBar.EventContent" />
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ class MapboxTripNotification constructor(
currentInstructionText = null
currentDistanceText = null

collapsedNotificationRemoteViews?.apply {
setTextViewText(R.id.notificationDistanceText, "")
setTextViewText(R.id.notificationArrivalText, "")
setTextViewText(R.id.notificationInstructionText, "")
}

expandedNotificationRemoteViews?.apply {
setTextViewText(R.id.notificationDistanceText, "")
setTextViewText(R.id.notificationArrivalText, "")
setTextViewText(R.id.notificationInstructionText, "")
setTextViewText(R.id.endNavigationBtnText, "")
}

unregisterReceiver()
try {
notificationActionButtonChannel.cancel()
Expand Down Expand Up @@ -256,6 +269,7 @@ class MapboxTripNotification constructor(

private fun setFreeDriveMode(isFreeDriveMode: Boolean) {
updateEtaContentVisibility(isFreeDriveMode)
updateInstructionTextVisibility(isFreeDriveMode)
updateFreeDriveTextVisibility(isFreeDriveMode)
updateManeuverImageResource(isFreeDriveMode)
updateEndNavigationBtnText(isFreeDriveMode)
Expand All @@ -273,6 +287,17 @@ class MapboxTripNotification constructor(
)
}

private fun updateInstructionTextVisibility(isFreeDriveMode: Boolean) {
collapsedNotificationRemoteViews?.setViewVisibility(
R.id.notificationInstructionText,
if (isFreeDriveMode) GONE else VISIBLE
)
expandedNotificationRemoteViews?.setViewVisibility(
R.id.notificationInstructionText,
if (isFreeDriveMode) GONE else VISIBLE
)
}

private fun updateFreeDriveTextVisibility(isFreeDriveMode: Boolean) {
collapsedNotificationRemoteViews?.setViewVisibility(
R.id.freeDriveText,
Expand Down Expand Up @@ -333,11 +358,11 @@ class MapboxTripNotification constructor(
}
collapsedNotificationRemoteViews?.setTextViewText(
R.id.notificationDistanceText,
currentDistanceText
currentDistanceText.toString()
)
expandedNotificationRemoteViews?.setTextViewText(
R.id.notificationDistanceText,
currentDistanceText
currentDistanceText.toString()
)
}
}
Expand Down
12 changes: 6 additions & 6 deletions libtrip-notification/src/main/res/drawable/ic_close.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
android:width="14dp"
android:height="14dp"
android:viewportWidth="14"
android:viewportHeight="14">
<path
android:fillColor="#FF000000"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
android:fillColor="#FFFFFF"
android:pathData="M14,1.4l-1.4,-1.4l-5.6,5.6l-5.6,-5.6l-1.4,1.4l5.6,5.6l-5.6,5.6l1.4,1.4l5.6,-5.6l5.6,5.6l1.4,-1.4l-5.6,-5.6z" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigationCollapsedNotificationLayout"
style="@android:style/TextAppearance.StatusBar.EventContent"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="@color/mapboxNotificationBlue">
Expand All @@ -15,6 +14,7 @@
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:cropToPadding="true"
Expand All @@ -26,13 +26,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/maneuverImage"
android:layout_marginTop="4dp"
android:layout_toEndOf="@id/maneuverImage"
android:layout_toRightOf="@id/maneuverImage"
android:orientation="horizontal">

<TextView
android:id="@+id/notificationDistanceText"
style="@style/NotificationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="1"
Expand All @@ -51,6 +51,7 @@

<TextView
android:id="@+id/notificationArrivalText"
style="@style/NotificationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
Expand All @@ -63,10 +64,10 @@

<TextView
android:id="@+id/freeDriveText"
style="@style/NotificationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/maneuverImage"
android:layout_marginTop="4dp"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/maneuverImage"
android:layout_toRightOf="@id/maneuverImage"
android:lines="1"
Expand All @@ -76,6 +77,7 @@

<TextView
android:id="@+id/notificationInstructionText"
style="@style/NotificationText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/maneuverImage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
android:layout_gravity="center"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:src="@drawable/ic_close"
android:tint="@android:color/white" />
android:src="@drawable/ic_close" />

<TextView
android:id="@+id/endNavigationBtnText"
Expand Down
2 changes: 1 addition & 1 deletion libtrip-notification/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- Notification Strings -->
<string name="end_navigation">End Navigation</string>
<string name="stop_session">Stop session</string>
<string name="free_drive_notification_text">Free Drive session</string>
<string name="free_drive_notification_text">Free Drive Session</string>
<string name="channel_name">Navigation Notifications</string>
<string name="notification_arrival_time_format">Arrive at %s</string>
<string name="eta_format">%s ETA</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="NotificationText" parent="android:TextAppearance.Material.Notification" />
<style name="NotificationTitle" parent="android:TextAppearance.Material.Notification.Title" />
<style name="NotificationTime" parent="android:TextAppearance.Material.Notification.Time" />

<style name="NotificationTitle" parent="android:TextAppearance.StatusBar.EventContent">
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
</style>

<style name="NotificationText" parent="android:TextAppearance.StatusBar.EventContent" />
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,14 @@ class MapboxTripNotificationTest {
val routeProgress = mockk<RouteProgress>(relaxed = true)
val distance = 30f
val duration = 112L
val distanceText = distanceSpannable.toString()
mockLegProgress(routeProgress, distance, duration)
val distanceSlot1 = slot<SpannableString>()
val distanceSlot2 = slot<SpannableString>()
every { collapsedViews.setTextViewText(any(), capture(distanceSlot1)) } just Runs
every { expandedViews.setTextViewText(any(), capture(distanceSlot2)) } just Runs
mockUpdateNotificationAndroidInteractions()

notification.updateNotification(routeProgress)

verify(exactly = 1) { collapsedViews.setTextViewText(any(), distanceSpannable) }
verify(exactly = 1) { expandedViews.setTextViewText(any(), distanceSpannable) }
assertEquals(distanceSpannable, distanceSlot1.captured)
assertEquals(distanceSpannable, distanceSlot2.captured)
verify(exactly = 1) { collapsedViews.setTextViewText(any(), distanceText) }
verify(exactly = 1) { expandedViews.setTextViewText(any(), distanceText) }
}

@Test
Expand Down

0 comments on commit 3104a01

Please sign in to comment.