-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from erkutaras/develop
convert kotlin ShowcaseUtil class
- Loading branch information
Showing
4 changed files
with
72 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 0 additions & 60 deletions
60
library/src/main/java/com/erkutaras/showcaseview/ShowcaseUtils.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
library/src/main/java/com/erkutaras/showcaseview/ShowcaseUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |