This file contains hidden or 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
object ViewBindingAdapter { | |
@BindingAdapter("visibilityGone") | |
@JvmStatic | |
fun visibilityGone(view: View, isShouldGone: Boolean) { | |
if (isShouldGone) { | |
view.visibility = View.GONE | |
} else { | |
view.visibility = View.VISIBLE | |
} | |
} |
This file contains hidden or 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
class MainActivity : AppCompatActivity() { | |
lateinit var binding: ActivityMainBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = DataBindingUtil.setContentView(this, R.layout.activity_main) | |
binding.buttonContinue.setOnClickListener { | |
binding.name = Random.nextInt(100).toString() | |
} |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | |
<data> | |
<variable | |
name="name" | |
type="String" /> | |
</data> | |
<LinearLayout |
This file contains hidden or 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
class MainActivity : AppCompatActivity() { | |
lateinit var binding: ActivityMainBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = DataBindingUtil.setContentView(this, R.layout.activity_main) | |
} | |
} |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> | |
... |
This file contains hidden or 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
class WithoutHolderActivity : AppCompatActivity() { | |
private val adapter = GenericAdapter(Utils.getFeedItems()) | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_without_holder) | |
initAdapter() | |
initRV() | |
} |
This file contains hidden or 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
//If you dont want to use GenericAdapter | |
class FeedAdapter(var items: List<FeedItem>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { | |
private val delegateManager = AdapterDelegateManager<FeedItem>() | |
init { | |
delegateManager.run { | |
addDelegate(FeedPostAdapterDelegate()) | |
addDelegate(FeedStandardAdapterDelegate()) | |
addDelegate(FeedStoryAdapterDelegate()) |
This file contains hidden or 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
class FeedStoryAdapterDelegate : AdapterDelegate<FeedItem> { | |
override fun isForViewType(items: List<FeedItem>, position: Int): Boolean { | |
return items[position] is FeedStoryItem | |
} | |
override fun onCreateViewHolder(parent: ViewGroup): RecyclerView.ViewHolder { | |
return ItemStoryViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.feed_story_item, parent, false)) | |
} | |
override fun onBindViewHolder(items: List<FeedItem>, position: Int, holder: RecyclerView.ViewHolder) { |
This file contains hidden or 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
class FeedStandardAdapterDelegate : AdapterDelegate<FeedItem> { | |
override fun isForViewType(items: List<FeedItem>, position: Int): Boolean { | |
return items[position] is FeedStandardItem | |
} | |
override fun onCreateViewHolder(parent: ViewGroup): RecyclerView.ViewHolder { | |
return ItemStandardViewHolder( | |
LayoutInflater.from(parent.context).inflate(R.layout.feed_standard_item, parent, false) | |
) | |
} |
This file contains hidden or 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
class FeedPostAdapterDelegate : AdapterDelegate<FeedItem> { | |
override fun isForViewType(items: List<FeedItem>, position: Int): Boolean { | |
return items[position] is FeedPostItem | |
} | |
override fun onCreateViewHolder(parent: ViewGroup): RecyclerView.ViewHolder { | |
return ItemPostViewHolder( | |
LayoutInflater.from(parent.context).inflate(R.layout.feed_post_item, parent, false) | |
) | |
} |