6 Star 0 Fork 0

hihopeorg / SectionedRecyclerViewAdapter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

SectionedRecyclerViewAdapter

本项目是基于开源项目SectionedRecyclerViewAdapter进行ohos化的移植和开发的,可以通过项目标签以及github地址(https://github.com/luizgrp/SectionedRecyclerViewAdapter )追踪到原项目版本

项目介绍

  • 项目名称:SectionedRecyclerViewAdapter
  • 所属系列:ohos的第三方组件适配移植
  • 功能:一种适配器,允许将回收视图拆分为带有页眉和/或页脚的节。每个部分可以单独控制其状态。
  • 项目移植状态:完成
  • 调用差异:ohos暂时不支SearchView功能。
  • 项目作者和维护人:hihope
  • 联系方式:hihope@hoperun.com
  • 原项目Doc地址:https://github.com/luizgrp/SectionedRecyclerViewAdapter
  • 原项目基线版本:master,sha1: 97b4574a98cc3dd6b95e2d580016566f0a193f9f
  • 编程语言:Java
  • 外部库依赖:无

展示效果

avatar

安装教程

方法1.

  1. 编译依赖包SectionedRecyclerViewAdapter.har。
  2. 启动 DevEco Studio,将依赖包导入工程目录“entry->libs”下。
  3. 在moudle级别下的build.gradle文件中添加依赖,在dependences标签中增加对libs目录下har包的引用。
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
	……
}
  1. 在导入的har包上点击右键,选择“Add as Library”对包进行引用,选择需要引用的模块,并点击“OK”即引用成功。

方法2.

  1. 在工程的build.gradle的allprojects中,添加HAR所在的Maven仓地址
repositories {
    maven {
        url 'http://106.15.92.248:8081/repository/Releases/' 
    }
}
  1. 在应用模块的build.gradle的dependencies闭包中,添加如下代码:
dependencies {
    Implementation 'com.github.luizgrp.ohos:SectionedRecyclerViewAdapter:1.0.1'
}

使用说明

  1. 创建Section类:
final class ContactsSection extends Section {

    private final String title;
    private final List<Contact> list;
    private final ClickListener clickListener;
    private final Context context;

    ContactsSection(Context context, final String title, final List<Contact> list,
                    final ClickListener clickListener) {

        super(SectionParameters.builder()
                .itemResourceId(ResourceTable.Layout_section_ex1_item)
                .headerResourceId(ResourceTable.Layout_section_ex1_header)
                .build());
        this.context = context;
        this.title = title;
        this.list = list;
        this.clickListener = clickListener;
    }

    @Override
    public int getContentItemsTotal() {
        return list.size();
    }

    @Override
    public ViewHolder getItemViewHolder(final Component component) {
        return new ItemViewHolder(component);
    }

    @Override
    public void onBindItemViewHolder(ViewHolder holder, int position) {
        final ItemViewHolder itemHolder = (ItemViewHolder) holder;
        final Contact contact = list.get(position);
        itemHolder.tvItem.setText(contact.name);
        VectorElement element = new VectorElement(context, contact.profileImage);
        itemHolder.imgItem.setImageElement(element);
        itemHolder.root.setClickedListener(v ->
                clickListener.onItemRootViewClicked(this, position)
        );
    }

    @Override
    public ViewHolder getHeaderViewHolder(final Component component) {
        ViewHolder viewHolder = null;
        try {
            viewHolder = new HeaderViewHolder(component);
        } catch (Exception e) {
            System.out.println("ContactsSection getHeaderViewHolder Exception " + e.getMessage());
        }
        return viewHolder;
    }

    @Override
    public void onBindHeaderViewHolder(final ViewHolder holder) {
        final HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
        headerHolder.tvTitle.setText(title);
    }

    interface ClickListener {
        void onItemRootViewClicked(final ContactsSection section, final int position);
    }
}
  1. 创建用户ViewHolder给section加载条目:
final class ItemViewHolder extends RecyclerAdapter.ViewHolder {

    final Component root;
    final Image imgItem;
    final Text tvItem;

    public ItemViewHolder(Component component) {
        super(component);
        root = component;
        imgItem = (Image) component.findComponentById(ResourceTable.Id_imgItem);
        tvItem = (Text) component.findComponentById(ResourceTable.Id_tvItem);
    }
}
  1. 使用SectionedRecycleServiceAdapter设置视图:
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_fragment_ex1);
        sectionedAdapter = new SectionedRecyclerViewAdapter(this);
        final Map<String, List<Contact>> contactsMap = new LoadContactsUseCase().execute(this);
        for (final Map.Entry<String, List<Contact>> entry : contactsMap.entrySet()) {
            if (entry.getValue().size() > 0) {
                sectionedAdapter.addSection(new ContactsSection(this, entry.getKey(), entry.getValue(), this));
            }
        }
        ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_recyclerview);
        listContainer.setLayoutManager(new DirectionalLayoutManager());
        listContainer.setItemProvider(sectionedAdapter);
    }

版本迭代

  • v1.0.1

版权和许可信息

License

MIT License (MIT)

The MIT License (MIT) Copyright (c) 2016 Gustavo Pagani Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/hihopeorg/SectionedRecyclerViewAdapter.git
git@gitee.com:hihopeorg/SectionedRecyclerViewAdapter.git
hihopeorg
SectionedRecyclerViewAdapter
SectionedRecyclerViewAdapter
master

搜索帮助