Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Implemented shortcuts #463

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,48 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools">

<uses-feature
android:name="android.hardware.camera"
android:required="false" />

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/notify_logo"
android:label="@string/app_name"
android:name=".NotifyApplication"
android:roundIcon="@drawable/notify_logo"
android:supportsRtl="true"
android:theme="@style/Theme.Notify"
tools:targetApi="31">
android:name=".NotifyApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:enableOnBackInvokedCallback="true"
android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/notify_logo"
android:label="@string/app_name"
android:roundIcon="@drawable/notify_logo"
android:supportsRtl="true"
android:theme="@style/Theme.Notify"
tools:targetApi="33">

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>

<activity
android:name=".ui.screens.MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.MyApp.Splash">
android:name=".ui.screens.MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/Theme.MyApp.Splash"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="app"
android:scheme="${applicationId}" />
</intent-filter>
</activity>
<receiver android:name=".services.reciever.ReminderNoteNotificationBroadcast" />
</application>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/aritra/notify/NotifyApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ package com.aritra.notify

import android.app.Application
import com.aritra.notify.services.notification.createNotificationChannel
import com.aritra.notify.utils.AppShortcuts
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class NotifyApplication : Application() {

override fun onCreate() {
super.onCreate()

// creates the notification channel
createNotificationChannel(this)

// Adds the shortcuts
AppShortcuts.showShortCuts(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ fun AddEditBottomBar(
onDismissRequest = { showSheet = false },
sheetState = sheetState,
dragHandle = { BottomSheetDefaults.DragHandle() },
windowInsets = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) WindowInsets.ime
else WindowInsets(0,0,0,0),
windowInsets = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
WindowInsets.ime
} else {
WindowInsets(0, 0, 0, 0)
},
content = {
Column(
modifier = Modifier
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/aritra/notify/navigation/NavDeepLinks.kt
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()
}
14 changes: 13 additions & 1 deletion app/src/main/java/com/aritra/notify/navigation/NotifyApp.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.aritra.notify.navigation

import android.content.Intent
import android.widget.Toast
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -31,6 +32,7 @@ import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import androidx.navigation.navDeepLink
import com.aritra.notify.R
import com.aritra.notify.ui.screens.notes.addEditScreen.route.AddEditRoute
import com.aritra.notify.ui.screens.notes.homeScreen.NoteScreen
Expand Down Expand Up @@ -101,7 +103,17 @@ fun NotifyApp(navController: NavHostController = rememberNavController()) {

composable(
route = "${NotifyScreens.AddEditNotes.name}/{noteId}",
arguments = listOf(navArgument("noteId") { type = IntType })
arguments = listOf(
navArgument("noteId") {
type = IntType
}
),
deepLinks = listOf(
navDeepLink {
uriPattern = NavDeepLinks.addNotesUriPattern
action = Intent.ACTION_VIEW
}
)
) { backStack ->
AddEditRoute(
navController = navController,
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/com/aritra/notify/ui/screens/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.aritra.notify.components.biometric.AppBioMetricManager
import com.aritra.notify.navigation.NotifyApp
import com.aritra.notify.ui.theme.NotifyTheme
Expand All @@ -35,6 +37,8 @@ class MainActivity : FragmentActivity() {
private lateinit var appUpdateManager: AppUpdateManager
private val updateType = AppUpdateType.IMMEDIATE

private lateinit var navController: NavHostController

@Inject
lateinit var appBioMetricManager: AppBioMetricManager

Expand All @@ -54,14 +58,22 @@ class MainActivity : FragmentActivity() {
}
}
setContent {
navController = rememberNavController()

NotifyTheme {
NotifyApp()
NotifyApp(navController = navController)
}
}

setObservers()
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
// handle deeplinks
navController.handleDeepLink(intent)
}

private val installStateUpdatedListener = InstallStateUpdatedListener { state ->
if (state.installStatus() == InstallStatus.DOWNLOADED) {
Toast.makeText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,12 @@ fun AddEditScreen(
)

DateTimeDialog(
isOpen = shouldShowDialogDateTime, isEdit = isEditDateTime,
isOpen = shouldShowDialogDateTime,
isEdit = isEditDateTime,
onDateTimeUpdated = {
onUpdateReminderDateTime(it)
shouldShowDialogDateTime = false
},
}
) {
shouldShowDialogDateTime = false
isEditDateTime = false
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/java/com/aritra/notify/utils/AppShortcuts.kt
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)
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/shortcut_add_icon.xml
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>
3 changes: 1 addition & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@
<string name="rate_us_on_google_play">Rate us on Google Play</string>
<string name="on_share_message">https://play.google.com/store/apps/details?id=com.aritra.notify</string>
<string name="image">Image</string>
<string name="no_clicked_photos">No Clicked Photos</string>
<string name="clear_image">Clear Image</string>
<string name="speech_to_text">Speech to Text</string>
<string name="drawing">Drawing</string>
<string name="add_image">Add image</string>
<string name="take_image">Take Photo</string>
<string name="add_box">Add Box</string>
<string name="default_notification_channel_id">notify</string>
<string name="request_notification_permission">Request permission</string>
<string name="notification_permission_title">Notification permission</string>
<string name="notification_permission_description">The notification permission is important for this app. Please grant the permission.</string>
Expand All @@ -61,4 +59,5 @@
<string name="set_reminder">Set Reminder</string>
<string name="general">General</string>
<string name="by_aritra_das">By Aritra Das 💙</string>
<string name="add_new_note_shortcut_label">Add New Note</string>
</resources>
Loading