the great warrior
12/04/2022, 6:54 PM@Singleton
class DataStorePreference @Inject constructor(@ApplicationContext context: Context) {
private val dataSource = context.dataStore
companion object {
const val CALCULATOR_USER_PREFERENCES = "CALCULATOR_USER_PREFERENCES"
val CURRENT_INPUT = stringPreferencesKey("CURRENT_INPUT")
}
suspend fun <T> getPreference(key: Preferences.Key<T>, defaultValue: T):
Flow<T> = dataSource.data.catch { exception ->
if (exception is IOException) {
emit(emptyPreferences())
} else {
throw exception
}
}.map { preferences ->
val result = preferences[key] ?: defaultValue
result
}
}
@HiltViewModel
class CalculatorViewModel @Inject constructor(
private val dataStorePreferenceRepository: DataStorePreferenceRepository
) : ViewModel() {
// pass CURRENT_INPUT preference value to mutableStateFlow initial value
private val _currentInput: MutableStateFlow<String?> = MutableStateFlow(null)
val currentInput = _currentInput.asStateFlow()
suspend fun<T> getPreference(key: Preferences.Key<T>, defaultValue : T) =
dataStorePreferenceRepository.getPreference(key, defaultValue)
}
Eugene Maksymenko
12/04/2022, 11:50 PMSlackbot
12/05/2022, 9:40 AMElio Maroun
12/05/2022, 11:01 AMRobert St. John
12/05/2022, 5:38 PMequals()
and hashCode()
methods. i also would prefer that all properties of the class are immutable, so the class is more like a functional style data type, and i would appreciate having kotlin auto-generate the copy()
method with the selective override parameters. however, i can't seem to achieve all these things at the same time because if i create the data class with only the primary key property in the primary constructor, Room needs public setters for the rest of the properties, and i will not get the copy()
method with parameters for all the non-constructor properties. if i put all immutable properties in the primary constructor, i lose the desired equals()
and hashCode()
semantics and i also have concerns about the overhead of that many properties participating in those methods. has anyone tried/been able to achieve this with a data class? my current solution is a standard class with all immutable properties in the primary constructor, and a copy constructor that takes a source instance argument, then individual override parameters for all the properties, but that's a bit of headache and error-prone to maintainChrimaeon
12/05/2022, 5:44 PMSaadat Sayem
12/06/2022, 4:47 AMAmrJyniat
12/06/2022, 7:40 AMOnPageChangeCallback()
to the viewPager
like this:
binding.viewPager.registerOnPageChangeCallback(pageChangeListener)
Then, the onPageSelected()
fun is called immediately, can I prevent this behavior(calling the fun on the first initialized)?Vivek Sharma
12/06/2022, 9:53 AMBottomSheet
, I am not able to have fix footer
, footer just can not be fixed I mean at bottom and behind the footer, I am doing scrolling and things, so how can we achieve that?Louis
12/06/2022, 4:04 PMAbdulaziz Mohammed
12/07/2022, 5:28 AMShagun Chahar
12/07/2022, 6:27 AMShagun Chahar
12/07/2022, 6:27 AMShagun Chahar
12/07/2022, 6:27 AMShagun Chahar
12/07/2022, 6:27 AMShagun Chahar
12/07/2022, 9:09 AMElio Maroun
12/07/2022, 12:24 PMElio Maroun
12/07/2022, 12:24 PMdead.fish
12/07/2022, 2:22 PMimport android.os.Bundle
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
class OuterFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MyDialogFragment.create(Bundle()).apply {
show(childFragmentManager, "DIALOG")
// ^--- this should be this@OuterFragment.childFragmentManager
}
}
}
class MyDialogFragment : DialogFragment() {
companion object {
fun create(bundle: Bundle): MyDialogFragment =
MyDialogFragment().apply {
arguments = bundle
}
}
}
Any hints how I could make childFragmentManager
yellowish in the IDE?Guilherme Delgado
12/08/2022, 1:45 AMProcessBuilder
. It “works”, but the output is different if I run the same command via terminal:
~ adb shell am broadcast -p com.sample -a sample.action -e "extra" "bla bla"
produces (correctly):
Broadcasting: Intent { act=sample.action flg=0x400000 pkg=com.sample (has extras) }
Broadcast completed: result=0
but the same command via ProcessBuilder
produces:
Broadcasting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x400000 pkg= -p }
Broadcast completed: result=0
any idea why? 🤔Bhargav Pandya
12/08/2022, 2:22 PMYacov Rosenberg
12/08/2022, 6:51 PMSlackbot
12/09/2022, 1:40 PMJustin Tullgren
12/09/2022, 5:03 PMcompileOnly
as the actual runtime dependency will be provided by a user of the library. This works fine for normal compiling, but compiling the android test class path throws an IR error:
No such enum entry LIBRARY_GROUP_PREFIX
I have tried adding the annotations as an implementation
and testCompileOnly
and androidTestImplementation
dependency but I can't get passed that IR error. Does anyone have a workaround or solution? Thanks!Michael Langford
12/09/2022, 8:20 PMrishabhsinghbisht
12/10/2022, 3:27 PMkotlinx.parcelize.RawValue
can’t find much.Nat Strangerweather
12/11/2022, 3:49 PMgts13
12/11/2022, 8:30 PMgts13
12/11/2022, 8:38 PMEric Womer
12/11/2022, 9:58 PM