-
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.
Implement ExternalStorage and extract BinarySerializer
- Loading branch information
1 parent
b3b56b4
commit 86e2206
Showing
22 changed files
with
147 additions
and
28 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
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
1 change: 0 additions & 1 deletion
1
app/src/main/java/me/profiluefter/profinote/data/CSVSerializer.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
37 changes: 37 additions & 0 deletions
37
app/src/main/java/me/profiluefter/profinote/data/ExternalStorage.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,37 @@ | ||
package me.profiluefter.profinote.data | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import java.io.File | ||
import java.io.FileNotFoundException | ||
import javax.inject.Inject | ||
import javax.inject.Named | ||
|
||
private const val TAG = "ExternalStorage" | ||
|
||
class ExternalStorage @Inject constructor( | ||
@ApplicationContext private val context: Context, | ||
@Named("fileName") private val fileName: String | ||
) : Storage { | ||
override suspend fun store(data: ByteArray) = withContext(Dispatchers.IO) { | ||
val externalStorage = context.getExternalFilesDir(null) | ||
val file = File(externalStorage!!.absolutePath + File.separator + fileName) | ||
Log.i(TAG, "Saving data to ${file.absolutePath}!") | ||
file.writeBytes(data) | ||
} | ||
|
||
override suspend fun get(): ByteArray? = withContext(Dispatchers.IO) { | ||
val externalStorage = context.getExternalFilesDir(null) | ||
try { | ||
val file = File(externalStorage!!.absolutePath + File.separator + fileName) | ||
Log.i(TAG, "Trying to read data from ${file.absolutePath}!") | ||
file.readBytes() | ||
} catch (e: FileNotFoundException) { | ||
Log.w(TAG, "File not found.") | ||
null | ||
} | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
app/src/main/java/me/profiluefter/profinote/data/SampleSerializer.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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,31 @@ | ||
plugins { | ||
id 'org.jetbrains.kotlin.jvm' | ||
id 'java-library' | ||
id 'org.jetbrains.dokka' version '1.4.20' | ||
} | ||
|
||
dependencies { | ||
implementation 'javax.inject:javax.inject:1' | ||
} | ||
|
||
task srcZip(type: Zip) { | ||
archiveAppendix = "src" | ||
destinationDirectory = file("$buildDir/output") | ||
from sourceSets*.allSource | ||
} | ||
|
||
jar { | ||
destinationDirectory = file("$buildDir/output") | ||
} | ||
|
||
tasks.named("dokkaHtml") { | ||
outputDirectory = file("$buildDir/dokka") | ||
} | ||
|
||
task docZip(type: Zip, dependsOn: [dokkaHtml]) { | ||
archiveAppendix = "doc" | ||
destinationDirectory = file("$buildDir/output") | ||
from file("$buildDir/dokka") | ||
} | ||
|
||
task generateZIPs(dependsOn: [jar, srcZip, docZip]) |
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
2 changes: 1 addition & 1 deletion
2
.../me/profiluefter/profinote/models/Note.kt → ...va/me/profiluefter/profinote/data/Note.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
2 changes: 0 additions & 2 deletions
2
...profiluefter/profinote/data/Serializer.kt → ...profiluefter/profinote/data/Serializer.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
3 changes: 3 additions & 0 deletions
3
...me/profiluefter/profinote/data/Storage.kt → ...me/profiluefter/profinote/data/Storage.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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include ':app' | ||
include ':data-lib' | ||
rootProject.name = "Notian" |