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

Commit

Permalink
Merge pull request #424 from squanchy-dev/more_minor_improvement
Browse files Browse the repository at this point in the history
More minor improvement
  • Loading branch information
rock3r committed Jan 13, 2018
2 parents 30e4a40 + 64bf645 commit 56fdc91
Show file tree
Hide file tree
Showing 25 changed files with 189 additions and 187 deletions.
Expand Up @@ -12,7 +12,7 @@ import com.google.firebase.storage.StorageReference
class GlideImageLoader(private val requestManager: RequestManager, private val firebaseStorage: FirebaseStorage) : ImageLoader {

companion object {
val FIREBASE_URL_SCHEMA = "gs://"
const val FIREBASE_URL_SCHEMA = "gs://"
}

override fun load(url: String): ImageRequest {
Expand Down
Expand Up @@ -18,5 +18,5 @@ internal class ImageLoaderModule {

@Provides
fun imageLoader(requestManager: RequestManager, firebaseStorage: FirebaseStorage): ImageLoader =
GlideImageLoader(requestManager, firebaseStorage)
GlideImageLoader(requestManager, firebaseStorage)
}
14 changes: 7 additions & 7 deletions app/src/main/java/net/squanchy/injection/ApplicationComponent.kt
Expand Up @@ -30,13 +30,13 @@ fun createApplicationComponent(application: Application): ApplicationComponent {
@ApplicationLifecycle
@Component(
modules = [
ApplicationContextModule::class,
FirebaseModule::class,
ChecksumModule::class,
RepositoryModule::class,
AnalyticsModule::class,
RemoteConfigModule::class,
CurrentTimeModule::class
ApplicationContextModule::class,
FirebaseModule::class,
ChecksumModule::class,
RepositoryModule::class,
AnalyticsModule::class,
RemoteConfigModule::class,
CurrentTimeModule::class
]
)
interface ApplicationComponent {
Expand Down
Expand Up @@ -8,8 +8,8 @@ internal class FirstStartPersister(private val preferences: SharedPreferences) {

fun storeHasBeenStarted() {
preferences.edit()
.putBoolean(KEY_HAS_BEEN_STARTED_ALREADY, true)
.apply()
.putBoolean(KEY_HAS_BEEN_STARTED_ALREADY, true)
.apply()
}

companion object {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/net/squanchy/navigation/Navigator.kt
Expand Up @@ -70,9 +70,9 @@ class Navigator(
}

private fun canResolve(intent: Intent) =
!activity.packageManager
.queryIntentActivities(intent, 0)
.isEmpty()
!activity.packageManager
.queryIntentActivities(intent, 0)
.isEmpty()

fun toMapsFor(venue: Venue) {
toExternalUrl("http://maps.google.com/?daddr=${Uri.encode(venue.name)},${Uri.encode(venue.address)}")
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/net/squanchy/navigation/RoutingActivity.kt
Expand Up @@ -38,7 +38,7 @@ class RoutingActivity : AppCompatActivity() {

subscriptions.add(
signInService.signInAnonymouslyIfNecessary()
.subscribe({ this.onboardOrProceedToRouting() }, { this.handleSignInError(it) })
.subscribe({ onboardOrProceedToRouting() }, { handleSignInError(it) })
)
}

Expand All @@ -57,10 +57,10 @@ class RoutingActivity : AppCompatActivity() {
}

private fun createContinueIntentFrom(intent: Intent) =
Intent(intent).apply {
removeCategory(Intent.CATEGORY_LAUNCHER)
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
Intent(intent).apply {
removeCategory(Intent.CATEGORY_LAUNCHER)
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
Expand All @@ -78,7 +78,7 @@ class RoutingActivity : AppCompatActivity() {

private fun onboardOrProceedToRouting() {
onboarding.nextPageToShow()
?.let { navigator.toOnboardingForResult(it, ONBOARDING_REQUEST_CODE) }
?.let { navigator.toOnboardingForResult(it, ONBOARDING_REQUEST_CODE) }
?: proceedTo(intent)
}

Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/net/squanchy/navigation/RoutingComponent.kt
Expand Up @@ -15,13 +15,13 @@ import net.squanchy.signin.SignInService

internal fun routingComponent(activity: AppCompatActivity) =
DaggerRoutingComponent.builder()
.activityContextModule(ActivityContextModule(activity))
.applicationComponent(activity.applicationComponent)
.deepLinkModule(DeepLinkModule())
.navigationModule(NavigationModule())
.signInModule(SignInModule())
.routingModule(RoutingModule())
.build()
.activityContextModule(ActivityContextModule(activity))
.applicationComponent(activity.applicationComponent)
.deepLinkModule(DeepLinkModule())
.navigationModule(NavigationModule())
.signInModule(SignInModule())
.routingModule(RoutingModule())
.build()

@ActivityLifecycle
@Component(
Expand Down
Expand Up @@ -42,7 +42,7 @@ internal class DeepLinkNavigator(private val navigator: Navigator) {

private fun extractSegments(path: String): List<String> {
return path.split("/".toRegex())
.filterNot { it.isEmpty() }
.filterNot { it.isEmpty() }
}

fun toFavorites() {
Expand Down
Expand Up @@ -42,7 +42,7 @@ class FirstStartWithNoNetworkActivity : AppCompatActivity() {
setContentView(R.layout.activity_first_start_with_no_network)

DialogLayoutParameters.wrapHeight(this)
.applyTo(window)
.applyTo(window)

firstStartNevermind.setOnClickListener { finish() }

Expand All @@ -57,8 +57,8 @@ class FirstStartWithNoNetworkActivity : AppCompatActivity() {
super.onStart()

val networkRequest = NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.build()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.build()
connectivityManager.registerNetworkCallback(networkRequest, networkCallback)

doIfAnimatedVectorDrawable(firstStartProgress.drawable) { start() }
Expand All @@ -80,7 +80,7 @@ class FirstStartWithNoNetworkActivity : AppCompatActivity() {
firstStartCta.setText(R.string.first_start_with_no_network_network_connected)

animate(firstStartProgress, popOut()) { this.swapProgressWithSuccessAndContinue() }
.start()
.start()
}

private fun popOut(): (View) -> Animator = {
Expand All @@ -96,7 +96,7 @@ class FirstStartWithNoNetworkActivity : AppCompatActivity() {
firstStartProgress.setImageResource(R.drawable.ic_circle_tick)

animate(firstStartProgress, popBackIn()) { this.continueToScheduleAfterDelay() }
.start()
.start()
}

private fun popBackIn(): (View) -> Animator = {
Expand Down Expand Up @@ -131,17 +131,21 @@ class FirstStartWithNoNetworkActivity : AppCompatActivity() {

private fun animate(view: View, animationProducer: (View) -> Animator, endAction: () -> Unit): Animator {
val animator = animationProducer.invoke(view)
animator.addListener(object : AnimationEndListener {
override fun onAnimationEnd(animation: Animator) = endAction.invoke()
})
animator.addListener(
object : AnimationEndListener {
override fun onAnimationEnd(animation: Animator) = endAction()
}
)
return animator
}

private fun continueToScheduleAfterDelay() {
firstStartProgress.postDelayed({
startActivity(continuationIntent) // We don't use the navigator here, we basically want to restart the whole flow
finish()
}, DELAY_AFTER_ANIMATIONS_MILLIS)
firstStartProgress.postDelayed(
{
startActivity(continuationIntent) // We don't use the navigator here, we basically want to restart the whole flow
finish()
}, DELAY_AFTER_ANIMATIONS_MILLIS
)
}

private inner class NetworkConnectedCallback : ConnectivityManager.NetworkCallback() {
Expand Down Expand Up @@ -180,8 +184,8 @@ class FirstStartWithNoNetworkActivity : AppCompatActivity() {
private const val DELAY_AFTER_ANIMATIONS_MILLIS: Long = 700

fun createIntentContinuingTo(context: Context, continuationIntent: Intent) =
Intent(context, FirstStartWithNoNetworkActivity::class.java).apply {
putExtra(EXTRA_CONTINUATION_INTENT, continuationIntent)
}
Intent(context, FirstStartWithNoNetworkActivity::class.java).apply {
putExtra(EXTRA_CONTINUATION_INTENT, continuationIntent)
}
}
}
Expand Up @@ -11,9 +11,9 @@ import net.squanchy.injection.applicationComponent

internal fun notificationComponent(service: Service): NotificationComponent {
return DaggerNotificationComponent.builder()
.applicationComponent(service.applicationComponent)
.serviceContextModule(ServiceContextModule(service))
.build()
.applicationComponent(service.applicationComponent)
.serviceContextModule(ServiceContextModule(service))
.build()
}

@ActivityLifecycle
Expand Down
94 changes: 48 additions & 46 deletions app/src/main/java/net/squanchy/notification/NotificationCreator.kt
Expand Up @@ -28,8 +28,8 @@ class NotificationCreator(private val context: Context) {
}

val notifications = events
.map { createFrom(it) }
.toMutableList()
.map { createFrom(it) }
.toMutableList()

if (events.size > 1) {
notifications.add(createSummaryNotification(events))
Expand All @@ -55,12 +55,12 @@ class NotificationCreator(private val context: Context) {
private fun createFrom(event: Event): Notification {
val notificationBuilder = createDefaultBuilder(1)
notificationBuilder
.setContentIntent(createPendingIntentForSingleEvent(event.id))
.setContentTitle(event.title)
.setColor(getTrackColor(event))
.setWhen(event.startTime.toDateTime().millis)
.setShowWhen(true)
.setGroup(GROUP_KEY_NOTIFY_SESSION)
.setContentIntent(createPendingIntentForSingleEvent(event.id))
.setContentTitle(event.title)
.setColor(getTrackColor(event))
.setWhen(event.startTime.toDateTime().millis)
.setShowWhen(true)
.setGroup(GROUP_KEY_NOTIFY_SESSION)

val placeName = getPlaceName(event)
if (!placeName.isNullOrEmpty()) {
Expand All @@ -75,11 +75,11 @@ class NotificationCreator(private val context: Context) {
private fun createSummaryNotification(events: List<Event>): Notification {
val summaryBuilder = createDefaultBuilder(events.size)
summaryBuilder
.setContentIntent(createPendingIntentForMultipleEvents())
.setContentTitle(createSummaryTitle(events.size))
.setGroup(GROUP_KEY_NOTIFY_SESSION)
.setGroupSummary(true)
.setLocalOnly(true)
.setContentIntent(createPendingIntentForMultipleEvents())
.setContentTitle(createSummaryTitle(events.size))
.setGroup(GROUP_KEY_NOTIFY_SESSION)
.setGroupSummary(true)
.setLocalOnly(true)

val richNotification = createInboxStyleRichNotification(summaryBuilder, events)

Expand All @@ -93,22 +93,22 @@ class NotificationCreator(private val context: Context) {
extender.background = BitmapFactory.decodeResource(resources, R.drawable.notification_background)

return NotificationCompat.Builder(context, EVENTS_ABOUT_TO_START_CHANNEL_ID)
.setTicker(
context.resources.getQuantityString(
R.plurals.event_notification_ticker,
talksCount,
talksCount
)
)
.setDefaults(Notification.DEFAULT_SOUND or Notification.DEFAULT_VIBRATE)
.setLights(
ContextCompat.getColor(context, R.color.notification_led_color),
NOTIFICATION_LED_ON_MS,
NOTIFICATION_LED_OFF_MS
)
.setSmallIcon(R.drawable.ic_stat_notification)
.setAutoCancel(true)
.extend(extender)
.setTicker(
context.resources.getQuantityString(
R.plurals.event_notification_ticker,
talksCount,
talksCount
)
)
.setDefaults(Notification.DEFAULT_SOUND or Notification.DEFAULT_VIBRATE)
.setLights(
ContextCompat.getColor(context, R.color.notification_led_color),
NOTIFICATION_LED_ON_MS,
NOTIFICATION_LED_OFF_MS
)
.setSmallIcon(R.drawable.ic_stat_notification)
.setAutoCancel(true)
.extend(extender)
}

private fun createPendingIntentForSingleEvent(eventId: String): PendingIntent {
Expand All @@ -125,8 +125,8 @@ class NotificationCreator(private val context: Context) {

private fun getTrackColor(event: Event): Int {
return event.track
.map { (_, _, accentColor) -> Color.parseColor(accentColor.or(ARGB_TRANSPARENT)) }
.or(Color.TRANSPARENT)
.map { (_, _, accentColor) -> Color.parseColor(accentColor.or(ARGB_TRANSPARENT)) }
.or(Color.TRANSPARENT)
}

private fun createPendingIntentForMultipleEvents(): PendingIntent {
Expand All @@ -138,23 +138,23 @@ class NotificationCreator(private val context: Context) {
val homescreenIntent = Intent(context, HomeActivity::class.java)
homescreenIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
return TaskStackBuilder.create(context)
.addNextIntent(homescreenIntent)
.addNextIntent(homescreenIntent)
}

private fun createBigTextRichNotification(notificationBuilder: NotificationCompat.Builder, event: Event): NotificationCompat.BigTextStyle {
val bigTextBuilder = StringBuilder()
.append(getSpeakerNamesFrom(event.speakers))
.append(getSpeakerNamesFrom(event.speakers))

val placeName = getPlaceName(event)
if (!placeName.isNullOrEmpty()) {
bigTextBuilder
.append('\n')
.append(context.getString(R.string.event_notification_starting_in, placeName))
.append('\n')
.append(context.getString(R.string.event_notification_starting_in, placeName))
}

return NotificationCompat.BigTextStyle(notificationBuilder)
.setBigContentTitle(event.title)
.bigText(bigTextBuilder.toString())
.setBigContentTitle(event.title)
.bigText(bigTextBuilder.toString())
}

private fun getSpeakerNamesFrom(speakers: List<Speaker>): String {
Expand All @@ -163,11 +163,13 @@ class NotificationCreator(private val context: Context) {
return context.getString(R.string.event_notification_starting_by, speakerNames)
}

private fun createInboxStyleRichNotification(notificationBuilder: NotificationCompat.Builder,
events: List<Event>): NotificationCompat.InboxStyle {
private fun createInboxStyleRichNotification(
notificationBuilder: NotificationCompat.Builder,
events: List<Event>
): NotificationCompat.InboxStyle {
val bigContentTitle = createSummaryTitle(events.size)
val richNotification = NotificationCompat.InboxStyle(notificationBuilder)
.setBigContentTitle(bigContentTitle)
.setBigContentTitle(bigContentTitle)

for (event in events) {
if (event.place.isPresent) {
Expand All @@ -188,17 +190,17 @@ class NotificationCreator(private val context: Context) {

private fun createSummaryTitle(talksCount: Int): String {
val quantityString = context.resources
.getQuantityString(R.plurals.event_notification_count_starting, talksCount)
.getQuantityString(R.plurals.event_notification_count_starting, talksCount)
return String.format(quantityString, talksCount)
}

companion object {
private val GROUP_KEY_NOTIFY_SESSION = "group_key_notify_session"
private val EVENTS_ABOUT_TO_START_CHANNEL_ID = "events_about_to_start"
private const val GROUP_KEY_NOTIFY_SESSION = "group_key_notify_session"
private const val EVENTS_ABOUT_TO_START_CHANNEL_ID = "events_about_to_start"

// pulsate every 1 second, indicating a relatively high degree of urgency
private val NOTIFICATION_LED_ON_MS = 100
private val NOTIFICATION_LED_OFF_MS = 1000
private val ARGB_TRANSPARENT = "#00000000"
private const val NOTIFICATION_LED_ON_MS = 100
private const val NOTIFICATION_LED_OFF_MS = 1000
private const val ARGB_TRANSPARENT = "#00000000"
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/net/squanchy/onboarding/Onboarding.kt
Expand Up @@ -3,9 +3,9 @@ package net.squanchy.onboarding
class Onboarding(private val persister: OnboardingPersister) {

fun nextPageToShow(): OnboardingPage? =
OnboardingPage.values()
.asList()
.firstOrNull { page -> page.canShow() }
OnboardingPage.values()
.asList()
.firstOrNull { page -> page.canShow() }

private fun OnboardingPage.canShow() = !persister.pageSeen(this)

Expand Down

0 comments on commit 56fdc91

Please sign in to comment.