From b7def58edc3e974213209cffb3b9ecd264c59f69 Mon Sep 17 00:00:00 2001 From: erike Date: Sat, 13 Jan 2024 23:12:31 -0600 Subject: [PATCH] feature: codigo qr y link de usuario --- app/build.gradle | 3 + .../profile/data/remote/UserProfileDto.kt | 1 + .../profile/domain/entity/UserProfile.kt | 2 + .../profile/ui/ProfileMainFragment.kt | 4 + .../isolaatti/profile/ui/QrCodeFragment.kt | 73 +++++++++++++++++++ .../main/res/drawable/baseline_share_24.xml | 5 ++ app/src/main/res/layout/fragment_qr_code.xml | 40 ++++++++++ app/src/main/res/menu/qr_code_menu.xml | 9 +++ .../res/navigation/profile_navigation.xml | 12 +++ build.gradle | 1 + 10 files changed, 150 insertions(+) create mode 100644 app/src/main/java/com/isolaatti/profile/ui/QrCodeFragment.kt create mode 100644 app/src/main/res/drawable/baseline_share_24.xml create mode 100644 app/src/main/res/layout/fragment_qr_code.xml create mode 100644 app/src/main/res/menu/qr_code_menu.xml diff --git a/app/build.gradle b/app/build.gradle index cc0b240..5e16cd7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -122,4 +122,7 @@ dependencies { implementation 'androidx.media3:media3-exoplayer:1.2.0' implementation "androidx.media3:media3-ui:1.2.0" + // QR + implementation 'com.github.androidmads:QRGenerator:1.0.1' + } \ No newline at end of file diff --git a/app/src/main/java/com/isolaatti/profile/data/remote/UserProfileDto.kt b/app/src/main/java/com/isolaatti/profile/data/remote/UserProfileDto.kt index 63d967c..b93086a 100644 --- a/app/src/main/java/com/isolaatti/profile/data/remote/UserProfileDto.kt +++ b/app/src/main/java/com/isolaatti/profile/data/remote/UserProfileDto.kt @@ -4,6 +4,7 @@ import com.isolaatti.audio.common.data.AudioDto data class UserProfileDto( val id: Int, + val uniqueUsername: String, val name: String, val email: String?, val numberOfFollowers: Int, diff --git a/app/src/main/java/com/isolaatti/profile/domain/entity/UserProfile.kt b/app/src/main/java/com/isolaatti/profile/domain/entity/UserProfile.kt index bd3026a..d0a4a42 100644 --- a/app/src/main/java/com/isolaatti/profile/domain/entity/UserProfile.kt +++ b/app/src/main/java/com/isolaatti/profile/domain/entity/UserProfile.kt @@ -8,6 +8,7 @@ import java.io.Serializable data class UserProfile( override val userId: Int, + val uniqueUsername: String, var name: String, val email: String?, val numberOfFollowers: Int, @@ -29,6 +30,7 @@ data class UserProfile( fun fromDto(userProfileDto: UserProfileDto): UserProfile { return UserProfile( userId = userProfileDto.id, + uniqueUsername = userProfileDto.uniqueUsername, name = userProfileDto.name, email = userProfileDto.email, numberOfFollowers = userProfileDto.numberOfFollowers, diff --git a/app/src/main/java/com/isolaatti/profile/ui/ProfileMainFragment.kt b/app/src/main/java/com/isolaatti/profile/ui/ProfileMainFragment.kt index 0c7c1c3..cdac403 100644 --- a/app/src/main/java/com/isolaatti/profile/ui/ProfileMainFragment.kt +++ b/app/src/main/java/com/isolaatti/profile/ui/ProfileMainFragment.kt @@ -285,6 +285,10 @@ class ProfileMainFragment : Fragment() { true } R.id.user_link_menu_item -> { + viewModel.profile.value?.let { profile -> + findNavController().navigate(ProfileMainFragmentDirections.actionMainFragmentToQrCodeFragment(profile)) + } + true } R.id.report_profile_menu_item -> { diff --git a/app/src/main/java/com/isolaatti/profile/ui/QrCodeFragment.kt b/app/src/main/java/com/isolaatti/profile/ui/QrCodeFragment.kt new file mode 100644 index 0000000..97c52d8 --- /dev/null +++ b/app/src/main/java/com/isolaatti/profile/ui/QrCodeFragment.kt @@ -0,0 +1,73 @@ +package com.isolaatti.profile.ui + +import android.content.Intent +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidmads.library.qrgenearator.BuildConfig +import androidmads.library.qrgenearator.QRGContents +import androidmads.library.qrgenearator.QRGEncoder +import androidx.core.content.res.ResourcesCompat +import androidx.fragment.app.Fragment +import androidx.navigation.fragment.findNavController +import androidx.navigation.fragment.navArgs +import com.isolaatti.R +import com.isolaatti.databinding.FragmentQrCodeBinding +import com.isolaatti.utils.UrlGen + +class QrCodeFragment : Fragment() { + + private lateinit var binding: FragmentQrCodeBinding + private val args: QrCodeFragmentArgs by navArgs() + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + binding = FragmentQrCodeBinding.inflate(layoutInflater) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + generateQR(generateUrl()) + binding.usernameText.text ="@${args.profile.uniqueUsername}" + + binding.toolbar.menu.findItem(R.id.share).icon?.setTint(ResourcesCompat.getColor(resources, android.R.color.white, null)) + + binding.toolbar.setOnMenuItemClickListener { + when(it.itemId) { + R.id.share -> { + share() + true + } + else -> false + } + } + + binding.toolbar.setNavigationOnClickListener { + findNavController().popBackStack() + } + } + + private fun generateUrl(): String { + return "${com.isolaatti.BuildConfig.backend}/@${args.profile.uniqueUsername}" + } + private fun generateQR(text: String) { + val qrgEncoder = QRGEncoder(text, null, QRGContents.Type.TEXT, 200) + + val bitmap = qrgEncoder.getBitmap(0) + + binding.imageView.setImageBitmap(bitmap) + } + + private fun share() { + val intent = Intent(Intent.ACTION_SEND).apply { + type = "text/uri" + putExtra(Intent.EXTRA_TEXT, generateUrl()) + } + + startActivity(Intent.createChooser(intent, "Share profile")) + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/baseline_share_24.xml b/app/src/main/res/drawable/baseline_share_24.xml new file mode 100644 index 0000000..87cea78 --- /dev/null +++ b/app/src/main/res/drawable/baseline_share_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/fragment_qr_code.xml b/app/src/main/res/layout/fragment_qr_code.xml new file mode 100644 index 0000000..fa0a444 --- /dev/null +++ b/app/src/main/res/layout/fragment_qr_code.xml @@ -0,0 +1,40 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/qr_code_menu.xml b/app/src/main/res/menu/qr_code_menu.xml new file mode 100644 index 0000000..ae08b42 --- /dev/null +++ b/app/src/main/res/menu/qr_code_menu.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/profile_navigation.xml b/app/src/main/res/navigation/profile_navigation.xml index 30b5b8c..1b2e0cc 100644 --- a/app/src/main/res/navigation/profile_navigation.xml +++ b/app/src/main/res/navigation/profile_navigation.xml @@ -28,6 +28,10 @@ app:destination="@id/mainFollowersFragment"> + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 60de2e7..210657a 100644 --- a/build.gradle +++ b/build.gradle @@ -4,6 +4,7 @@ buildscript { gradlePluginPortal() google() mavenCentral() + maven { url 'https://jitpack.io' } } dependencies { def nav_version = "2.6.0"