small code cleanup
No code behavior has been changed.
This commit is contained in:
@@ -47,9 +47,9 @@ import java.util.Date
|
|||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
companion object {
|
companion object {
|
||||||
val TAG = "MainActivity"
|
const val TAG = "MainActivity"
|
||||||
val UPDATE_EVERY_SECS: Long = 30
|
const val UPDATE_EVERY_SECS: Long = 30
|
||||||
val DEBUG_CHECK_LOGBOOK_CONSISTENCY = false
|
const val DEBUG_CHECK_LOGBOOK_CONSISTENCY = false
|
||||||
}
|
}
|
||||||
|
|
||||||
var logbook: Logbook? = null
|
var logbook: Logbook? = null
|
||||||
@@ -113,19 +113,19 @@ class MainActivity : AppCompatActivity() {
|
|||||||
moreButton.setOnClickListener {
|
moreButton.setOnClickListener {
|
||||||
showOverflowPopupWindow(moreButton)
|
showOverflowPopupWindow(moreButton)
|
||||||
}
|
}
|
||||||
findViewById<View>(R.id.button_no_connection_settings).setOnClickListener({
|
findViewById<View>(R.id.button_no_connection_settings).setOnClickListener {
|
||||||
showSettings()
|
showSettings()
|
||||||
})
|
}
|
||||||
findViewById<View>(R.id.button_settings).setOnClickListener({
|
findViewById<View>(R.id.button_settings).setOnClickListener {
|
||||||
showSettings()
|
showSettings()
|
||||||
})
|
}
|
||||||
findViewById<View>(R.id.button_no_connection_retry).setOnClickListener({
|
findViewById<View>(R.id.button_no_connection_retry).setOnClickListener {
|
||||||
// This may happen at start, when logbook is still null: better ask the logbook list
|
// This may happen at start, when logbook is still null: better ask the logbook list
|
||||||
loadLogbookList()
|
loadLogbookList()
|
||||||
})
|
}
|
||||||
findViewById<View>(R.id.button_sync).setOnClickListener({
|
findViewById<View>(R.id.button_sync).setOnClickListener {
|
||||||
loadLogbookList()
|
loadLogbookList()
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setListAdapter(items: ArrayList<LunaEvent>) {
|
private fun setListAdapter(items: ArrayList<LunaEvent>) {
|
||||||
|
@@ -61,9 +61,9 @@ open class SettingsActivity : AppCompatActivity() {
|
|||||||
switchNoBreastfeeding.isChecked = noBreastfeeding
|
switchNoBreastfeeding.isChecked = noBreastfeeding
|
||||||
|
|
||||||
if (webDavCredentials != null) {
|
if (webDavCredentials != null) {
|
||||||
textViewWebDAVUrl.setText(webDavCredentials[0])
|
textViewWebDAVUrl.text = webDavCredentials[0]
|
||||||
textViewWebDAVUser.setText(webDavCredentials[1])
|
textViewWebDAVUser.text = webDavCredentials[1]
|
||||||
textViewWebDAVPass.setText(webDavCredentials[2])
|
textViewWebDAVPass.text = webDavCredentials[2]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ open class SettingsActivity : AppCompatActivity() {
|
|||||||
*/
|
*/
|
||||||
private fun copyLocalLogbooksToWebdav(webDAVLogbookRepository: WebDAVLogbookRepository, listener: OnCopyLocalLogbooksToWebdavFinishedListener) {
|
private fun copyLocalLogbooksToWebdav(webDAVLogbookRepository: WebDAVLogbookRepository, listener: OnCopyLocalLogbooksToWebdavFinishedListener) {
|
||||||
Thread(Runnable {
|
Thread(Runnable {
|
||||||
var errors = StringBuilder()
|
val errors = StringBuilder()
|
||||||
val fileLogbookRepo = FileLogbookRepository()
|
val fileLogbookRepo = FileLogbookRepository()
|
||||||
val logbooks = fileLogbookRepo.getAllLogbooks(this)
|
val logbooks = fileLogbookRepo.getAllLogbooks(this)
|
||||||
for (logbook in logbooks) {
|
for (logbook in logbooks) {
|
||||||
|
@@ -128,7 +128,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "${type} qty: $quantity time: ${Date(time * 1000)}"
|
return "$type qty: $quantity time: ${Date(time * 1000)}"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun compareTo(other: LunaEvent): Int {
|
override fun compareTo(other: LunaEvent): Int {
|
||||||
|
@@ -13,9 +13,9 @@ import java.io.FilenameFilter
|
|||||||
|
|
||||||
class FileLogbookRepository: LogbookRepository {
|
class FileLogbookRepository: LogbookRepository {
|
||||||
companion object {
|
companion object {
|
||||||
val TAG = "FileLogbookRepository"
|
const val TAG = "FileLogbookRepository"
|
||||||
val FILE_NAME_START = "data"
|
const val FILE_NAME_START = "data"
|
||||||
val FILE_NAME_END = ".json"
|
const val FILE_NAME_END = ".json"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadLogbook(context: Context, name: String, listener: LogbookLoadedListener) {
|
override fun loadLogbook(context: Context, name: String, listener: LogbookLoadedListener) {
|
||||||
@@ -32,7 +32,7 @@ class FileLogbookRepository: LogbookRepository {
|
|||||||
fun loadLogbook(context: Context, name: String): Logbook {
|
fun loadLogbook(context: Context, name: String): Logbook {
|
||||||
val logbook = Logbook(name)
|
val logbook = Logbook(name)
|
||||||
val fileName = getFileName(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 json = FileInputStream(file).bufferedReader().use { it.readText() }
|
||||||
val ja = JSONArray(json)
|
val ja = JSONArray(json)
|
||||||
for (i in 0 until ja.length()) {
|
for (i in 0 until ja.length()) {
|
||||||
@@ -58,7 +58,7 @@ class FileLogbookRepository: LogbookRepository {
|
|||||||
|
|
||||||
fun saveLogbook(context: Context, logbook: Logbook) {
|
fun saveLogbook(context: Context, logbook: Logbook) {
|
||||||
val fileName = getFileName(logbook.name)
|
val fileName = getFileName(logbook.name)
|
||||||
val file = File(context.getFilesDir(), fileName)
|
val file = File(context.filesDir, fileName)
|
||||||
val ja = JSONArray()
|
val ja = JSONArray()
|
||||||
for (l in logbook.logs) {
|
for (l in logbook.logs) {
|
||||||
ja.put(l.toJson())
|
ja.put(l.toJson())
|
||||||
@@ -82,7 +82,7 @@ class FileLogbookRepository: LogbookRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun listLogbooks(context: Context): ArrayList<String> {
|
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 {
|
override fun accept(dir: File?, name: String?): Boolean {
|
||||||
if (name == null)
|
if (name == null)
|
||||||
return false
|
return false
|
||||||
|
@@ -7,13 +7,13 @@ import androidx.core.content.edit
|
|||||||
|
|
||||||
class LocalSettingsRepository(val context: Context) {
|
class LocalSettingsRepository(val context: Context) {
|
||||||
companion object {
|
companion object {
|
||||||
val SHARED_PREFS_FILE_NAME = "lunasettings"
|
const val SHARED_PREFS_FILE_NAME = "lunasettings"
|
||||||
val SHARED_PREFS_BB_CONTENT = "bbcontent"
|
const val SHARED_PREFS_BB_CONTENT = "bbcontent"
|
||||||
val SHARED_PREFS_DATA_REPO = "data_repo"
|
const val SHARED_PREFS_DATA_REPO = "data_repo"
|
||||||
val SHARED_PREFS_DAV_URL = "webdav_url"
|
const val SHARED_PREFS_DAV_URL = "webdav_url"
|
||||||
val SHARED_PREFS_DAV_USER = "webdav_user"
|
const val SHARED_PREFS_DAV_USER = "webdav_user"
|
||||||
val SHARED_PREFS_DAV_PASS = "webdav_password"
|
const val SHARED_PREFS_DAV_PASS = "webdav_password"
|
||||||
val SHARED_PREFS_NO_BREASTFEEDING = "no_breastfeeding"
|
const val SHARED_PREFS_NO_BREASTFEEDING = "no_breastfeeding"
|
||||||
}
|
}
|
||||||
enum class DATA_REPO {LOCAL_FILE, WEBDAV}
|
enum class DATA_REPO {LOCAL_FILE, WEBDAV}
|
||||||
val sharedPreferences: SharedPreferences
|
val sharedPreferences: SharedPreferences
|
||||||
@@ -23,7 +23,7 @@ class LocalSettingsRepository(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun saveBabyBottleContent(content: Int) {
|
fun saveBabyBottleContent(content: Int) {
|
||||||
sharedPreferences.edit().putInt(SHARED_PREFS_BB_CONTENT, content).apply()
|
sharedPreferences.edit { putInt(SHARED_PREFS_BB_CONTENT, content) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadBabyBottleContent(): Int {
|
fun loadBabyBottleContent(): Int {
|
||||||
@@ -31,7 +31,7 @@ class LocalSettingsRepository(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun saveNoBreastfeeding(content: Boolean) {
|
fun saveNoBreastfeeding(content: Boolean) {
|
||||||
sharedPreferences.edit().putBoolean(SHARED_PREFS_NO_BREASTFEEDING, content).apply()
|
sharedPreferences.edit { putBoolean(SHARED_PREFS_NO_BREASTFEEDING, content) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadNoBreastfeeding(): Boolean {
|
fun loadNoBreastfeeding(): Boolean {
|
||||||
@@ -39,15 +39,15 @@ class LocalSettingsRepository(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun saveDataRepository(repo: DATA_REPO) {
|
fun saveDataRepository(repo: DATA_REPO) {
|
||||||
val spe = sharedPreferences.edit()
|
sharedPreferences.edit(commit = true) {
|
||||||
spe.putString(
|
putString(
|
||||||
SHARED_PREFS_DATA_REPO,
|
SHARED_PREFS_DATA_REPO,
|
||||||
when (repo) {
|
when (repo) {
|
||||||
DATA_REPO.WEBDAV -> "webdav"
|
DATA_REPO.WEBDAV -> "webdav"
|
||||||
DATA_REPO.LOCAL_FILE -> "localfile"
|
DATA_REPO.LOCAL_FILE -> "localfile"
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
spe.commit()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadDataRepository(): DATA_REPO {
|
fun loadDataRepository(): DATA_REPO {
|
||||||
@@ -60,11 +60,11 @@ class LocalSettingsRepository(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun saveWebdavCredentials(url: String, username: String, password: String) {
|
fun saveWebdavCredentials(url: String, username: String, password: String) {
|
||||||
val spe = sharedPreferences.edit()
|
sharedPreferences.edit(commit = true) {
|
||||||
spe.putString(SHARED_PREFS_DAV_URL, url)
|
putString(SHARED_PREFS_DAV_URL, url)
|
||||||
spe.putString(SHARED_PREFS_DAV_USER, username)
|
putString(SHARED_PREFS_DAV_USER, username)
|
||||||
spe.putString(SHARED_PREFS_DAV_PASS, password)
|
putString(SHARED_PREFS_DAV_PASS, password)
|
||||||
spe.commit()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadWebdavCredentials(): Array<String>? {
|
fun loadWebdavCredentials(): Array<String>? {
|
||||||
|
Reference in New Issue
Block a user