Skip to content

Instantly share code, notes, and snippets.

View n8ebel's full-sized avatar
🏠
Working from home

Nate Ebel n8ebel

🏠
Working from home
View GitHub Profile
@n8ebel
n8ebel / MainActivity.kt
Last active February 27, 2023 22:31
Basic example of using databinding to handle button clicks
class MainActivity : AppCompatActivity(), ViewModelListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main).bindData {
viewModel = MainViewModel("hello", 5, this@MainActivity)
}
}
@n8ebel
n8ebel / BindingAdapters.kt
Last active July 8, 2021 18:40
BindingAdapters for separation of viewmodels and Android framework for resource loading
// I would typically place this adapter in main/_BindingAdapters.kt
// The gist tool won't allow that filename structure
//
@BindingAdapter("mainSubtitleText")
fun setText(view: TextView, value:Int) {
view.text = view.context.getString(R.string.main_subtitle_format, value)
}
@BindingAdapter("textColor")
fun setTextColor(view: TextView, @ColorRes resId: Int) = view.setTextColor(ContextCompat.getColor(view.context, resId))
@n8ebel
n8ebel / ActivityBindingProvider.kt
Created November 22, 2017 07:10
A custom Kotlin delegate for initializing ViewDataBinding objects for Android databinding
/**
* Provides a [ViewDataBinding] object of the declared type by
* calling [DataBindingUtil.setContentView] with the property owning [Activity] and the specified
* layout resource id
*/
class ActivityBindingProvider<out T : ViewDataBinding>(
@LayoutRes private val layoutRes: Int) : ReadOnlyProperty<Activity, T> {
private var binding : T? = null
@BindingAdapter("uiState")
fun setUiStateForLoading(progressView: ProgressBar, uiState: UIState) {
progressView.visibility = when (uiState) {
Loading -> View.VISIBLE
else -> View.GONE
}
}
@BindingAdapter("uiState")
fun setUiStateForLoadedContent(view: View, uiState: UIState) {
@n8ebel
n8ebel / file_system_watching.scenarios
Last active August 25, 2020 21:33
Collection of gradle-profiler scenarios for benchmarking Android builds
//
// Non-abi change
//
1_non_abi_change {
title = "Non-api change to :location module"
tasks = [":app:assembleEnvQADebug"]
apply-non-abi-change-to = "location/src/main/java/com/premise/android/data/location/AndroidLocationProvider.java"
}
2_non_abi_change {
@n8ebel
n8ebel / gist:8d35aff899d583765304d80572931433
Created December 4, 2019 00:59
GitHub repository_dispatch curl command
curl -H "Accept: application/vnd.github.everest-preview+json" \
-H "Authorization: token <personal access token with repo access>" \
--request POST \
--data '{"event_type": "process-layouts"}' \
https://api.github.com/repos/pixiteapps/pigment-android/dispatches
@n8ebel
n8ebel / pull_request_template.md
Created June 7, 2019 21:32
Pull Request Template

Related To-Do

** link **

Proposed Changes

  • change 1
  • change 2

Additional Info

** any additional useful context or info **

@n8ebel
n8ebel / MainActivity.kt
Created February 19, 2018 04:24
Blink Rainbow HAT LED for Android Things
class MainActivity : Activity() {
private val TAG = MainActivity::class.java.simpleName
private val blinkHandler = Handler()
private var redLED: Gpio? = null
private val blinkRunnable = object : Runnable {
override fun run() {
redLED?.also {
@n8ebel
n8ebel / BaseActivity.kt
Last active January 25, 2018 05:09
Activity subscription to a ViewModel SnackData PublishSubject
fun bindViewModel(root:View, viewModel: BaseViewModel) {
viewModel.snackPub.subscribe { snackData ->
showSnackbar(rootView, snackData)
}
}
/**
* Maps the passed [SnackData] to the appropriate UI representation of a [Snackbar]
*/
private fun showSnackbar(root: View, data: SnackData) {
typealias SnackFinishedListener = () -> Unit
typealias SnackActionListener = () -> Unit
/**
* Representation of [Snackbar] data that can be exposed by a view model, observed, and bound to
* the current UI
*/
sealed class SnackData
/**