Skip to content

Instantly share code, notes, and snippets.

@BurakDizlek
BurakDizlek / MyServiceClass.kt
Last active July 16, 2018 13:11
Retrofit Settings Sample
object MyService {
private val TIMEOUTOFSECOND = 12
private val _instanceOfService: Service by lazy { setupHttpClient() }
fun on(): Service {
return _instanceOfService
}
@BurakDizlek
BurakDizlek / Service.kt
Last active August 25, 2017 08:47
Retrofit interface sample
interface Service {
@FormUrlEncoded
@POST("info/getInfoDetail")
fun GetInfoDetail(@FieldMap params: HashMap<String, Any>): Call<InfoDetailObject>
@GET("search/{search_word}")
fun getSuggestSearchWords(@Path("search_word") search_word: String): Call<SearchWorObject>
@BurakDizlek
BurakDizlek / Share.kt
Last active August 25, 2017 09:07
SharedPreferences Helper Class
class Share private constructor() {
private var context: Context? = null
private var preferences: SharedPreferences? = null
companion object {
private val PREF_NAME = "_Share"
private val ourInstance: Share by lazy { setInstance() }
private fun setInstance(): Share {
@BurakDizlek
BurakDizlek / MyApplication.kt
Created August 25, 2017 09:17
Application Class Sample for access context in everywhere
class MyApplication : Application() {
//sample usage : MyApplication.context
override fun onCreate() {
super.onCreate()
instance = this
}
companion object {
@BurakDizlek
BurakDizlek / HashUtils.kt
Created October 25, 2017 14:28 — forked from kobeumut/HashUtils.kt
I found Sam Clarke's kit. SHA 512 etc.
package com.samclarke.android.util
import java.security.MessageDigest
/**
* Hashing Utils
* @author Sam Clarke <www.samclarke.com>
* @license MIT
*/
object HashUtils {
@BurakDizlek
BurakDizlek / navigationViewSlide.kt
Last active November 6, 2017 10:22
Navigation View pust to content screen.
val toggle = object : ActionBarDrawerToggle(this, binding.drawerLayout, null, R.string.ok, R.string.close) {
override fun onDrawerSlide(drawerView: View?, slideOffset: Float) {
super.onDrawerSlide(drawerView, slideOffset)
if (drawerView === binding.navigationView)
binding.screen.translationX = slideOffset * drawerView.width
else if (drawerView === binding.navigationViewRight)
binding.screen.translationX = -(slideOffset * drawerView.width)
binding.drawerLayout.bringChildToFront(drawerView)
binding.drawerLayout.requestLayout()
}
if (supportFragmentManager.findFragmentByTag("searchfragment") != null) { // to kill a specific Fragment
supportFragmentManager().popBackStack();
} else {
//Do Something
}
private fun closeFragments() {
repeat(supportFragmentManager.backStackEntryCount) {
supportFragmentManager.popBackStack()
@BurakDizlek
BurakDizlek / safeEnumKotlin.kt
Last active June 14, 2019 09:27
no enum constant for default safe enum value
inline fun <reified T : kotlin.Enum<T>> safeEnumValueOf(type: String?,defaultEnum:T): T {
return try {
java.lang.Enum.valueOf(T::class.java, type)
} catch (e: Exception) {
defaultEnum
}
}
fun sureChildViewVisibleOnScreen(childView: View, parenView: View): Boolean {
val scrollBounds = Rect()
parenView.getHitRect(scrollBounds)
return childView.getLocalVisibleRect(scrollBounds) // if childView visible return true else false
}
@BurakDizlek
BurakDizlek / TableViewClickExampleViewController.swift
Last active October 24, 2022 22:48
Swift Tableview Cell Click Event
var items = [MyModelClass]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableCell") as! TableCell
let position = indexPath.row
let item = items?[position]
//click event for label
let labelRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.tableViewLabelClick))
cell.Label?.isUserInteractionEnabled = true