Skip to content

Commit

Permalink
v0.1.1
Browse files Browse the repository at this point in the history
- μ˜€ν”ˆμ†ŒμŠ€ λΌμ΄μ„ μŠ€ μΆ”κ°€
- μƒν’ˆ μΆ”κ°€ ν™”λ©΄μ—μ„œ λͺ©ν‘œ 가격 섀정을 λ‹¨κ³„λ³„λ‘œ ν•  수 있게 μΆ”κ°€
- μƒν’ˆ μΆ”κ°€ ν™”λ©΄μ—μ„œ λͺ©ν‘œ 가격에 아무 값이 μ—†μœΌλ©΄ 창이 κΊΌμ§€λŠ” 문제 μˆ˜μ •
- μƒν’ˆ 인기 μˆœμœ„ μ„žμ΄λŠ” 버그 μˆ˜μ •

Co-Authored-By: EunhoKang <[email protected]>
Co-Authored-By: ootr47 <[email protected]>
Co-Authored-By: 손문기 <[email protected]>
Co-Authored-By: ByeongIk Choi <[email protected]>
  • Loading branch information
5 people committed Nov 24, 2023
1 parent 5a4cff4 commit 0e32b7c
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 55 deletions.
8 changes: 6 additions & 2 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.gms.google-services")
id("com.google.android.gms.oss-licenses-plugin")
id("com.google.firebase.crashlytics")
id("com.google.firebase.firebase-perf")
id("kotlin-kapt")
Expand All @@ -18,8 +19,8 @@ android {
applicationId = "app.priceguard"
minSdk = 29
targetSdk = 34
versionCode = 1
versionName = "0.1.0"
versionCode = 2
versionName = "0.1.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -94,6 +95,9 @@ dependencies {
implementation("androidx.navigation:navigation-fragment-ktx:$navVersion")
implementation("androidx.navigation:navigation-ui-ktx:$navVersion")

// OSS licences
implementation("com.google.android.gms:play-services-oss-licenses:17.0.1")

// Glide
implementation("com.github.bumptech.glide:glide:4.16.0")
}
Expand Down
6 changes: 6 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<activity
android:name=".ui.detail.DetailActivity"
android:exported="false" />
<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
android:theme="@style/Theme.PriceGuard.WithActionBar" />
<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
android:theme="@style/Theme.PriceGuard.WithActionBar" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import app.priceguard.R
import app.priceguard.data.dto.ProductVerifyDTO
import app.priceguard.databinding.FragmentConfirmItemLinkBinding
import java.text.NumberFormat
import kotlinx.serialization.json.Json

class ConfirmItemLinkFragment : Fragment() {

private var _binding: FragmentConfirmItemLinkBinding? = null
private val binding get() = _binding!!
private val viewModel: ConfirmItemLinkViewModel by viewModels()

private lateinit var productInfo: ProductVerifyDTO

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -28,12 +30,23 @@ class ConfirmItemLinkFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.lifecycleOwner = viewLifecycleOwner
binding.viewModel = viewModel

binding.initListener()
binding.initView()
}

private fun FragmentConfirmItemLinkBinding.initView() {
val productJson = requireArguments().getString("product") ?: return
val productInfo = Json.decodeFromString<ProductVerifyDTO>(productJson)
viewModel.setProductInfo(productInfo)
productInfo = Json.decodeFromString(productJson)

tvConfirmItemPrice.text =
String.format(
resources.getString(R.string.won),
NumberFormat.getNumberInstance().format(productInfo.productPrice)
)
tvConfirmItemBrand.text = productInfo.shop
tvConfirmItemItemTitle.text = productInfo.productName
imageUrl = productInfo.imageUrl
}

