Skip to content

Commit

Permalink
#91 AI카메라 화면 오류 수정 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
pknujsp committed Jun 1, 2023
1 parent d6b1a43 commit dad2251
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 55 deletions.
5 changes: 5 additions & 0 deletions core/ui/src/main/res/drawable/baseline_add_24.xml
Original file line number Diff line number Diff line change
@@ -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="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
5 changes: 5 additions & 0 deletions core/ui/src/main/res/drawable/baseline_remove_24.xml
Original file line number Diff line number Diff line change
@@ -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="M19,13H5v-2h14v2z"/>
</vector>
1 change: 1 addition & 0 deletions feature/camera/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ dependencies {
implementation(libs.bundles.navigations)
implementation(libs.bundles.lifecycles)
implementation(libs.kotlinx.datetime)
implementation(libs.photo.view)

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
package com.android.mediproject.feature.camera.imagedialog

import android.annotation.SuppressLint
import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ScaleGestureDetector
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener
import android.view.View
import android.view.ViewGroup
import android.view.Window
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import com.android.mediproject.core.common.bindingadapter.GlideApp
import com.android.mediproject.core.common.viewmodel.UiState
import com.android.mediproject.feature.camera.MedicinesDetectorViewModel
import com.android.mediproject.feature.camera.R
import com.android.mediproject.feature.camera.databinding.FragmentDetectedImageDialogBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
import repeatOnStarted


@AndroidEntryPoint
Expand All @@ -27,48 +19,26 @@ class DetectedImageFragment : DialogFragment() {

private val medicinesDetectorViewModel by activityViewModels<MedicinesDetectorViewModel>()

private lateinit var scaleGestureDetector: ScaleGestureDetector

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = super.onCreateDialog(savedInstanceState).also { dialog ->
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog.setCanceledOnTouchOutside(false)
dialog.setCancelable(false)
}


@SuppressLint("ClickableViewAccessibility")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewModel = medicinesDetectorViewModel
viewLifecycleOwner.repeatOnStarted {
medicinesDetectorViewModel.capturedImage.collectLatest {
when (it) {
is UiState.Success -> {
GlideApp.with(requireContext()).load(it.data).into(binding.imageView)
}

else -> {

}
}
}
}

binding.apply {
scaleGestureDetector = ScaleGestureDetector(requireContext(), object : SimpleOnScaleGestureListener() {
private var mScaleFactor = 1.0f

override fun onScale(detector: ScaleGestureDetector): Boolean {
mScaleFactor *= scaleGestureDetector.scaleFactor
mScaleFactor = maxOf(0.1f, minOf(mScaleFactor, 10.0f))
imageView.scaleX = mScaleFactor
imageView.scaleY = mScaleFactor
return true
}
})

imageView.setOnTouchListener { v, event ->
scaleGestureDetector.onTouchEvent(event)
viewModel = medicinesDetectorViewModel
backBtn.setOnClickListener {
dismiss()
}
imageView.minimumScale = 1.0f
imageView.maximumScale = 2.5f
zoomIn.setOnClickListener {
val scale = imageView.scale + 0.4f
if (scale <= imageView.maximumScale) imageView.setScale(scale, true)
else imageView.setScale(imageView.maximumScale, true)
}
zoomOut.setOnClickListener {
val scale = imageView.scale - 0.4f
if (scale >= imageView.minimumScale) imageView.setScale(scale, true)
else imageView.setScale(imageView.minimumScale, true)
}
}
}
Expand All @@ -79,9 +49,7 @@ class DetectedImageFragment : DialogFragment() {
return binding.root
}

override fun getView(): View {
return binding.root
}
override fun getTheme(): Int = R.style.DialogFullscreen

override fun onDestroyView() {
_binding = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,59 @@
</data>


<FrameLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true">
android:layout_height="match_parent">

<ImageView

<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:contentDescription="@string/capturedImage"
app:img="@{viewModel.capturedImageValue}" />

</FrameLayout>

<ImageButton
android:id="@+id/backBtn"
style="@style/Widget.Material3.Button.IconButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="48dp"
android:contentDescription="@string/back"
android:src="@drawable/left_arrow"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="@color/black" />

<ImageButton
android:id="@+id/zoomIn"
style="@style/Widget.Material3.Button.IconButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginBottom="16dp"
android:contentDescription="@string/zoomIn"
android:src="@drawable/baseline_add_24"
app:layout_constraintBottom_toTopOf="@id/zoomOut"
app:layout_constraintEnd_toEndOf="parent"
app:tint="@color/black" />

<ImageButton
android:id="@+id/zoomOut"
style="@style/Widget.Material3.Button.IconButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginBottom="48dp"
android:contentDescription="@string/zoomOut"
android:src="@drawable/baseline_remove_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:tint="@color/black" />

</androidx.constraintlayout.widget.ConstraintLayout>


</layout>
3 changes: 3 additions & 0 deletions feature/camera/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@

<string name="loadingAiModels">AI를 초기화하는 중입니다.</string>
<string name="getDetectedObjects">Processing...</string>
<string name="capturedImage">캡처된 이미지</string>
<string name="zoomOut">축소</string>
<string name="zoomIn">확대</string>

</resources>
9 changes: 9 additions & 0 deletions feature/camera/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="DialogFullscreen" parent="Theme.MediProject">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowIsFloating">false</item>
</style>
</resources>
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ksp = "1.8.21-1.0.11"

androidGradlePlugin = "8.0.1"
androidDesugarJdkLibs = "2.0.3"
photoview = "2.3.0"

# androidx
androidXPagingCompose = "1.0.0-alpha19"
Expand Down Expand Up @@ -218,6 +219,7 @@ okhttp-logginginterceptor = { module = "com.squareup.okhttp3:logging-interceptor
glide-main = { module = "com.github.bumptech.glide:glide", version.ref = "glide" }
glide-kapt = { module = "com.github.bumptech.glide:compiler", version.ref = "glide" }
glide-kapt-arch = { module = "android.arch.lifecycle:compiler", version.ref = "androidArchLifecycle" }
photo-view = { module = "com.github.chrisbanes:PhotoView", version.ref = "photoview" }

# lottie --------------------------------------------------------------------------------------------------------------
lottie = { module = "com.airbnb.android:lottie", version.ref = "lottie" }
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pluginManagement {
google()
mavenCentral()
gradlePluginPortal()
maven { url = uri("https://www.jitpack.io") }
}
}

Expand All @@ -12,6 +13,7 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://www.jitpack.io") }
}
}
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
Expand Down

0 comments on commit dad2251

Please sign in to comment.