Skip to content

Commit

Permalink
[FEAT] #248 : Banner - 메인(홈) 배너 작업
Browse files Browse the repository at this point in the history
  • Loading branch information
HJinhee committed Apr 3, 2022
1 parent b8ab394 commit b2f13a5
Show file tree
Hide file tree
Showing 39 changed files with 211 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.charo.android.domain.model.home

import android.graphics.fonts.Font

data class BannerLocal(
val homeViewPagerRoadImage: Int,
val homeViewPagerTitle: String,
val homeViewPagerSubTitle: String,
val homeViewPagerSubTitleImg: Int,
val titleFontSize: Float,
val charoImgVisible: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ 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
import com.charo.android.presentation.ui.alarm.AlarmActivity
Expand All @@ -31,6 +33,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
private var theme = ThemeUtil()
private var location = LocationUtil()
private lateinit var homeViewPagerAdapter: HomeViewPagerAdapter
private lateinit var homeViewPagerLocalAdapter: HomeViewPagerLocalAdapter
private lateinit var homeTodayDriveAdapter: HomeTodayDriveAdapter
private lateinit var homeThemeAdapter: HomeThemeAdapter
private lateinit var homeHotDriveAdapter: HomeTrendDriveAdapter
Expand All @@ -53,7 +56,8 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
goAlarm()
initToolBar()
replaceMoreViewFragment(Hidden.userId)
initBanner()
initBannerLocal()
// initBanner()
initTrendDrive()
initLocalDrive()
initTodayCharoDrive()
Expand All @@ -67,6 +71,22 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
(activity as AppCompatActivity).setSupportActionBar(toolbar)
}

//배너 디지인
private fun initBannerLocal() {
val bannerLocal : List<BannerLocal>
val userEmail = SharedInformation.getEmail(requireActivity())
homeViewModel.getBanner(userEmail)
homeViewPagerLocalAdapter = HomeViewPagerLocalAdapter()
binding.vpMain.adapter = homeViewPagerLocalAdapter

val Banner1 : BannerLocal = BannerLocal(R.drawable.banner_img_one,"강릉 해변 \n드라이브 코스와 맛집","강릉 8년차가 소개해주는",0,28f,false)
val Banner2 : BannerLocal = BannerLocal(R.drawable.banner_img_two,"봄의 선선한 바람 \n플레이리스트","",R.drawable.spring_playlist,28f,false)
val Banner3 : BannerLocal = BannerLocal(R.drawable.banner_img_three,"자동차 극장\n드라이브 코스","",R.drawable.drive_in_theater,28f,false)
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())
}

//배너 설정
private fun initBanner() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.charo.android.presentation.ui.home.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.charo.android.databinding.ItemHomeViewpagerLocalBinding
import com.charo.android.domain.model.home.BannerLocal
import com.charo.android.domain.model.home.BannerRoad

class HomeViewPagerLocalAdapter() :
RecyclerView.Adapter<HomeViewPagerLocalAdapter.HomeViewPagerViewHolder>() {
private val _banner = mutableListOf<BannerLocal>()
var banner: List<BannerLocal> = _banner

private val _bannerRoad = mutableListOf<BannerRoad>()
var bannerRoad : List<BannerRoad> = _bannerRoad

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): HomeViewPagerViewHolder {
val binding = ItemHomeViewpagerLocalBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
return HomeViewPagerViewHolder(binding)
}

override fun onBindViewHolder(
holder: HomeViewPagerViewHolder,
position: Int
) {
holder.onBind(banner[position], bannerRoad[position])

}

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

class HomeViewPagerViewHolder(
private val binding: ItemHomeViewpagerLocalBinding
) : RecyclerView.ViewHolder(binding.root) {
fun onBind(banner : BannerLocal, bannerRoad: BannerRoad){

Glide.with(binding.imgViewpager)
.load(banner.homeViewPagerRoadImage)
.into(binding.imgViewpager)

if(banner.homeViewPagerSubTitleImg == 0){
binding.textViewpagerSubTitleImg.visibility = View.GONE
}else{
binding.textViewpagerSubTitleImg.visibility = View.VISIBLE
binding.textViewpagerSubTitleImg.setImageResource(banner.homeViewPagerSubTitleImg)
}

if(banner.charoImgVisible){
binding.imgViewpagerCharo.visibility = View.VISIBLE
}else{
binding.imgViewpagerCharo.visibility = View.INVISIBLE
}
binding.textViewpagerTitle.textSize = banner.titleFontSize
binding.banner = banner
binding.bannerRoad = bannerRoad
binding.executePendingBindings()
}
}

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

}
Binary file added app/src/main/res/drawable-hdpi/banner_charo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/banner_img_one.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/banner_img_two.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/banner_charo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/banner_img_one.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/banner_img_two.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/drive_in_theater.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/banner_charo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions app/src/main/res/layout/item_home_viewpager_local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>

<layout xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="banner"
type="com.charo.android.domain.model.home.BannerLocal" />

<variable
name="bannerRoad"
type="com.charo.android.domain.model.home.BannerRoad" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/img_viewpager"
android:layout_width="0dp"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/main_image"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>

<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#63000000"
/>

<ImageView
android:id="@+id/text_viewpager_sub_title_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/text_viewpager_title"
app:layout_constraintStart_toStartOf="@+id/text_viewpager_title"
/>

<TextView
android:id="@+id/text_viewpager_sub_title"
style="@style/HeaderH2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:includeFontPadding="false"
android:textColor="@color/white"
android:text="@{banner.homeViewPagerSubTitle}"
app:layout_constraintBottom_toTopOf="@id/text_viewpager_title"
app:layout_constraintStart_toStartOf="@+id/text_viewpager_title"
/>

<TextView
android:id="@+id/text_viewpager_title"
style="@style/HeaderH1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
app:layout_constraintVertical_bias="0.55"
android:text="@{banner.homeViewPagerTitle}"
tools:text="차에서의\n오늘이 최고가 될 수 있게\n당신의 드라이브 메이트"
android:lineSpacingExtra="1sp"
android:includeFontPadding="false"
app:layout_constraintBottom_toBottomOf="@+id/img_viewpager"
app:layout_constraintStart_toStartOf="@+id/img_viewpager"
app:layout_constraintTop_toTopOf="@+id/img_viewpager"
app:layout_constraintEnd_toStartOf="@+id/img_viewpager_charo"/>

<ImageView
android:id="@+id/img_viewpager_charo"
android:layout_width="0dp"
android:scaleType="fitStart"
android:layout_height="wrap_content"
android:src="@drawable/banner_charo"
app:layout_constraintStart_toEndOf="@id/text_viewpager_title"
app:layout_constraintBottom_toBottomOf="@id/text_viewpager_title"
app:layout_constraintEnd_toEndOf="parent"
android:visibility="invisible"/>

<ImageView
android:id="@+id/img_viewpager_line"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
imgIntBind="@{bannerRoad.bannerRoadImg}"
app:layout_constraintBottom_toBottomOf="parent"/>


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit b2f13a5

Please sign in to comment.