Skip to content

Commit b57df04

Browse files
authored
Merge pull request #99 from timusus/feature/snowfall-config
Feature/snowfall config
2 parents b2360bf + 967ab74 commit b57df04

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

androidApp/main/app/src/debug/res/layout/activity_main.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636

3737
</androidx.drawerlayout.widget.DrawerLayout>
3838

39+
<com.simplecityapps.shuttle.ui.common.view.SnowfallView
40+
android:id="@+id/snowfallView"
41+
android:layout_width="match_parent"
42+
android:layout_height="match_parent" />
43+
3944
<com.simplecityapps.shuttle.ui.common.view.KeylineView
4045
android:layout_width="match_parent"
4146
android:layout_height="match_parent"

androidApp/main/app/src/main/java/com/simplecityapps/shuttle/ui/MainActivity.kt

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ import android.provider.MediaStore
88
import androidx.appcompat.app.AppCompatActivity
99
import androidx.core.content.ContextCompat
1010
import androidx.navigation.fragment.NavHostFragment
11+
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
1112
import com.simplecityapps.playback.PlaybackService
1213
import com.simplecityapps.shuttle.R
14+
import com.simplecityapps.shuttle.di.AppCoroutineScope
1315
import com.simplecityapps.shuttle.persistence.GeneralPreferenceManager
16+
import com.simplecityapps.shuttle.ui.common.view.SnowfallView
1417
import com.simplecityapps.trial.BillingManager
1518
import dagger.hilt.android.AndroidEntryPoint
19+
import kotlinx.coroutines.CoroutineScope
20+
import kotlinx.coroutines.launch
21+
import kotlinx.coroutines.tasks.await
22+
import kotlinx.coroutines.withTimeout
1623
import javax.inject.Inject
1724

1825
@AndroidEntryPoint
@@ -28,6 +35,15 @@ class MainActivity :
2835
@Inject
2936
lateinit var billingManager: BillingManager
3037

38+
@Inject
39+
lateinit var remoteConfig: FirebaseRemoteConfig
40+
41+
@Inject
42+
@AppCoroutineScope
43+
lateinit var scope: CoroutineScope
44+
45+
lateinit var snowfallView: SnowfallView
46+
3147
// Lifecycle
3248

3349
override fun onCreate(savedInstanceState: Bundle?) {
@@ -54,6 +70,15 @@ class MainActivity :
5470
handleSearchQuery(intent)
5571

5672
billingManager.queryPurchases()
73+
74+
snowfallView = findViewById(R.id.snowfallView)
75+
76+
scope.launch {
77+
withTimeout(5000) {
78+
remoteConfig.fetchAndActivate().await()
79+
}
80+
snowfallView.setForecast(remoteConfig.getDouble("snow_forecast"))
81+
}
5782
}
5883

5984
override fun onResume() {
@@ -78,14 +103,12 @@ class MainActivity :
78103
if (intent?.action == MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH) {
79104
ContextCompat.startForegroundService(
80105
this,
81-
(
82-
Intent(this, PlaybackService::class.java).apply {
83-
action = PlaybackService.ACTION_SEARCH
84-
intent.extras?.let { extras ->
85-
putExtras(extras)
86-
}
106+
Intent(this, PlaybackService::class.java).apply {
107+
action = PlaybackService.ACTION_SEARCH
108+
intent.extras?.let { extras ->
109+
putExtras(extras)
87110
}
88-
)
111+
}
89112
)
90113
}
91114
}

androidApp/main/app/src/main/java/com/simplecityapps/shuttle/ui/common/view/SnowfallView.kt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import kotlin.math.roundToInt
1515

1616
class SnowfallView(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
1717

18+
fun setForecast(forecast: Double) {
19+
if (random.nextDouble() <= forecast) {
20+
letItSnow()
21+
}
22+
}
23+
1824
/** Used to paint each snowflake */
1925
private val snowPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
2026
color = Color.WHITE
@@ -70,14 +76,6 @@ class SnowfallView(context: Context?, attrs: AttributeSet?) : View(context, attr
7076
}
7177
}
7278

73-
override fun onAttachedToWindow() {
74-
super.onAttachedToWindow()
75-
76-
if (lerp(0f, 1f, random.nextFloat()) <= LUCKY) {
77-
letItSnow()
78-
}
79-
}
80-
8179
override fun onDetachedFromWindow() {
8280
clear()
8381
super.onDetachedFromWindow()
@@ -137,9 +135,6 @@ class SnowfallView(context: Context?, attrs: AttributeSet?) : View(context, attr
137135

138136
companion object {
139137

140-
/** Forecast a <= 5% chance of snowing */
141-
private const val LUCKY = 0.05f
142-
143138
/** The total number of snowflakes to generate */
144139
private const val TOTAL_FLAKES = 200
145140

androidApp/main/app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
app:defaultNavHost="true" />
1515

1616
<com.simplecityapps.shuttle.ui.common.view.SnowfallView
17+
android:id="@+id/snowfallView"
1718
android:layout_width="match_parent"
1819
android:layout_height="match_parent" />
1920

androidApp/main/remote-config/src/main/java/com/simplecityapps/shuttle/remote_config/RemoteConfigModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class RemoteConfigModule {
2727
mapOf(
2828
"pricing_tier" to "high",
2929
"pre_trial_length" to 0,
30-
"trial_length" to 14L
30+
"trial_length" to 14L,
31+
"snow_forecast" to 0.0,
3132
)
3233
)
3334

0 commit comments

Comments
 (0)