Skip to content

Commit

Permalink
#248 [FEAT] : Home Banner - Add Car Animation
Browse files Browse the repository at this point in the history
  • Loading branch information
HJinhee committed Apr 8, 2022
1 parent 8063c93 commit c7c65d1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.charo.android.presentation.ui.home

import android.animation.ObjectAnimator
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearSnapHelper
import androidx.viewpager2.widget.ViewPager2
import com.charo.android.R
import com.charo.android.data.datasource.local.home.LocalHomeThemeDataSourceImpl
import com.charo.android.data.model.request.home.RequestHomeLikeData
import com.charo.android.databinding.FragmentHomeBinding
import com.charo.android.domain.model.home.Banner
import com.charo.android.domain.model.home.BannerLocal
import com.charo.android.hidden.Hidden
import com.charo.android.presentation.base.BaseFragment
Expand All @@ -25,6 +27,7 @@ import com.charo.android.presentation.util.SharedInformation
import com.charo.android.presentation.util.ThemeUtil
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
import android.util.DisplayMetrics


class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
Expand Down Expand Up @@ -56,8 +59,11 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
goAlarm()
initToolBar()
replaceMoreViewFragment(Hidden.userId)

initBannerLocal()
// initBanner()
carAnimation()

initTrendDrive()
initLocalDrive()
initTodayCharoDrive()
Expand All @@ -71,6 +77,30 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
(activity as AppCompatActivity).setSupportActionBar(toolbar)
}

private fun carAnimation(){
binding.vpMain.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)

val displayMetrics = DisplayMetrics()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
requireContext().display!!.getRealMetrics(displayMetrics)
} else {
requireActivity().windowManager.defaultDisplay.getMetrics(displayMetrics)
displayMetrics.widthPixels
}

val width = displayMetrics.widthPixels

val xValues: Float = (width * (position.toFloat()/4))
val anim : ObjectAnimator = ObjectAnimator.ofFloat(view, "translationX", xValues)

anim.target = binding.ivHomeCharoCar
anim.duration = 700
anim.start()
}
})
}
//배너 디지인
private fun initBannerLocal() {
val bannerLocal : List<BannerLocal>
Expand All @@ -85,7 +115,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
val Banner4 : BannerLocal = BannerLocal(R.drawable.banner_img_four,"차에서의 \n오늘이 최고가 될 수 있게\n당신의 드라이브 메이트","",0,22f,true)
bannerLocal = listOf(Banner1,Banner2,Banner3,Banner4)

homeViewPagerLocalAdapter.setHomeBanner(bannerLocal, homeViewModel.getBannerRoad())
homeViewPagerLocalAdapter.setHomeBanner(bannerLocal)
}

//배너 설정
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class HomeViewPagerLocalAdapter() : RecyclerView.Adapter<HomeViewPagerLocalAdapt
holder: HomeViewPagerViewHolder,
position: Int
) {
holder.onBind(banner[position], bannerRoad[position])
holder.onBind(banner[position])

holder.itemView.setOnClickListener {
val activity = it.context as AppCompatActivity
Expand Down Expand Up @@ -67,7 +67,7 @@ class HomeViewPagerLocalAdapter() : RecyclerView.Adapter<HomeViewPagerLocalAdapt
class HomeViewPagerViewHolder(
private val binding: ItemHomeViewpagerLocalBinding
) : RecyclerView.ViewHolder(binding.root) {
fun onBind(banner : BannerLocal, bannerRoad: BannerRoad){
fun onBind(banner : BannerLocal){

Glide.with(binding.imgViewpager)
.load(banner.homeViewPagerRoadImage)
Expand All @@ -87,14 +87,12 @@ class HomeViewPagerLocalAdapter() : RecyclerView.Adapter<HomeViewPagerLocalAdapt
}
binding.textViewpagerTitle.textSize = banner.titleFontSize
binding.banner = banner
binding.bannerRoad = bannerRoad
binding.executePendingBindings()
}
}

fun setHomeBanner(banner: List<BannerLocal>, bannerRoad: List<BannerRoad>){
fun setHomeBanner(banner: List<BannerLocal>){
this.banner = banner
this.bannerRoad = bannerRoad
notifyDataSetChanged()
}

Expand Down
Binary file added app/src/main/res/drawable-mdpi/move_charo_road.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />

<ImageView
android:id="@+id/iv_home_car_road"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_gravity="bottom"
android:layout_marginBottom="17dp"
android:background="@drawable/move_charo_road"
/>

<ImageView
android:id="@+id/iv_home_charo_car"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_gravity="bottom"
android:layout_marginBottom="25dp"
android:background="@drawable/car_main_animation"
/>

</FrameLayout>

<androidx.appcompat.widget.Toolbar
Expand Down

0 comments on commit c7c65d1

Please sign in to comment.