Skip to content

Instantly share code, notes, and snippets.

@andreymusth
Created May 26, 2020 07:49
Show Gist options
  • Save andreymusth/69f0e6362f20e8a741e547138518db78 to your computer and use it in GitHub Desktop.
Save andreymusth/69f0e6362f20e8a741e547138518db78 to your computer and use it in GitHub Desktop.
class UserProfileActivity : AppCompatActivity(), View.OnClickListener, UserProfileView {
private val presenter: UserProfilePresenter = UserProfilePresenterImpl(this)
@Inject
lateinit var api: CardInfoApi
override fun onCreate(savedInstanceState: Bundle?) {
App.component.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val nameTextView = findViewById<TextView>(R.id.name_text)
val user = presenter.getUser()
nameTextView.text = user.name
findViewById<Button>(R.id.log_out_button).setOnClickListener(this)
val requestCardInformationButton = findViewById<Button>(R.id.card_information_button)
requestCardInformationButton.setOnClickListener {
api.getCardInfoById(user.id)
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
showInfoDialog(it.info)
},
{}
)
}
}
fun showInfoDialog(info: String) {
// some irrelevant code
}
override fun onClick(v: View?) {
if (v?.id == R.id.log_out_button) {
presenter.onLogoutClicked()
}
}
override fun showConfirmLogoutDialog() {
showLogoutDialog(confirmAction = {
presenter.onLogoutConfirmed()
finish()
})
}
private fun showLogoutDialog(confirmAction: (() -> Unit)? = null) {
// some irrelevant code
}
}
interface UserProfileView {
fun showConfirmLogoutDialog()
}
interface UserProfilePresenter {
fun onLogoutClicked()
fun onLogoutConfirmed()
fun getUser(): User
}
interface CardInfoApi {
fun getCardInfoById(id: String): Observable<CardInfo>
}
class User(
val id: String,
val name: String
)
data class CardInfo(
val info: String
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment