From 0fa43edfb6235fa98c27df6ff32830aac93313f1 Mon Sep 17 00:00:00 2001 From: Woohyeok Choi Date: Sat, 22 Feb 2020 17:16:23 +0900 Subject: [PATCH] v0.9.9-c --- app/build.gradle | 16 ++++++++-------- .../kaist/iclab/abclogger/AbcApplication.kt | 2 +- .../iclab/abclogger/collector/Commons.kt | 2 +- .../collector/call/CallLogCollector.kt | 10 +++++++++- .../collector/media/MediaCollector.kt | 18 ++++++++++++++---- .../collector/message/MessageCollector.kt | 12 ++++++++++-- .../collector/survey/SurveyCollector.kt | 19 +++++++++++++------ .../collector/traffic/DataTrafficCollector.kt | 3 ++- .../iclab/abclogger/commons/Notifications.kt | 7 +++++++ .../abclogger/ui/config/ConfigViewModel.kt | 1 - .../ui/question/item/CheckBoxesView.kt | 11 +++++++---- .../item/HorizontalRadioButtonsView.kt | 10 ++++++---- .../ui/question/item/RadioButtonsView.kt | 10 ++++++---- .../abclogger/ui/question/item/SliderView.kt | 9 +++++---- .../abclogger/ui/splash/SplashViewModel.kt | 2 ++ build.gradle | 1 + config.gradle | 13 +++++++++++++ 17 files changed, 105 insertions(+), 41 deletions(-) create mode 100644 config.gradle diff --git a/app/build.gradle b/app/build.gradle index b58c73e..249bbe4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,15 +28,15 @@ android { applicationId 'kaist.iclab.abclogger' minSdkVersion 23 targetSdkVersion 29 - versionCode 24 - versionName "0.9.9-a" + versionCode config.version_code + versionName config.version_name setProperty('archivesBaseName', applicationId + "-v" + versionName) - buildConfigField("String", "DB_NAME", "\"abc-logger\"") - buildConfigField("String", "PREF_NAME", "\"abc-logger-pref\"") - buildConfigField("Long", "DB_MAX_SIZE", "3145728L") - buildConfigField("Boolean", "IS_TEST_MODE", "false") - buildConfigField("String", "SERVER_ADDRESS", "\"143.248.100.24:50052\"") - buildConfigField("String", "TEST_SERVER_ADDRESS", "\"143.248.90.87:50055\"") + buildConfigField("String", "DB_NAME", "\"${config.db_name}\"") + buildConfigField("String", "PREF_NAME", "\"${config.pref_name}\"") + buildConfigField("Long", "DB_MAX_SIZE", "${config.db_max_size}L") + buildConfigField("Boolean", "IS_TEST_MODE", "${config.is_test_mode}") + buildConfigField("String", "SERVER_ADDRESS", "\"${config.server_address}\"") + buildConfigField("String", "TEST_SERVER_ADDRESS", "\"${config.test_server_address}\"") } buildTypes { release { diff --git a/app/src/main/kotlin/kaist/iclab/abclogger/AbcApplication.kt b/app/src/main/kotlin/kaist/iclab/abclogger/AbcApplication.kt index 47fdb1a..7b67451 100644 --- a/app/src/main/kotlin/kaist/iclab/abclogger/AbcApplication.kt +++ b/app/src/main/kotlin/kaist/iclab/abclogger/AbcApplication.kt @@ -21,7 +21,7 @@ class AbcApplication : Application() { AbcCollector.bind(this@AbcApplication) if (BuildConfig.IS_TEST_MODE) { - Debug.generateEntities(500000) + Debug.generateSurveyEntities(50) } } } diff --git a/app/src/main/kotlin/kaist/iclab/abclogger/collector/Commons.kt b/app/src/main/kotlin/kaist/iclab/abclogger/collector/Commons.kt index e9b0b4e..ea8e83b 100644 --- a/app/src/main/kotlin/kaist/iclab/abclogger/collector/Commons.kt +++ b/app/src/main/kotlin/kaist/iclab/abclogger/collector/Commons.kt @@ -72,7 +72,7 @@ fun toHash(input: String, start: Int = 0, end: Int = input.length, algorithm: St if (safeStart >= safeEnd || safeEnd > input.length) return input - val subString = input.substring(safeEnd, input.length - 1).toByteArray() + val subString = try { input.substring(safeEnd, input.length - 1).toByteArray() } catch (e: Exception) { return input } val bytes = MessageDigest.getInstance(algorithm).digest(subString) return input.substring(safeStart, safeEnd) + "\$" + diff --git a/app/src/main/kotlin/kaist/iclab/abclogger/collector/call/CallLogCollector.kt b/app/src/main/kotlin/kaist/iclab/abclogger/collector/call/CallLogCollector.kt index 45d9b26..2fec1e8 100644 --- a/app/src/main/kotlin/kaist/iclab/abclogger/collector/call/CallLogCollector.kt +++ b/app/src/main/kotlin/kaist/iclab/abclogger/collector/call/CallLogCollector.kt @@ -5,6 +5,7 @@ import android.content.Context import android.content.Intent import android.database.ContentObserver import android.os.Handler +import android.os.HandlerThread import android.provider.CallLog import androidx.core.database.getIntOrNull import androidx.core.database.getLongOrNull @@ -50,7 +51,14 @@ class CallLogCollector(private val context: Context) : BaseCollector setStatus(Status(lastTimeAccessedMms = timestamp)) } } - private val smsObserver: ContentObserver = object : ContentObserver(Handler()) { + private val handler : Handler + get() { + val thread = HandlerThread(this::class.java.name) + thread.start() + return Handler(thread.looper) + } + + private val smsObserver: ContentObserver = object : ContentObserver(handler) { override fun onChange(selfChange: Boolean) { super.onChange(selfChange) handleSmsRetrieval() } } - private val mmsObserver: ContentObserver = object : ContentObserver(Handler()) { + private val mmsObserver: ContentObserver = object : ContentObserver(handler) { override fun onChange(selfChange: Boolean) { super.onChange(selfChange) handleMmsRetrieval() diff --git a/app/src/main/kotlin/kaist/iclab/abclogger/collector/survey/SurveyCollector.kt b/app/src/main/kotlin/kaist/iclab/abclogger/collector/survey/SurveyCollector.kt index ddeac09..6a7827a 100644 --- a/app/src/main/kotlin/kaist/iclab/abclogger/collector/survey/SurveyCollector.kt +++ b/app/src/main/kotlin/kaist/iclab/abclogger/collector/survey/SurveyCollector.kt @@ -139,10 +139,10 @@ class SurveyCollector(private val context: Context) : BaseCollector scheduleSurvey(setting) } + updateSettings(event)?.let { updatedSettings -> + setStatus(Status(settings = updatedSettings)) + updatedSettings.forEach { setting -> scheduleSurvey(setting) } + } } private suspend fun cancelAll() { @@ -239,8 +239,8 @@ class SurveyCollector(private val context: Context) : BaseCollector? { val startTime = getStatus()?.startTime ?: return null - - return getStatus()?.settings?.mapNotNull { setting -> + val prevSettings = getStatus()?.settings + val newSettings = prevSettings?.mapNotNull { setting -> setting.json?.let { json -> Survey.fromJson(json) }?.let { survey -> when (survey) { is IntervalBasedSurvey -> updateIntervalBasedSurvey(survey = survey, setting = setting, startTime = startTime) @@ -250,6 +250,13 @@ class SurveyCollector(private val context: Context) : BaseCollector + val newSetting= newSettings?.find { setting -> prevSetting.id == setting.id } + newSetting != prevSetting + } ?: false + + return if (isUpdated) newSettings else prevSettings } private fun updateIntervalBasedSurvey(survey: IntervalBasedSurvey, diff --git a/app/src/main/kotlin/kaist/iclab/abclogger/collector/traffic/DataTrafficCollector.kt b/app/src/main/kotlin/kaist/iclab/abclogger/collector/traffic/DataTrafficCollector.kt index f9ac594..2960bf7 100644 --- a/app/src/main/kotlin/kaist/iclab/abclogger/collector/traffic/DataTrafficCollector.kt +++ b/app/src/main/kotlin/kaist/iclab/abclogger/collector/traffic/DataTrafficCollector.kt @@ -11,6 +11,7 @@ import kaist.iclab.abclogger.collector.BaseCollector import kaist.iclab.abclogger.collector.BaseStatus import kaist.iclab.abclogger.collector.fill import kotlinx.coroutines.launch +import java.util.concurrent.Executors import java.util.concurrent.atomic.AtomicLong import kotlin.reflect.KClass @@ -44,7 +45,7 @@ class DataTrafficCollector(private val context: Context) : BaseCollector - edtEtc.isEnabled = isChecked + setOnCheckedChangeListener { view, isChecked -> + edtEtc.isEnabled = isChecked && view.isEnabled + edtEtc.hint = if (edtEtc.isEnabled) context.getString(R.string.general_free_text) else null attrChanged?.onChange() } } private val edtEtc: TextInputEditText = TextInputEditText(context).apply { id = View.generateViewId() - setHint(R.string.general_free_text) setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text)) addTextChangedListener({ _, _, _, _ -> }, { _, _, _, _ -> attrChanged?.onChange() }, {}) + isEnabled = false + hint = null } init { @@ -59,7 +62,7 @@ class CheckBoxesView(context: Context, attrs: AttributeSet?) : QuestionView(cont } override fun setAvailable(isAvailable: Boolean) { - (layoutCheckGroup.children + btnEtc + edtEtc).forEach { view -> view.isEnabled = isAvailable } + (layoutCheckGroup.children + btnEtc).forEach { view -> view.isEnabled = isAvailable } } override fun setShowEtc(showEtc: Boolean) { diff --git a/app/src/main/kotlin/kaist/iclab/abclogger/ui/question/item/HorizontalRadioButtonsView.kt b/app/src/main/kotlin/kaist/iclab/abclogger/ui/question/item/HorizontalRadioButtonsView.kt index 28035a1..f1de426 100644 --- a/app/src/main/kotlin/kaist/iclab/abclogger/ui/question/item/HorizontalRadioButtonsView.kt +++ b/app/src/main/kotlin/kaist/iclab/abclogger/ui/question/item/HorizontalRadioButtonsView.kt @@ -21,17 +21,19 @@ class HorizontalRadioButtonsView(context: Context, attributeSet: AttributeSet?) private val edtEtc: EditText = EditText(context).apply { id = View.generateViewId() - setHint(R.string.general_free_text) setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text)) addTextChangedListener({ _, _, _, _ -> }, { _, _, _, _ -> attrChanged?.onChange() }, {}) + isEnabled = false + hint = null } private val btnEtc: CheckBox = CheckBox(context).apply { id = View.generateViewId() text = context.getString(R.string.general_etc) setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text)) - setOnCheckedChangeListener { _, isChecked -> - edtEtc.isEnabled = isChecked + setOnCheckedChangeListener { view, isChecked -> + edtEtc.isEnabled = isChecked && view.isEnabled + edtEtc.hint = if (isChecked) context.getString(R.string.general_free_text) else null layoutRadioGroup.isEnabled = !isChecked layoutRadioGroup.children.forEach { (it as? CompoundButton)?.isEnabled = !isChecked } attrChanged?.onChange() @@ -61,7 +63,7 @@ class HorizontalRadioButtonsView(context: Context, attributeSet: AttributeSet?) } override fun setAvailable(isAvailable: Boolean) { - (layoutRadioGroup.children + btnEtc + edtEtc).forEach { view -> view.isEnabled = isAvailable } + (layoutRadioGroup.children + btnEtc).forEach { view -> view.isEnabled = isAvailable } } override fun setShowEtc(showEtc: Boolean) { diff --git a/app/src/main/kotlin/kaist/iclab/abclogger/ui/question/item/RadioButtonsView.kt b/app/src/main/kotlin/kaist/iclab/abclogger/ui/question/item/RadioButtonsView.kt index 2cb7ca7..ddbfed0 100644 --- a/app/src/main/kotlin/kaist/iclab/abclogger/ui/question/item/RadioButtonsView.kt +++ b/app/src/main/kotlin/kaist/iclab/abclogger/ui/question/item/RadioButtonsView.kt @@ -19,17 +19,19 @@ class RadioButtonsView(context: Context, attributeSet: AttributeSet?) : Question private val edtEtc: EditText = EditText(context).apply { id = View.generateViewId() - setHint(R.string.general_free_text) setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text)) addTextChangedListener({ _, _, _, _ -> }, { _, _, _, _ -> attrChanged?.onChange() }, {}) + isEnabled = false + hint = null } private val btnEtc: CheckBox = CheckBox(context).apply { id = View.generateViewId() text = context.getString(R.string.general_etc) setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text)) - setOnCheckedChangeListener { _, isChecked -> - edtEtc.isEnabled = isChecked + setOnCheckedChangeListener { view, isChecked -> + edtEtc.isEnabled = isChecked && view.isEnabled + edtEtc.hint = if (isChecked) context.getString(R.string.general_free_text) else null layoutRadioGroup.isEnabled = !isChecked layoutRadioGroup.children.forEach { (it as? CompoundButton)?.isEnabled = !isChecked } attrChanged?.onChange() @@ -59,7 +61,7 @@ class RadioButtonsView(context: Context, attributeSet: AttributeSet?) : Question } override fun setAvailable(isAvailable: Boolean) { - (layoutRadioGroup.children + btnEtc + edtEtc).forEach { view -> view.isEnabled = isAvailable } + (layoutRadioGroup.children + btnEtc).forEach { view -> view.isEnabled = isAvailable } } override fun setShowEtc(showEtc: Boolean) { diff --git a/app/src/main/kotlin/kaist/iclab/abclogger/ui/question/item/SliderView.kt b/app/src/main/kotlin/kaist/iclab/abclogger/ui/question/item/SliderView.kt index 8e42ee4..dae0fc5 100644 --- a/app/src/main/kotlin/kaist/iclab/abclogger/ui/question/item/SliderView.kt +++ b/app/src/main/kotlin/kaist/iclab/abclogger/ui/question/item/SliderView.kt @@ -33,8 +33,9 @@ class SliderView(context: Context, attrs: AttributeSet?) : QuestionView(context, id = View.generateViewId() text = context.getString(R.string.general_etc) setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text)) - setOnCheckedChangeListener { _, isChecked -> - edtEtc.isEnabled = isChecked + setOnCheckedChangeListener { view, isChecked -> + edtEtc.isEnabled = isChecked && view.isEnabled + edtEtc.hint = if (isChecked) context.getString(R.string.general_free_text) else null seekBar.isEnabled = !isChecked attrChanged?.onChange() } @@ -42,9 +43,10 @@ class SliderView(context: Context, attrs: AttributeSet?) : QuestionView(context, private val edtEtc: EditText = EditText(context).apply { id = View.generateViewId() - setHint(R.string.general_free_text) setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.txt_size_text)) addTextChangedListener({ _, _, _, _ -> }, { _, _, _, _ -> attrChanged?.onChange() }, {}) + isEnabled = false + hint = null } init { @@ -70,7 +72,6 @@ class SliderView(context: Context, attrs: AttributeSet?) : QuestionView(context, } override fun setAvailable(isAvailable: Boolean) { - edtEtc.isEnabled = isAvailable btnEtc.isEnabled = isAvailable seekBar.isEnabled = isAvailable } diff --git a/app/src/main/kotlin/kaist/iclab/abclogger/ui/splash/SplashViewModel.kt b/app/src/main/kotlin/kaist/iclab/abclogger/ui/splash/SplashViewModel.kt index 0adc9bb..223efc6 100644 --- a/app/src/main/kotlin/kaist/iclab/abclogger/ui/splash/SplashViewModel.kt +++ b/app/src/main/kotlin/kaist/iclab/abclogger/ui/splash/SplashViewModel.kt @@ -53,6 +53,8 @@ class SplashViewModel(private val permissions: Array, ui { nav?.navigateFirebaseAuth(user) } } catch (e: Exception) { + e.printStackTrace() + ui { nav?.navigateError(e) } } } diff --git a/build.gradle b/build.gradle index ebf44c0..fb60f48 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,5 @@ buildscript { + apply from: 'config.gradle' repositories { google() jcenter() diff --git a/config.gradle b/config.gradle new file mode 100644 index 0000000..10476ba --- /dev/null +++ b/config.gradle @@ -0,0 +1,13 @@ +ext.config = [:] +def config = [:] + +config.version_code = 26 +config.version_name = "0.9.9-c" +config.is_test_mode = false +config.server_address = "143.248.100.24:50052" +config.test_server_address = "143.248.100.24:50052" +config.db_max_size = 3145728L +config.db_name = "abc-logger" +config.pref_name = "abc-logger-pref" + +ext.config = config