Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/detail screen #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".scenes.employeedetail.EmployeeDetailActivity"
android:configChanges="orientation|screenSize|screenLayout"
android:label="@string/app_name" />
<activity
android:name=".scenes.maindirectory.MainDirectoryActivity"
android:configChanges="orientation|screenSize|screenLayout">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.treyherman.employeedirectory

import com.treyherman.employeedirectory.di.scope.ActivityScope
import com.treyherman.employeedirectory.scenes.employeedetail.EmployeeDetailActivity
import com.treyherman.employeedirectory.scenes.employeedetail.EmployeeDetailModule
import com.treyherman.employeedirectory.scenes.maindirectory.MainDirectoryActivity
import com.treyherman.employeedirectory.scenes.maindirectory.MainDirectoryModule
import dagger.Module
Expand All @@ -12,4 +14,8 @@ interface InjectorModule {
@ActivityScope
@ContributesAndroidInjector(modules = [MainDirectoryModule::class])
fun contributesMainDirectoryActivity(): MainDirectoryActivity

@ActivityScope
@ContributesAndroidInjector(modules = [EmployeeDetailModule::class])
fun contributesEmployeeDetailActivity(): EmployeeDetailActivity
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.treyherman.employeedirectory.extension

import android.content.Intent
import android.net.Uri

private const val TEL_INTENT = "tel: %s"

fun createPhoneIntent(phoneNumber: String): Intent = Intent(
Intent.ACTION_DIAL, Uri.parse(
String.format(
TEL_INTENT, phoneNumber
)
)
)

//fun createEmailIntent(email: String): Intent = Intent(
// Intent.ACTION_SENDTO, Uri.fromParts("mailto", email, null)
//
//)
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.treyherman.employeedirectory.scenes.employeedetail

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View

import androidx.appcompat.app.AppCompatActivity
import coil.ImageLoader
import coil.load
import com.jakewharton.rxbinding3.view.clicks
import com.treyherman.employeedirectory.R
import com.treyherman.employeedirectory.extension.createPhoneIntent
import com.treyherman.employeedirectory.scenes.maindirectory.model.UIEmployee

import dagger.android.AndroidInjection
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import kotlinx.android.synthetic.main.activity_employee_detail.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject

class EmployeeDetailActivity : AppCompatActivity(), EmployeeDetailMvp.View {

companion object {
const val KEY_EMPLOYEE_PARCELABLE = "employee"

fun createIntent(context: Context, employee: UIEmployee): Intent =
Intent(context, EmployeeDetailActivity::class.java)
.putExtra(KEY_EMPLOYEE_PARCELABLE, employee)
}

@Inject
lateinit var presenter: EmployeeDetailMvp.Presenter

@Inject
lateinit var imageLoader: ImageLoader

private val disposables = CompositeDisposable()

override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_employee_detail)
setupView()
presenter.onCreate(intent.extras)
}

override fun onDestroy() {
disposables.dispose()
super.onDestroy()
}

override fun displayEmployee(employee: UIEmployee) {
ivEmployee.load(employee.photoUrlLarge, imageLoader) {
placeholder(R.drawable.ic_profile_placeholder)
}
tvNameAndTeam.text = employee.nameAndTeam
employee.phoneNumber?.let {
tvPhoneNumber.text = it
tvPhoneNumber.visibility = View.VISIBLE
btCall.visibility = View.VISIBLE
} ?: run {
tvPhoneNumber.visibility = View.GONE
btCall.visibility = View.GONE
}

tvEmail.text = employee.email

employee.phoneNumber?.let {
tvBio.text = it
tvBio.visibility = View.VISIBLE
} ?: run { tvBio.visibility = View.GONE }

tvClassification.text = employee.classification
}

override fun displayNonCancelableErrorDialog(message: String) {

}

override fun openDialScreen(phoneNumber: String) {
startActivity(createPhoneIntent(phoneNumber))
}

override fun openEmailScreen(email: String) {
TODO("Not yet implemented")
}

// region private
private fun setupView() {
subscribeToCallClickEvent()
subscribeToEmailClickEvent()
}

private fun subscribeToCallClickEvent() {
btCall.clicks()
.debounce(300L, TimeUnit.MILLISECONDS)
.subscribe {
presenter.onCallClicked()
}.addTo(disposables)
}

private fun subscribeToEmailClickEvent() {
btEmail.clicks()
.debounce(300L, TimeUnit.MILLISECONDS)
.subscribe {
presenter.onEmailClicked()
}.addTo(disposables)
}
// endregion private
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.treyherman.employeedirectory.scenes.employeedetail

import com.treyherman.employeedirectory.di.scope.ActivityScope

import dagger.Binds
import dagger.Module

