Skip to content

Instantly share code, notes, and snippets.

View amalhanaja's full-sized avatar

Alfian Akmal Hanantio amalhanaja

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@amalhanaja
amalhanaja / md
Created June 2, 2018 13:50
README MD ReactiveConnectivity
# ReactiveConnectivity
ReactiveConnectivity - a library for Listen Connectivity Change on Android
[![API](https://img.shields.io/badge/API-15%2B-red.svg?style=flat)](https://android-arsenal.com/api?level=15)
[![](https://jitpack.io/v/amalhanaja/ReactiveConnectivity.svg)](https://jitpack.io/#amalhanaja/ReactiveConnectivity)
[![codebeat badge](https://codebeat.co/badges/f6612a30-4467-49b5-860f-98f9b34b8975)](https://codebeat.co/projects/github-com-amalhanaja-reactiveconnectivity-master)
ReactiveConnectivity is an Android Library to Listening NetworkConnectivity with RxJava Observables, It's written with Reactive Programming Approach. Library supports both new and legacy network monitoring.
## Installation
@amalhanaja
amalhanaja / ArgbEvaluator.kt
Created June 5, 2018 09:20
Slide Transisi Warna
private fun setParentBackgroundColor(offset: Float, position: Int): Int {
val bgColorList = listOf(
ContextCompat.getColor(baseActivity, R.color.blue),
ContextCompat.getColor(baseActivity, R.color.green)
)
return ArgbEvaluator().evaluate(
offset,
bgColorList[if (position > bgColorList.size - 1) 0 else position],
bgColorList[when {
@amalhanaja
amalhanaja / ParallaxPagerTransformer.kt
Created June 5, 2018 09:27
Parralax Page Transformer
class ParallaxPagerTransformer : ViewPager.PageTransformer {
override fun transformPage(page: View, position: Float) {
val pageWidth = page.width
val pageWidthTimesPosition = pageWidth.times(position)
val imageScreen = page.findViewById<ImageView>(R.id.img_screen)
val imageBgTop = page.findViewById<ImageView>(R.id.img_bg_top)
val staticPosition = position <= -1.0f || position >= 1.0f
val zeroPosition = position == 0.0f
@amalhanaja
amalhanaja / ItemOffsetsDecorator.kt
Created September 15, 2018 14:56
ItemOffsetDecorator for RecyclerView
class ItemOffsetsDecorator(
private val block: (position: Int, count: Int, rect: Rect) -> Unit
): RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect?, view: View?, parent: RecyclerView?, state: RecyclerView.State?) {
super.getItemOffsets(outRect, view, parent, state)
parent?.getChildAdapterPosition(view)?.run position@ {
outRect?.run rect@ {
state?.itemCount?.run count@ {
block.invoke(this@position, this@count, this@rect)
fun updateWidget(context: Context) {
val appWidgetManager = AppWidgetManager.getInstance(context)
val favoriteAppWidget = ComponentName(context, FavoriteAppWidget::class.java)
val widgetIds = appWidgetManager.getAppWidgetIds(favoriteAppWidget)
val intent = Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE)
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds)
context.sendBroadcast(intent)
}
@amalhanaja
amalhanaja / ConsumerActivity.kt
Last active July 24, 2020 03:54
Content Provider Dao
class ConsumerActivity : AppCompatActivity(R.layout.activity_main) {
companion object {
private const val KEY_SAVED_INSTANCE_STATE_MAIN_ITEM = "MAIN_ITEM"
}
private val adapter: MainAdapter by lazy {
MainAdapter()
}
@amalhanaja
amalhanaja / start-mysql-runtime.sh
Created September 16, 2022 17:35
Docker Container .sh
docker run --rm \
--name=mysql-runtime \
-e MYSQL_ROOT_PASSWORD=password \
-e MYSQL_DATABASE=development \
-v ./data/mysql:/var/lib/mysql \
-p 3306:3306 \
-d mysql:latest
@amalhanaja
amalhanaja / semantic-commit-messages.md
Created September 20, 2022 00:09 — forked from joshbuchea/semantic-commit-messages.md
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

val KEY_NAME = stringPreferencesKey("name")
class UserRepository(
private val dataStore: DataStore<Preferences>,
) {
val name: Flow<String> = dataStore.data.map { preferences ->
preferences[KEY_NAME].orEmpty()
}
suspend fun setName(name: String) {