Skip to content

Instantly share code, notes, and snippets.

View soulduse's full-sized avatar
💭
🔥

Dave soulduse

💭
🔥
View GitHub Profile
@soulduse
soulduse / build.gradle.kts
Created December 13, 2020 03:13
Root Gradle 설정
val projectGroup: String by project
val projectVersion: String by project
val kotlinVersion: String by project
val ktlintVersion: String by project
plugins {
val kotlinVersion = "1.4.10"
kotlin("jvm") version kotlinVersion
kotlin("kapt") version kotlinVersion
}
@soulduse
soulduse / blog-post.kt
Created August 25, 2019 06:12
Open app or go to the google play store market in Android with Kotlin
// 앱이 설치 설치되었는지 판단하는 함수
fun Context.isInstalledApp(packageName: String): Boolean {
val intent = packageManager.getLaunchIntentForPackage(packageName)
return intent != null
}
// 특정 앱을 실행하는 함수
fun Context.openApp(packageName: String) {
val intent = packageManager.getLaunchIntentForPackage(packageName)
startActivity(intent)
@soulduse
soulduse / Sort.kt
Last active July 5, 2019 01:00
How to sort based on/compare multiple values in Kotlin?
class SortTest {
@Test
fun `sorting`() {
DUMMY.sortedWith(
compareByDescending<SortItem> { it.bool }
.thenBy { it.num }
.thenBy { it.date }
.thenBy { it.name }
).print()
@soulduse
soulduse / HmacGenerator.kt
Created April 11, 2019 08:24
HmacGenerator for Coupang partners with Kotlin
import org.apache.commons.codec.binary.Hex
import java.nio.charset.Charset
import java.security.GeneralSecurityException
import java.text.SimpleDateFormat
import java.util.*
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
object HmacGenerator {
@soulduse
soulduse / AndroidManifest.xml
Last active October 24, 2018 09:47
When I copied some text in Android, How to get copied text from listener.
<application ...>
...
<service android:name=".ClipboardService"/>
</application>
@soulduse
soulduse / AndroidManifest.xml
Last active October 22, 2018 05:49
Auto launch apps randomly.
<application .. >
...
<service android:name=".StartAppService"/>
</application>
@soulduse
soulduse / DLog.kt
Last active September 12, 2018 05:48
This is log util for Android. You don't need TAG and care about showing log after released.
/**
* Usage
* DLog.w("This is awesome!")
*
* print -> W/Dave: [xx.kt::methodName]This is awesome!
*/
object DLog {
private const val TAG : String = "Dave"
fun e(message : String){
@soulduse
soulduse / ApiInterface.kt
Last active May 7, 2022 08:48
ver.2) Example of usage kotlin-coroutines-retrofit
interface ApiInterface {
@GET("User")
fun getUser(
@Query("user_id") userId: String
): Deferred<User>
}
class DynamicImageView: LinearLayout {
private var imagesPath = mutableListOf<String>()
private val horizontalLayoutParam by lazy { LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT) }
private val weightZeroLayoutParam by lazy { LinearLayout.LayoutParams(0, 380, 1F) }
constructor(context: Context) : super(context)
fun addImage(vararg path: String) : DynamicImageView {
@soulduse
soulduse / ankoExt.kt
Created February 16, 2018 11:18
Anko Extensions
inline fun ViewManager.flexboxLayout(theme: Int = 0, init: FlexboxLayout.() -> Unit) = ankoView(::FlexboxLayout, theme, init)
inline fun ViewManager.swipeRefreshLayout(theme: Int = 0, init: SwipeRefreshLayout.() -> Unit) = ankoView(::SwipeRefreshLayout, theme, init)
inline fun ViewManager.zoomTextView(theme: Int = 0, init: ZoomTextView.() -> Unit) = ankoView(::ZoomTextView, theme, init)
inline fun ViewManager.textView(theme: Int = 0, init: TextView.() -> Unit) = ankoView(::TextView, theme, init)
inline fun ViewManager.imageView(theme: Int = 0, init: ImageView.() -> Unit) = ankoView(::ImageView, theme, init)
inline fun ViewManager.view(theme: Int = 0, init: View.() -> Unit) = ankoView(::View, theme, init)
inline fun ViewManager.button(theme: Int = 0, init: Button.() -> Unit) = ankoView(::Button, theme, init)