Skip to content

Instantly share code, notes, and snippets.

View shamshadpattani's full-sized avatar
:shipit:
Focusing

Muhammed shamshad p shamshadpattani

:shipit:
Focusing
View GitHub Profile
@shamshadpattani
shamshadpattani / DATABASE
Created June 1, 2020 09:36
Room database example
/**
* Abstract Foodium database.
* It provides DAO [DEtailsDap] by using method [getDEtailsDAO].
*/
@Database(
entities = [UserDetails::class],
version = 1,
exportSchema = false
)
class PreferenceHelper(private val mContext: Context = App.applicationContext()) {
fun putInt(key: String?, value: Int): PreferenceHelper {
val preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext)
val edit = preferences.edit()
edit.putInt(key, value)
edit.apply()
return this
}
object DataPersistenceManager {
private const val KEY_TOKEN = "dpm_token"
private var token: AccessToken? = null
fun getTokenDetails(c: Context): AccessToken? {
if(token == null) loadToken(c)
return token
}
@shamshadpattani
shamshadpattani / NetworkUtlis
Created May 9, 2020 17:12
Check the android device has internet connectivity or not. It ensure that it will be supported in all API levels or android versions. Using Kotlin
object NetworkUtils {
private val networkLiveData: MutableLiveData<Boolean> = MutableLiveData()
/**
* Returns instance of [LiveData] which can be observed for network changes.
*/
fun getNetworkLiveData(context: Context): LiveData<Boolean> {
val connectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager