kotlin

Dealing with R8 + JvmStatic Annotation + Lambda in public API for Android Library written in Kotlin

谁说胖子不能爱 提交于 2021-02-07 05:51:01
问题 First of all, please note that I'm not expecting why do you want to obfuscate library comments. This is a genuine problem I'm asking about. I have been having an issue dealing with R8/obfuscation with an Android library written in Kotlin. I've a public API method which is annotated with @JvmStatic and that method takes a Lambda as parameter. For example, take a look at code below, typealias MyLambdaCallback = (String, Map<String, Any>) -> Unit @Keep object MyApi { private var callback:

Implement Asymmetrical Grid Layout Manager Like Instagram Search

我只是一个虾纸丫 提交于 2021-02-07 04:29:15
问题 I Created a RecyclerView And Set layoutManager Of My Adapter To GridLayout . But I Want GridLayout Like Instagram Search below image, I Want A GridView Like This : Please Help Me . Thanks . i tried SpanSizeLookup But i Have Still My Problem And i Cant Control My Items to laying out exactly that way . . . 回答1: please take a look this answer and for show Your list in Span val manager = SpannedGridLayoutManager(object : SpannedGridLayoutManager.GridSpanLookup{ override fun getSpanInfo(position:

How to avoid occurring many AsyncTask class in my Android Room repository?

我的未来我决定 提交于 2021-02-07 04:19:21
问题 I'm learning how to use Android Room from google-developer-training, where I found example of repository class . I try to simplify my SportRepository class. I wonder how to avoid repetition of inner class ...AsyncTask in my code. Here is very sample example: @Singleton class SportRepository { val LOG_TAG = SportRepository::class.java.name @Inject lateinit var sportDAO: SportDAO var list: LiveData<List<Sport>> init { App.app().appComponent()?.inject(this) list = sportDAO.getAll() } fun insert

How to show/hide BottomAppBar programmatically?

岁酱吖の 提交于 2021-02-07 02:56:54
问题 I try to use an BottomAppBar and I would like to be able to hide or show it programmatically like a setExpanded in an AppBarLayout. My layout is like <androidx.coordinatorlayout.widget.CoordinatorLayout android:id="@+id/coordinator" android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content"> ... </com.google.android.material.appbar

Kotlin coroutine flow example for Android button click event?

那年仲夏 提交于 2021-02-07 02:56:52
问题 I used to use Channel to send out click event from Anko View class to Activity class, however more and more Channel functions are marked as deprecated. So I wanted to start using Flow apis. I migrated code below: private val btnProduceChannel = Channel<Unit>() val btnChannel : ReceiveChannel<Unit> = btnProduceChannel // Anko button { onClick { btnProduceChannel.send(Unit) } } to: lateinit var btnFlow: Flow<Unit> private set button { btnFlow = flow { onClick { emit(Unit) } } } I have to mark

How to show/hide BottomAppBar programmatically?

心不动则不痛 提交于 2021-02-07 02:56:32
问题 I try to use an BottomAppBar and I would like to be able to hide or show it programmatically like a setExpanded in an AppBarLayout. My layout is like <androidx.coordinatorlayout.widget.CoordinatorLayout android:id="@+id/coordinator" android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content"> ... </com.google.android.material.appbar

How to show/hide BottomAppBar programmatically?

非 Y 不嫁゛ 提交于 2021-02-07 02:56:02
问题 I try to use an BottomAppBar and I would like to be able to hide or show it programmatically like a setExpanded in an AppBarLayout. My layout is like <androidx.coordinatorlayout.widget.CoordinatorLayout android:id="@+id/coordinator" android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content"> ... </com.google.android.material.appbar

Kotlin coroutine flow example for Android button click event?

与世无争的帅哥 提交于 2021-02-07 02:56:01
问题 I used to use Channel to send out click event from Anko View class to Activity class, however more and more Channel functions are marked as deprecated. So I wanted to start using Flow apis. I migrated code below: private val btnProduceChannel = Channel<Unit>() val btnChannel : ReceiveChannel<Unit> = btnProduceChannel // Anko button { onClick { btnProduceChannel.send(Unit) } } to: lateinit var btnFlow: Flow<Unit> private set button { btnFlow = flow { onClick { emit(Unit) } } } I have to mark

How to handle multiple NavHosts/NavControllers?

无人久伴 提交于 2021-02-06 09:31:50
问题 I'm having a problem when dealing with multiple NavHosts. This issue is very similar to the one asked here. I think the solution for this question would help me as well, but it's a post from 2017 and it still has no answer. Android Developers Documentation doesn't help and searching through the web shows absolutely nothing that could possibly help. So basically I have one Activity and two Fragments. Let's call them FruitsActivity, FruitListFragment, FruitDetailFragment, where FruitsActivity

Time conversion from seconds to date issue

荒凉一梦 提交于 2021-02-05 12:20:55
问题 I have the following Long variable holding epoch value in seconds, which I'm trying to convert into a Date . val seconds = 1341855763000 val date = Date(TimeUnit.SECONDS.toMillis(seconds)) The output is way off than I expected. Where did I go wrong? Actual: Wed Sep 19 05:26:40 GMT+05:30 44491 Expected: Monday July 9 11:12:43 GMT+05:30 2012 回答1: The output is way off than I expected. Where did I go wrong? Actual: Wed Sep 19 05:26:40 GMT+05:30 44491 Expected: Monday July 9 11:12:43 GMT+05:30