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
class NetworkFactoryTest { | |
private val baseUrl = "/" | |
private val testData = TestData("hello!") | |
private val testDataJson = "{\"name\":\"${testData.name}\"}" | |
private val mockWebServer = MockWebServer() | |
private val httpUrl = mockWebServer.url(baseUrl) | |
private val moshi = createMoshi() |
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
class FirebaseLiveData<T>( | |
private val reference: DatabaseReference, | |
private val resourceType: Class<T> | |
) : LiveData<Resource<T>>(), ValueEventListener { | |
override fun onActive() { | |
super.onActive() | |
if (value == null) { | |
value = Resource.loading() | |
} |
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
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
homeRecycler.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) | |
homeRecycler.adapter = adapter | |
homeViewModel.homePage.observe(this, Observer { resource -> | |
resource?.apply { | |
when (resource.status) { | |
SUCCESS -> { |
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
data class HomePage( | |
val locationInfo: LocationInfo? = null, | |
val travelInfo: TravelInfo? = null, | |
val weddingLocation: WeddingLocation? = null, | |
val weddingInfo: WeddingInfo? = null, | |
val weddingDate: WeddingDate? = null, | |
val welcome: WelcomeItem? = null | |
) |
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
data class MyViewData(val text: String) | |
class MyViewModel(application: Application): AndroidViewModel(application) { | |
private val _myViewData = MutableLiveData<MyViewData>() | |
val myViewData: LiveData<MyViewData> = _myViewData | |
fun updateViewData() { | |
val value = getDistance() |
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
data class MyViewData(val value: Int, val textId: Int, val labelId: Int) | |
class MyViewModel: ViewModel() { | |
private val _myViewData = MutableLiveData<MyViewData>() | |
val myViewData: LiveData<MyViewData> = _myViewData | |
fun updateViewData() { | |
val value = getDistance() |
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
sealed class MyViewData { | |
abstract val distance: Int | |
data class Km(override val distance: Int): MyViewData() | |
data class Miles(override val distance: Int): MyViewData() | |
} | |
class MyViewModel: ViewModel() { |
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
abstract class BaseSlice(val context: Context, val sliceUri: Uri) { | |
/** | |
* @return the slice implementation to be used by SliceProvider | |
*/ | |
abstract fun buildSlice(): Slice | |
/** | |
* Call refresh to notify the SliceProvider to load again. | |
*/ |
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 androidx.compose.Composable | |
import androidx.compose.unaryPlus | |
import androidx.ui.core.Text | |
import androidx.ui.core.dp | |
import androidx.ui.core.sp | |
import androidx.ui.foundation.shape.corner.RoundedCornerShape | |
import androidx.ui.graphics.Color | |
import androidx.ui.layout.* | |
import androidx.ui.material.MaterialTheme | |
import androidx.ui.material.surface.Card |
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
/** | |
* Copyright 2022 Google LLC. | |
* SPDX-License-Identifier: Apache-2.0 | |
*/ | |
@Composable | |
fun MyScreen(glanceAppWidget: GlanceAppWidget) { | |
val state = rememberAppWidgetHostState() | |
// the available size for the widget | |
val size = DpSize(200.dp, 200.dp) |