-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa539cf
commit 890066d
Showing
7 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
core-ui/src/main/java/com/going/ui/base/BaseBottomSheet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...java/com/going/core_ui/ExampleUnitTest.kt → ...test/java/com/going/ui/ExampleUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|