mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-11 13:11:01 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/13935: Enhanced File Type List Icons (https://github.com/mozilla-mobile/fenix/pull/14036)
* For https://github.com/mozilla-mobile/fenix/issues/13935: Enhanced File Type List Icons * For https://github.com/mozilla-mobile/fenix/issues/13935 - Pulls out and tests logic for getting the icon for a DownloadItem Co-authored-by: Kate Glazko <kglazko@Kates-MacBook-Pro.local> Co-authored-by: Jeff Boek <jeff@jeffboek.com>
This commit is contained in:
parent
728d78bf10
commit
dc44991fea
48
app/src/main/java/org/mozilla/fenix/ext/DownloadItem.kt
Normal file
48
app/src/main/java/org/mozilla/fenix/ext/DownloadItem.kt
Normal file
@ -0,0 +1,48 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.ext
|
||||
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.library.downloads.DownloadItem
|
||||
|
||||
// While this looks complex, it's actually pretty simple.
|
||||
@SuppressWarnings("ComplexMethod")
|
||||
fun DownloadItem.getIcon(): Int {
|
||||
fun getIconCornerCases(fileName: String?): Int {
|
||||
return when {
|
||||
fileName?.endsWith("apk") == true -> R.drawable.ic_file_type_apk
|
||||
fileName?.endsWith("zip") == true -> R.drawable.ic_file_type_zip
|
||||
else -> R.drawable.ic_file_type_default
|
||||
}
|
||||
}
|
||||
|
||||
fun checkForApplicationArchiveSubtypes(contentType: String): Int? {
|
||||
return when {
|
||||
contentType.contains("rar") -> R.drawable.ic_file_type_zip
|
||||
contentType.contains("zip") -> R.drawable.ic_file_type_zip
|
||||
contentType.contains("7z") -> R.drawable.ic_file_type_zip
|
||||
contentType.contains("tar") -> R.drawable.ic_file_type_zip
|
||||
contentType.contains("freearc") -> R.drawable.ic_file_type_zip
|
||||
contentType.contains("octet-stream") -> null
|
||||
contentType.contains("vnd.android.package-archive") -> null
|
||||
else -> R.drawable.ic_file_type_document
|
||||
}
|
||||
}
|
||||
|
||||
fun getIconFromContentType(contentType: String): Int? {
|
||||
return when {
|
||||
contentType.contains("image/") -> R.drawable.ic_file_type_image
|
||||
contentType.contains("audio/") -> R.drawable.ic_file_type_audio_note
|
||||
contentType.contains("video/") -> R.drawable.ic_file_type_video
|
||||
contentType.contains("application/") -> checkForApplicationArchiveSubtypes(contentType)
|
||||
contentType.contains("text/") -> R.drawable.ic_file_type_document
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
return contentType?.let { contentType ->
|
||||
getIconFromContentType(contentType)
|
||||
} ?: getIconCornerCases(fileName)
|
||||
}
|
@ -14,6 +14,7 @@ import org.mozilla.fenix.library.SelectionHolder
|
||||
import org.mozilla.fenix.library.downloads.DownloadInteractor
|
||||
import org.mozilla.fenix.library.downloads.DownloadItem
|
||||
import mozilla.components.feature.downloads.toMegabyteString
|
||||
import org.mozilla.fenix.ext.getIcon
|
||||
|
||||
class DownloadsListItemViewHolder(
|
||||
view: View,
|
||||
@ -34,7 +35,7 @@ class DownloadsListItemViewHolder(
|
||||
itemView.download_layout.changeSelected(item in selectionHolder.selectedItems)
|
||||
|
||||
itemView.overflow_menu.hideAndDisable()
|
||||
itemView.favicon.setImageResource(R.drawable.ic_download_default)
|
||||
itemView.favicon.setImageResource(item.getIcon())
|
||||
itemView.favicon.isClickable = false
|
||||
|
||||
this.item = item
|
||||
|
12
app/src/main/res/drawable/ic_file_type_apk.xml
Normal file
12
app/src/main/res/drawable/ic_file_type_apk.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M16.9,9.634l1.665,-2.883a0.347,0.347 0,0 0,-0.6 -0.347L16.281,9.323a10.472,10.472 0,0 0,-8.562 0L6.034,6.4a0.347,0.347 0,0 0,-0.6 0.347L7.1,9.634A9.826,9.826 0,0 0,2 17.5L22,17.5A9.826,9.826 0,0 0,16.9 9.634ZM7.4,14.65a0.833,0.833 0,1 1,0.833 -0.833A0.833,0.833 0,0 1,7.4 14.65ZM16.606,14.65a0.833,0.833 0,1 1,0.832 -0.833A0.832,0.832 0,0 1,16.6 14.65Z"/>
|
||||
</vector>
|
13
app/src/main/res/drawable/ic_file_type_audio_note.xml
Normal file
13
app/src/main/res/drawable/ic_file_type_audio_note.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M18,3H9A2,2 0,0 0,7 5V15.171a3.077,3.077 0,0 0,-1.95 -0.025A2.927,2.927 0,0 0,3.131 17.1,3.009 3.009,0 0,0 5.98,21 3.139,3.139 0,0 0,9 17.788V7h9v8.171a3.077,3.077 0,0 0,-1.952 -0.024A2.925,2.925 0,0 0,14.131 17.1a3.008,3.008 0,0 0,2.85 3.9A3.139,3.139 0,0 0,20 17.788V5A2,2 0,0 0,18 3Z"
|
||||
android:fillType="evenOdd"/>
|
||||
</vector>
|
12
app/src/main/res/drawable/ic_file_type_default.xml
Normal file
12
app/src/main/res/drawable/ic_file_type_default.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M18,22H6a3,3 0,0 1,-3 -3V5A3,3 0,0 1,6 2H18a3,3 0,0 1,3 3V19A3,3 0,0 1,18 22ZM6,4A1,1 0,0 0,5 5V19a1,1 0,0 0,1 1H18a1,1 0,0 0,1 -1V5a1,1 0,0 0,-1 -1Z"/>
|
||||
</vector>
|
24
app/src/main/res/drawable/ic_file_type_document.xml
Normal file
24
app/src/main/res/drawable/ic_file_type_document.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M18,2L6,2A3,3 0,0 0,3 5L3,19a3,3 0,0 0,3 3L18,22a3,3 0,0 0,3 -3L21,5A3,3 0,0 0,18 2ZM19,19a1,1 0,0 1,-1 1L6,20a1,1 0,0 1,-1 -1L5,5A1,1 0,0 1,6 4L18,4a1,1 0,0 1,1 1Z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M9.5,6L9.5,6A1.5,1.5 0,0 1,11 7.5L11,7.5A1.5,1.5 0,0 1,9.5 9L9.5,9A1.5,1.5 0,0 1,8 7.5L8,7.5A1.5,1.5 0,0 1,9.5 6z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M15.5,11h-7a0.5,0.5 0,0 0,0 1h7a0.5,0.5 0,0 0,0 -1Z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M15.5,14h-7a0.5,0.5 0,0 0,0 1h7a0.5,0.5 0,0 0,0 -1Z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M11.5,17h-3a0.5,0.5 0,0 0,0 1h3a0.5,0.5 0,0 0,0 -1Z"/>
|
||||
</vector>
|
18
app/src/main/res/drawable/ic_file_type_image.xml
Normal file
18
app/src/main/res/drawable/ic_file_type_image.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M15.455,9.826a0.573,0.573 0,0 0,-0.912 0L12.275,12.65a0.584,0.584 0,0 1,-0.684 0.188l-2.273,-0.952a0.576,0.576 0,0 0,-0.594 0.09l-2.5,2.087A0.621,0.621 0,0 0,6 14.55V16.5a0.5,0.5 0,0 0,0.5 0.5h11a0.5,0.5 0,0 0,0.5 -0.5V13.225a0.61,0.61 0,0 0,-0.144 -0.4Z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M8.5,9.25m-1.25,0a1.25,1.25 0,1 1,2.5 0a1.25,1.25 0,1 1,-2.5 0"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M19,3L5,3A3,3 0,0 0,2 6L2,18a3,3 0,0 0,3 3L19,21a3,3 0,0 0,3 -3L22,6A3,3 0,0 0,19 3ZM20,18a1,1 0,0 1,-1 1L5,19a1,1 0,0 1,-1 -1L4,6A1,1 0,0 1,5 5L19,5a1,1 0,0 1,1 1Z"/>
|
||||
</vector>
|
12
app/src/main/res/drawable/ic_file_type_video.xml
Normal file
12
app/src/main/res/drawable/ic_file_type_video.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M18.622,11.134 L6.5,4.135A1,1 0,0 0,5 5V19a1,1 0,0 0,1.5 0.867l12.122,-7A1,1 0,0 0,18.622 11.134Z"/>
|
||||
</vector>
|
21
app/src/main/res/drawable/ic_file_type_zip.xml
Normal file
21
app/src/main/res/drawable/ic_file_type_zip.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,6h2v2h-2z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M10,8h2v2h-2z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M10.5,12a0.5,0.5 0,0 0,-0.5 0.5v5a0.5,0.5 0,0 0,0.5 0.5h3a0.5,0.5 0,0 0,0.5 -0.5V10H12v2ZM13,17H11V15h2Z"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M18,2L6,2A3,3 0,0 0,3 5L3,19a3,3 0,0 0,3 3L18,22a3,3 0,0 0,3 -3L21,5A3,3 0,0 0,18 2ZM19,19a1,1 0,0 1,-1 1L6,20a1,1 0,0 1,-1 -1L5,5A1,1 0,0 1,6 4h4L10,6h2L12,4h6a1,1 0,0 1,1 1Z"/>
|
||||
</vector>
|
@ -0,0 +1,27 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.ext
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.library.downloads.DownloadItem
|
||||
|
||||
class DownloadItemKtTest {
|
||||
@Test
|
||||
fun getIcon() {
|
||||
val downloadItem = DownloadItem(0, "MyAwesomeFile", "", "", "image/png")
|
||||
|
||||
assertEquals(R.drawable.ic_file_type_image, downloadItem.getIcon())
|
||||
assertEquals(R.drawable.ic_file_type_audio_note, downloadItem.copy(contentType = "audio/mp3").getIcon())
|
||||
assertEquals(R.drawable.ic_file_type_video, downloadItem.copy(contentType = "video/mp4").getIcon())
|
||||
assertEquals(R.drawable.ic_file_type_document, downloadItem.copy(contentType = "text/csv").getIcon())
|
||||
assertEquals(R.drawable.ic_file_type_zip, downloadItem.copy(contentType = "application/gzip").getIcon())
|
||||
assertEquals(R.drawable.ic_file_type_apk, downloadItem.copy(contentType = null, fileName = "Fenix.apk").getIcon())
|
||||
assertEquals(R.drawable.ic_file_type_zip, downloadItem.copy(contentType = null, fileName = "Fenix.zip").getIcon())
|
||||
assertEquals(R.drawable.ic_file_type_default, downloadItem.copy(contentType = null, fileName = null).getIcon())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user