Skip to content

Commit

Permalink
Merge pull request #38 from 3dollar-in-my-pocket/feat/2.4.6
Browse files Browse the repository at this point in the history
2.4.6
  • Loading branch information
zion830 authored Mar 4, 2022
2 parents c8a6cfe + a21d469 commit 20f6d5e
Show file tree
Hide file tree
Showing 23 changed files with 636 additions and 142 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.zion830.threedollars.repository.model.v2.response

import com.zion830.threedollars.R

data class HomeStoreEmptyResponse(
val emptyImage: Int = R.drawable.ic_no_store,
val emptyTitle: Int = R.string.empty_store,
val emptyBody: Int = R.string.empty_store_msg
) : AdAndStoreItem
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.zion830.threedollars.repository.model.v2.response

import com.google.gson.annotations.SerializedName

interface AdAndStoreItem

data class PopupsResponse(
@SerializedName("data")
Expand All @@ -14,9 +15,9 @@ data class PopupsResponse(

data class Popups(
@SerializedName("bgColor")
val bgColor: String = "",
val bgColor: String? = "",
@SerializedName("fontColor")
val fontColor: String = "",
val fontColor: String? = "",
@SerializedName("imageUrl")
val imageUrl: String = "",
@SerializedName("linkUrl")
Expand All @@ -25,4 +26,4 @@ data class Popups(
val subTitle: String = "",
@SerializedName("title")
val title: String = ""
)
) : AdAndStoreItem
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.zion830.threedollars.repository.model.v2.response.store

import com.google.gson.annotations.SerializedName
import com.zion830.threedollars.repository.model.v2.response.AdAndStoreItem

interface StoreByMenuItem

data class StoreInfo(
@SerializedName("categories")
Expand All @@ -25,4 +28,4 @@ data class StoreInfo(
val visitHistory: VisitHistory = VisitHistory(),
@SerializedName("isDeleted")
val isDeleted: Boolean = false
)
) : AdAndStoreItem
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class NearStoreNaverMapFragment(private val cameraMoved: () -> Unit = {}) : Nave
}

override fun onMyLocationLoaded(position: LatLng) {
viewModel.requestStoreInfo(position)
viewModel.requestHomeItem(position)
viewModel.updateCurrentLocation(position)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import android.net.Uri
import androidx.core.graphics.toColorInt
import androidx.core.text.bold
import androidx.core.text.buildSpannedString
import androidx.core.view.isVisible
Expand All @@ -19,6 +20,7 @@ import com.zion830.threedollars.repository.model.v2.response.store.CategoryInfo
import com.zion830.threedollars.ui.category.adapter.SelectCategoryRecyclerAdapter
import com.zion830.threedollars.ui.popup.PopupViewModel
import zion830.com.common.base.BaseFragment
import zion830.com.common.base.loadUrlImg
import zion830.com.common.listener.OnItemClickListener

class SelectCategoryFragment :
Expand Down Expand Up @@ -65,17 +67,16 @@ class SelectCategoryFragment :
if (popups.isNotEmpty()) {
val popup = popups[0]
binding.tvAdTitle.text = popup.title
binding.tvAdTitle.setTextColor(Color.parseColor(popup.fontColor))

binding.tvAdBody.text = popup.subTitle
binding.tvAdBody.setTextColor(Color.parseColor(popup.fontColor))

binding.cdAdCategory.setCardBackgroundColor(Color.parseColor(popup.bgColor))
popup.fontColor?.let {
binding.tvAdTitle.setTextColor(it.toColorInt())
binding.tvAdBody.setTextColor(it.toColorInt())
}
popup.bgColor?.let { binding.cdAdCategory.setCardBackgroundColor(it.toColorInt()) }

Glide.with(requireContext())
.load(popup.imageUrl)
.transition(DrawableTransitionOptions.withCrossFade())
.into(binding.ivAdImage)
binding.ivAdImage.loadUrlImg(popup.imageUrl)

binding.cdAdCategory.setOnClickListener {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(popup.linkUrl)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@ package com.zion830.threedollars.ui.category

import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.activity.viewModels
import androidx.core.graphics.toColorInt
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.google.android.gms.ads.AdRequest
import com.zion830.threedollars.R
import com.zion830.threedollars.databinding.ActivityStoreByMenuBinding
import com.zion830.threedollars.repository.model.v2.response.Popups
import com.zion830.threedollars.repository.model.v2.response.store.CategoryInfo
import com.zion830.threedollars.repository.model.v2.response.store.StoreInfo
import com.zion830.threedollars.ui.category.adapter.SearchByDistanceRecyclerAdapter
import com.zion830.threedollars.ui.category.adapter.SearchByRatingRecyclerAdapter
import com.zion830.threedollars.ui.popup.PopupViewModel
import com.zion830.threedollars.ui.store_detail.StoreDetailActivity
import com.zion830.threedollars.ui.store_detail.map.StoreByMenuNaverMapFragment
import com.zion830.threedollars.ui.store_detail.vm.StoreByMenuViewModel
import com.zion830.threedollars.utils.*
import zion830.com.common.base.BaseActivity
import zion830.com.common.base.loadUrlImg
import zion830.com.common.listener.OnItemClickListener

class StoreByMenuActivity :
BaseActivity<ActivityStoreByMenuBinding, StoreByMenuViewModel>(R.layout.activity_store_by_menu), OnMapTouchListener {
BaseActivity<ActivityStoreByMenuBinding, StoreByMenuViewModel>(R.layout.activity_store_by_menu),
OnMapTouchListener {

override val viewModel: StoreByMenuViewModel by viewModels()

private val popupViewModel: PopupViewModel by viewModels()

private lateinit var menuType: CategoryInfo

private val listener = object : OnItemClickListener<StoreInfo> {
Expand All @@ -30,12 +40,17 @@ class StoreByMenuActivity :
startActivity(intent)
}
}
private val adListener = object : OnItemClickListener<Popups> {
override fun onClick(item: Popups) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(item.linkUrl)))
}
}
private val storeByDistanceAdapters by lazy {
SearchByDistanceRecyclerAdapter(listener)
SearchByDistanceRecyclerAdapter(listener, adListener)
}

private val storeByRatingAdapters by lazy {
SearchByRatingRecyclerAdapter(listener)
SearchByRatingRecyclerAdapter(listener, adListener)
}

override fun onTouch() {
Expand Down Expand Up @@ -73,13 +88,36 @@ class StoreByMenuActivity :
viewModel.changeSortType(SortType.RATING, currentPosition)
}
}
popupViewModel.popups.observe(this, { popups ->
if (popups.isNotEmpty()) {
binding.itemStoreListAd.run {
tvAdTitle.text = popups[0].title
popups[0].fontColor?.let {
tvAdTitle.setTextColor(it.toColorInt())
tvAdBody.setTextColor(it.toColorInt())
}
tvAdBody.text = popups[0].subTitle

popups[0].bgColor?.let { layoutItem.setBackgroundColor(it.toColorInt()) }

ivAdImage.loadUrlImg(popups[0].imageUrl)

tvDetail.setOnClickListener {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(popups[0].linkUrl)))
}
}
storeByDistanceAdapters.submitAdList(popups)
storeByRatingAdapters.submitAdList(popups)
}
})
viewModel.storeByRating.observe(this) {
val storeInfoList = if (binding.cbCertification.isChecked) {
it.filter { storeInfo -> storeInfo.visitHistory.isCertified }
} else {
it
}
storeByRatingAdapters.submitList(storeInfoList)
popupViewModel.getPopups("STORE_CATEGORY_LIST")
}
viewModel.storeByDistance.observe(this) {
val storeInfoList = if (binding.cbCertification.isChecked) {
Expand All @@ -88,6 +126,7 @@ class StoreByMenuActivity :
it
}
storeByDistanceAdapters.submitList(storeInfoList)
popupViewModel.getPopups("STORE_CATEGORY_LIST")
}
binding.btnBack.setOnClickListener {
finish()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.zion830.threedollars.ui.category.adapter

import android.annotation.SuppressLint
import android.view.ViewGroup
import androidx.core.graphics.toColorInt
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.zion830.threedollars.R
import com.zion830.threedollars.databinding.ItemStoreListAdBinding
import com.zion830.threedollars.repository.model.v2.response.Popups
import zion830.com.common.base.BaseViewHolder
import zion830.com.common.base.loadUrlImg
import zion830.com.common.listener.OnItemClickListener

class SearchByAdViewHolder(parent: ViewGroup) :
BaseViewHolder<ItemStoreListAdBinding, Popups>(R.layout.item_store_list_ad, parent) {

@SuppressLint("Range")
override fun bind(item: Popups, listener: OnItemClickListener<Popups>?) {
super.bind(item, listener)
if (!item.fontColor.isNullOrEmpty()) {
binding.tvAdTitle.setTextColor(item.fontColor.toColorInt())
binding.tvAdBody.setTextColor(item.fontColor.toColorInt())
}
if (!item.bgColor.isNullOrEmpty()) {
binding.layoutItem.setBackgroundColor(item.bgColor.toColorInt())
}
binding.ivAdImage.loadUrlImg(item.imageUrl)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,97 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.zion830.threedollars.R
import com.zion830.threedollars.databinding.ItemStoreByDistanceBinding
import com.zion830.threedollars.repository.model.v2.response.AdAndStoreItem
import com.zion830.threedollars.repository.model.v2.response.Popups
import com.zion830.threedollars.repository.model.v2.response.store.StoreInfo
import com.zion830.threedollars.utils.SharedPrefUtils
import zion830.com.common.base.BaseViewHolder
import zion830.com.common.ext.toFormattedNumber
import zion830.com.common.listener.OnItemClickListener

class SearchByDistanceRecyclerAdapter(
private val listener: OnItemClickListener<StoreInfo>
) : RecyclerView.Adapter<SearchByDistanceViewHolder>() {
private val items = arrayListOf<StoreInfo>()
private val listener: OnItemClickListener<StoreInfo>,
private val adListener: OnItemClickListener<Popups>
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private val items = arrayListOf<AdAndStoreItem>()

override fun getItemCount(): Int = items.size
override fun getItemCount(): Int {
return items.size
}

override fun getItemViewType(position: Int): Int {
return when (items[position]) {
is Popups -> {
VIEW_TYPE_AD
}
is StoreInfo -> {
VIEW_TYPE_STORE
}
else -> {
throw IllegalStateException("Not Found ViewHolder Type")
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchByDistanceViewHolder {
return SearchByDistanceViewHolder(parent)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType) {
VIEW_TYPE_AD -> {
SearchByAdViewHolder(parent)
}
VIEW_TYPE_STORE -> {
SearchByDistanceViewHolder(parent)
}
else -> {
throw IllegalStateException("Not Found ViewHolder Type $viewType")
}
}

override fun onBindViewHolder(holder: SearchByDistanceViewHolder, position: Int) {
holder.bind(items[position], listener)
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (holder) {
is SearchByDistanceViewHolder -> {
holder.bind(items[position] as StoreInfo, listener)
}
is SearchByAdViewHolder -> {
holder.bind(items[position] as Popups, adListener)
}
}
}

fun submitList(newItems: List<StoreInfo>) {
fun submitList(newItems: List<AdAndStoreItem>) {
items.clear()
items.addAll(newItems)
notifyDataSetChanged()
}

fun submitAdList(newItems: List<AdAndStoreItem>) {
if (items.isEmpty()) {
return
}
val list = items.filterIsInstance<StoreInfo>()
items.clear()
items.addAll(list)
items.add(1, newItems[0])
notifyDataSetChanged()
}


companion object {
private const val VIEW_TYPE_AD = 1
private const val VIEW_TYPE_STORE = 2
}
}

class SearchByDistanceViewHolder(parent: ViewGroup) : BaseViewHolder<ItemStoreByDistanceBinding, StoreInfo>(R.layout.item_store_by_distance, parent) {

class SearchByDistanceViewHolder(parent: ViewGroup) :
BaseViewHolder<ItemStoreByDistanceBinding, StoreInfo>(R.layout.item_store_by_distance, parent) {

override fun bind(item: StoreInfo, listener: OnItemClickListener<StoreInfo>?) {
super.bind(item, listener)

val categoryInfo = SharedPrefUtils.getCategories()
val categories = item.categories.joinToString(" ") { "#${categoryInfo.find { categoryInfo -> categoryInfo.category == it }?.name}" }
val categories =
item.categories.joinToString(" ") { "#${categoryInfo.find { categoryInfo -> categoryInfo.category == it }?.name}" }
val distanceString = "${item.distance.toString().toFormattedNumber()}m"
binding.tvCategory.text = categories
binding.tvDistance.text = distanceString
}
}
}
Loading

0 comments on commit 20f6d5e

Please sign in to comment.