# CalendarListView **Repository Path**: chinasoft5_ohos/CalendarListView ## Basic Information - **Project Name**: CalendarListView - **Description**: No description available - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-07-29 - **Last Updated**: 2024-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # CalendarListView ## 项目介绍 - 项目名称:CalendarListView - 所属系列:openharmony的第三方组件适配移植 - 功能:一个ListView 和 CalendarView 结合并互相联动的控件,日历可以伸缩扩展,列表可以上拉下沉, 日历的选择会让ListView 滑动到指定的位置,ListView的滑动同时也会带动日历滑到指定位置并能同时自动切换月份 - 项目移植状态:主功能完成 - 调用差异:无 - 开发版本:sdk6,DevEco Studio2.2 beta1 - 基线版本:Release 1.0.1 ## 效果演示 ![CalendarListView Demo](art/CalendarViewDemo.gif) ## 安装教程 1.在项目根目录下的build.gradle文件中, ``` allprojects { repositories { maven { url 'https://s01.oss.sonatype.org/content/repositories/releases/' } } } ``` 2.在app模块的build.gradle文件中, ``` dependencies { implementation('com.gitee.chinasoft_ohos:CalendarListView:1.0.0') ...... } ``` 在sdk6,DevEco Studio2.2 beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 ## 使用说明 **1、Custom style of your CalendarView (like:add price、tag、icon into your items of CalendarView)** ```java //create a Model extends BaseCalendarItemModel then add your custom field. public class CustomCalendarItemModel extends BaseCalendarItemModel{ //data count. private int count; private boolean isFav; ... //getXXX //setXXX ... } //create a custom Adapter extends BaseCalendarItemAdapter (T extends //BaseCalendarItemModel),then override getView function to custom your //calendar item's style. public class CalendarItemAdapter extends BaseCalendarItemAdapter{ //date format:"yyyy-MM-dd" @Override public Component getView(String date, CustomCalendarItemModel model, Component convertView, ComponentContainer parent) { // CustomCalendarItemModel model = dayModelList.get(date); is supported. .... .... ComponentContainer view = LayoutScatter.getInstance(mContext).parse (ResourceTable.Layout_custom_calendar_item, null, false); Text dayNum = (Text) view.findComponentById((ResourceTable.Id_day_num); dayNum.setText(model.getDayNumber()); .... //get data from model then render your UI. .... .... } } ``` > tips:you can just use BaseCalendarItemAdapter but it is only show date in calendar View. **2、Custom style of your ListView,override getSectionHeaderView and getItemView** ```java public class ListItemAdapter extends BaseCalendarListAdapter { //date format:'yyyy-MM-dd' @Override public Component getSectionHeaderView(String date, Component convertView, ComponentContainer parent) { // List modelList = dateDataMap.get(date);is supported. ..... //custom style of SectionHeader ..... } @Override public Component getItemView(ListModel model,String date, int pos, Component convertView, ComponentContainer parent) { //you can get model by follow code. //List modelList = dateDataMap.get(date); //model = modelList.get(pos) ..... //custom style of List Items ..... } } ``` **3、Initialize CalendarListView and set CalendarItemAdapter and ListItemAdapter** ```xml ``` ```java @Override public void onStart(Intent intent) { ... calendarListView = (CalendarListView) findComponentById(ResourceTable.Id_calendar_listview); listItemAdapter = new ListItemAdapter(getContext()); calendarItemAdapter = new CalendarItemAdapter(getContext()); calendarListView.setCalendarListViewAdapter(calendarItemAdapter, listItemAdapter); ... } ``` **4、Loading data from server then update DataSet** - CalendarView ```java private void onCalendarDataLoadFinish(List datas){ .... .... //TreeMap,key:'yyyy-MM-dd',value:model of this date. TreeMap dateMap=calendarItemAdapter.getDayModelList(); .... CustomCalendarItemModel customCalendarItemModel = dateMap.get(date); //update model customCalendarItemModel.setXXX(data.getXXX()); .... calendarItemAdapter.notifyDataSetChanged(); } ``` - ListView ```java //key:'yyyy-mm-dd' format date private TreeMap> listTreeMap = new TreeMap<>(); private void onListDataLoadFinish(List datas){ .... .... for(Data item:datas) { String day=item.getDate(); //add data if (listTreeMap.get(day) != null) { List list = listTreeMap.get(day); list.add(i); } else { List list = new ArrayList(); list.add(i); listTreeMap.put(day, list); } } .... listItemAdapter.setDateDataMap(listTreeMap); listItemAdapter.notifyDataSetChanged(); } ``` **5、event support** - date selected. ```java calendarListView.setOnCalendarViewItemClickListener(new CalendarListView.OnCalendarViewItemClickListener() { @Override public void onDateSelected(Component View, String selectedDate, int listSection, SelectedDateRegion selectedDateRegion) { //do something.... } }); ``` - month changed. ```java calendarListView.setOnMonthChangedListener(new CalendarListView.OnMonthChangedListener() { @Override public void onMonthChanged(String yearMonth) { //yearMonth:'yyyy-MM-dd' } }); ``` - refresh and load more. ```java calendarListView.setOnListPullListener(new CalendarListView.onListPullListener() { @Override public void onRefresh() { } @Override public void onLoadMore() { } }); ``` ## 测试信息 - CodeCheck代码测试无异常 - CloudTest代码测试无异常 - 病毒安全检测通过 - 当前版本demo功能与原组件基本无差异 ## 版本迭代 - 1.0.0 - 0.0.1-SNAPSHOT ## 版权和许可信息 ``` Copyright 2016 Kelin Hong Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ```