Open superdiazzz opened 3 years ago
Can you provide an example code that you use in the project?
Hi @rtugeek , sorry for my late response. This is how i use the library, i put it on my Viewholder item_adapter.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/parent_headline_endless"
android:animateLayoutChanges="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="@+id/ad_view_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</FrameLayout>
<!-- Headline -->
<FrameLayout
android:id="@+id/slide_parent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="visible"
app:layout_constraintDimensionRatio="w,5:8"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ad_view_container">
<com.freegeek.android.materialbanner.MaterialBanner
android:id="@+id/banner_slider"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" />
<com.rd.PageIndicatorView
android:id="@+id/page_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="@dimen/_16dp"
app:piv_animationType="drop"
app:piv_dynamicCount="true"
app:piv_interactiveAnimation="true"
app:piv_padding="@dimen/_4dp"
app:piv_radius="@dimen/_4dp"
app:piv_selectedColor="@color/colorWhite"
app:piv_unselectedColor="@color/colorGray" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/slide_parent">
<!-- Trending Tag -->
<HorizontalScrollView
android:id="@+id/horizontal_tag_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:visibility="visible">
<LinearLayout
android:id="@+id/layout_for_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:layout_margin="@dimen/_4dp">
<LinearLayout
android:id="@+id/layout_for_logo_and_weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="horizontal">
<include
android:id="@+id/headline_weather"
android:visibility="gone"
layout="@layout/item_weather" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
And my ViewHolder
class HeadlineEndlessViewHolder(itemView: View,
private val application: TribunNewsApplication,
private val activity: FragmentActivity,
private val ctx: Context,
private val kanal: String,
private val weather: Weather?,
private val imsakiyah: Imsakiyah?,
private val config: TribunConfig?,
private val dataPreference: DataPreference,
private val titleSize: Float
) : RecyclerView.ViewHolder(itemView), LifecycleObserver {
private lateinit var adView: AdManagerAdView
private val slider = itemView.findViewById<MaterialBanner<Any>>(R.id.banner_slider)
private val indicator = itemView.findViewById<PageIndicatorView>(R.id.page_indicator)
private val adContainer = itemView.findViewById<FrameLayout>(R.id.ad_view_container)
var pageExist : Boolean = false
private var initialLayoutComplete = false
fun bindItem(headline: Headline?) {
itemView.run {
activity.lifecycle.addObserver(this@HeadlineEndlessViewHolder)
headline?.let {
if(!headline.headline.isNullOrEmpty()){
val news = headline.headline[0]
val vpager = slider.viewPager
indicator.setViewPager(vpager)
val headlines = headline.headline
headlines?.let {
if(headlines.isNotEmpty()){
pageExist = true
slider.setPages(EditSimpleHolderCreator(kanal, titleSize), headlines)
slider.setOnPageChangeListener(object : ViewPager.OnPageChangeListener{
override fun onPageScrollStateChanged(state: Int) {}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
override fun onPageSelected(position: Int) {
indicator.setSelected(position)
}
})
}
}
-------------
}
}
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
fun connectPauseListener(){
Timber.d("LIFECYCLE HEADLINE PAUSE")
if(::adView.isInitialized){
adView.pause()
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun connectDestroyListener(){
Timber.d("LIFECYCLE HEADLINE DESTROY")
stopSlide()
if(::adView.isInitialized){
adView.destroy()
}
}
fun playSlide() {
slider.startTurning(4000)
}
fun stopSlide(){
slider.stopTurning()
}
}
I often got crash from internal library, however i can't handle it from outside. What make me so confused was i can't produce this crash. Please help me