-
Notifications
You must be signed in to change notification settings - Fork 730
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
not for merge #1186
Open
eboudrant
wants to merge
2
commits into
airbnb:master
Choose a base branch
from
eboudrant:dsl_marker_experimention
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
not for merge #1186
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
150 changes: 150 additions & 0 deletions
150
kotlinsample/src/main/java/com/airbnb/epoxy/kotlinsample/MainController.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,150 @@ | ||
package com.airbnb.epoxy.kotlinsample | ||
|
||
import android.content.Intent | ||
import android.graphics.Color | ||
import android.util.Log | ||
import android.widget.Toast | ||
import com.airbnb.epoxy.EpoxyController | ||
import com.airbnb.epoxy.EpoxyModel | ||
import com.airbnb.epoxy.ModelCollector | ||
import com.airbnb.epoxy.group | ||
import com.airbnb.epoxy.kotlinsample.helpers.carouselNoSnapBuilder | ||
import com.airbnb.epoxy.kotlinsample.models.ItemDataClass | ||
import com.airbnb.epoxy.kotlinsample.models.ItemViewBindingDataClass | ||
import com.airbnb.epoxy.kotlinsample.models.carouselItemCustomView | ||
import com.airbnb.epoxy.kotlinsample.models.coloredSquareView | ||
import com.airbnb.epoxy.kotlinsample.models.decoratedLinearGroup | ||
import com.airbnb.epoxy.kotlinsample.models.itemCustomView | ||
import com.airbnb.epoxy.kotlinsample.models.itemEpoxyHolder | ||
import com.airbnb.epoxy.kotlinsample.models.itemViewBindingEpoxyHolder | ||
|
||
class MainController( | ||
private val mainActivity: MainActivity | ||
) : EpoxyController() { | ||
|
||
override fun buildModels() { | ||
group { | ||
id("epoxyModelGroupDsl") | ||
layout(R.layout.vertical_linear_group) | ||
|
||
coloredSquareView { | ||
id("coloredSquareView 1") | ||
color(Color.DKGRAY) | ||
onVisibilityStateChanged { model, _, visibilityState -> | ||
Log.d(TAG, "$model -> $visibilityState") | ||
} | ||
} | ||
|
||
coloredSquareView { | ||
id("coloredSquareView 2") | ||
color(Color.GRAY) | ||
} | ||
|
||
coloredSquareView { | ||
id("coloredSquareView 3") | ||
color(Color.LTGRAY) | ||
} | ||
|
||
carouselNoSnapBuilder { | ||
id("nested carousel") | ||
val lastPage = 10 | ||
for (i in 0 until lastPage) { | ||
carouselItemCustomView { | ||
id("nested carousel $i") | ||
title("Page $i / $lastPage") | ||
onVisibilityStateChanged { model, _, visibilityState -> | ||
[email protected](model, visibilityState, i) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
decoratedLinearGroup { | ||
id("epoxyModelGroupWithLayoutDsl") | ||
|
||
[email protected](Color.DKGRAY) | ||
[email protected](Color.GRAY) | ||
[email protected](Color.LTGRAY) | ||
} | ||
|
||
for (i in 0 until 100) { | ||
dataBindingItem { | ||
id("data binding $i") | ||
text("this is a data binding model2") | ||
onClick { _ -> | ||
Toast.makeText([email protected], "clicked", Toast.LENGTH_LONG).show() | ||
} | ||
onVisibilityStateChanged { model, _, visibilityState -> | ||
[email protected](model, visibilityState) | ||
} | ||
} | ||
|
||
itemCustomView { | ||
id("custom view $i") | ||
color(Color.GREEN) | ||
title("Open sticky header activity") | ||
listener { _ -> | ||
Toast.makeText([email protected], "clicked", Toast.LENGTH_LONG).show() | ||
[email protected](Intent([email protected], StickyHeaderActivity::class.java)) | ||
} | ||
} | ||
|
||
itemEpoxyHolder { | ||
id("view holder $i") | ||
title("this is a View Holder item") | ||
listener { | ||
Toast.makeText([email protected], "clicked", Toast.LENGTH_LONG) | ||
.show() | ||
} | ||
} | ||
|
||
itemViewBindingEpoxyHolder { | ||
id("view binding $i") | ||
title("This is a ViewBinding item") | ||
listener { | ||
Toast.makeText([email protected], "clicked", Toast.LENGTH_LONG) | ||
.show() | ||
} | ||
} | ||
|
||
carouselNoSnapBuilder { | ||
id("carousel $i") | ||
val lastPage = 10 | ||
for (j in 0 until lastPage) { | ||
carouselItemCustomView { | ||
id("carousel $i-$j") | ||
title("Page $j / $lastPage") | ||
} | ||
} | ||
} | ||
|
||
// Since data classes do not use code generation, there's no extension generated here | ||
ItemDataClass("this is a Data Class Item") | ||
.id("data class $i") | ||
.addTo(this) | ||
|
||
ItemViewBindingDataClass("This is a Data Class Item using ViewBinding") | ||
.id("data class view binding $i") | ||
.addTo(this) | ||
} | ||
} | ||
|
||
private fun ModelCollector.addColoredSquareView(color: Int) { | ||
coloredSquareView { | ||
id("coloredSquareView-$color") | ||
color(Color.DKGRAY) | ||
onVisibilityStateChanged { model, _, visibilityState -> | ||
[email protected](model, visibilityState) | ||
} | ||
} | ||
} | ||
|
||
private fun logVisibilityState(model: EpoxyModel<*>, visibilityState: Int, position: Int? = null) { | ||
Log.d(TAG, "$model -> $visibilityState position=$position") | ||
} | ||
|
||
companion object { | ||
private const val TAG = "MainController" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is here :
e: kotlinsample/src/main/java/com/airbnb/epoxy/kotlinsample/MainController.kt: (66, 33): 'fun ModelCollector.addColoredSquareView(color: Int): Unit' can't be called in this context by implicit receiver. Use the explicit one if necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will work with
but this is not ideal.