diff --git a/android/build.gradle b/android/build.gradle index 42a01b9a4..3ddded147 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -53,7 +53,7 @@ android { defaultConfig { versionCode 259 versionName "2.5.9" - minSdkVersion 14 + minSdkVersion 16 targetSdkVersion 29 applicationId "org.ligi.gobandroid_hd" testInstrumentationRunner "org.ligi.gobandroid_hd.AppReplacingRunner" diff --git a/android/src/main/java/org/ligi/gobandroid_hd/ui/GoActivity.kt b/android/src/main/java/org/ligi/gobandroid_hd/ui/GoActivity.kt index b7b136abe..e55ac24c2 100644 --- a/android/src/main/java/org/ligi/gobandroid_hd/ui/GoActivity.kt +++ b/android/src/main/java/org/ligi/gobandroid_hd/ui/GoActivity.kt @@ -76,6 +76,7 @@ import java.util.* /** * Activity for a Go Game */ +@RuntimePermissions open class GoActivity : GobandroidFragmentActivity(), OnTouchListener, OnKeyListener { var sound_man: GoSoundManager? = null @@ -243,7 +244,7 @@ open class GoActivity : GobandroidFragmentActivity(), OnTouchListener, OnKeyList } R.id.menu_write_sgf -> { - SaveSGFDialog(this).show() + prepareSaveWithPermissionCheck() return true } @@ -262,6 +263,11 @@ open class GoActivity : GobandroidFragmentActivity(), OnTouchListener, OnKeyList return super.onOptionsItemSelected(item) } + @NeedsPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) + fun prepareSave() { + SaveSGFDialog(this).show() + } + @TargetApi(19) fun doPrint() { val printManager = getSystemService(Context.PRINT_SERVICE) as PrintManager diff --git a/android/src/main/java/org/ligi/gobandroid_hd/ui/GobanDroidTVActivity.kt b/android/src/main/java/org/ligi/gobandroid_hd/ui/GobanDroidTVActivity.kt index e6829c6b9..09578512a 100644 --- a/android/src/main/java/org/ligi/gobandroid_hd/ui/GobanDroidTVActivity.kt +++ b/android/src/main/java/org/ligi/gobandroid_hd/ui/GobanDroidTVActivity.kt @@ -9,11 +9,15 @@ import org.ligi.gobandroid_hd.App import org.ligi.gobandroid_hd.InteractionScope import org.ligi.gobandroid_hd.R import org.ligi.gobandroid_hd.ui.application.GobandroidFragmentActivity +import permissions.dispatcher.NeedsPermission +import permissions.dispatcher.OnPermissionDenied +import permissions.dispatcher.RuntimePermissions import java.io.File /** * Activity to replay GO Games in TV / Lean back style */ +@RuntimePermissions open class GobanDroidTVActivity : GobandroidFragmentActivity() { private val path_to_play_from: File by lazy { File(env.reviewPath, "commented") } @@ -21,7 +25,7 @@ open class GobanDroidTVActivity : GobandroidFragmentActivity() { open val intent2start: Intent get() = Intent(this, GobanDroidTVActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) - override fun onCreate(savedInstanceState: Bundle?) { + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) interactionScope.mode = InteractionScope.Mode.TELEVIZE @@ -29,6 +33,11 @@ open class GobanDroidTVActivity : GobandroidFragmentActivity() { App.tracker.init(this) + checkStorageWithPermissionCheck() + } + + @NeedsPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) + fun checkStorage(){ if (path_to_play_from.listFiles() == null) { setContentView(R.layout.empty) App.tracker.trackEvent("intern", "unzip", "gtv", null) @@ -36,7 +45,10 @@ open class GobanDroidTVActivity : GobandroidFragmentActivity() { } else { startTV() } - + } + @OnPermissionDenied(android.Manifest.permission.READ_EXTERNAL_STORAGE) + fun onStorageDenied() { + finish() } private fun startTV() { @@ -71,4 +83,10 @@ open class GobanDroidTVActivity : GobandroidFragmentActivity() { startTV() super.onNewIntent(intent) } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + // NOTE: delegate the permission handling to generated function + onRequestPermissionsResult(requestCode, grantResults) + } } diff --git a/android/src/main/java/org/ligi/gobandroid_hd/ui/application/GobandroidFragmentActivity.kt b/android/src/main/java/org/ligi/gobandroid_hd/ui/application/GobandroidFragmentActivity.kt index 28f7772b1..4c6b10651 100644 --- a/android/src/main/java/org/ligi/gobandroid_hd/ui/application/GobandroidFragmentActivity.kt +++ b/android/src/main/java/org/ligi/gobandroid_hd/ui/application/GobandroidFragmentActivity.kt @@ -234,7 +234,6 @@ open class GobandroidFragmentActivity : AppCompatActivity() { } - override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) onRequestPermissionsResult(requestCode, grantResults)