binding
This commit is contained in:
3
.idea/misc.xml
generated
Normal file
3
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -6,11 +6,9 @@ import android.app.Activity.RESULT_OK
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@@ -18,6 +16,7 @@ import android.widget.ImageView
|
|||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import androidx.navigation.fragment.navArgs
|
import androidx.navigation.fragment.navArgs
|
||||||
@@ -85,7 +84,7 @@ class CaptureUserImageFragment : Fragment() {
|
|||||||
|
|
||||||
private fun setupCameraLauncher() {
|
private fun setupCameraLauncher() {
|
||||||
cameraLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
cameraLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||||
if (result.resultCode == Activity.RESULT_OK && result.data != null) {
|
if (result.resultCode == RESULT_OK && result.data != null) {
|
||||||
val thumbnail: Bitmap = result.data!!.extras!!.get("data") as Bitmap
|
val thumbnail: Bitmap = result.data!!.extras!!.get("data") as Bitmap
|
||||||
val uri: Uri = saveImageToInternalStorage(thumbnail)
|
val uri: Uri = saveImageToInternalStorage(thumbnail)
|
||||||
uri.let {
|
uri.let {
|
||||||
@@ -125,6 +124,20 @@ class CaptureUserImageFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun submitImage(uri: Uri) {
|
private fun submitImage(uri: Uri) {
|
||||||
|
|
||||||
|
val cropLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||||
|
if (result.resultCode == RESULT_OK && result.data != null) {
|
||||||
|
val resultUri: Uri? = UCrop.getOutput(result.data!!)
|
||||||
|
binding.userImage.loadImageFromUri(Uri.parse(resultUri.toString()))
|
||||||
|
} else if (result.resultCode == UCrop.RESULT_ERROR) {
|
||||||
|
val cropError: Throwable? = UCrop.getError(result.data!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// val cropIntent: Intent = // Create your crop intent here
|
||||||
|
// cropLauncher.launch(cropIntent)
|
||||||
|
|
||||||
|
|
||||||
// userData.userImage = uri.toString()
|
// userData.userImage = uri.toString()
|
||||||
// viewModel.insert(userData)
|
// viewModel.insert(userData)
|
||||||
// navigate()
|
// navigate()
|
||||||
@@ -139,23 +152,15 @@ class CaptureUserImageFragment : Fragment() {
|
|||||||
.withMaxResultSize(maxWidth, maxHeight)
|
.withMaxResultSize(maxWidth, maxHeight)
|
||||||
.start(requireActivity())
|
.start(requireActivity())
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
// super.onActivityResult(requestCode, resultCode, data)
|
if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
|
||||||
// if (resultCode == RESULT_OK) when (requestCode) {
|
val resultUri: Uri? = data?.let { UCrop.getOutput(it) }
|
||||||
// UCrop.REQUEST_CROP -> {
|
binding.userImage.loadImageFromUri(Uri.parse(resultUri.toString()))
|
||||||
// val fi = headPic.inputStream()
|
} else if (resultCode == UCrop.RESULT_ERROR) {
|
||||||
// navhbg.setImageBitmap(BitmapFactory.decodeStream(fi))
|
val cropError: Throwable? = data?.let { UCrop.getError(it) }
|
||||||
// fi.close()
|
}
|
||||||
// }
|
}
|
||||||
// 1 -> {
|
|
||||||
// data?.data?.let {
|
|
||||||
// saveFile(it)
|
|
||||||
// cropImageUri()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private fun navigate() {
|
private fun navigate() {
|
||||||
val action = CaptureUserImageFragmentDirections
|
val action = CaptureUserImageFragmentDirections
|
||||||
@@ -207,14 +212,14 @@ class CaptureUserImageFragment : Fragment() {
|
|||||||
requestPermissionLauncher.launch(permissions)
|
requestPermissionLauncher.launch(permissions)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
|
||||||
super.onDestroyView()
|
|
||||||
_binding = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun ImageView.loadImageFromUri(uri: Uri) {
|
private fun ImageView.loadImageFromUri(uri: Uri) {
|
||||||
Glide.with(this)
|
Glide.with(this)
|
||||||
.load(uri)
|
.load(uri)
|
||||||
.into(this)
|
.into(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
super.onDestroyView()
|
||||||
|
_binding = null
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user