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
dependencies { | |
// DataStore | |
implementation "androidx.datastore:datastore-preferences:1.0.0" | |
implementation "androidx.datastore:datastore-preferences-core:1.0.0" | |
} |
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
val Context.user: DataStore<Preferences> by preferencesDataStore(name = "userInfo") |
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
object DataStoreKeys { | |
val USER_NAME = stringPreferencesKey("user_name") | |
val EMAIL = stringPreferencesKey("email") | |
} |
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
private suspend fun saveUserData(name: String, email: String) { | |
user.edit { usrData -> | |
usrData[DataStoreKeys.USER_NAME] = name | |
usrData[DataStoreKeys.EMAIL] = email | |
} | |
} |
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
private suspend fun getUserData() { | |
user.data.collect { usrData -> | |
val name = usrData[DataStoreKeys.USER_NAME] ?: "none" | |
val email = usrData[DataStoreKeys.EMAIL] ?: "none" | |
} | |
} |
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
private suspend fun deleteUserData() { | |
user.edit { usrData -> | |
usrData.clear() | |
} | |
} |
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
import android.annotation.SuppressLint | |
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import androidx.datastore.preferences.core.edit | |
import co.encept.datastore.databinding.ActivityMainBinding | |
import kotlinx.coroutines.CoroutineScope | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.launch | |
class MainActivity : AppCompatActivity() { |
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
""" | |
Made By Karim Abdallah, Android Engineer. | |
contact: karim@kotect.com | |
website: https://kotect.com | |
""" | |
import time | |
import random | |
CHOICES = { |
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
""" | |
Made By Karim Abdallah, Android Engineer. | |
contact: karim@kotect.com | |
website: https://kotect.com | |
""" | |
import json | |
import discord | |
import requests | |