diff --git a/.gitignore b/.gitignore
index 39fb081..ebef7f5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,10 @@
+.idea/**/workspace.xml
+.idea/**/gradle.xml
+.idea/**/libraries
+.gradle/
+build/
+local.properties
*.iml
-.gradle
-/local.properties
-/.idea/workspace.xml
-/.idea/libraries
-.DS_Store
-/build
-/captures
-.externalNativeBuild
+.idea/caches
+.idea/codeStyles
+.idea/misc.xml
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 085136f..a22e539 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,8 +1,5 @@
-
-
-
@@ -43,17 +40,7 @@
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 94a99da..8879949 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -4,6 +4,7 @@
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 2bdbb0b..a7a4fc8 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -3,13 +3,13 @@ apply plugin: 'com.github.dcendents.android-maven'
group='com.github.AnkitKiet'
android {
- compileSdkVersion 25
- buildToolsVersion "25.0.3"
+ compileSdkVersion 27
+ buildToolsVersion "27.0.3"
defaultConfig {
- minSdkVersion 10
- targetSdkVersion 25
- versionCode 1
- versionName "1.0"
+ minSdkVersion 11
+ targetSdkVersion 27
+ versionCode 2
+ versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
@@ -21,11 +21,11 @@ android {
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ implementation 'com.android.support:appcompat-v7:27.1.1'
+ implementation 'com.android.support.constraint:constraint-layout:1.1.3'
+ testImplementation 'junit:junit:4.12'
+ androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
- compile 'com.android.support:appcompat-v7:25.+'
- compile 'com.android.support.constraint:constraint-layout:1.0.2'
- testCompile 'junit:junit:4.12'
}
diff --git a/app/src/main/java/edu/counterview/CounterListner.java b/app/src/main/java/edu/counterview/CounterListener.java
similarity index 80%
rename from app/src/main/java/edu/counterview/CounterListner.java
rename to app/src/main/java/edu/counterview/CounterListener.java
index 0ba17ab..9b37a2f 100644
--- a/app/src/main/java/edu/counterview/CounterListner.java
+++ b/app/src/main/java/edu/counterview/CounterListener.java
@@ -6,7 +6,7 @@
-public interface CounterListner {
+public interface CounterListener {
void onIncClick(String value);
void onDecClick(String value);
diff --git a/app/src/main/java/edu/counterview/CounterView.java b/app/src/main/java/edu/counterview/CounterView.java
index cd5ef7d..504691a 100644
--- a/app/src/main/java/edu/counterview/CounterView.java
+++ b/app/src/main/java/edu/counterview/CounterView.java
@@ -11,19 +11,18 @@
public class CounterView extends LinearLayout implements View.OnClickListener {
-
public static final String TAG = CounterView.class.getSimpleName();
private TextView itemCounterValue;
private Button incButton;
private Button decButton;
private LinearLayout rootView;
- private CounterListner listener;
+ private CounterListener listener;
+ private boolean isMinusSupported;
public CounterView(Context context) {
super(context);
init(context, null, 0);
-
}
public CounterView(Context context, AttributeSet attrs) {
@@ -34,21 +33,18 @@ public CounterView(Context context, AttributeSet attrs) {
public CounterView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr);
-
}
private void init(Context context, AttributeSet attrs, int defStyle) {
inflate(context, R.layout.item_counter, this);
- this.rootView = (LinearLayout) findViewById(R.id.root_view);
- this.itemCounterValue = (TextView) findViewById(R.id.item_counter_value);
- this.incButton = (Button) findViewById(R.id.inc_button);
- this.decButton = (Button) findViewById(R.id.dec_button);
+ this.rootView = findViewById(R.id.root_view);
+ this.itemCounterValue = findViewById(R.id.item_counter_value);
+ this.incButton = findViewById(R.id.inc_button);
+ this.decButton = findViewById(R.id.dec_button);
this.incButton.setOnClickListener(this);
this.decButton.setOnClickListener(this);
-
}
-
public CounterView setStartCounterValue(String startValue) {
if (this.itemCounterValue != null)
this.itemCounterValue.setText(startValue);
@@ -61,7 +57,7 @@ public CounterView setStartCounterValue(@StringRes int startValue) {
return this;
}
- public CounterView setCounterListener(CounterListner counterListener) {
+ public CounterView setCounterListener(CounterListener counterListener) {
listener = counterListener;
return this;
}
@@ -78,7 +74,6 @@ private String getString(@StringRes int textResourceValue) {
}
public CounterView setColor(@ColorRes int left, @ColorRes int right, @ColorRes int text) {
-
this.incButton.setBackgroundColor(getColor(right));
this.decButton.setBackgroundColor(getColor(left));
this.itemCounterValue.setTextColor(getColor(text));
@@ -89,10 +84,14 @@ private int getColor(@ColorRes int colorRes) {
return getContext().getResources().getColor(colorRes);
}
+ public CounterView setMinus(boolean isSupported) {
+ this.isMinusSupported = isSupported;
+ return this;
+ }
+
@Override
public void onClick(View view) {
- int value = 0;
- value = Integer.parseInt(this.itemCounterValue.getText().toString());
+ int value = Integer.parseInt(this.itemCounterValue.getText().toString());
int i = view.getId();
if (i == R.id.inc_button) {
value++;
@@ -101,14 +100,12 @@ public void onClick(View view) {
this.listener.onIncClick(this.itemCounterValue.getText().toString());
} else if (i == R.id.dec_button) {
value--;
- if (value < 1) {
- value = 1;
+ if (value < 0 && !isMinusSupported) {
+ value = 0;
}
this.itemCounterValue.setText(String.valueOf(value));
if (this.listener != null)
this.listener.onDecClick(this.itemCounterValue.getText().toString());
}
}
-
-
}
diff --git a/app/src/main/res/layout/item_counter.xml b/app/src/main/res/layout/item_counter.xml
index 9beb53c..db2215b 100644
--- a/app/src/main/res/layout/item_counter.xml
+++ b/app/src/main/res/layout/item_counter.xml
@@ -12,15 +12,21 @@
android:layout_height="25dp"
android:layout_weight="0.5"
android:background="@color/colorPrimary"
- android:text="-"
+ android:text="@string/decrement"
android:textColor="#ffffff" />
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 3fbc9f6..5ed3701 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,3 +1,6 @@
CounterView
+ +
+ -
+ 0
diff --git a/build.gradle b/build.gradle
index e17c8de..948b344 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2,11 +2,12 @@
buildscript {
repositories {
+ google()
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.3.3'
- classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
+ classpath 'com.android.tools.build:gradle:3.1.4'
+ classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@@ -15,6 +16,7 @@ buildscript {
allprojects {
repositories {
+ google()
jcenter()
maven { url 'https://jitpack.io' }
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 5b5226c..a2938b2 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip