Skip to content

Commit

Permalink
-Updated accessibility service not running screens to comply with goo…
Browse files Browse the repository at this point in the history
…gle play policies

-hotfixes and minor improvements
  • Loading branch information
tahaak67 committed Aug 29, 2022
1 parent fb3479f commit c59f52c
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 30 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Farhan

[![GitHub issues](https://img.shields.io/github/issues/tahaak67/Farhan?style=flat-square)](https://github.com/tahaak67/Farhan/issues) [![GitHub stars](https://img.shields.io/github/stars/tahaak67/Farhan?style=flat-square)](https://github.com/tahaak67/Farhan/stargazers) [![GitHub license](https://img.shields.io/github/license/tahaak67/Farhan?style=flat-square)](https://github.com/tahaak67/Farhan/blob/main/LICENSE)

## Downloads

Download the latest apk from Github by
clicking [here](https://github.com/tahaak67/Farhan/releases/latest) \
or download from google play by clicking the badge below

<a href='https://play.google.com/store/apps/details?id=ly.com.tahaben.farhan&pcampaignid=pcampaignidMKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1'><img alt='Get it on Google Play' src='https://play.google.com/intl/en_us/badges/static/images/badges/en_badge_web_generic.png' width="250"/></a>

Farhan is an open-source application that offers many ways to eliminate manipulative strategies used
by other apps on your phone, so you can eliminate distractions and use your phone!
Included features:
Expand Down
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "0.1",
"versionCode": 3,
"versionName": "0.1.1",
"outputFile": "app-release.apk"
}
],
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/ProjectConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ object ProjectConfig {
const val compileSdk = 32
const val minSdk = 23
const val targetSdk = 32
const val versionCode = 2
const val versionCode = 3
const val versionName = "0.1.1"
}
2 changes: 1 addition & 1 deletion core-ui/src/main/java/ly/com/tahaben/core_ui/Color.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ val BrightGreen = Color(0xFF00C713)
val DarkGreen = Color(0xFF00790C)
val Orange = Color(0xFFFFAA00)
val CarbColor = Color(0xFFEEFF00)
val ProteinColor = Orange
val CategoryBarColor = Orange
val FatColor = Color(0xFFF44336)
val MediumGray = Color(0xFF404040)
val DarkGray = Color(0xFF202020)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package ly.com.tahaben.core_ui.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextAlign
import ly.com.tahaben.core.R
import ly.com.tahaben.core_ui.Black
import ly.com.tahaben.core_ui.LocalSpacing

@Composable
fun AccessibilityNotRunningContent(
modifier: Modifier,
message: String,
subMessage: String,
permissionReasons: AnnotatedString? = null,
onGrantClick: () -> Unit,
onBack: () -> Unit,
onHowClick: () -> Unit
) {
val spacing = LocalSpacing.current
val accessibilityServiceNotRunningScrollState = rememberScrollState()
Column(
modifier = modifier
.padding(horizontal = spacing.spaceMedium)
.verticalScroll(accessibilityServiceNotRunningScrollState),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
text = message,
style = MaterialTheme.typography.h3,
color = Black,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(spacing.spaceMedium))
Text(
text = subMessage,
style = MaterialTheme.typography.h4,
color = Black,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(spacing.spaceMedium))
if (permissionReasons != null) {
Text(
text = permissionReasons,
style = MaterialTheme.typography.h4,
color = Black,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(spacing.spaceMedium))
}
Text(
text = stringResource(R.string.if_you_choose_agree_msg),
style = MaterialTheme.typography.h4,
color = Black,
textAlign = TextAlign.Center
)
Spacer(modifier = Modifier.height(spacing.spaceMedium))
Row {
Button(onClick = onGrantClick) {
Text(
text = stringResource(R.string.agree),
style = MaterialTheme.typography.button,
color = Black
)
}
Spacer(modifier = Modifier.width(spacing.spaceSmall))
Button(onClick = onBack) {
Text(
text = stringResource(R.string.cancel),
style = MaterialTheme.typography.button,
color = Black
)
}
}
Spacer(modifier = Modifier.height(spacing.spaceMedium))
Text(
modifier = Modifier.clickable(onClick = onHowClick),
text = stringResource(R.string.how),
style = MaterialTheme.typography.button,
color = Black
)
}
}
Binary file modified core/src/main/res/drawable/accessibility_permission_howto.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions core/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,10 @@
<string name="notification_settings_shocase_tip">يمكن اضافة استثناءات او تعيين وقت للتذكير من اعدادات فلترة الإشعارات</string>
<string name="version">إصدار التطبيق</string>
<string name="notification_filter_showcase_greeting">اهلا بك في فلتر الإشعارات، ستظهر اشعاراتك المفلترة هنا!.</string>
<string name="agree">موافق</string>
<string name="cancel">إلغاء</string>
<string name="if_you_choose_agree_msg">عند الضغط على موافق، سيتم توجيهك إلى إعدادات إمكانية الوصول في جهازك.</string>
<string name="privacy_policy">سياسة الخصوصية</string>
<string name="cant_open_link_error_link_copied">لا يمكن ايجاد متصفح، تم نسخ الرابط إلى الحافظة.</string>
</resources>

