@ -26,10 +26,13 @@ import cc.niushuai.dididone.biz.roomx.DBManager;
@@ -26,10 +26,13 @@ import cc.niushuai.dididone.biz.roomx.DBManager;
import cc.niushuai.dididone.biz.vo.ProjectCount ;
import cc.niushuai.dididone.util.IntSnowflake ;
import cc.niushuai.dididone.util.XLog ;
import cn.hutool.core.collection.CollUtil ;
import cn.hutool.core.date.DatePattern ;
import cn.hutool.core.date.DateTime ;
import cn.hutool.core.date.DateUtil ;
import io.reactivex.Flowable ;
import io.reactivex.android.schedulers.AndroidSchedulers ;
import io.reactivex.disposables.Disposable ;
import io.reactivex.schedulers.Schedulers ;
import kotlin.Unit ;
import kotlin.jvm.functions.Function1 ;
@ -45,8 +48,7 @@ public class BizGlobal {
@@ -45,8 +48,7 @@ public class BizGlobal {
public static final String PROJECT_ICON_COLOR = "projectIconColor" ;
public static final Map < Long , Project > CACHE_PROJECT = new HashMap < > ( ) ;
public static final Map < Long , Integer > CACHE_PROJECT_COUNT = new HashMap < > ( ) ;
public static final Map < Long , Integer > CACHE_PROJECT_TODAY_COUNT = new HashMap < > ( ) ;
public static final Map < String , List < Record > > CACHE_RECORD_LIST = new HashMap < > ( ) ;
public static final Map < String , Map < Long , List < Record > > > CACHE_RECORD_LIST = new HashMap < > ( ) ;
public static final String EMPTY_PROJECT_TIPS = "先去添加打卡项吧~" ;
public static final String EMPTY_PROJECT_TIPS_ICON = "cmd_alert_decagram_outline" ;
public static final int REQUEST_CODE_GENERAL = 1 ;
@ -71,11 +73,39 @@ public class BizGlobal {
@@ -71,11 +73,39 @@ public class BizGlobal {
// 按类别区分每一个打卡项 存在多少条打卡记录
buildProjectCountCache ( ) ;
// 全部打卡项列表
buildAllRecordCache ( ) ;
}
private static void buildAllRecordCache ( ) {
Flowable < List < Record > > listFlowable = DBManager . INSTANCE . recordDao ( ) . listAll ( ) ;
Disposable subscribe = listFlowable . subscribeOn ( Schedulers . io ( ) )
. observeOn ( AndroidSchedulers . mainThread ( ) )
. subscribe ( records - > {
XLog . d ( "build all record cache size: {}" , records . size ( ) ) ;
if ( CollUtil . isNotEmpty ( records ) ) {
CACHE_RECORD_LIST . clear ( ) ;
for ( Record record : records ) {
DateTime dateTime = DateUtil . date ( record . getCreateDate ( ) ) ;
String dateStr = dateTime . toString ( "yyyy-MM-dd" ) ;
Map < Long , List < Record > > currDateMap = CACHE_RECORD_LIST . getOrDefault ( dateStr , new HashMap < > ( ) ) ;
List < Record > currDateList = currDateMap . getOrDefault ( record . getProjectId ( ) , new ArrayList < > ( ) ) ;
currDateList . add ( record ) ;
currDateMap . put ( record . getProjectId ( ) , currDateList ) ;
CACHE_RECORD_LIST . put ( dateStr , currDateMap ) ;
}
}
XLog . d ( "build record cache size: {}" , CACHE_RECORD_LIST . size ( ) ) ;
} ) ;
}
private static void buildProjectCountCache ( ) {
Flowable < List < ProjectCount > > listFlowable = DBManager . INSTANCE . recordDao ( ) . groupCountProject ( ) ;
listFlowable . subscribeOn ( Schedulers . io ( ) )
Disposable subscribe = listFlowable . subscribeOn ( Schedulers . io ( ) )
. observeOn ( AndroidSchedulers . mainThread ( ) )
. subscribe ( projectCountList - > {
@ -159,7 +189,8 @@ public class BizGlobal {
@@ -159,7 +189,8 @@ public class BizGlobal {
checkDateLayout . addRule ( RelativeLayout . BELOW , projectNameViewId ) ;
int checkDateViewId = IntSnowflake . next_id ( ) ;
// 打卡时间文本view
TextView checkDateTextView = getTextView ( context , checkDateViewId , DateUtil . date ( record . getCheckDate ( ) ) . toString ( DatePattern . NORM_DATE_PATTERN ) , checkDateLayout , R . color . _666666 , 12 , Gravity . TOP ) ;
// TextView checkDateTextView = getTextView(context, checkDateViewId, DateUtil.date(record.getCheckDate()).toString(DatePattern.NORM_DATE_PATTERN), checkDateLayout, R.color._666666, 12, Gravity.TOP);
TextView checkDateTextView = getTextView ( context , checkDateViewId , record . getDescription ( ) , checkDateLayout , R . color . _666666 , 12 , Gravity . TOP ) ;
itemLayout . addView ( checkDateTextView ) ;
// 创建时间