feature: codigo qr y link de usuario

This commit is contained in:
erike 2024-01-13 23:12:31 -06:00
parent 2a72ea0d09
commit b7def58edc
10 changed files with 150 additions and 0 deletions

View File

@ -122,4 +122,7 @@ dependencies {
implementation 'androidx.media3:media3-exoplayer:1.2.0' implementation 'androidx.media3:media3-exoplayer:1.2.0'
implementation "androidx.media3:media3-ui:1.2.0" implementation "androidx.media3:media3-ui:1.2.0"
// QR
implementation 'com.github.androidmads:QRGenerator:1.0.1'
} }

View File

@ -4,6 +4,7 @@ import com.isolaatti.audio.common.data.AudioDto
data class UserProfileDto( data class UserProfileDto(
val id: Int, val id: Int,
val uniqueUsername: String,
val name: String, val name: String,
val email: String?, val email: String?,
val numberOfFollowers: Int, val numberOfFollowers: Int,

View File

@ -8,6 +8,7 @@ import java.io.Serializable
data class UserProfile( data class UserProfile(
override val userId: Int, override val userId: Int,
val uniqueUsername: String,
var name: String, var name: String,
val email: String?, val email: String?,
val numberOfFollowers: Int, val numberOfFollowers: Int,
@ -29,6 +30,7 @@ data class UserProfile(
fun fromDto(userProfileDto: UserProfileDto): UserProfile { fun fromDto(userProfileDto: UserProfileDto): UserProfile {
return UserProfile( return UserProfile(
userId = userProfileDto.id, userId = userProfileDto.id,
uniqueUsername = userProfileDto.uniqueUsername,
name = userProfileDto.name, name = userProfileDto.name,
email = userProfileDto.email, email = userProfileDto.email,
numberOfFollowers = userProfileDto.numberOfFollowers, numberOfFollowers = userProfileDto.numberOfFollowers,

View File

@ -285,6 +285,10 @@ class ProfileMainFragment : Fragment() {
true true
} }
R.id.user_link_menu_item -> { R.id.user_link_menu_item -> {
viewModel.profile.value?.let { profile ->
findNavController().navigate(ProfileMainFragmentDirections.actionMainFragmentToQrCodeFragment(profile))
}
true true
} }
R.id.report_profile_menu_item -> { R.id.report_profile_menu_item -> {

View File

@ -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"))
}
}

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
</vector>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/purple">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:navigationIcon="@drawable/baseline_close_24"
app:navigationIconTint="#FFF"
app:menu="@menu/qr_code_menu"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="40dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/baseline_qr_code_24"/>
<TextView
android:id="@+id/usernameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView"
android:textColor="#FFF"
android:textSize="18sp"
android:layout_marginHorizontal="24dp"
android:textAlignment="center"
tools:text="\@username" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/share"
android:title="@string/save"
android:icon="@drawable/baseline_share_24"
app:showAsAction="always"/>
</menu>

View File

@ -28,6 +28,10 @@
app:destination="@id/mainFollowersFragment"> app:destination="@id/mainFollowersFragment">
</action> </action>
<action
android:id="@+id/action_mainFragment_to_qrCodeFragment"
app:destination="@id/qrCodeFragment"
app:popExitAnim="@android:anim/slide_out_right" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/audiosFragment" android:id="@+id/audiosFragment"
@ -73,4 +77,12 @@
<argument <argument
android:name="userId" android:name="userId"
app:argType="integer" /> app:argType="integer" />
<fragment
android:id="@+id/qrCodeFragment"
android:name="com.isolaatti.profile.ui.QrCodeFragment"
android:label="QrCodeFragment" >
<argument
android:name="profile"
app:argType="com.isolaatti.profile.domain.entity.UserProfile" />
</fragment>
</navigation> </navigation>

View File

@ -4,6 +4,7 @@ buildscript {
gradlePluginPortal() gradlePluginPortal()
google() google()
mavenCentral() mavenCentral()
maven { url 'https://jitpack.io' }
} }
dependencies { dependencies {
def nav_version = "2.6.0" def nav_version = "2.6.0"