Skip to content

Commit

Permalink
Merge pull request #136 from pknu-wap/#91/feature/jsp/app_enhancement2
Browse files Browse the repository at this point in the history
#91/feature/jsp/app enhancement2
  • Loading branch information
pknujsp authored Jun 7, 2023
2 parents 6f02ab1 + 9d778a1 commit 45206c3
Show file tree
Hide file tree
Showing 114 changed files with 1,669 additions and 839 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
implementation(project(":core:ui"))
implementation(project(":core:model"))
implementation(project(":core:database"))
implementation(project(":core:domain"))


implementation(project(":feature:interestedmedicine"))
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@style/Theme.App.Starting">
android:theme="@style/Theme.App.Starting"
android:windowSoftInputMode="adjustResize|adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
48 changes: 28 additions & 20 deletions app/src/main/java/com/android/mediproject/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ package com.android.mediproject
import android.animation.ObjectAnimator
import android.os.Build
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import android.view.ViewTreeObserver
import android.view.animation.AnticipateInterpolator
import androidx.activity.viewModels
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.animation.doOnEnd
import androidx.core.net.toUri
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.isVisible
import androidx.core.view.marginBottom
import androidx.core.view.updateLayoutParams
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.android.mediproject.core.common.uiutil.LayoutController
import com.android.mediproject.core.common.uiutil.SystemBarStyler
import com.android.mediproject.core.ui.WindowViewModel
import com.android.mediproject.core.ui.base.BaseActivity
Expand All @@ -25,7 +26,7 @@ import repeatOnStarted
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(ActivityMainBinding::inflate) {
class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(ActivityMainBinding::inflate), LayoutController {

private val windowViewModel: WindowViewModel by viewModels()

Expand All @@ -40,7 +41,7 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(ActivityMa
private lateinit var navController: NavController

override fun afterBinding() {
systemBarStyler.init(this, window)
systemBarStyler.init(this, window, this::changeFragmentContainerHeight)
systemBarStyler.setStyle(SystemBarStyler.StatusBarColor.WHITE, SystemBarStyler.NavigationBarColor.BLACK)

//SDK 31이상일 때 Splash가 소소하게 사라지는 이펙트 입니다. 추후 걸리적거리면 삭제해도 됌
Expand Down Expand Up @@ -83,30 +84,20 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(ActivityMa
if (bottomAppBar.height > 0 && bottomNav.marginBottom == systemBarStyler.navigationBarHeightPx) {
root.viewTreeObserver.removeOnPreDrawListener(this)
windowViewModel.bottomNavHeightInPx = bottomAppBar.height
setFragmentContainerFullHeight(false)
this@MainActivity.changeFragmentContainerHeight(false)
}
return true
}
})
}
}

/**
* fragmentContainerView의 높이를 조정해주는 함수
*
* CoordinatorLayout으로 인해 fragmentContainerView의 높이가 앱 전체의 높이로 되어있는데
* isFull true를 전달받으면 fragmentContainerView의 bottom좌표가 bottomNav의 top좌표가 되고,
* isFull false를 전달받으면 fragmentContainerView의 bottom좌표가 앱 전체의 bottom좌표가 된다.
*
* @param isFull true: 전체화면, false: 전체화면X
*/
private fun setFragmentContainerFullHeight(isFull: Boolean) {
if (windowViewModel.bottomNavHeight.value > 0) {
binding.fragmentContainerView.layoutParams = CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
if (isFull) ViewGroup.LayoutParams.MATCH_PARENT else (binding.root.height - windowViewModel.bottomNavHeight.value))
}
override fun onRestart() {
super.onRestart()

}


override fun setSplash() {
installSplashScreen()
}
Expand Down Expand Up @@ -144,11 +135,28 @@ class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>(ActivityMa
log(visible.toString())
binding.cameraFAB.isVisible = visible
binding.bottomAppBar.isVisible = visible
setFragmentContainerFullHeight(!visible)
this.changeFragmentContainerHeight(!visible)
}

fun handleEvent(event: MainViewModel.MainEvent) = when (event) {
is MainViewModel.MainEvent.AICamera -> navController.navigate("medilens://main/camera_nav".toUri())
}

