Skip to content

Commit f8d079e

Browse files
authored
Develop - translation s and your android crash fix (#312)
2 parents 72f566c + 60050f2 commit f8d079e

5 files changed

Lines changed: 192 additions & 0 deletions

File tree

app/src/main/java/com/sameerasw/essentials/MainActivity.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ import com.sameerasw.essentials.ui.components.EssentialsFloatingToolbar
9292
import com.sameerasw.essentials.ui.components.ToolbarItem
9393
import com.sameerasw.essentials.ui.components.cards.TrackedRepoCard
9494
import androidx.compose.foundation.layout.statusBarsPadding
95+
import com.sameerasw.essentials.data.repository.SettingsRepository
9596
import com.sameerasw.essentials.ui.components.containers.RoundedCardContainer
9697
import com.sameerasw.essentials.ui.components.sheets.AddRepoBottomSheet
9798
import com.sameerasw.essentials.ui.components.sheets.GitHubAuthSheet
9899
import com.sameerasw.essentials.ui.components.sheets.InstructionsBottomSheet
100+
import com.sameerasw.essentials.ui.components.sheets.PrankBottomSheet
99101
import com.sameerasw.essentials.ui.components.sheets.UpdateBottomSheet
100102
import com.sameerasw.essentials.ui.components.menus.SegmentedDropdownMenu
101103
import com.sameerasw.essentials.ui.components.menus.SegmentedDropdownMenuItem
@@ -353,6 +355,25 @@ class MainActivity : AppCompatActivity() {
353355
)
354356
}
355357

