Skip to content

Commit

Permalink
Merge pull request #37 from FakeDevelopers/feature/BDBD-166
Browse files Browse the repository at this point in the history
Feature/BDBD-166 글쓰기 화면 만들기
  • Loading branch information
minseonglove authored Jun 20, 2022
2 parents 87a264c + 9efa916 commit 773dd3c
Show file tree
Hide file tree
Showing 28 changed files with 757 additions and 120 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
id 'kotlin-kapt'
id 'kotlin-parcelize'
id 'dagger.hilt.android.plugin'
id 'androidx.navigation.safeargs.kotlin'
}
Expand Down Expand Up @@ -74,6 +75,8 @@ dependencies {
// Glide
implementation 'com.github.bumptech.glide:glide:4.13.0'
kapt 'com.github.bumptech.glide:compiler:4.13.0'
// time 라이브러리 백포트
implementation 'com.jakewharton.threetenabp:threetenabp:1.3.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import com.fakedevelopers.bidderbidder.databinding.ActivityMainBinding
import com.jakewharton.threetenabp.AndroidThreeTen
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -19,6 +20,7 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
_binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
AndroidThreeTen.init(this)
navController = (supportFragmentManager.findFragmentById(R.id.navigation_main) as NavHostFragment).navController
navController.addOnDestinationChangedListener { _, destination, _ ->
when (destination.id) {
Expand All @@ -37,7 +39,6 @@ class MainActivity : AppCompatActivity() {
}
true
}
// navController.navigate(R.id.productRegistrationFragment)
}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import retrofit2.http.PartMap

interface ProductRegistrationService {
@Multipart
@POST("board/write")
@POST("product/write")
suspend fun postProductRegistration(
@Part files: List<MultipartBody.Part>,
@PartMap params: HashMap<String, RequestBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.fakedevelopers.bidderbidder.R
import com.fakedevelopers.bidderbidder.api.data.Constants.Companion.BASE_URL
import com.fakedevelopers.bidderbidder.api.data.Constants.Companion.dec
import com.fakedevelopers.bidderbidder.databinding.RecyclerProductListBinding
import com.fakedevelopers.bidderbidder.databinding.RecyclerProductListFooterBinding
import com.fakedevelopers.bidderbidder.ui.product_list.ProductListViewModel.Companion.LIST_COUNT
import java.text.DecimalFormat
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import java.util.TimeZone

class ProductListAdapter(
private val onClick: () -> Unit,
Expand All @@ -26,7 +26,9 @@ class ProductListAdapter(
) : ListAdapter<ProductListDto, RecyclerView.ViewHolder>(diffUtil) {

private var listSize = 0
private val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault())
private val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm").apply {
timeZone = TimeZone.getTimeZone("Asia/Seoul")
}

inner class ItemViewHolder(
private val binding: RecyclerProductListBinding,
Expand All @@ -38,8 +40,7 @@ class ProductListAdapter(
if (::timerTask.isInitialized) {
timerTask.cancel()
}
val timer = dateFormat.parse(item.expirationDate)!!.time - Date(System.currentTimeMillis()).time
timerTask = object : CountDownTimer(timer, 1000) {
timerTask = object : CountDownTimer(getRemainTimeMillisecond(item.expirationDate), 1000) {
override fun onTick(millisUntilFinished: Long) {
textviewProductListExpire.text = getRemainTimeString(millisUntilFinished)
}
Expand All @@ -66,6 +67,10 @@ class ProductListAdapter(
textviewProductListParticipant.text = if (item.bidderCount != 0) "${item.bidderCount}명 입찰" else ""
}
}

private fun getRemainTimeMillisecond(expirationDate: String) =
dateFormat.parse(expirationDate)!!.time - dateFormat.parse(dateFormat.format(Date()))!!.time

private fun getRemainTimeString(millisUntilFinished: Long): String {
val totalMinute = millisUntilFinished / 60000
val day = totalMinute / 1440
Expand All @@ -81,7 +86,7 @@ class ProductListAdapter(
}
// 분, 초
if (day == 0L && hour < 3) {
val minute = totalMinute % 1440 % 60
val minute = totalMinute % 60
if (minute != 0L) {
remainTimeString.append("${minute}")
}
Expand Down Expand Up @@ -149,8 +154,6 @@ class ProductListAdapter(
const val TYPE_ITEM = 1
const val TYPE_FOOTER = 2

val dec = DecimalFormat("#,###")

val diffUtil = object : DiffUtil.ItemCallback<ProductListDto>() {
override fun areItemsTheSame(oldItem: ProductListDto, newItem: ProductListDto) =
oldItem.productId == newItem.productId
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.fakedevelopers.bidderbidder.ui.product_registration

import android.text.Editable
import android.text.Selection
import android.text.TextUtils
import android.text.TextWatcher
import android.widget.EditText
import com.fakedevelopers.bidderbidder.api.data.Constants.Companion.dec

class PriceTextWatcher(
private val editText: EditText,
private val checkCondition: () -> Unit
) : TextWatcher {

private var strAmount = ""

override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
// 안해!
}

override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if (!TextUtils.isEmpty(s.toString()) && s.toString() != strAmount) {
strAmount = makeComma(s.toString())
editText.setText(strAmount)
Selection.setSelection(editText.text, strAmount.length)
}
}

override fun afterTextChanged(s: Editable?) {
checkCondition()
}

private fun makeComma(price: String): String {
price.replace(",", "").toLongOrNull()?.let {
return dec.format(it)
}
return ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.fakedevelopers.bidderbidder.ui.product_registration

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class ProductRegistrationDto(
var urlList: List<String>,
val title: String,
val hopePrice: String,
val openingBid: String,
val tick: String,
val expiration: String,
val content: String
) : Parcelable
Loading

0 comments on commit 773dd3c

Please sign in to comment.