Skip to content

Commit

Permalink
Mega update for demo app.
Browse files Browse the repository at this point in the history
  • Loading branch information
slambang committed May 12, 2022
1 parent 038faca commit 2f06739
Show file tree
Hide file tree
Showing 65 changed files with 400 additions and 388 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.6.21'
ext.gradle_version = '7.1.3'
ext.hilt_version = '2.38.1'

ext.minimum_supported_android_version = 16

repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "com.android.tools.build:gradle:$gradle_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
}
Expand Down
11 changes: 5 additions & 6 deletions jarvis-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ plugins {
}

android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
compileSdkVersion 32
buildToolsVersion "32.0.0"

defaultConfig {
applicationId "com.jarvis.app"
minSdkVersion 21
targetSdkVersion 31
minSdkVersion minimum_supported_android_version
targetSdkVersion 32
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

buildConfigField "Boolean", "IS_JARVIS_ACTIVE_DEFAULT", "true"
buildConfigField "Boolean", "IS_JARVIS_LOCKED_DEFAULT", "false"

buildConfigField "String", "JARVIS_CONFIG_AUTHORITY", "\"${JARVIS_CONFIG_AUTHORITY}\""

manifestPlaceholders = [
Expand Down Expand Up @@ -54,7 +53,7 @@ dependencies {
implementation "com.google.android.material:material:1.5.0"
implementation "androidx.core:core-ktx:1.7.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.5.0-alpha05"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.5.0-beta01"
implementation "androidx.fragment:fragment-ktx:1.4.1"

implementation "com.google.dagger:hilt-android:$hilt_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class JarvisContentProvider : ReadOnlyContentProvider() {
}

companion object {
private const val TAG = "[JARVIS APP]"
private const val TAG = "[JARVIS]"

private const val PATH_VALUE = "value"
private const val JARVIS_CONFIG_FILE_URI = "jarvis_config_file_uri"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import javax.inject.Inject

@OptIn(ExperimentalSerializationApi::class)
class AppJsonMapper @Inject constructor() {

fun readConfig(inputStream: InputStream): JarvisConfig =
Json.decodeFromStream(inputStream)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class JarvisAppSettings(
class SettingsRepository @Inject constructor(
@ApplicationContext context: Context
) {
private val prefs = context.getSharedPreferences("jarvis_settings", Context.MODE_PRIVATE)
private val prefs = context.getSharedPreferences("jarvis_app_settings", Context.MODE_PRIVATE)

private val _state = MutableStateFlow(getLatestModel())
val toFlow: Flow<JarvisAppSettings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,64 +27,20 @@ class UpdateFieldUseCase @Inject constructor(
isPublished: Boolean
): JarvisField<*> =
when (jarvisField) {

is StringField ->
StringField(
jarvisField.type,
jarvisField.name,
newValue as String,
jarvisField.defaultValue,
jarvisField.description,
isPublished,
jarvisField.hint,
jarvisField.minLength,
jarvisField.maxLength,
jarvisField.regex
)
jarvisField.copy(value = newValue as String, isPublished = isPublished)

is LongField ->
LongField(
jarvisField.type,
jarvisField.name,
newValue as Long,
jarvisField.defaultValue,
jarvisField.description,
isPublished,
jarvisField.hint,
jarvisField.min,
jarvisField.max,
jarvisField.asRange
)
jarvisField.copy(value = newValue as Long, isPublished = isPublished)

is DoubleField ->
DoubleField(
jarvisField.type,
jarvisField.name,
newValue as Double,
jarvisField.defaultValue,
jarvisField.description,
isPublished,
jarvisField.hint,
jarvisField.min,
jarvisField.max,
jarvisField.asRange
)
jarvisField.copy(value = newValue as Double, isPublished = isPublished)

is BooleanField ->
BooleanField(
jarvisField.type,
jarvisField.name,
newValue as Boolean,
jarvisField.defaultValue,
jarvisField.description,
isPublished
)
jarvisField.copy(value = newValue as Boolean, isPublished = isPublished)

is StringListField ->
StringListField(
jarvisField.type,
jarvisField.name,
jarvisField.value,
jarvisField.defaultValue,
jarvisField.description,
isPublished,
jarvisField.defaultSelection,
newValue as Int
)
jarvisField.copy(currentSelection = newValue as Int, isPublished = isPublished)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,32 @@ package com.jarvis.app.view.main.editfielddialog

import android.content.Context
import android.view.View
import android.widget.TextView
import com.google.android.material.switchmaterial.SwitchMaterial
import com.jarvis.app.R
import com.jarvis.app.view.main.BooleanFieldItemViewModel

class EditBooleanFieldView(
private val item: BooleanFieldItemViewModel,
context: Context
context: Context,
private val item: BooleanFieldItemViewModel
) : EditFieldView {

private var container: View =
View.inflate(context, R.layout.view_edit_boolean_field, null)
View.inflate(context, R.layout.view_edit_boolean_field, null).apply {
setOnClickListener {
switch.toggle()
}
}

private var switch: SwitchMaterial =
container.findViewById<SwitchMaterial>(R.id.edit_boolean_switch).apply {
isChecked = item.value
}

private var errorMessageView: TextView =
container.findViewById(R.id.edit_boolean_error_message)

override val view: View = container

override val value: Any
get() = switch.isChecked

override var error: String = ""

override var isPublished: Boolean = item.isPublished
set(value) {
field = value
Expand All @@ -40,11 +38,5 @@ class EditBooleanFieldView(
switch.isChecked = item.defaultValue
}

override fun isValid(): Boolean {
val errorMessage = item.validate(value as Boolean)
if (errorMessage != null) {
errorMessageView.text = errorMessage
}
return errorMessage == null
}
override fun isValid(): Boolean = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import com.jarvis.app.view.main.DoubleFieldItemViewModel
import com.jarvis.app.view.util.toSafeDouble

class EditDoubleFieldView(
context: Context,
private val item: DoubleFieldItemViewModel,
private val onFieldEmpty: (Boolean) -> Unit,
context: Context
private val onFieldEmpty: (Boolean) -> Unit
) : EditFieldView {

private var container: View =
Expand All @@ -35,12 +35,6 @@ class EditDoubleFieldView(
override val value: Any
get() = textInput.editText!!.text.toString().toSafeDouble(item.defaultValue)

override var error: String = ""
set(value) {
field = value
textInput.error = value
}

override var isPublished: Boolean = item.isPublished
set(value) {
field = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jarvis.app.view.main.editfielddialog

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.CheckBox
import android.widget.FrameLayout
Expand All @@ -14,12 +15,6 @@ import com.jarvis.app.R
import com.jarvis.app.view.main.*
import javax.inject.Inject

/**
* TODO
* Range slider
* signed/unsigned
* Help dialog
*/
class EditFieldDialogFactory @Inject constructor() {

fun getEditFieldDialog(
Expand All @@ -44,8 +39,10 @@ class EditFieldDialogFactory @Inject constructor() {
.create()

with(dialog) {
// TODO This causes the weird click/dismiss issue at the top of the dialog!
window?.setBackgroundDrawableResource(R.drawable.edit_dialog_dialog_background)
window?.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)

setOnShowListener {
val saveButton = getButton(AlertDialog.BUTTON_POSITIVE)
Expand Down Expand Up @@ -114,10 +111,10 @@ class EditFieldDialogFactory @Inject constructor() {
onFieldEmpty: (Boolean) -> Unit,
context: Context
): EditFieldView = when (item) {
is StringFieldItemViewModel -> EditStringFieldView(item, onFieldEmpty, context)
is LongFieldItemViewModel -> EditLongFieldView(item, onFieldEmpty, context)
is DoubleFieldItemViewModel -> EditDoubleFieldView(item, onFieldEmpty, context)
is BooleanFieldItemViewModel -> EditBooleanFieldView(item, context)
is StringListFieldItemViewModel -> EditStringListFieldView(item, context)
is StringFieldItemViewModel -> EditStringFieldView(context, item, onFieldEmpty)
is LongFieldItemViewModel -> EditLongFieldView(context, item, onFieldEmpty)
is DoubleFieldItemViewModel -> EditDoubleFieldView(context, item, onFieldEmpty)
is BooleanFieldItemViewModel -> EditBooleanFieldView(context, item)
is StringListFieldItemViewModel -> EditStringListFieldView(context, item)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.view.View
interface EditFieldView {
val view: View
val value: Any
var error: String
var isPublished: Boolean

fun setDefault()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import com.jarvis.app.view.main.LongFieldItemViewModel
import com.jarvis.app.view.util.toSafeLong

class EditLongFieldView(
context: Context,
private val item: LongFieldItemViewModel,
private val onFieldEmpty: (Boolean) -> Unit,
context: Context
private val onFieldEmpty: (Boolean) -> Unit
) : EditFieldView {

private var container: View =
Expand All @@ -35,12 +35,6 @@ class EditLongFieldView(
override val value: Any
get() = textInput.editText!!.text.toString().toSafeLong(item.defaultValue)

override var error: String = ""
set(value) {
field = value
textInput.error = value
}

override var isPublished: Boolean = item.isPublished
set(value) {
field = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import com.jarvis.app.R
import com.jarvis.app.view.main.StringFieldItemViewModel

class EditStringFieldView(
context: Context,
private val item: StringFieldItemViewModel,
private val onFieldEmpty: (Boolean) -> Unit,
context: Context
private val onFieldEmpty: (Boolean) -> Unit
) : EditFieldView {

private val container =
Expand All @@ -34,12 +34,6 @@ class EditStringFieldView(
override val value: Any
get() = textInput.editText!!.text.toString()

override var error: String = ""
set(value) {
field = value
textInput.error = value
}

override var isPublished: Boolean = item.isPublished
set(value) {
field = value
Expand Down
Loading

0 comments on commit 2f06739

Please sign in to comment.