Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Styl alexstyl

View GitHub Profile
@alexstyl
alexstyl / SafeContent.kt
Last active May 5, 2022
A Composable that will keep push its content so that they are not drawn behind the system bars. This is useful for when you want to work on a layout without having to worry about insets.
View SafeContent.kt
@Composable
fun SafeContent(
systemBarsColor: Color = Color(0xFF082A3A),
content: @Composable () -> Unit
) {
Box(
modifier = Modifier
.background(systemBarsColor)
.systemBarsPadding()
.background(MaterialTheme.colors.background)
View FromViewToComposable.kt
// instead of a LinearLayout (horizontal) use:
Row {
Text("Main Header")
Spacer(Modifier.weight(1f))
Text("23 mins ago")
}
// instead of FrameLayout use:
Box {
@alexstyl
alexstyl / ConversationItem.kt
Created Mar 21, 2022
Code sample for composables.co
View ConversationItem.kt
@Composable
fun ConversationItem(
modifier: Modifier = Modifier,
onClick: () -> Unit,
title: String,
snippet: String,
unread: Boolean = false,
timestamp: String,
profilePainters: List<Painter>,
) {
@alexstyl
alexstyl / CommonIntents.kt
Created Feb 23, 2022
Factory functions for common Intents in Android such as starting a call or sending an e-mail
View CommonIntents.kt
import android.content.Intent
import android.net.Uri
import android.provider.CalendarContract
import android.provider.Settings
import java.util.Calendar
fun sendTextMessage(phoneNumber: String): Intent {
return Intent(
Intent.ACTION_SENDTO,
smrUri(phoneNumber)
View Logs.kt
import android.util.Log
object Logs {
var isLoggingEnabled = false
private const val TAG = "Logs"
private const val PREFIX = ">>>PREFIX:"
fun verboseln(message: () -> String) {
if (isLoggingEnabled) {
View summaryViewModelFactory.kt
override fun summaryViewModelOf(viewModels: List<ContactEventNotificationViewModel>): SummaryNotificationViewModel {
val title = NaturalLanguageUtils.joinContacts(strings, contacts, MAX_CONTACTS)
val label = strings.dontForgetToSendWishes()
val lines = arrayListOf<CharSequence>()
viewModels.forEach { contactViewModel ->
val boldedTitle = SpannableString("${contactViewModel.title}\t\t${contactViewModel.label}").apply {
setSpan(StyleSpan(Typeface.BOLD), 0, contactViewModel.title.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
}
View notifyContacts.kt
private fun notifyContacts(viewModels: List<ContactEventNotificationViewModel>) {
viewModels.forEach { viewModel ->
val requestCode = NotificationConstants.CHANNEL_ID_CONTACTS.hashCode() + viewModel.hashCode()
val startIntent = PersonActivity.buildIntentFor(context, viewModel.contact)
val pendingIntent = PendingIntent.getActivity(
context,
requestCode,
startIntent,
PendingIntent.FLAG_UPDATE_CURRENT)
View gist:ed682669cddeba9462580f90f9be4926
private fun notifyContacts(viewModels: List<ContactEventNotificationViewModel>) {
viewModels.forEach { viewModel ->
val requestCode = NotificationConstants.CHANNEL_ID_CONTACTS.hashCode() + viewModel.hashCode()
val startIntent = PersonActivity.buildIntentFor(context, viewModel.contact)
val pendingIntent = PendingIntent.getActivity(
context,
requestCode,
startIntent,
PendingIntent.FLAG_UPDATE_CURRENT)
View RadiusTransition
class RadiusTransition private constructor(private val startingRadius: Float, private val endingRadius: Float) : Transition() {
override fun captureStartValues(transitionValues: TransitionValues) {
if (transitionValues.view is ImageView) {
transitionValues.values[PROPNAME_RADIUS] = startingRadius
}
}
override fun captureEndValues(transitionValues: TransitionValues) {
if (transitionValues.view is ImageView) {
View AndroidStringResources.class
package com.alexstyl.myapplication;
import android.content.res.Resources;
import android.support.annotation.StringRes;
class AndroidStringResources implements StringResources {
private final Resources resources;
AndroidStringResources(Resources resources) {