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

#32 / dialog custom #37

Merged
merged 5 commits into from
Jul 15, 2023
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
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@
android:screenOrientation="portrait" />

<activity
android:name=".presentation.MainHistoryActivity"
android:exported="true"
android:name=".presentation.HistoryMainActivity"
android:exported="false"
android:screenOrientation="portrait" />

<activity
android:name=".presentation.SubHistoryActivity"
android:name=".presentation.HistorySubActivity"
android:exported="false"
android:screenOrientation="portrait" />

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/sopt/uni/presentation/HistoryAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.recyclerview.widget.RecyclerView
import sopt.uni.data.entity.history.HistoryItem
import sopt.uni.databinding.ItemHistorylistBinding
import sopt.uni.util.extension.ItemDiffCallback
import sopt.uni.util.extension.setOnSingleClickListener

class HistoryAdapter(
private val context: Context,
Expand Down Expand Up @@ -65,7 +66,7 @@ class HistoryAdapter(
historyItemGameResult.text = item.result
historyItemRightImage.setImageDrawable(binding.root.context.getDrawable(item.next))

historyItemRightImage.setOnClickListener {
historyItemRightImage.setOnSingleClickListener {
// 클릭 이벤트 처리
val item = getItem(adapterPosition)
itemClickedListener.invoke(item)
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/sopt/uni/presentation/HistoryDialog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package sopt.uni.presentation

import android.os.Bundle
import android.view.View
import sopt.uni.R
import sopt.uni.databinding.TitleAction1DialogBinding
import sopt.uni.util.extension.setOnSingleClickListener

// 예시용 입니다! 히스토리는 다이얼로그 없어용
class HistoryDialog :
BindingDialogFragment<TitleAction1DialogBinding>(R.layout.title_action1_dialog) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// 텍스트 넣기
binding.dialogBody.setText("내용임둥")
binding.dialogTitle.setText("제목임둥")
// 클릭시 로직 처리
binding.btnPositive.setOnSingleClickListener {
dismiss()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import sopt.uni.data.entity.history.HistoryList
import sopt.uni.databinding.ActivityMainHistoryBinding
import sopt.uni.util.binding.BindingActivity

class MainHistoryActivity :
class HistoryMainActivity :
BindingActivity<ActivityMainHistoryBinding>(R.layout.activity_main_history) {

private val historyAdapter by lazy {
HistoryAdapter(
context = this@MainHistoryActivity,
context = this@HistoryMainActivity,
onEmptyList = { isEmpty ->
if (isEmpty) {
binding.itemHistoryEmptylist.visibility = View.VISIBLE
Expand All @@ -24,7 +24,7 @@ class MainHistoryActivity :
}
},
itemClickedListener = { historyItem ->
val intent = Intent(this, SubHistoryActivity::class.java)
val intent = Intent(this, HistorySubActivity::class.java)
startActivity(intent)
},
)
Expand All @@ -35,14 +35,17 @@ class MainHistoryActivity :
setContentView(binding.root)

binding.rvHistoryList.adapter = historyAdapter
binding.rvHistoryList.layoutManager = LinearLayoutManager(this@MainHistoryActivity)
binding.rvHistoryList.layoutManager = LinearLayoutManager(this@HistoryMainActivity)

// 다이얼로그 띄우는 부분
HistoryDialog().show(supportFragmentManager, "HistoryDialog")

historyAdapter.submitList(HistoryList)

val dividerItemDecoration =
DividerItemDecoration(
binding.rvHistoryList.context,
LinearLayoutManager(this@MainHistoryActivity).orientation,
LinearLayoutManager(this@HistoryMainActivity).orientation,
)
binding.rvHistoryList.addItemDecoration(dividerItemDecoration)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import sopt.uni.R
import sopt.uni.databinding.ActivitySubHistoryBinding
import sopt.uni.util.binding.BindingActivity

class SubHistoryActivity :
class HistorySubActivity :
BindingActivity<ActivitySubHistoryBinding>(R.layout.activity_sub_history) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)

binding.historySubBack.setOnClickListener {
val intent = Intent(this, MainHistoryActivity::class.java)
val intent = Intent(this, HistoryMainActivity::class.java)
startActivity(intent)
finish()
}
Expand Down
120 changes: 0 additions & 120 deletions app/src/main/java/sopt/uni/presentation/HistoryViewModel.kt

This file was deleted.

40 changes: 40 additions & 0 deletions app/src/main/java/sopt/uni/util/binding/BindingDialogFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package sopt.uni.presentation

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.DialogFragment

abstract class BindingDialogFragment<B : ViewDataBinding>(@LayoutRes private val layoutRes: Int) :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아주 좋다!

DialogFragment() {
private var _binding: B? = null
val binding get() = requireNotNull(_binding!!) { "${this::class.java.simpleName}에서 에러가 발생했습니다." }

override fun onStart() {
super.onStart()
dialog?.window?.setLayout(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
)
dialog?.window?.setBackgroundDrawableResource(android.R.color.transparent)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
_binding = DataBindingUtil.inflate(inflater, layoutRes, container, false)
return binding.root
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/sopt/uni/util/binding/BindingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import androidx.fragment.app.Fragment
import sopt.uni.R

abstract class BindingFragment<T : ViewDataBinding>(
@LayoutRes private val layoutRes: Int
@LayoutRes private val layoutRes: Int,
) : Fragment() {
private var _binding: T? = null
protected val binding get() = _binding ?: error(getString(R.string.binding_error))

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
savedInstanceState: Bundle?,
): View? {
_binding = DataBindingUtil.inflate(inflater, layoutRes, container, false)
binding.lifecycleOwner = viewLifecycleOwner
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_mission_detail_create.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="40dp"
android:background="@drawable/bg_mission_detail_button_rounded"
android:fontFamily="@font/pretendard_semibold"
android:paddingVertical="12dp"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_sub_history.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Gray_100"
tools:context=".presentation.SubHistoryActivity">
tools:context=".presentation.HistorySubActivity">

<ImageView
android:id="@+id/history_sub_back"
Expand Down
62 changes: 62 additions & 0 deletions app/src/main/res/layout/datepicker_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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">

<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/bg_mission_detail_textbox">


<DatePicker
android:id="@+id/date_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:calendarViewShown="false"
android:datePickerMode="spinner"
android:maxDate="07/15/2023"
app:layout_constraintBottom_toTopOf="@+id/btn_left"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/btn_left"
style="@style/Body1_Regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="120dp"
android:layout_marginBottom="16dp"
android:paddingHorizontal="14dp"
android:paddingVertical="7dp"
android:text="@string/dialog_cancel_text"
android:textColor="@color/Lightblue_600"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/btn_right"
style="@style/Btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="16dp"
android:paddingHorizontal="14dp"
android:paddingVertical="7dp"
android:text="@string/dialog_apply_text"
android:textColor="@color/Lightblue_600"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn_left"
app:layout_constraintTop_toTopOf="@+id/btn_left" />


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