From 2c40a1bf57b821844e6a9ff26d86d5740b27b684 Mon Sep 17 00:00:00 2001 From: Isanz Date: Mon, 13 May 2024 13:01:56 +0200 Subject: [PATCH] [] -- Refactor with Sonar, code as clean as possible --- .../inmomarket/InmomarketInstrumentedTest.kt | 5 +- .../ConversationListAdapter.kt | 1 - .../propertyItem/PropertyItemListAdapter.kt | 25 +++---- .../rv/propertyItem/PropertyItemViewModel.kt | 4 +- .../isanz/inmomarket/ui/add/AddFragment.kt | 30 ++++---- .../isanz/inmomarket/ui/chat/ChatFragment.kt | 11 ++- .../isanz/inmomarket/ui/chat/ChatViewModel.kt | 45 ++++++------ .../ui/conversations/ConversationsFragment.kt | 1 - .../conversations/ConversationsViewModel.kt | 4 +- .../isanz/inmomarket/ui/home/HomeViewModel.kt | 5 +- .../inmomarket/ui/portal/PortalViewModel.kt | 35 ++++++---- .../ui/portal/login/LoginActivity.kt | 22 +++--- .../ui/portal/register/RegisterActivity.kt | 11 +-- .../inmomarket/ui/profile/ProfileFragment.kt | 26 +++---- .../inmomarket/ui/profile/ProfileViewModel.kt | 19 ++++-- .../inmomarket/ui/profile/ViewPagerAdapter.kt | 2 +- .../favorites/FavoritesProfileFragment.kt | 1 - .../favorites/FavoritesProfileViewModel.kt | 55 ++++++++++----- .../uploads/YourUploadsProfileViewModel.kt | 68 ++++++++++++------- .../ui/property/MiniPropertyFragment.kt | 11 +-- .../ui/property/PropertyFragment.kt | 64 +++++++++-------- .../ui/property/PropertyViewModel.kt | 46 +++++++------ .../inmomarket/ui/search/SearchFragment.kt | 55 ++++++++------- .../ui/settings/SettingsFragment.kt | 1 - .../ui/settings/SettingsViewModel.kt | 1 + .../com/isanz/inmomarket/utils/Constants.kt | 3 - .../utils/interfaces/OnItemClickListener.kt | 2 +- .../utils/retrofit/GeocodingService.kt | 3 +- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 33 files changed, 316 insertions(+), 245 deletions(-) diff --git a/app/src/androidTest/java/com/isanz/inmomarket/InmomarketInstrumentedTest.kt b/app/src/androidTest/java/com/isanz/inmomarket/InmomarketInstrumentedTest.kt index e98e608..e291e30 100644 --- a/app/src/androidTest/java/com/isanz/inmomarket/InmomarketInstrumentedTest.kt +++ b/app/src/androidTest/java/com/isanz/inmomarket/InmomarketInstrumentedTest.kt @@ -8,10 +8,9 @@ import com.isanz.inmomarket.ui.home.HomeViewModel import com.isanz.inmomarket.ui.profile.ProfileViewModel import com.isanz.inmomarket.ui.search.SearchViewModel import com.isanz.inmomarket.ui.settings.SettingsViewModel -import com.isanz.inmomarket.utils.Constants import com.isanz.inmomarket.utils.entities.Message -import com.isanz.inmomarket.utils.entities.Property -import org.junit.Assert.* +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull import org.junit.Test import org.junit.runner.RunWith import java.lang.reflect.Method diff --git a/app/src/main/java/com/isanz/inmomarket/rv/conversationItem/ConversationListAdapter.kt b/app/src/main/java/com/isanz/inmomarket/rv/conversationItem/ConversationListAdapter.kt index f37c87f..9ee010b 100644 --- a/app/src/main/java/com/isanz/inmomarket/rv/conversationItem/ConversationListAdapter.kt +++ b/app/src/main/java/com/isanz/inmomarket/rv/conversationItem/ConversationListAdapter.kt @@ -13,7 +13,6 @@ import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide import com.isanz.inmomarket.InmoMarket import com.isanz.inmomarket.R -import com.isanz.inmomarket.rv.propertyItem.PropertyItemViewModel import com.isanz.inmomarket.utils.entities.Conversation import com.isanz.inmomarket.utils.interfaces.OnItemClickListener import kotlinx.coroutines.CoroutineScope diff --git a/app/src/main/java/com/isanz/inmomarket/rv/propertyItem/PropertyItemListAdapter.kt b/app/src/main/java/com/isanz/inmomarket/rv/propertyItem/PropertyItemListAdapter.kt index 9d86b6c..fac5945 100644 --- a/app/src/main/java/com/isanz/inmomarket/rv/propertyItem/PropertyItemListAdapter.kt +++ b/app/src/main/java/com/isanz/inmomarket/rv/propertyItem/PropertyItemListAdapter.kt @@ -1,13 +1,19 @@ package com.isanz.inmomarket.rv.propertyItem +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import android.graphics.drawable.Drawable import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.view.ViewTreeObserver import android.view.animation.AnimationUtils import android.widget.ImageView import android.widget.TextView +import androidx.core.content.ContextCompat +import androidx.core.view.OneShotPreDrawListener import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide @@ -16,12 +22,6 @@ import com.isanz.inmomarket.R import com.isanz.inmomarket.rv.extraItem.ExtraListAdapter import com.isanz.inmomarket.utils.entities.Property import com.isanz.inmomarket.utils.interfaces.OnItemClickListener -import androidx.recyclerview.widget.ItemTouchHelper -import android.graphics.Canvas -import android.graphics.Color -import android.graphics.drawable.ColorDrawable -import android.graphics.drawable.Drawable -import androidx.core.content.ContextCompat class PropertyItemListAdapter(private val listener: OnItemClickListener) : ListAdapter((PropertyItemDiffCallback())) { @@ -56,14 +56,9 @@ class PropertyItemListAdapter(private val listener: OnItemClickListener) : } private fun setUpImage(holder: PropertyViewHolder, property: Property) { - holder.view.viewTreeObserver.addOnPreDrawListener(object : - ViewTreeObserver.OnPreDrawListener { - override fun onPreDraw(): Boolean { - holder.view.viewTreeObserver.removeOnPreDrawListener(this) - loadImage(holder, property) - return true - } - }) + OneShotPreDrawListener.add(holder.image) { + loadImage(holder, property) + } } private fun loadImage(holder: PropertyViewHolder, property: Property) { diff --git a/app/src/main/java/com/isanz/inmomarket/rv/propertyItem/PropertyItemViewModel.kt b/app/src/main/java/com/isanz/inmomarket/rv/propertyItem/PropertyItemViewModel.kt index 0c91648..f02be35 100644 --- a/app/src/main/java/com/isanz/inmomarket/rv/propertyItem/PropertyItemViewModel.kt +++ b/app/src/main/java/com/isanz/inmomarket/rv/propertyItem/PropertyItemViewModel.kt @@ -17,7 +17,7 @@ class PropertyItemViewModel : ViewModel() { fun getIfFavorite(property: Property, callback: (Boolean) -> Unit) { val docRef = getDocumentReference(property) docRef.get().addOnSuccessListener { document -> - val isFavorite = checkIfFavorite(document.get("favorites") as? List<*>) + val isFavorite = checkIfFavorite(document["favorites"] as? List<*>) callback(isFavorite) } } @@ -30,7 +30,7 @@ class PropertyItemViewModel : ViewModel() { viewModelScope.launch { val docRef = getDocumentReference(property) docRef.get().addOnSuccessListener { document -> - val favorites = document.get("favorites") as? List<*> + val favorites = document["favorites"] as? List<*> if (checkIfFavorite(favorites)) { removeFavorite(docRef, updateFavoriteIcon) } else { diff --git a/app/src/main/java/com/isanz/inmomarket/ui/add/AddFragment.kt b/app/src/main/java/com/isanz/inmomarket/ui/add/AddFragment.kt index bb2aa8f..e1d4788 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/add/AddFragment.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/add/AddFragment.kt @@ -8,6 +8,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast +import androidx.activity.result.contract.ActivityResultContracts import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider @@ -23,7 +24,7 @@ import com.isanz.inmomarket.rv.imageItem.ImageListAdapter import com.isanz.inmomarket.utils.Constants import java.util.UUID -@Suppress("DEPRECATION") + class AddFragment : Fragment() { @@ -38,13 +39,17 @@ class AddFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { mBinding = FragmentAddBinding.inflate(inflater, container, false) + setUp() + return mBinding.root + } + + private fun setUp() { db = InmoMarket.getDb() setupImageListAdapter() initializePlaces() setupAddressClickListener() setUpButtons() setUpDrawables() - return mBinding.root } private fun setupImageListAdapter() { @@ -68,7 +73,7 @@ class AddFragment : Fragment() { val fields = listOf(Place.Field.ID, Place.Field.NAME, Place.Field.ADDRESS) val intent = Autocomplete.IntentBuilder(AutocompleteActivityMode.OVERLAY, fields) .build(requireContext()) - startActivityForResult(intent, Constants.REQUEST_CODE_AUTOCOMPLETE) + placeAutocompleteLauncher.launch(intent) } private fun setUpDrawables() { @@ -202,21 +207,22 @@ class AddFragment : Fragment() { type = "image/*" putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true) } - startActivityForResult(intent, Constants.REQUEST_CODE_PICK_IMAGES) + imagePickerResultLauncher.launch(intent) } + private val imagePickerResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == Activity.RESULT_OK) { + handleImagePickResult(result.data) + } + } - @Deprecated("Deprecated in Java") - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - - if (requestCode == Constants.REQUEST_CODE_PICK_IMAGES && resultCode == Activity.RESULT_OK) { - handleImagePickResult(data) - } else if (requestCode == Constants.REQUEST_CODE_AUTOCOMPLETE && resultCode == Activity.RESULT_OK) { - handlePlaceAutocompleteResult(data!!) + private val placeAutocompleteLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == Activity.RESULT_OK) { + handlePlaceAutocompleteResult(result.data!!) } } + private fun handleImagePickResult(data: Intent?) { val imageUris = extractImageUrisFromIntent(data) val adapter = (mBinding.rvImages.adapter as? ImageListAdapter) diff --git a/app/src/main/java/com/isanz/inmomarket/ui/chat/ChatFragment.kt b/app/src/main/java/com/isanz/inmomarket/ui/chat/ChatFragment.kt index 5f6205d..d66c8a5 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/chat/ChatFragment.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/chat/ChatFragment.kt @@ -1,11 +1,9 @@ package com.isanz.inmomarket.ui.chat -import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.annotation.RequiresApi import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope @@ -34,7 +32,7 @@ class ChatFragment : Fragment() { recipientId = InmoMarket.getAuth().currentUser?.uid!! } - @RequiresApi(Build.VERSION_CODES.O) + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { @@ -43,7 +41,7 @@ class ChatFragment : Fragment() { return mBinding.root } - @RequiresApi(Build.VERSION_CODES.O) + private fun setUpView() { setUpOtherUser() setUpButtons() @@ -81,7 +79,7 @@ class ChatFragment : Fragment() { Glide.with(this).load(imageUri).circleCrop().into(mBinding.ivProfileChat) } - @RequiresApi(Build.VERSION_CODES.O) + private fun setUpButtons() { mBinding.fabSendMessage.setOnClickListener { lifecycleScope.launch { @@ -93,8 +91,7 @@ class ChatFragment : Fragment() { } } - @RequiresApi(Build.VERSION_CODES.O) - private suspend fun sendMessage() { + private fun sendMessage() { val text = mBinding.tieMessage.text.toString() chatViewModel.sendMessage(text, idChat, recipientId) mBinding.tieMessage.text?.clear() diff --git a/app/src/main/java/com/isanz/inmomarket/ui/chat/ChatViewModel.kt b/app/src/main/java/com/isanz/inmomarket/ui/chat/ChatViewModel.kt index a7aefd5..6c473c4 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/chat/ChatViewModel.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/chat/ChatViewModel.kt @@ -1,12 +1,11 @@ package com.isanz.inmomarket.ui.chat import android.content.ContentValues.TAG -import android.os.Build import android.util.Log -import androidx.annotation.RequiresApi import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.google.firebase.database.DataSnapshot import com.google.firebase.database.DatabaseError import com.google.firebase.database.FirebaseDatabase @@ -17,47 +16,53 @@ import com.google.firebase.ktx.Firebase import com.isanz.inmomarket.utils.entities.Conversation import com.isanz.inmomarket.utils.entities.Message import com.isanz.inmomarket.utils.entities.User +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async +import kotlinx.coroutines.launch import kotlinx.coroutines.tasks.await -import kotlinx.coroutines.withContext -import java.time.LocalDateTime -import java.time.format.DateTimeFormatter +import java.text.SimpleDateFormat +import java.util.Calendar +import java.util.Locale import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import kotlin.coroutines.suspendCoroutine -class ChatViewModel : ViewModel() { +class ChatViewModel(private val dispatcher: CoroutineDispatcher = Dispatchers.IO) : ViewModel() { private val database: FirebaseDatabase = Firebase.database private val _messageList = MutableLiveData>() val messageList: LiveData> get() = _messageList - @RequiresApi(Build.VERSION_CODES.O) - suspend fun sendMessage(text: String, chatId: String, senderId: String) { - val message = createMessage(text, senderId) - try { - withContext(Dispatchers.IO) { + private val _messageSentStatus = MutableLiveData() + + fun sendMessage(text: String, chatId: String, senderId: String) { + viewModelScope.launch(dispatcher) { + val message = createMessage(text, senderId) + try { database.getReference("chatMessages").child(chatId).push().setValue(message).await() - database.getReference("chats").child(chatId).child("lastMessage").setValue(message).await() + database.getReference("chats").child(chatId).child("lastMessage").setValue(message) + .await() + _messageSentStatus.postValue(true) + } catch (e: Exception) { + Log.e(TAG, "sendMessage:failure", e) + _messageSentStatus.postValue(false) } - } catch (e: Exception) { - Log.e(TAG, "sendMessage:failure", e) } } - @RequiresApi(Build.VERSION_CODES.O) + private fun createMessage(text: String, senderId: String): Message { - val current = LocalDateTime.now() - val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") - val timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss") + val current = Calendar.getInstance().time + val dateFormatter = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) + val timeFormatter = SimpleDateFormat("HH:mm:ss", Locale.getDefault()) return Message( message = text, senderId = senderId, - messageDate = current.format(dateFormatter), - messageTime = current.format(timeFormatter) + messageDate = dateFormatter.format(current), + messageTime = timeFormatter.format(current) ) } diff --git a/app/src/main/java/com/isanz/inmomarket/ui/conversations/ConversationsFragment.kt b/app/src/main/java/com/isanz/inmomarket/ui/conversations/ConversationsFragment.kt index c45cea8..86e29c1 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/conversations/ConversationsFragment.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/conversations/ConversationsFragment.kt @@ -5,7 +5,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment -import androidx.fragment.app.viewModels import androidx.lifecycle.ViewModelProvider import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager diff --git a/app/src/main/java/com/isanz/inmomarket/ui/conversations/ConversationsViewModel.kt b/app/src/main/java/com/isanz/inmomarket/ui/conversations/ConversationsViewModel.kt index 9a7320e..6914da3 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/conversations/ConversationsViewModel.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/conversations/ConversationsViewModel.kt @@ -27,7 +27,7 @@ class ConversationsViewModel : ViewModel() { private val userId = InmoMarket.getAuth().currentUser!!.uid @RequiresApi(Build.VERSION_CODES.O) - fun sortConversations(conversations: MutableList): List { + fun sortConversations(conversations: List): List { return conversations.sortedByDescending { if (it.lastMessage.messageDate.isNotBlank() && it.lastMessage.messageTime.isNotBlank()) { val dateTimeStr = "${it.lastMessage.messageDate} ${it.lastMessage.messageTime}" @@ -62,7 +62,7 @@ class ConversationsViewModel : ViewModel() { } override fun onCancelled(error: com.google.firebase.database.DatabaseError) { - + Log.w(Constants.TAG, "retrieveConversations:onCancelled", error.toException()) } } chatsRef.addValueEventListener(messageListener) diff --git a/app/src/main/java/com/isanz/inmomarket/ui/home/HomeViewModel.kt b/app/src/main/java/com/isanz/inmomarket/ui/home/HomeViewModel.kt index e6f296c..4edd9d6 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/home/HomeViewModel.kt @@ -10,11 +10,12 @@ import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.firestore.QuerySnapshot import com.isanz.inmomarket.InmoMarket import com.isanz.inmomarket.utils.entities.Property +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -class HomeViewModel : ViewModel() { +class HomeViewModel(private val dispatcher: CoroutineDispatcher = Dispatchers.IO) : ViewModel() { private val _listParcelas = MutableLiveData>() val listParcelas: LiveData> = _listParcelas @@ -34,7 +35,7 @@ class HomeViewModel : ViewModel() { Log.w(TAG, "listenForParcelas:failure", e) } - private suspend fun listenForParcelasUpdates() = withContext(Dispatchers.IO) { + private suspend fun listenForParcelasUpdates() = withContext(dispatcher) { db.collection("properties").addSnapshotListener { snapshot, e -> if (e != null) { logError(e) diff --git a/app/src/main/java/com/isanz/inmomarket/ui/portal/PortalViewModel.kt b/app/src/main/java/com/isanz/inmomarket/ui/portal/PortalViewModel.kt index feb39ff..e816526 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/portal/PortalViewModel.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/portal/PortalViewModel.kt @@ -1,27 +1,32 @@ package com.isanz.inmomarket.ui.portal +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.isanz.inmomarket.InmoMarket import com.isanz.inmomarket.utils.Constants +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import kotlinx.coroutines.tasks.await -import java.lang.Exception -class PortalViewModel : ViewModel() { +class PortalViewModel(private val dispatcher: CoroutineDispatcher = Dispatchers.IO) : ViewModel() { - suspend fun getImageRandom(): String { - val url = try { - val listResult = InmoMarket.getStorage().reference.child("images/portal/") - .listAll() - .await() + private val _imageUrl = MutableLiveData() + fun getImageRandom() { + viewModelScope.launch(dispatcher) { + val url = try { + val listResult = + InmoMarket.getStorage().reference.child("images/portal/").listAll().await() - val images = listResult.items - val image = images.random() - val downloadUrl = image.downloadUrl.await() - downloadUrl.toString() - } catch (e: Exception) { - Constants.LOGIN_IMAGE + val images = listResult.items + val image = images.random() + val downloadUrl = image.downloadUrl.await() + downloadUrl.toString() + } catch (e: Exception) { + Constants.LOGIN_IMAGE + } + _imageUrl.postValue(url) } - return url } - } \ No newline at end of file diff --git a/app/src/main/java/com/isanz/inmomarket/ui/portal/login/LoginActivity.kt b/app/src/main/java/com/isanz/inmomarket/ui/portal/login/LoginActivity.kt index 017cd51..c3b0ead 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/portal/login/LoginActivity.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/portal/login/LoginActivity.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.content.ContentValues.TAG import android.content.Context import android.content.Intent +import android.os.Build import android.os.Bundle import android.util.Log import android.widget.ImageView @@ -103,9 +104,10 @@ class LoginActivity : AppCompatActivity() { } private fun showBiometricPrompt() { - val promptInfo = BiometricPrompt.PromptInfo.Builder().setTitle(getString(R.string.biometric_login)) - .setSubtitle(getString(R.string.login_use_biometric)) - .setNegativeButtonText(getString(R.string.use_account_password)).build() + val promptInfo = + BiometricPrompt.PromptInfo.Builder().setTitle(getString(R.string.biometric_login)) + .setSubtitle(getString(R.string.login_use_biometric)) + .setNegativeButtonText(getString(R.string.use_account_password)).build() val biometricPrompt = BiometricPrompt(this, ContextCompat.getMainExecutor(this), @@ -176,12 +178,13 @@ class LoginActivity : AppCompatActivity() { } } else { Log.w(TAG, "signInWithCredential:failure", task.exception) - Toast.makeText(baseContext, "Authentication failed.", Toast.LENGTH_SHORT).show() + Toast.makeText(baseContext, + getString(R.string.authentication_failed), Toast.LENGTH_SHORT).show() } } } catch (e: Exception) { Log.w(TAG, "signInWithCredential:failure", e) - Toast.makeText(baseContext, "Authentication failed.", Toast.LENGTH_SHORT).show() + Toast.makeText(baseContext, getString(R.string.authentication_failed), Toast.LENGTH_SHORT).show() } } @@ -275,15 +278,18 @@ class LoginActivity : AppCompatActivity() { } } - @Suppress("DEPRECATION") private fun goToRegister() { val intent = Intent(this, RegisterActivity::class.java) startActivity(intent) - overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + overrideActivityTransition(OVERRIDE_TRANSITION_OPEN, R.anim.slide_out_right, R.anim.slide_in_left) + } else { + overridePendingTransition(R.anim.slide_out_right , R.anim.slide_in_left) + } finish() } - private suspend fun setImage(view: ImageView) { + private fun setImage(view: ImageView) { try { Glide.with(this).load(portalViewModel.getImageRandom()).centerCrop().into(view) } catch (e: Exception) { diff --git a/app/src/main/java/com/isanz/inmomarket/ui/portal/register/RegisterActivity.kt b/app/src/main/java/com/isanz/inmomarket/ui/portal/register/RegisterActivity.kt index d3bf46c..0bb001f 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/portal/register/RegisterActivity.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/portal/register/RegisterActivity.kt @@ -2,6 +2,7 @@ package com.isanz.inmomarket.ui.portal.register import android.app.Activity import android.content.Intent +import android.os.Build import android.os.Bundle import android.util.Log import android.widget.ImageView @@ -214,16 +215,18 @@ class RegisterActivity : AppCompatActivity() { } } - @Suppress("DEPRECATION") private fun goToLogin() { val intent = Intent(this, LoginActivity::class.java) startActivity(intent) - overridePendingTransition(R.anim.slide_out_right, R.anim.slide_in_left) - + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + overrideActivityTransition(OVERRIDE_TRANSITION_OPEN, R.anim.slide_in_left, R.anim.slide_out_right) + } else { + overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right) + } finish() } - private suspend fun setImage(view: ImageView) { + private fun setImage(view: ImageView) { Glide.with(this).load(portalViewModel.getImageRandom()).centerCrop().into(view) } } \ No newline at end of file diff --git a/app/src/main/java/com/isanz/inmomarket/ui/profile/ProfileFragment.kt b/app/src/main/java/com/isanz/inmomarket/ui/profile/ProfileFragment.kt index 13da1e3..a213a65 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/profile/ProfileFragment.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/profile/ProfileFragment.kt @@ -9,6 +9,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView +import androidx.activity.result.contract.ActivityResultContracts import androidx.core.view.GravityCompat import androidx.drawerlayout.widget.DrawerLayout import androidx.fragment.app.Fragment @@ -24,7 +25,6 @@ import com.isanz.inmomarket.ui.portal.login.LoginActivity import com.isanz.inmomarket.utils.Constants import kotlinx.coroutines.launch -@Suppress("DEPRECATION") class ProfileFragment : Fragment() { private lateinit var mBinding: FragmentProfileBinding @@ -60,14 +60,13 @@ class ProfileFragment : Fragment() { private fun launchImagePicker() { val intent = Intent(Intent.ACTION_PICK) intent.type = "image/*" - startActivityForResult(intent, Constants.REQUEST_CODE_PICK_IMAGES) + imagePickerResultLauncher.launch(intent) } - @Deprecated("Deprecated in Java") - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - if (requestCode == Constants.REQUEST_CODE_PICK_IMAGES && resultCode == Activity.RESULT_OK && data != null) { - handleImagePicked(data.data) + private val imagePickerResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == Activity.RESULT_OK) { + val imageUri = result.data?.data + handleImagePicked(imageUri) } } @@ -91,7 +90,7 @@ class ProfileFragment : Fragment() { when (position) { 0 -> tab.text = getString(R.string.tab_favorites) 1 -> tab.text = getString(R.string.tab_your_uploads) - else -> throw IllegalStateException("Invalid position") + else -> error("Invalid position") } }.attach() } @@ -140,12 +139,15 @@ class ProfileFragment : Fragment() { } } - private suspend fun setUpView() { + private fun setUpView() { navView = mBinding.navView drawerLayout = mBinding.drawerLayout - val user = profileViewModel.retrieveProfile() - loadImage(mBinding.profileLayout.ivProfile, user.photoUrl!!) - mBinding.profileLayout.tvName.text = user.displayName + profileViewModel.retrieveProfile { user -> + if (user != null) { + loadImage(mBinding.profileLayout.ivProfile, user.photoUrl!!) + mBinding.profileLayout.tvName.text = user.displayName + } + } } private fun loadImage(view: ImageView, url: String) { diff --git a/app/src/main/java/com/isanz/inmomarket/ui/profile/ProfileViewModel.kt b/app/src/main/java/com/isanz/inmomarket/ui/profile/ProfileViewModel.kt index 8aaca8c..60beb43 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/profile/ProfileViewModel.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/profile/ProfileViewModel.kt @@ -3,6 +3,7 @@ package com.isanz.inmomarket.ui.profile import android.net.Uri import android.util.Log import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.google.firebase.auth.FirebaseAuth import com.google.firebase.firestore.FirebaseFirestore import com.google.firebase.storage.FirebaseStorage @@ -10,19 +11,23 @@ import com.google.firebase.storage.StorageReference import com.isanz.inmomarket.InmoMarket import com.isanz.inmomarket.utils.Constants import com.isanz.inmomarket.utils.entities.User +import kotlinx.coroutines.launch import kotlinx.coroutines.tasks.await class ProfileViewModel : ViewModel() { private val db = InmoMarket.getDb() - suspend fun retrieveProfile(): User { - return try { - val userId = InmoMarket.getAuth().currentUser!!.uid - getUserFromDb(userId) - } catch (e: Exception) { - Log.e(Constants.TAG, "retrieveProfile:failure", e) - User() + fun retrieveProfile(callback: (User?) -> Unit) { + viewModelScope.launch { + try { + val userId = InmoMarket.getAuth().currentUser!!.uid + val user = getUserFromDb(userId) + callback(user) + } catch (e: Exception) { + Log.e(Constants.TAG, "retrieveProfile:failure", e) + callback(User()) + } } } diff --git a/app/src/main/java/com/isanz/inmomarket/ui/profile/ViewPagerAdapter.kt b/app/src/main/java/com/isanz/inmomarket/ui/profile/ViewPagerAdapter.kt index cd0900a..c515685 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/profile/ViewPagerAdapter.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/profile/ViewPagerAdapter.kt @@ -16,7 +16,7 @@ class ViewPagerAdapter(fragmentActivity: FragmentActivity) : return when (position) { 0 -> FavoritesProfileFragment() 1 -> YourUploadsProfileFragment() - else -> throw IllegalStateException("Invalid position") + else -> error("Invalid position") } } } \ No newline at end of file diff --git a/app/src/main/java/com/isanz/inmomarket/ui/profile/tabs/favorites/FavoritesProfileFragment.kt b/app/src/main/java/com/isanz/inmomarket/ui/profile/tabs/favorites/FavoritesProfileFragment.kt index 33c00a2..ac4d3bc 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/profile/tabs/favorites/FavoritesProfileFragment.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/profile/tabs/favorites/FavoritesProfileFragment.kt @@ -11,7 +11,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.isanz.inmomarket.R import com.isanz.inmomarket.databinding.FragmentFavoritesProfileBinding import com.isanz.inmomarket.rv.propertyItem.PropertyItemListAdapter -import com.isanz.inmomarket.ui.search.SearchViewModel import com.isanz.inmomarket.utils.entities.Property import com.isanz.inmomarket.utils.interfaces.OnItemClickListener diff --git a/app/src/main/java/com/isanz/inmomarket/ui/profile/tabs/favorites/FavoritesProfileViewModel.kt b/app/src/main/java/com/isanz/inmomarket/ui/profile/tabs/favorites/FavoritesProfileViewModel.kt index 06551be..0dcfa78 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/profile/tabs/favorites/FavoritesProfileViewModel.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/profile/tabs/favorites/FavoritesProfileViewModel.kt @@ -6,13 +6,16 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.google.firebase.firestore.DocumentSnapshot +import com.google.firebase.firestore.QuerySnapshot import com.isanz.inmomarket.InmoMarket import com.isanz.inmomarket.utils.entities.Property +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -class FavoritesProfileViewModel : ViewModel() { +class FavoritesProfileViewModel(private val dispatcher: CoroutineDispatcher = Dispatchers.IO) : ViewModel() { val db = InmoMarket.getDb() private val _listfavorites = MutableLiveData>() @@ -28,31 +31,47 @@ class FavoritesProfileViewModel : ViewModel() { } } - private suspend fun listenForFavorites() = withContext(Dispatchers.IO) { + private suspend fun listenForFavorites() = withContext(dispatcher) { db.collection("properties").addSnapshotListener { snapshot, e -> if (e != null) { - Log.w(ContentValues.TAG, "Listen failed.", e) + logFailure(e) return@addSnapshotListener } try { - if (snapshot != null) { - val properties = mutableListOf() - val currentUserId = InmoMarket.getAuth().currentUser!!.uid - for (document in snapshot.documents) { - if (document.exists()) { - val property = document.toObject(Property::class.java) - property?.id = document.id - if (property?.favorites!!.contains(currentUserId)) { - property.let { properties.add(it) } - } - } - } - _listfavorites.postValue(properties) - } + snapshot?.let { + handleSnapshot(it) + } ?: logNullData() } catch (e: Exception) { - Log.w(ContentValues.TAG, "listenForFavorites:failure.", e) + logFailure(e) } } } + + private fun logFailure(e: Exception) { + Log.w(ContentValues.TAG, "Listen failed.", e) + } + + private fun logNullData() { + Log.d(ContentValues.TAG, "Current data: null") + } + + private fun handleSnapshot(snapshot: QuerySnapshot) { + val properties = mutableListOf() + val currentUserId = InmoMarket.getAuth().currentUser!!.uid + for (document in snapshot.documents) { + if (document.exists()) { + handleDocument(document, currentUserId, properties) + } + } + _listfavorites.postValue(properties) + } + + private fun handleDocument(document: DocumentSnapshot, currentUserId: String, properties: MutableList) { + val property = document.toObject(Property::class.java) + property?.id = document.id + if (property?.favorites!!.contains(currentUserId)) { + property.let { properties.add(it) } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/isanz/inmomarket/ui/profile/tabs/uploads/YourUploadsProfileViewModel.kt b/app/src/main/java/com/isanz/inmomarket/ui/profile/tabs/uploads/YourUploadsProfileViewModel.kt index 3b47627..9d19fe6 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/profile/tabs/uploads/YourUploadsProfileViewModel.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/profile/tabs/uploads/YourUploadsProfileViewModel.kt @@ -6,14 +6,17 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.google.firebase.firestore.DocumentSnapshot import com.google.firebase.firestore.FirebaseFirestore +import com.google.firebase.firestore.QuerySnapshot import com.isanz.inmomarket.InmoMarket import com.isanz.inmomarket.utils.entities.Property +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -class YourUploadsProfileViewModel : ViewModel() { +class YourUploadsProfileViewModel(private val dispatcher: CoroutineDispatcher = Dispatchers.IO) : ViewModel() { private val _listParcelas = MutableLiveData>() val listParcelas: LiveData> = _listParcelas @@ -29,34 +32,49 @@ class YourUploadsProfileViewModel : ViewModel() { } } - private suspend fun listenForParcelasUpdates() = withContext(Dispatchers.IO) { - db.collection("properties").addSnapshotListener { snapshot, e -> - if (e != null) { - Log.w(ContentValues.TAG, "listenForParcelasUpdates:failure", e) - return@addSnapshotListener - } + private suspend fun listenForParcelasUpdates() { + withContext(dispatcher){ + db.collection("properties").addSnapshotListener { snapshot, e -> + if (e != null) { + logFailure(e) + return@addSnapshotListener + } - try { - if (snapshot != null) { - val properties = mutableListOf() - val currentUserId = InmoMarket.getAuth().currentUser!!.uid - for (document in snapshot.documents) { - if (document.exists()) { - val property = document.toObject(Property::class.java) - property?.id = document.id - if (property?.userId == currentUserId) { - property.let { properties.add(it) } - } - } - } - _listParcelas.postValue(properties) - } else { - Log.d(ContentValues.TAG, "Current data: null") + try { + snapshot?.let { + handleSnapshot(it) + } ?: logNullData() + } catch (e: Exception) { + logFailure(e) } - } catch (e: Exception) { - Log.w(ContentValues.TAG, "listenForparcelasUpdates:failure", e) } } + } + + private fun logFailure(e: Exception) { + Log.w(ContentValues.TAG, "listenForParcelasUpdates:failure", e) + } + private fun logNullData() { + Log.d(ContentValues.TAG, "Current data: null") + } + + private fun handleSnapshot(snapshot: QuerySnapshot) { + val properties = mutableListOf() + val currentUserId = InmoMarket.getAuth().currentUser!!.uid + for (document in snapshot.documents) { + if (document.exists()) { + handleDocument(document, currentUserId, properties) + } + } + _listParcelas.postValue(properties) + } + + private fun handleDocument(document: DocumentSnapshot, currentUserId: String, properties: MutableList) { + val property = document.toObject(Property::class.java) + property?.id = document.id + if (property?.userId == currentUserId) { + property.let { properties.add(it) } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/isanz/inmomarket/ui/property/MiniPropertyFragment.kt b/app/src/main/java/com/isanz/inmomarket/ui/property/MiniPropertyFragment.kt index e01907e..7cb73a1 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/property/MiniPropertyFragment.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/property/MiniPropertyFragment.kt @@ -41,11 +41,12 @@ class MiniPropertyFragment : DialogFragment() { return mBinding.root } - private suspend fun setUp(propertyId: String?) { - val property = propertyViewModel.retrieveProperty(propertyId!!) - if (property != null) { - setPropertyDetails(property) - setOverlayClickListener(propertyId) + private fun setUp(propertyId: String?) { + propertyViewModel.retrieveProperty(propertyId!!) { property -> + if (property != null) { + setPropertyDetails(property) + setOverlayClickListener(propertyId) + } } } diff --git a/app/src/main/java/com/isanz/inmomarket/ui/property/PropertyFragment.kt b/app/src/main/java/com/isanz/inmomarket/ui/property/PropertyFragment.kt index 7110e76..2f40f8d 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/property/PropertyFragment.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/property/PropertyFragment.kt @@ -80,37 +80,41 @@ class PropertyFragment : Fragment() { return mBinding.root } - private suspend fun setUpView(propertyId: String?) { - val property = propertyViewModel.retrieveProperty(propertyId!!) - if (property != null) { - mBinding.tvProperty.text = property.tittle - mBinding.tvDescription.text = property.description - "${property.location.split(",")[0]}, ${property.location.split(",")[1]}, ${ - property.location.split( - "," - )[2].split(" ")[1] - }".also { mBinding.tvAddress.text = it } - - (property.price.toInt().toString() + "€").also { mBinding.tvPrice.text = it } - val imageList = property.listImagesUri - val adapter = CarouselAdapter(imageList) - this.mBinding.vpProperty.adapter = adapter - - setupIndicators(imageList.size) - - this.mBinding.vpProperty.registerOnPageChangeCallback(object : - ViewPager2.OnPageChangeCallback() { - override fun onPageSelected(position: Int) { - super.onPageSelected(position) - setCurrentIndicator(position) + private fun setUpView(propertyId: String?) { + propertyViewModel.retrieveProperty(propertyId!!) { property -> + if (property != null) { + mBinding.tvProperty.text = property.tittle + mBinding.tvDescription.text = property.description + "${property.location.split(",")[0]}, ${property.location.split(",")[1]}, ${ + property.location.split( + "," + )[2].split(" ")[1] + }".also { mBinding.tvAddress.text = it } + + (property.price.toInt().toString() + "€").also { mBinding.tvPrice.text = it } + val imageList = property.listImagesUri + val adapter = CarouselAdapter(imageList) + this.mBinding.vpProperty.adapter = adapter + + setupIndicators(imageList.size) + + this.mBinding.vpProperty.registerOnPageChangeCallback(object : + ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + setCurrentIndicator(position) + } + }) + propertyViewModel.retrieveProfile(property.userId) { user -> + if (user != null) { + mBinding.tvProfile.text = user.displayName + Glide.with(this).load(user.photoUrl).circleCrop().into(mBinding.ivProfile) + } } - }) - val user = propertyViewModel.retrieveProfile(property.userId) - mBinding.tvProfile.text = user.displayName - Glide.with(this).load(user.photoUrl).circleCrop().into(mBinding.ivProfile) - loadExtras(property) - setUpButtons(property) - mBinding.progressBar.visibility = View.GONE + loadExtras(property) + setUpButtons(property) + mBinding.progressBar.visibility = View.GONE + } } } diff --git a/app/src/main/java/com/isanz/inmomarket/ui/property/PropertyViewModel.kt b/app/src/main/java/com/isanz/inmomarket/ui/property/PropertyViewModel.kt index ef15390..0acfbac 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/property/PropertyViewModel.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/property/PropertyViewModel.kt @@ -35,7 +35,7 @@ class PropertyViewModel : ViewModel() { try { val docRef = db.collection("properties").document(property.id!!) docRef.get().addOnSuccessListener { document -> - val favorites = document.get("favorites") as? List<*> + val favorites = document["favorites"] as? List<*> if (favorites != null && favorites.contains(user!!.uid)) { callback(true) } else { @@ -55,7 +55,7 @@ class PropertyViewModel : ViewModel() { try { val docRef = db.collection("properties").document(property.id!!) docRef.get().addOnSuccessListener { document -> - val favorites = document.get("favorites") as? List<*> + val favorites = document["favorites"] as? List<*> if (favorites != null && favorites.contains(user!!.uid)) { updateFavoriteIcon(false) docRef.update("favorites", FieldValue.arrayRemove(user.uid)) @@ -81,27 +81,35 @@ class PropertyViewModel : ViewModel() { } } - suspend fun retrieveProperty(propertyId: String): Property? { - return try { - val document = db.collection("properties").document(propertyId).get().await() - if (document.exists()) { - val property = document.toObject(Property::class.java) - property?.id = document.id - property - } else { - null + fun retrieveProperty(propertyId: String, callback: (Property?) -> Unit) { + viewModelScope.launch { + try { + val document = db.collection("properties").document(propertyId).get().await() + if (document.exists()) { + val property = document.toObject(Property::class.java) + property?.id = document.id + callback(property) + } else { + callback(null) + } + } catch (e: Exception) { + Log.e(Constants.TAG, "retrieveProperty:failure", e) + callback(null) } - } catch (e: Exception) { - Log.e( - Constants.TAG, "retrieveProperty:failure", e - ) - null } } - suspend fun retrieveProfile(userId: String): User { - val user = db.collection("users").document(userId).get().await() - return user.toObject(User::class.java)!! + fun retrieveProfile(userId: String, callback: (User?) -> Unit) { + viewModelScope.launch { + try { + val userDocument = db.collection("users").document(userId).get().await() + val user = userDocument.toObject(User::class.java) + callback(user) + } catch (e: Exception) { + Log.e(Constants.TAG, "retrieveProfile:failure", e) + callback(null) + } + } } fun createChat(senderId: String, recipientId: String, callback: (String) -> Unit) { diff --git a/app/src/main/java/com/isanz/inmomarket/ui/search/SearchFragment.kt b/app/src/main/java/com/isanz/inmomarket/ui/search/SearchFragment.kt index 24a9b23..fc035bb 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/search/SearchFragment.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/search/SearchFragment.kt @@ -11,6 +11,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast +import androidx.activity.result.contract.ActivityResultContracts import androidx.core.app.ActivityCompat import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider @@ -25,9 +26,7 @@ import com.google.android.gms.maps.model.BitmapDescriptorFactory import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.MarkerOptions import com.isanz.inmomarket.R -import com.isanz.inmomarket.utils.Constants -@Suppress("DEPRECATION") class SearchFragment : Fragment(), OnMapReadyCallback { private lateinit var mMap: GoogleMap @@ -71,6 +70,18 @@ class SearchFragment : Fragment(), OnMapReadyCallback { checkLocationPermission() } + private val requestPermissionLauncher = registerForActivityResult( + ActivityResultContracts.RequestMultiplePermissions() + ) { permissions -> + val locationPermissionGranted = + permissions[Manifest.permission.ACCESS_FINE_LOCATION] ?: false + if (locationPermissionGranted) { + enableUserLocation() + } else { + Toast.makeText(requireContext(), "Permission denied", Toast.LENGTH_SHORT).show() + } + } + private fun checkLocationPermission() { if (ActivityCompat.checkSelfPermission( requireContext(), Manifest.permission.ACCESS_FINE_LOCATION @@ -78,40 +89,30 @@ class SearchFragment : Fragment(), OnMapReadyCallback { requireContext(), Manifest.permission.ACCESS_COARSE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) { - + requestPermissionLauncher.launch( + arrayOf( + Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION + ) + ) return } enableUserLocation() } - @Deprecated("Deprecated in Java") - override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray - ) { - if (requestCode == Constants.LOCATION_PERMISSION_REQUEST_CODE) { - if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - enableUserLocation() - } else { - Toast.makeText(requireContext(), "Permission denied", Toast.LENGTH_SHORT).show() - } - } - } - private fun enableUserLocation() { if (allowUbication) { if (ActivityCompat.checkSelfPermission( - requireContext(), - Manifest.permission.ACCESS_FINE_LOCATION + requireContext(), Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( - requireContext(), - Manifest.permission.ACCESS_COARSE_LOCATION + requireContext(), Manifest.permission.ACCESS_COARSE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) { - requestPermissions( + requestPermissionLauncher.launch( arrayOf( Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION - ), Constants.LOCATION_PERMISSION_REQUEST_CODE + ) ) return } @@ -127,18 +128,16 @@ class SearchFragment : Fragment(), OnMapReadyCallback { private fun setMapLocationToUserLocation() { if (ActivityCompat.checkSelfPermission( - requireContext(), - Manifest.permission.ACCESS_FINE_LOCATION + requireContext(), Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( - requireContext(), - Manifest.permission.ACCESS_COARSE_LOCATION + requireContext(), Manifest.permission.ACCESS_COARSE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) { - requestPermissions( + requestPermissionLauncher.launch( arrayOf( Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION - ), Constants.LOCATION_PERMISSION_REQUEST_CODE + ) ) return } diff --git a/app/src/main/java/com/isanz/inmomarket/ui/settings/SettingsFragment.kt b/app/src/main/java/com/isanz/inmomarket/ui/settings/SettingsFragment.kt index e850714..4da6f37 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/settings/SettingsFragment.kt @@ -11,7 +11,6 @@ import androidx.lifecycle.ViewModelProvider import androidx.navigation.fragment.findNavController import com.isanz.inmomarket.InmoMarket import com.isanz.inmomarket.databinding.FragmentSettingsBinding -import com.isanz.inmomarket.ui.home.HomeViewModel class SettingsFragment : Fragment() { diff --git a/app/src/main/java/com/isanz/inmomarket/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/isanz/inmomarket/ui/settings/SettingsViewModel.kt index 3cb6529..f3d19d5 100644 --- a/app/src/main/java/com/isanz/inmomarket/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/isanz/inmomarket/ui/settings/SettingsViewModel.kt @@ -62,6 +62,7 @@ class SettingsViewModel : ViewModel() { } override fun onCancelled(databaseError: DatabaseError) { + Log.e(Constants.TAG, "deleteChats:onCancelled", databaseError.toException()) } }) } catch (e: Exception) { diff --git a/app/src/main/java/com/isanz/inmomarket/utils/Constants.kt b/app/src/main/java/com/isanz/inmomarket/utils/Constants.kt index 2805824..fb56593 100644 --- a/app/src/main/java/com/isanz/inmomarket/utils/Constants.kt +++ b/app/src/main/java/com/isanz/inmomarket/utils/Constants.kt @@ -3,9 +3,6 @@ package com.isanz.inmomarket.utils object Constants { const val TAG: String = "com.isanz.inmomarket" - const val REQUEST_CODE_PICK_IMAGES = 1 - const val REQUEST_CODE_AUTOCOMPLETE = 2 - const val LOCATION_PERMISSION_REQUEST_CODE = 1 const val API_GOOGLE = "AIzaSyCqFDsTiczZy6sYp1Tkr0Jp1pXOaUc4Nls" const val DEFAULT_IMAGE = "https://firebasestorage.googleapis.com/v0/b/inmomarket0.appspot.com/o/images%2Fdefault%2Fdefault_user_icon.jpg?alt=media&token=985bc947-2895-4b69-ad06-5e5891e6f463" diff --git a/app/src/main/java/com/isanz/inmomarket/utils/interfaces/OnItemClickListener.kt b/app/src/main/java/com/isanz/inmomarket/utils/interfaces/OnItemClickListener.kt index 08cc93a..1cdd762 100644 --- a/app/src/main/java/com/isanz/inmomarket/utils/interfaces/OnItemClickListener.kt +++ b/app/src/main/java/com/isanz/inmomarket/utils/interfaces/OnItemClickListener.kt @@ -1,5 +1,5 @@ package com.isanz.inmomarket.utils.interfaces -interface OnItemClickListener { +fun interface OnItemClickListener { fun onItemClicked(propertyId: String) } \ No newline at end of file diff --git a/app/src/main/java/com/isanz/inmomarket/utils/retrofit/GeocodingService.kt b/app/src/main/java/com/isanz/inmomarket/utils/retrofit/GeocodingService.kt index e6b0e3c..63a8cb1 100644 --- a/app/src/main/java/com/isanz/inmomarket/utils/retrofit/GeocodingService.kt +++ b/app/src/main/java/com/isanz/inmomarket/utils/retrofit/GeocodingService.kt @@ -1,11 +1,10 @@ package com.isanz.inmomarket.utils.retrofit -import com.isanz.inmomarket.utils.retrofit.GeocodingResponse import retrofit2.Call import retrofit2.http.GET import retrofit2.http.Query -interface GeocodingService { +fun interface GeocodingService { @GET("maps/api/geocode/json") fun getLatLng( @Query("address") location: String, diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 6e6b3be..2a01419 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -92,5 +92,6 @@ Melden Sie sich mit Ihrem biometrischen Ausweis an Biometrische Anmeldung Konto-Passwort verwenden + Authentifizierung fehlgeschlagen diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 269075d..77a860f 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -92,5 +92,6 @@ Melden Sie sich mit Ihrem biometrischen Ausweis an Biometrische Anmeldung Konto-Passwort verwenden + Autenticación fallida diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 0f1805a..e7c47d1 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -92,6 +92,7 @@ Connectez-vous avec vos informations biométriques Connexion biométrique Utiliser le mot de passe du compte + Authentification échouée diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 515cc53..e829083 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -92,4 +92,5 @@ Accedi utilizzando le tue credenziali biometriche Accesso biometrico Utilizza la password dell\'account + Autenticazione fallita diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 42d6324..926d699 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -93,4 +93,5 @@ Log in using your biometric credential Biometric login Use account password + Authentication failed. \ No newline at end of file