//главный экран
class MainFragment : Fragment(),IItemClickListener {
override fun onActivityCreated(savedInstanceState: Bundle?) {
mAdapter = MyAdapter(mIItemClickListener = this)
}
}
override fun onItemLongClick(position: Int) {
val dialog = AlertDialog.Builder(requireContext())
dialog.setMessage(R.string.sure_delete)
dialog.setPositiveButton("Да",DialogInterface.OnClickListener { dialog, which ->
val id:Int=mAdapter.list[position].id
coroutine_delete.launch {
mViewModel.deleteAllInfoByPersonId(id)
}
dialog.cancel()
})
dialog.setNegativeButton("Нет", DialogInterface.OnClickListener { dialog, which -> dialog.cancel()})
dialog.show()
}
//Адаптер
class MyAdapter(
var list:ArrayList<Person> = ArrayList<Person>(),
val mIItemClickListener: IItemClickListener
):RecyclerView.Adapter<MyAdapter.ViewHolder>() {
inner class ViewHolder(item:View):RecyclerView.ViewHolder(item),View.OnClickListener,View.OnLongClickListener {
init {
setOnClickListeners()
}
override fun onClick(v: View?) {
mIItemClickListener.onItemClick(adapterPosition)
}
private fun setOnClickListeners(){
itemView.setOnClickListener(this)
itemView.setOnLongClickListener(this)
}
override fun onLongClick(v: View?): Boolean {
mIItemClickListener.onItemLongClick(adapterPosition)
return true
}
}
val flowable = Flowable.range(0,10000)
.onBackpressureBuffer(1,{},BackpressureOverflowStrategy.DROP_OLDEST)
.observeOn(Schedulers.computation()).subscribe{
Log.e("@",it.toString())
}
flovable
.onBackpressureBuffer(10)
.subscribe{
Thread.sleep(10000L)
Log.e("@@@@@",it.toString())
}
val flovable = Flowable.create(FlowableOnSubscribe<Int> {
for(a in 1..10000){
it.onNext(a)
}
},BackpressureStrategy.ERROR)
findNavController().navigate(R.id.action_FragmentA_to_FragmentB,bundle)
class MainActivity : AppCompatActivity() {
lateinit var navController:NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
navController= Navigation.findNavController(this,R.id.fragment)
NavigationUI.setupActionBarWithNavController(this,navController)
}
override fun onSupportNavigateUp(): Boolean {
return navController.navigateUp()
}
}