Skip to content

Commit

Permalink
feature/#9-home-ui : 업로드 에러 다이얼로그 UI 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
BENDENG1 committed Jul 12, 2024
1 parent d1e3668 commit ad03599
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.depromeet.presentation.home

import android.annotation.SuppressLint
import android.net.Uri
import android.os.Bundle
import android.view.View
Expand Down Expand Up @@ -49,11 +50,29 @@ class ProfileImageUploadDialog() : BindingBottomSheetDialog<FragmentProfileEditB
pickSingleImageLauncher =
registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? ->
uri?.let {
viewModel.setProfileImage(uri.toString())
dismiss()
handleSelectedImage(uri)
}
}
}

@SuppressLint("Recycle")
private fun handleSelectedImage(uri: Uri) {
val inputStream = requireContext().contentResolver.openInputStream(uri)
val sizeBytes = inputStream?.available() ?: 0
val sizeMB = sizeBytes / (1024f * 1024f)

if (sizeMB > 5) {
val fragment = UploadErrorDialog(
getString(R.string.upload_error_capacity_description),
getString(R.string.upload_error_capacity_5MB)
)
fragment.show(parentFragmentManager, fragment.tag)
dismiss()
} else {
viewModel.setProfileImage(uri.toString())
dismiss()
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.depromeet.presentation.home

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import androidx.fragment.app.DialogFragment
import com.depromeet.core.base.BindingDialogFragment
import com.depromeet.presentation.R
import com.depromeet.presentation.databinding.FragmentUploadErrorDialogBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class UploadErrorDialog(
private val description: String,
private val discipline: String,
) : BindingDialogFragment<FragmentUploadErrorDialogBinding>(
layoutResId = R.layout.fragment_upload_error_dialog,
bindingInflater = FragmentUploadErrorDialogBinding::inflate
) {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NORMAL, R.style.TransparentDialogFragment)

}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

dialog?.window?.apply {
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val params = attributes
params.width = WindowManager.LayoutParams.MATCH_PARENT
params.height = WindowManager.LayoutParams.WRAP_CONTENT
attributes = params
}
with(binding) {
tvErrorDescription.text = description
tvErrorDiscipline.text = discipline
btErrorCheck.setOnClickListener {
dismiss()
}
}

}
}
10 changes: 10 additions & 0 deletions presentation/src/main/res/drawable/ic_solid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:pathData="M16,0C7.163,0 0,7.163 0,16C0,24.837 7.163,32 16,32C24.837,32 32,24.837 32,16C32,7.163 24.837,0 16,0ZM17.455,10.182C17.455,9.378 16.803,8.727 16,8.727C15.197,8.727 14.545,9.378 14.545,10.182V16C14.545,16.803 15.197,17.455 16,17.455C16.803,17.455 17.455,16.803 17.455,16V10.182ZM16,20.364C15.197,20.364 14.545,21.015 14.545,21.818C14.545,22.622 15.197,23.273 16,23.273H16.014C16.818,23.273 17.469,22.622 17.469,21.818C17.469,21.015 16.818,20.364 16.014,20.364H16Z"
android:fillColor="#AFAFAF"
android:fillType="evenOdd"/>
</vector>
6 changes: 6 additions & 0 deletions presentation/src/main/res/drawable/rect_gray900_fill_8.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp" />
<solid android:color="@color/gray900" />
</shape>
77 changes: 77 additions & 0 deletions presentation/src/main/res/layout/fragment_upload_error_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TransparentDialogFragment">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_error"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginHorizontal="35dp"
android:background="@drawable/rect_white_fill_12"
android:padding="20dp">

<ImageView
android:id="@+id/iv_error_caution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_solid"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_error_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="@string/upload_error_capacity_description"
android:textColor="@color/gray900"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_error_caution" />

<TextView
android:id="@+id/tv_error_discipline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textColor="@color/gray700"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_error_description"
tools:text="5MB에 맞게 다시 선택해주세요" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/bt_error_check"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginTop="24dp"
android:background="@drawable/rect_gray900_fill_8"
android:gravity="center"
android:text="@string/upload_error_check"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_error_discipline" />



</androidx.constraintlayout.widget.ConstraintLayout>



</androidx.constraintlayout.widget.ConstraintLayout>
6 changes: 6 additions & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<string name="profile_edit_error_length">닉네임은 최소 2글자에서 최대 10글자로 입력해 주세요.</string>
<string name="profile_edit_error_no">정상적으로 입력 완료!</string>

<!-- upload_error -->
<string name="upload_error_capacity_description">선택한 사진\n용량이 너무 커요</string>
<string name="upload_error_capacity_5MB">5MB에 맞게 다시 선택해주세요</string>
<string name="upload_error_check">확인</string>

<!-- viewfinder -->
<string name="viewfinder_find_view">시야찾기</string>
<string name="viewfinder_stadium_selection_description">어떤 야구장의\n시야가 궁금하신가요?</string>
Expand All @@ -38,4 +43,5 @@
<string name="viewfinder_lock_warning_trigger">"<u>"잠실야구장 시야보기"</u>"</string>



</resources>
7 changes: 7 additions & 0 deletions presentation/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@
<item name="android:backgroundDimEnabled">true</item> // Scrim이 있는 Modal
<item name="android:colorBackground">@android:color/transparent</item>
</style>

<style name="TransparentDialogFragment" parent="Theme.Material3.Light.Dialog">
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:colorBackground">@android:color/transparent</item>
<item name="android:background">@android:color/transparent</item>
</style>
</resources>

0 comments on commit ad03599

Please sign in to comment.