5 changes: 5 additions & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,9 @@
<string name="notification_settings_shocase_tip">You can add exceptions or set a reminder from notification filter settings</string>
<string name="version">App Version</string>
<string name="notification_filter_showcase_greeting">Welcome to notifications filter, your filtered notifications will apear here!.</string>
<string name="agree">Agree</string>
<string name="cancel">Cancel</string>
<string name="if_you_choose_agree_msg">When you choose Agree you will be navigated to accessibility settings in your device.</string>
<string name="privacy_policy">Privacy Policy</string>
<string name="cant_open_link_error_link_copied">Can\'t find a browser, link copied to clipboard</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import ly.com.tahaben.core.R
import ly.com.tahaben.core_ui.LocalSpacing
import ly.com.tahaben.core_ui.OnLifecycleEvent
import ly.com.tahaben.core_ui.White
import ly.com.tahaben.core_ui.components.AccessibilityNotRunningContent
import ly.com.tahaben.core_ui.components.HowDialog
import ly.com.tahaben.core_ui.components.PermissionNotGrantedContent
import ly.com.tahaben.core_ui.components.getAnnotatedStringBulletList
Expand Down Expand Up @@ -99,12 +100,13 @@ fun InfiniteScrollingBlockerScreen(
style = MaterialTheme.typography.h3,
textAlign = TextAlign.Center
)
PermissionNotGrantedContent(
AccessibilityNotRunningContent(
modifier = Modifier,
message = stringResource(R.string.accessibility_permission_not_granted),
subMessage = stringResource(R.string.accessibility_permission_needed_message),
permissionReasons = permissionReasons,
onGrantClick = viewModel::askForAccessibilityPermission,
onBack = onNavigateUp,
onHowClick = { openHowAccessibilityDialog.value = true }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class GrayscaleUtilImpl(
return rootBeer.isRootedWithBusyBoxCheck
}

@Suppress("BlockingMethodInNonBlockingContext")
override suspend fun getSecureSettingsPermissionWithRoot(): Boolean {

override fun getSecureSettingsPermissionWithRoot(): Boolean {
val cmds =
arrayOf("pm grant ly.com.tahaben.farhan android.permission.WRITE_SECURE_SETTINGS")
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package ly.com.tahaben.screen_grayscale_domain.use_cases
import ly.com.tahaben.screen_grayscale_domain.util.GrayscaleUtil

class AskForSecureSettingsPermission(
private val accessibilityUtil: GrayscaleUtil
private val grayscaleUtil: GrayscaleUtil
) {

suspend operator fun invoke(): Boolean {
return accessibilityUtil.getSecureSettingsPermissionWithRoot()
operator fun invoke(): Boolean {
return grayscaleUtil.getSecureSettingsPermissionWithRoot()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ interface GrayscaleUtil {

fun isSecureSettingsPermissionGranted(): Boolean
fun isDeviceRooted(): Boolean
suspend fun getSecureSettingsPermissionWithRoot(): Boolean
fun getSecureSettingsPermissionWithRoot(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.Lifecycle
import ly.com.tahaben.core.R
import ly.com.tahaben.core_ui.*
import ly.com.tahaben.core_ui.components.AccessibilityNotRunningContent
import ly.com.tahaben.core_ui.components.HowDialog
import ly.com.tahaben.core_ui.components.PermissionNotGrantedContent
import ly.com.tahaben.core_ui.components.getAnnotatedStringBulletList

@Composable
Expand Down Expand Up @@ -132,13 +132,14 @@ fun GrayscaleScreen(
val permissionReasons =
getAnnotatedStringBulletList(messages)

PermissionNotGrantedContent(
AccessibilityNotRunningContent(
modifier = Modifier.fillMaxSize(),
message = stringResource(id = R.string.accessibility_permission_not_granted),
subMessage = stringResource(id = R.string.accessibility_permission_needed_grayscale_message),
permissionReasons = permissionReasons,
onHowClick = { openHowAccessibilityDialog.value = true },
onGrantClick = viewModel::askForAccessibilityPermission
onGrantClick = viewModel::askForAccessibilityPermission,
onBack = onNavigateUp
)
} else {
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import ly.com.tahaben.screen_grayscale_domain.use_cases.GrayscaleUseCases
import timber.log.Timber
import javax.inject.Inject
Expand Down Expand Up @@ -66,16 +64,13 @@ class GrayscaleViewModel @Inject constructor(

fun askForSecureSettingsPermissionWithRoot() {
viewModelScope.launch {
state = state.copy(
isLoading = true
)
withContext(Dispatchers.IO) {
grayscaleUseCases.askForSecureSettingsPermission()
state = state.copy(isLoading = true)

if (grayscaleUseCases.askForSecureSettingsPermission()) {
state = state.copy(isLoading = false)
checkSecureSettingsPermissionStats()
}
state = state.copy(
isLoading = false
)
checkSecureSettingsPermissionStats()

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import ly.com.tahaben.core.R
import ly.com.tahaben.core_ui.FatColor
import ly.com.tahaben.core_ui.CategoryBarColor
import ly.com.tahaben.core_ui.LocalSpacing
import ly.com.tahaben.core_ui.Page
import ly.com.tahaben.core_ui.ProteinColor
import ly.com.tahaben.usage_overview_presentation.UsageOverviewState


Expand Down Expand Up @@ -144,21 +143,21 @@ fun UsageOverviewHeader(
value = state.totalSocialUsageMilli,
total = state.totalUsageMilli,
name = stringResource(id = R.string.category_social),
color = ProteinColor,
color = CategoryBarColor,
modifier = Modifier.size(90.dp)
)
UsageBarInfo(
value = state.totalProductivityUsageMilli,
total = state.totalUsageMilli,
name = stringResource(id = R.string.category_productivity),
color = ProteinColor,
color = CategoryBarColor,
modifier = Modifier.size(90.dp)
)
UsageBarInfo(
value = state.totalGameUsageMilli,
total = state.totalUsageMilli,
name = stringResource(id = R.string.category_game),
color = FatColor,
color = CategoryBarColor,
modifier = Modifier.size(90.dp)
)
}
Expand Down

0 comments on commit c59f52c

Please sign in to comment.