Skip to content

Commit

Permalink
Merge pull request #18 from erkutaras/develop
Browse files Browse the repository at this point in the history
convert kotlin ShowcaseUtil class
  • Loading branch information
erkutaras authored May 22, 2019
2 parents 4f8de55 + c978573 commit 30856eb
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ allprojects {
**Step 2.** Add the library dependency to your project build.gradle:
```
dependencies {
implementation 'com.github.erkutaras:ShowcaseView:1.3.1'
implementation 'com.github.erkutaras:ShowcaseView:1.3.2'
}
```

Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
targetSdkVersion 28
minSdkVersion 14
versionCode 14
versionName "1.3.1"
versionName "1.3.2"
}

buildTypes {
Expand Down

This file was deleted.

70 changes: 70 additions & 0 deletions library/src/main/java/com/erkutaras/showcaseview/ShowcaseUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.erkutaras.showcaseview

import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import android.content.res.Resources
import android.util.TypedValue

/**
* Created by erkutaras on 25.02.2018.
*/

class ShowcaseUtils {

companion object {

@JvmStatic
fun convertDpToPx(dp: Float): Float {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, Resources.getSystem().displayMetrics)
}

@JvmStatic
fun isNonNull(o: Any?): Boolean {
return o != null
}

@JvmStatic
fun isNull(o: Any?): Boolean {
return o == null
}

@JvmStatic
fun isNotZero(f: Float): Boolean {
return f != 0f
}
}

internal class ShowcaseSP @SuppressLint("CommitPrefEdits")
private constructor(appContext: Context) {

private val SHARED_PREF_NAME = "intro"

private val sharedPreferences: SharedPreferences
private val editor: SharedPreferences.Editor

private val sp by lazy { ShowcaseSP(appContext) }

init {
this.sharedPreferences = appContext.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE)
this.editor = sharedPreferences.edit()
}

fun show(key: String) {
editor.putBoolean(key, true)
editor.commit()
}

fun getShowing(key: String): Boolean {
return sharedPreferences.getBoolean(key, false)
}

companion object {

@JvmStatic
fun instance(appContext: Context): ShowcaseSP {
return ShowcaseSP(appContext).sp
}
}
}
}

0 comments on commit 30856eb

Please sign in to comment.