Skip to content

Commit

Permalink
DEP-195 ui: 이미지가 있는 스낵바 구현 (#70)
Browse files Browse the repository at this point in the history
* ui: 이미지가 있는 스낵바 구현

* fix: lint 이슈 해결
  • Loading branch information
juhwankim-dev authored Dec 15, 2022
1 parent c931b48 commit bc92b3e
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.depromeet.threedays.core.util

import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.core.content.ContextCompat
import com.depromeet.threedays.core.databinding.ImageSnackbarThreeDaysBinding
import com.depromeet.threedays.core.setOnSingleClickListener
import com.google.android.material.snackbar.Snackbar

class ThreeDaysImageSnackBar {
fun show(
view: View,
title: String,
content: String,
actionText: String,
onAction: () -> Unit
) {
val binding = ImageSnackbarThreeDaysBinding.inflate(LayoutInflater.from(view.context), null, false)
val snackbar = Snackbar.make(view, title, 5000)
val snackbarLayout = snackbar.view as Snackbar.SnackbarLayout

with(snackbarLayout) {
removeAllViews()
setPadding(0, 0, 0, 0)
setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent))
addView(binding.root, 0)

val params = layoutParams as FrameLayout.LayoutParams
params.gravity = Gravity.TOP
}

binding.tvTitle.text = title
binding.tvContent.text = content
binding.tvActionButton.text = actionText
binding.tvActionButton.setOnSingleClickListener {
onAction()
snackbar.dismiss()
}

snackbar.show()
}
}
77 changes: 77 additions & 0 deletions core/src/main/res/layout/image_snackbar_three_days.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
tools:ignore="ContentDescription">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="6dp"
android:background="@drawable/bg_rect_gray700_r15"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<ImageView
android:id="@+id/iv_illustrator"
android:layout_width="61dp"
android:layout_height="61dp"
android:layout_marginVertical="14dp"
android:layout_marginStart="14dp"
android:src="@drawable/bg_rect_gray100_r10"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginBottom="4dp"
android:textAppearance="@style/Typography.SubTitle"
android:textColor="@color/gray_500"
android:textSize="14dp"
app:layout_constraintBottom_toTopOf="@+id/tv_content"
app:layout_constraintStart_toEndOf="@+id/iv_illustrator"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="레벨 업" />

<TextView
android:id="@+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/Typography.Body1"
android:textColor="@color/white"
android:textSize="14dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/tv_title"
app:layout_constraintTop_toBottomOf="@+id/tv_title"
tools:text="Lv.2 로 레벨업 했어요!" />

<TextView
android:id="@+id/tv_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:padding="12dp"
android:textAppearance="@style/Typography.Body4.SemiBold"
android:textColor="@color/blue_50"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="이동" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit bc92b3e

Please sign in to comment.