Skip to content

Commit

Permalink
update 1.4.0
Browse files Browse the repository at this point in the history
add: advanced settings, translation to German
improve: color picker, value seekbar
fix: some strings
  • Loading branch information
vadiole committed Apr 27, 2021
1 parent ed254da commit fe1617b
Show file tree
Hide file tree
Showing 25 changed files with 1,088 additions and 266 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId "vadiole.boids2d"
minSdkVersion 21
targetSdkVersion 30
versionCode 8
versionName "1.3.3"
versionCode 9
versionName "1.4.0"
setProperty("archivesBaseName", "Boids2D" + "_v" + versionName + "(" + versionCode + ")")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -70,7 +70,7 @@ dependencies {

implementation 'dev.chrisbanes:insetter-ktx:0.3.1'

implementation 'io.github.vadiole:colorpicker:1.0.1'
implementation 'io.github.vadiole:colorpicker:1.0.2'

testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
Expand Down
73 changes: 55 additions & 18 deletions app/src/main/java/vadiole/boids2d/Config.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package vadiole.boids2d

import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import android.graphics.Color
import androidx.core.content.edit
import vadiole.boids2d.global.DevicePerformance
import vadiole.boids2d.global.extensions.getDouble
import vadiole.boids2d.global.extensions.putDouble
import vadiole.colorpicker.ColorModel


@SuppressLint("StaticFieldLeak")
object Config {
private const val SHARED_PREFERENCES_NAME = "boids2d_config"

Expand All @@ -19,7 +22,6 @@ object Config {
/**
* call on start up to init preferences
*/
@Suppress("DEPRECATION")
fun init(context: Context) {
preferences = context.applicationContext.getSharedPreferences(
SHARED_PREFERENCES_NAME,
Expand All @@ -39,6 +41,7 @@ object Config {
is Long -> edit { putLong(key, value) }
is Double -> edit { putDouble(key, value) }
is DevicePerformance -> edit { putString(key, value.code) }
is ColorModel -> edit { putString(key, value.name) }
else -> throw UnsupportedOperationException("Not yet implemented")
}

Expand All @@ -58,9 +61,9 @@ object Config {
Long::class -> getLong(key, default as? Long ?: -1) as T
Double::class -> getDouble(key, default as? Double ?: -1.0) as T
DevicePerformance::class -> DevicePerformance.lookupByCode(
getString(key, null) ?: (default as? DevicePerformance)?.code
?: DevicePerformance.MEDIUM.code
getString(key, null) ?: (default as DevicePerformance).code
) as T
ColorModel::class -> ColorModel.fromName(getString(key, (default as ColorModel).name)) as T
else -> throw UnsupportedOperationException("Not yet implemented")
}
// endregion
Expand All @@ -71,46 +74,80 @@ object Config {
private const val KEY = "preferenceKey"
var template: String
get() = preferences[KEY, null]
set(value) = run { preferences[KEY] = value }
set(value) = preferences.set(KEY, value)

private const val TUTORIAL_SETTINGS_SHOWN_KEY = "tutorialSettingsShown"
var tutorialSettingsShown: Boolean
get() = preferences[TUTORIAL_SETTINGS_SHOWN_KEY, false]
set(value) = run { preferences[TUTORIAL_SETTINGS_SHOWN_KEY] = value }
set(value) = preferences.set(TUTORIAL_SETTINGS_SHOWN_KEY, value)

private const val TUTORIAL_EXIT_SETTINGS_SHOWN_KEY = "tutorialExitSettingsShown"
var tutorialExitSettingsShown: Boolean
get() = preferences[TUTORIAL_EXIT_SETTINGS_SHOWN_KEY, false]
set(value) = run { preferences[TUTORIAL_EXIT_SETTINGS_SHOWN_KEY] = value }
set(value) = preferences.set(TUTORIAL_EXIT_SETTINGS_SHOWN_KEY, value)


// colors
private const val BOIDS_COLOR_KEY = "boidsColorKey"
var boidsColor: Int
get() = preferences[BOIDS_COLOR_KEY, Color.WHITE]
set(value) = preferences.set(BOIDS_COLOR_KEY, value)

private const val BACKGROUND_COLOR_KEY = "backgroundColorKey"
var backgroundColor: Int
get() = preferences[BACKGROUND_COLOR_KEY, Color.BLACK]
set(value) = preferences.set(BACKGROUND_COLOR_KEY, value)

private const val COLOR_PICKER_MODEL_KEY = "colorPickerModel"
var colorPickerModel: ColorModel
get() = preferences[COLOR_PICKER_MODEL_KEY, ColorModel.HSV]
set(value) = preferences.set(COLOR_PICKER_MODEL_KEY, value)

// settings
private const val BOIDS_COUNT_KEY = "boidsCountKey"
var boidsCount: Int
get() = preferences[BOIDS_COUNT_KEY, 500]
set(value) = run { preferences[BOIDS_COUNT_KEY] = value }

set(value) = preferences.set(BOIDS_COUNT_KEY, value)

private const val BOIDS_SIZE_KEY = "boidsSizeKey"
var boidsSize: Int
get() {
val size = preferences[BOIDS_SIZE_KEY, 3]
return if (size >= 16) 16 else size
}
set(value) = run { preferences[BOIDS_SIZE_KEY] = value }
set(value) = preferences.set(BOIDS_SIZE_KEY, value)

private const val BOIDS_COLOR_KEY = "boidsColorKey"
var boidsColor: Int
get() = preferences[BOIDS_COLOR_KEY, Color.WHITE]
set(value) = run { preferences[BOIDS_COLOR_KEY] = value }
// advanced settings
private const val ADVANCED_EXTENDED_KEY = "advanced_extended"
var advancedExtended: Boolean
get() = preferences[ADVANCED_EXTENDED_KEY, false]
set(value) = preferences.set(ADVANCED_EXTENDED_KEY, value)

private const val BACKGROUND_COLOR_KEY = "backgroundColorKey"
var backgroundColor: Int
get() = preferences[BACKGROUND_COLOR_KEY, Color.BLACK]
set(value) = run { preferences[BACKGROUND_COLOR_KEY] = value }
private const val USER_SEPARATION_KEY = "userSeparation"
var userSeparation: Int
get() = preferences[USER_SEPARATION_KEY, 10]
set(value) = preferences.set(USER_SEPARATION_KEY, value)


private const val USER_ALIGNMENT_KEY = "userAlignment"
var userAlignment: Int
get() = preferences[USER_ALIGNMENT_KEY, 10]
set(value) = preferences.set(USER_ALIGNMENT_KEY, value)

private const val USER_COHESION_KEY = "userCohesion"
var userCohesion: Int
get() = preferences[USER_COHESION_KEY, 10]
set(value) = preferences.set(USER_COHESION_KEY, value)


private const val USER_TARGET_KEY = "userTarget"
var userTarget: Int
get() = preferences[USER_TARGET_KEY, 10]
set(value) = preferences.set(USER_TARGET_KEY, value)

private const val DEVICE_PERFORMANCE_KEY = "devicePerformanceKey"
var devicePerformance: DevicePerformance
get() = preferences[DEVICE_PERFORMANCE_KEY, DevicePerformance.getDevicePerformance()]
set(value) = run { preferences[DEVICE_PERFORMANCE_KEY] = value }
set(value) = preferences.set(DEVICE_PERFORMANCE_KEY, value)

}
5 changes: 2 additions & 3 deletions app/src/main/java/vadiole/boids2d/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.GestureDetectorCompat
import androidx.core.view.isGone
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.logEvent
import vadiole.boids2d.SettingsDialog.Companion.BACK_EVENT_TYPE
Expand All @@ -19,7 +20,6 @@ import vadiole.boids2d.base.BaseDialog
import vadiole.boids2d.boids.BoidsGLSurfaceView
import vadiole.boids2d.boids.BoidsRenderer
import vadiole.boids2d.global.extensions.findDialogByTag
import vadiole.boids2d.global.extensions.hide
import vadiole.boids2d.global.extensions.hideSystemUI


Expand Down Expand Up @@ -57,7 +57,7 @@ class MainActivity : AppCompatActivity(), SettingsDialog.OnDialogInteractionList
setContentView(this)
}
mDetector = GestureDetectorCompat(this, MyGestureListener { event ->
tutorialText.hide()
tutorialText.isGone = true
with(supportFragmentManager) {
val dialog = findDialogByTag("settings") ?: SettingsDialog.newInstance(
event.rawX,
Expand Down Expand Up @@ -90,7 +90,6 @@ class MainActivity : AppCompatActivity(), SettingsDialog.OnDialogInteractionList
}

override fun onWindowFocusChanged(hasFocus: Boolean) {
// super.onWindowFocusChanged(hasFocus)
hideSystemUI()
}

Expand Down
Loading

0 comments on commit fe1617b

Please sign in to comment.