Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytroporoshyn committed Sep 10, 2019
0 parents commit b9b4669
Show file tree
Hide file tree
Showing 32 changed files with 916 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
1 change: 1 addition & 0 deletions .idea/.name

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

122 changes: 122 additions & 0 deletions .idea/codeStyles/Project.xml

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

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

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

7 changes: 7 additions & 0 deletions .idea/dictionaries/dmitriy.xml

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

19 changes: 19 additions & 0 deletions .idea/gradle.xml

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

14 changes: 14 additions & 0 deletions .idea/misc.xml

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

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

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

1 change: 1 addition & 0 deletions answerselector/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
36 changes: 36 additions & 0 deletions answerselector/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"


defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Empty file.
21 changes: 21 additions & 0 deletions answerselector/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.dmytroporoshyn.answerselectorview

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.dmytroporoshyn.answerselectorview.test", appContext.packageName)
}
}
2 changes: 2 additions & 0 deletions answerselector/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dmytroporoshyn.answerselectorview" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*******************************************************************************
* Developed by Dimitry Poroshyn on 7/31/19 1:47 PM
* Last modified 7/31/19 1:47 PM
* Copyright (c) 2019. All rights reserved.
******************************************************************************/

package com.dmytroporoshyn.answerselectorview

import android.content.Context
import android.util.AttributeSet
import android.widget.Checkable
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.content.res.AppCompatResources

class AnswerItemView(context: Context, attributes: AttributeSet?) : FrameLayout(context, attributes),
Checkable {

private var selectorText: TextView
private var viewBackground: FrameLayout
private var checkedSelector: Boolean = false
var baseId: Int = 0
private var listener: ((Int, Boolean) -> Unit?)? = null


init {
val view = LinearLayout.inflate(context, R.layout.view_answer_item, this)
selectorText = view.findViewById(R.id.selectorText)
viewBackground = view.findViewById(R.id.viewBackground)
}

fun setText(string: String) {
selectorText.text = string
}

override fun isChecked(): Boolean {
return checkedSelector
}

override fun toggle() {
if (!isChecked) {
isChecked = !checkedSelector
refreshDrawableState()
}
}

override fun performClick(): Boolean {
toggle()
return super.performClick()
}

override fun setChecked(boolean: Boolean) {
checkedSelector = boolean
listener?.invoke(baseId, checkedSelector)
refreshDrawableState()
}

override fun onCreateDrawableState(extraSpace: Int): IntArray {
val drawableState = super.onCreateDrawableState(extraSpace + 1)
if (isChecked) {
selectorText.setTextColor(
AppCompatResources.getColorStateList(
this.context,
R.color.colorAccent
)
)
viewBackground.background =
AppCompatResources.getDrawable(
this.context,
R.drawable.ic_answer_view_background_checked
)
} else {
selectorText.setTextColor(
AppCompatResources.getColorStateList(
this.context,
R.color.blackText
)
)
viewBackground.background =
AppCompatResources.getDrawable(this.context, R.drawable.ic_answer_view_background)
}
return drawableState
}

fun listener(listener: (Int, Boolean) -> Unit) {
this.listener = listener
}
}
Loading

0 comments on commit b9b4669

Please sign in to comment.