Skip to content

Instantly share code, notes, and snippets.

View Nimrodda's full-sized avatar

Nimrod Dayan Nimrodda

View GitHub Profile
class DetailActivity : AppCompatActivity() {
@Inject
internal lateinit var detailViewModelFactory: DetailViewModelFactory
private val viewModel: DetailViewModel by viewModels {
GenericSavedStateViewModelFactory(detailViewModelFactory, this)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
class GenericSavedStateViewModelFactory<out V : ViewModel>(
private val viewModelFactory: ViewModelAssistedFactory<V>,
owner: SavedStateRegistryOwner,
defaultArgs: Bundle? = null
) : AbstractSavedStateViewModelFactory(owner, defaultArgs) {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(
key: String,
modelClass: Class<T>,
handle: SavedStateHandle
class DetailViewModel( // Remove @Inject annotation from here
private val handle: SavedStateHandle
private val githubApi: GithubApi,
) : ViewModel() {
fun loadData() {
val id = handle["id"] ?: "default"
viewModelScope.launch {
val response = githubApi.getCommit(id)
// Handle response
}
@Nimrodda
Nimrodda / move-check.py
Last active February 1, 2020 13:18
Python script for verifying moved files in an Android projects with variants
"""
Helper script for verifying moved files match variant folders in an Android project.
Useful when modularizing.
Pipe the script to a Git diff command like so:
git --no-pager diff develop --name-status -R|python move-check.py
"""
import re
import sys
@Nimrodda
Nimrodda / maven-publish.gradle
Last active September 9, 2019 13:42
Script for publishing Android Kotlin libraries to Maven repository with sources and KDocs included
/*
* Script for publishing Android Kotlin libraries to Maven repository with sources and KDocs included.
* Inspired by: https://github.com/JakeWharton/butterknife/blob/f0b735144d24592d665eeff90051b6adea2e564a/gradle/gradle-mvn-push.gradle
* Copy this file to your project's root dir and then apply it to the bottom of build.gradle of the modules you wish
* to publish: apply from: '../maven-publish.gradle`
* The publish with the following command:
* ./gradlew :modulename:uploadArchives
* Note that this script doesn't define signing configuration. See link above for example.
* This scripts requires the presence of a gradle.properties file in the module's root
* with the following properties defined:
@Nimrodda
Nimrodda / letsencrypt-wildcard-renewal.md
Last active February 17, 2024 12:53
Setup automatic LetsEncrypt wildcard certificate renewal on Ubuntu server 18.04 with Namecheap

All credits go to by Bryan Roessler for his original post that I followed on how to setup LetsEncrypt wildcard certificate auto-renewal with Namecheap. I highly recommend you read his tutorial first and if you bump into issues, check out this gist next.

Unfortunately the original article is not up-to-date and doesn't have the option to leave comments so I can't communicate with the author for updates so I decided to write the updates in a Gist. I highlighted the sections that required an updated with Correction #:. I managed to get the correct setup with the help of the amazing guys at LetsEncrypt community. Here's the help thread.

Set up acme-dns

  1. Download acme-dns from https://github.com/joohoi/acme-dns/releases
  2. Move the binary somewhere sensible since we will be using
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GamesListActivity">
<androidx.recyclerview.widget.RecyclerView
class GamesListActivity : AppCompatActivity() {
private val viewModel by lazy {
ViewModelProviders.of(this).get(GamesListViewModel::class.java)
}
private val gamesListController = GamesListController()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
class GamesListViewModel : ViewModel() {
val gamesLiveData: LiveData<Container>
get() = _liveData
private val _liveData = MutableLiveData<Container>()
private val onGenreExpanded: OnGenreExpanded = { genre: Genre ->
val oldContainer = _liveData.value
if (oldContainer != null) {
val newGenres = oldContainer.genres.map {
if (it.genre.id == genre.id) {
class GamesListController : TypedEpoxyController<Container>() {
override fun buildModels(container: Container?) {
container?.genres?.forEach {
header {
id(it.header.id)
genre(it.genre)
onHeaderExpanded { model, _, _, _ ->
container.onGenreExpanded(model.genre())
}
}