This file contains hidden or 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
val bottomSheetState = rememberStandardBottomSheetState() | |
val scaffoldState = rememberBottomSheetScaffoldState(bottomSheetState) | |
BottomSheetScaffold( | |
modifier = Modifier.fillMaxSize(), | |
scaffoldState = scaffoldState, | |
sheetContainerColor = Color.Transparent, | |
sheetContent = { | |
// Put whatever the sheet you want in here | |
} |
This file contains hidden or 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
fun SomeComposable(){ | |
val bottomSheetState = rememberStandardBottomSheetState() | |
val scaffoldState = rememberBottomSheetScaffoldState(bottomSheetState) | |
var currentOffset by remember { mutableFloatStateOf(0f) } | |
runCatching { | |
LaunchedEffect(bottomSheetState.requireOffset()) { | |
snapshotFlow { bottomSheetState.requireOffset() } | |
.collect { currentOffset = it } |
This file contains hidden or 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
override fun onReceive(context: Context?, intent: Intent?) { | |
context?.let { | |
Log.d("InteractiveNotificationBroadcastReceiver", "onReceive") | |
val notification = NotificationCompat.Builder(context, CHANNEL_ID) | |
.setSmallIcon(R.drawable.ic_launcher_foreground) | |
.setContentTitle("Interactive Notification Title") | |
.setContentText("MODIFIED text") | |
.setContentIntent(newPendingIntent(context)) | |
.build() | |
NotificationManagerCompat.from(context) |
This file contains hidden or 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
val builder = NotificationCompat.Builder(this, CHANNEL_ID) | |
.setSmallIcon(R.drawable.ic_launcher_foreground) | |
.setContentTitle("Interactive Notification Title") | |
.setContentText("Interactive Notification Text") | |
.setContentIntent(InteractiveNotificationBroadcastReceiver.newPendingIntent(this)) | |
val soCloseInteractiveNotification = builder.build() |
This file contains hidden or 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
class InteractiveNotificationBroadcastReceiver : BroadcastReceiver() { | |
override fun onReceive(context: Context?, intent: Intent?) { | |
Log.d("InteractiveNotificationBroadcastReceiver", "onReceive") | |
} | |
companion object { | |
fun newPendingIntent(context: Context): PendingIntent { | |
val intent = Intent(context, InteractiveNotificationBroadcastReceiver::class.java) | |
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) |
This file contains hidden or 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
val builder = NotificationCompat.Builder(this, CHANNEL_ID) | |
.setSmallIcon(R.drawable.ic_launcher_foreground) | |
.setContentTitle("Interactive Notification Title") | |
.setContentText("Interactive Notification Text") | |
val notSoInteractiveNotification = builder.build() |
This file contains hidden or 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
private fun createNotificationChannel() { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
val importance = NotificationManager.IMPORTANCE_DEFAULT | |
val channel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME, importance).apply { | |
description = CHANNEL_DESCRIPTION | |
} | |
val notificationManager: NotificationManager = | |
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | |
notificationManager.createNotificationChannel(channel) | |
} |
This file contains hidden or 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
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { | |
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) { | |
super.onScrolled(recyclerView, dx, dy) | |
if ((recyclerView?.layoutManager as LinearLayoutManager) | |
.findFirstCompletelyVisibleItemPosition() == 0) { | |
buttonReturnToTop.visibility = View.GONE | |
} | |
} | |
}) |
This file contains hidden or 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
recyclerView.layoutManager = object : | |
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) { | |
override fun onLayoutCompleted(state: RecyclerView.State?) { | |
super.onLayoutCompleted(state) | |
if (showReturnToTopButton | |
&& (findLastVisibleItemPosition() | |
- findFirstVisibleItemPosition() | |
+ 1 | |
< adapter.itemCount)) { | |
buttonReturnToTop.visibility = View.VISIBLE |
This file contains hidden or 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
override fun start() { | |
itemDBObservable = itemDao.getAllItems() | |
compositeDisposable.clear() | |
compositeDisposable += itemDBObservable | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.scan { previousList: List<Item>, newList: List<Item> -> | |
val newItems = newList - previousList | |
if (previousList.isNotEmpty() && newItems.isNotEmpty()) { | |
showReturnToTopButton() |
NewerOlder