small code cleanup
No code behavior has been changed.
This commit is contained in:
@@ -13,9 +13,9 @@ import java.io.FilenameFilter
|
||||
|
||||
class FileLogbookRepository: LogbookRepository {
|
||||
companion object {
|
||||
val TAG = "FileLogbookRepository"
|
||||
val FILE_NAME_START = "data"
|
||||
val FILE_NAME_END = ".json"
|
||||
const val TAG = "FileLogbookRepository"
|
||||
const val FILE_NAME_START = "data"
|
||||
const val FILE_NAME_END = ".json"
|
||||
}
|
||||
|
||||
override fun loadLogbook(context: Context, name: String, listener: LogbookLoadedListener) {
|
||||
@@ -32,7 +32,7 @@ class FileLogbookRepository: LogbookRepository {
|
||||
fun loadLogbook(context: Context, name: String): Logbook {
|
||||
val logbook = Logbook(name)
|
||||
val fileName = getFileName(name)
|
||||
val file = File(context.getFilesDir(), fileName)
|
||||
val file = File(context.filesDir, fileName)
|
||||
val json = FileInputStream(file).bufferedReader().use { it.readText() }
|
||||
val ja = JSONArray(json)
|
||||
for (i in 0 until ja.length()) {
|
||||
@@ -58,7 +58,7 @@ class FileLogbookRepository: LogbookRepository {
|
||||
|
||||
fun saveLogbook(context: Context, logbook: Logbook) {
|
||||
val fileName = getFileName(logbook.name)
|
||||
val file = File(context.getFilesDir(), fileName)
|
||||
val file = File(context.filesDir, fileName)
|
||||
val ja = JSONArray()
|
||||
for (l in logbook.logs) {
|
||||
ja.put(l.toJson())
|
||||
@@ -82,7 +82,7 @@ class FileLogbookRepository: LogbookRepository {
|
||||
}
|
||||
|
||||
private fun listLogbooks(context: Context): ArrayList<String> {
|
||||
val logbooksFileNames = context.getFilesDir().list(object: FilenameFilter {
|
||||
val logbooksFileNames = context.filesDir.list(object: FilenameFilter {
|
||||
override fun accept(dir: File?, name: String?): Boolean {
|
||||
if (name == null)
|
||||
return false
|
||||
|
||||
@@ -7,13 +7,13 @@ import androidx.core.content.edit
|
||||
|
||||
class LocalSettingsRepository(val context: Context) {
|
||||
companion object {
|
||||
val SHARED_PREFS_FILE_NAME = "lunasettings"
|
||||
val SHARED_PREFS_BB_CONTENT = "bbcontent"
|
||||
val SHARED_PREFS_DATA_REPO = "data_repo"
|
||||
val SHARED_PREFS_DAV_URL = "webdav_url"
|
||||
val SHARED_PREFS_DAV_USER = "webdav_user"
|
||||
val SHARED_PREFS_DAV_PASS = "webdav_password"
|
||||
val SHARED_PREFS_NO_BREASTFEEDING = "no_breastfeeding"
|
||||
const val SHARED_PREFS_FILE_NAME = "lunasettings"
|
||||
const val SHARED_PREFS_BB_CONTENT = "bbcontent"
|
||||
const val SHARED_PREFS_DATA_REPO = "data_repo"
|
||||
const val SHARED_PREFS_DAV_URL = "webdav_url"
|
||||
const val SHARED_PREFS_DAV_USER = "webdav_user"
|
||||
const val SHARED_PREFS_DAV_PASS = "webdav_password"
|
||||
const val SHARED_PREFS_NO_BREASTFEEDING = "no_breastfeeding"
|
||||
}
|
||||
enum class DATA_REPO {LOCAL_FILE, WEBDAV}
|
||||
val sharedPreferences: SharedPreferences
|
||||
@@ -23,7 +23,7 @@ class LocalSettingsRepository(val context: Context) {
|
||||
}
|
||||
|
||||
fun saveBabyBottleContent(content: Int) {
|
||||
sharedPreferences.edit().putInt(SHARED_PREFS_BB_CONTENT, content).apply()
|
||||
sharedPreferences.edit { putInt(SHARED_PREFS_BB_CONTENT, content) }
|
||||
}
|
||||
|
||||
fun loadBabyBottleContent(): Int {
|
||||
@@ -31,7 +31,7 @@ class LocalSettingsRepository(val context: Context) {
|
||||
}
|
||||
|
||||
fun saveNoBreastfeeding(content: Boolean) {
|
||||
sharedPreferences.edit().putBoolean(SHARED_PREFS_NO_BREASTFEEDING, content).apply()
|
||||
sharedPreferences.edit { putBoolean(SHARED_PREFS_NO_BREASTFEEDING, content) }
|
||||
}
|
||||
|
||||
fun loadNoBreastfeeding(): Boolean {
|
||||
@@ -39,15 +39,15 @@ class LocalSettingsRepository(val context: Context) {
|
||||
}
|
||||
|
||||
fun saveDataRepository(repo: DATA_REPO) {
|
||||
val spe = sharedPreferences.edit()
|
||||
spe.putString(
|
||||
SHARED_PREFS_DATA_REPO,
|
||||
when (repo) {
|
||||
DATA_REPO.WEBDAV -> "webdav"
|
||||
DATA_REPO.LOCAL_FILE -> "localfile"
|
||||
}
|
||||
)
|
||||
spe.commit()
|
||||
sharedPreferences.edit(commit = true) {
|
||||
putString(
|
||||
SHARED_PREFS_DATA_REPO,
|
||||
when (repo) {
|
||||
DATA_REPO.WEBDAV -> "webdav"
|
||||
DATA_REPO.LOCAL_FILE -> "localfile"
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun loadDataRepository(): DATA_REPO {
|
||||
@@ -60,11 +60,11 @@ class LocalSettingsRepository(val context: Context) {
|
||||
}
|
||||
|
||||
fun saveWebdavCredentials(url: String, username: String, password: String) {
|
||||
val spe = sharedPreferences.edit()
|
||||
spe.putString(SHARED_PREFS_DAV_URL, url)
|
||||
spe.putString(SHARED_PREFS_DAV_USER, username)
|
||||
spe.putString(SHARED_PREFS_DAV_PASS, password)
|
||||
spe.commit()
|
||||
sharedPreferences.edit(commit = true) {
|
||||
putString(SHARED_PREFS_DAV_URL, url)
|
||||
putString(SHARED_PREFS_DAV_USER, username)
|
||||
putString(SHARED_PREFS_DAV_PASS, password)
|
||||
}
|
||||
}
|
||||
|
||||
fun loadWebdavCredentials(): Array<String>? {
|
||||
|
||||
Reference in New Issue
Block a user