override fun onDestroyView() {
Expand All @@ -45,9 +58,9 @@ class ConfirmItemLinkFragment : Fragment() {
btnConfirmItemNext.setOnClickListener {
val action =
ConfirmItemLinkFragmentDirections.actionConfirmItemLinkFragmentToSetTargetPriceFragment(
viewModel?.flow?.value?.productCode ?: "",
viewModel?.flow?.value?.productName ?: "",
viewModel?.flow?.value?.productPrice ?: 0
productInfo.productCode ?: "",
productInfo.productName ?: "",
productInfo.productPrice ?: 0
)
findNavController().navigate(action)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import androidx.navigation.fragment.findNavController
import app.priceguard.R
import app.priceguard.databinding.FragmentSetTargetPriceBinding
import app.priceguard.ui.util.lifecycle.repeatOnStarted
import com.google.android.material.slider.Slider
import com.google.android.material.slider.Slider.OnSliderTouchListener
import dagger.hilt.android.AndroidEntryPoint
import java.text.NumberFormat

@AndroidEntryPoint
class SetTargetPriceFragment : Fragment() {
Expand Down Expand Up @@ -39,8 +42,14 @@ class SetTargetPriceFragment : Fragment() {
val title = requireArguments().getString("productTitle") ?: ""
val price = requireArguments().getInt("productPrice")

binding.tvSetPriceCurrentPrice.text =
String.format(
resources.getString(R.string.won),
NumberFormat.getNumberInstance().format(price)
)

viewModel.setProductInfo(productCode, title, price)
binding.etTargetPrice.setText(price.toString())
binding.etTargetPrice.setText((price * 0.8).toInt().toString())

binding.initListener()
handleEvent()
Expand All @@ -50,33 +59,50 @@ class SetTargetPriceFragment : Fragment() {
btnConfirmItemBack.setOnClickListener {
findNavController().navigateUp()
}
slTargetPrice.addOnChangeListener { slider, value, fromUser ->
slTargetPrice.addOnChangeListener { _, value, _ ->
if (!etTargetPrice.isFocused) {
tvTargetPricePercent.text =
String.format(getString(R.string.current_price_percent), value.toInt())
etTargetPrice.setText(((viewModel?.state?.value?.productPrice ?: 0) * value.toInt() / 100).toString())
setTargetPriceAndPercent(value)
}
}
slTargetPrice.addOnSliderTouchListener(object : OnSliderTouchListener {
override fun onStartTrackingTouch(slider: Slider) {
etTargetPrice.clearFocus()
setTargetPriceAndPercent(slider.value)
}

override fun onStopTrackingTouch(slider: Slider) {
}
})
etTargetPrice.addTextChangedListener {
if (etTargetPrice.isFocused) {
if (it.toString().matches("^\\d+\$".toRegex())) {
val targetPrice = it.toString().toFloat()
var percent = ((targetPrice / (viewModel?.state?.value?.productPrice ?: 0)) * 100).toInt()
var percent =
((targetPrice / (viewModel?.state?.value?.productPrice ?: 0)) * 100).toInt()
tvTargetPricePercent.text =
String.format(getString(R.string.current_price_percent), percent)

percent = 10 * ((percent + 5) / 10)
if (targetPrice > (viewModel?.state?.value?.productPrice ?: 0)) {
tvTargetPricePercent.text = getString(R.string.over_current_price)
percent = 100
} else if (percent < 1) {
percent = 1
percent = 0
}
slTargetPrice.value = percent.toFloat()
}
}
}
}

private fun FragmentSetTargetPriceBinding.setTargetPriceAndPercent(value: Float) {
tvTargetPricePercent.text =
String.format(getString(R.string.current_price_percent), value.toInt())
etTargetPrice.setText(
((viewModel?.state?.value?.productPrice ?: 0) * value.toInt() / 100).toString()
)
}

private fun handleEvent() {
repeatOnStarted {
viewModel.event.collect { event ->
Expand All @@ -86,7 +112,6 @@ class SetTargetPriceFragment : Fragment() {

SetTargetPriceViewModel.SetTargetPriceEvent.SuccessProductAdd -> {
activity?.finish()
// TODO: AddProductItem μ•‘ν‹°λΉ„ν‹° μ’…λ£Œ ν›„ μƒν’ˆ μ„ΈλΆ€ 정보 ν™”λ©΄μœΌλ‘œ μ΄λ™ν•˜κΈ°
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,17 @@ class SetTargetPriceViewModel @Inject constructor(private val productRepository:
}

fun updateTargetPrice(price: String) {
_state.value = state.value.copy(targetPrice = price.toInt())
if (price.toIntOrNull() != null) {
_state.value = state.value.copy(targetPrice = price.toInt())
}
}

fun setProductInfo(productCode: String, name: String, price: Int) {
_state.value = state.value.copy(productCode = productCode, productName = name, productPrice = price)
_state.value =
state.value.copy(
productCode = productCode,
productName = name,
productPrice = price
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import app.priceguard.databinding.FragmentMyPageBinding
import app.priceguard.ui.home.mypage.MyPageViewModel.MyPageEvent
import app.priceguard.ui.intro.IntroActivity
import app.priceguard.ui.util.lifecycle.repeatOnStarted
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
Expand Down Expand Up @@ -69,7 +70,7 @@ class MyPageFragment : Fragment() {
}

Setting.LICENSE -> {
// TODO: μ˜€ν”ˆμ†ŒμŠ€ λΌμ΄μ„ μŠ€
startActivity(Intent(activity, OssLicensesMenuActivity::class.java))
}

Setting.LOGOUT -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class MyPageViewModel @Inject constructor(
val firstName: String
)

private val _flow = MutableStateFlow(MyPageInfo("", "", ""))
val flow = _flow.asStateFlow()
private val _state = MutableStateFlow(MyPageInfo("", "", ""))
val state = _state.asStateFlow()

private val _event = MutableSharedFlow<MyPageEvent>()
val event = _event.asSharedFlow()
Expand All @@ -39,20 +39,19 @@ class MyPageViewModel @Inject constructor(
private fun setInfo() {
viewModelScope.launch {
val userData = tokenRepository.getUserData()
_flow.value =
MyPageInfo(userData.name, userData.email, if (userData.name.isNotEmpty()) userData.name.first().toString() else "")
_state.value =
MyPageInfo(
userData.name,
userData.email,
if (userData.name.isNotEmpty()) userData.name.first().toString() else ""
)
}
}

fun logout() {
viewModelScope.launch {
val resetTokenJob = launch {
tokenRepository.clearTokens()
}
resetTokenJob.join()
if (resetTokenJob.isCompleted) {
_event.emit(MyPageEvent.StartIntroAndExitHome)
}
tokenRepository.clearTokens()
_event.emit(MyPageEvent.StartIntroAndExitHome)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<data>

<variable
name="viewModel"
type="app.priceguard.ui.additem.confirm.ConfirmItemLinkViewModel" />
name="imageUrl"
type="String" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -64,7 +64,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:imageFromUrl="@{viewModel.flow.imageUrl}"/>
app:imageFromUrl="@{imageUrl}"/>

<TextView
android:id="@+id/tv_confirm_item_item_title"
Expand All @@ -73,7 +73,6 @@
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"
android:maxLines="3"
android:text="@{viewModel.flow.productName}"
android:textAppearance="?attr/textAppearanceBodyLarge"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -84,7 +83,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@{viewModel.flow.shop}"
android:textAppearance="?attr/textAppearanceBodyMedium"
app:layout_constraintStart_toStartOf="@id/tv_confirm_item_item_title"
app:layout_constraintTop_toBottomOf="@id/tv_confirm_item_item_title" />
Expand All @@ -102,7 +100,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@{viewModel.flow.productPrice.toString()}"
android:textAppearance="?attr/textAppearanceTitleMedium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/iv_confirm_item_shop_logo" />
Expand Down
6 changes: 3 additions & 3 deletions android/app/src/main/res/layout/fragment_my_page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
android:layout_margin="16dp"
android:background="@drawable/bg_circle"
android:gravity="center"
android:text="@{viewModel.flow.firstName}"
android:text="@{viewModel.state.firstName}"
android:textAppearance="?attr/textAppearanceTitleMedium"
android:textColor="?attr/colorSurface"
app:layout_constraintBottom_toBottomOf="parent"
Expand All @@ -86,7 +86,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="@{viewModel.flow.name}"
android:text="@{viewModel.state.name}"
android:textAppearance="?attr/textAppearanceBodyLarge"
app:layout_constraintBottom_toTopOf="@id/tv_my_page_email"
app:layout_constraintStart_toEndOf="@id/tv_my_page_profile"
Expand All @@ -96,7 +96,7 @@
android:id="@+id/tv_my_page_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{viewModel.flow.email}"
android:text="@{viewModel.state.email}"
android:textAppearance="?attr/textAppearanceBodyMedium"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@id/tv_my_page_name"
Expand Down
5 changes: 3 additions & 2 deletions android/app/src/main/res/layout/fragment_set_target_price.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
android:id="@+id/tv_set_price_current_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{String.valueOf(viewModel.state.productPrice)}"
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
app:layout_constraintEnd_toStartOf="@id/gl_vertical_end"
app:layout_constraintTop_toTopOf="@id/tv_set_price_name" />
Expand All @@ -73,6 +72,7 @@
android:paddingHorizontal="24dp"
android:textSize="22sp"
android:textStyle="bold"
android:imeOptions="actionDone"
android:onTextChanged="@{(content, s, b, c) -> viewModel.updateTargetPrice(content.toString())}"
app:layout_constraintEnd_toStartOf="@id/gl_vertical_end"
app:layout_constraintStart_toEndOf="@id/gl_vertical_start"
Expand All @@ -83,8 +83,9 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:focusable="true"
android:stepSize="10"
android:value="80"
android:valueFrom="1"
android:valueFrom="0"
android:valueTo="100"
app:layout_constraintEnd_toStartOf="@id/gl_vertical_end"
app:layout_constraintStart_toEndOf="@id/gl_vertical_start"
Expand Down
3 changes: 2 additions & 1 deletion android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<string name="name_required">이름은 ν•„μˆ˜ μž…λ ₯ μ‚¬ν•­μž…λ‹ˆλ‹€.</string>
<string name="invalid_email">μœ νš¨ν•˜μ§€ μ•Šμ€ μ΄λ©”μΌμž…λ‹ˆλ‹€.</string>
<string name="valid_email">μœ νš¨ν•œ μ΄λ©”μΌμž…λ‹ˆλ‹€.</string>
<string name="invalid_password">λΉ„λ°€λ²ˆν˜ΈλŠ” 8~16자 사이어야 ν•©λ‹ˆλ‹€.</string>
<string name="invalid_password">λΉ„λ°€λ²ˆν˜ΈλŠ” 영문 λŒ€μ†Œλ¬Έμžμ™€ νŠΉμˆ˜λ¬Έμžκ°€ ν¬ν•¨λœ 8~16자 사이어야 ν•©λ‹ˆλ‹€.</string>
<string name="valid_password">μ ν•©ν•œ λΉ„λ°€λ²ˆν˜Έμž…λ‹ˆλ‹€.</string>
<string name="password_mismatch">λΉ„λ°€λ²ˆν˜Έκ°€ μΌμΉ˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.</string>
<string name="password_match">λΉ„λ°€λ²ˆν˜Έκ°€ μΌμΉ˜ν•©λ‹ˆλ‹€.</string>
Expand Down Expand Up @@ -78,4 +78,5 @@
<string name="invalid_request">잘λͺ»λœ μš”μ²­μž…λ‹ˆλ‹€.</string>
<string name="delete_success">μ‚­μ œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.</string>
<string name="cancel">μ·¨μ†Œ</string>
<string name="won">%s원</string>
</resources>
Loading

0 comments on commit 0e32b7c

Please sign in to comment.