Skip to content

Commit

Permalink
added feedback extension to viewer module that opens the log viewer o…
Browse files Browse the repository at this point in the history
…n notification click
  • Loading branch information
MFlisar committed Jun 8, 2021
1 parent 7ac61c5 commit 3ea7ef6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,21 @@ fun L.showCrashNotification(
}

/*
* convenient extension to simply show a notification for exceptions/infos/whatever that the user should report if possible
*
* - app version will be appended to the subject automatically
* - file should be local and accessible files - they will be exposed via a ContentProvider so that the email client can access the file
* convenient extension to simply show a notification to the user or for debugging infos
*/
fun L.showInfoNotification(
context: Context,
notificationChannelId: String,
notificationId: Int,
notificationTitle: String,
notificationText: String,
notificationIcon: Int,
notificationIcon: Int
) {
val builder: NotificationCompat.Builder = NotificationCompat.Builder(context, notificationChannelId)
.setSmallIcon(notificationIcon)
.setContentTitle(notificationTitle)
.setContentText(notificationText)

val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(notificationId, builder.build())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.michaelflisar.lumberjack

import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.pm.PackageManager
import androidx.core.app.NotificationCompat
import com.michaelflisar.feedbackmanager.FeedbackBuilder
import java.io.File

Expand All @@ -13,4 +16,35 @@ fun L.showLog(
fileLoggingSetup: FileLoggingSetup
) {
LumberjackViewerActivity.show(context, fileLoggingSetup.getLatestLogFiles()!!)
}

/*
* convenient extension to simply show a notification to the user or for debugging infos
*
* on click this will open the log file in an activity
*/
fun L.showInfoNotification(
context: Context,
notificationChannelId: String,
notificationId: Int,
notificationTitle: String,
notificationText: String,
notificationIcon: Int,
fileLoggingSetup: FileLoggingSetup
) {

val clickIntent = LumberjackViewerActivity.createIntent(context, fileLoggingSetup.getLatestLogFiles()!!)
val pendingClickIntent = PendingIntent.getActivity(context, 0, clickIntent, 0)

val builder: NotificationCompat.Builder = NotificationCompat.Builder(context, notificationChannelId)
.setSmallIcon(notificationIcon)
.setContentTitle(notificationTitle)
.setContentText(notificationText)
.setContentIntent(pendingClickIntent)



val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(notificationId, builder.build())
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ internal class LumberjackViewerActivity : AppCompatActivity() {
val FILE = "FILE"

fun show(context: Context, file: File) {
context.startActivity(
Intent(
context,
LumberjackViewerActivity::class.java
).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(FILE, file)
})
context.startActivity(createIntent(context, file))
}

fun createIntent(context: Context, file: File) : Intent {
return Intent(
context,
LumberjackViewerActivity::class.java
).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(FILE, file)
}
}
}

Expand Down

0 comments on commit 3ea7ef6

Please sign in to comment.