add app shortcut for favorites view

fixes #152
This commit is contained in:
Johan von Forstner
2022-01-01 15:43:20 +01:00
parent d21ac0a781
commit ae489aa6ef
4 changed files with 45 additions and 7 deletions

View File

@@ -256,6 +256,10 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
<!-- Override services of the com.mapzen.android.lost library with exported:false

View File

@@ -40,6 +40,7 @@ const val REQUEST_LOCATION_PERMISSION = 1
const val EXTRA_CHARGER_ID = "chargerId"
const val EXTRA_LAT = "lat"
const val EXTRA_LON = "lon"
const val EXTRA_FAVORITES = "favorites"
class MapsActivity : AppCompatActivity(),
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
@@ -115,6 +116,8 @@ class MapsActivity : AppCompatActivity(),
navController.graph = navGraph
return
} else {
navGraph.setStartDestination(R.id.map)
navController.setGraph(navGraph, MapFragmentArgs(appStart = true).toBundle())
var deepLink: PendingIntent? = null
if (intent?.scheme == "geo") {
@@ -158,15 +161,13 @@ class MapsActivity : AppCompatActivity(),
).toBundle()
)
.createPendingIntent()
} else if (intent.hasExtra(EXTRA_FAVORITES)) {
deepLink = navController.createDeepLink()
.setDestination(R.id.favs)
.createPendingIntent()
}
navGraph.setStartDestination(R.id.map)
if (deepLink != null) {
navController.graph = navGraph
deepLink.send()
} else {
navController.setGraph(navGraph, MapFragmentArgs(appStart = true).toBundle())
}
deepLink?.send()
}
}

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/colorSecondary"
android:pathData="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z" />
</vector>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="favs"
android:icon="@drawable/ic_shortcut_fav"
android:shortcutShortLabel="@string/menu_favs">
<!-- Note: the targetPackage is hardcoded here, because templates or string resources don't
work. This means that the shortcut will not work if the package name changes
(e.g. in the debug version). -->
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="net.vonforst.evmap"
android:targetClass="net.vonforst.evmap.MapsActivity">
<extra
android:name="favorites"
android:value="true" />
</intent>
<capability-binding android:key="actions.intent.OPEN_APP_FEATURE">
<parameter-binding
android:value="@string/menu_favs"
android:key="feature" />
</capability-binding>
</shortcut>
</shortcuts>