Skip to content

Commit

Permalink
Refactored de-duplicate .csv/.tsv values both in IntentHandler and in…
Browse files Browse the repository at this point in the history
… ImportFileSelectionFragment.
  • Loading branch information
argon2r committed Feb 3, 2025
1 parent f5b3d33 commit afa70f5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
10 changes: 2 additions & 8 deletions AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.anki.servicelayer.ScopedStorageService
import com.ichi2.anki.services.ReminderService
import com.ichi2.anki.ui.windows.reviewer.ReviewerFragment
import com.ichi2.anki.utils.MimeTypeUtils
import com.ichi2.anki.worker.SyncWorker
import com.ichi2.annotations.NeedsTest
import com.ichi2.libanki.DeckId
Expand Down Expand Up @@ -299,14 +300,7 @@ class IntentHandler : AbstractIntentHandler() {
private const val CLIPBOARD_INTENT = "com.ichi2.anki.COPY_DEBUG_INFO"
private const val CLIPBOARD_INTENT_EXTRA_DATA = "clip_data"

private val textMimeTypes =
setOf(
"text/tab-separated-values",
"text/tsv",
"text/comma-separated-values",
"text/csv",
"text/plain",
)
private val textMimeTypes = MimeTypeUtils.CSV_TSV_MIME_TYPES

private fun isValidViewIntent(intent: Intent): Boolean {
// Negating a negative because we want to call specific attention to the fact that it's invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import com.ichi2.anki.AnkiActivity
import com.ichi2.anki.R
import com.ichi2.anki.analytics.UsageAnalytics
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.utils.MimeTypeUtils
import com.ichi2.annotations.NeedsTest
import com.ichi2.utils.AssetHelper.TEXT_PLAIN
import com.ichi2.utils.title
import kotlinx.parcelize.Parcelize
import timber.log.Timber
Expand Down Expand Up @@ -95,16 +95,7 @@ class ImportFileSelectionFragment : DialogFragment() {
R.string.import_csv,
UsageAnalytics.Actions.IMPORT_CSV_FILE,
ImportFileType.CSV,
multiple = false,
mimeType = "*/*",
extraMimes =
arrayOf(
TEXT_PLAIN,
"text/comma-separated-values",
"text/csv",
"text/tab-separated-values",
"text/tsv",
),
extraMimes = MimeTypeUtils.CSV_TSV_MIME_TYPES,
),
)
}
Expand Down
27 changes: 27 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/utils/MimeTypeUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 argon2r <vincentcs008@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.ichi2.anki.utils

object MimeTypeUtils {
val CSV_TSV_MIME_TYPES =
arrayOf(
"text/comma-separated-values",
"text/csv",
"text/tab-separated-values",
"text/tsv",
)
}

0 comments on commit afa70f5

Please sign in to comment.