/**
* fragmentContainerView의 높이를 조정해주는 함수
*
* CoordinatorLayout으로 인해 fragmentContainerView의 높이가 앱 전체의 높이로 되어있는데
* isFull true를 전달받으면 fragmentContainerView의 bottom좌표가 bottomNav의 top좌표가 되고,
* isFull false를 전달받으면 fragmentContainerView의 bottom좌표가 앱 전체의 bottom좌표가 된다.
*
* @param isFull true: 전체화면, false: 전체화면X
*/
override fun changeFragmentContainerHeight(isFull: Boolean) {
if (windowViewModel.bottomNavHeight.value > 0) {
binding.fragmentContainerView.updateLayoutParams<MarginLayoutParams> {
bottomMargin = if (!isFull) (windowViewModel.bottomNavHeight.value) else 0
}
}
}

}
20 changes: 16 additions & 4 deletions app/src/main/java/com/android/mediproject/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@ package com.android.mediproject
import MutableEventFlow
import androidx.lifecycle.viewModelScope
import asEventFlow
import com.android.mediproject.core.domain.sign.GetAccountStateUseCase
import com.android.mediproject.core.ui.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

class MainViewModel : BaseViewModel() {
@HiltViewModel
class MainViewModel @Inject constructor(
private val getAccountStateUseCase: GetAccountStateUseCase,
) : BaseViewModel() {
private val _eventFlow = MutableEventFlow<MainEvent>()
val eventFlow = _eventFlow.asEventFlow()

fun event(event : MainEvent) = viewModelScope.launch{ _eventFlow.emit(event)}
fun event(event: MainEvent) = viewModelScope.launch { _eventFlow.emit(event) }
fun aicamera() = event(MainEvent.AICamera())

sealed class MainEvent{
data class AICamera(val unit : Unit? = null) : MainEvent()
init {
viewModelScope.launch {
getAccountStateUseCase.loadAccountState()
}
}

sealed class MainEvent {
data class AICamera(val unit: Unit? = null) : MainEvent()
}
}
3 changes: 2 additions & 1 deletion core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ android {
buildConfigField("String", "DATA_GO_KR_SERVICE_KEY", "\"${properties["dataGoKrServiceKey"]}\"")
buildConfigField("String", "DATA_GO_KR_BASE_URL", "\"${properties["dataGoKrBaseUrl"]}\"")
buildConfigField("String", "AWS_BASE_URL", "\"${properties["awsUrl"]}\"")
buildConfigField("String", "VERTEX_ENDPOINT_URL", "\"${properties["vertexEndpointUrl"]}\"")
}
}

hilt {
enableAggregatingTask = true
}
}

dependencies {
implementation(libs.kotlinx.coroutines.android)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import androidx.core.text.PrecomputedTextCompat
import androidx.core.view.isVisible
import androidx.core.widget.TextViewCompat
import androidx.databinding.BindingAdapter
import com.android.mediproject.core.common.R
Expand Down Expand Up @@ -66,5 +67,19 @@ object BindingAdapter {
}
}

