Browse Source

feat: 🅰️ 页面调整

master
niushuai233 1 year ago
parent
commit
2be4882a87
  1. 111
      app/src/main/java/cc/niushuai/dididone/ui/calendar/CalendarFragment.java
  2. 5
      app/src/main/res/layout/fragment_calendar.xml
  3. 1
      app/src/main/res/values/colors.xml

111
app/src/main/java/cc/niushuai/dididone/ui/calendar/CalendarFragment.java

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

5
app/src/main/res/layout/fragment_calendar.xml

@ -16,6 +16,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:textSize="15dp"
android:padding="15dp" /> android:padding="15dp" />
<com.necer.view.WeekBar <com.necer.view.WeekBar
@ -35,7 +36,7 @@
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@android:color/darker_gray"> android:background="@color/gray_light_less">
<LinearLayout <LinearLayout
android:id="@id/c_calendar_check_in_list" android:id="@id/c_calendar_check_in_list"
@ -86,7 +87,7 @@
app:menu_labels_singleLine="false" app:menu_labels_singleLine="false"
app:menu_labels_style="@style/Animation.Design.BottomSheetDialog" app:menu_labels_style="@style/Animation.Design.BottomSheetDialog"
app:menu_labels_textColor="#FFFFFF" app:menu_labels_textColor="#FFFFFF"
app:menu_labels_textSize="14sp" app:menu_labels_textSize="18dp"
app:menu_openDirection="up" app:menu_openDirection="up"
app:menu_shadowColor="#66000000" app:menu_shadowColor="#66000000"
app:menu_shadowRadius="4dp" app:menu_shadowRadius="4dp"

1
app/src/main/res/values/colors.xml

@ -15,6 +15,7 @@
<color name="s_yellow">#F8FF26</color> <color name="s_yellow">#F8FF26</color>
<color name="s_cyan">#B246EB90</color> <color name="s_cyan">#B246EB90</color>
<color name="gray">#AAA0A0</color> <color name="gray">#AAA0A0</color>
<color name="gray_light_less">#D1D1D1</color>
<color name="gray_light">#E8E8E8</color> <color name="gray_light">#E8E8E8</color>
<color name="gray_light_more">#8DE8E8E8</color> <color name="gray_light_more">#8DE8E8E8</color>
</resources> </resources>
Loading…
Cancel
Save