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 SimpleIdlingResource(private val resourceName: String) : IdlingResource { | |
private val isIdle = AtomicBoolean(true) | |
// written from main thread, read from any thread. | |
@Volatile private var resourceCallback: IdlingResource.ResourceCallback? = null | |
override fun getName(): String = resourceName | |
override fun isIdleNow(): Boolean = isIdle.get() |
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
// Expose resource IDs instead | |
public class MyViewModel extends ViewModel { | |
public final MutableLiveData<Int> statusLabel = new MutableLiveData<>(); | |
public SampleViewModel() { | |
... | |
statusLabel.setValue(R.string.labelString); | |
} | |
} |
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
// Don't do this | |
public class MyViewModel extends AndroidViewModel { | |
public final MutableLiveData<String> statusLabel = new MutableLiveData<>(); | |
public SampleViewModel(Application context) { | |
super(context); | |
statusLabel.setValue(context.getString(R.string.labelString)); | |
} | |
} |
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
val binding = DataBindingUtil.setContentView<TheGeneratedBinding>( | |
this, | |
R.layout.activity_data_binding | |
) | |
binding.lifecycleOwner = this // Use viewLifecycleOwner for fragments | |
binding.name = myLiveData // or myViewModel |
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
val binding = DataBindingUtil.setContentView<TheGeneratedBinding>( | |
this, | |
R.layout.activity_data_binding | |
) | |
binding.name = myLiveData // or myViewModel |
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 MyViewModel : ViewModel() { | |
private val _name = MutableLiveData<String>().apply { value = "Ada" } | |
val name: LiveData<String> = _name // Expose the immutable version of the LiveData | |
} |
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 MyViewModel : ViewModel() { | |
val name = ObservableField<String>("Ada") | |
} |
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
<data> | |
<import type="android.arch.lifecycle.LiveData" /> | |
<variable | |
name="name" | |
type="LiveData<String>" /> | |
</data> | |
… | |
<TextView | |
android:text="@{name}" | |
android:layout_width="wrap_content" |
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
<data> | |
<import type="android.databinding.ObservableField"/> | |
<variable | |
name="name" | |
type="ObservableField<String>" /> | |
</data> | |
… | |
<TextView | |
android:text="@{name}" | |
android:layout_width="wrap_content" |
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 getDataForUser(newUser: String?): LiveData<UserDataResult> { | |
if (newUser == null) { | |
return MutableLiveData<UserDataResult>().apply { value = null } | |
} | |
return userOnlineDataSource.getOnlineTime(newUser) | |
.combineAndCompute(userCheckinsDataSource.getCheckins(newUser)) { a, b -> | |
UserDataSuccess(a, b) | |
} | |
} |