This repository has been archived by the owner on May 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WorkerManager and Notification support for reminders added AND detekt…
… and Ktlint support Added (#66) * Base Integration of Detekt Analytics tool done. * added the detekt as pre-push git-hooks. * Enabled the ktlint and also added it into the pre-push git-hooks. * change order and define the taks to generate output in some dir * change some files and tasks and testing that pre-push is working or not * manually it is running but while push it is not working * code cleanup. * tried once more that scripts is working or not * fixed detekt and lint errors. * fixed detekt errors. * Working on Notification and WorkManager * Working on Notification and WorkManager * Working on Notification and WorkManager * n * modified * changed gitignore * refactoring * refactoring * Update misc.xml * Update gradle.xml * Update gradle.xml * Update gradle.xml * Update misc.xml * Delete misc.xml * Delete gradle.xml * Update gradle.xml * Update gradle.xml * Update misc.xml * changed NoteXApp to myContent * added NotificationDTO.kt * Update misc.xml * Update gradle.xml * Update gradle.xml * Update gradle.xml * Update misc.xml * Update gradle.xml * Update gradle.xml * Update misc.xml * detekt requested changes applied * ktlint changes applied * ktlint changes applied Co-authored-by: Abhinav Suman <[email protected]> Co-authored-by: Abhinav Suman <[email protected]> Co-authored-by: MosesATJTC <[email protected]> Co-authored-by: Arunshaik2001 <[email protected]> Co-authored-by: Shaik Ahron <[email protected]>
- Loading branch information
1 parent
7d3e5fd
commit e0a54c6
Showing
42 changed files
with
1,427 additions
and
94 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,7 +1,20 @@ | ||
package com.hadiyarajesh.notex | ||
|
||
import android.app.Application | ||
import androidx.hilt.work.HiltWorkerFactory | ||
import androidx.work.Configuration | ||
import dagger.hilt.android.HiltAndroidApp | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidApp | ||
class MyApplication: Application() | ||
class MyApplication : Application(), Configuration.Provider { | ||
|
||
@Inject | ||
lateinit var workerFactory: HiltWorkerFactory | ||
|
||
override fun getWorkManagerConfiguration(): Configuration { | ||
return Configuration.Builder() | ||
.setWorkerFactory(workerFactory) | ||
.build() | ||
} | ||
} |
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
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
3 changes: 1 addition & 2 deletions
3
app/src/main/java/com/hadiyarajesh/notex/network/api/NoteApi.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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
package com.hadiyarajesh.notex.network.api | ||
|
||
interface NoteApi { | ||
} | ||
interface NoteApi |
64 changes: 64 additions & 0 deletions
64
...c/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationBroadCastReceiver.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,64 @@ | ||
package com.hadiyarajesh.notex.reminder.notification | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.util.Log | ||
import androidx.annotation.CallSuper | ||
import androidx.core.app.NotificationManagerCompat | ||
import com.hadiyarajesh.notex.R | ||
import com.hadiyarajesh.notex.reminder.worker.ReminderWorkManager | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import java.time.Instant | ||
import java.time.temporal.ChronoUnit | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class NotificationBroadCastReceiver : HiltBroadcastReceiver() { | ||
|
||
companion object { | ||
const val TAG = "NotificationBroadCast" | ||
} | ||
|
||
@Inject | ||
lateinit var reminderWorkManager: ReminderWorkManager | ||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
super.onReceive(context, intent) | ||
when (intent.action) { | ||
context.resources.getString(R.string.done_action) -> | ||
reminderWorkManager.cancelWorkRequest( | ||
context, | ||
intent.getStringExtra(context.resources.getString(R.string.worker_tag)) ?: "" | ||
) | ||
context.resources.getString(R.string.postpone_action) -> { | ||
reminderWorkManager.cancelWorkRequest( | ||
context, | ||
intent.getStringExtra(context.resources.getString(R.string.worker_tag)) ?: "" | ||
) | ||
|
||
reminderWorkManager.createWorkRequestAndEnqueue( | ||
context, | ||
time = Instant.now().plus(1, ChronoUnit.HOURS), | ||
isFirstTime = false, | ||
reminderId = intent.getLongExtra( | ||
context.resources.getString(R.string.reminder_id), | ||
-1 | ||
) | ||
) | ||
} | ||
else -> Log.i(TAG, "Nothing to Perform this Action ${intent.action}") | ||
} | ||
|
||
with(NotificationManagerCompat.from(context)) { | ||
cancel(intent.getIntExtra(context.resources.getString(R.string.notification_id), -1)) | ||
} | ||
} | ||
} | ||
|
||
abstract class HiltBroadcastReceiver : BroadcastReceiver() { | ||
@SuppressWarnings("EmptyFunctionBlock") | ||
@CallSuper | ||
override fun onReceive(context: Context, intent: Intent) { | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationDTO.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,8 @@ | ||
package com.hadiyarajesh.notex.reminder.notification | ||
|
||
data class NotificationDTO( | ||
val title: String, | ||
val subTitle: String, | ||
val reminderId: Long, | ||
val workerTag: String | ||
) |
67 changes: 67 additions & 0 deletions
67
app/src/main/java/com/hadiyarajesh/notex/reminder/notification/NotificationHelper.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,67 @@ | ||
package com.hadiyarajesh.notex.reminder.notification | ||
|
||
import android.app.PendingIntent | ||
import android.app.PendingIntent.FLAG_IMMUTABLE | ||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.core.app.NotificationCompat | ||
import androidx.core.app.NotificationManagerCompat | ||
import com.hadiyarajesh.notex.MainActivity | ||
import com.hadiyarajesh.notex.R | ||
import kotlin.random.Random | ||
|
||
class NotificationHelper { | ||
|
||
fun createNotification( | ||
context: Context, | ||
notificationDTO: NotificationDTO | ||
) { | ||
val actionIntent = Intent(context, MainActivity::class.java) | ||
val actionPendingIntent = PendingIntent.getActivity( | ||
context, 0, | ||
actionIntent, PendingIntent.FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE | ||
) | ||
|
||
@SuppressWarnings("MagicNumber") | ||
val notificationId = Random(121).nextInt(10000) | ||
|
||
val postponeIntent = Intent(context, NotificationBroadCastReceiver::class.java).apply { | ||
action = context.resources.getString(R.string.postpone_action) | ||
putExtra(context.resources.getString(R.string.worker_tag), notificationDTO.workerTag) | ||
putExtra(context.resources.getString(R.string.reminder_id), notificationDTO.reminderId) | ||
putExtra(context.resources.getString(R.string.notification_id), notificationId) | ||
} | ||
|
||
val postponePendingIntent = PendingIntent.getBroadcast( | ||
context, 0, | ||
postponeIntent, PendingIntent.FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE | ||
) | ||
|
||
val cancelIntent = Intent(context, NotificationBroadCastReceiver::class.java).apply { | ||
action = context.resources.getString(R.string.done_action) | ||
putExtra(context.resources.getString(R.string.worker_tag), notificationDTO.workerTag) | ||
putExtra(context.resources.getString(R.string.notification_id), notificationId) | ||
} | ||
|
||
val cancelPendingIntent = PendingIntent.getBroadcast( | ||
context, 0, | ||
cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE | ||
) | ||
|
||
val builder = | ||
NotificationCompat.Builder(context, context.getString(R.string.notification_channel_id)) | ||
.setSmallIcon(R.drawable.ic_note_filled) | ||
.setContentTitle(notificationDTO.title) | ||
.setContentText(notificationDTO.subTitle) | ||
.setPriority(NotificationCompat.PRIORITY_DEFAULT) | ||
.setContentIntent(actionPendingIntent) | ||
.addAction(R.drawable.ic_note_filled, context.getString(R.string.one_hour), postponePendingIntent) | ||
.addAction(R.drawable.ic_note_filled, context.getString(R.string.done), cancelPendingIntent) | ||
.setAutoCancel(true) | ||
|
||
with(NotificationManagerCompat.from(context)) { | ||
// notificationId is a unique int for each notification that you must define | ||
notify(notificationId, builder.build()) | ||
} | ||
} | ||
} |
Oops, something went wrong.