Skip to content

Commit

Permalink
Merge pull request #25 from nathan29849/feature/price_setting
Browse files Browse the repository at this point in the history
가격 범위 그래프 구현
  • Loading branch information
jminie-o8o committed May 27, 2022
2 parents d9e1df2 + 3da4237 commit 9aacefe
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 2 deletions.
5 changes: 4 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ android {
}

dependencies {
// Chart Library
implementation 'com.github.stfalcon-studio:StfalconPriceRangeBar-android:v1.5'

def lifecycle_version = "2.4.0"
// repeatOnLifecycle
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
Expand All @@ -60,7 +63,7 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.1'
//lifecycle runtime
implementation'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
//calendar
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.core:core-ktx:1.7.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.example.airbnb.ui

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.example.airbnb.R
import com.example.airbnb.databinding.FragmentPriceSettingBinding
import com.stfalcon.pricerangebar.model.BarEntry
import java.text.DecimalFormat


class PriceSettingFragment : Fragment() {

lateinit var binding: FragmentPriceSettingBinding
private val formatter = DecimalFormat("#,###")

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding =
DataBindingUtil.inflate(inflater, R.layout.fragment_price_setting, container, false)

initPriceRange()
initChart()
listenPinPointChange()

binding.btnResetPrice.setOnClickListener {
binding.priceRangeBar.setSelectedEntries(RANGE_MIN_INDEX, RANGE_MAX_INDEX)
}

return binding.root
}

private fun initPriceRange() {
binding.tvPriceRange.text =
"${PRICE_MIN_VALUE} - ₩${formatter.format(PRICE_MAX_VALUE * TEN_MAAN)}+"
}


private fun listenPinPointChange() {
binding.priceRangeBar.onRightPinChanged = { index, rightPinValue ->
val rangeTextMin = binding.tvPriceRange.text.split(" - ")[0]
val rangeTextMax = rightPinValue?.toFloat()?.toInt()?.let {
if (it >= 10) formatter.format(
PRICE_MAX_VALUE * TEN_MAAN
) + "+"
else (formatter.format(rightPinValue.toFloat().toInt().times(TEN_MAAN)))
}
binding.tvPriceRange.text = "$rangeTextMin - ₩$rangeTextMax"
}
}

private fun initChart() {

val priceHashMap = getPriceData()

val seekBarEntries = ArrayList<BarEntry>()
for (i in PRICE_MIN_VALUE..PRICE_MAX_VALUE) {
priceHashMap[i]?.let {

seekBarEntries.add(BarEntry(i.toFloat(), it.toFloat()))
seekBarEntries.add(BarEntry(i + SEEKBAR_VALUE_GAP, it.toFloat()))

seekBarEntries.add(BarEntry(i + SEEKBAR_VALUE_GAP, SEEKBAR_VACANT_VALUE))
seekBarEntries.add(
BarEntry(
i + SEEKBAR_VALUE_GAP + SEEKBAR_VACANT_GAP,
SEEKBAR_VACANT_VALUE
)
)
} ?: kotlin.run {
seekBarEntries.add(BarEntry(i.toFloat(), SEEKBAR_VACANT_VALUE))
seekBarEntries.add(BarEntry(i + SEEKBAR_VALUE_GAP, SEEKBAR_VACANT_VALUE))

seekBarEntries.add(BarEntry(i + SEEKBAR_VALUE_GAP, SEEKBAR_VACANT_VALUE))
seekBarEntries.add(
BarEntry(
i + SEEKBAR_VALUE_GAP + SEEKBAR_VACANT_GAP,
SEEKBAR_VACANT_VALUE
)
)
}
}
binding.priceRangeBar.setEntries(seekBarEntries)
}

// key : 2(20만원 이상 30만원 미만) , value(해당 범위내의 개수)
private fun getPriceData(): HashMap<Int, Int> {
val hashMap = HashMap<Int, Int>()

//TODO 추후 viewModel 을 통해 데이터 가져오기
val dataSet =
listOf<Int>(11, 20, 30, 55, 100, 400, 23, 43, 22, 71, 45, 44, 43, 65, 11, 13, 26, 24)
dataSet.forEach {
val key = if (it / 10 >= 10) 10 else it / 10
hashMap[key] = hashMap[key]?.plus(1) ?: 1
}
return hashMap
}

companion object {
const val PRICE_MAX_VALUE = 10
const val PRICE_MIN_VALUE = 0
const val PRICE_GAP = 10

const val SEEKBAR_VALUE_GAP = 0.8f
const val SEEKBAR_VACANT_GAP = 0.2f

const val SEEKBAR_VACANT_VALUE = 0.0f
const val TEN_MAAN = 100000

const val RANGE_MAX_INDEX = 42
const val RANGE_MIN_INDEX = 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class PlaceSearchFragment : Fragment() {
val startDate = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(it.first)
val endDate = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(it.second)
Log.d("test", "startDate: $startDate, endDate : $endDate")
findNavController().navigate(PlaceSearchFragmentDirections.actionPlaceSearchFragmentToPriceSettingFragment())
}

}

return binding.root
Expand All @@ -85,7 +87,11 @@ class PlaceSearchFragment : Fragment() {
val formatted = current.format(formatter)
val currentDate = formatted.split("-")

calendarStart.set(currentDate[0].toInt(), currentDate[1].toInt() - 1, currentDate[2].toInt() - 1)
calendarStart.set(
currentDate[0].toInt(),
currentDate[1].toInt() - 1,
currentDate[2].toInt() - 1
)
calendarEnd.set(2999, 12, 31)

val minDate = calendarStart.timeInMillis
Expand Down
54 changes: 54 additions & 0 deletions android/app/src/main/res/layout/fragment_price_setting.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.PriceSettingFragment">


<com.stfalcon.pricerangebar.RangeBarWithChart
android:id="@+id/price_range_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_price_range"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="@string/tempString"
android:textSize="40sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


<Button
android:layout_marginBottom="100dp"
android:id="@+id/btn_jump_setting_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/price_page_jump"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:layout_marginBottom="100dp"
android:id="@+id/btn_reset_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="@string/price_page_reset"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/btn_jump_setting_price" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
17 changes: 17 additions & 0 deletions android/app/src/main/res/navigation/navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,22 @@
<action
android:id="@+id/action_placeSearchFragment_to_searchFragment"
app:destination="@id/searchFragment" />
<action
android:id="@+id/action_placeSearchFragment_to_priceSettingFragment"
app:destination="@id/priceSettingFragment" />
</fragment>
<fragment
android:id="@+id/calendarFragment"
android:name="com.example.airbnb.ui.calendar.CalendarFragment"
android:label="fragment_calendar"
tools:layout="@layout/fragment_calendar" >
<action
android:id="@+id/action_calendarFragment_to_priceSettingFragment"
app:destination="@id/priceSettingFragment" />
</fragment>
<fragment
android:id="@+id/priceSettingFragment"
android:name="com.example.airbnb.ui.PriceSettingFragment"
android:label="fragment_price_setting"
tools:layout="@layout/fragment_price_setting" />
</navigation>
2 changes: 2 additions & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
<string name="mtrl_picker_range_header_only_end_selected" tools:override="true">시작일 - %s</string>
<string name="mtrl_picker_range_header_unselected" tools:override="true">시작일 - 종료일</string>
<string name="mtrl_picker_save" tools:override="true">저장</string>
<string name="price_page_jump">건너뛰기</string>
<string name="price_page_reset">지우기</string>
</resources>
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
rootProject.name = "airbnb"
Expand Down

0 comments on commit 9aacefe

Please sign in to comment.