-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from ProteGO-Safe/release/4.10.0
Release/4.10.0
- Loading branch information
Showing
65 changed files
with
810 additions
and
805 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
60 changes: 60 additions & 0 deletions
60
app/src/main/java/pl/gov/mc/protegosafe/repository/FileRepositoryImpl.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,60 @@ | ||
package pl.gov.mc.protegosafe.repository | ||
|
||
import android.content.Context | ||
import io.reactivex.Completable | ||
import io.reactivex.Single | ||
import pl.gov.mc.protegosafe.domain.repository.FileRepository | ||
import java.io.File | ||
|
||
class FileRepositoryImpl(private val context: Context) : FileRepository { | ||
|
||
/** | ||
* Writes text to file in internal storage | ||
* | ||
* @param fileName File name | ||
* @param text Text to write | ||
*/ | ||
override fun writeInternalFile(fileName: String, text: String): Completable { | ||
return Completable.fromAction { | ||
val file = File(context.filesDir.path + "/$fileName") | ||
if (file.exists().not()) { | ||
file.createNewFile() | ||
} | ||
file.writeText(text) | ||
} | ||
} | ||
|
||
/** | ||
* Reads text from file in internal storage | ||
* | ||
* @param fileName File name | ||
* @return File content | ||
*/ | ||
override fun readInternalFile(fileName: String): Single<String> { | ||
return Single.fromCallable { | ||
val file = File(context.filesDir.path + "/$fileName") | ||
file.readText() | ||
} | ||
} | ||
|
||
/** | ||
* Reads text from file in internal storage or returns empty string on error (eg. missing file) | ||
* | ||
* @param fileName File name | ||
* @return File content or empty string | ||
*/ | ||
override fun readInternalFileOrEmpty(fileName: String): Single<String> { | ||
return readInternalFile(fileName).onErrorReturn { "" } | ||
} | ||
|
||
/** | ||
* Removes all internal files recursively | ||
*/ | ||
override fun clearAllInternalFiles(): Completable { | ||
return Completable.fromAction { | ||
context.filesDir.listFiles()?.forEach { file -> | ||
file.deleteRecursively() | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.