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
/** | |
* Created by nambv on 11/18/2020 | |
*/ | |
sealed class EventItemBook { | |
data class AddFavoriteBook(val book: Book) : EventItemBook() | |
data class RemoveFavoriteBook(val book: Book) : EventItemBook() | |
data class ActionOpenBook(val book: Book) : EventItemBook() | |
data class OpenMenuBook(val book: Book) : EventItemBook() |
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
/** | |
* Created by nambv on 11/18/2020 | |
*/ | |
class BookAdapter : RecyclerView.Adapter<BookAdapter.BookViewHolder>() { | |
//Define function type | |
var mEventItemBook: ((EventItemBook) -> Unit)? = null | |
/////Setup for BookAdapter///////// |
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
//Set mEventItemBook | |
private val mBookAdapter: BookAdapter by lazy { | |
BookAdapter().apply { | |
mEventItemBook = { handleEventItemListBook(it) } | |
} | |
} | |
//handleEvent | |
private fun handleEventItemListBook(eventItemBook: EventItemBook) { | |
Log.d("TODO", "event: $eventItemBook") |
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
private val mBookAdapter: BookAdapter by lazy { | |
BookAdapter().apply { | |
setListenerEventItemBook(object : EventItemBook { | |
override fun addFavoriteBook(book: Book) { | |
Log.d("TODO", "addFavoriteBook: ") | |
} | |
override fun removeFavoriteBook(book: Book) { | |
Log.d("TODO", "removeFavoriteBook: ") | |
} | |
override fun actionOpenBook(book: Book) { |
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
class BookAdapter : RecyclerView.Adapter<BookViewHolder() { | |
private var mEventItemBook: EventItemBook? = null | |
fun setListenerEventItemBook(eventItemBook: EventItemBook) { | |
this.mEventItemBook = eventItemBook | |
} | |
/////// | |
inner class BookViewHolder(): RecyclerView.ViewHolder(itemView) { | |
val mIconFavorite= itemView.findViewById(R.id.favorite) | |
init { | |
mIconFavorite.setOnClickListener { |
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
interface EventItemBook { | |
fun addFavoriteBook(book: Book) | |
fun removeFavoriteBook(book: Book) | |
fun actionOpenBook(book: Book) | |
fun openMenuBook(book: Book) | |
} |
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
class MainActivity : AppCompatActivity() { | |
lateinit var instanceA : ClassA | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
instanceA = ClassA() | |
} | |
override fun onResume() { | |
super.onResume() |
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
class ClassA { | |
var objectA = null | |
init { | |
objectA = getAFromFrameworkApi() | |
} | |
fun registerListenerAChange() { | |
objectA.registerStateChange() | |
} |
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
class MainActivity : AppCompatActivity() { | |
var objectA = null | |
override fun onCreate(savedInstanceState: Bundle?) { | |
//// | |
initObjectA() | |
} | |
override fun onResume() { | |
super.onResume() |
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
//Not use Scope Functions | |
fun updateTextView(parentView: View) { | |
val textView = parentView.findViewById<TextView>(R.id.text_view) | |
if (textView != null) { | |
textView.text = "nambv" | |
textView.setTextColor(Color.RED) | |
textView.textSize = 15f | |
textView.maxLines = 1 | |
textView.gravity = Gravity.CENTER | |
} |
NewerOlder