Skip to content

Instantly share code, notes, and snippets.

View erdemtopak's full-sized avatar
:octocat:

Erdem Topak erdemtopak

:octocat:
  • Flink
  • Berlin
View GitHub Profile
@erdemtopak
erdemtopak / Annotation Searcher
Created August 28, 2016 21:16
A python script that searches source files of project for input annotation or text
import os
import re
import sys
from glob import glob
# Example use :
# test.py /Users/topake/Code/ProjectName @AnnotationTest
def analyse_source_file(filePath):
inputFile = open(filePath, "r")
@erdemtopak
erdemtopak / constraint_guideline.xml
Created February 21, 2018 14:54
Constraint Guideline
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.Guideline
android:id="@+id/left_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@erdemtopak
erdemtopak / Android MVVM Architecture.md
Last active August 14, 2018 12:33
Android MVVM Architecture Guideline

Android MVVM Architecture

MVVM Overview

1. Definition of View

The view is the part that user interacts with. This is the entry point of information flow from user perspective. A view has a direct reference to the view model but view model does not have a direct reference to view. A view can use it's direct reference to interact with view model.

2. Definition of ViewModel

The view model is the layer that stands between view and model. It's main role is exposing streams of data relevant to the view and receive ui events from user interactions. In other words it holds the ui logic and state. We need to make sure that every action of user is goes through the view model and every logic related with view is placed on view model. Any kind of holding a view reference is strictly forbidden to prevent memory leaks. Additionally, it is not required to depends on concrete implementations, depending on abstractions provides us with i

import android.support.v7.util.DiffUtil
import android.support.v7.widget.RecyclerView
fun <T> RecyclerView.Adapter<*>.autoNotify(
currentList: MutableList<T>,
newList: List<T>,
checkItemsSame: (T, T) -> Boolean = { t1, t2 -> t1 === t2 },
checkContentsSame: (T, T) -> Boolean = { t1, t2 -> t1 == t2 }
) {
val currentListCopy = currentList.toList()
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import java.lang.ref.WeakReference
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
public fun <V : View> Fragment.bindView(id: Int): ReadOnlyProperty<Fragment, V> = ViewFinderProperty(id)
@erdemtopak
erdemtopak / RestartApp.kt
Created March 13, 2019 16:49
Restart Android Application
package com.erdem.test;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@erdemtopak
erdemtopak / ShakeAnim.kt
Created July 9, 2019 08:24
Shake Animation for TextInputFields
/* res/anim/shake.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="50"
android:fromXDelta="-0.3%"
android:repeatCount="5"
android:repeatMode="reverse"
android:toXDelta="0.3%"/>
</set>
@erdemtopak
erdemtopak / DrawableTransition.kt
Created July 9, 2019 08:45
Drawable Transition animation
/*
** res/drawable/transition_background.xml **
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_selection_label_background_gray" />
<item android:drawable="@drawable/shape_selection_label_background_blue" />
</transition>
** layout file **
@erdemtopak
erdemtopak / NoNotNullAssertionOperator.kt
Created August 1, 2019 13:55
Ktlint rule for `!!` (not-null assertion operator)
import com.github.shyiko.ktlint.core.Rule
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.lexer.KtTokens.EXCLEXCL
class NoNotNullAssertionOperator : Rule("no-notnull-assertion") {
override fun visit(
node: ASTNode,
autoCorrect: Boolean,
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit
@erdemtopak
erdemtopak / extend_trial.sh
Created December 17, 2019 10:35
Extend Trial
#!/bin/sh
rm ~/Library/Preferences/GoLand2019*/eval/*evaluation.key
# The one below not required right not but keep in mind
# rm ~/Library/Preferences/GoLand2019*/options/options.xml