kotlin

Get current server Date and Time in Firebase Firestore

谁说我不能喝 提交于 2021-02-05 09:37:23
问题 I want to get my server time in Firebase Firestore so I can use it for my countdown logic. I can't find anywhere and mostly they suggest to use FiedValue.serverTimeStamp or ServerValue.TIMESTAMP which is both are used to save data. I don't want to save data I just want to get the server time. Is there a static way like FirebaseFirestore.getInstance().getServerTime() ? 回答1: As per said by the @Doug there is no way of getting just only time from Firebase. However there are many round-ways for

How to return failed task result in continuation task?

↘锁芯ラ 提交于 2021-02-05 09:36:13
问题 I am using Google's Task API in Kotlin and am faced with the next situation: ... val deleteTask = getItem(id)?.continueWithTask { task -> if (task.isSuccessful) task.result?.toObject(ItemModel::class.java)?.let { deleteFiles(it.media) } } deleteTask?.continueWithTask { task -> if (task.isSuccessful) doSomething() } ?: doSomething() ... Where getItem(id) returns the Firebase.firestore get task ( Task<DocumentSnapshot>? ) and deleteFiles(it.media) retuens the Firebase.storage delete task ( Task

How to write this java code to kotlin in Binding Adapter

泪湿孤枕 提交于 2021-02-05 09:28:35
问题 I have some lines of code written in onBindViewHolder in lang (java) .. I'm trying to write the exact code in kotlin in Binding Adapter , but i'm not able to write that EarthQuakeAdapter( JAVA) .. I tried but i was not able to write the same code to get magnitudeCircle , PrimaryLocation and LocationOffSet from onBindViewHolder(JAVA lang) method to Binding Adapter in kotlin which i posted below public class EarthquakeAdapter extends RecyclerView.Adapter<EarthquakeAdapter.MyViewHolder> {

How to write this java code to kotlin in Binding Adapter

吃可爱长大的小学妹 提交于 2021-02-05 09:27:48
问题 I have some lines of code written in onBindViewHolder in lang (java) .. I'm trying to write the exact code in kotlin in Binding Adapter , but i'm not able to write that EarthQuakeAdapter( JAVA) .. I tried but i was not able to write the same code to get magnitudeCircle , PrimaryLocation and LocationOffSet from onBindViewHolder(JAVA lang) method to Binding Adapter in kotlin which i posted below public class EarthquakeAdapter extends RecyclerView.Adapter<EarthquakeAdapter.MyViewHolder> {

runtime error while accessing google api in android emulator

心已入冬 提交于 2021-02-05 09:27:16
问题 I am trying to access the googleFit API. It seems pretty straightforward. Get the google sign-in permissions and required authorizations then query for Step count. My code doesn't seem to work. When I debug this the fitnessOption declaration part throws "source code doesn't match byte code" error. I cleaned my project, rebuild it it didn't work Android gurus, Where am I going wrong?? fun getAuthorizationAndReadData() { try { MainActivity().fitSignIn(FitActionRequestCode.READ_DATA) } catch ()

Split a list into groups of consecutive elements based on a condition in Kotlin

北慕城南 提交于 2021-02-05 09:17:47
问题 I am trying to group a list based on some type and if they are in sequence data class Item(val type: Int, val name: String) private fun splitItems(items: List<Item>): List<List<Item>> { val groupedItems = mutableListOf<List<Item>>() var tempList = mutableListOf<Item>() items.mapIndexed { index, item -> if (index > 0) { val previousItem = items[index - 1] if (previousItem.type == item.type) { tempList.add(item) } else { if (tempList.isNotEmpty()) groupedItems.add(tempList) tempList =

How to test Coroutine with ViewModel in Kotlin?

不问归期 提交于 2021-02-05 09:16:10
问题 I could not test my method it feels it doesn't reach inside uiScope.launch block and I have posted my viewModel method which I am trying to test and fetchActivationCodeWithDuration is suspend function. and in the bottom is my test class and I get this message java.lang.AssertionError: Expected :ActivationCode(code=111111, expires=2019-05-23T10:03:50.614Z, duration=815960) Actual :null protected val uiScope = CoroutineScope(Dispatchers.Main + viewModelJob) fun loadActivationCode() { uiScope

How to test Coroutine with ViewModel in Kotlin?

浪尽此生 提交于 2021-02-05 09:16:02
问题 I could not test my method it feels it doesn't reach inside uiScope.launch block and I have posted my viewModel method which I am trying to test and fetchActivationCodeWithDuration is suspend function. and in the bottom is my test class and I get this message java.lang.AssertionError: Expected :ActivationCode(code=111111, expires=2019-05-23T10:03:50.614Z, duration=815960) Actual :null protected val uiScope = CoroutineScope(Dispatchers.Main + viewModelJob) fun loadActivationCode() { uiScope

KOTLIN - First item in BottomNavigationBar isn't visible, title issues

﹥>﹥吖頭↗ 提交于 2021-02-05 08:56:49
问题 I have a BottomNavigationBar with 5 items. The first item is the same as the rest, apart from the name and icon. Here is the xml for the bottom_nav menu <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/name_configuration" android:title="Name Mech" android:icon="@drawable/ic_action_name" /> <item android:id="@+id/mech_skills" android:title="Skills" android:icon="@drawable/ic_action_skills" /> <item android:id="@+id

CharSet for MS Access '97 DB using UCanAccess

孤人 提交于 2021-02-05 08:28:13
问题 Hey I am reading a database using ucanaccess-5.0.0. The database is propably < Access 2000, since it's not UTF-8. It seems like I have to setup a charset. I tried this using the charset parameter in the url: jdbc:ucanaccess://${databaseFile.absolutePath};memory=false;charSet=Cp1250 It seems to be ignored, since I still don't get my german umlauts out of the DB. What can I do about it? 回答1: Working Solution: class DatabaseOpener : JackcessOpenerInterface { override fun open(fl: File, pwd: