Skip to content

Commit 6e6c4d1

Browse files
argon2rlukstbit
authored andcommitted
Refactored de-duplicate .csv/.tsv values both in IntentHandler and in ImportFileSelectionFragment.
1 parent 5726c43 commit 6e6c4d1

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import com.ichi2.anki.preferences.sharedPrefs
3232
import com.ichi2.anki.servicelayer.ScopedStorageService
3333
import com.ichi2.anki.services.ReminderService
3434
import com.ichi2.anki.ui.windows.reviewer.ReviewerFragment
35+
import com.ichi2.anki.utils.MimeTypeUtils
3536
import com.ichi2.anki.worker.SyncWorker
3637
import com.ichi2.annotations.NeedsTest
3738
import com.ichi2.libanki.DeckId
@@ -311,14 +312,7 @@ class IntentHandler : AbstractIntentHandler() {
311312
private const val CLIPBOARD_INTENT = "com.ichi2.anki.COPY_DEBUG_INFO"
312313
private const val CLIPBOARD_INTENT_EXTRA_DATA = "clip_data"
313314

314-
private val textMimeTypes =
315-
setOf(
316-
"text/tab-separated-values",
317-
"text/tsv",
318-
"text/comma-separated-values",
319-
"text/csv",
320-
"text/plain",
321-
)
315+
private val textMimeTypes = MimeTypeUtils.CSV_TSV_MIME_TYPES
322316

323317
private fun isValidViewIntent(intent: Intent): Boolean {
324318
// Negating a negative because we want to call specific attention to the fact that it's invalid

AnkiDroid/src/main/java/com/ichi2/anki/dialogs/ImportFileSelectionFragment.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import com.ichi2.anki.AnkiActivity
3131
import com.ichi2.anki.R
3232
import com.ichi2.anki.analytics.UsageAnalytics
3333
import com.ichi2.anki.snackbar.showSnackbar
34+
import com.ichi2.anki.utils.MimeTypeUtils
3435
import com.ichi2.annotations.NeedsTest
35-
import com.ichi2.utils.AssetHelper.TEXT_PLAIN
3636
import com.ichi2.utils.title
3737
import kotlinx.parcelize.Parcelize
3838
import timber.log.Timber
@@ -97,14 +97,7 @@ class ImportFileSelectionFragment : DialogFragment() {
9797
ImportFileType.CSV,
9898
multiple = false,
9999
mimeType = "*/*",
100-
extraMimes =
101-
arrayOf(
102-
TEXT_PLAIN,
103-
"text/comma-separated-values",
104-
"text/csv",
105-
"text/tab-separated-values",
106-
"text/tsv",
107-
),
100+
extraMimes = MimeTypeUtils.CSV_TSV_MIME_TYPES,
108101
),
109102
)
110103
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2025 argon2r <vincentcs008@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify it under
5+
* the terms of the GNU General Public License as published by the Free Software
6+
* Foundation; either version 3 of the License, or (at your option) any later
7+
* version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
10+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11+
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package com.ichi2.anki.utils
18+
19+
object MimeTypeUtils {
20+
val CSV_TSV_MIME_TYPES =
21+
arrayOf(
22+
"text/comma-separated-values",
23+
"text/csv",
24+
"text/tab-separated-values",
25+
"text/tsv",
26+
"text/plain",
27+
)
28+
}

0 commit comments

Comments
 (0)