-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inform user about missing permissions
- Loading branch information
Showing
6 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
aat-android/src/main/kotlin/ch/bailu/aat/views/msg/overlay/TipMsgView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...roid/src/main/kotlin/ch/bailu/aat/views/msg/permission/DataDirectoryPermissionInfoView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ch.bailu.aat.views.msg.permission | ||
|
||
import android.content.Context | ||
import ch.bailu.aat.util.ui.theme.UiTheme | ||
import ch.bailu.aat_lib.preferences.OnPreferencesChanged | ||
import ch.bailu.aat_lib.preferences.SolidFile | ||
import ch.bailu.aat_lib.preferences.StorageInterface | ||
import ch.bailu.aat_lib.resources.ToDo | ||
import ch.bailu.foc.Foc | ||
|
||
class DataDirectoryPermissionInfoView(context: Context, private val solid: SolidFile, theme: UiTheme) : PermissionInfoView(context, theme), | ||
OnPreferencesChanged { | ||
|
||
public override fun onAttachedToWindow() { | ||
super.onAttachedToWindow() | ||
solid.register(this) | ||
updateText() | ||
} | ||
|
||
override fun onPreferencesChanged(storage: StorageInterface, key: String) { | ||
if (solid.hasKey(key)) { | ||
updateText() | ||
} | ||
} | ||
|
||
public override fun onDetachedFromWindow() { | ||
super.onDetachedFromWindow() | ||
solid.unregister(this) | ||
} | ||
|
||
private fun updateText() { | ||
updateText(getPermissionText(solid.getValueAsFile())) | ||
} | ||
|
||
companion object { | ||
private fun getPermissionText(file: Foc): String { | ||
var result = "" | ||
if (!file.exists()) { | ||
if (file.hasParent()) { | ||
result = getPermissionText(file.parent()) | ||
} else { | ||
result = missingPermissionText | ||
} | ||
} else if (!file.canWrite() || !file.canRead()) { | ||
result = missingPermissionText | ||
} | ||
return result | ||
} | ||
|
||
private val missingPermissionText = ToDo.translate( | ||
"Data directory is missing permissions.\nChoose another directory or acquire permission with `Pick (SAF)…`\nPreferences -> General/System -> Data directory" | ||
) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
aat-android/src/main/kotlin/ch/bailu/aat/views/msg/permission/LocationPermissionInfoView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ch.bailu.aat.views.msg.permission | ||
|
||
import android.content.Context | ||
import ch.bailu.aat.util.AppPermission | ||
import ch.bailu.aat.util.ui.theme.UiTheme | ||
import ch.bailu.aat_lib.resources.ToDo | ||
|
||
class LocationPermissionInfoView(context: Context, theme: UiTheme) : PermissionInfoView(context, theme) { | ||
|
||
override fun onAttachedToWindow() { | ||
super.onAttachedToWindow() | ||
updateText(getPermissionText()) | ||
} | ||
|
||
private fun getPermissionText(): String { | ||
var result = "" | ||
|
||
if (AppPermission.checkLocation(context)) { | ||
if (!AppPermission.checkBackgroundLocation(context)) { | ||
result = noBackgroundPermissionText | ||
} | ||
} else { | ||
result = noPermissionText | ||
} | ||
return result | ||
} | ||
|
||
companion object { | ||
private val noBackgroundPermissionText = ToDo.translate( | ||
"No permission to access location from background\nUse Android app-specific settings to enable this permission" | ||
) | ||
private val noPermissionText = ToDo.translate( | ||
"No permission to access location" | ||
) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
aat-android/src/main/kotlin/ch/bailu/aat/views/msg/permission/PermissionInfoView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ch.bailu.aat.views.msg.permission | ||
|
||
import android.content.Context | ||
import android.widget.TextView | ||
import ch.bailu.aat.util.ui.theme.AppTheme | ||
import ch.bailu.aat.util.ui.theme.UiTheme | ||
|
||
open class PermissionInfoView(context: Context, theme: UiTheme) : TextView(context) { | ||
init { | ||
theme.background(this) | ||
theme.toolTip(this) | ||
AppTheme.padding(this, 5) | ||
} | ||
|
||
fun updateText(text: String) { | ||
visibility = if (text.isEmpty()) { | ||
GONE | ||
} else { | ||
VISIBLE | ||
} | ||
this.text = text | ||
} | ||
} |