forked from github/szkolny
[Architecture] Add base MVP classes
This commit is contained in:
parent
399ae7e3dc
commit
eb1984c6b5
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.base
|
||||
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
|
||||
abstract class BaseFragment<T : BasePresenter<out BaseView>> : Fragment(), BaseView {
|
||||
|
||||
abstract val presenter: T
|
||||
|
||||
override fun showMessage(text: String) {
|
||||
Toast.makeText(activity, text, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
presenter.onDetachView()
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.base
|
||||
|
||||
open class BasePresenter<T : BaseView> {
|
||||
|
||||
var view: T? = null
|
||||
|
||||
open fun onAttachView(view: T) {
|
||||
this.view = view
|
||||
}
|
||||
|
||||
open fun onDetachView() {
|
||||
view = null
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-4
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.ui.base
|
||||
|
||||
interface BaseView {
|
||||
|
||||
fun showMessage(text: String)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user