zain
05/28/2021, 2:03 PMnextButton.setOnLongClickListener {
val handler = Handler(Looper.myLooper()!!)
val runnable: Runnable = object : Runnable {
override fun run() {
handler.removeCallbacks(this)
if (nextButton.isPressed) {
println("Do Something!")
handler.postDelayed(this, 500)
}
}
}
handler.postDelayed(runnable, 0)
true
}Christian Dräger
05/28/2021, 9:03 PMclass StargazerViewModel : ViewModel() {
private var _users: MutableLiveData<List<User>> = MutableLiveData(emptyList())
val users: LiveData<List<User>> = _users
fun updateUsers() {
viewModelScope.launch {
_users.postValue(fetch())
// _users.postValue(dummyData) // when using valid dummy data here the app works as aspected
}
}
}
private suspend fun fetch(): List<User> =
skrape(HttpFetcher) {
request {
url = "<https://github.com/skrapeit/skrape.it/stargazers>"
}
...
full code here: https://github.com/skrapeit/skrape.it/blob/android-example/examples/android/app/src/main/java/it/skrape/skrapeitexample/MainActivity.kt
whenever i call the fetch method i get a android.os.NetworkOnMainThreadException
which i assume is because my client call is blocking and thereby break the coroutine (maybe?)
what can i do to run the blocking client in a background thread to avoid the NetworkOnMainThreadException in a jetpack-compose project?theapache64
05/29/2021, 10:50 AMdagger.hilt.android.plugin
plugin 🧵Sunny
05/29/2021, 2:00 PMAldan Rizki Santosa
05/29/2021, 3:29 PMPair
?
The code like this :
val distributorNotes = ArrayList<PairDistributorNotes<String, String>>()
distributorNotes.add(PairDistributorNotes("350631771", "test"))
data class PairDistributorNotes<out x, out y>(val distributor_id: x, val note: y) {
override fun toString(): String = "($distributor_id, $note)"
}
and i create asReverse(
) with distinctBy
val dataJson = Gson().toJson(distributorNotes.asReversed().distinctBy { it.distributor_id })
Output from dataJson :
[{"a":"350631771","b":"test"}]
Can field a and b change to distributor_id and note ?
Expected :
[{"distributor_id":"350631771","note":"test"}]
UPDATE
Based on Christian Grach answer, because Proguard is enabled, Gson require annotations to preserve the field name.. We need to add @field:SerializedName()
on data class
data class PairDistributorNotes<out A, out B>(
@field:SerializedName("distributor_id")
val distributor_id: A,
@field:SerializedName("note")
val note: B
) {
override fun toString(): String = "($distributor_id, $note)"
}
Mjahangiry75
05/30/2021, 9:46 AMnoone
05/30/2021, 6:12 PMonirutlA
05/31/2021, 7:39 AMizyaboi
05/31/2021, 8:34 AMEmiliano Schiavone
05/31/2021, 6:00 PMJesus Cruz Victoria
05/31/2021, 9:04 PMonirutlA
06/01/2021, 12:55 AMknthmn
06/01/2021, 3:43 AMclass MainActivity : ComponentActivity() {
val foo by lazy { Foo() }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
foo // initialize
}
}
I see the following benefits
• the "initialization" of the value is visually closer to where it is defined
• foo
is a val
Are there any disadvantages doing this? What do you guys prefer?Pawan Gorai
06/01/2021, 10:03 AMAny, None, and All
but as I want only matched data and which I am not getting using any of these predicates.
As Any returns true if at least there is one match element, and All returns true if there are all matched elements but how can I get only the matched elements from the nested list irrespective of any non-matched element.
I can use the traditional approach of looping through the list, but I wanted to know whether it is possible using a predicate.
Here's the sample JSON
I am trying to get the center whose session elements contains min_age_limit is > 18
and available_dose_1 > 0
.
{
"centers": [
{
....
"sessions": [
{
"session_id":"adad",
...
"min_age_limit":45,
"available_capacity_dose1": 5,
"available_capacity_dose2": 5
...
},
{
"session_id":"adad1",
...
"min_age_limit":18,
"available_capacity_dose1": 0,
"available_capacity_dose2": 5
...
},
{
"session_id":"adad2",
...
"min_age_limit":18,
"available_capacity_dose1": 5,
"available_capacity_dose2": 0
...
}
]
}
....
]
}
Paul
06/01/2021, 7:18 PMinterface ImageLoader
@BindType
class GlideImageLoader @Inject constructor(): ImageLoader
and HiltBinder will generate the following:
@Module
@InstallIn(SingletonComponent.class)
public interface HiltBinder_SingletonComponentModule {
@Binds
ImageLoader bind_GlideImageLoader(GlideImageLoader binding);
}
HiltBinder supports lots of features:
• Specifying a particular type to bind to.
• Installing bindings in both Dagger Hilt's predefined and custom components.
• Contributing bindings into a set and map collections (Dagger multibindings).
• Associating bindings with Dagger qualifiers.
• KSP support.
For more info, take a look at the GitHub repository that contains extensive documentation for the API as well as sample application to showcase the library in action.KD
06/01/2021, 8:23 PMsolidogen
06/02/2021, 7:23 AMSergio C.
06/02/2021, 9:55 PMNabeel
06/03/2021, 6:41 AM<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/name"
layout="@layout/form_element_layout" />
<include
android:id="@+id/unit"
layout="@layout/form_element_layout" />
<include
android:id="@+id/quantity"
layout="@layout/form_element_layout" />
</LinearLayout>
form_element_layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title"
style="@style/TextViewRegularHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title"
android:textSize="@dimen/title_text_size" />
<EditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_text_forms_bg"
android:hint="@string/form_hint"
android:inputType="text" />
</LinearLayout>
After entering values in name.input
, unit.input
and quantity.input
fields, I've navigated to fragment_two.
When returning from the fragment_two to fragment_one, the values in every field changed to the value of the quantity.input
Eg : name is John, unit is Kg and quantity is 80. After navigating to fragment_two and returned, the name, unit and quantity values are changed to 80, Any help?Slackbot
06/03/2021, 8:41 AMVivek Modi
06/03/2021, 5:54 PMdata class CategoryResponse(
val item: List<CategoryItem>
)
data class CategoryItem(
val id: Int,
val Category1: List<ItemOptions>? = null,
val Category2: List<ItemOptions>? = null,
val Category3: List<ItemOptions>? = null
)
data class ItemOptions(
val name: String? = null,
val url: String? = null
)
I have an enum class, which has 4 enum types
enum class CategoryType(val name :String){
ALL("ALL"),
Category1("Category1"),
Category2("Category2"),
Category3("Category3");
}
There is a category named ALL, so i need the list of all the data but I don't want any null values, and still want the data that other categories hold.
Example - the list consist of 5 elements
Desired output:
ALL : list-> [id : 1 , category1 : ”..”] , [id : 2 ,category2 : “..”] , [id : 3 ,category2 : ”..”] , [id : 4 ,category1 : “..”] , [id : 5 ,category3: “.."]
CATEGORY2: list -> [id : 2 , category2 : “..”] , [id : 3 , category2 : “..”]
(this list may or may not consist of more than 5 elements)
is there any way that this list won’t occupy a lot of memory, or duplicate the objects and could be more efficient.?Shivam Verma
06/03/2021, 7:41 PMinit {
viewModelScope.launch {
launch { loadTotalCirculation() }
launch { loadMarketPrice() }
}
}
private suspend fun loadTotalCirculation() {
val totalCirculation = bitcoinChartsRepository.getTotalCirculation(5, TimeUnit.HOURS)
_viewState.value = _viewState.value.copy(totalCirculation = chartViewEntityMapper(totalCirculation))
}
private suspend fun loadMarketPrice() {
val marketPrice = bitcoinChartsRepository.getMarketPrice(27, TimeUnit.DAYS)
_viewState.value = _viewState.value.copy(marketPrice = chartViewEntityMapper(marketPrice))
}
However, I would like to prevent the concurrent execution of the _viewState.value = _viewState.value.copy...
parts in both my methods. What's the best way to achieve this ?
These two requests update parts of a stateflow that's collected inside a Fragment. However, often they run concurrently emitting the wrong states. Is there a way to better architect this solution ?taponidhi
06/04/2021, 5:01 AMZan Skamljic
06/04/2021, 6:39 AMSlackbot
06/04/2021, 10:10 AMSlackbot
06/04/2021, 12:50 PMZun
06/04/2021, 12:51 PMMărcuţ Andrei
06/04/2021, 1:17 PMMuhammad Zaryab Rafique
06/06/2021, 6:40 AMSudhir Singh Khanger
06/07/2021, 4:10 AMviewModelScope.launch {
launch { task1 }
launch { task2 }
}