fix VkLink.kt target NullPointerException

This commit is contained in:
2021-10-10 18:38:43 +03:00
parent ff5d449b3b
commit 118c531d00
9 changed files with 22 additions and 23 deletions
@@ -4,5 +4,4 @@ object ApiExtensions {
val Boolean.intString get() = (if (this) 1 else 0).toString()
}
@@ -9,7 +9,7 @@ data class VkLink(
val title: String?,
val caption: String?,
val photo: VkPhoto?,
val target: String,
val target: String?,
val isFavorite: Boolean
) : VkAttachment() {
@@ -9,7 +9,7 @@ data class BaseVkLink(
val title: String?,
val caption: String?,
val photo: BaseVkPhoto?,
val target: String,
val target: String?,
val is_favorite: Boolean
) : BaseVkAttachment() {
@@ -1,13 +1,11 @@
package com.meloda.fast.base
import android.os.Bundle
import android.view.View
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import com.google.android.material.snackbar.Snackbar
abstract class BaseActivity : AppCompatActivity, LifecycleOwner {
@@ -39,10 +37,4 @@ abstract class BaseActivity : AppCompatActivity, LifecycleOwner {
lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
}
val rootView: View? get() = findViewById(android.R.id.content)
fun requireRootView() = rootView!!
var errorSnackbar: Snackbar? = null
}
@@ -13,6 +13,7 @@ import kotlinx.coroutines.Job
object AppSettings {
val keyIsMultilineEnabled = booleanPreferencesKey("isMultilineEnabled")
}
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(
@@ -91,7 +91,7 @@ class ConversationsFragment :
requireContext().dataStore.data.map {
adapter.isMultilineEnabled = it[AppSettings.keyIsMultilineEnabled] ?: true
adapter.notifyItemRangeChanged(0, adapter.itemCount)
}.collect { }
}.collect()
}
binding.createChat.setOnClickListener {}
@@ -77,7 +77,7 @@ class LoginFragment : BaseViewModelFragment<LoginViewModel>(R.layout.fragment_lo
is ErrorEvent -> showErrorSnackbar(event.errorText)
is CaptchaEvent -> showCaptchaDialog(event.sid, event.image)
is ValidationEvent -> showValidationRequired(event.sid)
is SuccessAuth -> goToMain(event.haveAuthorized)
is SuccessAuth -> goToMain(event)
is CodeSent -> showValidationDialog()
is StartProgressEvent -> onProgressStarted()
@@ -384,8 +384,11 @@ class LoginFragment : BaseViewModelFragment<LoginViewModel>(R.layout.fragment_lo
snackbar.show()
}
private fun goToMain(haveAuthorized: Boolean) = lifecycleScope.launch {
if (haveAuthorized) delay(500)
private fun goToMain(event: SuccessAuth) = lifecycleScope.launch {
UserConfig.userId = event.userId
UserConfig.accessToken = event.vkToken
if (event.haveAuthorized) delay(500)
launchWebView()
@@ -1,11 +1,10 @@
package com.meloda.fast.screens.login
import androidx.lifecycle.viewModelScope
import com.meloda.fast.api.UserConfig
import com.meloda.fast.api.VKConstants
import com.meloda.fast.api.VKException
import com.meloda.fast.api.network.auth.RequestAuthDirect
import com.meloda.fast.api.network.auth.AuthDataSource
import com.meloda.fast.api.network.auth.RequestAuthDirect
import com.meloda.fast.base.viewmodel.*
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
@@ -45,10 +44,12 @@ class LoginViewModel @Inject constructor(
return@makeJob
}
UserConfig.userId = it.userId
UserConfig.accessToken = it.accessToken
sendEvent(SuccessAuth())
sendEvent(
SuccessAuth(
userId = it.userId,
vkToken = it.accessToken
)
)
},
onError = {
if (it !is VKException) {
@@ -72,4 +73,8 @@ class LoginViewModel @Inject constructor(
object CodeSent : VkEvent()
data class SuccessAuth(val haveAuthorized: Boolean = true) : VkEvent()
data class SuccessAuth(
val haveAuthorized: Boolean = true,
val userId: Int,
val vkToken: String
) : VkEvent()
@@ -42,5 +42,4 @@ class MainFragment : BaseViewModelFragment<MainViewModel>(R.layout.fragment_main
}
}
}