|
|
|
@ -1,7 +1,6 @@
@@ -1,7 +1,6 @@
|
|
|
|
|
package cc.niushuai.dididone.ui.calendar; |
|
|
|
|
|
|
|
|
|
import android.content.Context; |
|
|
|
|
import android.icu.text.DateFormat; |
|
|
|
|
import android.os.Bundle; |
|
|
|
|
import android.util.Log; |
|
|
|
|
import android.view.Gravity; |
|
|
|
@ -44,6 +43,7 @@ import cc.niushuai.dididone.util.XLog;
@@ -44,6 +43,7 @@ import cc.niushuai.dididone.util.XLog;
|
|
|
|
|
import cn.hutool.core.date.DatePattern; |
|
|
|
|
import cn.hutool.core.date.DateTime; |
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import io.reactivex.Completable; |
|
|
|
|
import io.reactivex.CompletableObserver; |
|
|
|
|
import io.reactivex.Flowable; |
|
|
|
@ -60,10 +60,8 @@ public class CalendarFragment extends Fragment {
@@ -60,10 +60,8 @@ public class CalendarFragment extends Fragment {
|
|
|
|
|
|
|
|
|
|
private List<Project> floatingActionProjectList; |
|
|
|
|
|
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, |
|
|
|
|
ViewGroup container, Bundle savedInstanceState) { |
|
|
|
|
CalendarViewModel calendarViewModel = |
|
|
|
|
new ViewModelProvider(this).get(CalendarViewModel.class); |
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
|
|
|
|
CalendarViewModel calendarViewModel = new ViewModelProvider(this).get(CalendarViewModel.class); |
|
|
|
|
|
|
|
|
|
binding = FragmentCalendarBinding.inflate(inflater, container, false); |
|
|
|
|
View root = binding.getRoot(); |
|
|
|
@ -117,10 +115,11 @@ public class CalendarFragment extends Fragment {
@@ -117,10 +115,11 @@ public class CalendarFragment extends Fragment {
|
|
|
|
|
actionButton.show(true); |
|
|
|
|
actionButton.setTag(project.getName() + project.getId()); |
|
|
|
|
actionButton.setLabelText(project.getName()); |
|
|
|
|
actionButton.setImageDrawable(new IconicsDrawable(context).icon(project.getIcon()).color(project.getIconColor()).sizeDp(24)); |
|
|
|
|
actionButton.setImageDrawable(new IconicsDrawable(context).icon(project.getIcon()).color(project.getIconColor()).sizeDp(32)); |
|
|
|
|
actionButton.setButtonSize(FloatingActionButton.SIZE_NORMAL); |
|
|
|
|
actionButton.setColorNormal(getResources().getColor(R.color.white)); |
|
|
|
|
actionButton.setColorPressed(getResources().getColor(R.color.white)); |
|
|
|
|
|
|
|
|
|
actionButton.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
@Override |
|
|
|
|
public void onClick(View v) { |
|
|
|
@ -135,28 +134,26 @@ public class CalendarFragment extends Fragment {
@@ -135,28 +134,26 @@ public class CalendarFragment extends Fragment {
|
|
|
|
|
|
|
|
|
|
// 插入数据库
|
|
|
|
|
Completable completable = DBManager.INSTANCE.recordDao().insertAll(record); |
|
|
|
|
completable.subscribeOn(Schedulers.io()) |
|
|
|
|
.observeOn(AndroidSchedulers.mainThread()) |
|
|
|
|
.subscribe(new CompletableObserver() { |
|
|
|
|
@Override |
|
|
|
|
public void onSubscribe(Disposable d) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onComplete() { |
|
|
|
|
XLog.i("[{}]打卡成功", project.getName()); |
|
|
|
|
Toasts.shortShow(getActivity(), "[{}]打卡成功", project.getName()); |
|
|
|
|
|
|
|
|
|
// 更新视图
|
|
|
|
|
add2Top(project, record); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onError(Throwable e) { |
|
|
|
|
XLog.e("[{}]打卡失败, {}", project.getName(), e); |
|
|
|
|
Toasts.shortShow(getActivity(), "[{}]打卡失败, {}", project.getName(), e.getMessage()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
completable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new CompletableObserver() { |
|
|
|
|
@Override |
|
|
|
|
public void onSubscribe(Disposable d) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onComplete() { |
|
|
|
|
XLog.i("[{}]打卡成功", project.getName()); |
|
|
|
|
Toasts.shortShow(getActivity(), "[{}]打卡成功", project.getName()); |
|
|
|
|
|
|
|
|
|
// 更新视图
|
|
|
|
|
add2Top(project, record); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onError(Throwable e) { |
|
|
|
|
XLog.e("[{}]打卡失败, {}", project.getName(), e); |
|
|
|
|
Toasts.shortShow(getActivity(), "[{}]打卡失败, {}", project.getName(), e.getMessage()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -184,6 +181,8 @@ public class CalendarFragment extends Fragment {
@@ -184,6 +181,8 @@ public class CalendarFragment extends Fragment {
|
|
|
|
|
// 重置上次选中日期
|
|
|
|
|
lastDate = localDate.toString(); |
|
|
|
|
|
|
|
|
|
binding.tvResult.setText(StrUtil.format("{} | {}", lastDate, lunarDate)); |
|
|
|
|
|
|
|
|
|
// 重组日期
|
|
|
|
|
rebuildRecordListViewByDate(lastDate); |
|
|
|
|
} |
|
|
|
@ -197,37 +196,36 @@ public class CalendarFragment extends Fragment {
@@ -197,37 +196,36 @@ public class CalendarFragment extends Fragment {
|
|
|
|
|
binding.cCalendarCheckInList.removeAllViews(); |
|
|
|
|
// 添加新内容项
|
|
|
|
|
Flowable<List<Record>> flowable = DBManager.INSTANCE.recordDao().queryByDate(dateTime.getTime()); |
|
|
|
|
flowable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) |
|
|
|
|
.subscribe(new FlowableSubscriber<List<Record>>() { |
|
|
|
|
@Override |
|
|
|
|
public void onSubscribe(Subscription s) { |
|
|
|
|
// 3s超时
|
|
|
|
|
s.request(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onNext(List<Record> recordList) { |
|
|
|
|
XLog.d("DataListOnNext 查询到数据: {}", recordList.size()); |
|
|
|
|
flowable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new FlowableSubscriber<List<Record>>() { |
|
|
|
|
@Override |
|
|
|
|
public void onSubscribe(Subscription s) { |
|
|
|
|
// 3s超时
|
|
|
|
|
s.request(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (Record record : recordList) { |
|
|
|
|
Project project = BizGlobal.CACHE_PROJECT.get(record.getProjectId()); |
|
|
|
|
if (null == project) { |
|
|
|
|
Toasts.longShow(getContext(), "ProjectId: {}不存在, 可能存在BUG", String.valueOf(record.getProjectId())); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
add2Top(project, record); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
public void onNext(List<Record> recordList) { |
|
|
|
|
XLog.d("DataListOnNext 查询到数据: {}", recordList.size()); |
|
|
|
|
|
|
|
|
|
for (Record record : recordList) { |
|
|
|
|
Project project = BizGlobal.CACHE_PROJECT.get(record.getProjectId()); |
|
|
|
|
if (null == project) { |
|
|
|
|
Toasts.longShow(getContext(), "ProjectId: {}不存在, 可能存在BUG", String.valueOf(record.getProjectId())); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
add2Top(project, record); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onError(Throwable t) { |
|
|
|
|
Toasts.shortShow(getActivity(), "DataList根据时间拉取历史数据失败: ", t.getLocalizedMessage()); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
public void onError(Throwable t) { |
|
|
|
|
Toasts.shortShow(getActivity(), "DataList根据时间拉取历史数据失败: ", t.getLocalizedMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onComplete() { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
@Override |
|
|
|
|
public void onComplete() { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -296,7 +294,6 @@ public class CalendarFragment extends Fragment {
@@ -296,7 +294,6 @@ public class CalendarFragment extends Fragment {
|
|
|
|
|
|
|
|
|
|
private void fetchNewestActionButtonData() { |
|
|
|
|
Flowable<List<Project>> listFlowable = DBManager.INSTANCE.projectDao().listAll(); |
|
|
|
|
listFlowable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) |
|
|
|
|
.subscribe(projectList -> floatingActionProjectList = projectList); |
|
|
|
|
listFlowable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(projectList -> floatingActionProjectList = projectList); |
|
|
|
|
} |
|
|
|
|
} |