Closed Merka84 closed 5 years ago
Can anyone provide some suggestion?
it looks like your problem is this
@ModelView(defaultLayout = R.layout.test_layout)
class CustomImageSlider
The layout you provide to the @ModelView annotation must have a top level component of CustomImageSlider
Also, I would not recommend using @Automodel - just use kotlin and manually specify the id, this is mentioned in the wiki.
Lastly, I would be wary of setting up your custom Image slider with a viewpager as you have. There are a host of issues with that that Epoxy's provided Carousel is designed to automatically solve. For one thing, your EpoxyImageSliderModel does not clear anything on unbind.
If you need snapping behavior of a Viewpager that can be achieved with custom SnapHelper logic
Actually I was trying to use the suggested approach that you were provided for this issue for my problem. I tried it without the @ModelView
annotation first (as it was in here) and since it throws exception, I tried to fix it by adding @ModelView
and then by adding @Automodel
.
In the time I was waiting for suggestion I tried many different variations including using CustomImageSlider
as top view in the layout file (that you suggested above) and still same error.
I wanted the ViewPager behaviour and I achieved it with SnapHelper. Although as I need autoscroll behaviour in my slider, having it with a custom ViewPager could make its implementation easier. My problem with this costume model is not resolved but as I am not using this approach, I close the issue.
FYI you can setup auto scrolling for a recyclerview pretty easy with something like this
class AutoScrollingController(private val target: Target) {
private val automationHandler: Handler by lazy { Handler(Looper.getMainLooper()) }
private var itemIndex: Int = 0
var isRunning: Boolean = false
private set
var isCancelled: Boolean = false
private set
interface Target {
/**
* Scroll to the given position.
* @return true if the scroll was successful, false if no more attempts should be made.
*/
fun scrollToPosition(position: Int): Boolean
}
/**
* Starts auto scrolling, if it hasn't already been started. Scrolling continues until it is canceled. Once [MAX_SCROLL_COUNT] images are
* scrolled to this loops back to the first image and continues anew.
*/
fun start() {
if (isRunning || ANIMATIONS_DISABLED) {
return
}
isCancelled = false
isRunning = true
automationHandler.postDelayed(object : Runnable {
override fun run() {
itemIndex++
// Auto scrolling can be cancelled during the target callback
if (target.scrollToPosition(itemIndex % MAX_SCROLL_COUNT) && !isCancelled) {
automationHandler.postDelayed(this, CYCLE_DELAY_MS)
} else {
cancel()
}
}
}, START_DELAY_MS)
}
fun cancel() {
isCancelled = true
isRunning = false
automationHandler.removeCallbacksAndMessages(null)
}
}
@elihart How can I apply this AutoScrollingController
to RecyclerView?
I am using a custom view to create imageSlider and I receive this error:
android.widget.FrameLayout cannot be cast to PACKAGE_NAME.epoxy.CustomImageSlider
Here is my code: layout file:
test_layout.xml
Custom View class:
Epoxy Model:
Epoxy Controller (I have coded this class in java, as I couldn't use
@AutoModel
in my controller class when I wrote it in kotlin, it threwAutoModel annotations must not be on private or static fields
even though the field was public and non static)The
AdapterSliderItemBindingModel_
epoxy model is generated from layout file with databinding, and I have used it inEpoxyImageSliderModel
I get this error :
android.widget.FrameLayout cannot be cast to PACKAGE_NAME.epoxy.CustomImageSlider
. I have checked similar issues and I used@AutoModel
to generateid
s for models, also I have setid
s in controller before adding the model to controller but it didn't help.Here is the complete stack trace for error:
@elihart Can you please have a look and give some insight on this error?