|
|
@ -7,6 +7,7 @@ import android.view.LayoutInflater; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.widget.LinearLayout; |
|
|
|
import android.widget.LinearLayout; |
|
|
|
|
|
|
|
import android.widget.RelativeLayout; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.NonNull; |
|
|
@ -18,17 +19,23 @@ import com.necer.entity.CalendarDate; |
|
|
|
import com.necer.entity.Lunar; |
|
|
|
import com.necer.entity.Lunar; |
|
|
|
import com.necer.enumeration.DateChangeBehavior; |
|
|
|
import com.necer.enumeration.DateChangeBehavior; |
|
|
|
import com.necer.listener.OnCalendarChangedListener; |
|
|
|
import com.necer.listener.OnCalendarChangedListener; |
|
|
|
|
|
|
|
import com.necer.painter.InnerPainter; |
|
|
|
import com.necer.utils.CalendarUtil; |
|
|
|
import com.necer.utils.CalendarUtil; |
|
|
|
|
|
|
|
|
|
|
|
import org.joda.time.LocalDate; |
|
|
|
import org.joda.time.LocalDate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import cc.niushuai.dididone.R; |
|
|
|
import cc.niushuai.dididone.R; |
|
|
|
import cc.niushuai.dididone.databinding.FragmentCalendarBinding; |
|
|
|
import cc.niushuai.dididone.databinding.FragmentCalendarBinding; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
|
|
|
|
|
|
|
|
public class CalendarFragment extends Fragment { |
|
|
|
public class CalendarFragment extends Fragment { |
|
|
|
|
|
|
|
|
|
|
|
private FragmentCalendarBinding binding; |
|
|
|
private FragmentCalendarBinding binding; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String lastDate; |
|
|
|
|
|
|
|
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, |
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, |
|
|
|
ViewGroup container, Bundle savedInstanceState) { |
|
|
|
ViewGroup container, Bundle savedInstanceState) { |
|
|
|
CalendarViewModel calendarViewModel = |
|
|
|
CalendarViewModel calendarViewModel = |
|
|
@ -37,12 +44,23 @@ public class CalendarFragment extends Fragment { |
|
|
|
binding = FragmentCalendarBinding.inflate(inflater, container, false); |
|
|
|
binding = FragmentCalendarBinding.inflate(inflater, container, false); |
|
|
|
View root = binding.getRoot(); |
|
|
|
View root = binding.getRoot(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化数据
|
|
|
|
|
|
|
|
init(); |
|
|
|
|
|
|
|
// 设置监听器
|
|
|
|
setListeners(); |
|
|
|
setListeners(); |
|
|
|
|
|
|
|
|
|
|
|
return root; |
|
|
|
return root; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void init() { |
|
|
|
|
|
|
|
// initPointList();
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initPointList(List<String> pointList) { |
|
|
|
|
|
|
|
InnerPainter painter = (InnerPainter) binding.miui10Calendar.getCalendarPainter(); |
|
|
|
|
|
|
|
painter.addPointList(pointList); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setListeners() { |
|
|
|
private void setListeners() { |
|
|
|
// 日历选择变更事件
|
|
|
|
// 日历选择变更事件
|
|
|
|
setCalendarChangeListener(); |
|
|
|
setCalendarChangeListener(); |
|
|
@ -56,13 +74,19 @@ public class CalendarFragment extends Fragment { |
|
|
|
binding.miui10Calendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { |
|
|
|
binding.miui10Calendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { |
|
|
|
public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { |
|
|
|
Log.d(getTag(), " 当前选中 " + localDate); |
|
|
|
if (null != lastDate && lastDate.equals(localDate.toString())) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CalendarDate calendarDate = CalendarUtil.getCalendarDate(localDate); |
|
|
|
Log.d(getTag(), "当前选中 " + localDate); |
|
|
|
Lunar lunar = calendarDate.lunar; |
|
|
|
Lunar lunar = CalendarUtil.getCalendarDate(localDate).lunar; |
|
|
|
String lunarDate = lunar.chineseEra + "年" + lunar.lunarMonthStr + lunar.lunarDayStr; |
|
|
|
String lunarDate = lunar.chineseEra + "年" + lunar.lunarMonthStr + lunar.lunarDayStr; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 当前选中的日期放到最上面
|
|
|
|
add2Top(localDate.toString(), lunarDate); |
|
|
|
add2Top(localDate.toString(), lunarDate); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 重置上次选中日期
|
|
|
|
|
|
|
|
lastDate = localDate.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -70,40 +94,46 @@ public class CalendarFragment extends Fragment { |
|
|
|
|
|
|
|
|
|
|
|
private void add2Top(String localDate, String lunarDate) { |
|
|
|
private void add2Top(String localDate, String lunarDate) { |
|
|
|
// 外层layout 白色背景 存在边距
|
|
|
|
// 外层layout 白色背景 存在边距
|
|
|
|
LinearLayout itemLinearLayout = new LinearLayout(getContext()); |
|
|
|
LinearLayout itemLayout = new LinearLayout(getContext()); |
|
|
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 175); |
|
|
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 175); |
|
|
|
layoutParams.setMargins(25, 20, 25, 15); |
|
|
|
layoutParams.setMargins(25, 20, 25, 15); |
|
|
|
|
|
|
|
|
|
|
|
itemLinearLayout.setLayoutParams(layoutParams); |
|
|
|
itemLayout.setId(13); |
|
|
|
itemLinearLayout.setPadding(15, 15, 15, 5); |
|
|
|
itemLayout.setLayoutParams(layoutParams); |
|
|
|
itemLinearLayout.setBackgroundResource(R.drawable.bg_miui10); |
|
|
|
itemLayout.setPadding(15, 15, 15, 5); |
|
|
|
itemLinearLayout.setOrientation(LinearLayout.VERTICAL); |
|
|
|
itemLayout.setBackgroundResource(R.drawable.bg_miui10); |
|
|
|
|
|
|
|
itemLayout.setOrientation(LinearLayout.VERTICAL); |
|
|
|
|
|
|
|
|
|
|
|
ViewGroup.LayoutParams textLayoutParams = new ViewGroup.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
|
|
|
ViewGroup.LayoutParams textLayoutParams = new ViewGroup.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
|
|
|
TextView dateTextView = new TextView(getContext()); |
|
|
|
TextView projectTextView = this.getTextView(11, localDate, textLayoutParams, R.color._333333, 16, Gravity.CENTER_VERTICAL); |
|
|
|
|
|
|
|
itemLayout.addView(projectTextView); |
|
|
|
dateTextView.setLayoutParams(textLayoutParams); |
|
|
|
|
|
|
|
dateTextView.setText(localDate); |
|
|
|
|
|
|
|
dateTextView.setTextColor(getResources().getColor(R.color._333333)); |
|
|
|
|
|
|
|
dateTextView.setTextSize(16); |
|
|
|
|
|
|
|
dateTextView.setGravity(Gravity.CENTER_VERTICAL); |
|
|
|
|
|
|
|
itemLinearLayout.addView(dateTextView); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// empty textview 占位view 撑大位置
|
|
|
|
// empty textview 占位view 撑大位置
|
|
|
|
itemLinearLayout.addView(new TextView(getContext())); |
|
|
|
TextView emptyTextView = new TextView(getContext()); |
|
|
|
|
|
|
|
emptyTextView.setId(33); |
|
|
|
|
|
|
|
itemLayout.addView(emptyTextView); |
|
|
|
|
|
|
|
|
|
|
|
TextView lunarDateTextView = new TextView(getContext()); |
|
|
|
TextView dateTextView = this.getTextView(22, DateUtil.now(), textLayoutParams, R.color._666666, 12, Gravity.TOP); |
|
|
|
lunarDateTextView.setLayoutParams(textLayoutParams); |
|
|
|
itemLayout.addView(dateTextView); |
|
|
|
lunarDateTextView.setText(lunarDate); |
|
|
|
|
|
|
|
lunarDateTextView.setTextColor(getResources().getColor(R.color._666666)); |
|
|
|
|
|
|
|
lunarDateTextView.setTextSize(12); |
|
|
|
|
|
|
|
lunarDateTextView.setGravity(Gravity.BOTTOM); |
|
|
|
|
|
|
|
itemLinearLayout.addView(lunarDateTextView); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.cCalendarCheckInList.addView(itemLinearLayout, 0); |
|
|
|
binding.cCalendarCheckInList.removeAllViews(); |
|
|
|
|
|
|
|
binding.cCalendarCheckInList.removeAllViewsInLayout(); |
|
|
|
|
|
|
|
binding.cCalendarCheckInList.addView(itemLayout, 0); |
|
|
|
binding.cCalendarCheckInList.requestLayout(); |
|
|
|
binding.cCalendarCheckInList.requestLayout(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TextView getTextView(int id, String text, ViewGroup.LayoutParams textLayoutParams, int textColor, int textSize, int gravity) { |
|
|
|
|
|
|
|
TextView textView = new TextView(getContext()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textView.setId(id); |
|
|
|
|
|
|
|
textView.setLayoutParams(textLayoutParams); |
|
|
|
|
|
|
|
textView.setText(text); |
|
|
|
|
|
|
|
textView.setTextColor(getResources().getColor(textColor)); |
|
|
|
|
|
|
|
textView.setTextSize(textSize); |
|
|
|
|
|
|
|
textView.setGravity(gravity); |
|
|
|
|
|
|
|
return textView; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onDestroyView() { |
|
|
|
public void onDestroyView() { |
|
|
|
super.onDestroyView(); |
|
|
|
super.onDestroyView(); |
|
|
|