/**
* ImageView에 이미지를 설정합니다.
* 이미지가 없을 경우 TextView에 메시지를 표시합니다.
* @param imageView 이미지를 설정할 ImageView
* @param img 이미지의 URL
* @param textView 이미지가 없을 경우 표시할 TextView
*/
@BindingAdapter("img", "messageView", "message")
@JvmStatic
fun setImage(imageView: ImageView, img: String, textView: TextView, message: String) {
textView.text = message
textView.isVisible = img.isEmpty()

if (img.isNotEmpty()) GlideApp.with(imageView.context).load(img).centerInside().skipMemoryCache(false).into(imageView)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlin.properties.Delegates
@SuppressLint("InternalInsetResource", "DiscouragedApi")
@Singleton
class SystemBarStyler @Inject constructor(
) {
) : LayoutController {
enum class StatusBarColor {
BLACK, WHITE
}
Expand All @@ -31,6 +31,8 @@ class SystemBarStyler @Inject constructor(
MARGIN, PADDING
}

private var acitivityLayoutController: LayoutController? = null

private lateinit var window: Window

data class ChangeView(val view: View, val type: SpacingType)
Expand All @@ -44,8 +46,9 @@ class SystemBarStyler @Inject constructor(
val navigationBarHeightPx: Int
get() = navigationBarHeight

fun init(context: Context, window: Window) {
fun init(context: Context, window: Window, activityLayoutController: LayoutController) {
this.window = window
this.acitivityLayoutController = activityLayoutController
context.resources.apply {
statusBarHeight = getDimensionPixelSize(getIdentifier("status_bar_height", "dimen", "android"))
navigationBarHeight = getDimensionPixelSize(getIdentifier("navigation_bar_height", "dimen", "android"))
Expand Down Expand Up @@ -112,4 +115,13 @@ class SystemBarStyler @Inject constructor(
}
}
}

override fun changeFragmentContainerHeight(isFull: Boolean) {
acitivityLayoutController?.changeFragmentContainerHeight(isFull)
}
}


fun interface LayoutController {
fun changeFragmentContainerHeight(isFull: Boolean)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ class AesCoder @Inject constructor(@ApplicationContext context: Context) {
private val cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")

init {
val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) context.packageManager.getPackageInfo(
context.packageName,
PackageManager.PackageInfoFlags.of(0)
)
else context.packageManager.getPackageInfo(context.packageName, 0)
val packageInfo =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) context.packageManager.getPackageInfo(context.packageName,
PackageManager.PackageInfoFlags.of(0))
else context.packageManager.getPackageInfo(context.packageName, 0)

var key: String? = "${packageInfo.firstInstallTime}".repeat(4).substring(0, 32)
key?.apply {
Expand All @@ -34,6 +33,38 @@ class AesCoder @Inject constructor(@ApplicationContext context: Context) {
key = null
}

private fun createSecretKey(plainArray: CharArray): Pair<SecretKeySpec, IvParameterSpec> {
val keyLength = plainArray.size
val extraLength = 32 - keyLength

val key = ByteArray(32).apply {
plainArray.mapIndexed { index, c ->
this[index] = c.code.toByte()
}
if (extraLength > 0) {
val extra = "5".toByte()
IntRange(0, extraLength - 1).forEachIndexed { index, i ->
this[keyLength + index] = extra
}
}
}
key.fill(0)
return (SecretKeySpec(key, "AES") to IvParameterSpec(key.copyOfRange(0, 16)))
}

/**
* 비밀번호 암호화
*/
@OptIn(ExperimentalEncodingApi::class)
fun encodePassword(email: CharArray, password: CharArray): String {
val (pwSecretKey, pwIvParameterSpec) = createSecretKey(email)
cipher.init(Cipher.ENCRYPT_MODE, pwSecretKey, pwIvParameterSpec)
val encrpytionByte = cipher.doFinal(ByteArray(password.size) { password[it].code.toByte() })
val result = Base64.encode(encrpytionByte, 0, encrpytionByte.size)
encrpytionByte.fill(0)
return result
}

/**
* 암호화
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.navigation.NavArgument
import androidx.navigation.NavController
import androidx.navigation.NavDeepLink
import androidx.navigation.NavDeepLinkRequest
import androidx.navigation.NavDestination
import androidx.navigation.NavOptions
import androidx.navigation.NavType
import com.android.mediproject.core.model.local.navargs.BaseNavArgs
Expand Down Expand Up @@ -118,6 +119,23 @@ fun NavController.deepNavigate(
navigate(finalUri, navOptions)
}

inline fun <reified N : BaseNavArgs> NavDestination.setArguments(navArgs: N) {
navArgs.toMap().forEach { (key, value) ->
if (value == null) return@forEach
val navType: NavType<out Any?> = when (value) {
is String -> NavType.StringType
is Int -> NavType.IntType
is Long -> NavType.LongType
is Float -> NavType.FloatType
is Boolean -> NavType.BoolType
else -> NavType.ReferenceType
}

addArgument(key, NavArgument.Builder().setType(navType).setIsNullable(false).setDefaultValue(value).build())
}
}


@MainThread
inline fun <reified Args : BaseNavArgs> Fragment.navArgs(): NavArgsLazy<out Args> = NavArgsLazy(Args::class) {
val bundle = arguments ?: Bundle()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.android.mediproject.core.data.remote.ai

import com.android.mediproject.core.model.ai.VertexAiPredictResponse
import com.android.mediproject.core.model.requestparameters.VertexAiPredictParameter
import kotlinx.coroutines.flow.Flow

interface VertexAiRepository {
fun predict(parameter: VertexAiPredictParameter): Flow<Result<VertexAiPredictResponse>>
}
Loading

0 comments on commit 45206c3

Please sign in to comment.