Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.21.4-beta #84

Merged
merged 8 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ android {
applicationId = "f.cking.software"
minSdk = 29
targetSdk = 34
versionCode = 1704045671
versionName = "0.21.3-beta"
versionCode = 1704045672
versionName = "0.21.4-beta"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

buildConfigField("String", "REPORT_ISSUE_URL", "\"https://github.com/Semper-Viventem/MetaRadar/issues\"")
buildConfigField("String", "GITHUB_URL", "\"https://github.com/Semper-Viventem/MetaRadar\"")
buildConfigField("String", "GOOGLE_PLAY_URL", "\"https://play.google.com/store/apps/details?id=f.cking.software&pcampaignid=web_share\"")
buildConfigField("String", "STORE_PAGE_URL", "\"Not specified\"")

buildConfigField("String", "DISTRIBUTION", "\"Not specified\"")
}
Expand Down Expand Up @@ -83,18 +83,23 @@ android {
versionCode = (System.currentTimeMillis() / 1000).toInt()

buildConfigField("String", "DISTRIBUTION", "\"Github\"")
buildConfigField("Boolean", "STORE_RATING_IS_APPLICABLE", "false")
buildConfigField("String", "STORE_PAGE_URL", "\"https://github.com/Semper-Viventem/MetaRadar/releases?q=release+build\"")
}
create("googlePlay") {
isDefault = false
dimension = "distribution"
versionCode = (System.currentTimeMillis() / 1000).toInt()

buildConfigField("String", "DISTRIBUTION", "\"Google play\"")
buildConfigField("Boolean", "STORE_RATING_IS_APPLICABLE", "true")
buildConfigField("String", "STORE_PAGE_URL", "\"https://play.google.com/store/apps/details?id=f.cking.software&pcampaignid=web_share\"")
}
create("fdroid") {
isDefault = false
dimension = "distribution"

buildConfigField("Boolean", "STORE_RATING_IS_APPLICABLE", "false")
buildConfigField("String", "DISTRIBUTION", "\"F-Droid\"")
}
}
Expand Down Expand Up @@ -155,7 +160,6 @@ dependencies {
// compose
implementation(libs.compose.ui)
implementation(libs.compose.foundation)
implementation(libs.compose.material)
implementation(libs.compose.tooling)
implementation(libs.lifecycle.compose)
implementation(libs.compose.activity)
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class PermissionHelper(
return (BLE_PERMISSIONS + BACKGROUND_LOCATION).all { checkPermission(it) }
}

fun checkLocationPermission(): Boolean {
return checkPermission(Manifest.permission.ACCESS_FINE_LOCATION)
}

private fun checkPermission(permission: String): Boolean {
return ActivityCompat.checkSelfPermission(
context,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/f/cking/software/ui/UiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object UiModule {
single<Router> { get<RouterImpl>() }
viewModel { MainViewModel(get(), get(), get(), get(), get(), get()) }
viewModel { DeviceListViewModel(get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { SettingsViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { SettingsViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { ProfilesListViewModel(get(), get()) }
viewModel { ProfileDetailsViewModel(profileId = it[0], template = it[1], get(), get(), get(), get(), get()) }
viewModel { SelectManufacturerViewModel(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.google.accompanist.flowlayout.FlowRow
import com.vanpra.composematerialdialogs.MaterialDialog
import com.vanpra.composematerialdialogs.rememberMaterialDialogState
import f.cking.software.R
import f.cking.software.dateTimeStringFormat
Expand All @@ -64,6 +63,7 @@ import f.cking.software.utils.graphic.MapView
import f.cking.software.utils.graphic.RoundedBox
import f.cking.software.utils.graphic.SystemNavbarSpacer
import f.cking.software.utils.graphic.TagChip
import f.cking.software.utils.graphic.ThemedDialog
import kotlinx.coroutines.isActive
import org.koin.androidx.compose.koinViewModel
import org.koin.core.parameter.parametersOf
Expand Down Expand Up @@ -273,14 +273,14 @@ object DeviceDetailsScreen {
) {
val dialogState = rememberMaterialDialogState()

MaterialDialog(
ThemedDialog(
dialogState = dialogState,
buttons = {
negativeButton(
text = stringResource(R.string.cancel),
textStyle = TextStyle(color = MaterialTheme.colorScheme.secondaryContainer)
textStyle = TextStyle(color = MaterialTheme.colorScheme.onSurface)
) { dialogState.hide() }
positiveButton(text = stringResource(R.string.confirm), textStyle = TextStyle(color = MaterialTheme.colorScheme.secondaryContainer)) {
positiveButton(text = stringResource(R.string.confirm), textStyle = TextStyle(color = MaterialTheme.colorScheme.onSurface)) {
dialogState.hide()
viewModel.onRemoveTagClick(deviceData, name)
}
Expand Down Expand Up @@ -318,12 +318,12 @@ object DeviceDetailsScreen {
viewModel: DeviceDetailsViewModel,
) {
val dialog = rememberMaterialDialogState()
MaterialDialog(
ThemedDialog(
dialogState = dialog,
buttons = {
negativeButton(
stringResource(R.string.cancel),
textStyle = TextStyle(color = MaterialTheme.colorScheme.secondaryContainer)
textStyle = TextStyle(color = MaterialTheme.colorScheme.onSurface)
) { dialog.hide() }
},
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ object DeviceListScreen {
}
}

if (viewModel.enjoyTheAppState != DeviceListViewModel.EnjoyTheAppState.NONE) {
if (viewModel.enjoyTheAppState != DeviceListViewModel.EnjoyTheAppState.None) {
item {
Spacer(modifier = Modifier.height(8.dp))
EnjoyTheApp(viewModel, viewModel.enjoyTheAppState)
Expand Down Expand Up @@ -137,10 +137,10 @@ object DeviceListScreen {
private fun EnjoyTheApp(viewModel: DeviceListViewModel, enjoyTheAppState: DeviceListViewModel.EnjoyTheAppState) {
RoundedBox {
when (enjoyTheAppState) {
DeviceListViewModel.EnjoyTheAppState.QUESTION -> EnjoyTheAppQuestion(viewModel)
DeviceListViewModel.EnjoyTheAppState.LIKE -> EnjoyTheAppLike(viewModel)
DeviceListViewModel.EnjoyTheAppState.DISLIKE -> EnjoyTheAppDislike(viewModel)
DeviceListViewModel.EnjoyTheAppState.NONE -> throw IllegalStateException("EnjoyTheAppState.NONE is not supported here")
is DeviceListViewModel.EnjoyTheAppState.Question -> EnjoyTheAppQuestion(viewModel)
is DeviceListViewModel.EnjoyTheAppState.Like -> EnjoyTheAppLike(enjoyTheAppState, viewModel)
is DeviceListViewModel.EnjoyTheAppState.Dislike -> EnjoyTheAppDislike(viewModel)
is DeviceListViewModel.EnjoyTheAppState.None -> throw IllegalStateException("EnjoyTheAppState.NONE is not supported here")
}
}
}
Expand Down Expand Up @@ -171,17 +171,18 @@ object DeviceListScreen {
}

@Composable
private fun EnjoyTheAppLike(viewModel: DeviceListViewModel) {
private fun EnjoyTheAppLike(state: DeviceListViewModel.EnjoyTheAppState.Like, viewModel: DeviceListViewModel) {
Column {
Text(text = stringResource(R.string.rate_the_app), fontWeight = FontWeight.SemiBold)
Spacer(modifier = Modifier.height(8.dp))
Row {
Button(modifier = Modifier.weight(1f), onClick = { viewModel.onEnjoyTheAppRatePlayStoreClick() }) {
Text(text = stringResource(R.string.rate_the_app_google_play), color = MaterialTheme.colorScheme.onPrimary)
}
Spacer(modifier = Modifier.width(8.dp))
Button(modifier = Modifier.weight(1f), onClick = { viewModel.onEnjoyTheAppRateGithubClick() }) {
Text(text = stringResource(R.string.rate_the_app_github), color = MaterialTheme.colorScheme.onPrimary)
state.actions.forEachIndexed { i, action ->
Button(modifier = Modifier.weight(1f), onClick = { viewModel.onRateButtonClick(action) }) {
Text(text = action.title, color = MaterialTheme.colorScheme.onPrimary)
}
if (i < state.actions.lastIndex) {
Spacer(modifier = Modifier.width(8.dp))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class DeviceListViewModel(
context: Application,
private val context: Application,
private val devicesRepository: DevicesRepository,
private val filterCheckerImpl: FilterCheckerImpl,
val router: Router,
Expand All @@ -46,7 +46,7 @@ class DeviceListViewModel(
DefaultFilters.isFavorite(context),
)
)
var enjoyTheAppState: EnjoyTheAppState by mutableStateOf(EnjoyTheAppState.NONE)
var enjoyTheAppState: EnjoyTheAppState by mutableStateOf(EnjoyTheAppState.None)

private val generalComparator = Comparator<DeviceData> { second, first ->
when {
Expand Down Expand Up @@ -152,38 +152,56 @@ class DeviceListViewModel(
}

private fun showEnjoyTheAppIfNeeded() {
if (enjoyTheAppState == EnjoyTheAppState.NONE
if (enjoyTheAppState is EnjoyTheAppState.None
&& checkNeedToShowEnjoyTheAppInteractor.execute()
) {
enjoyTheAppState = EnjoyTheAppState.QUESTION
enjoyTheAppState = EnjoyTheAppState.Question
}
}

fun onEnjoyTheAppAnswered(answer: EnjoyTheAppAnswer) {
enjoyTheAppState = when (answer) {
EnjoyTheAppAnswer.LIKE -> EnjoyTheAppState.LIKE
EnjoyTheAppAnswer.DISLIKE -> EnjoyTheAppState.DISLIKE
EnjoyTheAppAnswer.LIKE -> buildLikeTheAppState()
EnjoyTheAppAnswer.DISLIKE -> EnjoyTheAppState.Dislike
EnjoyTheAppAnswer.ASK_LATER -> {
enjoyTheAppAskLaterInteractor.execute()
EnjoyTheAppState.NONE
EnjoyTheAppState.None
}
}
}

fun onEnjoyTheAppRatePlayStoreClick() {
settingsRepository.setEnjoyTheAppAnswered(true)
enjoyTheAppState = EnjoyTheAppState.NONE
intentHelper.openUrl(BuildConfig.GOOGLE_PLAY_URL)
private fun buildLikeTheAppState(): EnjoyTheAppState.Like {
val actions = mutableListOf<EnjoyTheAppState.RateAppAction>()
if (BuildConfig.STORE_RATING_IS_APPLICABLE) {
actions.add(
EnjoyTheAppState.RateAppAction(
title = BuildConfig.DISTRIBUTION,
url = BuildConfig.STORE_PAGE_URL,
saveAnswer = true,
)
)
}
actions.add(
EnjoyTheAppState.RateAppAction(
title = context.getString(R.string.rate_the_app_github),
url = BuildConfig.GITHUB_URL,
saveAnswer = !BuildConfig.STORE_RATING_IS_APPLICABLE,
)
)
return EnjoyTheAppState.Like(actions)
}

fun onEnjoyTheAppRateGithubClick() {
settingsRepository.setEnjoyTheAppAnswered(true)
intentHelper.openUrl(BuildConfig.GITHUB_URL)
fun onRateButtonClick(rateAction: EnjoyTheAppState.RateAppAction) {
if (rateAction.saveAnswer) {
settingsRepository.setEnjoyTheAppAnswered(true)
enjoyTheAppState = EnjoyTheAppState.None
}
intentHelper.openUrl(rateAction.url)
}

fun onEnjoyTheAppReportClick() {
settingsRepository.setEnjoyTheAppAnswered(true)
enjoyTheAppState = EnjoyTheAppState.NONE
enjoyTheAppState = EnjoyTheAppState.None
intentHelper.openUrl(BuildConfig.REPORT_ISSUE_URL)
}

Expand All @@ -209,8 +227,21 @@ class DeviceListViewModel(
val filter: RadarProfile.Filter,
)

enum class EnjoyTheAppState {
NONE, QUESTION, LIKE, DISLIKE
sealed interface EnjoyTheAppState {
data object None : EnjoyTheAppState
data object Question : EnjoyTheAppState

data class Like(
val actions: List<RateAppAction>
) : EnjoyTheAppState

data object Dislike : EnjoyTheAppState

data class RateAppAction(
val title: String,
val url: String,
val saveAnswer: Boolean,
)
}

enum class EnjoyTheAppAnswer {
Expand Down
65 changes: 38 additions & 27 deletions app/src/main/java/f/cking/software/ui/filter/SelectFilterScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
Expand All @@ -22,16 +24,20 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import f.cking.software.R
import f.cking.software.domain.model.RadarProfile
import f.cking.software.utils.graphic.BottomNavigationSpacer
import f.cking.software.utils.graphic.GlassBottomSpace
import f.cking.software.utils.graphic.SystemNavbarSpacer
import f.cking.software.utils.graphic.pxToDp
import f.cking.software.utils.navigation.BackCommand
import f.cking.software.utils.navigation.Router

Expand All @@ -52,32 +58,9 @@ object SelectFilterScreen {
AppBar(scrollBehavior) { router.navigate(BackCommand) }
},
content = { paddings ->
var bottomBarHeight by mutableStateOf(0f)
GlassBottomSpace(
modifier = Modifier.fillMaxSize(),
bottomContent = {
val context = LocalContext.current
Button(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
onClick = {
val filter = initialFilterState
.takeIf { it.isCorrect() }
?.let { FilterUiMapper.mapToDomain(it) }

if (filter != null) {
router.navigate(BackCommand)
onConfirm.invoke(filter)
} else {
Toast.makeText(context, context.getString(R.string.filter_is_not_valid), Toast.LENGTH_SHORT).show()
}
}
) {
Text(text = stringResource(R.string.confirm), color = MaterialTheme.colorScheme.onPrimary)
}

SystemNavbarSpacer()
},
globalContent = {
Column(
modifier = Modifier
Expand All @@ -96,9 +79,37 @@ object SelectFilterScreen {
onDeleteClick = { router.navigate(BackCommand) }
)
}
BottomNavigationSpacer()
Spacer(modifier = Modifier.height(pxToDp(px = bottomBarHeight).dp))
}
},
bottomContent = {
val context = LocalContext.current
Column(
modifier = Modifier
.onGloballyPositioned { bottomBarHeight = it.size.height.toFloat() }
) {
Button(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
onClick = {
val filter = initialFilterState
.takeIf { it.isCorrect() }
?.let { FilterUiMapper.mapToDomain(it) }

if (filter != null) {
router.navigate(BackCommand)
onConfirm.invoke(filter)
} else {
Toast.makeText(context, context.getString(R.string.filter_is_not_valid), Toast.LENGTH_SHORT).show()
}
}
) {
Text(text = stringResource(R.string.confirm), color = MaterialTheme.colorScheme.onPrimary)
}
SystemNavbarSpacer()
}
}
},
)
}
)
Expand Down
Loading