-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#17 in progress - custom rute from assets
- Loading branch information
Showing
17 changed files
with
158 additions
and
19 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
app/src/main/java/pl/marianjureczko/poszukiwacz/activity/main/CustomInitializerForRoute.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,64 @@ | ||
package pl.marianjureczko.poszukiwacz.activity.main | ||
|
||
import android.content.res.AssetManager | ||
import pl.marianjureczko.poszukiwacz.shared.StorageHelper | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import java.io.InputStream | ||
|
||
class CustomInitializerForRoute( | ||
val storageHelper: StorageHelper, | ||
val assetManager: AssetManager | ||
) { | ||
companion object { | ||
const val routeName = "custom" | ||
} | ||
private val markerFile = "copied_marker.txt" | ||
private val pathToDestination = storageHelper.pathToRoutesDir() + File.separator | ||
fun copyRouteToLocalStorage() { | ||
if (!isAlreadyCopied()) { | ||
copyRouteDefinition() | ||
copyPhotosAndSounds() | ||
markIsCopied() | ||
} | ||
} | ||
|
||
private fun copyRouteDefinition() { | ||
val inputStream = assetManager.open("$routeName.xml") | ||
copy(inputStream, storageHelper.getRouteFile(routeName)) | ||
} | ||
|
||
private fun copyPhotosAndSounds() { | ||
val route = storageHelper.loadRoute(routeName) | ||
route.treasures.forEach { td -> | ||
td.photoFileName?.let { photoFileName -> | ||
val inputToPhoto = assetManager.open(photoFileName) | ||
copy(inputToPhoto, File(pathToDestination + photoFileName)) | ||
td.photoFileName = pathToDestination + photoFileName | ||
} | ||
td.tipFileName?.let { soundFileName -> | ||
val inputToSound = assetManager.open(soundFileName) | ||
copy(inputToSound, File(pathToDestination + soundFileName)) | ||
td.tipFileName = pathToDestination + soundFileName | ||
} | ||
} | ||
storageHelper.save(route) | ||
} | ||
|
||
private fun isAlreadyCopied(): Boolean { | ||
return File(pathToDestination + markerFile).exists() | ||
} | ||
|
||
private fun markIsCopied() { | ||
File(pathToDestination + markerFile).createNewFile() | ||
} | ||
|
||
private fun copy(inputStream: InputStream, outputFile: File) { | ||
val outputStream = FileOutputStream(outputFile) | ||
inputStream.use { input -> | ||
outputStream.use { output -> | ||
input.copyTo(output) | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
File renamed without changes.
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,22 @@ | ||
<route> | ||
<name>custom</name> | ||
<treasures class="java.util.ArrayList"> | ||
<treasureDescription> | ||
<id>1</id> | ||
<latitude>50.501055</latitude> | ||
<longitude>18.180191</longitude> | ||
<photoFileName>photo_3035c809-d834-4dc6-a7ef-c8a0b670b945.jpg</photoFileName> | ||
<tipFileName>sound_ddaa89a4-2925-45a1-a5a1-93f72c04aeff.3gp</tipFileName> | ||
<qrCode>k01abc</qrCode> | ||
<movieFileName>kalinowice_01.mp4</movieFileName> | ||
</treasureDescription> | ||
<treasureDescription> | ||
<id>2</id> | ||
<latitude>50.505667</latitude> | ||
<longitude>18.185020</longitude> | ||
<photoFileName>photo_2185c623-ef91-4e00-b1fc-3c6d4082d1be.jpg</photoFileName> | ||
<tipFileName>sound_72686712-ceb1-40b6-a420-2d4016bf3872.3gp</tipFileName> | ||
<movieFileName>kalinowice_01.mp4</movieFileName> | ||
</treasureDescription> | ||
</treasures> | ||
</route> |
Binary file not shown.
Binary file added
BIN
+84.5 KB
assets/kalinowice/assets/photo_2185c623-ef91-4e00-b1fc-3c6d4082d1be.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+117 KB
assets/kalinowice/assets/photo_3035c809-d834-4dc6-a7ef-c8a0b670b945.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.27 KB
assets/kalinowice/assets/sound_72686712-ceb1-40b6-a420-2d4016bf3872.3gp
Binary file not shown.
Binary file added
BIN
+11 KB
assets/kalinowice/assets/sound_ddaa89a4-2925-45a1-a5a1-93f72c04aeff.3gp
Binary file not shown.
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