Skip to content

Instantly share code, notes, and snippets.

@LAHomieJob
Created October 29, 2018 20:37
Show Gist options
  • Save LAHomieJob/d786355666795a8f58b8e7975d302e49 to your computer and use it in GitHub Desktop.
Save LAHomieJob/d786355666795a8f58b8e7975d302e49 to your computer and use it in GitHub Desktop.
Cicerone ask for help
package com.novgorod.quadroteka.presentation.chooseCallActivity.view
import android.content.Intent
import android.os.Bundle
import android.support.v4.view.GravityCompat
import android.support.v7.app.ActionBar
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.DividerItemDecoration
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.Toolbar
import android.view.MenuItem
import android.widget.ImageView
import android.widget.TextView
import com.arellomobile.mvp.presenter.InjectPresenter
import com.arellomobile.mvp.presenter.ProvidePresenter
import com.novgorod.quadroteka.R
import com.novgorod.quadroteka.di.DI
import com.novgorod.quadroteka.di.components.chooseCallActivity.ChooseCallActivityComponent
import com.novgorod.quadroteka.domain.model.PhoneCallPresentation
import com.novgorod.quadroteka.presentation.base.BaseActivity
import com.novgorod.quadroteka.presentation.chooseCallActivity.presentation.ChooseCallActivityPresenter
import com.novgorod.quadroteka.presentation.loginActivity.view.LoginActivity
import com.novgorod.quadroteka.presentation.navigation.ScreenKeys
import com.novgorod.quadroteka.util.CircleTransform
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.layout_choose_call.*
import ru.terrakok.cicerone.Navigator
import ru.terrakok.cicerone.commands.Command
import ru.terrakok.cicerone.commands.Forward
import ru.terrakok.cicerone.commands.Replace
import javax.inject.Inject
class ChooseCallActivity : BaseActivity(), ChooseCallActivityView {
companion object {
const val SELECTED_PHONE_PRESENTATION = "Selected phone presentation"
}
@Inject
@InjectPresenter
lateinit var presenter: ChooseCallActivityPresenter
private var component: ChooseCallActivityComponent? =
DI.componentManager().provideChooseCallActivityComponent()
lateinit var adapter: ChooseCallAdapter
lateinit var linearLayoutManager: LinearLayoutManager
@ProvidePresenter
fun providePresenter() = presenter
override fun onCreate(savedInstanceState: Bundle?) {
component?.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.layout_choose_call)
initToolbar()
initRecyclerViewWithCalls()
initNavigationDrawer()
}
private fun initRecyclerViewWithCalls() {
linearLayoutManager = LinearLayoutManager(applicationContext, LinearLayoutManager.VERTICAL, false)
list_calls.layoutManager = linearLayoutManager
val dividerItemDecoration = DividerItemDecoration(
this,
linearLayoutManager.orientation
)
list_calls.apply {
addItemDecoration(dividerItemDecoration)
itemAnimator = DefaultItemAnimator()
}
}
override fun onResume() {
super.onResume()
presenter.getListOfPhoneCalls()
}
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
android.R.id.home -> {
drawer_layout.openDrawer(GravityCompat.START)
true
}
else -> super.onOptionsItemSelected(item)
}
private fun initToolbar() {
val toolbar: Toolbar = findViewById(R.id.toolbar_choose_call)
setSupportActionBar(toolbar)
val actionbar: ActionBar? = supportActionBar
actionbar?.apply {
setDisplayHomeAsUpEnabled(true)
setHomeAsUpIndicator(R.drawable.ic_baseline_menu_24px)
title = getString(R.string.choose_call)
}
}
private fun initNavigationDrawer() {
nav_view.setNavigationItemSelectedListener { menuItem ->
when (menuItem.itemId) {
R.id.nav_exit -> presenter.leaveAuthorizedUser()
}
drawer_layout.closeDrawers()
true
}
val headerView = nav_view.getHeaderView(0)
val drawerImage = headerView.findViewById<ImageView>(R.id.imageViewUserName)
Picasso.get().load(R.drawable.user_demo).transform(CircleTransform()).into(drawerImage)
}
override fun setUserName(userName: String?) {
val headerView = nav_view.getHeaderView(0)
val textViewUserName = headerView.findViewById<TextView>(R.id.textViewUserName)
textViewUserName.text = userName
}
override fun showListOfCalls(list: List<PhoneCallPresentation>) {
adapter = ChooseCallAdapter({}, list)
list_calls.adapter = adapter
}
override val navigator: Navigator
get() = Navigator {
for (command in it) {
applyCommand(command)
}
}
private fun applyCommand(command: Command) {
if (command is Replace) {
when (command.screenKey) {
ScreenKeys.LOGIN_SCREEN -> {
val intent = Intent(
this@ChooseCallActivity,
LoginActivity::class.java
)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_TASK_ON_HOME
startActivity(intent)
finish()
}
}
}
if (command is Forward) {
when (command.screenKey) {
ScreenKeys.LOGIN_SCREEN -> {
val intent = Intent(
this@ChooseCallActivity,
LoginActivity::class.java
).apply {
//putExtra(SELECTED_PHONE_PRESENTATION, phoneCallRepresentation: Ph)
}
startActivity(intent)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment