This repository was archived by the owner on Feb 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #394 from squanchy-dev/SQ-332/convert_favourites_k…
…otlin SQ-332/Convert favourites to kotlin
- Loading branch information
Showing
19 changed files
with
445 additions
and
525 deletions.
There are no files selected for viewing
150 changes: 0 additions & 150 deletions
150
app/src/main/java/net/squanchy/eventdetails/EventDetailsActivity.java
This file was deleted.
Oops, something went wrong.
140 changes: 140 additions & 0 deletions
140
app/src/main/java/net/squanchy/eventdetails/EventDetailsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
app/src/main/java/net/squanchy/eventdetails/EventDetailsComponent.java
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
app/src/main/java/net/squanchy/eventdetails/EventDetailsComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
21 changes: 0 additions & 21 deletions
21
app/src/main/java/net/squanchy/eventdetails/EventDetailsInjector.java
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
app/src/main/java/net/squanchy/eventdetails/EventDetailsModule.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
app/src/main/java/net/squanchy/eventdetails/EventDetailsModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.