-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include new components, extensions and utils
- Loading branch information
Showing
36 changed files
with
1,326 additions
and
180 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
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,6 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.jeluchu.jchucomponentscompose"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.WAKE_LOCK" /> | ||
</manifest> |
1 change: 0 additions & 1 deletion
1
...c/main/java/com/jeluchu/jchucomponentscompose/core/extensions/context/ContextExensions.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
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
121 changes: 121 additions & 0 deletions
121
...com/jeluchu/jchucomponentscompose/core/extensions/notifications/NotificationExtensions.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,121 @@ | ||
package com.jeluchu.jchucomponentscompose.core.extensions.notifications | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.* | ||
import android.content.Context | ||
import android.os.Build | ||
import androidx.annotation.DrawableRes | ||
import androidx.annotation.StringRes | ||
import androidx.core.app.NotificationCompat | ||
import androidx.core.app.NotificationManagerCompat | ||
|
||
/** | ||
* NotificationExtensions.kt | ||
* is a class that contain all extension functions | ||
* to help us easy to create and update notification | ||
* from anywhere that has context object. | ||
*/ | ||
|
||
/** | ||
* Create notification group | ||
*/ | ||
fun Context.createNotificationChannelGroup(@StringRes groupId: Int, @StringRes groupName: Int) { | ||
val id = this.getString(groupId) | ||
val name = this.getString(groupName) | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
val notificationManager = this.getSystemService(NotificationManager::class.java) | ||
notificationManager?.createNotificationChannelGroup(NotificationChannelGroup(id, name)) | ||
} | ||
} | ||
|
||
/** | ||
* Get notification channel | ||
* @param channelId | ||
* @return [NotificationChannel] | ||
*/ | ||
fun Context.getNotificationChannel(@StringRes channelId: Int): NotificationChannel? { | ||
return NotificationManagerCompat.from(this).getNotificationChannel(this.getString(channelId)) | ||
} | ||
|
||
/** | ||
* Get notification channel group | ||
* @param groupId | ||
* @return [NotificationChannelGroup] | ||
*/ | ||
fun Context.getNotificationChannelGroup(@StringRes groupId: Int): NotificationChannelGroup? { | ||
return NotificationManagerCompat.from(this).getNotificationChannelGroup(this.getString(groupId)) | ||
} | ||
|
||
/** | ||
* Create notification channel | ||
*/ | ||
fun Context.createNotificationChannel( | ||
@StringRes channelId: Int, | ||
@StringRes channelName: Int, | ||
@StringRes channelDescription: Int, | ||
@SuppressLint("InlinedApi") importance: Int = NotificationManager.IMPORTANCE_DEFAULT | ||
) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
val id = this.getString(channelId) | ||
val name = this.getString(channelName) | ||
val descriptionText = this.getString(channelDescription) | ||
val channel = NotificationChannel(id, name, importance).also { | ||
it.description = descriptionText | ||
if (importance >= NotificationManager.IMPORTANCE_HIGH) { | ||
it.enableVibration(true) | ||
it.enableLights(true) | ||
} else if (importance < NotificationManager.IMPORTANCE_DEFAULT) { | ||
it.enableVibration(false) | ||
it.enableLights(false) | ||
it.setSound(null, null) | ||
} | ||
} | ||
val notificationManager = this.getSystemService(NotificationManager::class.java) | ||
notificationManager?.createNotificationChannel(channel) | ||
} | ||
} | ||
|
||
/** | ||
* Build a notification | ||
*/ | ||
fun Context.getNotificationBuilder( | ||
@StringRes channelId: Int, | ||
title: Int, | ||
text: Int, | ||
@DrawableRes icon: Int, | ||
@StringRes groupId: Int, | ||
importance: Int = NotificationCompat.PRIORITY_DEFAULT, | ||
pendingIntent: PendingIntent? = null | ||
): NotificationCompat.Builder = | ||
NotificationCompat.Builder(this, this.getString(channelId)) | ||
.setSmallIcon(icon) | ||
.setContentTitle(this.getString(title)) | ||
.setContentText(this.getString(text)) | ||
.setPriority(importance) | ||
.setContentIntent(pendingIntent) | ||
.setGroup(this.getString(groupId)) | ||
|
||
/** | ||
* Update notification | ||
*/ | ||
fun Context.notifyNotification(notificationId: Int, notification: Notification) = | ||
NotificationManagerCompat.from(this).notify(notificationId, notification) | ||
|
||
/** | ||
* Cancel notification base on notification id | ||
* | ||
* @param notificationId id to cancel | ||
* | ||
* Note: | ||
* - if [notificationId] is empty or default, this method | ||
* will cancel all notifications | ||
*/ | ||
fun Context.cancelNotification(vararg notificationId: Int = intArrayOf()) { | ||
if (notificationId.isEmpty()) { | ||
NotificationManagerCompat.from(this).cancelAll() | ||
return | ||
} | ||
notificationId.forEach { | ||
NotificationManagerCompat.from(this).cancel(it) | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
...pose/src/main/java/com/jeluchu/jchucomponentscompose/core/extensions/uri/UriExtensions.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,30 @@ | ||
package com.jeluchu.jchucomponentscompose.core.extensions.uri | ||
|
||
import android.content.ContentResolver | ||
import android.database.Cursor | ||
import android.net.Uri | ||
import android.provider.OpenableColumns | ||
import java.io.IOException | ||
|
||
fun Uri.getFileName(contentResolver: ContentResolver): String { | ||
var result: String? = null | ||
if (scheme == "content") { | ||
val cursor: Cursor? = contentResolver.query(this, null, null, null, null) | ||
try { | ||
if (cursor != null && cursor.moveToFirst()) { | ||
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)) | ||
} | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
cursor?.close() | ||
} | ||
} | ||
if (result == null) { | ||
result = path | ||
val cut = result!!.lastIndexOf('/') | ||
if (cut != -1) { | ||
result = result.substring(cut + 1) | ||
} | ||
} | ||
return result | ||
} |
Oops, something went wrong.