Skip to content

Instantly share code, notes, and snippets.

View MtaufiqH's full-sized avatar
🇮🇩
Indonesian

M. Taufiq Hidayat MtaufiqH

🇮🇩
Indonesian
View GitHub Profile
@MtaufiqH
MtaufiqH / activity_main.xml
Created May 26, 2022 11:56
Activity main UI Code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MainActivity">
<ImageView
android:id="@+id/ivFooter"
@MtaufiqH
MtaufiqH / Executor.kt
Created September 7, 2021 00:43
Executor to move another thread easier.
class AppExecutors @VisibleForTesting constructor(
private val diskIO: Executor,
private val networkIO: Executor,
private val mainThread: Executor
) {
companion object {
private const val THREAD_COUNT = 3
}
@MtaufiqH
MtaufiqH / BaseDao.kt
Created June 17, 2021 03:30 — forked from florina-muntenescu/BaseDao.kt
Use Dao inheritance to reduce the amount of boilerplate code - https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1
/*
* Copyright (C) 2017 The Android Open Source Project
*
* 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
@MtaufiqH
MtaufiqH / Event.kt
Created April 26, 2021 02:40 — forked from JoseAlcerreca/Event.kt
An event wrapper for data that is exposed via a LiveData that represents an event.
/**
* Used as a wrapper for data that is exposed via a LiveData that represents an event.
*/
open class Event<out T>(private val content: T) {
var hasBeenHandled = false
private set // Allow external read but not write
/**
* Returns the content and prevents its use again.
@MtaufiqH
MtaufiqH / Utils.kt
Created April 13, 2021 02:57
Utilities view for visibility in the UI
fun View.show() {
visibility = View.VISIBLE
}
fun View.hide() {
visibility = View.GONE
}
inline fun <T : View> T.showIf(condition: (T) -> Boolean) {
@MtaufiqH
MtaufiqH / Main.kt
Created April 13, 2021 02:53
A dynamis SharedPrefs that implemented with GSON inspired by https://with.isfa.xyz/sharedpref-dinamis/
// to use it.
private val preferencesManager by lazy {
SharedPrefreencesManager(context)
}
private val key_uname = "username"
preferencesManager.add(key_uname, "isfaaghyth")
...
@MtaufiqH
MtaufiqH / Resource.kt
Created April 13, 2021 02:50
Resource for state management
sealed class Resource<out T> {
object Loading: Resource<Nothing>()
data class Success<out T>(val data: T) : Resource<T>()
data class Failure(val exception: Exception) : Resource<Nothing>()
}
@MtaufiqH
MtaufiqH / BaseViewHolder.kt
Last active April 13, 2021 02:48
Abstraction viewholder to make an dinamis holder data in recyclerview
import android.view.View
import androidx.recyclerview.widget.RecyclerView
abstract class BaseViewHolder<T>(itemView: View) : RecyclerView.ViewHolder(itemView) {
abstract fun bind(item: T)
}
@MtaufiqH
MtaufiqH / README.md
Created November 22, 2018 00:35 — forked from lopspower/README.md
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

All hex value from 100% to 0% alpha: