-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #463 from tuuhin/add-shortcuts
Feature: Implemented shortcuts
- Loading branch information
Showing
10 changed files
with
133 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/aritra/notify/navigation/NavDeepLinks.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.aritra.notify.navigation | ||
|
||
import androidx.core.net.toUri | ||
|
||
object NavDeepLinks { | ||
|
||
private const val BASE_URI = "app://com.aritra.notify" | ||
|
||
// deeplinks for add notes screen set to -1 means only to add note | ||
val addNotesUriPattern = BASE_URI + NotifyScreens.AddEditNotes.name + "/{noteId}" | ||
val addNotesUri = (BASE_URI + NotifyScreens.AddEditNotes.name + "/-1").toUri() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.aritra.notify.utils | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.util.Log | ||
import androidx.core.content.pm.ShortcutInfoCompat | ||
import androidx.core.content.pm.ShortcutManagerCompat | ||
import androidx.core.graphics.drawable.IconCompat | ||
import com.aritra.notify.R | ||
import com.aritra.notify.navigation.NavDeepLinks | ||
import com.aritra.notify.ui.screens.MainActivity | ||
|
||
object AppShortcuts { | ||
|
||
private fun createNoteShortCut(context: Context): ShortcutInfoCompat = | ||
ShortcutInfoCompat.Builder(context, "add_new_note") | ||
.setShortLabel(context.getString(R.string.add_new_note_shortcut_label)) | ||
.setIcon(IconCompat.createWithResource(context, R.drawable.shortcut_add_icon)) | ||
.setIntent( | ||
Intent(context, MainActivity::class.java).apply { | ||
// opens create note screen | ||
data = NavDeepLinks.addNotesUri | ||
action = Intent.ACTION_VIEW | ||
} | ||
) | ||
.build() | ||
|
||
fun showShortCuts(context: Context) { | ||
val shortcut1 = createNoteShortCut(context) | ||
try { | ||
val isSuccess = ShortcutManagerCompat.addDynamicShortcuts(context, listOf(shortcut1)) | ||
Log.d("SHORTCUTS", "CREATED $isSuccess") | ||
} catch (e: Exception) { | ||
Log.e("SHORTCUTS", "ERROR IN LAYING SHORTCUTS", e) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="@color/logo_background" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#000000" | ||
android:pathData="M19,3H5C4.47,3 3.961,3.211 3.586,3.586C3.211,3.961 3,4.47 3,5V19C3,19.53 3.211,20.039 3.586,20.414C3.961,20.789 4.47,21 5,21H19C20.1,21 21,20.1 21,19V5C21,3.9 20.1,3 19,3ZM19,19H5V5H19V19ZM11,17H13V13H17V11H13V7H11V11H7V13H11V17Z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters