Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
Focusing

Muhammed shamshad p shamshadpattani

💻
Focusing
View GitHub Profile
@shamshadpattani
shamshadpattani / NetworkUtlis
Created May 9, 2020
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
View NetworkUtlis
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
View PresitanceMANGER
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
}
View PRESISTRANCE MANAGER
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
}
@shamshadpattani
shamshadpattani / DATABASE
Created Jun 1, 2020
Room database example
View DATABASE
/**
* Abstract Foodium database.
* It provides DAO [DEtailsDap] by using method [getDEtailsDAO].
*/
@Database(
entities = [UserDetails::class],
version = 1,
exportSchema = false
)