@Module
interface EmployeeDetailBindModule {

@Binds
@ActivityScope
fun bindView(activity: EmployeeDetailActivity): EmployeeDetailMvp.View
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.treyherman.employeedirectory.scenes.employeedetail

import android.content.Context
import coil.ImageLoader
import com.treyherman.employeedirectory.di.scope.ActivityScope
import com.treyherman.employeedirectory.view.image.ImageLoaderProvider
import dagger.Module
import dagger.Provides

@Module(includes = [EmployeeDetailBindModule::class])
class EmployeeDetailModule {

@Provides
@ActivityScope
fun providePresenter(presenter: EmployeeDetailPresenter): EmployeeDetailMvp.Presenter {
return presenter
}

@Provides
@ActivityScope
fun provideImageLoader(
imageLoaderProvider: ImageLoaderProvider,
context: Context
): ImageLoader {
return imageLoaderProvider.provide(context)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.treyherman.employeedirectory.scenes.employeedetail

import android.os.Bundle
import com.treyherman.employeedirectory.scenes.maindirectory.model.UIEmployee


interface EmployeeDetailMvp {
interface View {
fun displayEmployee(employee: UIEmployee)

fun displayNonCancelableErrorDialog(message: String)

fun finish()

fun openDialScreen(phoneNumber: String)

fun openEmailScreen(email: String)
}

interface Presenter {
fun onCreate(extras: Bundle?)

fun onNonCancelableErrorDialogDismissed()

fun onCallClicked()

fun onEmailClicked()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.treyherman.employeedirectory.scenes.employeedetail

import android.content.res.Resources
import android.os.Bundle
import com.treyherman.employeedirectory.R
import com.treyherman.employeedirectory.di.scope.ActivityScope
import com.treyherman.employeedirectory.scenes.employeedetail.EmployeeDetailActivity.Companion.KEY_EMPLOYEE_PARCELABLE
import com.treyherman.employeedirectory.scenes.maindirectory.model.UIEmployee
import javax.inject.Inject

@ActivityScope
class EmployeeDetailPresenter @Inject constructor(
private val view: EmployeeDetailMvp.View,
private val resources: Resources
) : EmployeeDetailMvp.Presenter {

private lateinit var employee: UIEmployee

override fun onCreate(extras: Bundle?) {
extras?.getParcelable<UIEmployee>(KEY_EMPLOYEE_PARCELABLE)?.let {
employee = it
when (it.isValid()) {
true -> view.displayEmployee(it)
false -> view.displayNonCancelableErrorDialog(resources.getString(R.string.something_went_wrong))
}
}
?: view.displayNonCancelableErrorDialog(resources.getString(R.string.something_went_wrong))
}

override fun onNonCancelableErrorDialogDismissed() {
view.finish()
}

override fun onCallClicked() {
employee.phoneNumber?.let {
view.openDialScreen(it)
}
}

override fun onEmailClicked() {
view.openEmailScreen(employee.email)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.jakewharton.rxbinding3.swiperefreshlayout.refreshes
import com.jakewharton.rxbinding3.view.clicks
import com.jakewharton.rxbinding3.widget.itemSelections
import com.treyherman.employeedirectory.R
import com.treyherman.employeedirectory.scenes.employeedetail.EmployeeDetailActivity
import com.treyherman.employeedirectory.scenes.maindirectory.list.EmployeeAdapter
import com.treyherman.employeedirectory.scenes.maindirectory.list.employee.EmployeeSubcomponent
import com.treyherman.employeedirectory.scenes.maindirectory.model.DataSelectionType
Expand Down Expand Up @@ -99,6 +100,10 @@ class MainDirectoryActivity : AppCompatActivity(), MainDirectoryMvp.View {
vRefresh.isRefreshing = false
}

override fun openEmployeeDetails(employee: UIEmployee) {
startActivity(EmployeeDetailActivity.createIntent(this, employee))
}

// region private
private fun setupView() {
rvEmployees.adapter = rvAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ interface MainDirectoryMvp {
fun hideLoading()

fun displayEmptyContent(message: String)

fun openEmployeeDetails(employee: UIEmployee)
}

interface Presenter {
Expand All @@ -27,5 +29,7 @@ interface MainDirectoryMvp {
fun onTryAgainClicked(dataSelection: DataSelectionType, currentEmployees: List<UIEmployee>)

fun onDataTypeSelected(dataSelection: DataSelectionType, currentEmployees: List<UIEmployee>)

fun presentEmployeeDetails(employee: UIEmployee)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class MainDirectoryPresenter @Inject constructor(
}
}

override fun presentEmployeeDetails(employee: UIEmployee) {
view.openEmployeeDetails(employee)
}

// region private
private fun subscribeToRefreshedDefaultEmployees(currentEmployees: List<UIEmployee>) {
employeesDisposable?.dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ interface EmployeeMvp {

interface Presenter {
fun onBind(employee: UIEmployee)

fun onEmployeeClicked()
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package com.treyherman.employeedirectory.scenes.maindirectory.list.employee

import com.treyherman.employeedirectory.di.scope.ViewScope
import com.treyherman.employeedirectory.scenes.maindirectory.MainDirectoryMvp
import com.treyherman.employeedirectory.scenes.maindirectory.model.UIEmployee
import javax.inject.Inject

@ViewScope
class EmployeePresenter @Inject constructor(
private val view: EmployeeMvp.View
private val view: EmployeeMvp.View,
private val parentPresenter: MainDirectoryMvp.Presenter
) : EmployeeMvp.Presenter {

private lateinit var employee: UIEmployee

override fun onBind(employee: UIEmployee) {
this.employee = employee
view.displayEmployeeInfo(
employee.nameAndTeam,
employee.email,
employee.classification,
employee.photoUrl
employee.photoUrlSmall
)

employee.phoneNumber?.let {
Expand All @@ -24,4 +30,8 @@ class EmployeePresenter @Inject constructor(
view.displayBio(it)
} ?: view.hideBio()
}

override fun onEmployeeClicked() {
parentPresenter.presentEmployeeDetails(employee)
}
}
Loading