Skip to content

Instantly share code, notes, and snippets.

View sebaslogen's full-sized avatar

Sebas LG sebaslogen

View GitHub Profile
@sebaslogen
sebaslogen / item-server-driven-ui.json
Last active September 12, 2019 13:56
Item from Server Driven UI JSON example for post
{
"title": "Dance - Smith Quartet",
"image": "https://demo.com/624.jpg",
"action": {
"type": "ComponentScreen",
"url": "/query/view/album/635212023624"
}
}
@sebaslogen
sebaslogen / server-driven-ui.json
Last active September 6, 2024 17:18
Server Driven UI simple JSON example for post
{
"type": "componentScreen",
"title": "Home",
"sections": [
{
"title": "New Releases",
"type": "album",
"items": [
{
"title": "Dance - Smith Quartet",
@sebaslogen
sebaslogen / old-style.json
Last active August 8, 2019 14:18
Old style json for Server Driven UI post
[
{
"id": 0362403,
"title": "Dance - Smith Quartet",
"image": "https://demo.com/03624.jpg"
},
{
"id": 06083706,
"title": "Sixteen Contemporary Love Songs for Piano",
"image": "https://demo.com/060837.jpg"
@sebaslogen
sebaslogen / Toolbar.java
Last active March 3, 2018 14:43
Imaginary new Android Toolbar constructor
public class Toolbar extends ViewGroup {
public Toolbar(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, getToolbarStyle());
}
private static int getToolbarStyle() {
return (BuildConfig.VERSION_CODE >= Build.VERSION_CODES.O) ? R.attr.newCompatToolbarStyle : R.attr.toolbarStyle;
}
}
@sebaslogen
sebaslogen / Toolbar.java
Created March 3, 2018 10:46
Android Toolbar constructor
public class Toolbar extends ViewGroup {
public Toolbar(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, R.attr.toolbarStyle);
}
}
@sebaslogen
sebaslogen / MyCustomView.kt
Created March 3, 2018 10:37
Kotlin Android CustomView with default parameters
class MyCustomView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr)
@sebaslogen
sebaslogen / MyCustomView.kt
Created March 3, 2018 10:34
Kotlin Android CustomView without default parameters
class MyCustomView : View {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, attributeSetId: Int) : super(context, attrs, attributeSetId)
}
@sebaslogen
sebaslogen / MyAndroidApplication.kt
Created January 28, 2018 17:06
Finish all opened activities in my Android app (also across different tasks)
class MainApplication : Application() {
private val createdActivities = mutableListOf<WeakReference<Activity>>()
override fun onCreate() {
super.onCreate()
registerActivityLifecycleCallbacks(activityLifecycleCallbacks())
}
fun closeAllActivities() {
@sebaslogen
sebaslogen / LiveObservable.kt
Created July 9, 2017 21:15
LiveObservable: Android lifecycle aware wrapper for an RxJava Observable
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.LifecycleOwner
import android.arch.lifecycle.OnLifecycleEvent
import com.jakewharton.rxrelay.BehaviorRelay
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
import rx.functions.Action1
import rx.subscriptions.CompositeSubscription
@sebaslogen
sebaslogen / Project_Default.xml
Last active October 3, 2016 09:50
Autocorrect suggestion: Escape apostrophes in Android string XMLs (file should be inside .idea/inspectionProfiles/)
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AndroidLintDrawAllocation" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SSBasedInspection" enabled="true" level="ERROR" enabled_by_default="true">
<replaceConfiguration name="Escape apostrophes in Android string XMLs" text="&lt;string $attributes$&gt;$text$&lt;/string&gt;" recursive="false" caseInsensitive="true" type="XML" reformatAccordingToStyle="true" shortenFQN="true" useStaticImport="true" replacement="&lt;string $attributes$&gt;$fixedText$&lt;/string&gt;">
<constraint name="attributes" minCount="0" maxCount="2147483647" within="" contains="" />
<constraint name="text" regexp=".*[^\\]'.*" maxCount="2147483647" within="" contains="" />
<variableDefinition name="fixedText" script="&quot;text.getValue().replaceAll( &quot;\\\\'|\'&quot;, &quot;\\\\'&quot; )&quot;" />
</replace