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

Add a skip button for all files access permission #17653

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import com.ichi2.anki.dialogs.DatabaseErrorDialog.DatabaseErrorDialogType.INCOMP
import com.ichi2.anki.dialogs.ImportFileSelectionFragment.ImportOptions
import com.ichi2.anki.isLoggedIn
import com.ichi2.anki.launchCatchingTask
import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.anki.requireAnkiActivity
import com.ichi2.anki.servicelayer.DebugInfoService
import com.ichi2.anki.showImportDialog
Expand Down Expand Up @@ -496,7 +497,10 @@ class DatabaseErrorDialog : AsyncDialogFragment() {

companion object {
/** A dialog which creates a new collection in an unsafe location */
fun displayResetToNewDirectoryDialog(context: AnkiActivity) {
fun displayResetToNewDirectoryDialog(
context: AnkiActivity,
skipButton: Boolean = false,
) {
AlertDialog.Builder(context).show {
title(R.string.backup_new_collection)
setIcon(R.drawable.ic_warning)
Expand All @@ -507,6 +511,11 @@ class DatabaseErrorDialog : AsyncDialogFragment() {
"closeCollection: %s",
"DatabaseErrorDialog: Before Create New Collection",
)
if (skipButton) {
val sharedPrefsEdit = context.sharedPrefs().edit()
sharedPrefsEdit.putBoolean("skipStoragePermission", true)
sharedPrefsEdit.apply()
}
CollectionManager.closeCollectionBlocking()
CollectionHelper.resetAnkiDroidDirectory(context)
context.closeCollectionAndFinish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ class Full30and31PermissionsFragment : PermissionsFragment(R.layout.permissions_
view.findViewById<PermissionItem>(R.id.all_files_permission).setOnSwitchClickListener {
accessAllFilesLauncher.showManageAllFilesScreen()
}
(activity as? PermissionsActivity)?.setSkipButtonVisible(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import android.os.Parcelable
import androidx.activity.addCallback
import androidx.appcompat.widget.AppCompatButton
import androidx.core.content.IntentCompat
import androidx.core.view.isVisible
import androidx.fragment.app.commit
import com.ichi2.anki.AnkiActivity
import com.ichi2.anki.PermissionSet
import com.ichi2.anki.R
import com.ichi2.anki.dialogs.DatabaseErrorDialog.UninstallListItem.Companion.displayResetToNewDirectoryDialog
import com.ichi2.themes.Themes
import com.ichi2.themes.setTransparentStatusBar

Expand Down Expand Up @@ -55,6 +57,10 @@ class PermissionsActivity : AnkiActivity() {
finish()
}

findViewById<AppCompatButton>(R.id.skip_button).setOnClickListener {
displayResetToNewDirectoryDialog(ankiActivity, true)
}

val permissionSet =
requireNotNull(IntentCompat.getParcelableExtra(intent, PERMISSIONS_SET_EXTRA, PermissionSet::class.java)) {
"PERMISSIONS_SET_EXTRA not set"
Expand All @@ -75,6 +81,10 @@ class PermissionsActivity : AnkiActivity() {
findViewById<AppCompatButton>(R.id.continue_button).isEnabled = isEnabled
}

fun setSkipButtonVisible(isVisible: Boolean) {
findViewById<AppCompatButton>(R.id.skip_button).isVisible = isVisible
}

companion object {
const val PERMISSIONS_SET_EXTRA = "permissionsSet"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ class TiramisuPermissionsFragment : PermissionsFragment(R.layout.permissions_tir
view.findViewById<PermissionItem>(R.id.all_files_permission).setOnSwitchClickListener {
accessAllFilesLauncher.showManageAllFilesScreen()
}
(activity as? PermissionsActivity)?.setSkipButtonVisible(true)
}
}
3 changes: 2 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/utils/Permissions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.ichi2.anki.IntentHandler
import com.ichi2.anki.common.utils.android.isRobolectric
import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.compat.CompatHelper.Companion.getPackageInfoCompat
import com.ichi2.compat.PackageInfoFlagsCompat
import timber.log.Timber
Expand Down Expand Up @@ -174,7 +175,7 @@ object Permissions {

fun canManageExternalStorage(context: Context): Boolean {
// TODO: See if we can move this to a testing manifest
if (isRobolectric) {
if (isRobolectric or context.sharedPrefs().getBoolean("skipStoragePermission", false)) {
return false
}
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
Expand Down
12 changes: 12 additions & 0 deletions AnkiDroid/src/main/res/layout/permissions_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
/>
</ScrollView>

<com.google.android.material.button.MaterialButton
android:id="@+id/skip_button"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:paddingVertical="12dp"
android:text="@string/dialog_skip"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/permissions_scroll_area"
/>

<com.google.android.material.button.MaterialButton
android:id="@+id/continue_button"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/03-dialogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<string name="dialog_keep">Keep</string>
<string name="dialog_remove">Remove</string>
<string name="dialog_continue">Continue</string>
<string name="dialog_skip">Skip</string>
<string name="dialog_processing">Processing…</string>
<string name="dialog_positive_create" comment="Create a new collection, probably erasing the previous one, may be necessary in case of error.">Create</string>
<string name="dialog_positive_delete" maxLength="28">Delete</string>
Expand Down
Loading