Add logging with Timber
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package gq.kirmanak.mealie.ui.auth
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -13,6 +12,7 @@ import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import gq.kirmanak.mealie.databinding.FragmentAuthenticationBinding
|
||||
import timber.log.Timber
|
||||
|
||||
private const val TAG = "AuthenticationFragment"
|
||||
|
||||
@@ -25,6 +25,7 @@ class AuthenticationFragment : Fragment() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
Timber.v("onCreate() called with: savedInstanceState = $savedInstanceState")
|
||||
checkIfAuthenticatedAlready()
|
||||
}
|
||||
|
||||
@@ -33,18 +34,19 @@ class AuthenticationFragment : Fragment() {
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
Timber.v("onCreateView() called with: inflater = $inflater, container = $container, savedInstanceState = $savedInstanceState")
|
||||
_binding = FragmentAuthenticationBinding.inflate(inflater, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding.button.setOnClickListener {
|
||||
onLoginClicked()
|
||||
}
|
||||
Timber.v("onViewCreated() called with: view = $view, savedInstanceState = $savedInstanceState")
|
||||
binding.button.setOnClickListener { onLoginClicked() }
|
||||
}
|
||||
|
||||
private fun checkIfAuthenticatedAlready() {
|
||||
Timber.v("checkIfAuthenticatedAlready() called")
|
||||
lifecycleScope.launchWhenCreated {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
@@ -56,6 +58,7 @@ class AuthenticationFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun onLoginClicked() {
|
||||
Timber.v("onLoginClicked() called")
|
||||
val email: String
|
||||
val pass: String
|
||||
val url: String
|
||||
@@ -72,7 +75,6 @@ class AuthenticationFragment : Fragment() {
|
||||
}
|
||||
lifecycleScope.launchWhenResumed {
|
||||
val exception = viewModel.authenticate(email, pass, url)
|
||||
Log.e(TAG, "onLoginClicked: ", exception)
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"Exception is ${exception?.message ?: "null"}",
|
||||
@@ -86,7 +88,9 @@ class AuthenticationFragment : Fragment() {
|
||||
inputLayout: TextInputLayout,
|
||||
errorText: () -> String
|
||||
): String? {
|
||||
Timber.v("checkIfInputIsEmpty() called with: input = " + input + ", inputLayout = " + inputLayout + ", errorText = " + errorText)
|
||||
val text = input.text?.toString()
|
||||
Timber.d("Input text is \"$text\"")
|
||||
if (text.isNullOrBlank()) {
|
||||
inputLayout.error = errorText()
|
||||
return null
|
||||
@@ -96,6 +100,7 @@ class AuthenticationFragment : Fragment() {
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
Timber.v("onDestroyView() called")
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,29 @@ package gq.kirmanak.mealie.ui.auth
|
||||
import androidx.lifecycle.ViewModel
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import gq.kirmanak.mealie.data.auth.AuthRepo
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class AuthenticationViewModel @Inject constructor(
|
||||
private val authRepo: AuthRepo
|
||||
) : ViewModel() {
|
||||
suspend fun isAuthenticated(): Boolean = authRepo.isAuthenticated()
|
||||
init {
|
||||
Timber.v("constructor called")
|
||||
}
|
||||
|
||||
suspend fun isAuthenticated(): Boolean {
|
||||
Timber.v("isAuthenticated() called")
|
||||
val result = authRepo.isAuthenticated()
|
||||
Timber.d("isAuthenticated() returned: $result")
|
||||
return result
|
||||
}
|
||||
|
||||
suspend fun authenticate(username: String, password: String, baseUrl: String): Throwable? {
|
||||
return authRepo.authenticate(username, password, baseUrl)
|
||||
Timber.v("authenticate() called with: username = $username, password = $password, baseUrl = $baseUrl")
|
||||
val result = authRepo.authenticate(username, password, baseUrl)
|
||||
if (result == null) Timber.d("authenticate() returns null")
|
||||
else Timber.e("authenticate() returns error", result)
|
||||
return result
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user