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