mirror of
https://github.com/imcarlost/Friendlists.git
synced 2026-04-10 10:56:54 -04:00
add navigation framework and implement it
This commit is contained in:
@@ -10,4 +10,4 @@ fun <T> LiveData<T>.observeNonNull(owner: LifecycleOwner, func: (T) -> Unit) {
|
||||
func(it)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.hako.base.extensions
|
||||
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
fun <T> RecyclerView.Adapter<*>.autoNotify(oldList: List<T>, newList: List<T>, compare: (T, T) -> Boolean) {
|
||||
val diff = DiffUtil.calculateDiff(object : DiffUtil.Callback() {
|
||||
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
return compare(oldList[oldItemPosition], newList[newItemPosition])
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
return oldList[oldItemPosition] == newList[newItemPosition]
|
||||
}
|
||||
|
||||
override fun getOldListSize() = oldList.size
|
||||
|
||||
override fun getNewListSize() = newList.size
|
||||
})
|
||||
|
||||
diff.dispatchUpdatesTo(this)
|
||||
}
|
||||
@@ -1,19 +1,6 @@
|
||||
package com.hako.base.extensions
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
|
||||
fun AppCompatActivity.findNavHostFragment(@IdRes id: Int) =
|
||||
supportFragmentManager.findFragmentById(id) as NavHostFragment
|
||||
|
||||
fun Fragment.findNavHostFragment(@IdRes id: Int) =
|
||||
childFragmentManager.findFragmentById(id) as NavHostFragment
|
||||
|
||||
fun Fragment.findNavController(@IdRes id: Int) =
|
||||
androidx.navigation.Navigation.findNavController(view?.findViewById(id) ?: viewNotFound(id, this))
|
||||
|
||||
private fun viewNotFound(@IdRes id: Int, fragment: Fragment): Nothing = throw IllegalStateException(
|
||||
"View ID $id at '${fragment::class.java.simpleName}' not found."
|
||||
)
|
||||
fun buildNavigation(@IdRes id: Int, bundle: Bundle = Bundle()) = Pair(id, bundle)
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
fun View.enable() {
|
||||
isEnabled = true
|
||||
@@ -37,3 +39,22 @@ fun ViewGroup.inflate(@LayoutRes layout: Int, attachToRoot: Boolean = false): Vi
|
||||
LayoutInflater
|
||||
.from(context)
|
||||
.inflate(layout, this, attachToRoot)
|
||||
|
||||
fun <T> RecyclerView.Adapter<*>.autoNotify(oldList: List<T>, newList: List<T>, compare: (T, T) -> Boolean) {
|
||||
val diff = DiffUtil.calculateDiff(object : DiffUtil.Callback() {
|
||||
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
return compare(oldList[oldItemPosition], newList[newItemPosition])
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
return oldList[oldItemPosition] == newList[newItemPosition]
|
||||
}
|
||||
|
||||
override fun getOldListSize() = oldList.size
|
||||
|
||||
override fun getNewListSize() = newList.size
|
||||
})
|
||||
|
||||
diff.dispatchUpdatesTo(this)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.hako.base.navigation
|
||||
|
||||
interface NavigationEvent
|
||||
|
||||
interface NavigationController {
|
||||
fun sendNavigation(event: NavigationEvent)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.hako.base.navigation
|
||||
|
||||
class NavigationRouter : NavigationController {
|
||||
private var onNavigationEvent: (NavigationEvent) -> Unit = {}
|
||||
|
||||
override fun sendNavigation(event: NavigationEvent) {
|
||||
onNavigationEvent(event)
|
||||
}
|
||||
|
||||
fun setOnNavigationEvent(listener: (NavigationEvent) -> Unit) {
|
||||
onNavigationEvent = listener
|
||||
}
|
||||
}
|
||||
5
base/src/main/res/anim/slide_in_left.xml
Normal file
5
base/src/main/res/anim/slide_in_left.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate android:fromXDelta="-100%p" android:toXDelta="0"
|
||||
android:duration="@android:integer/config_shortAnimTime"/>
|
||||
</set>
|
||||
5
base/src/main/res/anim/slide_in_right.xml
Normal file
5
base/src/main/res/anim/slide_in_right.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate android:fromXDelta="100%p" android:toXDelta="0"
|
||||
android:duration="@android:integer/config_shortAnimTime"/>
|
||||
</set>
|
||||
5
base/src/main/res/anim/slide_out_left.xml
Normal file
5
base/src/main/res/anim/slide_out_left.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate android:fromXDelta="0" android:toXDelta="-100%p"
|
||||
android:duration="@android:integer/config_shortAnimTime"/>
|
||||
</set>
|
||||
5
base/src/main/res/anim/slide_out_right.xml
Normal file
5
base/src/main/res/anim/slide_out_right.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate android:fromXDelta="0" android:toXDelta="100%p"
|
||||
android:duration="@android:integer/config_shortAnimTime"/>
|
||||
</set>
|
||||
Reference in New Issue
Block a user