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
interface ConnectivityObserver { | |
fun observe(): Flow<Status> | |
enum class Status { | |
Available, Unavailable, Losing, Lost | |
} | |
} |
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 singleValueEvent((ref: DatabaseReference ,onCancellation: CancellationCallback = {}),onCancellation: CancellationCallback = {}): DataResponse<DataSnapshot> { | |
return suspendCancellableCoroutine { continuation -> // can use suspendCoroutine not worry about cancellation | |
val valueEventListener = object : ValueEventListener { | |
override fun onCancelled(error: DatabaseError) { | |
continuation.resume(DataResponse.Error(error.toException()), onCancellation) // setting data | |
} | |
override fun onDataChange(snapshot: DataSnapshot) { | |
continuation.resume(DataResponse.Changed(snapshot), onCancellation) | |
} |
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
// calling the Activity B | |
resultLauncher.launch(Intent(requireContext(), B::class.java)) | |
// we get data in here from B | |
private var resultLauncher = | |
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> | |
when (result.resultCode) { | |
Activity.RESULT_OK -> { | |
result.data?.getStringExtra("VALUE")?.let { | |
// data received here |
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 android.content.SharedPreferences | |
import androidx.appcompat.app.AppCompatDelegate | |
private const val COUNTRY_CODE = "COUNTRY_CODE" | |
private const val FIRST_TIME = "FIRST_TIME" | |
private const val THEME = "theme" | |
private const val PREVIOUS_USER = "PREVIOUS_USER" | |
class PrefManager(val context: Context, private val preferenceName: String = "eldhopj") { |