Skip to content

Instantly share code, notes, and snippets.

View pdegand's full-sized avatar

Pierre Degand pdegand

  • Octo Technology
  • Paris, France
View GitHub Profile
@pdegand
pdegand / MainActivity.kt
Last active August 1, 2019 12:56
Weird Race condition with Channels and ViewModel/LiveData
class MainActivity : AppCompatActivity(R.layout.activity_main) {
private val viewModel by viewModels<MainViewModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel.liveData.observe(this, Observer {
Log.d("MAIN", "Display $it in view")
@pdegand
pdegand / GridSpacingItemDecoration.java
Created April 19, 2016 09:18
A RecyclerView.ItemDecoration that you can apply on grids to have spacing between cells without using ugly margins on the cell layout. Feel free to use either the Kotlin version or the Java version.
/* The MIT License (MIT)
Copyright (c) 2016 Pierre Degand
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@pdegand
pdegand / ShinnyTextView.java
Last active November 9, 2018 17:47
Shinny TextView that glows like the "slide to unlock" text on iOS 7+
/*
* Copyright 2014 Pierre Degand
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
output.assemble << { // Clean the assets folder of all apk
ant.delete(includeEmptyDirs: 'true') {
fileset(dir: file('./src/main/assets/'), includes: '*.apk')
}
}
variant.outputs.each { output ->
task("handle${variant.name.capitalize()}WearDesc") << {
def apkFileName = "wear-${variant.flavorName}-${variant.buildType.name}.apk"
File wearDescFile = file("${output.processResources.resDir}/xml/wear_desc.xml")
String content = wearDescFile.getText('UTF-8')
content = content.replaceAll(/APPICATION_ID/, "${variant.mergedFlavor.applicationId}")
content = content.replaceAll(/VERSION_CODE/, "${variant.mergedFlavor.versionCode}")
content = content.replaceAll(/VERSION_NAME/, "${variant.mergedFlavor.versionName}")
content = content.replaceAll(/WEAR_BUILD/, apkFileName)
wearDescFile.write(content, 'UTF-8')
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is filled automatically at build time -->
<wearableApp package="APPICATION_ID">
<versionCode>VERSION_CODE</versionCode>
<versionName>VERSION_NAME</versionName>
<path>WEAR_BUILD</path>
</wearableApp>
project.afterEvaluate {
android.applicationVariants.all { variant ->
if (variant.buildType.name == 'release') {
tasks["generate${variant.name.capitalize()}Assets"]
.dependsOn(":wear:assemble${variant.name.capitalize()}")
}
}
}
android.applicationVariants.all { variant ->
if (variant.buildType.name == 'release') {
variant.outputs.each { output ->
output.assemble << {
println "Copying Wear APK inside mobile"
copy {
from output.outputFile.path
into "../mobile/src/main/assets"
}
android {
...
defaultConfig {
...
versionCode appVersionCode
versionName appVersionName
}
...
}
ext {
appVersionCode = 1
appVersionName = "1.0"
}