Skip to content

Commit

Permalink
Smth
Browse files Browse the repository at this point in the history
  • Loading branch information
Deaths-Door committed Dec 25, 2022
1 parent e57a67a commit 1c55bc9
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 79 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

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

23 changes: 3 additions & 20 deletions app/src/main/java/com/deathsdoor/myapplication/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
package com.deathsdoor.myapplication

import android.os.Bundle
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import com.deathsdoor.myapplication.databinding.ActivityMainBinding
import com.deathsdoor.myapplication.databinding.ActivityMainBinding.inflate
import com.deathsdoor.ui_core.public.SettingBuilder.SwitchSetting
import com.deathsdoor.ui_core.public.createAttributeSet
import com.deathsdoor.ui_core.widgets.Switch
import org.xmlpull.v1.XmlPullParserFactory
import com.deathsdoor.ui_core.public.SettingBuilder

class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = inflate(layoutInflater)
setContentView(binding.root)

val parserFactory = XmlPullParserFactory.newInstance()
val parser = parserFactory.newPullParser()
parser.setInput(AttributeSetInputStream(attrs), null)
val xmlBlockParser = XmlBlock.Parser.newInstance(parser)


binding.root.addView(
Switch(this,
SwitchSetting(
title = "Switch Setting",
shortDescription = "This is a switch setting"
).createAttributeSet()
)
)
// SettingBuilder.show(binding.root.id,R.layout.setting_test,supportFragmentManager)
// SettingBuilder.show(binding.root.id,R.layout.setting_test,supportFragmentManager)
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">My Application</string>
<string name="app_name">Setting-UI Library Test</string>
</resources>
10 changes: 6 additions & 4 deletions ui-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ plugins {

android {
compileSdk 33

defaultConfig {
minSdk 16
targetSdk 32
Expand All @@ -19,7 +18,6 @@ android {
minCompileSdk = 16
}
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -41,6 +39,7 @@ android {
}
}


dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
Expand All @@ -59,7 +58,7 @@ dependencies {
publishing {
publications {
maven(MavenPublication) {
groupId = "com.deathsdoor"
groupId = "com.github.deathsdoor"
artifactId = "ui-core"
version = "1.0"
afterEvaluate {
Expand All @@ -73,4 +72,7 @@ publishing {
url = uri("${project.buildDir}/repo")
}
}
}
}



5 changes: 1 addition & 4 deletions ui-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deathsdoor.ui_core">

</manifest>
<manifest package="com.deathsdoor.ui_core" />
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.deathsdoor.ui_core.extras.functinos.extensions

import com.deathsdoor.ui_core.R
import com.deathsdoor.ui_core.extras.interfaces.OnSwitchToggleListener

/*
object AttributesBuilder {
class AttributeSet(
private val attributes: Map<String, Any>) : android.util.AttributeSet {
Expand Down Expand Up @@ -86,4 +86,4 @@ object AttributesBuilder {
return value
}
}
}
}*/
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
package com.deathsdoor.ui_core.public

import android.graphics.Color
import android.widget.Toast
import androidx.fragment.app.FragmentManager
import com.deathsdoor.ui_core.extras.fragments.SettingsFragment
import com.deathsdoor.ui_core.extras.functinos.extensions.AttributesBuilder
import com.deathsdoor.ui_core.extras.interfaces.OnSwitchToggleListener
import com.google.android.material.switchmaterial.SwitchMaterial

const val NON_NESTED_SETTING = "non_nested"

object SettingBuilder {
fun show(rootID:Int, layout:Int,fragmentManager: FragmentManager) = fragmentManager.beginTransaction().replace(rootID, SettingsFragment.newInstance(layout),NON_NESTED_SETTING).commit()
}

/*fun SwitchSetting(
title: String,
shortDescription: String,
detailedDescription: String = shortDescription,
useShortDescription: Boolean = true,
switchChecked: Boolean = false,
switchOnColor: Int = Color.GREEN,
switchOffColor: Int = Color.RED,
showWarnWhenSwitchToggledOn: Boolean = false,
showWarnWhenSwitchToggledOff: Boolean = false,
showWarnWhenSwitchToggledOnMsg: String = "WARNING",
showWarnWhenSwitchToggledOffMsg: String = "WARNING",
toggleListener: OnSwitchToggleListener = object : OnSwitchToggleListener {
override fun onSwitchToggleOn(switchView: SwitchMaterial) { if(showWarnWhenSwitchToggledOn) Toast.makeText(switchView.context,showWarnWhenSwitchToggledOnMsg, Toast.LENGTH_SHORT).show() }
override fun onSwitchToggleOff(switchView: SwitchMaterial) { if(showWarnWhenSwitchToggledOff) Toast.makeText(switchView.context,showWarnWhenSwitchToggledOffMsg, Toast.LENGTH_SHORT).show() }
}
): CustomSettingView = CustomSettingView(TYPE.SWITCH,
mapOf(
"title" to title,
"shortDescription" to shortDescription,
"detailedDescription" to detailedDescription,
"useShortDescription" to useShortDescription,
"switchChecked" to switchChecked,
"switchOnColor" to switchOnColor,
"switchOffColor" to switchOffColor,
"showWarnWhenSwitchToggledOn" to showWarnWhenSwitchToggledOn,
"showWarnWhenSwitchToggledOff" to showWarnWhenSwitchToggledOff,
"showWarnWhenSwitchToggledOnMsg" to showWarnWhenSwitchToggledOnMsg,
"showWarnWhenSwitchToggledOffMsg" to showWarnWhenSwitchToggledOffMsg,
"toggleListener" to toggleListener
)
)*/
/*
data class CustomSettingView(val type:TYPE,val extraAttributes:Map<String,Any>)
enum class TYPE{
Expand All @@ -18,46 +50,6 @@ enum class TYPE{
CATEGORY,
TEXTINPUT
}

object SettingBuilder {
//For non-nested settings or settings where all attributes aer given via xml
fun show(rootID:Int, layout:Int,fragmentManager: FragmentManager)
= fragmentManager.beginTransaction().replace(rootID, SettingsFragment.newInstance(layout),NON_NESTED_SETTING).commit()

fun SwitchSetting(
title: String,
shortDescription: String,
detailedDescription: String = shortDescription,
useShortDescription: Boolean = true,
switchChecked: Boolean = false,
switchOnColor: Int = Color.GREEN,
switchOffColor: Int = Color.RED,
showWarnWhenSwitchToggledOn: Boolean = false,
showWarnWhenSwitchToggledOff: Boolean = false,
showWarnWhenSwitchToggledOnMsg: String = "WARNING",
showWarnWhenSwitchToggledOffMsg: String = "WARNING",
toggleListener: OnSwitchToggleListener = object : OnSwitchToggleListener {
override fun onSwitchToggleOn(switchView: SwitchMaterial) { if(showWarnWhenSwitchToggledOn) Toast.makeText(switchView.context,showWarnWhenSwitchToggledOnMsg, Toast.LENGTH_SHORT).show() }
override fun onSwitchToggleOff(switchView: SwitchMaterial) { if(showWarnWhenSwitchToggledOff) Toast.makeText(switchView.context,showWarnWhenSwitchToggledOffMsg, Toast.LENGTH_SHORT).show() }
}
): CustomSettingView = CustomSettingView(TYPE.SWITCH,
mapOf(
"title" to title,
"shortDescription" to shortDescription,
"detailedDescription" to detailedDescription,
"useShortDescription" to useShortDescription,
"switchChecked" to switchChecked,
"switchOnColor" to switchOnColor,
"switchOffColor" to switchOffColor,
"showWarnWhenSwitchToggledOn" to showWarnWhenSwitchToggledOn,
"showWarnWhenSwitchToggledOff" to showWarnWhenSwitchToggledOff,
"showWarnWhenSwitchToggledOnMsg" to showWarnWhenSwitchToggledOnMsg,
"showWarnWhenSwitchToggledOffMsg" to showWarnWhenSwitchToggledOffMsg,
"toggleListener" to toggleListener
)
)
}

fun CustomSettingView.createAttributeSet(): AttributesBuilder.AttributeSet
= AttributesBuilder.AttributeSet( this.extraAttributes)
*/
//fun CustomSettingView.createAttributeSet(): AttributesBuilder.AttributeSet = AttributesBuilder.AttributeSet( this.extraAttributes)

11 changes: 10 additions & 1 deletion ui-core/src/main/res/values/attrs_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<attr name="preferenceName" format="string"/>
<attr name="key" format="string"/>
<attr name="title" format="string"/>
<attr name="description" format="string"/>

<declare-styleable name="Switch">
<attr name="preferenceName"/>
Expand Down Expand Up @@ -31,12 +32,20 @@
<attr name="key"/>

<attr name="title"/>
<attr name="description" format="string"/>
<attr name="description" />
</declare-styleable>

<declare-styleable name="Category" />

<declare-styleable name="TextInput">
<attr name="preferenceName"/>
<attr name="key"/>

<attr name="title"/>
<attr name="description"/>
<attr name="inputType" format="enum">
<enum name=""/>
</attr>

</declare-styleable>
</resources>

0 comments on commit 1c55bc9

Please sign in to comment.