358+
val isAprilFoolsSheetVisible by viewModel.isAprilFoolsSheetVisible
359+
val prankSheetState = androidx.compose.material3.rememberModalBottomSheetState(
360+
skipPartiallyExpanded = true
361+
)
362+
363+
if (isAprilFoolsSheetVisible) {
364+
PrankBottomSheet(
365+
viewModel = viewModel,
366+
sheetState = prankSheetState,
367+
onDismissRequest = {
368+
viewModel.isAprilFoolsSheetVisible.value = false
369+
viewModel.settingsRepository.putBoolean(
370+
SettingsRepository.KEY_APRIL_FOOLS_SHOWN,
371+
true
372+
)
373+
}
374+
)
375+
}
376+
356377
val refreshingRepoIds by updatesViewModel.refreshingRepoIds
357378
val updateProgress by updatesViewModel.updateProgress
358379
val animatedProgress by animateFloatAsState(

app/src/main/java/com/sameerasw/essentials/data/repository/SettingsRepository.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class SettingsRepository(private val context: Context) {
170170
const val KEY_SENTRY_REPORT_MODE = "sentry_report_mode"
171171
const val KEY_ONBOARDING_COMPLETED = "onboarding_completed"
172172
const val KEY_PRIVATE_DNS_PRESETS = "private_dns_presets"
173+
const val KEY_APRIL_FOOLS_SHOWN = "april_fools_shown"
173174
}
174175

175176
// Observe changes
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package com.sameerasw.essentials.ui.components.sheets
2+
3+
import androidx.compose.foundation.gestures.detectTapGestures
4+
import androidx.compose.foundation.layout.Arrangement
5+
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.Row
7+
import androidx.compose.foundation.layout.Spacer
8+
import androidx.compose.foundation.layout.fillMaxWidth
9+
import androidx.compose.foundation.layout.height
10+
import androidx.compose.foundation.layout.padding
11+
import androidx.compose.foundation.layout.size
12+
import androidx.compose.material3.Button
13+
import androidx.compose.material3.ExperimentalMaterial3Api
14+
import androidx.compose.material3.MaterialTheme
15+
import androidx.compose.material3.ModalBottomSheet
16+
import androidx.compose.material3.SheetState
17+
import androidx.compose.material3.Text
18+
import androidx.compose.runtime.Composable
19+
import androidx.compose.runtime.getValue
20+
import androidx.compose.runtime.mutableStateOf
21+
import androidx.compose.runtime.remember
22+
import androidx.compose.runtime.setValue
23+
import androidx.compose.ui.Alignment
24+
import androidx.compose.ui.Modifier
25+
import androidx.compose.ui.input.pointer.pointerInput
26+
import androidx.compose.ui.platform.LocalView
27+
import androidx.compose.ui.res.painterResource
28+
import androidx.compose.ui.res.stringResource
29+
import androidx.compose.ui.text.font.FontWeight
30+
import androidx.compose.ui.text.style.TextAlign
31+
import androidx.compose.ui.unit.dp
32+
import coil.compose.AsyncImage
33+
import com.sameerasw.essentials.R
34+
import com.sameerasw.essentials.data.repository.SettingsRepository
35+
import com.sameerasw.essentials.utils.HapticUtil
36+
import com.sameerasw.essentials.viewmodels.MainViewModel
37+
38+
@OptIn(ExperimentalMaterial3Api::class)
39+
@Composable
40+
fun PrankBottomSheet(
41+
viewModel: MainViewModel,
42+
sheetState: SheetState,
43+
onDismissRequest: () -> Unit
44+
) {
45+
var isRevealed by remember { mutableStateOf(false) }
46+
val view = LocalView.current
47+
48+
ModalBottomSheet(
49+
onDismissRequest = {
50+
if (isRevealed) {
51+
onDismissRequest()
52+
}
53+
},
54+
sheetState = sheetState,
55+
dragHandle = null
56+
) {
57+
Column(
58+
modifier = Modifier
59+
.fillMaxWidth()
60+
.padding(24.dp),
61+
horizontalAlignment = Alignment.CenterHorizontally,
62+
verticalArrangement = Arrangement.spacedBy(16.dp)
63+
) {
64+
// App Logo
65+
AsyncImage(
66+
model = R.mipmap.ic_launcher_round,
67+
contentDescription = null,
68+
modifier = Modifier.size(80.dp)
69+
)
70+
71+
if (!isRevealed) {
72+
// Prank Phase
73+
Text(
74+
text = stringResource(R.string.prank_trial_expired_title),
75+
style = MaterialTheme.typography.headlineSmall,
76+
fontWeight = FontWeight.Bold,
77+
textAlign = TextAlign.Center
78+
)
79+
80+
Text(
81+
text = stringResource(R.string.prank_trial_expired_desc),
82+
style = MaterialTheme.typography.bodyMedium,
83+
textAlign = TextAlign.Center,
84+
color = MaterialTheme.colorScheme.onSurfaceVariant
85+
)
86+
87+
Spacer(modifier = Modifier.height(8.dp))
88+
89+
Button(
90+
onClick = {
91+
HapticUtil.performHeavyHaptic(view)
92+
isRevealed = true
93+
},
94+
modifier = Modifier.fillMaxWidth()
95+
) {
96+
Text(text = stringResource(R.string.prank_button_premium))
97+
}
98+
} else {
99+
// Reveal Phase
100+
Text(
101+
text = stringResource(R.string.prank_reveal_title),
102+
style = MaterialTheme.typography.headlineSmall,
103+
fontWeight = FontWeight.Bold,
104+
textAlign = TextAlign.Center,
105+
color = MaterialTheme.colorScheme.primary
106+
)
107+
108+
Text(
109+
text = stringResource(R.string.prank_reveal_desc),
110+
style = MaterialTheme.typography.bodyLarge,
111+
textAlign = TextAlign.Center
112+
)
113+
114+
Spacer(modifier = Modifier.height(8.dp))
115+
116+
Button(
117+
onClick = {
118+
onDismissRequest()
119+
},
120+
modifier = Modifier
121+
.fillMaxWidth()
122+
.pointerInput(Unit) {
123+
detectTapGestures(
124+
onLongPress = {
125+
// Debug reset
126+
viewModel.settingsRepository.putBoolean(
127+
SettingsRepository.KEY_APRIL_FOOLS_SHOWN,
128+
false
129+
)
130+
HapticUtil.performHeavyHaptic(view)
131+
android.widget.Toast.makeText(view.context, "Prank reset for testing", android.widget.Toast.LENGTH_SHORT).show()
132+
},
133+
onTap = {
134+
HapticUtil.performUIHaptic(view)
135+
onDismissRequest()
136+
}
137+
)
138+
}
139+
) {
140+
Text(text = stringResource(R.string.action_continue))
141+
}
142+
}
143+
144+
Spacer(modifier = Modifier.height(16.dp))
145+
}
146+
}
147+
}

app/src/main/java/com/sameerasw/essentials/viewmodels/MainViewModel.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ class MainViewModel : ViewModel() {
223223
val windowAnimationScale = mutableFloatStateOf(1.0f)
224224
val smallestWidth = mutableIntStateOf(360)
225225
val hasShizukuPermission = mutableStateOf(false)
226+
val isAprilFoolsSheetVisible = mutableStateOf(false)
227+
val isAprilFoolsShown = mutableStateOf(false)
226228

227229
private var lastUpdateCheckTime: Long = 0
228230
lateinit var settingsRepository: SettingsRepository
@@ -444,6 +446,10 @@ class MainViewModel : ViewModel() {
444446
dnsPresets.clear()
445447
dnsPresets.addAll(settingsRepository.getPrivateDnsPresets())
446448
}
449+
450+
SettingsRepository.KEY_APRIL_FOOLS_SHOWN -> {
451+
isAprilFoolsShown.value = settingsRepository.getBoolean(key)
452+
}
447453
}
448454
}
449455
}
@@ -793,6 +799,18 @@ class MainViewModel : ViewModel() {
793799

794800
isAirSyncConnectionEnabled.value =
795801
settingsRepository.getBoolean(SettingsRepository.KEY_AIRSYNC_CONNECTION_ENABLED)
802+
803+
// April Fools Check
804+
isAprilFoolsShown.value = settingsRepository.getBoolean(SettingsRepository.KEY_APRIL_FOOLS_SHOWN)
805+
if (!isAprilFoolsShown.value) {
806+
val calendar = java.util.Calendar.getInstance()
807+
val month = calendar.get(java.util.Calendar.MONTH)
808+
val day = calendar.get(java.util.Calendar.DAY_OF_MONTH)
809+
if (month == java.util.Calendar.APRIL && day == 1) {
810+
isAprilFoolsSheetVisible.value = true
811+
}
812+
}
813+
796814
macBatteryLevel.intValue =
797815
settingsRepository.getInt(SettingsRepository.KEY_MAC_BATTERY_LEVEL, -1)
798816
isMacBatteryCharging.value =

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,5 +1328,10 @@
13281328
<string name="msg_flashbang">Get ready to be flashbanged!</string>
13291329
<string name="action_abort">Abort</string>
13301330
<string name="action_continue">Continue</string>
1331+
<string name="prank_trial_expired_title">Your Essentials trial has expired</string>
1332+
<string name="prank_trial_expired_desc">Your free trial period of Essentials has ended. Access to advanced features like Button Remap, App Freezing, and DIY Automations with Premium.</string>
1333+
<string name="prank_button_premium">What\'s in Premium?</string>
1334+
<string name="prank_reveal_title">April Fools!</string>
1335+
<string name="prank_reveal_desc">Just kidding, Essentials is and will always be free and open source. Enjoy! (っ◕‿◕)っ</string>
13311336

13321337
</resources>

0 commit comments

Comments
 (0)