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.pm.PackageManager
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -18,6 +16,7 @@ import android.widget.ImageView
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
@@ -85,7 +84,7 @@ class CaptureUserImageFragment : Fragment() {
|
||||
|
||||
private fun setupCameraLauncher() {
|
||||
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 uri: Uri = saveImageToInternalStorage(thumbnail)
|
||||
uri.let {
|
||||
@@ -125,6 +124,20 @@ class CaptureUserImageFragment : Fragment() {
|
||||
}
|
||||
|
||||
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()
|
||||
// viewModel.insert(userData)
|
||||
// navigate()
|
||||
@@ -139,23 +152,15 @@ class CaptureUserImageFragment : Fragment() {
|
||||
.withMaxResultSize(maxWidth, maxHeight)
|
||||
.start(requireActivity())
|
||||
}
|
||||
//
|
||||
// override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
// super.onActivityResult(requestCode, resultCode, data)
|
||||
// if (resultCode == RESULT_OK) when (requestCode) {
|
||||
// UCrop.REQUEST_CROP -> {
|
||||
// val fi = headPic.inputStream()
|
||||
// navhbg.setImageBitmap(BitmapFactory.decodeStream(fi))
|
||||
// fi.close()
|
||||
// }
|
||||
// 1 -> {
|
||||
// data?.data?.let {
|
||||
// saveFile(it)
|
||||
// cropImageUri()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
|
||||
val resultUri: Uri? = data?.let { UCrop.getOutput(it) }
|
||||
binding.userImage.loadImageFromUri(Uri.parse(resultUri.toString()))
|
||||
} else if (resultCode == UCrop.RESULT_ERROR) {
|
||||
val cropError: Throwable? = data?.let { UCrop.getError(it) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun navigate() {
|
||||
val action = CaptureUserImageFragmentDirections
|
||||
@@ -207,14 +212,14 @@ class CaptureUserImageFragment : Fragment() {
|
||||
requestPermissionLauncher.launch(permissions)
|
||||
}
|
||||
|
||||
private fun ImageView.loadImageFromUri(uri: Uri) {
|
||||
Glide.with(this)
|
||||
.load(uri)
|
||||
.into(this)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
|
||||
private fun ImageView.loadImageFromUri(uri: Uri) {
|
||||
Glide.with(this)
|
||||
.load(uri)
|
||||
.into(this)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user