-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from kimhyebeen/master
통계 화면 구현 Pull Request
- Loading branch information
Showing
35 changed files
with
957 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
Picon/app/src/main/java/com/yapp/picon/presentation/model/ListItemForPlaceGraph.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.yapp.picon.presentation.model | ||
|
||
data class ListItemForPlaceGraph ( | ||
var color: String, | ||
var count: Int | ||
) |
7 changes: 7 additions & 0 deletions
7
Picon/app/src/main/java/com/yapp/picon/presentation/model/StatisticDate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.yapp.picon.presentation.model | ||
|
||
data class StatisticDate ( | ||
var selected: Boolean, | ||
var year: Int, | ||
var month: Int | ||
) |
6 changes: 6 additions & 0 deletions
6
Picon/app/src/main/java/com/yapp/picon/presentation/model/StatisticEmotionGraphItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.yapp.picon.presentation.model | ||
|
||
data class StatisticEmotionGraphItem ( | ||
var color: String, | ||
var count: Int | ||
) |
7 changes: 7 additions & 0 deletions
7
Picon/app/src/main/java/com/yapp/picon/presentation/model/StatisticPlaceGraphItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.yapp.picon.presentation.model | ||
|
||
data class StatisticPlaceGraphItem ( | ||
var place: String, | ||
var graphItems: List<ListItemForPlaceGraph>, | ||
var total: Int | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
Picon/app/src/main/java/com/yapp/picon/presentation/nav/StatisticContentViewFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.yapp.picon.presentation.nav | ||
|
||
import android.annotation.SuppressLint | ||
import androidx.fragment.app.activityViewModels | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.yapp.picon.BR | ||
import com.yapp.picon.R | ||
import com.yapp.picon.databinding.NavStatisticContentViewBinding | ||
import com.yapp.picon.presentation.base.BaseFragment | ||
import com.yapp.picon.presentation.nav.adapter.EmotionGraphAdapter | ||
import com.yapp.picon.presentation.nav.adapter.PlaceGraphAdapter | ||
|
||
class StatisticContentViewFragment: BaseFragment<NavStatisticContentViewBinding, NavViewModel>( | ||
R.layout.nav_statistic_content_view | ||
) { | ||
private lateinit var placeAdapter: PlaceGraphAdapter | ||
private lateinit var emotionAdapter: EmotionGraphAdapter | ||
private lateinit var colorList: List<String> | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override val vm: NavViewModel by activityViewModels { | ||
object : ViewModelProvider.Factory { | ||
override fun <T : ViewModel?> create(modelClass: Class<T>): T = | ||
NavViewModel() as T | ||
} | ||
} | ||
|
||
override fun initBinding() { | ||
} | ||
|
||
@SuppressLint("ResourceType") | ||
override fun onStart() { | ||
super.onStart() | ||
colorList = listOf( | ||
getString(R.color.soft_blue), | ||
getString(R.color.cornflower), | ||
getString(R.color.bluegrey), | ||
getString(R.color.very_light_brown), | ||
getString(R.color.warm_grey) | ||
) | ||
|
||
setEmotionAdapter() | ||
setPlaceAdapter() | ||
observeGraphData() | ||
} | ||
|
||
private fun setEmotionAdapter() { | ||
emotionAdapter = EmotionGraphAdapter( | ||
colorList, | ||
R.layout.emotion_graph_item, | ||
BR.emotionItem | ||
) | ||
binding.navStatisticEmotionGraphRv.apply { | ||
adapter = emotionAdapter | ||
layoutManager = LinearLayoutManager(context) | ||
setHasFixedSize(true) | ||
} | ||
} | ||
|
||
private fun setPlaceAdapter() { | ||
placeAdapter = PlaceGraphAdapter( | ||
colorList, | ||
R.layout.place_graph_item, | ||
BR.placeItem | ||
) | ||
binding.navStatisticPlaceGraphRv.apply { | ||
adapter = placeAdapter | ||
layoutManager = LinearLayoutManager(context) | ||
setHasFixedSize(true) | ||
} | ||
} | ||
|
||
@SuppressLint("SetTextI18n") | ||
private fun observeGraphData() { | ||
vm.statisticRepository.placeList.observe(this, { | ||
placeAdapter.setItems(it) | ||
}) | ||
vm.statisticRepository.emotionList.observe(this, { | ||
emotionAdapter.setItems(it) | ||
var max = 0 | ||
it.map { item -> | ||
if (max < item.count) max = item.count | ||
} | ||
emotionAdapter.setMaxCount(max) | ||
|
||
var sum = 0 | ||
it.map { item -> | ||
sum += item.count | ||
} | ||
binding.navStatisticPinNumberTv.text = "$sum 핀" | ||
}) | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
Picon/app/src/main/java/com/yapp/picon/presentation/nav/StatisticFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.yapp.picon.presentation.nav | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.View | ||
import android.view.animation.Animation | ||
import android.view.animation.AnimationUtils | ||
import androidx.core.view.isVisible | ||
import androidx.fragment.app.FragmentTransaction | ||
import androidx.fragment.app.activityViewModels | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.yapp.picon.BR | ||
import com.yapp.picon.R | ||
import com.yapp.picon.databinding.NavStatisticFragmentBinding | ||
import com.yapp.picon.presentation.base.BaseFragment | ||
import com.yapp.picon.presentation.nav.adapter.MonthListAdapter | ||
|
||
class StatisticFragment: BaseFragment<NavStatisticFragmentBinding, NavViewModel>( | ||
R.layout.nav_statistic_fragment | ||
) { | ||
private lateinit var transaction: FragmentTransaction | ||
private lateinit var transrateUp: Animation | ||
private lateinit var transrateDown: Animation | ||
private lateinit var monthAdapter: MonthListAdapter | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override val vm: NavViewModel by activityViewModels { | ||
object : ViewModelProvider.Factory { | ||
override fun <T : ViewModel?> create(modelClass: Class<T>): T = | ||
NavViewModel() as T | ||
} | ||
} | ||
|
||
override fun initBinding() { | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
// childFragmentManager를 사용해서 nav_statistic_content_view 붙이기 | ||
transaction = childFragmentManager.beginTransaction() | ||
transaction.replace(R.id.nav_statistic_frame, StatisticContentViewFragment()).addToBackStack(null).commit() | ||
|
||
setTransrateUpDownAnimation() | ||
|
||
setMonthAdapter() | ||
binding.navStatisticMonthRecycler.apply { | ||
adapter = monthAdapter | ||
layoutManager = LinearLayoutManager(context) | ||
setHasFixedSize(true) | ||
} | ||
|
||
setAnimationToMonthList() | ||
observeVM() | ||
} | ||
|
||
private fun setTransrateUpDownAnimation() { | ||
transrateUp = AnimationUtils.loadAnimation(context, R.anim.translate_up) | ||
transrateDown = AnimationUtils.loadAnimation(context, R.anim.translate_down) | ||
|
||
transrateUp.setAnimationListener(object : Animation.AnimationListener { | ||
override fun onAnimationStart(animation: Animation?) { } | ||
override fun onAnimationEnd(animation: Animation?) { | ||
binding.navStatisticMonthRecycler.visibility = View.INVISIBLE | ||
} | ||
override fun onAnimationRepeat(animation: Animation?) { } | ||
}) | ||
} | ||
|
||
@SuppressLint("ResourceType") | ||
private fun setMonthAdapter() { | ||
monthAdapter = MonthListAdapter( | ||
listOf(getString(R.color.cornflower), getString(R.color.very_light_pink_two)), | ||
{ str -> vm.statisticRepository.setTitle(str) }, | ||
{ pre, cur -> | ||
vm.statisticRepository.changeSelected(pre) | ||
vm.statisticRepository.changeSelected(cur) | ||
}, | ||
{ monthListClickEvent() }, | ||
R.layout.month_list_item, | ||
BR.monthItem | ||
) | ||
} | ||
|
||
private fun setAnimationToMonthList() { | ||
binding.navStatisticAppBar.navStatisticTitleLinearLayout.setOnClickListener { | ||
monthListClickEvent() | ||
} | ||
} | ||
|
||
private fun monthListClickEvent() { | ||
binding.navStatisticMonthRecycler.let { monthList -> | ||
if (monthList.isVisible) monthList.startAnimation(transrateUp) | ||
else { | ||
monthList.apply { | ||
visibility = View.VISIBLE | ||
startAnimation(transrateDown) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun observeVM() { | ||
vm.statisticRepository.monthList.observe(this, { | ||
monthAdapter.setItems(it) | ||
// todo - 감정별, 지역별 그래프 데이터도 바꿔주기 | ||
}) | ||
vm.statisticRepository.title.observe(this, { | ||
binding.navStatisticAppBar.navStatisticTitleTv.text = it | ||
}) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../presentation/nav/CustomEmotionAdapter.kt → ...ation/nav/adapter/CustomEmotionAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Picon/app/src/main/java/com/yapp/picon/presentation/nav/adapter/EmotionGraphAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.yapp.picon.presentation.nav.adapter | ||
|
||
import androidx.annotation.LayoutRes | ||
import com.broooapps.lineargraphview2.DataModel | ||
import com.yapp.picon.R | ||
import com.yapp.picon.databinding.EmotionGraphItemBinding | ||
import com.yapp.picon.databinding.PlaceGraphItemBinding | ||
import com.yapp.picon.presentation.base.BaseRecyclerView | ||
import com.yapp.picon.presentation.model.StatisticEmotionGraphItem | ||
import com.yapp.picon.presentation.model.StatisticPlaceGraphItem | ||
import kotlinx.android.synthetic.main.emotion_graph_item.view.* | ||
import kotlinx.android.synthetic.main.place_graph_item.view.* | ||
|
||
class EmotionGraphAdapter( | ||
private val colorList: List<String>, | ||
@LayoutRes private val layoutRes: Int, | ||
bindingVariabledId: Int | ||
) : BaseRecyclerView.BaseAdapter<StatisticEmotionGraphItem, EmotionGraphItemBinding>( | ||
layoutRes, | ||
bindingVariabledId | ||
) { | ||
private var maxCount = 0 | ||
|
||
fun setMaxCount(value: Int) { | ||
maxCount = value | ||
} | ||
|
||
override fun onBindViewHolder( | ||
baseViewHolder: BaseRecyclerView.BaseViewHolder<EmotionGraphItemBinding>, | ||
position: Int | ||
) { | ||
super.onBindViewHolder(baseViewHolder, position) | ||
|
||
baseViewHolder.itemView.emotion_graph_view | ||
.setData( | ||
listOf( | ||
DataModel( | ||
items[position].color, | ||
colorList[position], | ||
items[position].count | ||
) | ||
), | ||
maxCount.toFloat() | ||
) | ||
} | ||
} |
Oops, something went wrong.