Skip to content
This repository was archived by the owner on Feb 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #394 from squanchy-dev/SQ-332/convert_favourites_k…
Browse files Browse the repository at this point in the history
…otlin

SQ-332/Convert favourites to kotlin
  • Loading branch information
rock3r authored Nov 16, 2017
2 parents 2754354 + 20dc6ec commit f82cae7
Show file tree
Hide file tree
Showing 19 changed files with 445 additions and 525 deletions.
150 changes: 0 additions & 150 deletions app/src/main/java/net/squanchy/eventdetails/EventDetailsActivity.java

This file was deleted.

140 changes: 140 additions & 0 deletions app/src/main/java/net/squanchy/eventdetails/EventDetailsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package net.squanchy.eventdetails

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.activity_event_details.eventDetailsRoot
import kotlinx.android.synthetic.main.activity_event_details.toolbar
import net.squanchy.R
import net.squanchy.eventdetails.widget.EventDetailsCoordinatorLayout
import net.squanchy.navigation.Navigator
import net.squanchy.notification.NotificationsIntentService
import net.squanchy.schedule.domain.view.Event
import net.squanchy.speaker.domain.view.Speaker

class EventDetailsActivity : AppCompatActivity() {

private val subscriptions = CompositeDisposable()

private lateinit var service: EventDetailsService

private lateinit var navigator: Navigator
private lateinit var eventId: String

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_event_details)

setupToolbar()

with(eventDetailsComponent(this)) {
service = service()
navigator = navigator()
}
}

private fun setupToolbar() {
setSupportActionBar(toolbar)
supportActionBar!!.setDisplayShowTitleEnabled(false)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
}

override fun onStart() {
super.onStart()

eventId = intent.getStringExtra(EXTRA_EVENT_ID)

subscribeToEvent(eventId)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == REQUEST_CODE_SIGNIN) {
subscribeToEvent(eventId)
} else {
super.onActivityResult(requestCode, resultCode, data)
}
}

private fun subscribeToEvent(eventId: String) {
subscriptions.add(
service.event(eventId)
.observeOn(AndroidSchedulers.mainThread())
.subscribe { event -> eventDetailsRoot.updateWith(event, onEventDetailsClickListener(event)) }
)
}

private fun onEventDetailsClickListener(event: Event): EventDetailsCoordinatorLayout.OnEventDetailsClickListener =
object : EventDetailsCoordinatorLayout.OnEventDetailsClickListener {
override fun onSpeakerClicked(speaker: Speaker) {
navigator.toSpeakerDetails(speaker.id)
}

override fun onFavoriteClick() {
subscriptions.add(
service.toggleFavorite(event)
.subscribe { result ->
if (result === EventDetailsService.FavoriteResult.MUST_AUTHENTICATE) {
requestSignIn()
} else {
triggerNotificationService()
}
}
)
}
}

private fun requestSignIn() {
navigator.toSignInForResult(REQUEST_CODE_SIGNIN)
unsubscribeFromUpdates()
}

private fun triggerNotificationService() {
val serviceIntent = Intent(this, NotificationsIntentService::class.java)
startService(serviceIntent)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.event_details, menu)
return super.onCreateOptionsMenu(menu)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_search -> {
navigator.toSearch(); true
}
android.R.id.home -> {
finish(); true
}
else -> super.onOptionsItemSelected(item)
}
}

override fun onStop() {
super.onStop()

unsubscribeFromUpdates()
}

private fun unsubscribeFromUpdates() {
subscriptions.clear()
}

companion object {

private val EXTRA_EVENT_ID = EventDetailsActivity::class.java.canonicalName + ".event_id"
private const val REQUEST_CODE_SIGNIN = 1235

fun createIntent(context: Context, eventId: String): Intent {
return Intent(context, EventDetailsActivity::class.java).apply {
putExtra(EXTRA_EVENT_ID, eventId)
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.squanchy.eventdetails

import net.squanchy.injection.ActivityLifecycle
import net.squanchy.injection.ApplicationComponent
import net.squanchy.navigation.NavigationModule
import net.squanchy.navigation.Navigator

import dagger.Component
import net.squanchy.injection.ActivityContextModule
import net.squanchy.injection.ApplicationInjector

internal fun eventDetailsComponent(activity: EventDetailsActivity): EventDetailsComponent {
return DaggerEventDetailsComponent.builder()
.applicationComponent(ApplicationInjector.obtain(activity))
.eventDetailsModule(EventDetailsModule())
.activityContextModule(ActivityContextModule(activity))
.navigationModule(NavigationModule())
.build()
}

@ActivityLifecycle
@Component(modules = arrayOf(EventDetailsModule::class, NavigationModule::class), dependencies = arrayOf(ApplicationComponent::class))
internal interface EventDetailsComponent {

fun service(): EventDetailsService

fun navigator(): Navigator
}

This file was deleted.

This file was deleted.

16 changes: 16 additions & 0 deletions app/src/main/java/net/squanchy/eventdetails/EventDetailsModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.squanchy.eventdetails

import net.squanchy.service.firebase.FirebaseAuthService
import net.squanchy.service.repository.EventRepository

import dagger.Module
import dagger.Provides

@Module
internal class EventDetailsModule {

@Provides
fun eventDetailsService(eventRepository: EventRepository, authService: FirebaseAuthService): EventDetailsService {
return EventDetailsService(eventRepository, authService)
}
}
Loading

0 comments on commit f82cae7

Please sign in to comment.