Skip to content

Commit

Permalink
all
Browse files Browse the repository at this point in the history
  • Loading branch information
shanhong cheng committed Mar 24, 2017
1 parent 37877b8 commit 3ed8cf0
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.loganfreeman.utahfishing.common.decorators;

import android.content.Context;
import android.graphics.drawable.Drawable;

import com.loganfreeman.utahfishing.R;
import com.loganfreeman.utahfishing.common.PLog;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;
import com.prolificinteractive.materialcalendarview.spans.DotSpan;

import java.util.Collection;
import java.util.HashSet;

/**
* Created by scheng on 3/23/17.
*/

public class EventDecorator implements DayViewDecorator {

private HashSet<CalendarDay> dates;
private final Drawable drawable;

public EventDecorator(Context context, Collection<CalendarDay> dates) {
this.dates = new HashSet<>(dates);

drawable = context.getResources().getDrawable(R.drawable.my_selector);
}

@Override
public boolean shouldDecorate(CalendarDay day) {
return dates.contains(day);
}

@Override
public void decorate(DayViewFacade view) {
view.setBackgroundDrawable(drawable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.loganfreeman.utahfishing.common.decorators;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;

import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;

import java.util.Calendar;

/**
* Created by scheng on 3/23/17.
*/

public class HighlightWeekendsDecorator implements DayViewDecorator {

private final Calendar calendar = Calendar.getInstance();
private final Drawable highlightDrawable;
private static final int color = Color.parseColor("#228BC34A");

public HighlightWeekendsDecorator() {
highlightDrawable = new ColorDrawable(color);
}

@Override
public boolean shouldDecorate(CalendarDay day) {
day.copyTo(calendar);
int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
return weekDay == Calendar.SATURDAY || weekDay == Calendar.SUNDAY;
}

@Override
public void decorate(DayViewFacade view) {
view.setBackgroundDrawable(highlightDrawable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.loganfreeman.utahfishing.common.decorators;

import android.app.Activity;
import android.graphics.drawable.Drawable;

import com.loganfreeman.utahfishing.R;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;

/**
* Created by scheng on 3/23/17.
*/

public class MySelectorDecorator implements DayViewDecorator {

private final Drawable drawable;

public MySelectorDecorator(Activity context) {
drawable = context.getResources().getDrawable(R.drawable.my_selector);
}

@Override
public boolean shouldDecorate(CalendarDay day) {
return true;
}

@Override
public void decorate(DayViewFacade view) {
view.setSelectionDrawable(drawable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.loganfreeman.utahfishing.common.decorators;

import android.graphics.Typeface;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;

import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;

import java.util.Date;

/**
* Created by scheng on 3/23/17.
*/

public class OneDayDecorator implements DayViewDecorator {

private CalendarDay date;

public OneDayDecorator() {
date = CalendarDay.today();
}

@Override
public boolean shouldDecorate(CalendarDay day) {
return date != null && day.equals(date);
}

@Override
public void decorate(DayViewFacade view) {
view.addSpan(new StyleSpan(Typeface.BOLD));
view.addSpan(new RelativeSizeSpan(1.4f));
}

/**
* We're changing the internals, so make sure to call {@linkplain MaterialCalendarView#invalidateDecorators()}
*/
public void setDate(Date date) {
this.date = CalendarDay.from(date);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.os.Parcelable;
import android.util.Pair;

import com.prolificinteractive.materialcalendarview.CalendarDay;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
Expand All @@ -16,14 +18,17 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import rx.Observable;
import rx.subjects.AsyncSubject;

import static android.R.id.list;
import static java.util.Arrays.stream;

/**
* Created by shanhong on 3/21/17.
Expand All @@ -37,12 +42,17 @@ public class StockReport implements Parcelable {

public static final DateFormat df = new SimpleDateFormat("mm/dd/yyyy");

public static final Pattern dayMonYear = Pattern.compile("(\\d{2})/(\\d{2})/(\\d{4})");

public String watername;
public String county;
public String species;
public int quantity;
public double length;
public Date stockdate;
public int day;
public int month;
public int year;

public String getCounty() {
return county;
Expand Down Expand Up @@ -114,17 +124,28 @@ public static List<StockReport> fromWildlife() throws IOException {
return reports;
}

@TargetApi(Build.VERSION_CODES.N)
private static StockReport fromElement(Element element) {
StockReport report = new StockReport();
report.watername = element.select("td.watername").first().text();
report.county = element.select("td.county").first().text();
report.species = element.select("td.species").first().text();
report.quantity = Integer.parseInt(element.select("td.quantity").first().text());
report.length = Double.parseDouble(element.select("td.length").first().text());
report.stockdate = getDate(element.select("td.stockdate").first().text());
String stockdate = element.select("td.stockdate").first().text();
report.stockdate = getDate(stockdate);
// parse day, month, year
List<Integer> parts = Arrays.stream(stockdate.split("/")).map(u -> Integer.parseInt(u)).collect(Collectors.toList());
report.month = parts.get(0);
report.day = parts.get(1);
report.year = parts.get(2);
return report;
}

public CalendarDay getCalendarDay() {
return CalendarDay.from(year, month, day);
}

@Override
public int describeContents() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.loganfreeman.utahfishing.modules.main.ui;

import android.annotation.TargetApi;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand All @@ -12,15 +16,26 @@
import com.loganfreeman.utahfishing.R;
import com.loganfreeman.utahfishing.base.AbstractBaseFragment;
import com.loganfreeman.utahfishing.common.PLog;
import com.loganfreeman.utahfishing.common.decorators.EventDecorator;
import com.loganfreeman.utahfishing.common.decorators.HighlightWeekendsDecorator;
import com.loganfreeman.utahfishing.common.decorators.MySelectorDecorator;
import com.loganfreeman.utahfishing.common.decorators.OneDayDecorator;
import com.loganfreeman.utahfishing.common.utils.StringUtils;
import com.loganfreeman.utahfishing.common.utils.ToastUtil;
import com.loganfreeman.utahfishing.modules.fishing.domain.StockReport;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import com.prolificinteractive.materialcalendarview.OnDateSelectedListener;
import com.prolificinteractive.materialcalendarview.OnMonthChangedListener;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

import butterknife.Bind;
import butterknife.ButterKnife;
Expand All @@ -34,10 +49,13 @@

public class CalendarFragment extends AbstractBaseFragment implements OnDateSelectedListener, OnMonthChangedListener {

public static final DateFormat df = new SimpleDateFormat("mm/dd/yyyy");

@Bind(R.id.calendarView)
MaterialCalendarView widget;
private View view;


@Override
protected void lazyLoad() {

Expand Down Expand Up @@ -69,7 +87,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

@Override
public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {

widget.invalidateDecorators();
}

@Override
Expand Down Expand Up @@ -98,10 +116,25 @@ public void onNext(List<StockReport> stockReports) {
});
}

@TargetApi(Build.VERSION_CODES.N)
private void initCalendar(List<StockReport> stockReports) {

widget.setOnDateChangedListener(this);
widget.setOnMonthChangedListener(this);

List<CalendarDay> calendarDays = stockReports.stream().map( u -> u.getCalendarDay() ).collect(Collectors.toList());

//PLog.e(calendarDays.stream().map(Object::toString).collect(Collectors.joining("\n")));

//PLog.e(stockReports.stream().map(u -> df.format(u.stockdate)).collect(Collectors.joining("\n")));



widget.addDecorator(new EventDecorator(CalendarFragment.this.getActivity(), calendarDays));

widget.addDecorators(
new HighlightWeekendsDecorator()
);

}
}
Binary file added app/src/main/res/drawable-hdpi/ic_my_selector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_my_selector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/my_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_shortAnimTime">

<item android:state_checked="true"
android:drawable="@drawable/ic_my_selector" />

<item android:state_pressed="true"
android:drawable="@drawable/ic_my_selector" />

<item android:drawable="@android:color/transparent" />

</selector>

0 comments on commit 3ed8cf0

Please sign in to comment.