Skip to content

Commit

Permalink
- refactoring package
Browse files Browse the repository at this point in the history
- update gradle
- fixing default year, month
  • Loading branch information
kal72 committed May 30, 2019
1 parent 14bcdad commit f129b14
Show file tree
Hide file tree
Showing 36 changed files with 169 additions and 83 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.3.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,6 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Dec 27 00:00:09 WIB 2017
#Thu May 30 16:24:51 WIB 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
File renamed without changes.
16 changes: 8 additions & 8 deletions rackmonthPicker/build.gradle → rackmonthpicker/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 28
versionCode 1
versionName "1.0"

Expand All @@ -22,11 +22,11 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(include: ['*.jar'], dir: 'libs')
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.0.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:recyclerview-v7:25.0.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'junit:junit:4.12'
implementation 'com.android.support:recyclerview-v7:28.0.0'
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.rackspira.kristiawan.rackmonthpicker;
package com.kal.rackmonthpicker;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rackspira.kristiawan.rackmonthpicker">
package="com.kal.rackmonthpicker">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.rackspira.kristiawan.rackmonthpicker;
package com.kal.rackmonthpicker;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.StateListDrawable;
Expand All @@ -15,7 +14,6 @@

import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
Expand All @@ -24,7 +22,7 @@

public class MonthAdapter extends RecyclerView.Adapter<MonthAdapter.MonthHolder> {

private String[] months = new String[0];
private String[] months;
private OnSelectedListener listener;
private int selectedItem = -1;
private Context context;
Expand All @@ -34,13 +32,6 @@ public MonthAdapter(Context context, OnSelectedListener listener) {
this.context = context;
this.listener = listener;
months = new DateFormatSymbols(Locale.ENGLISH).getShortMonths();

if (selectedItem == -1) {
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
selectedItem = cal.get(Calendar.MONTH);
}
}

@Override
Expand All @@ -52,7 +43,7 @@ public MonthHolder onCreateViewHolder(ViewGroup parent, int viewType) {
@Override
public void onBindViewHolder(MonthHolder holder, int position) {
holder.textViewMonth.setText(months[position]);
holder.textViewMonth.setTextColor(selectedItem == position ? Color.WHITE : Color.BLACK);
// holder.textViewMonth.setTextColor(selectedItem == position ? Color.WHITE : Color.BLACK);
holder.itemView.setSelected(selectedItem == position ? true : false);
}

Expand All @@ -61,6 +52,10 @@ public int getItemCount() {
return months.length;
}

/**
* change format by localization
* @param locale
*/
public void setLocale(Locale locale) {
months = new DateFormatSymbols(locale).getShortMonths();
notifyDataSetChanged();
Expand Down Expand Up @@ -114,26 +109,28 @@ public MonthHolder(View itemView) {
if (color != 0)
setMonthBackgroundSelected(color);

itemView.setClickable(true);
// itemView.setClickable(true);
itemView.setOnClickListener(this);
}

@Override
public void onClick(View v) {
notifyItemChanged(selectedItem);
// notifyItemChanged(selectedItem);
selectedItem = getAdapterPosition();
notifyItemChanged(selectedItem);
// notifyItemChanged(selectedItem);
notifyDataSetChanged();
listener.onContentSelected();
}

private void setMonthBackgroundSelected(int color) {
LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(context, R.drawable.month_selected);
GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable.getDrawable(1);
gradientDrawable.setColor(ContextCompat.getColor(context, color));
gradientDrawable.setColor(color);
layerDrawable.setDrawableByLayerId(1, gradientDrawable);

StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_selected}, gradientDrawable);
states.addState(new int[]{android.R.attr.state_pressed}, gradientDrawable);
states.addState(new int[]{}, ContextCompat.getDrawable(context, R.drawable.month_default));
layoutMain.setBackground(states);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package com.rackspira.kristiawan.rackmonthpicker;
package com.kal.rackmonthpicker;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rackspira.kristiawan.rackmonthpicker.listener.DateMonthDialogListener;
import com.rackspira.kristiawan.rackmonthpicker.listener.OnCancelMonthDialogListener;
import com.kal.rackmonthpicker.listener.DateMonthDialogListener;
import com.kal.rackmonthpicker.listener.OnCancelMonthDialogListener;

import java.util.Calendar;
import java.util.Date;
Expand Down Expand Up @@ -43,49 +47,98 @@ public RackMonthPicker(Context context) {
public void show() {
if (isBuild) {
mAlertDialog.show();
builder.setDefault();
} else {
builder.build();
isBuild = true;
}
}

/**
* set action callback when positive button clicked
*
* @param dateMonthDialogListener
* @return
*/
public RackMonthPicker setPositiveButton(DateMonthDialogListener dateMonthDialogListener) {
this.dateMonthDialogListener = dateMonthDialogListener;
mPositiveButton.setOnClickListener(builder.positiveButtonClick());
return this;
}

/**
* set action callback when negative button clicked
*
* @param onCancelMonthDialogListener
* @return
*/
public RackMonthPicker setNegativeButton(OnCancelMonthDialogListener onCancelMonthDialogListener) {
this.onCancelMonthDialogListener = onCancelMonthDialogListener;
mNegativeButton.setOnClickListener(builder.negativeButtonClick());
return this;
}

/**
* change text positive button
*
* @param text
* @return
*/
public RackMonthPicker setPositiveText(String text) {
mPositiveButton.setText(text);
return this;
}

/**
* change text negative button
*
* @param text
* @return
*/
public RackMonthPicker setNegativeText(String text) {
mNegativeButton.setText(text);
return this;
}

/**
* set localization show month
*
* @param locale
* @return
*/
public RackMonthPicker setLocale(Locale locale) {
builder.setLocale(locale);
return this;
}

public RackMonthPicker setSelectedMonth(int index) {
builder.setSelectedMonth(index);
/**
* change default selected month (1 - 12)
*
* @param month
* @return
*/
public RackMonthPicker setSelectedMonth(int month) {
builder.setSelectedMonth(month);
return this;
}

/**
* change default selected year
*
* @param year
* @return
*/
public RackMonthPicker setSelectedYear(int year) {
builder.setSelectedYear(year);
return this;
}

/**
* change color theme
*
* @param color
* @return
*/
public RackMonthPicker setColorTheme(int color) {
builder.setColorTheme(color);
return this;
Expand All @@ -100,7 +153,8 @@ private class Builder implements MonthAdapter.OnSelectedListener {
private MonthAdapter monthAdapter;
private TextView mTitleView;
private TextView mYear;
private int year = 2018;
private int year;
private int month;
private AlertDialog.Builder alertBuilder;
private View contentView;

Expand All @@ -114,27 +168,48 @@ private Builder() {
mTitleView = (TextView) contentView.findViewById(R.id.title);
mYear = (TextView) contentView.findViewById(R.id.text_year);

Button next = (Button) contentView.findViewById(R.id.btn_next);
ImageView next = (ImageView) contentView.findViewById(R.id.btn_next);
next.setOnClickListener(nextButtonClick());

Button previous = (Button) contentView.findViewById(R.id.btn_previous);
ImageView previous = (ImageView) contentView.findViewById(R.id.btn_previous);
previous.setOnClickListener(previousButtonClick());

mPositiveButton = (Button) contentView.findViewById(R.id.btn_p);
mNegativeButton = (Button) contentView.findViewById(R.id.btn_n);

Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
year = cal.get(Calendar.YEAR);

monthAdapter = new MonthAdapter(context, this);

RecyclerView recyclerView = (RecyclerView) contentView.findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new GridLayoutManager(context, 4));
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(monthAdapter);

Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
year = cal.get(Calendar.YEAR);
month = cal.get(Calendar.MONTH);

setColorTheme(getColorByThemeAttr(context, android.R.attr.colorPrimary, R.color.color_primary));
}

private int getColorByThemeAttr(Context context, int attr, int defaultColor) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
boolean got = theme.resolveAttribute(attr, typedValue, true);
return got ? typedValue.data : defaultColor;
}

private void setDefault() {
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
year = cal.get(Calendar.YEAR);
month = cal.get(Calendar.MONTH);

monthAdapter.setSelectedItem(month);
mTitleView.setText(monthAdapter.getShortMonth() + ", " + year);
monthAdapter.notifyDataSetChanged();
mYear.setText(year + "");
}

Expand All @@ -155,14 +230,18 @@ public void setSelectedYear(int year) {

public void setColorTheme(int color) {
LinearLayout linearToolbar = (LinearLayout) contentView.findViewById(R.id.linear_toolbar);
linearToolbar.setBackgroundResource(color);
linearToolbar.setBackgroundColor(color);

monthAdapter.setBackgroundMonth(color);
mPositiveButton.setTextColor(ContextCompat.getColor(context, color));
mNegativeButton.setTextColor(ContextCompat.getColor(context, color));
mPositiveButton.setTextColor(color);
mNegativeButton.setTextColor(color);
}

public void build() {
monthAdapter.setSelectedItem(month);
mTitleView.setText(monthAdapter.getShortMonth() + ", " + year);
mYear.setText(year + "");

mAlertDialog = alertBuilder.create();
mAlertDialog.show();
mAlertDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.rackspira.kristiawan.rackmonthpicker.listener;
package com.kal.rackmonthpicker.listener;

/**
* Created by kristiawan on 31/12/16.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.rackspira.kristiawan.rackmonthpicker.listener;
package com.kal.rackmonthpicker.listener;

import android.support.v7.app.AlertDialog;

Expand Down
Loading

0 comments on commit f129b14

Please sign in to comment.