Skip to content

Commit

Permalink
[ADD/#1] base util 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchbreeze committed Dec 27, 2023
1 parent aa539cf commit 890066d
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.going.core_ui
package com.going.ui

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand All @@ -19,6 +19,6 @@ class ExampleInstrumentedTest {
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.going.core_ui", appContext.packageName)
assertEquals("com.going.ui", appContext.packageName)
}
}
15 changes: 15 additions & 0 deletions core-ui/src/main/java/com/going/ui/UiState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.going.ui

sealed interface UiState<out T> {
object Empty : UiState<Nothing>

object Loading : UiState<Nothing>

data class Success<T>(
val data: T,
) : UiState<T>

data class Failure(
val msg: String,
) : UiState<Nothing>
}
27 changes: 27 additions & 0 deletions core-ui/src/main/java/com/going/ui/base/BaseActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.going.ui.base

import android.os.Bundle
import android.view.MotionEvent
import android.view.View
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

abstract class BaseActivity<T : ViewDataBinding>(
@LayoutRes private val layoutResId: Int,
) : AppCompatActivity() {

protected lateinit var binding: T

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, layoutResId)
binding.lifecycleOwner = this
}

override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
hideKeyboard(currentFocus ?: View(this))
return super.dispatchTouchEvent(ev)
}
}
34 changes: 34 additions & 0 deletions core-ui/src/main/java/com/going/ui/base/BaseBottomSheet.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.going.ui.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.google.android.material.bottomsheet.BottomSheetDialogFragment

abstract class BaseBottomSheet<T : ViewDataBinding>(
@LayoutRes private val layoutRes: Int,
) : BottomSheetDialogFragment() {

private var _binding: T? = null
protected val binding: T
get() = requireNotNull(_binding) { "binding object is not initialized" }

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

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
34 changes: 34 additions & 0 deletions core-ui/src/main/java/com/going/ui/base/BaseDialog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.going.ui.base

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

abstract class BaseDialog<T : ViewDataBinding>(
@LayoutRes private val layoutRes: Int,
) : DialogFragment() {

private var _binding: T? = null
protected val binding: T
get() = requireNotNull(_binding) { "binding object is not initialized" }

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

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
34 changes: 34 additions & 0 deletions core-ui/src/main/java/com/going/ui/base/BaseFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.going.ui.base

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

abstract class BaseFragment<T : ViewDataBinding>(
@LayoutRes private val layoutRes: Int,
) : Fragment() {

private var _binding: T? = null
protected val binding: T
get() = requireNotNull(_binding) { "binding object is not initialized" }

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

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.going.core_ui
package com.going.ui

import org.junit.Test

Expand Down

0 comments on commit 890066d

Please sign in to comment.