-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
VectorImageType detection
- Loading branch information
Showing
11 changed files
with
153 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/by/overpass/svgtocomposeintellij/domain/VectorImageTypeDetector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package by.overpass.svgtocomposeintellij.domain | ||
|
||
import java.io.File | ||
|
||
interface VectorImageTypeDetector { | ||
|
||
fun detect(path: String): VectorImageType? | ||
|
||
companion object : VectorImageTypeDetector { | ||
|
||
override fun detect(path: String): VectorImageType? { | ||
val files = File(path) | ||
.listFiles { file -> !file.isHidden } | ||
?: return null | ||
return if (files.all { file -> file.extension == "svg" }) { | ||
VectorImageType.SVG | ||
} else if (files.all { file -> file.extension == "xml" }) { | ||
VectorImageType.DRAWABLE | ||
} else { | ||
null | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/test/java/by/overpass/svgtocomposeintellij/domain/VectorImageTypeDetectorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package by.overpass.svgtocomposeintellij.domain | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
|
||
@RunWith(Parameterized::class) | ||
class VectorImageTypeDetectorTest( | ||
private val path: String, | ||
private val expected: VectorImageType?, | ||
) { | ||
|
||
companion object { | ||
|
||
@JvmStatic | ||
@Parameterized.Parameters | ||
fun data(): Collection<Array<Any?>> = listOf( | ||
arrayOf( | ||
"src/test/resources/svg/", | ||
VectorImageType.SVG, | ||
), | ||
arrayOf( | ||
"src/test/resources/xml/", | ||
VectorImageType.DRAWABLE, | ||
), | ||
arrayOf( | ||
"src/test/resources/mixed/", | ||
null, | ||
), | ||
arrayOf( | ||
"src/test/resources/svg-with-hidden-files/", | ||
VectorImageType.SVG, | ||
), | ||
) | ||
} | ||
|
||
private val detector = VectorImageTypeDetector | ||
|
||
@Test | ||
fun test() { | ||
val actual = detector.detect(path) | ||
|
||
assertEquals(expected, actual) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="48dp" | ||
android:height="48dp" | ||
android:viewportWidth="960" | ||
android:viewportHeight="960" | ||
android:tint="?attr/colorControlNormal" | ||
android:autoMirrored="true"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M120,720L120,660L600,660L600,720L120,720ZM120,510L120,450L840,450L840,510L120,510ZM120,300L120,240L840,240L840,300L120,300Z"/> | ||
</vector> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="48dp" | ||
android:height="48dp" | ||
android:viewportWidth="960" | ||
android:viewportHeight="960" | ||
android:tint="?attr/colorControlNormal" | ||
android:autoMirrored="true"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M120,720L120,660L600,660L600,720L120,720ZM120,510L120,450L840,450L840,510L120,510ZM120,300L120,240L840,240L840,300L120,300Z"/> | ||
</vector> |