Skip to content

Commit

Permalink
Merge pull request #103 from marcauberer/dev
Browse files Browse the repository at this point in the history
Release of version 1.1.1
  • Loading branch information
marcauberer committed Feb 13, 2021
2 parents e9b7ef8 + fc3a16a commit 71a795b
Show file tree
Hide file tree
Showing 23 changed files with 248 additions and 48 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ If you want to test the library, please visit the sample app on [Google Play](ht
## Usage
The first step for using this library is, to add it to the dependency section in your project:
```gradle
implementation 'com.chillibits:simplesettings:1.1.0'
implementation 'com.chillibits:simplesettings:1.1.1'
// Required dependencies
implementation 'com.google.android.material:material:<latest-version>'
implementation 'androidx.preference:preference:<latest-version>'
implementation 'androidx.preference:preference-ktx:<latest-version>'
```

You also have to register the activity in your manifest:
Expand Down Expand Up @@ -67,6 +67,8 @@ SimpleSettings(this).show {
```
This is especially useful, when you need to generate your preferences at runtime. You can use loops and conditions as you can see above.

*Note: If you want to pass a string / drawable / layout with its resource id, please use the properties with the `Res` suffix. For example: `titleRes = R.string.app_name`.*

*Note: It is not mandatory to pass keys to each preference. In this cases, the library does auto-generate a key by converting the title of each preference to CamelCase.*<br>
**Examples**:
```
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.5.0-beta01'

// Google dependencies
implementation 'com.google.android.material:material:1.3.0-rc01'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

// Test dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class MainActivity : AppCompatActivity(), SimpleSettingsConfig.OptionsItemSelect
// Programmatic settings data (especially useful for generating settings options at runtime)
SimpleSettings(this, config).show {
Section {
title = "Section"
titleRes = R.string.app_name
for (i in 1..numberOfSwitchPreferences) {
SwitchPref {
title = "SwitchPreference $i"
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/

buildscript {
ext.library_version = '1.1.0'
ext.library_version_code = 1100
ext.kotlin_version = '1.4.21-2'
ext.library_version = '1.1.1'
ext.library_version_code = 1101
ext.kotlin_version = '1.4.30'
repositories {
google()
jcenter()
Expand Down
6 changes: 3 additions & 3 deletions simplesettings/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ dependencies {
implementation 'androidx.activity:activity-ktx:1.2.0-rc01'

// Google dependencies
api 'com.google.android.material:material:1.2.1'
api 'com.google.android.material:material:1.3.0'
api 'androidx.preference:preference-ktx:1.1.1'

// External dependencies
api 'com.mikepenz:aboutlibraries-core:8.7.0'
api 'com.mikepenz:aboutlibraries:8.7.0@aar'
api 'com.mikepenz:aboutlibraries-core:8.8.0'
api 'com.mikepenz:aboutlibraries:8.8.0@aar'
api 'com.mikepenz:fastadapter:5.3.2'
api 'com.github.ibrahimsn98:live-preferences:1.9'
api 'com.github.skydoves:colorpickerpreference:2.0.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ package com.chillibits.simplesettings.core
import android.content.Context
import android.content.Intent
import androidx.annotation.XmlRes
import com.chillibits.simplesettings.core.elements.PreferenceElement
import com.chillibits.simplesettings.core.elements.PreferenceHeader
import com.chillibits.simplesettings.core.elements.PreferenceSection
import com.chillibits.simplesettings.ui.SimpleSettingsActivity

class SimpleSettings(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chillibits.simplesettings.core
package com.chillibits.simplesettings.core.elements

import android.content.Context

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.chillibits.simplesettings.core
package com.chillibits.simplesettings.core.elements

import android.content.Context
import androidx.annotation.LayoutRes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
* Copyright © Marc Auberer 2020-2021. All rights reserved
*/

package com.chillibits.simplesettings.core
package com.chillibits.simplesettings.core.elements

import android.content.Context
import androidx.annotation.StringRes
import com.chillibits.simplesettings.core.SimpleSettings
import com.chillibits.simplesettings.item.SimplePreference

/**
Expand All @@ -14,11 +16,15 @@ import com.chillibits.simplesettings.item.SimplePreference
class PreferencePage(
private val context: Context,
iconSpaceReservedByDefault: Boolean
): SimplePreference(iconSpaceReservedByDefault) {
): SimplePreference(context, iconSpaceReservedByDefault) {

// Attributes
var subSections = ArrayList<PreferenceElement>()

var activityTitle = ""
@StringRes var activityTitleRes = 0
set(value) { activityTitle = context.getString(value) }

var displayHomeAsUpEnabled = true

// ----------------------------------- Preference section --------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* Copyright © Marc Auberer 2020-2021. All rights reserved
*/

package com.chillibits.simplesettings.core
package com.chillibits.simplesettings.core.elements

import android.content.Context
import androidx.annotation.StringRes
import com.chillibits.simplesettings.item.*

/**
Expand All @@ -18,7 +19,11 @@ class PreferenceSection(

// Attributes
var title = ""
@StringRes var titleRes = 0
set(value) { title = context.getString(value) }

var enabled = true

val items = ArrayList<SimplePreference>()

// ----------------------------------------- Item types ----------------------------------------
Expand All @@ -38,7 +43,7 @@ class PreferenceSection(
* More information: https://github.com/marcauberer/simple-settings/wiki/SimpleTextPreference
*/
fun TextPref(func: SimpleTextPreference.() -> Unit)
= SimpleTextPreference(iconSpaceReserved).apply {
= SimpleTextPreference(context, iconSpaceReserved).apply {
func()
items.add(this)
}
Expand All @@ -48,7 +53,7 @@ class PreferenceSection(
* More information: https://github.com/marcauberer/simple-settings/wiki/SimpleSwitchPreference
*/
fun SwitchPref(func: SimpleSwitchPreference.() -> Unit)
= SimpleSwitchPreference(iconSpaceReserved).apply {
= SimpleSwitchPreference(context, iconSpaceReserved).apply {
func()
items.add(this)
}
Expand All @@ -58,7 +63,7 @@ class PreferenceSection(
* More information: https://github.com/marcauberer/simple-settings/wiki/SimpleCheckboxPreference
*/
fun CheckboxPref(func: SimpleCheckboxPreference.() -> Unit)
= SimpleCheckboxPreference(iconSpaceReserved).apply {
= SimpleCheckboxPreference(context, iconSpaceReserved).apply {
func()
items.add(this)
}
Expand All @@ -68,7 +73,7 @@ class PreferenceSection(
* More information: https://github.com/marcauberer/simple-settings/wiki/SimpleInputPreference
*/
fun InputPref(func: SimpleInputPreference.() -> Unit)
= SimpleInputPreference(iconSpaceReserved).apply {
= SimpleInputPreference(context, iconSpaceReserved).apply {
func()
items.add(this)
}
Expand All @@ -78,7 +83,7 @@ class PreferenceSection(
* More information: https://github.com/marcauberer/simple-settings/wiki/SimpleListPreference
*/
fun ListPref(func: SimpleListPreference.() -> Unit)
= SimpleListPreference(iconSpaceReserved).apply {
= SimpleListPreference(context, iconSpaceReserved).apply {
func()
items.add(this)
}
Expand All @@ -88,7 +93,7 @@ class PreferenceSection(
* More information: https://github.com/marcauberer/simple-settings/wiki/SimpleMSListPreference
*/
fun MSListPref(func: SimpleMSListPreference.() -> Unit)
= SimpleMSListPreference(iconSpaceReserved).apply {
= SimpleMSListPreference(context, iconSpaceReserved).apply {
func()
items.add(this)
}
Expand All @@ -98,7 +103,7 @@ class PreferenceSection(
* More information: https://github.com/marcauberer/simple-settings/wiki/SimpleDropDownPreference
*/
fun DropDownPref(func: SimpleDropDownPreference.() -> Unit)
= SimpleDropDownPreference(iconSpaceReserved).apply {
= SimpleDropDownPreference(context, iconSpaceReserved).apply {
func()
items.add(this)
}
Expand All @@ -107,7 +112,7 @@ class PreferenceSection(
* Seek Bar Preference. For selecting a number between two customizable bounds.
* More information: https://github.com/marcauberer/simple-settings/wiki/SimpleSeekbarPreference
*/
fun SeekBarPref(func: SimpleSeekBarPreference.() -> Unit) = SimpleSeekBarPreference(iconSpaceReserved).apply {
fun SeekBarPref(func: SimpleSeekBarPreference.() -> Unit) = SimpleSeekBarPreference(context, iconSpaceReserved).apply {
func()
items.add(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@

package com.chillibits.simplesettings.item

import android.content.Context
import androidx.annotation.StringRes

class SimpleCheckboxPreference(
private val context: Context,
iconSpaceReservedByDefault: Boolean
): SimplePreference(iconSpaceReservedByDefault) {
): SimplePreference(context, iconSpaceReservedByDefault) {

// Attributes
var defaultValue = OFF

var summaryOn = ""
@StringRes
var summaryOnRes = 0
set(value) { summaryOn = context.getString(value) }

var summaryOff = ""
@StringRes
var summaryOffRes = 0
set(value) { summaryOff = context.getString(value) }

companion object {
const val OFF = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
package com.chillibits.simplesettings.item

import android.content.Context
import androidx.annotation.StringRes
import com.chillibits.simplesettings.R

class SimpleColorPreference(
context: Context,
private val context: Context,
iconSpaceReservedByDefault: Boolean
): SimplePreference(iconSpaceReservedByDefault) {
): SimplePreference(context, iconSpaceReservedByDefault) {

// Attributes
var attachAlphaSlideBar = false

var attachBrightnessSlideBar = false

var colorBoxRadius = 26.0

var dialogNegative = context.getString(R.string.cancel)
@StringRes
var dialogNegativeRes = 0
set(value) { dialogNegative = context.getString(value) }

var dialogPositive = context.getString(R.string.ok)
@StringRes
var dialogPositiveRes = 0
set(value) { dialogPositive = context.getString(value) }

var dialogTitle = title
@StringRes
var dialogTitleRes = 0
set(value) { dialogTitle = context.getString(value) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

package com.chillibits.simplesettings.item

import android.content.Context
import androidx.annotation.ArrayRes

class SimpleDropDownPreference(
private val context: Context,
iconSpaceReservedByDefault: Boolean
): SimplePreference(iconSpaceReservedByDefault) {
): SimplePreference(context, iconSpaceReservedByDefault) {

// Attributes
var defaultIndex = 0

var simpleSummaryProvider = false
var entries: List<String> = emptyList()

var entries = emptyList<String>()
@ArrayRes var entriesRes = 0
set(value) { entries = context.resources.getStringArray(value).toList() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,35 @@

package com.chillibits.simplesettings.item

import android.content.Context
import android.graphics.drawable.Drawable
import androidx.annotation.DrawableRes
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes

class SimpleInputPreference(
private val context: Context,
iconSpaceReservedByDefault: Boolean
): SimplePreference(iconSpaceReservedByDefault) {
): SimplePreference(context, iconSpaceReservedByDefault) {

// Attributes
var defaultValue = ""
@StringRes var defaultValueRes = 0
set(value) { defaultValue = context.getString(value) }

var dialogTitle = ""
@StringRes var dialogTitleRes = 0
set(value) { dialogTitle = context.getString(value) }

var dialogMessage: String? = null
@StringRes var dialogMessageRes = 0
set(value) { dialogMessage = context.getString(value) }

var dialogIcon: Drawable? = null
@DrawableRes
var dialogIconRes = 0
var dialogIcon: Drawable? = null
@LayoutRes
var dialogLayoutRes = 0
set(value) { dialogIcon = context.getDrawable(value) }

@LayoutRes var dialogLayoutRes = 0
var simpleSummaryProvider = false
}

0 comments on commit 71a795b

Please sign in to comment.