-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from zsoltk/plugin-utils
Plugin utils
- Loading branch information
Showing
27 changed files
with
635 additions
and
40 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
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
8 changes: 6 additions & 2 deletions
8
...es/rib-base/src/main/java/com/badoo/ribs/core/customisation/RibCustomisationExtensions.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,14 +1,18 @@ | ||
package com.badoo.ribs.core.customisation | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.annotation.LayoutRes | ||
import com.badoo.ribs.core.view.RibView | ||
|
||
fun <T> RibView.inflate(@LayoutRes layoutResourceId: Int): T = | ||
androidView.inflate(layoutResourceId) | ||
|
||
fun <T> ViewGroup.inflate(@LayoutRes layoutResourceId: Int): T = | ||
LayoutInflater | ||
.from(androidView.context) | ||
.from(context) | ||
.inflate( | ||
layoutResourceId, | ||
androidView, | ||
this, | ||
false | ||
) as T |
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
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
23 changes: 23 additions & 0 deletions
23
libraries/rib-base/src/main/res/layout/debug_controls_host.xml
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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/debug_controls_host" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/label" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:padding="4dp" | ||
android:textSize="18sp" | ||
tools:text="Debug controls" /> | ||
|
||
<FrameLayout | ||
android:id="@+id/children_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="8dp" /> | ||
|
||
</LinearLayout> |
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
67 changes: 67 additions & 0 deletions
67
...debug-utils/src/main/java/com/badoo/ribs/core/plugin/utils/debug/AbstractDebugControls.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,67 @@ | ||
package com.badoo.ribs.core.plugin.utils.debug | ||
|
||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import com.badoo.mobile.rib.base.R | ||
import com.badoo.ribs.core.Rib | ||
import com.badoo.ribs.core.customisation.inflate | ||
import com.badoo.ribs.core.plugin.NodeAware | ||
import com.badoo.ribs.core.plugin.NodeAwareImpl | ||
import com.badoo.ribs.core.plugin.RibAware | ||
import com.badoo.ribs.core.plugin.RibAwareImpl | ||
import com.badoo.ribs.core.plugin.ViewLifecycleAware | ||
|
||
@SuppressWarnings("LongParameterList") | ||
abstract class AbstractDebugControls<T : Rib> internal constructor( | ||
private val viewFactory: ((ViewGroup) -> View)? = null, | ||
private var viewGroupForChildren: (() -> ViewGroup)? = null, | ||
private var growthDirection: GrowthDirection? = null, | ||
private val nodeAware: NodeAware = NodeAwareImpl(), | ||
private val ribAware: RibAware<T> = RibAwareImpl() | ||
) : NodeAware by nodeAware, | ||
RibAware<T> by ribAware, | ||
ViewLifecycleAware { | ||
|
||
abstract val label: String | ||
private var container: ViewGroup? = null | ||
private var target: ViewGroup? = null | ||
protected var debugView: View? = null | ||
|
||
final override fun onAttachToView() { | ||
node.pluginUp<AbstractDebugControls<*>>()?.let { parent -> | ||
if (viewGroupForChildren == null) viewGroupForChildren = parent.viewGroupForChildren | ||
if (growthDirection == null) growthDirection = parent.growthDirection | ||
} | ||
|
||
target = viewGroupForChildren?.invoke() | ||
target?.let { target -> | ||
debugView = viewFactory?.invoke(target) | ||
debugView?.let { debugView -> | ||
container = target.inflate<ViewGroup>(R.layout.debug_controls_host).also { | ||
it.findViewById<TextView>(R.id.label)?.text = label | ||
it.findViewById<ViewGroup>(R.id.children_container).addView(debugView) | ||
} | ||
|
||
target.addView(container, if (growthDirection == GrowthDirection.TOP) 0 else -1) | ||
onDebugViewCreated(debugView) | ||
} | ||
} | ||
} | ||
|
||
final override fun onDetachFromView() { | ||
super.onDetachFromView() | ||
if (target != null) { | ||
debugView?.let { | ||
target?.removeView(container) | ||
onDebugViewDestroyed(it) | ||
} | ||
debugView = null | ||
target = null | ||
} | ||
} | ||
|
||
open fun onDebugViewCreated(debugView: View) {} | ||
|
||
open fun onDebugViewDestroyed(debugView: View) {} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ies/rib-debug-utils/src/main/java/com/badoo/ribs/core/plugin/utils/debug/DebugControls.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,12 @@ | ||
package com.badoo.ribs.core.plugin.utils.debug | ||
|
||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.badoo.ribs.core.Rib | ||
|
||
abstract class DebugControls<T : Rib>( | ||
override val label: String, | ||
viewFactory: ((ViewGroup) -> View) | ||
) : AbstractDebugControls<T>( | ||
viewFactory = viewFactory | ||
) |
36 changes: 36 additions & 0 deletions
36
...rib-debug-utils/src/main/java/com/badoo/ribs/core/plugin/utils/debug/DebugControlsHost.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,36 @@ | ||
package com.badoo.ribs.core.plugin.utils.debug | ||
|
||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import android.widget.Toast | ||
import com.badoo.mobile.rib.debugutils.R | ||
import com.badoo.ribs.core.Node | ||
import com.badoo.ribs.core.Rib | ||
import com.badoo.ribs.core.customisation.inflate | ||
import com.badoo.ribs.debug.TreePrinter | ||
|
||
class DebugControlsHost( | ||
viewGroupForChildren: (() -> ViewGroup), | ||
growthDirection: GrowthDirection = GrowthDirection.TOP, | ||
includeDefaultDebugTools: Boolean = true, | ||
private val defaultTreePrinterFormat: (Node<*>) -> String = TreePrinter.FORMAT_SIMPLE_INSTANCE | ||
) : AbstractDebugControls<Rib>( | ||
viewFactory = if (includeDefaultDebugTools) defaultDebugTools else null, | ||
viewGroupForChildren = viewGroupForChildren, | ||
growthDirection = growthDirection | ||
) { | ||
companion object { | ||
private val defaultDebugTools: ((ViewGroup) -> View) = { it.inflate(R.layout.debug_root) } | ||
} | ||
|
||
override val label: String = "Debug root" | ||
|
||
override fun onDebugViewCreated(debugView: View) { | ||
super.onDebugViewCreated(debugView) | ||
debugView.findViewById<Button>(R.id.debug_tree).setOnClickListener { | ||
TreePrinter.printNodeSubtree(node, defaultTreePrinterFormat) | ||
Toast.makeText(debugView.context, "Check logs", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...s/rib-debug-utils/src/main/java/com/badoo/ribs/core/plugin/utils/debug/GrowthDirection.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,5 @@ | ||
package com.badoo.ribs.core.plugin.utils.debug | ||
|
||
enum class GrowthDirection { | ||
TOP, BOTTOM | ||
} |
Oops, something went wrong.