Skip to content

Instantly share code, notes, and snippets.

View coroutineDispatcher's full-sized avatar
💻
Androiding

Stavro Xhardha coroutineDispatcher

💻
Androiding
View GitHub Profile
ext {
compileSDKVersionValue = 29
minSDKVersionValue = 22
targetSDKVersionValue = 29
libraries = [
cardView : 'androidx.cardview:cardview:1.0.0',
androidXLegacySupport : 'androidx.legacy:legacy-support-v4:1.0.0',
androidXAppCompat : 'androidx.appcompat:appcompat:1.1.0',
@coroutineDispatcher
coroutineDispatcher / SetupViewModel.kt
Last active May 12, 2020 22:15
Current Setup ViewModel
class SetupViewModel @Inject constructor(private val setupRepository: SetupRepository) : ViewModel() {
//CoroutineContext:
private val completableJob = Job()
private val coroutineScope = CoroutineScope(Dispatchers.IO + completableJob)
//Other variables here
fun loadListOfCountries() {
//Fires in the IO thread.
inline fun <reified T : ViewModel> Fragment.viewModel(
crossinline provider: (SavedStateHandle) -> T
) = viewModels<T> {
object : AbstractSavedStateViewModelFactory(this, fragment.arguments ?: Bundle()) {
override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, handle: SavedStateHandle): T =
provider(handle) as T
}
}
javaCompileOptions {
annotationProcessorOptions {
arguments = mapOf(
"room.schemaLocation" to "$projectDir/schemas",
"room.incremental" to "true",
"room.expandProjection" to "true"
)
}
}
@ColumnInfo(name = "name")
val name: String? = "",
Room.databaseBuilder(appContext, AppDatabase.class, "Sample.db")
.createFromAsset("database/myapp.db")
.build()
class MainActivity : AppCompatActivity() {
private lateinit var viewPager: ViewPager2
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
viewPager = findViewById(R.id.my_view_pager)
val tabLayout = findViewById<TabLayout>(R.id.tabs)
val pagerAdapter = ScreenSlidePagerAdapter(this)
TabLayoutMediator(tabLayout, viewPager) { tab, position ->
when (position) {
0 -> tab.text = "Home"
1 -> tab.text = "School"
}
}.attach()
<androidx.viewpager2.widget.ViewPager2
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
compileSdkVersion(29)
defaultConfig {
applicationId = "com.sxhardha.someappName"
minSdkVersion(24)
targetSdkVersion(29)
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}