Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP-195 ui: 이미지가 있는 스낵바 구현 #70

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>