-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/Team-Sopetit/Sopetit-And…
…roid into feature/#8-add-daily-routine # Conflicts: # app/src/main/AndroidManifest.xml # app/src/main/res/drawable/ic_daily_theme_background.xml # app/src/main/res/drawable/ic_daily_theme_background_click.xml
- Loading branch information
Showing
38 changed files
with
1,430 additions
and
29 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
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/sopetit/softie/domain/entity/HappyCard.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,22 @@ | ||
package com.sopetit.softie.domain.entity | ||
|
||
import androidx.annotation.DrawableRes | ||
|
||
data class HappyCard( | ||
val categoryId: Int, | ||
val name: String, | ||
val nameColor: String, | ||
val title: String, | ||
@DrawableRes val iconImageUrl: Int, | ||
val routines: List<Routines> | ||
) { | ||
data class Routines( | ||
val routineId: Int, | ||
@DrawableRes val cardImageUrl: Int, | ||
val content: String, | ||
val detailTitle: String, | ||
val detailContent: String, | ||
val detailTime: String, | ||
val detailPlace: String | ||
) | ||
} |
2 changes: 1 addition & 1 deletion
2
...tie/ui/main/happy/HappyRoutineFragment.kt → ...e/ui/happyroutine/HappyRoutineFragment.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
127 changes: 127 additions & 0 deletions
127
app/src/main/java/com/sopetit/softie/ui/happyroutine/adddetail/HappyDetailActivity.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,127 @@ | ||
package com.sopetit.softie.ui.happyroutine.adddetail | ||
|
||
import android.content.Intent | ||
import android.graphics.Color | ||
import android.graphics.Rect | ||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.activity.viewModels | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.viewpager2.widget.CompositePageTransformer | ||
import androidx.viewpager2.widget.ViewPager2 | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.databinding.ActivityHappyAddDetailBinding | ||
import com.sopetit.softie.ui.happyroutine.addlist.HappyAddListActivity.Companion.ID | ||
import com.sopetit.softie.ui.main.MainActivity | ||
import com.sopetit.softie.util.binding.BindingActivity | ||
|
||
class HappyDetailActivity : | ||
BindingActivity<ActivityHappyAddDetailBinding>(R.layout.activity_happy_add_detail) { | ||
private lateinit var viewPager: ViewPager2 | ||
private lateinit var happyRoutineAddCardPagerAdapter: HappyDetailCardPagerAdapter | ||
|
||
private val viewModel by viewModels<HappyDetailCardViewModel>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
viewPager = binding.vpHappyAddDetailCard | ||
|
||
val categoryId = intent.getIntExtra(ID, -1) | ||
val viewModel = ViewModelProvider(this).get(HappyDetailCardViewModel::class.java) | ||
val happyCard = viewModel.mockHappyCardList.value?.get(categoryId - 1) | ||
|
||
happyCard?.let { | ||
with(binding) { | ||
tvHappyAddDetailTitle.text = happyCard.name | ||
ivHappyAddDetailIcon.setImageResource(happyCard.iconImageUrl) | ||
tvHappyAddDetailSubtitle.text = happyCard.title | ||
tvHappyAddDetailTitle.setTextColor(Color.parseColor(happyCard.nameColor)) | ||
} | ||
} | ||
|
||
setBackEnter() | ||
setSnackbarEnter() | ||
setupAdapter(categoryId) | ||
setIndicator() | ||
initViewPager() | ||
initPagerDiv(0, 90) | ||
} | ||
|
||
private fun setBackEnter() { | ||
binding.ivHappyAddDetailBack.setOnClickListener { | ||
finish() | ||
} | ||
} | ||
|
||
private fun setSnackbarEnter() { | ||
binding.btnHappyDetailAdd.setOnClickListener { | ||
moveToIng() | ||
} | ||
} | ||
|
||
private fun moveToIng() { | ||
Intent(this, MainActivity::class.java).apply { | ||
startActivity(this) | ||
} | ||
} | ||
|
||
private fun setupAdapter(categoryId: Int) { | ||
with(binding) { | ||
happyRoutineAddCardPagerAdapter = | ||
HappyDetailCardPagerAdapter() | ||
vpHappyAddDetailCard.adapter = happyRoutineAddCardPagerAdapter | ||
} | ||
happyRoutineAddCardPagerAdapter.submitList( | ||
viewModel.getHappyCardListForId(categoryId).get(0).routines | ||
) | ||
} | ||
|
||
private fun setIndicator() { | ||
binding.diHappyAddDetailIndicator.attachTo(binding.vpHappyAddDetailCard) | ||
} | ||
|
||
private fun initViewPager() { | ||
viewPager.adapter = happyRoutineAddCardPagerAdapter | ||
|
||
val dp = resources.getDimensionPixelSize(R.dimen.view_margin) | ||
val d = resources.displayMetrics.density | ||
val margin = (dp * d).toInt() | ||
|
||
with(binding.vpHappyAddDetailCard) { | ||
clipChildren = false | ||
clipToPadding = false | ||
offscreenPageLimit = 3 | ||
setPadding(margin, 0, margin, 0) | ||
} | ||
val compositePageTransformer = CompositePageTransformer() | ||
binding.vpHappyAddDetailCard.setPageTransformer(compositePageTransformer) | ||
} | ||
|
||
private fun initPagerDiv(previewWidth: Int, itemMargin: Int) { | ||
val decoMargin = previewWidth + itemMargin | ||
val pageTransX = decoMargin + previewWidth | ||
val decoration = PageDecoration(decoMargin) | ||
|
||
binding.vpHappyAddDetailCard.also { | ||
it.offscreenPageLimit = 1 | ||
it.addItemDecoration(decoration) | ||
it.setPageTransformer { page, position -> | ||
page.translationX = position * -pageTransX | ||
} | ||
} | ||
} | ||
|
||
private class PageDecoration(private val margin: Int) : RecyclerView.ItemDecoration() { | ||
|
||
override fun getItemOffsets( | ||
outRect: Rect, | ||
view: View, | ||
parent: RecyclerView, | ||
state: RecyclerView.State | ||
) { | ||
outRect.left = margin | ||
outRect.right = margin | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...src/main/java/com/sopetit/softie/ui/happyroutine/adddetail/HappyDetailCardPagerAdapter.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,65 @@ | ||
package com.sopetit.softie.ui.happyroutine.adddetail | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.sopetit.softie.databinding.ItemHappyAddDetailCardBinding | ||
import com.sopetit.softie.domain.entity.HappyCard | ||
import com.sopetit.softie.util.ItemDiffCallback | ||
|
||
class HappyDetailCardPagerAdapter() : | ||
ListAdapter<HappyCard.Routines, HappyDetailCardPagerAdapter.HappyPagerViewHolder>( | ||
ItemDiffCallback<HappyCard.Routines>( | ||
onItemsTheSame = { oldItem, newItem -> oldItem.routineId == newItem.routineId }, | ||
onContentsTheSame = { oldItem, newItem -> oldItem == newItem } | ||
) | ||
) { | ||
|
||
class HappyPagerViewHolder( | ||
private val binding: ItemHappyAddDetailCardBinding | ||
) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun onBind(data: HappyCard.Routines) { | ||
with(binding) { | ||
ivHappyRoutineAddCard.setImageResource(data.cardImageUrl) | ||
tvHappyRoutineAddCardDetailTitle.text = data.detailTitle | ||
tvHappyRoutineAddCardDetailTitleBack.text = data.detailTitle | ||
tvHappyRoutineAddCardDetailContentBack.text = data.detailContent | ||
tvHappyRoutineAddCardDetailTimeBack.text = data.detailTime | ||
tvHappyRoutineAddCardDetailPlaceBack.text = data.detailPlace | ||
|
||
clHappyRoutineAddCard.setOnClickListener { | ||
setCardFlip(clHappyRoutineAddCard, clHappyRoutineAddCardBack) | ||
} | ||
clHappyRoutineAddCardBack.setOnClickListener { | ||
setCardFlip(clHappyRoutineAddCardBack, clHappyRoutineAddCard) | ||
} | ||
} | ||
} | ||
|
||
private fun setCardFlip(viewFront: View, viewToBack: View) { | ||
val isVisible = viewFront.visibility == View.VISIBLE | ||
if (isVisible) { | ||
viewFront.visibility = View.INVISIBLE | ||
viewToBack.visibility = View.VISIBLE | ||
} else { | ||
viewFront.visibility = View.VISIBLE | ||
viewToBack.visibility = View.INVISIBLE | ||
} | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HappyPagerViewHolder { | ||
val binding = ItemHappyAddDetailCardBinding.inflate( | ||
LayoutInflater.from(parent.context), parent, false | ||
) | ||
return HappyPagerViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: HappyPagerViewHolder, position: Int) { | ||
holder.onBind(currentList[position]) | ||
} | ||
} |
Oops, something went wrong.