리오
08/05/2019, 9:45 PMval username = MutableLiveData<String>()
. In the xml, the edit text is defined as:
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/username_or_email"
android:inputType="textPersonName"
android:text="@={loginViewModel.username}" />
The login button is defined as:
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="65dp"
android:enabled="@{loginViewModel.loginButtonEnabled}"
android:onClick="@{() -> loginViewModel.onLogin()}"
android:text="@string/login"
app:layout_constraintEnd_toEndOf="@+id/password_text_input_layout"
app:layout_constraintTop_toBottomOf="@+id/password_text_input_layout" />
The loginButtonEnabled
is a variable in the LoginViewModel.
val loginButtonEnabled = Transformations.map(username) {
null != it
}
리오
08/05/2019, 9:46 PMmorozov
08/06/2019, 1:19 PMsamp
08/07/2019, 6:33 AMVishal
08/07/2019, 6:49 AMbin
folder is not getting generated in `SharedCode/build`folder
i rebuild the project, and was getting jar for andorid but not getting SharedCode/build/bin/iOS/main/debug/framework/SharedCode.framewor
only these folders are getting generated, see attached image.Alex Davidyuk
08/07/2019, 4:43 PMjw
08/07/2019, 5:17 PMPaul Dhaliwal
08/07/2019, 8:13 PMContextCompat.getColor(context, color.colorPrimaryDark)
which gives the error “type mismatch Required Context, Found Context?” I can get around this error by using “context as Context” or “context!!“, however these don’t feel like the right approaches. The Kotlin doc says !! is for “NPE-lovers” which I am not lol. What’s the best way to handle these situations? I’m still new to Kotlin and development in general and don’t want to develop any bad habits. Thanks!scottiedog45
08/08/2019, 1:20 AMsingleLargeTextInputViewModel = ViewModelProviders.of(this, SingleLargeInputViewModel.FACTORY(NetworkService())).get(
SingleLargeInputViewModel::class.java
)
) “know” (????) that a view model already exists? Or would it?myanmarking
08/08/2019, 9:07 AMZoneId.of(timeZone.id)
Branimir Conjar
08/08/2019, 3:29 PMarguments?.getString(FORCED_EMAIL).let {
binding.etEmail.setText(it)
binding.etEmail.isFocusable = false
binding.etEmail.isEnabled = false
}
getString()
returns null. Anyone has an idea why this goes through and executes statements inside let?TheDukerChip
08/09/2019, 4:31 AMandroidx.biometric
?jermainedilao
08/09/2019, 10:01 AMGunslingor
08/11/2019, 3:25 PMhenrikhorbovyi
08/12/2019, 4:06 PMlogs
on the code (with the purpose of future debug)?Simon Schubert
08/12/2019, 4:14 PMobject L {
private const val TAG = "FOOBAR"
fun e(log: String) {
if (BuildConfig.DEBUG) {
Log.e(TAG, log)
}
}
...
}
Marc Knaup
08/12/2019, 9:15 PMval myData = liveData { … }
extension.
How can I achieve the same with MutableLiveData
? There is no mutableLiveData { … }
.
1. Load document from DB using a coroutine upon activation (onActive
).
2. Update view model when Fragment requests changes & save them to DB (also using a coroutine).ivano
08/13/2019, 12:04 PM@Parcelize
class RemoteDeclarationRepository : DeclarationRepositoryInterface {
private val declareService: ProActiveDeclareApi
get() = Api()
override fun getDeclarations(periodId: Int, offset: Int, limit: Int): Single<DeclarationsResponse> {
return declareService.getDeclarations(periodId, offset, limit)
}
override fun getDeclarationPeriod(id: Int): Single<DeclarationPeriod> {
return declareService.getPeriod(id).map { it.data }
} //and so on 50 times almost
Marc Knaup
08/13/2019, 12:15 PMonPause
or onStop
, e.g. in case the user switches to another application.
The launched coroutine’s scope however cannot be bound to the activity’s lifecycle because the save operation may not have finished by the time the activity gets destroyed. Even worse the whole app may be destroyed or hibernated because there are no activities left, which would abort the save operation.
How would I model that properly?
• The most simple solution I can think of is to block the main thread on onStop
and wait for the coroutine to complete. But that’s somewhat counter-productive 🤔 OTOH that would ensure that if the user switches to another activity they’d not risk seeing stale data because the save hasn’t completed yet.
• Another solution could be a long-running service for any kind of database I/O but that seems unnecessarily complex (and may even need a foreground service?).Pablichjenkov
08/13/2019, 8:14 PMFlow<T>
. Is it a bad design?arekolek
08/14/2019, 6:29 AM@Parcelize
got rid of this lint error?alex.tavella
08/14/2019, 5:12 PM@VisibleForTesting
a bad practice for unit testing internals of a component?Mohamed Hamdan
08/14/2019, 8:31 PMraghuramjampala
08/15/2019, 2:25 PMjmfayard
08/15/2019, 4:13 PMBetter dependency management in Android Studio 3.5 with Gradle buildSrcVersions
https://dev.to/jmfayard/new-in-android-studio-3-5-dependency-management-with-gradle-buildsrcversions-22ia-temp-slug-2042205?preview=373ea29273e40c80e4579a999bbc305e8246511e13d599564be52fba5f20607b13305942fd8c4855b5e1807a66249612df27e19193a563106eb8d275
I will publish once Android Studio 3.5 is released (should be real soon now)리오
08/15/2019, 8:39 PMYuri
08/15/2019, 11:10 PMprivate val keyChangesObservable: Observable<String>
init {
keyChangesObservable = io.reactivex.Observable.create(ObservableOnSubscribe<String> { emitter ->
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key -> emitter.onNext(key) }
emitter.setCancellable { prefs.unregisterOnSharedPreferenceChangeListener(listener) }
prefs.registerOnSharedPreferenceChangeListener(listener)
}).share()
}
Paul Dhaliwal
08/16/2019, 12:06 AMKulwinder Singh
08/16/2019, 6:08 AMprivate val realInterceptor = Interceptor { chain ->
if (!NetworkConnection.getInstance().isConnected) {
throw NoInternetException()
}
/..../
}
but to work with this i have to add try/catch
block on every request, there are so many requests. Below is sample of how i'm handling each network request->
val response = apiService.getItems().toNetworkResult()
when (response) {
is NetworkResult.Success -> onDataLoaded(response.data)
is NetworkResult.Error -> toast(response.errorCode)
}
and this is how toNetworkResult
looks like
fun <T : Any> Response<T>.toNetworkResult(): NetworkResult<T> {
val response = this
if (response.isSuccessful)
return NetworkResult.Success(response.body()!!)
val error = GsonUtils.toObject<ErrorResponse>(response.errorBody()!!.string())
return NetworkResult.Error(response.code(), error)
}
I just want to know if it is possible to handle it inside toNetworkResult()
or any other similar solution i can implement, where i don't have to add try/catch
on every requestZaraki596
08/16/2019, 12:33 PMgildor
08/16/2019, 12:57 PM