This file contains hidden or 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.content.Context | |
import android.net.ConnectivityManager | |
import android.net.Network | |
import android.net.NetworkCapabilities | |
import android.net.NetworkRequest | |
import android.os.Build | |
import androidx.lifecycle.LiveData | |
import androidx.lifecycle.MutableLiveData | |
/** |
This file contains hidden or 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
fun observeSet(id: String) = resultLiveData( | |
databaseQuery = { dao.getLegoSet(id) }, | |
networkCall = { legoSetRemoteDataSource.fetchSet(id) }, | |
saveCallResult = { dao.insert(it) }) | |
/** | |
* Creates a new [LiveData] object does not emit a value until the source `this` LiveData value | |
* has been changed. The value is considered changed if `equals()` yields `false`. | |
*/ | |
.distinctUntilChanged() |
This file contains hidden or 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
class Converters | |
{ | |
@TypeConverter fun calendarToDatestamp(calendar: Calendar): Long = calendar.timeInMillis | |
@TypeConverter fun datestampToCalendar(value: Long): Calendar = | |
Calendar.getInstance().apply { timeInMillis = value } | |
} |
This file contains hidden or 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.content.Context | |
import android.net.ConnectivityManager | |
import android.net.NetworkInfo | |
object ConnectivityUtil | |
{ | |
fun isConnected(context: Context): Boolean | |
{ | |
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
val activeNetwork: NetworkInfo? = cm.activeNetworkInfo |
This file contains hidden or 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
btn_customToast.setOnClickListener {_button -> | |
Toast(this).showCustomToast ( | |
et_message.text.toString().trim(), | |
this | |
) | |
} |
This file contains hidden or 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
fun Toast.showCustomToast(message: String, activity: Activity) | |
{ | |
val layout = activity.layoutInflater.inflate ( | |
R.layout.custom_toast, | |
activity.findViewById(R.id.cl_customToastContainer) | |
) | |
val textView = layout.findViewById<TextView>(R.id.tv_message) | |
textView.text = message |
This file contains hidden or 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
btn_customToast.setOnClickListener { | |
showCustomToast(et_message.text.toString().trim()) | |
} |
This file contains hidden or 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 fun showCustomToast(message: String) | |
{ | |
val layout = layoutInflater.inflate ( | |
R.layout.custom_toast, | |
findViewById(R.id.cl_customToastContainer) | |
) | |
val textView = layout.findViewById(R.id.tv_message) | |
textView.text = message |
This file contains hidden or 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
<LinearLayout | |
android:id="@+id/cl_customToastContainer" | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:padding="12dp" | |
android:orientation="horizontal" | |
android:gravity="center" | |
android:background="@drawable/shape_roundedcorners"> |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<shape | |
xmlns:android="http://schemas.android.com/apk/res/android"> | |
<solid | |
android:color="@color/light_green"/> | |
<corners | |
android:radius="18dp"/> | |
<stroke | |
android:color="@color/green" |
NewerOlder